/* ═══════════════════════════════════════════════════════
   Mahjong — Premium Solitaire. NYT-Games-adjacent polish.
   ═══════════════════════════════════════════════════════ */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700;9..144,800&family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #0a0c12;
  --bg-raised: #0f1320;
  --bg-card: #161a24;
  --ink: #f2ecdc;
  --ink-soft: #c8c0a8;
  --ink-dim: #8a8473;
  --ink-faint: #4a4638;

  --jade-0: #0d1d1a;
  --jade-1: #15322d;
  --jade-2: #1a423a;

  --tile-hi: #fbf5dc;
  --tile-md: #f2ead0;
  --tile-lo: #d8cda8;
  --tile-edge: #a89c74;
  --tile-deep: #5c5236;
  --tile-shadow: rgba(0, 0, 0, 0.55);

  --accent: #f5b544;
  --accent-dk: #c48918;
  --accent-soft: #f5b54433;

  --red: #c13d32;
  --red-dk: #8a2a22;
  --green: #2a7a3a;
  --green-dk: #1c5826;
  --blue: #2a5a8c;
  --blue-dk: #1a3e66;
  --flower: #c13d7a;
  --season: #b87a1a;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;

  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overscroll-behavior: none;
}

/* Grain overlay for premium feel */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.38;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

/* Warm ambient glow behind everything */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 40% at 30% 10%, rgba(245, 181, 68, 0.08), transparent 60%),
    radial-gradient(ellipse 70% 50% at 70% 90%, rgba(45, 120, 100, 0.06), transparent 60%);
}

#app {
  height: 100dvh;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  animation: fade-in 260ms var(--ease-out);
}
.screen.active { display: flex; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ─── Start screen ─────────────────────────────────────── */
#start {
  padding: 32px 24px;
  align-items: center;
  justify-content: center;
  position: relative;
}

.start-content {
  width: 100%;
  max-width: 420px;
  text-align: center;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
}

.brand-mark {
  font-family: "Fraunces", serif;
  font-weight: 800;
  font-size: clamp(54px, 14vw, 88px);
  letter-spacing: -0.035em;
  background:
    linear-gradient(135deg,
      #fbf5dc 0%,
      #f5d27a 30%,
      #f5b544 48%,
      #c48918 62%,
      #8a5e12 78%,
      #f5d27a 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 4px 26px rgba(245, 181, 68, 0.22));
}

.brand-sub {
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-style: italic;
  font-size: clamp(18px, 5vw, 24px);
  color: var(--ink-soft);
  margin-top: 6px;
  letter-spacing: 0.06em;
}

.tagline {
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 32ch;
  font-weight: 400;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 340px;
}

.stat {
  background: linear-gradient(180deg, #1a1f2c 0%, #12151f 100%);
  border: 1px solid #242a3a;
  border-radius: var(--r-md);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.04) inset,
    0 4px 14px rgba(0,0,0,0.3);
}

.stat-value {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 28px;
  color: var(--ink);
  line-height: 1;
  letter-spacing: -0.02em;
}
.stat-value.accent {
  background: linear-gradient(135deg, #f5d27a 0%, #f5b544 50%, #c48918 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  font-weight: 600;
}

.play-cta {
  appearance: none;
  border: none;
  font-family: "Inter", sans-serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 17px 36px;
  border-radius: 999px;
  background:
    linear-gradient(180deg,
      #ffd47a 0%,
      #f5b544 28%,
      #e89a1a 68%,
      #b8781a 100%);
  color: #1a1408;
  cursor: pointer;
  position: relative;
  box-shadow:
    0 1px 0 rgba(255, 250, 220, 0.6) inset,
    0 -2px 8px rgba(0,0,0,0.18) inset,
    0 4px 0 #7a5210,
    0 8px 24px rgba(245, 181, 68, 0.28);
  transition: transform 140ms var(--ease-spring), box-shadow 140ms;
  min-width: 240px;
  text-shadow: 0 1px 0 rgba(255, 250, 220, 0.35);
}
.play-cta:active {
  transform: translateY(2px);
  box-shadow:
    0 1px 0 rgba(255, 250, 220, 0.6) inset,
    0 -2px 8px rgba(0,0,0,0.18) inset,
    0 2px 0 #7a5210,
    0 6px 18px rgba(245, 181, 68, 0.22);
}

.theme-pill {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--ink-soft);
  padding: 9px 18px;
  border-radius: 999px;
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 140ms, color 140ms;
}
.theme-pill:hover {
  background: rgba(255,255,255,0.08);
  color: var(--ink);
}
.theme-pill svg { opacity: 0.8; }

.ad-free-badge {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ad-free-badge::before,
.ad-free-badge::after {
  content: "";
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ink-faint), transparent);
}

/* Tile hero — flat row of real tiles anchored at screen bottom */
.tile-hero {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: 780px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.92;
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.6));
}

