/* ==========================================================================
   Ocean's Mahjong — styles.css
   Glassmorphism design system · 4 tile themes · accessibility modes
   All animations are compositor-friendly (transform / opacity only).
   ========================================================================== */

:root {
  /* declare the page as natively dark so Chrome/Samsung "force dark"
     modes don't invert the white tile faces or hue-shift the glyphs */
  color-scheme: dark;
  --ink: #eaf6f6;
  --ink-dim: rgba(234, 246, 246, 0.62);
  --accent: #35c8d8;
  --accent-soft: rgba(53, 200, 216, 0.18);
  --gold: #e8c170;
  --danger: #ff7d8a;
  --glass-bg: rgba(10, 34, 44, 0.55);
  --glass-line: rgba(255, 255, 255, 0.13);
  --radius: 20px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --tile-scale: 1;
  /* default (gem) tile palette — near-white face for maximum glyph contrast */
  --tile-face1: #fffefb;
  --tile-face2: #efe9da;
  --tile-side: #cbbb95;
  --tile-edge: #97875e;
  --tile-rim: rgba(158, 132, 78, 0.38);
  --sel-glow: #38e1f2;
  --hint-glow: #ffd86b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  color: var(--ink);
  background: #06222e;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  position: fixed;
  inset: 0;
}

/* ───────────────────────── Background ───────────────────────── */

#bg {
  position: fixed; inset: -12%;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(56, 189, 210, 0.28), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(16, 90, 130, 0.45), transparent 65%),
    linear-gradient(168deg, #0a3a4c 0%, #06222e 48%, #04141d 100%);
  animation: bg-drift 36s ease-in-out infinite alternate;
}
/* subtle felt-leaf texture, like the classic green table */
#bg::after {
  content: "";
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='170'%3E%3Cpath d='M30,46 Q52,12 74,46 Q52,72 30,46Z' fill='%23ffffff' fill-opacity='0.045'/%3E%3Cpath d='M104,118 Q126,84 148,118 Q126,144 104,118Z' fill='%23ffffff' fill-opacity='0.035' transform='rotate(42 126 114)'/%3E%3Ccircle cx='136' cy='38' r='3' fill='%23ffffff' fill-opacity='0.05'/%3E%3Ccircle cx='52' cy='132' r='2.4' fill='%23ffffff' fill-opacity='0.045'/%3E%3C/svg%3E");
  background-size: 170px 170px;
}
@keyframes bg-drift {
  from { transform: translate3d(-1.5%, -1%, 0) scale(1); }
  to   { transform: translate3d(1.5%, 1%, 0) scale(1.05); }
}

body.theme-zen #bg {
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(244, 154, 194, 0.25), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(120, 70, 130, 0.40), transparent 65%),
    linear-gradient(168deg, #3d2138 0%, #241326 48%, #140a16 100%);
}
body.theme-nature #bg {
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(132, 204, 110, 0.22), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(28, 94, 70, 0.45), transparent 65%),
    linear-gradient(168deg, #14382a 0%, #0b2419 48%, #051209 100%);
}
body.theme-gold #bg {
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(232, 193, 112, 0.20), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(90, 60, 20, 0.40), transparent 65%),
    linear-gradient(168deg, #21222e 0%, #14141d 48%, #0a0a10 100%);
}
body.theme-ocean #bg {
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(95, 210, 242, 0.25), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(20, 80, 140, 0.5), transparent 65%),
    linear-gradient(168deg, #0a3552 0%, #062441 48%, #03152a 100%);
}
body.theme-night #bg {
  background:
    radial-gradient(120% 90% at 80% -10%, rgba(185, 162, 232, 0.22), transparent 60%),
    radial-gradient(100% 80% at 10% 110%, rgba(70, 50, 130, 0.42), transparent 65%),
    linear-gradient(168deg, #251c45 0%, #161030 48%, #0a0719 100%);
}

