/* styles.css
 * Design thesis: COLOR MEANS CHAOS.
 * The base game is calm ink and one trustworthy blue on cool paper. The sly
 * magenta (--mischief) is reserved exclusively for the moment a troll acts, so
 * players learn the tell: magenta = something shady just happened. The polish
 * is the setup; the magenta is the punchline.
 */

/* Self-hosted fonts (formerly Google Fonts). woff2 only, latin subset,
   font-display swap so text paints immediately in the system fallback.
   Filenames carry the upstream version (v9/v22), so /fonts/* can be cached
   immutably; bump the filename if a font is ever updated. */
@font-face {
  font-family: 'Bricolage Grotesque'; font-style: normal; font-weight: 600;
  font-display: swap; src: url('fonts/bricolage-grotesque-v9-latin-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Bricolage Grotesque'; font-style: normal; font-weight: 800;
  font-display: swap; src: url('fonts/bricolage-grotesque-v9-latin-800.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 400;
  font-display: swap; src: url('fonts/space-grotesk-v22-latin-regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 500;
  font-display: swap; src: url('fonts/space-grotesk-v22-latin-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 600;
  font-display: swap; src: url('fonts/space-grotesk-v22-latin-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk'; font-style: normal; font-weight: 700;
  font-display: swap; src: url('fonts/space-grotesk-v22-latin-700.woff2') format('woff2');
}

:root {
  --paper:    #EEF1F5;
  --panel:    #FBFCFD;
  --ink:      #243142;
  --ink-soft: #5A6B7E;
  --player:   #2D6FE0;
  --mischief: #E8407A;
  --success:  #1FA37A;
  --conflict: #E2574C;
  --line:     #C9D2DD;
  --line-bold:#8FA0B3;

  /* Split out from --ink so dark mode can treat them separately: --text is
     readable body/label color, --grid is the heavy 3x3 dividers and board
     frame, --ink stays the dark "inverted surface" color (modals, pills,
     primary button). In light mode all three share the original ink value, so
     nothing changes. --glow is the soft top wash on the page background. */
  --text:     #243142;
  --grid:     #243142;
  --glow:     #F6F8FB;

  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --ui: 'Space Grotesk', system-ui, sans-serif;

  --r: 14px;
  --shadow: 0 1px 0 rgba(36,49,66,.04), 0 8px 24px -12px rgba(36,49,66,.25);
  --pink: #F2A9C8;
  --heat: 0;
}

/* ---------------------------------------------------------------------------
   Nighttime mode. The palette is a second set of variable values; every
   component already reads from the tokens, so this is a repaint, not a
   relayout. Behavior:
     - Auto (no data-theme attribute): follow the device via the media query.
     - Forced Day  (data-theme="light"): light values win, even on a dark device.
     - Forced Night(data-theme="dark"): dark values, even on a light device.
   Devices with no dark-mode concept never match the media query, so they stay
   in Day unless the user forces Night. The dark block is duplicated (once
   media-scoped for Auto, once attribute-scoped for forced Night) because a
   media query can't be combined into a plain selector.
--------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper:    #14181F;
    --panel:    #1E242D;
    --ink:      #2C3744;
    --ink-soft: #95A2B1;
    --player:   #5C9CFF;
    --mischief: #FF5C97;
    --success:  #35C99A;
    --conflict: #FF6F63;
    --line:     #2E3742;
    --line-bold:#566373;
    --text:     #E7ECF2;
    --grid:     #5E6B7B;
    --glow:     #232C37;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -12px rgba(0,0,0,.7);
    --pink: #7E3354;
  }
}
:root[data-theme="dark"] {
  --paper:    #14181F;
  --panel:    #1E242D;
  --ink:      #2C3744;
  --ink-soft: #95A2B1;
  --player:   #5C9CFF;
  --mischief: #FF5C97;
  --success:  #35C99A;
  --conflict: #FF6F63;
  --line:     #2E3742;
  --line-bold:#566373;
  --text:     #E7ECF2;
  --grid:     #5E6B7B;
  --glow:     #232C37;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -12px rgba(0,0,0,.7);
  --pink: #7E3354;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  /* Tinted base fills the entire viewport at any size, with a pink glow layered
     over the top. Previously a single radial gradient faded to flat paper, which
     left a large dull zone below the content on tall screens like an iPad. */
  background-color: color-mix(in srgb, var(--paper), var(--pink) calc(var(--heat) * 48%));
  background-image:
    radial-gradient(125% 80% at 50% -12%,
      color-mix(in srgb, var(--glow), var(--pink) calc(var(--heat) * 72%)) 0%,
      transparent 60%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  transition: background-color .6s ease;
  color: var(--text);
  font-family: var(--ui);
  min-height: 100dvh;
}

body.cruel .topbar h1::after { opacity: 1; transform: rotate(-8deg) translateY(-2px); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  max-width: 960px; margin: 0 auto; padding: 30px 22px 10px;
}
.brand h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(30px, 6vw, 46px); line-height: .95; letter-spacing: -.02em;
  margin: 0; position: relative; display: inline-block;
}
/* the only mischief in the header: a tiny crooked accent that wakes up in cruel mode */
.topbar h1::after {
  content: ""; position: absolute; right: -14px; top: 2px;
  width: 9px; height: 9px; border-radius: 2px; background: var(--mischief);
  opacity: .35; transform: rotate(12deg); transition: .4s;
}
.tagline { margin: 6px 0 0; color: var(--ink-soft); font-size: 14px; }

.newgame { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.sel { display: flex; flex-direction: column; gap: 4px; }
.sel > span {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-soft); padding-left: 2px;
}
select, button { font-family: var(--ui); }
.sel select {
  appearance: none; -webkit-appearance: none;
  border: 1.5px solid var(--line); background-color: var(--panel);
  color: var(--text); padding: 10px 32px 10px 14px; border-radius: 10px; font-size: 16px; /* >=16px: iOS won't focus-zoom */
  font-weight: 600; cursor: pointer; min-width: 124px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235A6B7E' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; background-size: 10px;
}
.sel select:hover { border-color: var(--line-bold); }
.primary {
  border: none; background: var(--ink); color: #fff; font-weight: 600;
  padding: 11px 18px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: transform .08s, background .2s;
}
.primary:hover { background: color-mix(in srgb, var(--ink) 80%, #000); }
.primary:active { transform: translateY(1px); }

/* ---------- layout ---------- */
.layout {
  max-width: 960px; margin: 0 auto; padding: 14px 22px 60px;
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  grid-template-rows: auto auto;
  column-gap: 30px; row-gap: 0;
  align-items: start;
}
/* The pre-board header (objective, stats, decay bar) sits in column 1, row 1.
   The board and the controls share row 2, so the controls top-align to the
   board rather than to the top of the header. */
.board-head  { grid-column: 1; grid-row: 1; }
#board-stage { grid-column: 1; grid-row: 2; }
.controls    { grid-column: 2; grid-row: 2; align-self: start; }
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: none; gap: 12px; padding: 8px 14px 34px; }
  .board-head, #board-stage, .controls { grid-column: auto; grid-row: auto; }
  .topbar { padding: 16px 14px 4px; gap: 10px; }
  .tagline { display: none; }            /* reclaim a line */
  .brand h1 { font-size: 30px; }
  .newgame { gap: 8px; }
  .sel select { min-width: 0; }
  .stats { margin-bottom: 8px; }
  .campaign { padding: 10px 12px; margin-bottom: 10px; }
  .doom { margin-bottom: 8px; }
  /* Control band: a clean 50/50 split, the four action buttons as a 2x2 block on
     the left, the number pad as a 3x3 block on the right, both stretched to the
     same height so their tops and bottoms line up. */
  .controls { display: flex; flex-wrap: wrap; align-items: stretch; gap: 12px; }
  .replay-btn { order: -1; flex: 1 0 100%; margin-bottom: 0; }
  .actions {
    order: 0; flex: 1 1 0; margin-top: 0;
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 10px;
  }
  .action {
    flex-direction: column; gap: 5px; padding: 8px 6px;
    font-size: 13px; line-height: 1.1; border-radius: 14px; text-align: center;
  }
  .action .ico { font-size: 19px; }
  .pad {
    order: 1; flex: 1 1 0;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  }
  .pad-key {
    padding: 0; aspect-ratio: 1; font-size: 24px;
    display: flex; align-items: center; justify-content: center;
  }
  /* Scale the board to leave room for the band so nothing scrolls. The 360px is
     the board-vs-controls knob: smaller number = bigger board, more scroll risk. */
  .board-stage { width: min(100%, calc(100svh - 360px)); margin: 0 auto; }
  .drawer { width: 100%; max-width: 100%; }   /* full-screen settings on phone */
}

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 5; }

/* ---------- decay bar (Decay troll only) ---------- */
.doom {
  display: none; align-items: center; gap: 10px; margin-bottom: 12px;
}
.doom-cap {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--mischief); white-space: nowrap;
}
.doom-track {
  flex: 1; height: 5px; border-radius: 99px; background: var(--line); overflow: hidden;
}
.doom-fill { display: block; height: 100%; width: 100%; background: var(--mischief); transition: width .2s linear; }
.doom.flash .doom-track { box-shadow: 0 0 0 2px rgba(232,64,122,.35); }
.doom.flash .doom-fill { background: #ff2d7a; }

/* ---------- campaign bar ---------- */
.campaign {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
  box-shadow: 0 10px 30px -16px rgba(36,49,66,.4);
  position: relative; z-index: 2;
}
.camp-left { min-width: 0; flex: 1; }
.camp-row { display: flex; align-items: center; gap: 10px; }
.camp-count {
  font-family: var(--display); font-weight: 800; font-size: 14px; color: var(--text);
  white-space: nowrap;
}
.camp-dots { display: flex; gap: 5px; flex-wrap: wrap; }
.camp-dots .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); transition: background .2s; }
.camp-dots .dot.filled { background: var(--success); }
.camp-dots .dot.current { background: var(--player); box-shadow: 0 0 0 3px rgba(45,111,224,.2); }
.camp-objective { font-size: 13px; color: var(--ink-soft); margin-top: 6px; line-height: 1.4; }
.camp-objective strong { color: var(--text); font-weight: 600; }

/* live stats: timer + mistakes */
.stats { display: flex; gap: 16px; margin-bottom: 12px; }
.stat {
  font-family: var(--display); font-weight: 700; font-size: 14px; color: var(--ink-soft);
}
#stat-time { color: var(--text); }

/* demo walk-through banner */
.demo-bar {
  display: none; align-items: center; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--mischief) 14%, var(--panel)); border: 1.5px solid var(--mischief); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
}
.demo-bar.show { display: flex; }
.demo-text { flex: 1; min-width: 180px; font-size: 13px; color: var(--text); line-height: 1.4; }
.demo-text strong { color: var(--mischief); }

