/* ============================================================
   8flowy — design system.
   Cool paper surfaces, dark mode, aqua accent, neumorphic buttons,
   Inter body + Oswald titles. Theme via [data-theme="dark"].
   Pipe colors live in the --fc-N palette below.
   ============================================================ */

/* ---------------- tokens ---------------- */
:root {
  --bg: #eef4f5;
  --surface: #fbfeff;
  --surface-2: #e2ecee;
  --text: #172022;
  --muted: #5b6d70;
  --border: #cfdee1;
  --accent: #0c7489;          /* AA on bg & surface for text/icons */
  --accent-2: #0e9fbe;        /* brand aqua (large/decorative) */
  --accent-soft: rgba(14, 159, 190, 0.16);
  --gold-1: #26b3d4;          /* primary-button gradient (aqua) */
  --gold-2: #0b7c99;
  --star: #f5b301;            /* achievement stars stay gold (conventional) */
  /* flow board vocabulary */
  --flow-back: #dce9ec;       /* grid gaps behind the tiles */
  --flow-tile: #f6fbfc;       /* uniform cell tile */
  --dot-bg: #22333a;          /* fallback dot chip when no pipe color set */
  --dot-fg: #ffffff;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fecaca;
  --btn-bg: #fbfeff;
  --btn-text: #22302f;
  --btn-hover-bg: #e6f0f2;
  --shadow-color: rgba(23, 64, 71, 0.08);
  /* neumorphic shadow pair */
  --neu-dark: rgba(0, 0, 0, 0.12);
  --neu-light: rgba(255, 255, 255, 0.75);
  --grid-line: #d5e4e7;       /* hairline between tiles */
  --board-border: 2.5px;      /* board frame outline (line) width */
  --board-padding: 4px;       /* thin, even frame ring so the colored corners can sit
                                 concentric with the rounded border (see --grid-radius) */
  --board-radius: 9.2px;
  --radius: 16px;
  --radius-lg: 20px;
  --maxw: 600px;
  /* pipe palette — 12 distinct, colorblind-considerate hues (lightness varies
     alongside hue so adjacent pipes separate even with reduced color vision) */
  --fc-0: #e0393f;  /* red */
  --fc-1: #2470e0;  /* blue */
  --fc-2: #eaa800;  /* gold */
  --fc-3: #1f9d44;  /* green */
  --fc-4: #f06a13;  /* orange */
  --fc-5: #00a9b7;  /* cyan */
  --fc-6: #d84fc0;  /* magenta */
  --fc-7: #7a4fd8;  /* violet */
  --fc-8: #8a5a33;  /* brown */
  --fc-9: #7fb814;  /* lime */
  --fc-10: #e86ca0; /* pink */
  --fc-11: #5c6b8a; /* slate */
  font-synthesis: none;
}

[data-theme="dark"] {
  --bg: #191c1d;           /* dark page surface */
  --surface: #2a2f30;      /* cards / status bar / buttons */
  --surface-2: #1f2324;
  --text: #e5e7e7;
  --muted: #a0a8a9;
  --border: #272c2d;
  --accent: #4cc9e2;
  --accent-2: #67d4e9;
  --accent-soft: rgba(76, 201, 226, 0.2);
  --gold-1: #26b3d4;
  --gold-2: #0b7c99;
  --star: #fbbf24;
  --flow-back: #1d2122;
  --flow-tile: #232829;
  --dot-bg: #e8f0f1;
  --dot-fg: #1c2426;
  --good: #54e08a;
  --good-soft: #123a25;
  --bad: #f07474;
  --bad-soft: #45191a;
  --btn-bg: #2a2f30;
  --btn-text: #e5e7e7;
  --btn-hover-bg: #3c4243;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --neu-dark: rgba(0, 0, 0, 0.4);
  --neu-light: rgba(255, 255, 255, 0.045);
  --grid-line: #161a1b;
  --board-border: 1.5px;
  --board-radius: 8.2px;
  /* brighter pipe hues pop on dark tiles */
  --fc-0: #ff6b6b;
  --fc-1: #5b9cff;
  --fc-2: #ffc93c;
  --fc-3: #4ade80;
  --fc-4: #ff9046;
  --fc-5: #2fd3e0;
  --fc-6: #f077de;
  --fc-7: #a685ff;
  --fc-8: #c58f5e;
  --fc-9: #b3e04a;
  --fc-10: #ff92bb;
  --fc-11: #93a6cc;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* iOS Safari: rapid taps while drawing must never trigger double-tap zoom */
  touch-action: manipulation;
  /* single-screen app: the page itself never scrolls; views scroll internally */
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, .display { font-family: "Oswald", "Inter", sans-serif; font-weight: 700; letter-spacing: 0.01em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- app shell (fills one screen, no page scroll) ---------------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  /* No side padding here: the topbar and each view supply their own horizontal
     padding INSIDE the scroll/clip box, so neumorphic shadows aren't cropped at
     the view edge (this container is overflow:hidden). */
  padding: 12px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
#main { flex: 1; min-height: 0; display: flex; }
#main > .view { width: 100%; }
/* most views scroll internally if they overflow; play fits exactly */
.view.active { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-gutter: stable; }
/* pre-boot: sessions that resume onto a board keep the statically-active welcome view
   invisible until the router picks the real view (see the boot-to-board head script) */
html.boot-to-board #view-welcome { visibility: hidden; }
/* bottom padding gives the action-bar's neumorphic shadow room (view clips overflow);
   side padding gives the board breathing room from the screen edges */
#view-play.active { overflow: hidden; display: flex; flex-direction: column; gap: 10px; padding: 6px 16px 12px; scrollbar-gutter: auto; }
/* header + board are centered together as one group, so the timer/difficulty/size sit
   right above the board instead of pinned far up at the top of the screen */
/* The stage always reserves the developer-row's slot at the bottom, so the group sits
   at the same (higher) position whether or not dev mode is on. Margin (not padding)
   keeps fitBoard's clientHeight math correct. */
.play-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; margin-bottom: 34px; }
#view-play:has(.debug-actions:not([hidden])) .play-stage { margin-bottom: 0; }
/* Side padding lives on the view (inside its scroll/clip box) instead of on .app, so
   the ~14px neumorphic shadows of cards/buttons have room and aren't clipped at the
   edge. Vertical padding gives the first/last rows' shadows room in scrolling views. */
.view.active { padding-left: 16px; padding-right: 16px; }
.view.active:not(#view-play) { padding-top: 9px; padding-bottom: 16px; }

/* ---------------- top bar ---------------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 16px; }
.topbar-left { display: inline-flex; align-items: center; gap: 10px; }
/* hamburger sits at the far left as a plain icon (not a raised button) */
.menu-trigger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 40px; margin-left: -6px; padding: 0;
  border: none; background: none; cursor: pointer; color: var(--text);
  transition: color 0.2s ease;
}
.menu-trigger:hover { color: var(--accent); }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: "Oswald", sans-serif; font-weight: 700; letter-spacing: 0.3px;
  font-size: 1.5rem; cursor: pointer; background: none; border: none; color: var(--text); padding: 0;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(145deg, var(--gold-1), var(--gold-2));
  box-shadow: 0 4px 12px rgba(11, 124, 153, 0.35);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
}
.brand-mark svg { width: 68%; height: 68%; display: block; }
.brand-text { color: var(--text); }.brand-text { color: var(--text); }
/* 8flowy wordmark — Shrikhand display face, with the "8" struck in brand orange. */
.brand-logo {
  font-family: "Shrikhand", "Oswald", serif; font-weight: 400;
  font-size: 1.38rem; line-height: 1; color: var(--text);
  display: inline-flex; align-items: center; letter-spacing: 0.2px;
}
.brand-8 {
  display: inline-block;
  color: var(--gold-2);
  margin-right: 0.02em;
  transform: translateY(-0.02em);
}
[data-theme="dark"] .brand-8 { color: var(--gold-1); }
.topbar-actions { display: inline-flex; align-items: center; gap: 10px; }

/* ---------------- neumorphic buttons ---------------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 1rem;
  padding: 11px 22px; border-radius: 22px;
  background: var(--btn-bg); color: var(--btn-text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px;
  white-space: nowrap; /* button labels never wrap to two lines */
  box-shadow: 6px 6px 14px var(--neu-dark), -6px -6px 14px var(--neu-light);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn:hover { background: var(--btn-hover-bg); transform: translateY(-2px); box-shadow: 9px 9px 18px var(--neu-dark), -9px -9px 18px var(--neu-light); }