.tile-hero-row {
  display: flex;
  gap: 5px;
  justify-content: center;
  transform: perspective(900px) rotateX(22deg);
  transform-origin: bottom center;
}

.hero-tile {
  width: 62px;
  height: 82px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #ffffff 0%, #fbf6e4 35%, #f1e6c6 100%);
  border-radius: 9px;
  font-family: "Fraunces", "Hiragino Sans GB", "PingFang SC", "Songti SC",
    "Noto Serif CJK SC", serif;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
  position: relative;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.95),
    inset -1px -1px 0 rgba(120, 95, 45, 0.35),
    0 0 0 1px rgba(70, 55, 25, 0.6),
    3px 0 0 -0.5px #e6cf8a,
    4px 0 0 -0.5px #c9a85a,
    0 3px 0 -0.5px #dcc080,
    0 4px 0 -0.5px #b89550,
    4px 10px 14px rgba(0, 0, 0, 0.55);
}
.hero-tile .hero-single { font-size: 50px; letter-spacing: -0.04em; }
.hero-tile .hero-top { font-size: 26px; margin-top: 6px; }
.hero-tile .hero-bot { font-size: 28px; margin-bottom: 4px; }

/* ─── Play screen ──────────────────────────────────────── */
#play {
  position: relative;
  overflow: hidden;
  background: var(--theme-bg,
    radial-gradient(ellipse 90% 65% at 50% 50%, #2a7a3a 0%, #1a5a2a 45%, #0d3818 80%, #061f0c 100%));
}

/* Theme definitions — each sets --theme-bg and --theme-mat (mat behind tiles) */
body.theme-jade {
  /* Classic casino mahjong felt — deep green with vignette */
  --theme-bg:
    radial-gradient(ellipse 90% 65% at 50% 50%, #2a7a3a 0%, #1a5a2a 45%, #0d3818 80%, #061f0c 100%);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(80, 160, 90, 0.22) 0%, rgba(40, 90, 50, 0.15) 55%, transparent 85%);
}
body.theme-sky {
  --theme-bg:
    linear-gradient(180deg, #1a2a5c 0%, #2d5a8c 40%, #5a8ab8 70%, #b8c8d8 100%),
    radial-gradient(ellipse 60% 30% at 30% 20%, rgba(255, 240, 200, 0.3), transparent);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(80, 130, 180, 0.3) 0%, rgba(30, 60, 100, 0.2) 55%, transparent 85%);
}
body.theme-forest {
  --theme-bg:
    radial-gradient(ellipse 90% 60% at 50% 40%, #1a3a1f 0%, #0a1f0f 60%, #050d06 100%);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(50, 100, 40, 0.3) 0%, rgba(20, 50, 15, 0.2) 55%, transparent 85%);
}
body.theme-beach {
  --theme-bg:
    linear-gradient(180deg, #8ab8d8 0%, #bcd5e0 30%, #e8d8a8 55%, #d4b880 85%, #a88850 100%);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(240, 220, 170, 0.5) 0%, rgba(200, 170, 120, 0.3) 55%, transparent 85%);
}
body.theme-ruby {
  --theme-bg:
    radial-gradient(ellipse 90% 60% at 50% 55%, #5c1a1a 0%, #2a0a0a 55%, #140505 100%);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(160, 40, 40, 0.3) 0%, rgba(100, 20, 20, 0.2) 55%, transparent 85%);
}
body.theme-midnight {
  --theme-bg: radial-gradient(ellipse 90% 60% at 50% 50%, #1a1f3a 0%, #0a0d1c 55%, #05070c 100%);
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(120, 100, 180, 0.2) 0%, rgba(60, 50, 100, 0.15) 55%, transparent 85%);
}

.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(10, 12, 18, 0.85) 0%, rgba(10, 12, 18, 0.65) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  gap: 12px;
  flex-shrink: 0;
  z-index: 5;
}

.hud-group {
  display: flex;
  gap: 18px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 48px;
}

.hud-value {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.hud-label {
  font-size: 9px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-top: 4px;
  font-weight: 600;
}

.icon-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--ink-soft);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: background 140ms, color 140ms, transform 140ms;
}
.icon-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--ink);
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Board */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 8px;
}

/* Felt table mat behind board */
.board-wrap::before {
  content: "";
  position: absolute;
  inset: 20px;
  border-radius: 24px;
  background: var(--theme-mat,
    radial-gradient(ellipse 80% 90% at 50% 50%, rgba(42, 95, 80, 0.35) 0%, rgba(20, 50, 42, 0.25) 55%, transparent 85%));
  pointer-events: none;
  z-index: 0;
}

.board {
  position: relative;
  transform-origin: center center;
  will-change: transform;
  z-index: 1;
  flex-shrink: 0;
}

.tile {
  position: absolute;
  cursor: pointer;
  user-select: none;
  transition: transform 200ms var(--ease-spring), opacity 240ms, filter 200ms;
  background: transparent;
  will-change: transform;
  /* Reserve 4px on the right + bottom of the tile's bounding box for the
     3D stone base (walls). The face sits top-left; ::before (right wall)
     and ::after (bottom wall) render the consistent stone sides. */
}

/* Right 3D wall — ivory with a dark green outer edge */
.tile::before {
  content: "";
  position: absolute;
  top: 2px;
  right: 0;
  width: 4px;
  bottom: 6px;
  background: linear-gradient(90deg, #f5ecd0 0%, #e0d09c 100%);
  border-right: 2px solid #1a5a2a;
  border-top: 1px solid rgba(26, 90, 42, 0.4);
  border-radius: 0 6px 0 0;
  pointer-events: none;
}

/* Bottom 3D wall — ivory with a dark green outer edge */
.tile::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 6px;
  bottom: 0;
  height: 4px;
  background: linear-gradient(180deg, #efe0ac 0%, #d6c380 100%);
  border-bottom: 2px solid #1a5a2a;
  border-left: 1px solid rgba(26, 90, 42, 0.4);
  border-radius: 0 0 0 6px;
  pointer-events: none;
}

/* Bottom-right corner cap — merges the two walls cleanly */
.tile > .tile-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 6px;
  height: 6px;
  background: #d4ba78;
  border-right: 2px solid #1a5a2a;
  border-bottom: 2px solid #1a5a2a;
  border-radius: 0 0 6px 0;
  pointer-events: none;
}

/* Tile face — an ivory chip with a subtle bevel (light top-left, warm
   right+bottom walls) and large CJK characters. The bevel is built from
   inset highlights + outer side-wall box-shadows that read as polished
   mahjong stone under top-left lighting. */
.tile-face {
  position: absolute;
  top: 0;
  left: 0;
  /* Face occupies the top-left; the 4px right + 4px bottom strip is used
     by the pseudo-element 3D walls so they are always visible. */
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  background: linear-gradient(160deg, #ffffff 0%, #fbf6e2 55%, #efe2b8 100%);
  border: 2px solid #1a5a2a;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: "Fraunces", "Hiragino Sans GB", "PingFang SC", "Songti SC",
    "Noto Serif CJK SC", serif;
  font-weight: 800;
  line-height: 1;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.85),
    2px 3px 6px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

/* Stacked (craks/bams/dots): CJK numeral top, suit char bottom */
.tile-face.kind-stacked .tile-top {
  font-size: calc(var(--tile-w) * 0.46);
  margin-top: calc(var(--tile-w) * 0.06);
  display: block;
}
.tile-face.kind-stacked .tile-bot {
  font-size: calc(var(--tile-w) * 0.48);
  margin-bottom: calc(var(--tile-w) * 0.08);
  display: block;
}
.tile-face.kind-stacked .tile-top,
.tile-face.kind-stacked .tile-bot {
  text-align: center;
  width: 100%;
  letter-spacing: -0.04em;
}

/* Single-character tiles (winds, dragons, flowers, seasons) */
.tile-face.kind-single .tile-big {
  font-size: calc(var(--tile-w) * 0.82);
  display: block;
  text-align: center;
  line-height: 1;
  letter-spacing: -0.04em;
}

/* White dragon — clean double-rect frame in blue */
.tile-face.kind-frame .tile-frame {
  width: 62%;
  height: 74%;
  border: 2px solid #2a5a8c;
  border-radius: 3px;
  position: relative;
}
.tile-face.kind-frame .tile-frame::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid #2a5a8c;
  border-radius: 2px;
}

/* Dots suit — SVG fills the tile face */
.tile-face.kind-dots .dots-svg,
.tile-face.kind-bams .bams-svg {
  width: 88%;
  height: 88%;
  display: block;
}

/* Semantic color classes — applied to .tile-face, colors the CJK text */
.color-red    { color: #c12a1f; }
.color-green  { color: #1e6d2c; }
.color-blue   { color: #1a3a6c; }
.color-ink    { color: #18120a; }
.color-flower { color: #c13d7a; }
.color-season { color: #b86a10; }
.color-dots   { color: #1a3a6c; }
/* Dots: top (number) blue, bottom (筒) dark green — classic two-tone */
.color-dots .tile-top { color: #c12a1f; }
.color-dots .tile-bot { color: #1e6d2c; }

/* Free vs blocked — blocked is dimmed but still readable */
.tile.free { /* default */ }
.tile.blocked {
  pointer-events: none;
}
.tile.blocked .tile-face,
.tile.blocked::before,
.tile.blocked::after,
.tile.blocked > .tile-corner {
  filter: brightness(0.82) saturate(0.8);
}

.tile.selected {
  transform: translateY(-4px);
  z-index: 50 !important;
}
.tile.selected .tile-face {
  border-color: var(--accent);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 2px var(--accent),
    0 0 18px rgba(245, 181, 68, 0.6),
    2px 3px 6px rgba(0, 0, 0, 0.4);
}

.tile.hint .tile-face {
  animation: hint-pulse 1.2s ease-in-out 3;
}
@keyframes hint-pulse {
  0%, 100% {
    box-shadow:
      inset 1px 1px 0 rgba(255, 255, 255, 0.85),
      2px 3px 6px rgba(0, 0, 0, 0.35);
  }
  50% {
    box-shadow:
      inset 1px 1px 0 rgba(255, 255, 255, 0.95),
      0 0 0 2px var(--accent),
      0 0 22px rgba(245, 181, 68, 0.75),
      2px 3px 6px rgba(0, 0, 0, 0.35);
  }
}

.tile.match-out {
  animation: match-out 480ms var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes match-out {
  0% { opacity: 1; transform: scale(1) rotateZ(0); }
  30% { opacity: 1; transform: scale(1.16) translateY(-4px) rotateZ(-2deg); filter: drop-shadow(0 10px 18px rgba(245, 181, 68, 0.6)); }
  100% { opacity: 0; transform: scale(0.3) rotateZ(6deg); }
}

/* Play footer */
.play-footer {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 12, 18, 0.65) 0%, rgba(10, 12, 18, 0.92) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.04);
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-shrink: 0;
  z-index: 5;
}

.foot-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--ink);
  padding: 13px 18px;
  border-radius: 14px;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 140ms, transform 140ms;
  flex: 1;
  max-width: 120px;
  justify-content: center;
}
.foot-btn:hover { background: rgba(255,255,255,0.09); }
.foot-btn:active { transform: scale(0.96); }
.foot-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.foot-btn .foot-icon {
  font-size: 14px;
  opacity: 0.9;
}

/* ─── Win screen ───────────────────────────────────────── */
#win {
  padding: 48px 24px;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.win-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  font-weight: 600;
}

.win-title {
  font-family: "Fraunces", serif;
  font-weight: 800;
  font-size: clamp(40px, 11vw, 64px);
  background: linear-gradient(135deg, #fbf5dc 0%, #f5d27a 35%, #f5b544 50%, #c48918 70%, #fbf5dc 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 28px rgba(245, 181, 68, 0.28));
  text-align: center;
  line-height: 1;
  letter-spacing: -0.03em;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

.win-actions {
  display: flex;
  gap: 10px;
}

/* Modals / Menu */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.menu-overlay.active { display: flex; }

.menu-card {
  background: linear-gradient(180deg, #1a1f2c 0%, #10131d 100%);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-lg);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.menu-title {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 24px;
  color: var(--ink);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.menu-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  color: var(--ink);
  padding: 14px 18px;
  border-radius: 12px;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  transition: background 140ms;
}
.menu-btn:hover { background: rgba(255,255,255,0.06); }
.menu-btn.primary {
  background:
    linear-gradient(180deg, #ffd47a 0%, #f5b544 50%, #c48918 100%);
  color: #1a1408;
  border: none;
  font-weight: 600;
  justify-content: center;
  box-shadow: 0 1px 0 rgba(255, 250, 220, 0.5) inset, 0 4px 14px rgba(245, 181, 68, 0.2);
}

/* Theme picker grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 4px 0 8px;
}

.theme-swatch {
  appearance: none;
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  height: 84px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  padding: 0;
  transition: border-color 140ms, transform 140ms;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  font-family: "Inter", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.theme-swatch:hover { transform: translateY(-1px); }
.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(245,181,68,0.3);
}
.theme-swatch-label {
  padding: 6px 10px;
  width: 100%;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.5) 100%);
  text-align: left;
}

.theme-swatch[data-theme="jade"]      { background: linear-gradient(140deg, #2a5c4f 0%, #0d1d1a 100%); }
.theme-swatch[data-theme="sky"]       { background: linear-gradient(180deg, #2d5a8c 0%, #b8c8d8 100%); }
.theme-swatch[data-theme="forest"]    { background: linear-gradient(140deg, #2a5a2f 0%, #0a1f0f 100%); }
.theme-swatch[data-theme="beach"]     { background: linear-gradient(180deg, #8ab8d8 0%, #d4b880 100%); }
.theme-swatch[data-theme="ruby"]      { background: linear-gradient(140deg, #8a2a2a 0%, #2a0a0a 100%); }
.theme-swatch[data-theme="midnight"]  { background: linear-gradient(140deg, #3a3560 0%, #0a0d1c 100%); }

/* Category swatches — evocative gradients for image themes */
.theme-swatch[data-cat="chinesisch"] {
  background:
    radial-gradient(circle at 30% 30%, #f5b544 0%, transparent 55%),
    radial-gradient(circle at 80% 80%, #f5d27a 0%, transparent 45%),
    linear-gradient(140deg, #8a2020 0%, #c13d32 55%, #5c1010 100%);
}
.theme-swatch[data-cat="himmel"] {
  background:
    radial-gradient(ellipse 80% 40% at 30% 30%, rgba(255, 240, 200, 0.6), transparent 60%),
    linear-gradient(180deg, #4a6fa0 0%, #a8c4e0 55%, #e0d8c0 100%);
}
.theme-swatch[data-cat="berge"] {
  background:
    linear-gradient(170deg, #6a7290 0%, #3d4560 45%, #1a1f30 100%),
    radial-gradient(ellipse 70% 30% at 50% 80%, rgba(120, 140, 180, 0.3), transparent);
}
.theme-swatch[data-cat="strand"] {
  background: linear-gradient(180deg, #86c5e0 0%, #d5e8f0 45%, #e8d8a8 75%, #c4a870 100%);
}

/* Theme tabs */
.theme-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}
.theme-tab {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: var(--ink-soft);
  padding: 10px 14px;
  border-radius: 10px;
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.theme-tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Difficulty picker */
.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
.diff-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--ink-soft);
  padding: 11px 8px;
  border-radius: 10px;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 140ms, color 140ms, border-color 140ms, transform 140ms;
}
.diff-btn:hover { background: rgba(255,255,255,0.08); color: var(--ink); }
.diff-btn:active { transform: scale(0.97); }
.diff-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 4px 14px rgba(245,181,68,0.15);
}

/* ─── Lose screen ─────────────────────────────────────── */
#lose {
  padding: 48px 24px;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.win-eyebrow.lose { color: #c48888; }
#lose .win-title {
  background: linear-gradient(135deg, #f5cccc 0%, #c13d32 35%, #8a2a22 70%, #f5cccc 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 22px rgba(193, 61, 50, 0.28));
}
.lose-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 34ch;
  text-align: center;
}

/* ─── Category themes (backgrounds per category + variant) ─── */

/* Chinesisch — reds/golds with different accent compositions */
body.cat-chinesisch {
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(200, 100, 60, 0.25) 0%, rgba(90, 30, 20, 0.2) 55%, transparent 85%);
}
body.cat-chinesisch-v0 {
  --theme-bg:
    radial-gradient(ellipse 70% 45% at 30% 20%, rgba(255, 200, 80, 0.18), transparent 70%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(245, 181, 68, 0.12), transparent 65%),
    linear-gradient(160deg, #4a1010 0%, #2a0606 50%, #140202 100%);
}
body.cat-chinesisch-v1 {
  --theme-bg:
    radial-gradient(ellipse 80% 50% at 50% 40%, rgba(193, 61, 50, 0.35) 0%, transparent 70%),
    linear-gradient(180deg, #2a0a08 0%, #1a0505 60%, #0a0202 100%);
}
body.cat-chinesisch-v2 {
  --theme-bg:
    radial-gradient(ellipse 70% 60% at 70% 30%, rgba(245, 181, 68, 0.2), transparent 70%),
    linear-gradient(140deg, #3a1a10 0%, #1a0808 55%, #0a0303 100%);
}
body.cat-chinesisch-v3 {
  --theme-bg:
    radial-gradient(circle at 50% 0%, rgba(255, 160, 80, 0.22), transparent 60%),
    linear-gradient(180deg, #5c1a1a 0%, #2a0808 55%, #140303 100%);
}

/* Himmel — sky-to-horizon gradients */
body.cat-himmel {
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(80, 130, 180, 0.32) 0%, rgba(30, 60, 100, 0.22) 55%, transparent 85%);
}
body.cat-himmel-v0 {
  --theme-bg:
    radial-gradient(ellipse 60% 30% at 30% 20%, rgba(255, 240, 200, 0.3), transparent),
    linear-gradient(180deg, #1a2a5c 0%, #2d5a8c 40%, #5a8ab8 70%, #b8c8d8 100%);
}
body.cat-himmel-v1 {
  --theme-bg:
    radial-gradient(ellipse 80% 50% at 60% 25%, rgba(255, 200, 140, 0.45), transparent 65%),
    linear-gradient(180deg, #4a2a5a 0%, #c46a5a 40%, #e8b898 75%, #f5d8b0 100%);
}
body.cat-himmel-v2 {
  --theme-bg:
    radial-gradient(ellipse 70% 30% at 30% 20%, rgba(200, 220, 250, 0.5), transparent 65%),
    linear-gradient(180deg, #4c6a90 0%, #8aadcc 40%, #c8d8e8 75%, #e8eef4 100%);
}
body.cat-himmel-v3 {
  --theme-bg:
    radial-gradient(ellipse 60% 30% at 50% 20%, rgba(255, 220, 120, 0.3), transparent 70%),
    linear-gradient(180deg, #0a1530 0%, #1a2d5a 45%, #4a6a98 75%, #a8c0dc 100%);
}

/* Berge — mountain blues/greys with mist */
body.cat-berge {
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(100, 115, 150, 0.32) 0%, rgba(40, 50, 75, 0.22) 55%, transparent 85%);
}
body.cat-berge-v0 {
  --theme-bg:
    radial-gradient(ellipse 80% 40% at 50% 80%, rgba(150, 170, 200, 0.25), transparent 65%),
    linear-gradient(170deg, #3d4665 0%, #1f2537 55%, #0a0d16 100%);
}
body.cat-berge-v1 {
  --theme-bg:
    radial-gradient(ellipse 60% 30% at 30% 20%, rgba(255, 220, 180, 0.2), transparent 65%),
    linear-gradient(180deg, #5a5070 0%, #3a3550 50%, #1a1628 100%);
}
body.cat-berge-v2 {
  --theme-bg:
    radial-gradient(ellipse 70% 40% at 50% 30%, rgba(140, 180, 200, 0.25), transparent 65%),
    linear-gradient(180deg, #2a3548 0%, #1a2030 55%, #0a0d16 100%);
}
body.cat-berge-v3 {
  --theme-bg:
    radial-gradient(ellipse 70% 60% at 70% 70%, rgba(180, 160, 130, 0.2), transparent 65%),
    linear-gradient(160deg, #4a4a60 0%, #282838 50%, #101018 100%);
}

/* Strand — sand + ocean gradients */
body.cat-strand {
  --theme-mat: radial-gradient(ellipse 80% 90% at 50% 50%, rgba(240, 220, 170, 0.45) 0%, rgba(180, 150, 100, 0.25) 55%, transparent 85%);
}
body.cat-strand-v0 {
  --theme-bg: linear-gradient(180deg, #86c5e0 0%, #d5e8f0 35%, #e8d8a8 60%, #c4a870 90%, #8a6a40 100%);
}
body.cat-strand-v1 {
  --theme-bg: linear-gradient(180deg, #ec8a5a 0%, #f0b888 30%, #f4d8a8 55%, #d8b080 85%, #9a6a38 100%);
}
body.cat-strand-v2 {
  --theme-bg:
    radial-gradient(ellipse 70% 30% at 50% 20%, rgba(255, 240, 210, 0.4), transparent 60%),
    linear-gradient(180deg, #c8d0d8 0%, #e8ddb8 45%, #d0b888 75%, #8a6a38 100%);
}
body.cat-strand-v3 {
  --theme-bg: linear-gradient(180deg, #2a4a68 0%, #4a6a8a 30%, #7a9ab0 55%, #d8c89a 85%, #8a6a38 100%);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(104px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 22, 32, 0.94);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--ink);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  z-index: 60;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
}
.toast.show {
  animation: toast-flash 1.6s var(--ease-out) forwards;
}
@keyframes toast-flash {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  20%, 70% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -4px); }
}