/* score breakdown on the win card */
.score-big {
  font-family: var(--display); font-weight: 800; font-size: 52px; line-height: 1;
  color: var(--text); margin-bottom: 14px;
}
.score-big span {
  display: block; font-family: var(--ui); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--success); margin-top: 4px;
}
.score-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.score-list li {
  display: flex; justify-content: space-between; font-size: 14px; color: var(--text);
  padding: 8px 0; border-top: 1px solid var(--line);
}
.score-list li span { color: var(--ink-soft); }

/* post-solve recap: what the trolls did */
.recap { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; text-align: left; }
.recap-head {
  font-family: var(--ui); font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--mischief); margin-bottom: 8px;
}
.recap-list { list-style: none; padding: 0; margin: 0; }
.recap-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; }
.rc-name { font-family: var(--ui); font-weight: 600; font-size: 14px; color: var(--text); }
.rc-detail { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.m-btn2 { display: none; }

/* first-run welcome color legend */
.welcome-legend { display: flex; justify-content: center; gap: 16px; margin: 18px 0; flex-wrap: wrap; }
.wl { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.wl-chip {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  background: var(--panel); border: 1.5px solid var(--line);
  font-family: var(--display); font-weight: 700; font-size: 21px;
}
.wl-chip.ink { color: var(--text); }
.wl-chip.you { color: var(--player); }
.wl-chip.troll { color: var(--mischief); border-color: color-mix(in srgb, var(--mischief) 40%, var(--line)); }

/* controls walk-through: a spotlight cut out of a dimming scrim, plus a bubble */
.coach { position: fixed; inset: 0; z-index: 96; }
.coach[hidden] { display: none; }
.coach-spot {
  position: absolute; border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(36, 49, 66, .55);
  transition: left .3s ease, top .3s ease, width .3s ease, height .3s ease;
  pointer-events: none;
}
.coach-bubble {
  position: absolute; background: var(--ink); color: #fff;
  padding: 15px 17px; border-radius: 16px; box-shadow: 0 16px 40px -12px rgba(36, 49, 66, .6);
  font-family: var(--ui);
}
.coach-text { margin: 0; font-size: 14px; line-height: 1.45; }
.coach-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.coach-skip { all: unset; cursor: pointer; font-family: var(--ui); font-weight: 600; font-size: 13px; color: #aab6c4; }
.coach-count { font-family: var(--ui); font-weight: 600; font-size: 12px; color: #aab6c4; }
.coach-next {
  all: unset; cursor: pointer; font-family: var(--ui); font-weight: 700; font-size: 14px;
  color: var(--ink); background: #fff; padding: 9px 18px; border-radius: 10px;
}
.about-link {
  all: unset; cursor: pointer; display: block; margin-top: 12px;
  font-family: var(--ui); font-size: 13px; font-weight: 600; color: var(--ink-soft);
  text-decoration: underline; text-underline-offset: 3px;
}
.about-link:hover { color: var(--text); }
.about-body p { margin: 0 0 12px; line-height: 1.5; }
.about-body p:last-child { margin-bottom: 0; }
.about-credit { color: var(--ink-soft); font-size: 13px; }

/* Daily share card (rendered in the result modal) */
.daily-btn { border-color: color-mix(in srgb, var(--player) 45%, var(--line)); }
.daily-streak {
  font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--text);
  margin-bottom: 10px;
}
.daily-next { margin-top: 10px; font-size: 13px; color: var(--ink-soft); }

.share-card {
  margin: 4px 0 0; padding: 16px 18px; border-radius: 12px;
  background: var(--paper); border: 1.5px solid var(--line);
  font-family: var(--ui); font-size: 15px; line-height: 1.7; color: var(--text);
  white-space: pre-wrap; word-break: break-word; text-align: left;
}

.ghost {
  all: unset; cursor: pointer; white-space: nowrap; font-size: 13px; font-weight: 600;
  color: var(--text); border: 1.5px solid var(--line); border-radius: 9px; padding: 9px 13px;
}
.ghost:hover { border-color: var(--line-bold); }
.ghost.small { font-size: 12px; padding: 7px 11px; color: var(--ink-soft); }

/* ---------- teaching / result card ---------- */
.card-introduces { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
.camp-score {
  font-family: var(--display); font-weight: 700; font-size: 14px; color: var(--success);
  margin: 0 0 12px;
}
.card-introduces strong { color: var(--text); }
.card-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.card-list li {
  font-size: 13px; color: var(--text); line-height: 1.4; padding: 9px 0;
  border-top: 1px solid var(--line);
}
.card-list li span {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--mischief); font-weight: 600; margin-bottom: 3px;
}
.card-cruel {
  margin-top: 12px; padding: 9px 11px; border-radius: 8px;
  background: color-mix(in srgb, var(--mischief) 14%, var(--panel)); color: var(--mischief); font-size: 12px; font-weight: 600; text-align: left;
}

/* graduation badge: a tile echoing the app icon, stamped in on the card */
.grad-badge { display: flex; justify-content: center; margin: 2px 0 16px; }
.gb-tile {
  display: grid; place-items: center; width: 76px; height: 76px; border-radius: 18px;
  background: var(--ink); color: #fff; font-family: var(--display); font-weight: 800; font-size: 38px;
  box-shadow: 0 0 0 3px var(--success), 0 10px 24px -10px rgba(36,49,66,.6);
  transform: scale(.4) rotate(-12deg); opacity: 0; animation: gbStamp .5s cubic-bezier(.2,1.4,.4,1) .08s forwards;
}
.grad-badge.cruel .gb-tile { background: var(--mischief); box-shadow: 0 0 0 3px var(--grid), 0 10px 24px -10px rgba(232,64,122,.6); }
@keyframes gbStamp {
  0% { transform: scale(.4) rotate(-12deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* hate / eh / love rating */
.rate-wrap { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.rate-q { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft);
  font-weight: 600; margin-bottom: 9px; }
.rate-row { display: flex; gap: 8px; }
.rate-btn {
  flex: 1; padding: 11px 4px; border-radius: 11px; border: 1.5px solid var(--line);
  background: var(--panel); color: var(--ink-soft); font-family: var(--ui); font-weight: 600;
  font-size: 13px; cursor: pointer; transition: border-color .15s, color .15s, background .15s, transform .1s;
}
.rate-btn:active { transform: scale(.96); }
.rate-btn.hate.on { border-color: var(--conflict); color: var(--conflict); background: color-mix(in srgb, var(--conflict) 14%, var(--panel)); }
.rate-btn.ehh.on  { border-color: var(--line-bold); color: var(--text); background: var(--paper); }
.rate-btn.love.on { border-color: var(--success); color: var(--success); background: color-mix(in srgb, var(--success) 14%, var(--panel)); }

/* badge tray */
.badge-sub { padding: 0 20px 14px; font-size: 13px; color: var(--ink-soft); line-height: 1.45; }
.badge-grid { display: flex; flex-direction: column; gap: 8px; padding: 0 20px 30px; }
.badge-card {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 13px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--panel); cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.badge-card.graduated:active { transform: scale(.99); }
.badge-card.locked { cursor: default; opacity: .6; }
.badge-card.upnext { opacity: 1; border-color: var(--player); border-style: dashed; }
.bc-tile {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 11px;
  background: var(--ink); color: #fff; font-family: var(--display); font-weight: 800; font-size: 22px;
}
.bc-tile.cruel { background: var(--mischief); }
.bc-tile.lock { background: var(--line); color: var(--ink-soft); font-size: 17px; }
.bc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bc-name { font-family: var(--ui); font-weight: 600; font-size: 15px; color: var(--text); }
.bc-meta { font-size: 12px; color: var(--ink-soft); }
.bc-replay { flex: none; font-family: var(--ui); font-weight: 600; font-size: 12px; color: var(--mischief); }

/* ---------- console additions ---------- */
.console-note {
  display: none; margin: 0 20px 6px; padding: 10px 12px; border-radius: 9px;
  background: color-mix(in srgb, var(--player) 10%, var(--panel)); color: var(--ink-soft); font-size: 12px; line-height: 1.4;
}
.console-foot { padding: 14px 20px 24px; border-top: 1px solid var(--line); }
.trow.locked { opacity: .45; }
.trow.locked .tname::after {
  content: ' · locked'; color: var(--ink-soft); font-weight: 500; font-size: 11px;
}

/* ---------- board ---------- */
.board-stage { position: relative; width: 100%; aspect-ratio: 1; transition: transform .7s cubic-bezier(.7,0,.2,1); }
.board {
  display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1;
  width: 100%; background: var(--line-bold); gap: 1px;
  border: 2.5px solid var(--grid); border-radius: var(--r); overflow: hidden;
  box-shadow: var(--shadow); transition: transform .7s cubic-bezier(.7,0,.2,1);
  touch-action: none;
}
.cell {
  all: unset; cursor: pointer; background: var(--panel);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(18px, 4.4vw, 30px); font-weight: 600; color: var(--text);
  position: relative; aspect-ratio: 1; user-select: none;
  transition: background .12s, color .12s, opacity .35s;
}
/* Heavy 3x3 separators live on a dedicated ::after layer, NOT the cell's own
   box-shadow. That box-shadow is used by the troll animations (tell pulse,
   flicker, etc.) and the selection ring; keeping the separators separate means
   none of those can erase a block border (which Decay/Flicker used to do). */
.cell::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 1;
}
/* Selection/group ring rides its own layer ABOVE the separators (which sit at
   z-index 1), so a 3x3 block boundary can never paint over a focused cell's
   edge. Transparent except for the inset ring, so the number shows through. */
.cell::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
}
.cell.br::after    { box-shadow: inset -2px 0 0 var(--grid); }
.cell.bb::after    { box-shadow: inset 0 -2px 0 var(--grid); }
.cell.br.bb::after { box-shadow: inset -2px 0 0 var(--grid), inset 0 -2px 0 var(--grid); }

/* Round the four corner cells (and their ring layer) to match the board's
   inner radius, so the focus ring isn't truncated where the rounded board edge
   clips a square corner cell. */
.cell:first-child,    .cell:first-child::before    { border-top-left-radius: 12px; }
.cell:nth-child(9),   .cell:nth-child(9)::before   { border-top-right-radius: 12px; }
.cell:nth-child(73),  .cell:nth-child(73)::before  { border-bottom-left-radius: 12px; }
.cell:nth-child(81),  .cell:nth-child(81)::before  { border-bottom-right-radius: 12px; }

.cell.given  { color: var(--text); }
.cell.player { color: var(--player); }
.cell.peer   { background: color-mix(in srgb, var(--player) 8%, var(--panel)); }
.cell.match  { background: color-mix(in srgb, var(--player) 18%, var(--panel)); }
.cell.selected { background: color-mix(in srgb, var(--player) 26%, var(--panel)); }
.cell.selected::before { box-shadow: inset 0 0 0 2px var(--player); }
.cell.grouped { background: color-mix(in srgb, var(--player) 14%, var(--panel)); }
.cell.grouped::before { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--player) 65%, transparent); }
.cell.conflict { color: var(--conflict); }

/* Round the four corner cells to match the board's radius so a selection ring
   (or any highlight) curves into the corner instead of being clipped flat. */
.cell:first-child   { border-top-left-radius: 12px; }
.cell:nth-child(9)  { border-top-right-radius: 12px; }
.cell:nth-child(73) { border-bottom-left-radius: 12px; }
.cell:last-child    { border-bottom-right-radius: 12px; }

.cell.faded { opacity: var(--fade, .18); transition: opacity .35s ease; }
.cell.faded:hover, .cell.faded.peeking { opacity: 1; }

/* notes */
.notes {
  display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr);
  width: 100%; height: 100%; padding: 3px;
}
.notes span {
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(7px, 1.5vw, 11px); color: var(--ink-soft); font-weight: 500;
}
.notes .nmatch { color: var(--player); font-weight: 700; }
.notes .struck { color: var(--ink-soft); opacity: .5; text-decoration: line-through; }

/* ---- troll feedback states: the ONLY places magenta appears ---- */
@keyframes flickerPulse {
  0%,100% { box-shadow: inset 0 0 0 0 var(--mischief); }
  50%     { box-shadow: inset 0 0 0 3px var(--mischief); color: var(--mischief); }
}
.cell.flicker { animation: flickerPulse .22s steps(2) 3; }
@keyframes tellPulse {
  0% { box-shadow: inset 0 0 0 3px var(--mischief); }
  100% { box-shadow: inset 0 0 0 0 rgba(232,64,122,0); }
}
.cell.tell { animation: tellPulse .9s ease-out; background: color-mix(in srgb, var(--mischief) 16%, var(--panel)); }
@keyframes dropIn {
  0% { transform: translateY(-160%) scale(1.15); opacity: 0; }
  55% { transform: translateY(14%) scale(1.05); opacity: 1; }
  75% { transform: translateY(-7%) scale(1); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.cell.drop { animation: dropIn .7s cubic-bezier(.34,1.3,.5,1); }
@keyframes hintPulse {
  0%,100% { box-shadow: inset 0 0 0 0 var(--player); }
  50% { box-shadow: inset 0 0 0 3px var(--player); }
}
.cell.hinted { animation: hintPulse .5s ease-in-out 3; }
/* a cell the autofill just dropped in, one at a time. Kept within the cell
   bounds (a tint+fade, no scaling past the edges) so it never covers borders. */
@keyframes autofillPop {
  0% { opacity: 0; background: color-mix(in srgb, var(--player) 30%, var(--panel)); }
  45% { opacity: 1; background: color-mix(in srgb, var(--player) 18%, var(--panel)); }
  100% { background: var(--panel); }
}
.cell.autofill { animation: autofillPop .34s ease-out; }
@keyframes lieHint {
  0%,100% { box-shadow: inset 0 0 0 0 var(--mischief); }
  50% { box-shadow: inset 0 0 0 3px var(--mischief); }
}
.cell.hinted-lie { animation: lieHint .5s ease-in-out 3; }

/* a finished block scrunching as it disappears */
@keyframes puff {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(.92); }
}
.cell.puff { animation: puff .42s ease-out; }

/* a column shimmering just before it lets go */
@keyframes release {
  0%,100% { box-shadow: inset 0 0 0 0 rgba(232,64,122,0); }
  50% { box-shadow: inset 0 0 0 2px var(--mischief); background: color-mix(in srgb, var(--mischief) 16%, var(--panel)); }
}
.cell.release { animation: release .32s ease-in-out; }

/* the board winding up before a spin (the tell) */
@keyframes winding {
  0% { transform: rotate(0deg) scale(1); }
  40% { transform: rotate(-4deg) scale(.97); }
  100% { transform: rotate(2deg) scale(.98); }
}
.board-stage.winding { animation: winding .26s ease-in-out; }

/* Block tilt now rotates the real cells of a block as a rigid group (each cell
   shares the block's center as its pivot), exactly like board-spin rotates the
   whole stage. That keeps the cells real and clickable. While tilting, a cell
   lifts above its neighbors and drops its heavy 3x3 separator so the rotating
   edges stay clean; the thin grid lines rotate with it. */
.cell.tilting {
  transition: transform .5s cubic-bezier(.7, 0, .2, 1);
  z-index: 4;
}
/* While tilted, a cell drops the board's inter-block separators (which would
   smear as it turns) and instead draws a clean heavy edge only where it sits on
   the block's outer boundary. The nine cells together frame the block, and the
   frame rotates rigidly with them. */
.cell.tilting::after { box-shadow: var(--tilt-frame, none); }

/* earthquake: a short, sharp shake that changes nothing */
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  10% { transform: translate(-3px,2px) rotate(-.6deg); }
  25% { transform: translate(4px,-2px) rotate(.5deg); }
  40% { transform: translate(-4px,1px) rotate(-.4deg); }
  55% { transform: translate(3px,2px) rotate(.5deg); }
  70% { transform: translate(-2px,-2px) rotate(-.3deg); }
  85% { transform: translate(2px,1px) rotate(.2deg); }
}
.board-stage.quaking { animation: quake .62s ease-in-out; }

/* ---------- fx overlay: cue chips and ping rings ---------- */
.fx-cue {
  position: absolute; transform: translate(-50%, -50%);
  background: var(--mischief); color: #fff; font-family: var(--ui); font-weight: 700;
  font-size: 12px; padding: 3px 9px; border-radius: 99px; white-space: nowrap;
  box-shadow: 0 5px 14px -5px rgba(232,64,122,.7);
  animation: cueRise .95s ease-out forwards;
}
@keyframes cueRise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.8); }
  18% { opacity: 1; transform: translate(-50%, -65%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -165%) scale(1); }
}
.fx-ping {
  position: absolute; transform: translate(-50%, -50%); border-radius: 9px;
  border: 2.5px solid var(--mischief); animation: pingExpand .7s ease-out forwards;
}
@keyframes pingExpand {
  0% { opacity: .85; transform: translate(-50%, -50%) scale(.65); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.9); }
}
/* a number physically falling (Gravity well) */
.fx-fall {
  position: absolute; display: flex; align-items: center; justify-content: center;
  color: var(--mischief); font-family: var(--ui); font-weight: 800;
  text-shadow: 0 3px 10px rgba(232,64,122,.55); z-index: 6;
  transition: transform .95s cubic-bezier(.5, 0, .85, .6); /* longer, heavier fall */
}
/* faint vertical streak behind the falling digit so the eye catches the column */
.fx-fall::before {
  content: ''; position: absolute; left: 50%; bottom: 45%;
  width: 3px; height: 240%; transform: translateX(-50%);
  background: linear-gradient(to top, color-mix(in srgb, var(--mischief) 55%, transparent), transparent);
  border-radius: 3px; pointer-events: none;
}