.btn:active { transform: translateY(0); box-shadow: inset 4px 4px 8px var(--neu-dark), inset -4px -4px 8px var(--neu-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 4px 4px 10px var(--neu-dark), -4px -4px 10px var(--neu-light); }
.btn svg { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(145deg, var(--gold-1), var(--gold-2));
  color: #fff; box-shadow: 0 10px 22px rgba(0, 0, 0, 0.16);
}
.btn-primary:hover { background: linear-gradient(145deg, #3fc3e0, var(--gold-1)); box-shadow: 0 12px 26px rgba(0, 0, 0, 0.2); }
.btn-primary:active { background: linear-gradient(145deg, var(--gold-2), #086079); box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.28); }
[data-theme="dark"] .btn-primary { box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55); }

.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 10px 22px rgba(14, 159, 190, 0.28); }
.btn-accent:hover { filter: brightness(1.05); }

.btn-block { width: 100%; }
.btn-lg { padding: 15px 26px; font-size: 1.1rem; border-radius: 26px; min-height: 54px; }

/* PWA install */
.install-cta { margin-top: 10px; border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); background: var(--accent-soft); }
.install-cta:hover { filter: brightness(1.03); }
.install-lead { margin: 0 0 14px; color: var(--text-soft, inherit); }
.install-step { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; line-height: 1.45; }
.install-step + .install-step { margin-top: 10px; }
.install-step-num { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; }
.install-step-ic { color: var(--accent); line-height: 0; flex: 0 0 auto; }
.install-step-ic svg { width: 22px; height: 22px; }
/* bouncing pointer aimed at Safari's share button (iPhone: bottom toolbar; iPad: top-right) */
/* iPhone Safari keeps its ••• menu at the toolbar's right edge — aim there */
.install-arrow { position: fixed; left: auto; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); color: #fff; z-index: 95; pointer-events: none; line-height: 0; animation: installNudge 1.1s ease-in-out infinite; }
.install-arrow svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.55)); }
#overlay-install[data-share-pos="top"] .install-arrow { left: auto; right: 14px; top: 8px; bottom: auto; animation-name: installNudgeTop; }
@keyframes installNudge { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, 9px); } }
@keyframes installNudgeTop { 0%, 100% { transform: rotate(180deg) translateY(0); } 50% { transform: rotate(180deg) translateY(9px); } }
.btn-toggle[aria-pressed="true"] { background: linear-gradient(145deg, var(--gold-1), var(--gold-2)); color: #fff; box-shadow: inset 3px 3px 7px rgba(0,0,0,0.18), inset -3px -3px 7px rgba(255,255,255,0.12); }

/* circular icon button (neumorphic) */
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--btn-bg); color: var(--btn-text);
  box-shadow: 5px 5px 12px var(--neu-dark), -5px -5px 12px var(--neu-light);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.icon-btn:hover { transform: translateY(-2px); box-shadow: 7px 7px 15px var(--neu-dark), -7px -7px 15px var(--neu-light); }
.icon-btn:active { box-shadow: inset 4px 4px 8px var(--neu-dark), inset -4px -4px 8px var(--neu-light); }
.icon-btn svg { width: 21px; height: 21px; }

/* ---------------- views (SPA) ---------------- */
.view { display: none; flex-direction: column; gap: 16px; animation: viewIn 0.28s ease; }
.view.active { display: flex; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-head { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; }
.view-head h1, .view-head .view-title { margin: 0; font-size: 1.4rem; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; pointer-events: none; }
.view-head .spacer { flex: 1; }
#playHead { margin-left: auto; margin-right: auto; max-width: 100%; flex: none; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; font-weight: 600; padding: 6px 4px; }
.back-btn:hover { color: var(--text); }
.play-meta {
  appearance: none; border: none; background: none; padding: 6px 4px;
  color: var(--muted); font: inherit; font-size: 0.85rem; font-weight: 700;
  white-space: nowrap;
  cursor: default;
}
.play-meta.is-action {
  cursor: pointer;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  min-width: 80px;
  text-align: center;
  letter-spacing: 0;
  transition: all 0.3s ease;
}
.play-meta.is-action::after { content: "▼"; font-size: 0.72em; line-height: 1; vertical-align: 0.08em; margin-left: 5px; color: var(--muted); }
.play-meta.is-action:hover { background: var(--btn-hover-bg); }

/* ---------------- welcome ---------------- */
/* center the (now compact) welcome content vertically for balance; still scrolls if tall */
#view-welcome.active { display: flex; flex-direction: column; justify-content: flex-start; }
/* .welcome-main fills the visible viewport (game UI centered inside), so the
   crawlable .home-seo copy that follows only appears once the player scrolls. */
.welcome-main { min-height: 100%; flex: none; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.hero { text-align: center; padding: 8px 6px 10px; }
.hero-mark {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 18px;
  background: linear-gradient(145deg, var(--gold-1), var(--gold-2));
  box-shadow: 0 12px 26px rgba(11, 124, 153, 0.36);
  display: flex; align-items: center; justify-content: center;
}
.hero-mark svg { width: 74%; height: 74%; display: block; }
/* the hero glyph draws itself in — a tiny taste of the game before playing */
.hero-flow-path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: heroDraw 1.3s cubic-bezier(0.4, 0, 0.2, 1) 0.25s forwards; }
.hero-flow-dot { opacity: 0; animation: heroDot 0.3s ease 1.45s forwards; }
@keyframes heroDraw { to { stroke-dashoffset: 0; } }
@keyframes heroDot { to { opacity: 1; } }
.hero h1 { margin: 0; font-size: 2.4rem; color: var(--text); }.hero h1 { margin: 0; font-size: 2.4rem; color: var(--text); }
/* welcome wordmark in the same Shrikhand 8flowy lockup as the header */
.hero-logo { font-family: "Shrikhand", "Oswald", serif; font-weight: 400; font-size: 2.35rem; letter-spacing: 0.3px; }
.hero-logo .brand-8 { margin-right: 0.04em; }
.hero p { margin: 8px auto 0; color: var(--muted); max-width: 36ch; line-height: 1.5; }

.cta-grid { display: flex; flex-direction: column; gap: 12px; max-width: 420px; margin: 0 auto; width: 100%; }
.cta-row { display: flex; gap: 10px; }
.cta-row > * { flex: 1; min-width: 0; }
/* tighter side padding so paired labels fit one line; wrap (not overflow) as fallback */
.cta-row .btn { padding-left: 14px; padding-right: 14px; }
.cta-row .btn-lg { font-size: 1rem; }
/* secondary actions (LB / stats / account): lighter, fit three across */
.cta-row.secondary { max-width: 420px; margin: 0 auto; width: 100%; }
.cta-row.secondary .btn { font-size: 0.86rem; min-height: 44px; padding: 9px 10px; gap: 6px; box-shadow: 4px 4px 10px var(--neu-dark), -4px -4px 10px var(--neu-light); }
.cta-row.secondary .btn svg { width: 16px; height: 16px; }

.play-main { justify-content: space-between; }
.play-main-label { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.play-main-label svg { width: 18px; height: 18px; }
.play-main-size {
  border-left: 1px solid rgba(255, 255, 255, 0.38);
  margin-left: 12px;
  padding-left: 14px;
  font-size: 0.92rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  opacity: 0.96;
  white-space: nowrap;
}


/* ---------------- status bar / board ---------------- */
/* Centered header: timer on top, difficulty pill centered below it */
.statusbar {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 4px 16px;
}
/* the whole timer is the pause control: tapping anywhere on it pauses. No button
   chrome — just the time and a quiet inline pause glyph beside it. */
.timer-display { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; margin: 0; padding: 0; cursor: pointer; color: var(--text); font: inherit; }
.timer-display .stat-value { font-size: 1.1rem; font-weight: 600; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: 0.3px; }
.timer-display .pause-ic { width: 16px; height: 16px; flex: none; display: block; color: var(--muted); transition: color 0.18s ease; }
.timer-display:hover .pause-ic { color: var(--accent); }
/* once solved, pausing is meaningless: drop the affordance but keep the time visible */
.timer-display.no-pause { cursor: default; }
.timer-display.no-pause .pause-ic { display: none; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-grow { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-value-small { font-size: 16px; }
.message { font-size: 13px; color: var(--muted); line-height: 1.35; }
.message.bad { color: var(--bad); }
.message.good { color: var(--good); }
/* simplified header: time on top, difficulty below; board-size button on the right */
.statusbar .spacer { flex: 1; }
/* timer + difficulty on one baseline row; size selector balanced on the right */
.status-left { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.status-left .stat-value { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: 0.3px; }
.size-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 0.9rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 12px; transition: background 0.2s ease, transform 0.1s ease;
}
.size-btn svg { width: 15px; height: 15px; opacity: 0.5; }
.size-btn:hover { background: var(--btn-hover-bg); }
.size-btn:active { transform: scale(0.96); }
.size-btn.is-fixed, .size-btn:disabled { cursor: default; }
.size-btn.is-fixed svg, .size-btn:disabled svg { display: none; }

.board-wrap { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; }
/* Board frame with button-matched neumorphic elevation. */
.board {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1; /* JS overrides width/height to fit the screen */
  background: var(--board-bg, var(--bg));
  border: var(--board-border) solid var(--border);
  border-radius: var(--board-radius);
  box-shadow: 5px 6px 16px var(--neu-dark), -5px -5px 14px var(--neu-light);
  padding: var(--board-padding);
  touch-action: none; user-select: none;
}
/* the colored grid, with rounded + clipped outer corners (the "bg areas" rounding) */
.board-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr); /* fixed square cells, content-independent */
  gap: 0;                       /* cells touch so each region's color is one block */
  width: 100%; height: 100%;
  background: var(--flow-back); /* shows through the tile gaps as the grid line */
  border-radius: var(--grid-radius, 9px);
  overflow: hidden;
  position: relative;
}
/* Board-generating shimmer:/* Board-generating shimmer: while the next board is fetched, the frame breathes and
   the current tiles glow up in a diagonal wave (negative delays start it mid-flow).
   Pure CSS on the OUTGOING board — the incoming board replaces this DOM the moment it
   arrives, killing every animation instantly, so the reveal is never delayed. */
.board.is-loading { opacity: 0.92; pointer-events: none; animation: gen-frame 1.15s ease-in-out infinite; }
.board.is-loading .cell .tile-bg {
  animation: gen-glow 1.15s ease-in-out infinite;
  animation-delay: calc((var(--gx, 0) + var(--gy, 0)) * -80ms);
}
@keyframes gen-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18) saturate(1.08); }
}
@keyframes gen-frame {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--accent-2); }
}