/* floating petals (pure CSS animation, GPU only) */
#petals { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.petal {
  position: absolute;
  top: -6vh;
  left: var(--x, 50%);
  width: var(--s, 14px); height: var(--s, 14px);
  border-radius: 80% 4% 80% 4%;
  background: radial-gradient(circle at 30% 30%, var(--pc1, #ffd9e8), var(--pc2, #e892b9));
  opacity: 0;
  animation: petal-fall var(--d, 16s) linear infinite;
  animation-delay: var(--dl, 0s);
  will-change: transform, opacity;
}
@keyframes petal-fall {
  0%   { transform: translate3d(0, -6vh, 0) rotate(0deg);      opacity: 0; }
  8%   { opacity: 0.55; }
  50%  { transform: translate3d(var(--sw, 6vw), 50vh, 0) rotate(200deg); opacity: 0.5; }
  92%  { opacity: 0.4; }
  100% { transform: translate3d(calc(var(--sw, 6vw) * -0.6), 108vh, 0) rotate(420deg); opacity: 0; }
}
body.no-petals .petal { display: none; }

/* ───────────────────────── Splash ───────────────────────── */

#splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px;
  background: linear-gradient(168deg, #0a3a4c, #04141d);
  transition: opacity 0.45s ease;
}
#splash.gone { opacity: 0; pointer-events: none; }
.splash-gem {
  width: 64px; height: 64px;
  background: linear-gradient(150deg, #6fe7f2, #1b98b5 55%, #0e6c85);
  clip-path: polygon(50% 0%, 95% 38%, 50% 100%, 5% 38%);
  animation: gem-pulse 1.4s ease-in-out infinite alternate;
}
@keyframes gem-pulse { from { transform: scale(0.92); opacity: 0.8; } to { transform: scale(1.06); opacity: 1; } }
.splash-logo { font-size: 24px; letter-spacing: 0.06em; font-weight: 300; }
.splash-logo b { font-weight: 700; color: var(--accent); }
.splash-bar { width: 140px; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.12); overflow: hidden; }
.splash-bar i { display: block; width: 40%; height: 100%; border-radius: 2px; background: var(--accent); animation: bar-slide 1.1s ease-in-out infinite; }
@keyframes bar-slide { from { transform: translateX(-110%); } to { transform: translateX(360%); } }

/* ───────────────────────── Layout / screens ───────────────────────── */

#app { position: fixed; inset: 0; z-index: 2; display: flex; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--sat) + 10px) 14px calc(var(--sab) + 12px);
}
.screen.active { display: flex; }

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  backdrop-filter: blur(18px) saturate(1.25);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

/* ───────────────────────── Menu ───────────────────────── */

#screen-menu { align-items: center; justify-content: center; gap: 18px; overflow-y: auto; }
.menu-head { text-align: center; margin-top: 6px; }
.logo {
  margin: 0;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 200; letter-spacing: 0.04em;
  text-shadow: 0 4px 30px rgba(53, 200, 216, 0.35);
}
.logo span { font-weight: 800; color: var(--accent); }
.tagline { margin: 6px 0 0; color: var(--ink-dim); letter-spacing: 0.35em; text-transform: uppercase; font-size: 11px; }

.menu-card { width: min(430px, 100%); padding: 14px; display: flex; flex-direction: column; gap: 10px; }

.btn {
  font: inherit; color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--glass-line);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.btn:active { transform: scale(0.97); background: rgba(255, 255, 255, 0.13); }