/* monte swap traveler: a digit visibly sliding from one cell to another */
.fx-slide {
  position: absolute; display: flex; align-items: center; justify-content: center;
  color: var(--mischief); font-family: var(--ui); font-weight: 800;
  text-shadow: 0 3px 10px rgba(232,64,122,.55); z-index: 6;
  transition-property: transform;
  transition-timing-function: cubic-bezier(.5, .05, .3, 1);
}
/* the cell's own digit is blanked while its traveler is in flight */
.cell.sliding { color: transparent !important; }
.cell.sliding .marks { visibility: hidden; }

.fx-eject {
  position: absolute; display: flex; align-items: center; justify-content: center;
  color: var(--mischief); font-family: var(--ui); font-weight: 700;
  text-shadow: 0 3px 10px rgba(232,64,122,.55); z-index: 7; pointer-events: none;
  transition: transform .56s cubic-bezier(.4, -0.5, .5, 1), opacity .56s ease-out;
}

/* ---------- controls ---------- */
.pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.pad-key {
  all: unset; cursor: pointer; text-align: center;
  font-family: var(--display); font-weight: 600; font-size: 26px; color: var(--text);
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 14px 0; transition: transform .07s, background .15s, border-color .15s;
}
.pad-key:hover { border-color: var(--line-bold); }
.pad-key:active { transform: translateY(1px); }
.pad-key.armed { background: var(--player); color: #fff; border-color: var(--player); }
.pad-key.done { opacity: .32; }
.pad-key.invalid { opacity: .26; cursor: default; }

.actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;
}