/* Every flow cell is the same paper tile; the drawn path tints the tiles it
   covers. The rounded, slightly-raised tile sits on top as .tile-bg, inset a
   few px so the grid line shows around it. */
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 0; /* never grow with content */
  background: transparent;     /* region color comes from the SVG backing layer */
  cursor: pointer;
}
/* inset and border-radius are PERCENTAGES of the cell so the tile gap and corner
   roundness are a constant fraction of the cell at every screen size. The shipped
   look is tight and flat: hairline gaps (0.5%) and gently rounded corners (4%). */
.tile-bg {
  position: absolute; inset: var(--tile-inset, 0.5%); z-index: 1;
  background: var(--flow-tile);
  border-radius: var(--tile-radius, 4%);
  box-shadow: var(--tile-shadow, 0 1px 2px rgba(0, 0, 0, 0.13));
  pointer-events: none;
  transition: box-shadow 0.2s, background-color 0.16s ease;
}
[data-theme="dark"] .tile-bg { box-shadow: var(--tile-shadow, 0 1px 2px rgba(0, 0, 0, 0.35)); }
/* cells a pipe covers get a wash of that pipe's color */
.cell.on .tile-bg { background: color-mix(in srgb, var(--pc, var(--accent-2)) 20%, var(--flow-tile)); }
[data-theme="dark"] .cell.on .tile-bg { background: color-mix(in srgb, var(--pc, var(--accent-2)) 26%, var(--flow-tile)); }
/* hover-capable pointers only: on touch, taps would leave the highlight stuck */
@media (hover: hover) {
  .cell:hover::after { content: ""; position: absolute; inset: var(--tile-inset, 0.5%); border-radius: var(--tile-radius, 4%); background: rgba(255, 255, 255, 0.12); z-index: 3; }
}

/* The raised tile in each of the four corner cells rounds its board-facing corner to the
   frame radius (--grid-radius, painted -> smooth) so the tile flows into the rounded board
   corner. Tied to the frame, not --tile-radius, so it is unaffected by the tile-roundness
   setting. The tile's other three corners keep --tile-radius. */
.cell.corner-tl .tile-bg, .cell.corner-tl:hover::after { border-top-left-radius: var(--grid-radius, 9px); }
.cell.corner-tr .tile-bg, .cell.corner-tr:hover::after { border-top-right-radius: var(--grid-radius, 9px); }
.cell.corner-bl .tile-bg, .cell.corner-bl:hover::after { border-bottom-left-radius: var(--grid-radius, 9px); }
.cell.corner-br .tile-bg, .cell.corner-br:hover::after { border-bottom-right-radius: var(--grid-radius, 9px); }

/* ---------------- flow pipes & endpoint dots ----------------
   One SVG overlay per board draws every color's pipe as a rounded thick
   polyline in viewBox units (1 unit = 1 cell), so geometry is resolution-
   independent and a drag only mutates polyline points. DOM endpoint dots sit
   ABOVE the overlay. Color classes c0..c11 bind --pc for pipes, dots and
   covered-tile tints alike. */
.flow-overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; display: block; pointer-events: none; overflow: visible; }
.flow-pipe { fill: none; stroke: var(--pc, var(--accent-2)); stroke-width: var(--pipe-width, 0.34); stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; transition: opacity 0.15s ease; }
.flow-pipe.done { opacity: 1; }
/* color slots: JS assigns cN (N = pair index mod 12) to pipes, dots and cells */
.c0 { --pc: var(--fc-0); } .c1 { --pc: var(--fc-1); } .c2 { --pc: var(--fc-2); }
.c3 { --pc: var(--fc-3); } .c4 { --pc: var(--fc-4); } .c5 { --pc: var(--fc-5); }
.c6 { --pc: var(--fc-6); } .c7 { --pc: var(--fc-7); } .c8 { --pc: var(--fc-8); }
.c9 { --pc: var(--fc-9); } .c10 { --pc: var(--fc-10); } .c11 { --pc: var(--fc-11); }
/* win beat: a white glint runs along each finished pipe (driven by GSAP) */
.flow-shimmer { fill: none; stroke: rgba(255, 255, 255, 0.85); stroke-width: 0.18; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }

/* endpoint dots: big colored circles (~56% of the cell) that pop when their
   pipe connects. No numerals — color IS the pairing. */
.cell .dot {
  position: absolute; inset: 22%; z-index: 4; border-radius: 50%;
  background: var(--pc, var(--dot-bg));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  pointer-events: none;
}
/* the two dots of a connected pair wear a soft same-color halo */
.cell .dot.hit {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22),
    0 0 0 max(2.5px, calc(var(--cellpx, 46px) * 0.07)) color-mix(in srgb, var(--pc, var(--accent-2)) 40%, transparent);
}
/* CSS fallback pop (GSAP does the springy version when motion is allowed) */
html:not(.gsap-ready) .cell .dot.hit { animation: dotPop 0.26s cubic-bezier(0.2, 0.8, 0.3, 1.4); }
@keyframes dotPop { 0% { transform: scale(0.85); } 55% { transform: scale(1.14); } 100% { transform: scale(1); } }
/* a refused dot (another color's endpoint) flashes its refusal */
.cell .dot.flash { animation: dotFlash 0.5s ease; }
@keyframes dotFlash {
  0%, 100% { filter: none; }
  40% { filter: brightness(0.6) saturate(0.3); }
}

/* blocked move: the head cell (and the offender) shake subtly */
@keyframes flowShake { 0%, 100% { transform: none; } 30% { transform: translateX(-6%); } 65% { transform: translateX(5%); } }
.cell.flow-shake .tile-bg, .cell.flow-shake .dot { animation: flowShake 0.3s ease; }

/* keyboard play: a clear focus ring on the whole board */
.board:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
.board:focus:not(:focus-visible) { outline: none; }

/* hint: no popup — the hint plays the move on the board itself; the only
   extra feedback is the clock blinking red as the time penalty lands */
#timer { display: inline-block; transition: color 0.25s ease; }
#timer.penalty { color: var(--bad); animation: penaltyPop 0.4s ease; }
@keyframes penaltyPop { 30% { transform: scale(1.18); } }

.actions { position: relative; }
.actions .btn { transition: opacity .13s ease, transform .15s ease; }

/* ---------------- actions ---------------- *//* ---------------- actions ---------------- */
/* Centered row of round neumorphic icon buttons below the
   board. Extra top padding lifts the row off the grid; padding counts toward the row
   height so fitBoard reclaims it from the board — no overflow. */
.actions { display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 12px 6px 9px; }
/* Desktop: wide rounded pills. On phones they collapse to circles below. */
.actions .btn { width: auto; height: 58px; min-width: 58px; min-height: 58px; flex: none; padding: 0 36px; gap: 0; border-radius: 29px; box-shadow: 3px 4px 10px var(--neu-dark), -3px -3px 9px var(--neu-light); }
.actions .btn:hover { box-shadow: 4px 6px 13px var(--neu-dark), -4px -4px 11px var(--neu-light); }
.actions .btn:active { box-shadow: inset 3px 3px 7px var(--neu-dark), inset -3px -3px 7px var(--neu-light); }
.actions .btn svg { width: 29px; height: 29px; }
/* ---------------- pause ---------------- */
/* full "Paused" curtain over the board; sized to the board in JS (centered in the wrap) */
.pause-overlay[hidden] { display: none !important; }
.pause-overlay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--board-radius);
  background: var(--board-bg, var(--bg));
  border: var(--board-border) solid var(--border);
  box-shadow: 5px 6px 16px var(--neu-dark), -5px -5px 14px var(--neu-light);
  color: var(--text); text-align: center; padding: 16px;
  animation: fade 0.18s ease;
}
.pause-overlay-ic { width: 46px; height: 46px; border-radius: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); }
.pause-overlay-ic svg { width: 26px; height: 26px; }
.pause-overlay-title { font-family: "Oswald", sans-serif; font-weight: 700; font-size: 1.5rem; letter-spacing: 0.3px; }
.pause-overlay-sub { color: var(--muted); font-size: 0.85rem; }

/* the Resume button occupies the action-row slot, mirroring the result bar */
.pause-bar[hidden] { display: none !important; }
.pause-bar { padding: 12px 6px 7px; }
.pause-bar .btn svg { width: 20px; height: 20px; }

.debug-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: -2px; }
.debug-copy-btn { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
.debug-copy-btn:hover { background: var(--surface-2); color: var(--text); }

/* board-size picker/* board-size picker — a bottom sheet opened from the size button (like the main menu
   opens a selection), reusing the menu backdrop for tap-outside dismissal */
.size-sheet {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 100%);
  width: 100%; max-width: var(--maxw); z-index: 96;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: none;
  padding: 14px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.size-sheet.open { transform: translate(-50%, 0); box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.18); }