.btn.big { min-height: 62px; text-align: left; }
.btn.primary { background: linear-gradient(135deg, rgba(53,200,216,0.85), rgba(20,118,150,0.85)); border-color: rgba(122,228,240,0.55); box-shadow: 0 6px 22px rgba(40, 170, 190, 0.35); }
.btn.subtle { justify-content: center; background: transparent; color: var(--ink-dim); font-size: 13px; margin-top: 14px; }
.btn .mi { font-size: 24px; width: 34px; text-align: center; flex: none; }
.btn .mt { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.btn .mt b { font-size: 16px; }
.btn .mt small { color: var(--ink-dim); font-size: 12px; }
.btn .badge { background: var(--gold); color: #2b2104; font-weight: 800; border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.btn.install { width: min(430px, 100%); justify-content: center; border-style: dashed; color: var(--accent); }
.version { color: rgba(234, 246, 246, 0.3); font-size: 11px; letter-spacing: 0.1em; margin: 2px 0 0; }

.menu-nav { display: flex; width: min(430px, 100%); padding: 8px; gap: 4px; }
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none; color: var(--ink-dim);
  font: inherit; font-size: 11px; padding: 8px 2px; border-radius: 12px; cursor: pointer;
}
.nav-btn:active { background: rgba(255,255,255,0.1); color: var(--ink); }
.nav-btn .ni { font-size: 20px; }

/* ───────────────────────── HUD / controls ───────────────────────── */

#screen-game { padding: calc(var(--sat) + 6px) 6px calc(var(--sab) + 6px); gap: 6px; }

/* floating HUD — round buttons + glass pills over the felt, no bar */
#hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.pill-row { display: flex; gap: 7px; flex: 1; justify-content: center; min-width: 0; }
.pill {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 13px;
  border-radius: 999px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}
.pill .pi { font-size: 14px; }
.pill b { font-size: 14.5px; }

.round-btn, .icon-btn {
  font: inherit; color: var(--ink);
  width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.icon-btn { border-radius: 12px; font-size: 22px; width: 40px; height: 40px; }
.round-btn:active, .icon-btn:active { transform: scale(0.94); }

/* floating action row — pills + the big golden hint button */
#controls { display: flex; align-items: center; gap: 10px; padding: 0 4px; flex: none; }
.ctl-pill {
  font: inherit; color: var(--ink); font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 12px 18px;
  position: relative;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.ctl-pill:active { transform: scale(0.95); }
.ctl-pill:disabled { opacity: 0.4; pointer-events: none; }
.ctl-pill .ci { font-size: 17px; }
.ctl-big {
  width: 62px; height: 62px; flex: none;
  margin-left: auto;
  border: none; border-radius: 50%;
  font: inherit; font-size: 26px;
  background: radial-gradient(circle at 32% 26%, #ffe9a8, #e8b339 58%, #b8860b);
  box-shadow: 0 6px 22px rgba(232, 179, 57, 0.5), inset 0 2px 6px rgba(255, 255, 255, 0.65), inset 0 -3px 8px rgba(120, 80, 10, 0.4);
  position: relative;
  cursor: pointer;
  animation: hint-breathe 2.4s ease-in-out infinite alternate;
}
@keyframes hint-breathe {
  from { box-shadow: 0 6px 18px rgba(232, 179, 57, 0.4), inset 0 2px 6px rgba(255,255,255,0.65), inset 0 -3px 8px rgba(120,80,10,0.4); }
  to   { box-shadow: 0 6px 30px rgba(232, 179, 57, 0.75), inset 0 2px 6px rgba(255,255,255,0.65), inset 0 -3px 8px rgba(120,80,10,0.4); }
}
.ctl-big:active { transform: scale(0.92); }
.ctl-big:disabled { opacity: 0.4; pointer-events: none; animation: none; }
.cbadge {
  position: absolute; top: -4px; right: -4px;
  background: #e8467c; color: #fff;
  font-style: normal; font-size: 11px; font-weight: 800;
  min-width: 20px; height: 20px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  border: 2px solid rgba(255, 255, 255, 0.75);
}
.pause-stats { color: var(--ink-dim); font-size: 13.5px; margin: -8px 0 14px; }
.pause-stats b { color: var(--ink); }
.pause-nav { margin-top: 14px; padding: 6px; width: 100%; }

/* ───────────────────────── Board & tiles ───────────────────────── */

#board-wrap {
  flex: 1; min-height: 0;
  overflow: auto;
  display: flex;                 /* margin:auto centring stays scroll-safe */
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
#board { position: relative; flex: none; margin: auto; }

.tile {
  position: absolute;
  padding: 0; border: none; font: inherit;
  border-radius: 9%;
  background: none;   /* marble body lives inside the face image */
  box-shadow:
    calc(var(--tw, 50px) * -0.055) calc(var(--tw, 50px) * 0.07) 0 var(--tile-side),
    calc(var(--tw, 50px) * -0.07) calc(var(--tw, 50px) * 0.09) 0 var(--tile-edge),
    calc(var(--tw, 50px) * -0.09) calc(var(--tw, 50px) * 0.2) calc(var(--tw, 50px) * 0.15) rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.3s ease, filter 0.25s ease;
  will-change: transform;
  contain: layout style;
}
.tile img { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; -webkit-user-select: none; }

.tile:active { transform: scale(0.95); }

/* assist: locked tiles recede so the playable layer pops */
.tile.blocked { filter: brightness(0.66) saturate(0.75); }

/* match charge-up: tiles glow gold for a beat before slamming together */
.tile.flash {
  filter: brightness(1.6) saturate(1.25) drop-shadow(0 0 12px #ffd86b);
  transition: filter 0.1s ease;
}

.tile.sel {
  transform: translateY(-4%) scale(1.08);
  filter: brightness(1.07) drop-shadow(0 0 12px var(--sel-glow));
  z-index: 999999 !important;
}
.tile.sel::after {
  content: ""; position: absolute; inset: -3px;
  border: 2.5px solid var(--sel-glow);
  border-radius: 12%;
  box-shadow: 0 0 14px var(--sel-glow);
}
.tile.hint::after {
  content: ""; position: absolute; inset: -3px;
  border: 2.5px solid var(--hint-glow);
  border-radius: 12%;
  animation: hint-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes hint-pulse {
  from { box-shadow: 0 0 4px var(--hint-glow); opacity: 0.65; }
  to   { box-shadow: 0 0 18px var(--hint-glow); opacity: 1; }
}
.tile.out {
  transform: translate(var(--fx, 0px), var(--fy, 0px)) scale(0.45) rotate(9deg);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.34s cubic-bezier(0.55, -0.1, 0.75, 0.55), opacity 0.34s ease-in;
}
.tile.in { animation: tile-in 0.34s ease both; }
@keyframes tile-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.tile.nope { animation: tile-nope 0.3s ease; }
@keyframes tile-nope {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5%); filter: brightness(0.7); }
  70% { transform: translateX(5%); filter: brightness(0.7); }
}
.tile.gone { display: none; }

/* tile theme palettes */
body.theme-zen   { --tile-face1: #fffbfa; --tile-face2: #f6e5df; --tile-side: #d6b1a4; --tile-edge: #a47e6f; --tile-rim: rgba(178, 120, 102, 0.34); --sel-glow: #ff9ec6; }
body.theme-nature{ --tile-face1: #fdfff7; --tile-face2: #ebefda; --tile-side: #b2be90; --tile-edge: #7f8c5d; --tile-rim: rgba(118, 134, 72, 0.34); --sel-glow: #8ef29a; }
body.theme-gold  { --tile-face1: #ffeec2; --tile-face2: #edc468; --tile-side: #b0842a; --tile-edge: #7b5b14; --tile-rim: rgba(118, 88, 18, 0.5); --sel-glow: #ffe28a; }
body.theme-ocean { --tile-side: #93b3c2; --tile-edge: #5f8294; --sel-glow: #5fd2f2; }
body.theme-night { --tile-side: #bfa45e; --tile-edge: #847041; --sel-glow: #d3baff; }

/* ───────────────────────── Modals ───────────────────────── */

#modal-root { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 18px; }
#modal-root.hidden, .hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 12, 18, 0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal {
  position: relative;
  width: min(460px, 100%);
  max-height: min(86vh, 720px);
  overflow-y: auto;
  padding: 22px 18px calc(18px + var(--sab));
  animation: modal-in 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes modal-in {
  from { transform: translateY(26px) scale(0.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.modal h2 { margin: 2px 36px 14px 2px; font-weight: 600; font-size: 21px; }
.modal-close { position: absolute; top: 12px; right: 12px; font-size: 16px; z-index: 2; }
.panel { display: none; }
.panel.active { display: block; }
.panel-note { color: var(--ink-dim); font-size: 13px; margin: -6px 0 14px; line-height: 1.45; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* layout picker */
.layout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.layout-card {
  font: inherit; color: var(--ink);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  padding: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer;
}
.layout-card:active { transform: scale(0.96); }
.layout-card svg { width: 100%; height: 64px; }
.layout-card b { font-size: 14px; }
.layout-card .diff { color: var(--gold); font-size: 11px; letter-spacing: 0.12em; }

/* theme picker */
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-card {
  font: inherit; color: var(--ink);
  background: rgba(255,255,255,0.06);
  border: 1.5px solid var(--glass-line);
  border-radius: 14px;
  padding: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer;
}
.theme-card.on { border-color: var(--accent); box-shadow: 0 0 16px var(--accent-soft); }
.theme-card .swatches { display: flex; gap: 7px; }
.theme-card .tile-mini {
  width: 45px; height: 54px;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4));
}
.theme-card .tile-mini img { display: block; width: 100%; height: 100%; }
.theme-card.locked { opacity: 0.6; }
.theme-card.locked .tile-mini { filter: grayscale(0.65) drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4)); }
.theme-card .lockline { color: var(--gold); font-size: 11.5px; font-weight: 700; }
.theme-card b { font-size: 14px; }
.theme-card small { color: var(--ink-dim); font-size: 11px; text-align: center; }

/* audio mixer */
.mix-group { margin-bottom: 18px; }
.mix-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.mix-head .gi { font-size: 18px; width: 24px; text-align: center; }
.mix-head b { font-size: 14px; flex: none; min-width: 72px; }
.slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 26px; background: transparent; margin: 0; cursor: pointer;
}
.slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.16); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%;
  background: linear-gradient(150deg, #7be8f4, var(--accent));
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.16); }
.slider::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 2px solid rgba(255,255,255,0.85); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 13px; color: var(--ink);
  background: rgba(255,255,255,0.07);
  border: 1.5px solid var(--glass-line);
  border-radius: 999px;
  padding: 8px 14px; cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: #aef0f8; }
.chip.on::before { content: "● "; color: var(--accent); font-size: 9px; vertical-align: 2px; }

/* settings */
.set-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.set-row:last-child { border-bottom: none; }
.set-row .st { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.set-row .st b { font-size: 14px; font-weight: 600; }
.set-row .st small { color: var(--ink-dim); font-size: 11.5px; }
.switch { position: relative; width: 50px; height: 29px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch .knob {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
  transition: background 0.2s ease;
}
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 23px; height: 23px; border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(21px); }

/* stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.stat-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 3px; align-items: center;
}
.stat-card b { font-size: 21px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-card small { color: var(--ink-dim); font-size: 11px; text-align: center; }

/* help */
.help-body p { font-size: 14px; line-height: 1.55; color: rgba(234,246,246,0.85); }
.help-body b { color: var(--ink); }

/* win panel — staged finale */
.win-crest { font-size: 54px; text-align: center; animation: crest-pop 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes crest-pop { from { transform: scale(0) rotate(-20deg); } to { transform: scale(1) rotate(0); } }
#panel-win h2 { text-align: center; }

.win-stars { display: flex; justify-content: center; gap: 14px; margin: 8px 0 14px; min-height: 44px; }
.win-stars .star { font-size: 38px; color: rgba(255, 255, 255, 0.16); transform: scale(0.6); transition: none; }
.win-stars .star.lit {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(232, 193, 112, 0.8);
  animation: star-stamp 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes star-stamp {
  0%   { transform: scale(2.4) rotate(-30deg); opacity: 0; }
  60%  { transform: scale(0.9) rotate(4deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.win-tally { display: flex; flex-direction: column; gap: 7px; margin: 0 4px 14px; }
.tally-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14.5px; color: var(--ink-dim);
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.tally-row.show { opacity: 1; transform: none; }
.tally-row b { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }
.tally-row.total { background: var(--accent-soft); border-color: rgba(53, 200, 216, 0.4); }
.tally-row.total span { color: var(--ink); font-weight: 700; }
.tally-row.total b { color: #9ef0f9; font-size: 21px; }

.win-best {
  text-align: center; margin: -4px 0 14px;
  color: var(--gold); font-weight: 800; letter-spacing: 0.18em; font-size: 13px;
  animation: best-glow 1.2s ease-in-out infinite alternate;
}
@keyframes best-glow { from { text-shadow: 0 0 6px rgba(232,193,112,.3); } to { text-shadow: 0 0 20px rgba(232,193,112,.85); } }
.win-flash {
  position: fixed; inset: 0; z-index: 38; pointer-events: none;
  background: radial-gradient(circle at 50% 42%, rgba(255, 235, 180, 0.5), rgba(123, 232, 244, 0.12) 45%, transparent 70%);
  animation: flash-fade 0.9s ease-out both;
}
@keyframes flash-fade { from { opacity: 1; } to { opacity: 0; } }

/* ── daily calendar ── */
.cal-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-nav b { font-size: 16px; }
.cal-nav .icon-btn:disabled { opacity: 0.25; pointer-events: none; }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.cal-week span { text-align: center; font-size: 10.5px; color: var(--ink-dim); letter-spacing: 0.08em; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 6px; }
.cal-day {
  font: inherit; color: var(--ink);
  aspect-ratio: 1; border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 13.5px; cursor: pointer; position: relative;
}
.cal-day:active { transform: scale(0.93); }
.cal-day.blank { background: none; border: none; pointer-events: none; }
.cal-day.future { opacity: 0.3; pointer-events: none; }
.cal-day.done { background: rgba(53, 200, 216, 0.2); border-color: rgba(53, 200, 216, 0.55); }
.cal-day.done::after { content: "✓"; font-size: 10px; color: var(--accent); font-weight: 800; }
.cal-day.today { border-color: var(--gold); box-shadow: 0 0 10px rgba(232, 193, 112, 0.35); }
#btn-daily-today { width: 100%; margin-top: 12px; }

/* ── voyage map ── */
#voyage-map { display: flex; flex-direction: column; gap: 4px; }
.voyage-row { display: flex; justify-content: space-around; align-items: flex-start; padding: 6px 0; }
.voyage-row.rev { flex-direction: row-reverse; }
.voyage-node {
  font: inherit; color: var(--ink);
  width: 76px; min-height: 86px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
}
.voyage-node .pearl {
  width: 58px; height: 58px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 800;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 4px 10px rgba(255, 255, 255, 0.08), 0 4px 12px rgba(0, 0, 0, 0.35);
}
.voyage-node small { font-size: 10px; color: var(--ink-dim); }
.voyage-node .vstars { font-size: 11px; color: var(--gold); letter-spacing: 1px; min-height: 13px; }
.voyage-node.done .pearl { background: rgba(53, 200, 216, 0.25); border-color: var(--accent); color: #b9f1f8; }
.voyage-node.current .pearl {
  border-color: var(--gold);
  background: rgba(232, 193, 112, 0.16);
  animation: pearl-pulse 1.6s ease-in-out infinite alternate;
}
@keyframes pearl-pulse { from { box-shadow: 0 0 6px rgba(232,193,112,.3); } to { box-shadow: 0 0 22px rgba(232,193,112,.75); } }
.voyage-node.locked { opacity: 0.32; pointer-events: none; }

/* layout-card earned stars */
.layout-card .earned { color: var(--accent); font-size: 12px; letter-spacing: 2px; min-height: 14px; }

/* dealing overlay */
#dealing {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(3, 16, 22, 0.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  color: var(--ink-dim); letter-spacing: 0.12em; font-size: 13px;
}
.deal-gem {
  width: 44px; height: 44px;
  background: linear-gradient(150deg, #6fe7f2, #1b98b5 55%, #0e6c85);
  clip-path: polygon(50% 0%, 95% 38%, 50% 100%, 5% 38%);
  animation: gem-pulse 0.9s ease-in-out infinite alternate;
}

/* ───────────────────────── FX canvas / toast ───────────────────────── */

#fx-canvas { position: fixed; inset: 0; z-index: 30; pointer-events: none; }

/* floating score popups & match burst ring */
.score-pop {
  position: fixed; z-index: 36; pointer-events: none;
  transform: translate(-50%, -50%);
  font-weight: 800; font-size: 26px;
  color: #ffd86b;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65), 0 0 20px rgba(255, 216, 107, 0.5);
  animation: score-pop 1.05s cubic-bezier(0.2, 0.7, 0.4, 1) both;
}
.score-pop.combo {
  font-size: 15px; letter-spacing: 0.14em;
  color: #7be8f4;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65), 0 0 16px rgba(123, 232, 244, 0.55);
}
@keyframes score-pop {
  0%   { opacity: 0; transform: translate(-50%, -28%) scale(0.5); }
  16%  { opacity: 1; transform: translate(-50%, -70%) scale(1.22); }
  34%  { transform: translate(-50%, -92%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -240%) scale(0.94); }
}
.match-ring {
  position: fixed; z-index: 34; pointer-events: none;
  width: 20px; height: 20px;
  border: 4px solid rgba(255, 216, 107, 0.95);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 22px rgba(255, 216, 107, 0.6), inset 0 0 12px rgba(255, 216, 107, 0.5);
  animation: ring-out 0.6s cubic-bezier(0.15, 0.6, 0.35, 1) both;
}
@keyframes ring-out {
  from { opacity: 1; transform: translate(-50%, -50%) scale(0.3); }
  to   { opacity: 0; transform: translate(-50%, -50%) scale(5.4); }
}
.blast-glow {
  position: fixed; z-index: 33; pointer-events: none;
  width: 96px; height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 242, 196, 0.95), rgba(255, 216, 107, 0.5) 42%, transparent 70%);
  transform: translate(-50%, -50%) scale(0.25);
  animation: blast-glow 0.5s ease-out both;
}
@keyframes blast-glow {
  0%   { transform: translate(-50%, -50%) scale(0.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.4);  opacity: 0; }
}
html.reduced-motion .blast-glow { display: none; }
html.reduced-motion .score-pop, html.reduced-motion .match-ring { display: none; }

#toast {
  position: fixed;
  left: 50%; bottom: calc(var(--sab) + 86px);
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(8, 30, 40, 0.92);
  border: 1px solid var(--glass-line);
  color: var(--ink);
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 26px rgba(0,0,0,0.45);
  animation: toast-in 0.25s ease both;
  max-width: 86vw; text-align: center;
}
@keyframes toast-in { from { transform: translate(-50%, 14px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ───────────────────────── Accessibility modes ───────────────────────── */

html.large-text body { font-size: 18px; }
html.large-text .hud-stat b { font-size: 19px; }
html.large-text .hud-stat small { font-size: 11px; }
html.large-text .help-body p { font-size: 16px; }
html.large-text .btn .mt b { font-size: 18px; }
html.large-text .btn .mt small { font-size: 13.5px; }

html.high-contrast body { --glass-bg: rgba(3, 14, 20, 0.88); --ink-dim: rgba(234, 246, 246, 0.85); --glass-line: rgba(255,255,255,0.35); }
html.high-contrast .tile {
  outline: 2.5px solid #16202a;
  outline-offset: -2px;
  box-shadow:
    calc(var(--tw, 50px) * -0.055) calc(var(--tw, 50px) * 0.07) 0 var(--tile-side),
    calc(var(--tw, 50px) * -0.07) calc(var(--tw, 50px) * 0.09) 0 #000,
    calc(var(--tw, 50px) * -0.09) calc(var(--tw, 50px) * 0.2) calc(var(--tw, 50px) * 0.15) rgba(0,0,0,0.6);
}
html.high-contrast .tile.blocked { filter: brightness(0.5) saturate(0.6); }
html.high-contrast .tile.sel::after { border-width: 4px; }
html.high-contrast .tile.hint::after { border-width: 4px; }

html.reduced-motion *, html.reduced-motion *::before, html.reduced-motion *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
}
html.reduced-motion #bg { animation: none; }
html.reduced-motion .petal { display: none; }

/* ───────────────────────── Small screens / landscape ───────────────────────── */

@media (max-height: 460px) {
  #screen-menu { flex-direction: row; flex-wrap: wrap; align-content: center; }
  .menu-head { width: 100%; }
  .logo { font-size: 30px; }
}
@media (min-width: 760px) {
  .menu-card, .menu-nav, .btn.install { width: 470px; }
}