/* Replay ("what just happened") — a contextual button above the pad, plus the
   caption banner and the focus highlight used during a re-enactment. */
.replay-btn {
  all: unset; box-sizing: border-box; cursor: pointer; display: block; width: 100%;
  text-align: center; font-family: var(--ui); font-weight: 600; font-size: 14px;
  color: var(--mischief); background: color-mix(in srgb, var(--mischief) 9%, var(--panel));
  border: 1.5px solid color-mix(in srgb, var(--mischief) 35%, var(--line));
  border-radius: 12px; padding: 11px 0; margin-bottom: 10px;
  transition: background .15s, opacity .15s;
}
.replay-btn:hover { background: color-mix(in srgb, var(--mischief) 16%, var(--panel)); }
.replay-btn:disabled { cursor: default; color: var(--ink-soft); background: var(--panel);
  border-color: var(--line); opacity: .7; }
.replay-banner { display: none; }
.replay-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
  background: var(--ink); color: #fff; padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px -12px rgba(36,49,66,.5);
  transform: translateY(110%); transition: transform .3s cubic-bezier(.5,0,.2,1);
  max-width: 520px; margin: 0 auto;
}
.replay-sheet.show { transform: translateY(0); }
.rs-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.rs-tag { font-family: var(--ui); font-weight: 700; font-size: 13px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--pink); }
.rs-close { all: unset; cursor: pointer; font-family: var(--ui); font-weight: 600; font-size: 14px;
  color: #fff; background: rgba(255,255,255,.14); padding: 7px 16px; border-radius: 9px; }
.rs-caption { font-family: var(--ui); font-size: 16px; line-height: 1.45; min-height: 3em; }
.rs-controls { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.rs-nav { all: unset; cursor: pointer; font-family: var(--ui); font-weight: 600; font-size: 14px;
  color: #fff; background: rgba(255,255,255,.12); padding: 9px 16px; border-radius: 10px; }
.rs-nav:disabled { opacity: .35; cursor: default; }
.rs-count { font-family: var(--ui); font-weight: 600; font-size: 14px; color: #aab6c4; }
.cell.replay-focus {
  animation: replayFocus 1.3s ease-in-out infinite;
  z-index: 3;
}
/* spotlight while a replay step is open: mute the rest of the board so the
   affected cells read clearly and the board isn't a free scratchpad to study */
#board.replay-dim .cell { opacity: .3; filter: grayscale(.5); transition: opacity .2s ease, filter .2s ease; }
#board.replay-dim .cell.replay-focus { opacity: 1; filter: none; }
@keyframes replayFocus {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--mischief); }
  50% { box-shadow: inset 0 0 0 3px var(--mischief), 0 0 0 3px color-mix(in srgb, var(--mischief) 30%, transparent); }
}
.fx-rchip {
  position: absolute; transform: translate(-50%, -150%);
  background: var(--mischief); color: #fff; font-family: var(--ui); font-weight: 700;
  font-size: 15px; padding: 5px 10px; border-radius: 9px; white-space: nowrap;
  box-shadow: 0 8px 20px -8px rgba(232,64,122,.6); z-index: 8; pointer-events: none;
}
.action {
  all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px;
  justify-content: center; font-size: 14px; font-weight: 500; color: var(--text);
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 10px; transition: background .15s, border-color .15s;
}
.action:hover { border-color: var(--line-bold); }
.action .ico { font-size: 15px; color: var(--ink-soft); }
.action.on { background: var(--player); color: #fff; border-color: var(--player); }
.action.on .ico { color: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.mischief { background: var(--mischief); }

/* ---------- settings drawers (opened from header buttons) ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 340px; max-width: 88vw;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 70;
  transform: translateX(105%); transition: transform .35s cubic-bezier(.5,0,.2,1);
  display: flex; flex-direction: column; box-shadow: -20px 0 50px -30px rgba(36,49,66,.5);
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 12px;
}
.drawer-head h2 { font-family: var(--display); font-weight: 800; font-size: 24px; margin: 0; }
.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--line); border-radius: 11px;
}
.seg-btn {
  all: unset; cursor: pointer; padding: 8px 16px; border-radius: 8px;
  font-family: var(--ui); font-weight: 700; font-size: 15px; color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.seg-btn.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* gameplay settings rows */
.setrows { padding: 4px 20px 24px; }
.setrow {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.setrow:first-child { border-top: none; }
.setrow-main { font-size: 14px; font-weight: 600; color: var(--text); }
.setrow-main em { display: block; font-style: normal; font-weight: 400; font-size: 12px; color: var(--ink-soft); margin-top: 3px; line-height: 1.35; }
.switch {
  flex: 0 0 auto; width: 44px; height: 26px; border-radius: 99px; border: none;
  background: var(--line-bold); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch.on { background: var(--player); }
.switch.on::after { transform: translateX(18px); }

/* three-way appearance control (Auto / Day / Night) */
.setrow-stack { flex-direction: column; align-items: stretch; gap: 11px; cursor: default; }
.theme-seg {
  display: flex; gap: 4px; padding: 3px;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px;
}
.theme-btn {
  all: unset; flex: 1; text-align: center; padding: 9px 0; border-radius: 9px;
  font-family: var(--ui); font-weight: 600; font-size: 13px; color: var(--ink-soft);
  cursor: pointer; transition: background .15s, color .15s;
}
.theme-btn.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.setnote {
  margin-top: 14px; padding: 12px; border-radius: 9px; background: var(--paper);
  font-size: 12px; color: var(--ink-soft); line-height: 1.45;
}
.x { all: unset; cursor: pointer; color: var(--ink-soft); font-size: 18px; padding: 4px 8px; }

/* master dial */
.dial { padding: 6px 20px 16px; border-bottom: 1px solid var(--line); }
.dial-readout { display: flex; align-items: baseline; gap: 10px; }
.dial-readout span {
  font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1;
}
.dial-readout em { font-style: normal; font-weight: 600; color: var(--mischief); font-size: 15px; }
.dial-scale { display: flex; justify-content: space-between; color: var(--ink-soft); font-size: 11px; margin-top: 4px; text-transform: uppercase; letter-spacing: .08em; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: linear-gradient(90deg, var(--player), var(--mischief));
  border-radius: 99px; margin: 10px 0 2px; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--ink); box-shadow: var(--shadow); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  border: 2.5px solid var(--ink); cursor: pointer;
}
input[type=range]:disabled { opacity: .4; filter: grayscale(.6); }

.unlock {
  display: flex; gap: 10px; align-items: flex-start; padding: 14px 20px;
  font-size: 13px; color: var(--text); border-bottom: 1px solid var(--line); cursor: pointer;
}
.unlock em { color: var(--mischief); font-style: normal; }
.unlock input { margin-top: 2px; accent-color: var(--mischief); }

/* troll rows */
.troll-list { overflow-y: auto; padding: 8px 20px 30px; flex: 1; }
.tgroup { margin-top: 16px; }
.tgroup-cap {
  display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft); margin-bottom: 8px;
}
.tgroup-cap .dot { width: 9px; height: 9px; border-radius: 50%; }
.t-low  .dot { background: var(--success); }
.t-mid  .dot { background: #E8A23E; }
.t-high .dot { background: var(--mischief); }

.trow { padding: 11px 0; border-top: 1px solid var(--line); }
.trow-head { display: flex; align-items: center; justify-content: space-between; }
.tname { font-weight: 600; font-size: 14px; }
.auto-btn {
  all: unset; cursor: pointer; font-size: 11px; font-weight: 600; padding: 4px 10px;
  border-radius: 99px; border: 1.5px solid var(--line); color: var(--ink-soft);
}
.auto-btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tblurb { font-size: 12px; color: var(--ink-soft); margin: 4px 0 8px; line-height: 1.35; }
.tbar { height: 5px; background: var(--line); border-radius: 99px; overflow: hidden; }
.tbar-fill { display: block; height: 100%; width: 0; background: var(--line-bold); transition: width .2s; }
.tbar-fill.live { background: linear-gradient(90deg, var(--player), var(--mischief)); }
.tslider { margin-top: 8px; }
.t-high .tslider { background: linear-gradient(90deg, #f0a, var(--mischief)); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(36,49,66,.4); z-index: 90; padding: 20px;
}
.modal.show { display: flex; }
.modal-card {
  background: var(--panel); border-radius: 18px; padding: 30px 28px; max-width: 360px;
  width: 100%; text-align: center; box-shadow: var(--shadow);
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.m-title { font-family: var(--display); font-weight: 800; font-size: 30px; margin: 0 0 8px; }
.m-body { color: var(--ink-soft); margin: 0 0 20px; line-height: 1.45; font-size: 15px; }
.m-body p { margin: 0 0 10px; }
.modal.celebrate .m-title { color: var(--success); }
.modal.celebrate .modal-card { box-shadow: 0 0 0 3px var(--success), var(--shadow); }
.m-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 4px; }
.m-btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .05ms !important; }
}