.size-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.size-option {
  font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer; color: var(--text);
  padding: 15px 10px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.size-option:hover { background: var(--btn-hover-bg); }
.size-option.is-current { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.be-head { display: flex; align-items: center; justify-content: space-between; }
.be-head strong { font-size: 1rem; }
.be-head .be-sub { color: var(--muted); font-size: 11px; font-weight: 600; }
.be-close { border: none; background: var(--surface-2); color: var(--text); width: 28px; height: 28px; border-radius: 8px; font-size: 15px; cursor: pointer; line-height: 1; }
.be-close:hover { background: var(--btn-hover-bg); }
.be-field { display: flex; flex-direction: column; gap: 5px; }
.be-field > span { display: flex; align-items: baseline; justify-content: space-between; font-size: 12.5px; font-weight: 600; color: var(--text); }
.be-field > span em { font-style: normal; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.be-field select { font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.be-field input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; height: 22px; }
/* color rows: label on the left, swatch picker on the right */
.be-color-field { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.be-color-field > span { flex: 1; }
.be-color-field input[type="color"] {
  width: 46px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); cursor: pointer; flex: none;
}
.be-color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.be-color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
.be-actions { display: flex; gap: 8px; margin-top: 2px; }
.be-actions .debug-copy-btn { flex: 1; padding: 9px 12px; font-size: 12px; }
.be-actions .be-primary { background: linear-gradient(145deg, var(--gold-1), var(--gold-2)); color: #fff; border-color: transparent; }
.be-actions .be-primary:hover { filter: brightness(1.05); color: #fff; }
.how { text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-weight: 700; color: var(--text); }
.chip-x { background: var(--surface-2); }
.chip-q { background: var(--accent-soft); color: var(--accent); }

/* ---------------- generic card / pills ---------------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light); padding: 18px; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.pill { display: inline-block; padding: 3px 11px; border-radius: 16px; font-size: 0.74rem; font-weight: 700; }
/* difficulty + cells-filled pills sit side by side under the timer */
.status-pills { display: flex; align-items: center; gap: 8px; }
.progress-pill {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600; line-height: 1.2; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 0.25rem 0.75rem; border-radius: 12px; min-width: 64px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.progress-pill.done { color: var(--good); border-color: var(--good); }
/* visually hidden, screen-reader audible (aria-live announcements) */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* Difficulty pill is a neutral chip whose color comes
   from the theme (white/cream in light, grey in dark) — NOT a tier-colored pill. */
.difficulty-tag { cursor: pointer; font: inherit; font-size: 0.85rem; font-weight: 500; line-height: 1.2; color: var(--text); background: var(--btn-bg); border: 1px solid var(--border); padding: 0.25rem 0.75rem; border-radius: 12px; min-width: 80px; text-align: center; text-transform: capitalize; white-space: nowrap; letter-spacing: 0; transition: all 0.3s ease; }
.difficulty-tag:hover { background: var(--btn-hover-bg); }
/* tier colors stay available for other tags (e.g. the journey level pill) */
.pill.easy   { background: #dcfce7; color: #166534; }
.pill.medium { background: #fef3c7; color: #a16207; }
.pill.hard   { background: #fed7aa; color: #c2410c; }
.pill.expert { background: #fecaca; color: #dc2626; }
[data-theme="dark"] .pill.easy   { background: #052e16; color: #86efac; }
[data-theme="dark"] .pill.medium { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .pill.hard   { background: #431407; color: #fb923c; }
[data-theme="dark"] .pill.expert { background: #450a0a; color: #f87171; }
.difficulty-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.difficulty-metric { background: var(--surface-2); border-radius: 14px; padding: 10px; }
.difficulty-metric b { display: block; font-size: 1.1rem; color: var(--text); }
.difficulty-metric span { color: var(--muted); font-size: 0.76rem; }
.difficulty-rules { display: flex; flex-direction: column; gap: 8px; }
.difficulty-rule { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.difficulty-rule:last-child { border-bottom: 0; padding-bottom: 0; }
.difficulty-rule span { color: var(--muted); font-size: 0.82rem; }

/* ---------------- journey map ---------------- */
.journey-progress-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.journey-progress-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-1), var(--gold-2)); transition: width 0.4s ease; }
.journey-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); font-weight: 600; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 11px; }
.level-tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: 16px; border: none;
  background: var(--surface); box-shadow: 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; transition: transform 0.1s ease, box-shadow 0.2s ease; font-weight: 700; color: var(--text);
}
@media (hover: hover) {
  .level-tile:hover { transform: translateY(-2px); }
}
.level-tile .lvl-num { font-family: "Oswald", sans-serif; font-size: 1.2rem; }
.level-tile .lvl-size { font-size: 0.62rem; color: var(--muted); font-weight: 700; }
.level-tile .lvl-stars { font-size: 0.6rem; letter-spacing: 1px; color: var(--star); height: 0.8em; }
.level-tile.done { box-shadow: inset 0 0 0 2px var(--gold-2), 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light); }
.level-tile.current { box-shadow: inset 0 0 0 2px var(--accent), 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light); }
.level-tile.locked { opacity: 0.7; cursor: not-allowed; box-shadow: inset 3px 3px 7px var(--neu-dark), inset -3px -3px 7px var(--neu-light); }
.level-tile.locked .lvl-num, .level-tile.locked .lvl-size, .level-tile.locked .lvl-stars { visibility: hidden; }
/* SVG lock / premium-flow badge, centered, matching the app icon set */
.lvl-badge { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.lvl-badge svg { width: 22px; height: 22px; }
.level-tile.premium-lock { opacity: 1; }
.level-tile.premium-lock .lvl-badge { color: var(--accent); }

/* ---------------- coming-soon / gated ---------------- */
.gate { text-align: center; padding: 34px 20px; }
.gate .gate-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.gate .gate-icon svg { width: 32px; height: 32px; }
.gate h2 { margin: 0 0 6px; }
.gate p { color: var(--muted); max-width: 40ch; margin: 0 auto 16px; line-height: 1.55; }
.gate .badge-soon { display: inline-block; margin-bottom: 14px; padding: 3px 12px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }

.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light); }
.stat-card .big { font-family: "Oswald", sans-serif; font-size: 1.9rem; color: var(--text); }
.stat-card .lbl { color: var(--muted); font-size: 0.78rem; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 12px; }
.ach-card { text-align: center; cursor: pointer; }
.ach-card img { width: 64px; height: 64px; border-radius: 50%; }
.ach-card.locked img { filter: grayscale(1) brightness(0.7); opacity: 0.55; }
.ach-card .ach-name { font-size: 0.72rem; font-weight: 600; margin-top: 5px; line-height: 1.2; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px; }
/* peep avatars are transparent PNGs — give them a soft tinted plate */
.avatar-tile { aspect-ratio: 1; border-radius: 14px; overflow: hidden; cursor: pointer; border: 2px solid var(--border); background: var(--accent-soft); padding: 0; }
.avatar-tile img { width: 100%; height: 100%; display: block; object-fit: cover; }
.avatar-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------- overlays / sheets ---------------- */
.overlay[hidden] { display: none !important; }
.overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(3px); animation: fade 0.2s ease; padding: 18px; }
.sheet { background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 20px 50px rgba(0,0,0,0.3); width: min(460px, 100%); max-height: min(86vh, 760px); overflow: auto; animation: rise 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); border: 1px solid var(--border); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.sheet-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.5rem; line-height: 1; padding: 4px; }
.sheet-close:hover { color: var(--text); }
.sheet-back { background: none; border: none; color: var(--muted); cursor: pointer; line-height: 0; padding: 4px; margin-right: -4px; }
.sheet-back:hover { color: var(--text); }
.sheet-back[hidden] { display: none; }
/* once an avatar is picked the chevron becomes an explicit "Done" */
.sheet-back.done { font: inherit; font-weight: 700; font-size: 0.95rem; line-height: 1; color: var(--accent); padding: 6px 10px; white-space: nowrap; }
/* back | title | close — keep the title hugging the back chevron, close pinned right */
.sheet-head h2 { flex: 1; }

/* settings opens as the right-side counterpart to the hamburger drawer */
#overlay-settings {
  align-items: stretch;
  justify-content: flex-end;
  padding: 0;
  z-index: 90;
}
#overlay-settings .settings-drawer {
  width: min(330px, 87vw);
  max-height: none;
  height: 100%;
  border-radius: 24px 0 0 24px;
  border-top: none;
  border-right: none;
  border-bottom: none;
  box-shadow: -10px 0 44px rgba(0, 0, 0, 0.32);
  animation: settingsDrawerIn 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes settingsDrawerIn {
  from { transform: translateX(105%); }
  to { transform: translateX(0); }
}

/* ---------------- share menu (bottom sheet) ---------------- */
.share-menu-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 1999; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.share-menu-overlay.show { opacity: 1; visibility: visible; }
.share-menu {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 100%);
  width: 100%; max-width: var(--maxw); z-index: 2000;
  background: var(--surface); color: var(--text);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  box-shadow: none;
  max-height: 85vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.share-menu.show { transform: translate(-50%, 0); box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.22); }
.share-menu-header { padding: 18px 20px 13px; border-bottom: 1px solid var(--border); text-align: center; }
.share-menu-title { font-size: 1.18rem; font-weight: 700; margin: 0; }
.share-menu-subtitle { font-size: 0.88rem; color: var(--muted); margin: 4px 0 0; }
.share-menu-content { padding: 16px 18px 22px; }
.share-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 12px; margin-bottom: 18px; }
.share-option {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 6px; border: none; border-radius: 16px; cursor: pointer;
  background: var(--btn-bg); color: var(--text);
  box-shadow: 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light);
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.share-option:hover { background: var(--btn-hover-bg); transform: translateY(-2px); box-shadow: 6px 6px 14px var(--neu-dark), -6px -6px 14px var(--neu-light); }
.share-option:active { transform: translateY(0); }
.share-option-icon { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; color: #fff; }
.share-option-icon svg { width: 20px; height: 20px; }
.share-option-label { font-size: 0.76rem; font-weight: 600; text-align: center; }
.share-url-section { margin-top: 2px; }
.share-url-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 7px; display: block; }
.share-url-container { display: flex; gap: 8px; }
.share-url-input { flex: 1; min-width: 0; padding: 11px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); color: var(--text); font-size: 0.85rem; font-family: ui-monospace, "Menlo", monospace; outline: none; }
.share-url-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.share-url-copy { padding: 11px 17px; border: none; border-radius: 11px; cursor: pointer; font: inherit; font-weight: 700; color: #fff; background: linear-gradient(145deg, var(--gold-1), var(--gold-2)); transition: filter 0.2s ease, transform 0.1s ease; }
.share-url-copy:hover { filter: brightness(1.05); }
.share-url-copy:active { transform: scale(0.97); }

.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
/* dev board-style tuning panel (settings drawer, dev options only) */
.dev-style-panel { border: 1px dashed var(--border); border-radius: 14px; padding: 12px 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 10px; }
.dev-style-title { font-weight: 700; }
.dev-style-title .muted { font-weight: 500; font-size: 0.8rem; }
.dev-style-row { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.dev-style-row > span { display: flex; justify-content: space-between; color: var(--muted); }
.dev-style-row > span b { color: var(--text); font-variant-numeric: tabular-nums; }
.dev-style-row input[type="range"] { width: 100%; accent-color: var(--accent-2); }
.dev-style-inline { flex-direction: row; align-items: center; justify-content: space-between; }
.dev-style-inline select { max-width: 55%; }
.dev-style-inline input[type="color"] { width: 44px; height: 32px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; }
.set-row:last-child { border-bottom: none; }
.set-row .set-label b { display: block; }
.set-row .set-label span { color: var(--muted); font-size: 0.8rem; }
.menu-links { display: flex; flex-direction: column; }
.menu-link { display: flex; align-items: center; gap: 12px; padding: 14px 6px; border-bottom: 1px solid var(--border); cursor: pointer; color: var(--text); font-weight: 600; background: none; border-left: none; border-right: none; border-top: none; width: 100%; text-align: left; font-size: 1rem; }
.menu-link:last-child { border-bottom: none; }
.menu-link:hover { color: var(--accent); }
.menu-link svg { width: 20px; height: 20px; color: var(--muted); }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--surface-2); border-radius: 999px; transition: background 0.2s; box-shadow: inset 2px 2px 5px var(--neu-dark), inset -2px -2px 5px var(--neu-light); }
.switch .track::before { content: ""; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(19px); }

