/* TapMahjong – mobile-first UI shell */
:root {
  --bg-deep: #120a08;
  --bg-panel: rgba(28, 16, 12, 0.92);
  --bg-glass: rgba(255, 245, 230, 0.06);
  --accent: #e8a84a;
  --accent-dim: #b87a2e;
  --accent-glow: rgba(232, 168, 74, 0.45);
  --text: #f5ebe0;
  --text-muted: #a89080;
  --ok: #7fd99a;
  --stage-green-deep: #243828;
  --stage-green: #2f4f3d;
  --stage-green-light: #3d6b52;
  --bad: #f08888;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 52px;
  --hud-h: 72px;
  --dock-h: 56px;
  --dock-btn-h: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Phaser canvas lives in .game-host; legacy intro vignette disabled */
html::after {
  display: none !important;
}

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, #3d2218 0%, transparent 55%),
    radial-gradient(ellipse 80% 50% at 80% 100%, #1a3020 0%, transparent 45%),
    var(--bg-deep);
}

.app {
  display: grid;
  grid-template-rows:
    var(--header-h)
    minmax(0, auto)
    minmax(0, 1fr)
    minmax(0, calc(var(--dock-h) + var(--safe-bottom)))
    auto;
  height: 100%;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  padding-top: var(--safe-top);
}

.top-bar {
  grid-row: 1;
}

.hud {
  grid-row: 2;
}

.stage {
  grid-row: 3;
}

.dock {
  grid-row: 4;
}

.app-foot {
  grid-row: 5;
}

.app > .hud,
.app > .stage,
.app > .dock {
  min-height: 0;
}

/* Ad row only when ads are enabled (see ads.js → html.ads-live) */
.ad-slot--game {
  display: none;
}

html.ads-live .app {
  grid-template-rows:
    var(--header-h)
    auto
    minmax(0, auto)
    minmax(0, 1fr)
    minmax(0, calc(var(--dock-h) + var(--safe-bottom)))
    auto;
}

html.ads-live .ad-slot--game {
  display: block;
  grid-row: 2;
  min-height: 50px;
  margin: 0;
  padding: 4px 10px 6px;
  overflow: hidden;
  text-align: center;
}

html.ads-live .hud {
  grid-row: 3;
}

html.ads-live .stage {
  grid-row: 4;
}

html.ads-live .dock {
  grid-row: 5;
}

html.ads-live .app-foot {
  grid-row: 6;
}

.ad-slot ins {
  display: block;
  margin: 0 auto;
}

.app-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px calc(6px + var(--safe-bottom));
  font-size: 0.68rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.app-foot a {
  color: var(--text-muted);
  text-decoration: none;
}

.app-foot a:hover {
  color: var(--accent);
}

.app-foot-sep {
  opacity: 0.5;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.brand-domain {
  font-size: 0.68rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.icon-btn:active {
  transform: scale(0.94);
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  min-height: 52px;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.stat-value--small {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* Game stage – helleres Grün nur um die Steine */
.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 95% 75% at 50% 42%, var(--stage-green-light) 0%, var(--stage-green) 48%, var(--stage-green-deep) 100%);
}

.game-host {
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--stage-green);
}

.game-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  margin: 0;
}

.stage-glow {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at 50% 40%,
    transparent 35%,
    rgba(36, 56, 40, 0.35) 70%,
    rgba(18, 10, 8, 0.22) 100%
  );
  opacity: 0.5;
  transition: opacity 0.5s;
}

html.lit .stage-glow {
  opacity: 0.12;
}

/* Dock */
.dock {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  padding-bottom: calc(6px + var(--safe-bottom));
  max-height: calc(var(--dock-h) + var(--safe-bottom));
  overflow: hidden;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.5), transparent);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.dock-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: var(--dock-btn-h);
  min-height: 0;
  max-height: var(--dock-btn-h);
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.dock-btn:active {
  transform: scale(0.97);
}

.dock-btn--primary {
  background: linear-gradient(180deg, #f0b85c, var(--accent-dim));
  border-color: #ffd89a;
  color: #1a0f0a;
  font-weight: 600;
}

.dock-icon {
  font-size: 1rem;
  line-height: 1;
}

.dock-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.1;
}