.field { width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------- side drawer menu + hamburger ---------------- */
.menu-backdrop[hidden] { display: none !important; }
.menu-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.42); backdrop-filter: blur(2px); z-index: 90; opacity: 0; transition: opacity 0.3s ease; }
.menu-backdrop.show { opacity: 1; }

.side-menu {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 87vw);
  background: var(--surface); z-index: 100;
  border-top-right-radius: 24px; border-bottom-right-radius: 24px;
  box-shadow: 10px 0 44px rgba(0, 0, 0, 0.32);
  transform: translateX(-105%); transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
}
.side-menu.open { transform: translateX(0); }
.side-menu-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 14px 18px; border-bottom: 1px solid var(--border); }
.side-menu-head .brand { font-size: 1.35rem; cursor: default; }
.side-menu-content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px 22px; }
.menu-section { margin-top: 14px; }
.menu-section:first-child { margin-top: 4px; }
.menu-section h5 { margin: 0 8px 5px; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-family: "Inter", sans-serif; font-weight: 700; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 10px; border-radius: 12px; background: none; border: none; color: var(--text); font: inherit; font-weight: 600; font-size: 0.98rem; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); color: var(--accent); text-decoration: none; }
.menu-item svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.menu-item.legal { font-weight: 500; font-size: 0.88rem; color: var(--muted); padding: 9px 10px; }
.menu-item.legal:hover { color: var(--accent); }

/* animated hamburger inside the icon button */
.hamburger { width: 20px; height: 15px; position: relative; display: inline-block; color: inherit; }
.hamburger i { position: absolute; left: 0; width: 100%; height: 2px; background: currentColor; border-radius: 2px; transition: transform 0.3s ease, opacity 0.2s ease; }
.hamburger i:nth-child(1) { top: 0; }
.hamburger i:nth-child(2) { top: 6.5px; }
.hamburger i:nth-child(3) { top: 13px; }
#menuBtn.menu-open .hamburger i:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
#menuBtn.menu-open .hamburger i:nth-child(2) { opacity: 0; }
#menuBtn.menu-open .hamburger i:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

/* ---------------- win overlay ---------------- */
/* non-modal solved state: occupies the action-row slot (zero layout shift) */
.result-bar[hidden] { display: none !important; }
.result-bar { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 2px 6px 7px; flex-wrap: wrap; }
.result-bar .result-actions { justify-content: center; }
.result-stars { color: var(--star); font-weight: 700; letter-spacing: 1px; font-size: 0.9rem; }
/* celebration banner: a random win word (plus journey stars) above the timer */
.win-banner { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.win-word { font-family: "Shrikhand", "Oswald", cursive; font-weight: 400; font-size: 1.8rem; line-height: 1.2; letter-spacing: 0.01em; color: var(--accent); }
.win-word .ww-ch { display: inline-block; }
.result-actions { display: flex; align-items: center; gap: 8px; }
.result-bar .btn { min-height: 44px; padding: 9px 14px; font-size: 0.9rem; gap: 6px; box-shadow: 3px 4px 10px var(--neu-dark), -3px -3px 9px var(--neu-light); }
.result-bar .btn svg { width: 16px; height: 16px; }
/* completion beat: the Share button glows softly, inviting the brag */
#resultShareBtn { animation: share-glow 1.8s ease-in-out infinite; }
@keyframes share-glow {
  0%, 100% { box-shadow: 3px 4px 10px var(--neu-dark), -3px -3px 9px var(--neu-light), 0 0 0 0 rgba(14, 159, 190, 0); }
  50% { box-shadow: 3px 4px 10px var(--neu-dark), -3px -3px 9px var(--neu-light), 0 0 0 5px var(--accent-soft), 0 0 16px 2px rgba(14, 159, 190, 0.35); }
}

/* one-breath radial glow over the board during the win celebration (added/removed by JS) */
.success-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 4; border-radius: var(--board-radius);
  background: radial-gradient(circle at 50% 50%, rgba(14,159,190,0.20) 0%, rgba(14,159,190,0.06) 45%, transparent 72%); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* ---------------- status toast ---------------- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; box-shadow: 0 12px 30px rgba(0,0,0,0.3); opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.25s ease; z-index: 80; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* status toasts: a colored lead-in glyph sets the tone at a glance */
.toast.good::before { content: "✓"; color: #4ade80; font-weight: 800; margin-right: 9px; }
.toast.bad::before { content: "✕"; color: #f87171; font-weight: 800; margin-right: 9px; }
/* rich toast: badge icon + title + detail (achievements, install) */
.toast.rich { display: flex; align-items: center; gap: 12px; text-align: left; border-radius: 18px; padding: 12px 20px 12px 12px; width: max-content; max-width: min(500px, 92vw); }
.toast-icon { width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; }
.toast-icon.dim { filter: grayscale(1); opacity: 0.55; }
.toast-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toast-body b { font-size: 0.92rem; line-height: 1.25; }
.toast-body span { font-weight: 500; font-size: 0.84rem; opacity: 0.85; line-height: 1.35; }

/* ---------------- footer ---------------- */
.site-footer { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 24px; color: var(--muted); font-size: 0.82rem; }
/* columns as a real grid: 4-up on desktop, 2-up on phones (see media query below) */
.footer-cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px 24px; }
.footer-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.footer-col h4 { margin: 0 0 6px; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text); font-family: "Inter", sans-serif; }
/* links get real tap height without visually spreading the column */
.footer-col a { color: var(--muted); padding: 4px 0; line-height: 1.35; }
.footer-col a:hover { color: var(--accent); text-decoration: none; }
.footer-note { margin: 20px 0 0; font-size: 0.76rem; color: var(--muted); max-width: 58ch; line-height: 1.6; }
.footer-base { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 0.78rem; }
.footer-base .brand-mark { width: 22px; height: 22px; }
@media (max-width: 640px) {
  .site-footer { margin-top: 34px; }
  .footer-cols { grid-template-columns: repeat(2, 1fr); gap: 22px 18px; }
  .footer-col a { padding: 5px 0; }
}

/* ---------------- static content pages ---------------- */
/* the app locks body scrolling (views scroll internally); content pages have no
   internal scroll container, so their body must scroll normally */
body.page-scroll { overflow-y: auto; height: auto; min-height: 100dvh; }
.static-page { max-width: 760px; margin: 0 auto; padding: 22px 20px 70px; }
.static-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 18px; font-size: 0.85rem; }
.static-nav a { color: var(--muted); padding: 4px 0; }
.static-nav .sep { color: var(--border); }
.article { background: var(--surface); border-radius: 18px; padding: 26px 24px; box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light); line-height: 1.7; }
.article h1 { margin-top: 0; text-wrap: balance; }
.article h2 { margin-top: 2em; text-wrap: balance; }
.article h3 { margin-top: 1.7em; margin-bottom: 0.5em; font-size: 1.06rem; text-wrap: balance; }
.article p, .article li, .article figcaption { text-wrap: pretty; }
.article li { margin-bottom: 0.35em; }
/* lede: the opening paragraph carries the page's promise — let it breathe a little */
.article h1 + p { font-size: 1.05rem; line-height: 1.75; }
.article code, .example { background: var(--surface-2); border-radius: 8px; padding: 2px 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.article .example { display: block; padding: 12px 14px; margin: 12px 0; white-space: pre-wrap; }
.callout { background: var(--accent-soft); border-radius: 12px; padding: 14px 16px; margin: 18px 0; }
/* guide index: cards pair up on desktop, stack on phones */
.tip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.tip-grid .tip-card { margin: 0; }
/* phones: the longform card chrome crowds the text — let articles sit flat on the page
   so the prose gets the full measure; interactive cards (tips index) keep their chrome */
@media (max-width: 640px) {
  .article { background: none; box-shadow: none; border-radius: 0; padding: 4px 2px 0; }
  .tip-grid { grid-template-columns: 1fr; gap: 10px; }
}
/* desktop: the card earns generous interior margins */
@media (min-width: 641px) {
  .static-page { padding: 34px 24px 90px; }
  .article { padding: 38px 46px 42px; }
}

/* ---- article board diagrams: static mini boards in the real board's visual language
   (inset rounded tile + the game's dot chips and path stroke). Tile colors
   are the Pastels palette (--t light / --td dark); the backing tint is derived the same
   way the game does it — pushed toward white in light mode, toward black in dark. ---- */
.board-demo { margin: 18px auto; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.demo-board {
  display: grid; grid-template-columns: repeat(5, 1fr);
  width: min(250px, 100%);
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 2px var(--border), 3px 3px 10px var(--neu-dark);
}
.dc { position: relative; aspect-ratio: 1; background: color-mix(in srgb, var(--t) 56%, #fff); }
[data-theme="dark"] .dc { background: color-mix(in srgb, var(--td) 72%, #000); }
.dc::before { content: ""; position: absolute; inset: 5.5%; border-radius: 19%; background: var(--t); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.13); }
[data-theme="dark"] .dc::before { background: var(--td); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
/* the demo path drawn through demo tiles (tutorial intro + articles) */
.dc.path::after {
  content: ""; position: absolute; left: -2%; right: -2%; top: 39%; bottom: 39%;
  background: var(--fc-1); border-radius: 999px; opacity: 0.9;
}
/* highlight ring = "this is the new deduction" *//* highlight ring = "this is the new deduction" */
.dc.hl::before { box-shadow: inset 0 0 0 2.5px var(--accent), 0 1px 2px rgba(0, 0, 0, 0.18); }
.board-demo figcaption { font-size: 0.92em; color: var(--muted); text-align: center; max-width: 360px; line-height: 1.55; }
/* Pastels palette slots (light tile / dark tile) for article diagrams */
.g0  { --t: #FFB3C1; --td: #DD7B93; }
.g4  { --t: #FFD66B; --td: #C0A84F; }
.g7  { --t: #A8E6A1; --td: #5CB873; }
.g11 { --t: #7FD1E8; --td: #4FA6D2; }
.g13 { --t: #C3A6F0; --td: #9579D6; }
/* tutorial-intro demo strip: press the 1, drag to the 2 */
.demo-flow { margin: 4px 0 0; }
.demo-flow svg { width: min(100%, 236px); display: block; }
.dzp-tile { fill: var(--flow-tile); stroke: var(--border); stroke-width: 1; }
.dzp-path { fill: none; stroke: var(--fc-1); stroke-width: 11; stroke-linecap: round; opacity: 0.9; }
.dzp-dot { fill: var(--fc-1); }
.dzp-dot2 { fill: var(--fc-0); }
.step-badge { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; font-size: 0.8rem; margin-right: 8px; }
.tip-card { display: block; background: var(--surface); border-radius: 16px; padding: 16px 18px; margin: 10px 0; box-shadow: 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light); transition: transform 0.1s ease; color: var(--text); }
.tip-card:hover { transform: translateY(-2px); text-decoration: none; }
.tip-card b { display: block; }
.tip-card span { color: var(--muted); font-size: 0.86rem; }

/* ---------------- how-to-play intro (rules at a glance) ----------------
   Also the one-time offer before a new player's first game. It must fit ONE
   viewport with no scrolling: compact cards, one-line icon rules, and the
   whole how-to view clips instead of scrolling. */
#view-howto.active { overflow: hidden; display: flex; flex-direction: column; }
.tut-intro { position: relative; display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 420px; margin: 0 auto; padding: 2px 0; }
.tut-intro-card { padding: 12px 16px; }
.tut-intro-card h5 { margin: 0 0 8px; font-family: "Inter", sans-serif; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tut-intro-card p { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); line-height: 1.45; }
.tut-intro .demo-flow svg { width: min(100%, 200px); }

/* the three rules: icon chip + ONE line each */
.tut-rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.tut-rules li { display: flex; align-items: center; gap: 12px; }
.tut-rule-ic { flex: none; width: 34px; height: 34px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.tut-rule-ic svg { width: 18px; height: 18px; }
.tut-rule-tx { min-width: 0; font-size: 0.84rem; color: var(--muted); line-height: 1.35; }
.tut-rule-tx b { color: var(--text); font-size: 0.88rem; }

/* inline mini icons used inside coach text (trusted, hand-written markup) */
.tut-mini { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.18em; fill: var(--accent); }

/* ---------------- interactive how-to-play ---------------- */
/* One step per rule on a live mini board: progress pips, the board, a coach card that
   talks back (guide / mistake / success), and Back · Show me · Next controls. */
/* `safe center`: if content ever outgrows the pane it aligns to the top
   instead of clipping its head off above the viewport */
.tut-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: safe center; max-width: 420px; width: 100%; margin: 0 auto; }
.tut-lesson { display: flex; flex-direction: column; gap: 13px; min-height: 0; }
.tut-lesson[hidden] { display: none !important; }

.tut-progress-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.tut-progress { display: flex; align-items: center; gap: 7px; }
.tut-pip {
  width: 10px; height: 10px; padding: 0; border: none; border-radius: 999px; cursor: pointer;
  background: var(--surface-2);
  box-shadow: inset 2px 2px 4px var(--neu-dark), inset -2px -2px 4px var(--neu-light);
  transition: width 0.25s cubic-bezier(0.22, 1, 0.36, 1), background 0.2s ease;
}
.tut-pip.done { background: var(--gold-2); box-shadow: none; }
.tut-pip.current { width: 26px; background: linear-gradient(145deg, var(--gold-1), var(--gold-2)); box-shadow: none; }
.tut-pip:disabled { cursor: default; }
.tut-progress-label { font-size: 0.76rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* coach card (below the board): icon tints by mode (guide = accent bulb,
   mistake = red ✕, success = green check) */
.tut-coach {
  display: flex; align-items: flex-start; gap: 12px; min-height: 96px;
  background: var(--surface); border-radius: var(--radius); padding: 13px 15px;
  box-shadow: 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light);
}
.tut-coach-ic {
  flex: none; width: 34px; height: 34px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  transition: background 0.2s ease, color 0.2s ease;
}
.tut-coach-ic svg { width: 19px; height: 19px; }
.tut-coach.bad .tut-coach-ic { background: var(--bad-soft); color: var(--bad); }
.tut-coach.good .tut-coach-ic { background: var(--good-soft); color: var(--good); }
.tut-coach-body { min-width: 0; }
.tut-coach-title { font-weight: 800; font-size: 0.95rem; }
.tut-coach-text { margin: 3px 0 0; font-size: 0.92rem; line-height: 1.5; color: var(--text); }
.tut-coach.pop .tut-coach-body { animation: tutCoachIn 0.3s ease; }
@keyframes tutCoachIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tut-board-wrap { position: relative; display: flex; justify-content: center; }
/* mini board: capped for phones-in-hand, shrinks on short screens so nothing scrolls */
.tut-board { width: max(200px, min(100%, 320px, calc(100dvh - 450px))); aspect-ratio: 1 / 1; }

/* step navigation: Back · Show me — and Next, which only exists once the
   step completes. A fill sweeps across Next matching the auto-advance
   countdown (duration mirrors TUT_NEXT_MS in JS). */
.tut-nav { display: flex; gap: 10px; }
.tut-nav .btn { flex: 1; min-height: 44px; font-size: 0.92rem; padding: 9px 10px; gap: 6px; box-shadow: 4px 4px 10px var(--neu-dark), -4px -4px 10px var(--neu-light); }
.tut-nav .btn svg { width: 16px; height: 16px; }
.tut-nav .btn:disabled { opacity: 0.45; }
.tut-next { position: relative; overflow: hidden; }
.tut-next .tut-next-label { position: relative; z-index: 1; }
.tut-next .tut-next-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: rgba(255, 255, 255, 0.28);
  pointer-events: none;
}
.tut-next.auto .tut-next-fill { animation: tutNextFill 6.4s linear forwards; }
@keyframes tutNextFill { from { width: 0; } to { width: 100%; } }
/* graduation panel *//* graduation panel */
.tut-done { display: flex; flex-direction: column; align-items: center; gap: 11px; text-align: center; padding: 4px 4px 0; animation: rise 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
/* graduation screen drops the view header — tighten the mark a touch so the
   whole block clears the browser chrome at the bottom */
.tut-done .hero-mark { width: 60px; height: 60px; margin-bottom: 4px; }
.tut-done h2 { margin: 0; font-size: 1.7rem; }
.tut-done > p { margin: 0; color: var(--muted); max-width: 36ch; line-height: 1.55; }
.tut-done-rules {
  list-style: none; margin: 2px 0 4px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 9px; text-align: left;
  font-size: 0.92rem; font-weight: 600;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 4px 4px 11px var(--neu-dark), -4px -4px 11px var(--neu-light);
}
.tut-done-rules li { display: flex; align-items: center; gap: 10px; }
.tut-done-rules svg { width: 18px; height: 18px; color: var(--good); flex: none; }
.tut-done .btn-block { max-width: 330px; }
.tut-done-row { display: flex; gap: 10px; width: 100%; max-width: 330px; }
.tut-done-row .btn { flex: 1; font-size: 0.92rem; padding-left: 12px; padding-right: 12px; }

@media (max-width: 400px) {
  .tut-coach { min-height: 118px; }
  .tut-coach-text { font-size: 0.88rem; }
}

/* ---------------- responsive ----------------
   Controls (round icon buttons) and the timer/difficulty pill scale across the same
   breakpoints (600/480/400/360/320). Icon, timer and difficulty sizes
   scale together; the circular buttons shrink in step so the five
   controls stay on a single centered row at every width. */
@media (max-width: 600px) {
  /* phones: slimmer side gutters so the board itself gets the extra width */
  #view-play.active { padding: 6px 12px 10px; }
  .actions { gap: 0.7rem; }
  /* phones: collapse the pills into round icon buttons */
  .actions .btn { width: 58px; height: 58px; min-width: 58px; min-height: 58px; padding: 0; border-radius: 50%; }
  .actions .btn svg { width: 24px; height: 24px; }
  .timer-display .stat-value { font-size: 1rem; }
  .difficulty-tag { font-size: 0.85rem; }
}
@media (max-width: 480px) {
  .actions { gap: 0.6rem; }
  .actions .btn { width: 55px; height: 55px; min-width: 55px; min-height: 55px; }
  .actions .btn svg { width: 22px; height: 22px; }
  .timer-display .stat-value { font-size: 0.95rem; }
  .difficulty-tag { font-size: 0.8rem; }
}
@media (max-width: 460px) {
  .hero h1 { font-size: 2.1rem; }
  .actions { padding-top: 16px; }
  .brand { font-size: 1.3rem; }
}
@media (max-width: 400px) {
  .actions { gap: 0.45rem; }
  .actions .btn { width: 53px; height: 53px; min-width: 53px; min-height: 53px; }
  .actions .btn svg { width: 19px; height: 19px; }
  .timer-display .stat-value { font-size: 0.9rem; }
  .difficulty-tag { font-size: 0.75rem; }
}
@media (max-width: 360px) {
  .actions { gap: 0.4rem; }
  .actions .btn { width: 50px; height: 50px; min-width: 50px; min-height: 50px; }
  .actions .btn svg { width: 17px; height: 17px; }
  .timer-display .stat-value { font-size: 0.85rem; }
  .difficulty-tag { font-size: 0.7rem; }
}
@media (max-width: 320px) {
  .actions { gap: 0.3rem; }
  .actions .btn { width: 46px; height: 46px; min-width: 46px; min-height: 46px; }
  .actions .btn svg { width: 14px; height: 14px; }
  .timer-display .stat-value { font-size: 0.8rem; }
  .difficulty-tag { font-size: 0.65rem; }
}

/* ---------------- desktop: pin the top bar to the screen edges ----------------
   On wide screens the app no longer caps the whole shell at --maxw; the top bar
   spans the full width (menu + game name in the top-left corner, theme/sound/settings
   in the top-right) while the views/board stay centered at --maxw. */
@media (min-width: 768px) {
  .app { max-width: none; }
  #main { max-width: var(--maxw); width: 100%; margin-inline: auto; }
  .topbar { padding: 4px 28px 0; }
}

/* Respect reduced-motion: neutralize game/UI animations (GSAP also no-ops via JS, and
   `gsap-ready` is withheld so the placement fallback below is silenced too). Where an
   animation is the ONLY way an element becomes visible, show a STATIC version instead
   of hiding it. */
@media (prefers-reduced-motion: reduce) {
  .view { animation: none !important; }
  .board.is-loading { animation: none !important; opacity: 0.6; }
  .board.is-loading .cell .tile-bg { animation: none !important; }
  #resultShareBtn { animation: none !important; box-shadow: 3px 4px 10px var(--neu-dark), -3px -3px 9px var(--neu-light), 0 0 0 4px var(--accent-soft) !important; }
  #timer.penalty { animation: none !important; }
  .cell.flow-shake .tile-bg, .cell.flow-shake .dot { animation: none !important; }
  .cell .dot.hit, .cell .dot.flash { animation: none !important; }
  .flow-shimmer { display: none !important; }
  .hero-flow-path { animation: none !important; stroke-dashoffset: 0 !important; }
  .hero-flow-dot { animation: none !important; opacity: 1 !important; }
  .tut-coach.pop .tut-coach-body { animation: none !important; }
  .tut-done { animation: none !important; }
  .tut-pip { transition: none !important; }
}

/* ===================== accounts: daily, LB, auth, premium ===================== */

/* Ad slot */
.ad-slot { margin: 16px 0 0; min-height: 0; overflow: hidden; }

/* LB */
.lb-banner { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light); }
.lb-banner-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.lb-banner-label { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.lb-reset { font-weight: 700; color: var(--accent); font-size: 0.85rem; white-space: nowrap; }
.lb-hero {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: var(--radius); margin-bottom: 12px;
  box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light);
}
.lb-hero-medal { font-size: 2rem; }
.lb-hero-info { flex: 1; }
.lb-hero-rank { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.9; font-weight: 700; }
.lb-hero-name { font-size: 1.3rem; font-weight: 700; font-family: "Oswald", sans-serif; }
.lb-hero-time { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-list { display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; background: var(--surface); border-radius: 14px; box-shadow: 3px 3px 8px var(--neu-dark), -3px -3px 8px var(--neu-light); }
.lb-avatar { width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0; object-fit: cover; }
.lb-hero-avatar { width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0; object-fit: cover; }
.lb-row .lb-rank { width: 34px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-row .lb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .lb-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-row.medal-1 .lb-rank { color: #f5b301; }
.lb-row.medal-2 .lb-rank { color: #9aa3ad; }
.lb-row.medal-3 .lb-rank { color: #cd7f32; }
.lb-row.me { outline: 2px solid var(--accent); }
.lb-me-bar {
  position: sticky; bottom: 10px; margin-top: 14px;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface); border-radius: 16px; border: 2px solid var(--accent);
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
}
.lb-me-bar .lb-rank { font-weight: 700; color: var(--accent); }
.lb-me-bar .lb-name { flex: 1; font-weight: 600; }
.lb-me-bar .lb-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-me-msg { flex: 1; color: var(--muted); font-weight: 600; }

/* small button + utility */
.btn-sm { padding: 8px 14px; font-size: 0.9rem; border-radius: 16px; min-height: 0; }

/* Auth */
.auth-card { display: flex; flex-direction: column; gap: 11px; text-align: center; }
/* compact badge (the bare svg would render huge and push the card past one screen) */
.auth-card .gate-icon { margin: 0 auto; width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.auth-card .gate-icon svg { width: 24px; height: 24px; }
.auth-card h2 { margin: 0; }
.auth-card .field { width: 100%; }
.btn-google { background: #fff; color: #1f1f1c; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
[data-theme="dark"] .btn-google { background: #fff; color: #1f1f1c; }
.g-mark { width: 20px; height: 20px; flex: none; display: block; }
/* email/code panels stack their field + buttons with breathing room */
#authEmailPanel, #authCodePanel { display: flex; flex-direction: column; gap: 12px; }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-legal { font-size: 0.78rem; margin: 4px 0 0; }

/* Profile (signed-in) */
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-avatar { width: 60px; height: 60px; border-radius: 18px; flex-shrink: 0; background: var(--accent-soft); object-fit: cover; }

/* ---------------- avatar backings ----------------
   Peep avatars sit on the board palette's pastel tints (Pastels slots, same hexes as
   the demo boards), derived exactly like game tiles: toward white in light mode,
   toward black in dark. Applied via avbg-N (N = avatar index mod 5). */
/* The peeps are portrait busts (720×972) shown in square frames: plain center-cover
   crops tall hair/heads. Bias the crop window toward the top so faces stay whole. */
.avatar-tile img, .profile-avatar, .lb-avatar, .lb-hero-avatar, #setAvatarImg {
  object-fit: cover;
  object-position: 50% 22%;
}
.avbg-0 { --av: #FFB3C1; --avd: #DD7B93; }
.avbg-1 { --av: #FFD66B; --avd: #C0A84F; }
.avbg-2 { --av: #A8E6A1; --avd: #5CB873; }
.avbg-3 { --av: #7FD1E8; --avd: #4FA6D2; }
.avbg-4 { --av: #C3A6F0; --avd: #9579D6; }
.avatar-tile[class*="avbg-"], .profile-avatar[class*="avbg-"], #setAvatarImg[class*="avbg-"],
.lb-avatar, .lb-hero-avatar { background: color-mix(in srgb, var(--av, #7FD1E8) 46%, #fff); }
[data-theme="dark"] .avatar-tile[class*="avbg-"], [data-theme="dark"] .profile-avatar[class*="avbg-"],
[data-theme="dark"] #setAvatarImg[class*="avbg-"], [data-theme="dark"] .lb-avatar, [data-theme="dark"] .lb-hero-avatar {
  background: color-mix(in srgb, var(--avd, #4FA6D2) 60%, #000);
}
#setAvatarImg { background: var(--accent-soft); object-fit: cover; }
.profile-id { flex: 1; min-width: 0; }
.profile-name-row { display: flex; gap: 8px; align-items: center; }
.profile-name { flex: 1; min-width: 0; }
.profile-email { font-size: 0.85rem; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; }
.profile-plan { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.profile-plan b { display: block; }
.profile-plan span { font-size: 0.85rem; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.profile-actions .btn { flex: 1; min-width: 130px; }

/* Premium */
.premium-card { background: var(--surface); border-radius: var(--radius); padding: 24px; text-align: center; box-shadow: 5px 5px 14px var(--neu-dark), -5px -5px 14px var(--neu-light); }
.premium-mark {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 16px;
  background: linear-gradient(135deg, var(--gold-1), var(--gold-2)); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.premium-mark svg { width: 58%; height: 58%; display: block; }
.premium-card h2 { margin: 0 0 8px; }
.premium-price { margin-bottom: 16px; }
.premium-amount { font-size: 2rem; font-weight: 800; font-family: "Oswald", sans-serif; color: var(--accent); }
.premium-perks { list-style: none; padding: 0; margin: 0 0 20px; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.premium-perks li { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.premium-perks svg { width: 20px; height: 20px; color: var(--good); flex-shrink: 0; }

/* Journey premium lock */
.level-tile.premium-lock { opacity: 0.75; }
.level-tile.premium-lock .lvl-stars { filter: grayscale(0.2); }

/* Stats sync card */
.stats-sync .btn { margin-top: 4px; }

/* ===== crawlable landing copy on the welcome view ===== */
#view-welcome { overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
#view-welcome::-webkit-scrollbar { display: none; }
.home-seo { margin-top: 10px; padding: 18px 4px 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.86rem; text-align: left; }
.home-seo h2 { margin: 0 0 8px; font-size: 1.02rem; color: var(--text); }
.home-seo p { margin: 0 0 10px; line-height: 1.55; max-width: 60ch; }
.home-seo a { color: var(--accent); }
.home-seo-links { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.home-seo-links li { margin: 0; }
.home-seo-note { font-size: 0.76rem; }

/* --- Account features gate ---------------------------------------------------
   Stats, leaderboard, login and Go Premium are hidden unless the server enables
   them (ENABLE_ACCOUNTS flag → the config script adds .accounts-enabled to
   <html>). Hidden by default; functionality is untouched — only the entry-point
   buttons are hidden, so the views remain reachable programmatically. */
html:not(.accounts-enabled) #lbBtn,
html:not(.accounts-enabled) #statsBtn,
html:not(.accounts-enabled) #accountBtn,
html:not(.accounts-enabled) #profilePremiumBtn,
html:not(.accounts-enabled) [data-nav="leaderboard"],
html:not(.accounts-enabled) [data-nav="stats"],
html:not(.accounts-enabled) [data-nav="account"],
html:not(.accounts-enabled) [data-nav="premium"],
/* settings drawer: display name + avatar chooser are account-tied */
html:not(.accounts-enabled) .set-row:has(#setName),
html:not(.accounts-enabled) .set-row:has(#avatarPickBtn),
html:not(.accounts-enabled) #settingsAvatarView {
  display: none !important;
}


/* dark-mode: board drop shadow is dark (no white glow); buttons keep their neumorphic light edge */
[data-theme="dark"] .board { --neu-light: rgba(0, 0, 0, 0.2); }

/* desktop: under-board action buttons ~20% smaller (mobile/compact size unchanged) */
@media (min-width: 768px) {
  .actions .btn { height: 46px; min-width: 46px; min-height: 46px; padding: 0 29px; border-radius: 23px; }
  .actions .btn svg { width: 23px; height: 23px; }
}

/* ---------------- "Other good games" cross-links (menu + footers) ----------------
   Each entry is a miniature of that game's real homepage hero: same gradient
   tile, same SVG glyph, same Shrikhand wordmark with the accent-colored 8. */
.gxa-crowns { --gx1: #60a5fa; --gx2: #3b82f6; --gxs: rgba(59,130,246,0.36); --gx8: #3b82f6; --gx8d: #60a5fa; }
.gxa-patches { --gx1: #8b5cf6; --gx2: #6d28d9; --gxs: rgba(109,40,217,0.36); --gx8: #6d28d9; --gx8d: #8b5cf6; }
.gxa-climb { --gx1: #f43f5e; --gx2: #be123c; --gxs: rgba(225,29,72,0.36); --gx8: #be123c; --gx8d: #f43f5e; }
.gxa-pippy { --gx1: #22c55e; --gx2: #15803d; --gxs: rgba(20,100,50,0.36); --gx8: #15803d; --gx8d: #22c55e; }
.gxa-wend { --gx1: #14b8a6; --gx2: #0b7d72; --gxs: rgba(11,125,114,0.36); --gx8: #0b7d72; --gx8d: #14b8a6; }
.gxa-zippy { --gx1: #f08c3a; --gx2: #d9660f; --gxs: rgba(217,102,15,0.36); --gx8: #d9660f; --gx8d: #f08c3a; }
.gx-mark { width: 28px; height: 28px; flex: none; border-radius: 25%; display: flex; align-items: center; justify-content: center; background: linear-gradient(145deg, var(--gx1), var(--gx2)); box-shadow: 0 3px 8px var(--gxs); }
.gx-mark svg { width: 74%; height: 74%; display: block; }
.gx-name { font-family: "Shrikhand", "Oswald", serif; font-weight: 400; font-size: 1.02rem; line-height: 1.25; letter-spacing: 0.2px; color: var(--text); display: inline-block; }
.gx-8 { color: var(--gx8); margin-right: 0.02em; }
[data-theme="dark"] .gx-8 { color: var(--gx8d); }
.footer-games { margin-top: 28px; }
.footer-games > h4 { margin: 0 0 12px; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text); font-family: "Inter", sans-serif; }
.footer-games-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; max-width: 600px; }
.footer-games-group h5 { margin: 0 0 2px; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-family: "Inter", sans-serif; font-weight: 700; }
.footer-game { display: flex; align-items: center; gap: 12px; padding: 7px 8px; margin: 0 -8px; border-radius: 12px; min-width: 0; }
.footer-game:hover { background: var(--surface-2); text-decoration: none; }
.footer-game .gx-mark { width: 34px; height: 34px; }
.footer-game .gx-name { font-size: 0.98rem; }
.footer-game-txt { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.footer-game-txt small { font-size: 0.73rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the main screen reuses the footer block inside .home-seo */
.home-seo .footer-games { margin: 26px 0 8px; }
@media (max-width: 480px) {
  .footer-games-cols { gap: 4px 14px; }
  .footer-game { gap: 10px; padding: 6px; margin: 0 -6px; }
  .footer-game .gx-mark { width: 30px; height: 30px; }
  .footer-game-txt small { display: none; }
}

/* ---------------- footer v5: games first, legal aligned in the base row ---------------- */
@media (min-width: 641px) { .footer-cols { grid-template-columns: repeat(3, 1fr); } }
.site-footer .footer-games { margin: 2px 0 26px; }
.footer-base { flex-wrap: wrap; justify-content: flex-start; row-gap: 4px; }
.footer-legal { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 16px; flex-basis: 100%; }
.footer-legal a { color: var(--muted); padding: 4px 0; }
.footer-legal a:hover { color: var(--accent); text-decoration: none; }
#view-welcome .site-footer { margin-top: 30px; }

/* journey: header + progress stay pinned while the level grid scrolls */
.journey-pin { position: sticky; top: -9px; z-index: 6; display: flex; flex-direction: column; gap: 16px; background: var(--bg); margin: -9px -16px 0; padding: 9px 16px 6px; }