@media (max-width: 767px) {
  :root {
    --dock-h: 50px;
    --dock-btn-h: 40px;
  }

  .dock-btn--side {
    flex-direction: row;
    gap: 5px;
  }

  .dock-btn--primary {
    flex-direction: column;
    gap: 2px;
  }

  .dock-btn--side .dock-label {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.68rem;
  }

  .hud {
    padding: 6px 8px;
    gap: 4px;
  }

  .stat {
    min-height: 40px;
    padding: 4px 2px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .app-foot {
    padding: 4px 10px calc(4px + var(--safe-bottom));
    font-size: 0.62rem;
  }

  .dock {
    gap: 5px;
    padding: 5px 8px;
    padding-bottom: calc(5px + var(--safe-bottom));
  }
}

@media (max-width: 380px) {
  .dock-btn--primary .dock-label {
    display: none;
  }

  .dock-btn--side .dock-label {
    display: inline;
  }

  :root {
    --dock-h: 46px;
    --dock-btn-h: 38px;
  }

  .dock-icon {
    font-size: 1.15rem;
  }
}

/* Dialogs */
.sheet {
  border: none;
  padding: 0;
  margin: auto;
  max-width: min(420px, calc(100vw - 24px));
  width: 100%;
  border-radius: calc(var(--radius) + 4px);
  background: transparent;
  color: var(--text);
  box-shadow: var(--shadow);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

html.menu-open .sheet--menu::backdrop {
  background: rgba(8, 4, 3, 0.42);
  backdrop-filter: blur(2px);
}

html.menu-open .sheet--menu {
  margin: auto auto 12px;
}

@media (min-width: 768px) {
  html.menu-open .sheet--menu {
    margin: auto;
  }
}

.sheet-inner {
  padding: 24px 20px 20px;
  background: linear-gradient(165deg, #2a1812 0%, #1a0f0a 100%);
  border: 1px solid rgba(232, 168, 74, 0.25);
  border-radius: calc(var(--radius) + 4px);
}

.sheet--compact .sheet-inner {
  padding: 20px;
}

.sheet-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-brand-mark {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.sheet-brand-text {
  flex: 1;
  min-width: 0;
}

.sheet-brand-text .sheet-kicker {
  margin: 0;
}

.sheet-brand-text .sheet-title {
  margin: 0;
}

.sheet-kicker {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.sheet-title {
  margin: 4px 0 12px;
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, #fff5e6, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sheet-title--sm {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.sheet-lead {
  margin: 0 0 18px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.field {
  border: none;
  margin: 0 0 16px;
  padding: 0;
}

.field legend {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.layout-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layout-card {
  cursor: pointer;
}

.layout-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.layout-card-body {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.08);
  background: var(--bg-glass);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.layout-card input:checked + .layout-card-body {
  border-color: var(--accent);
  background: rgba(232, 168, 74, 0.12);
  box-shadow: 0 0 20px var(--accent-glow);
}

.layout-preview {
  flex-shrink: 0;
  width: 64px;
  height: 44px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.layout-card-text {
  flex: 1;
  min-width: 0;
}

.layout-card-text strong {
  display: block;
  font-size: 0.95rem;
}

.layout-card-text small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.rules {
  margin-bottom: 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rules summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 8px;
}

.rules ul {
  margin: 0;
  padding-left: 1.2rem;
  line-height: 1.55;
}

.menu-links {
  margin-bottom: 18px;
}

.menu-links-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.menu-links-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.menu-links-grid a,
.menu-links-grid a:link,
.menu-links-grid a:visited {
  display: block;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  background: var(--bg-glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-text-fill-color: currentColor;
}

.menu-links-grid a:hover {
  color: #fff5e6;
  background: rgba(232, 168, 74, 0.14);
  border-color: rgba(232, 168, 74, 0.35);
}

.menu-links-grid a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (min-width: 560px) {
  .menu-links-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .menu-links-grid a {
    font-size: 0.72rem;
    padding: 8px 6px;
  }
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-actions--row {
  flex-direction: row;
}

.sheet-actions--row .btn {
  flex: 1;
}

.sheet-foot {
  margin: 16px 0 0;
  font-size: 0.68rem;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.45;
}

.sheet-foot a {
  color: var(--accent);
  text-decoration: none;
}

.sheet-foot a:hover {
  text-decoration: underline;
}

.btn {
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: linear-gradient(180deg, #f5c06a, var(--accent-dim));
  color: #1a0f0a;
}

.btn--ghost {
  background: var(--bg-glass);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Result */
.sheet--result .result-badge {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: rgba(127, 217, 154, 0.2);
  color: var(--ok);
}

.sheet--result.is-loss .result-badge {
  background: rgba(240, 136, 136, 0.2);
  color: var(--bad);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
}

.result-stats dt {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0;
}

.result-stats dd {
  margin: 4px 0 0;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.best-line {
  text-align: center;
  font-size: 0.85rem;
  color: var(--accent);
  margin: 0 0 16px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(120%);
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(28, 16, 12, 0.95);
  border: 1px solid rgba(232, 168, 74, 0.35);
  color: var(--text);
  font-size: 0.88rem;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 2000;
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.25s;
  pointer-events: none;
}

.toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Desktop enhancements */
@media (min-width: 768px) {
  :root {
    --header-h: 56px;
    --hud-h: 64px;
  }

  .hud {
    padding: 10px 16px;
  }

  .dock {
    max-width: 480px;
    margin: 0 auto;
    padding-left: 0;
    padding-right: 0;
  }

  .dock-btn {
    flex-direction: row;
    gap: 8px;
    height: 48px;
    max-height: 48px;
    --dock-btn-h: 48px;
  }

  .dock-label {
    font-size: 0.85rem;
    text-transform: none;
    letter-spacing: 0;
  }
}

@media (min-width: 1024px) {
  .app {
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }

  .stage {
    border-radius: var(--radius);
    margin: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .icon-btn,
  .dock-btn,
  .btn {
    transition: none;
  }
}
