:root {
  color-scheme: light dark;
  --bg: #eef2ec;
  --bg-2: #e0e8df;
  --panel: rgba(252, 253, 249, 0.8);
  --panel-solid: #fbfcf8;
  --ink: #1d2530;
  --muted: #66707a;
  --line: rgba(29, 37, 48, 0.12);
  --accent: #12a383;
  --accent-deep: #0b7a62;
  --accent-ink: #ffffff;
  --jade: #0f8a70;
  --gold: #e9a91c;
  --gold-dim: rgba(29, 37, 48, 0.15);
  --bad: #d23c45;
  --bad-soft: rgba(210, 60, 69, 0.22);
  --dim: rgba(238, 242, 236, 0.64);
  --display: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display-weight: 800; /* the weight hub/game.css gives display text */
  --text: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* the map */
  --c0: #f6c9c3;
  --c1: #f9dfae;
  --c2: #e6e9a2;
  --c3: #bfe3c0;
  --c4: #b4e0e6;
  --c5: #c4d2f4;
  --c6: #dcc7ef;
  --c7: #e9d5c2;
  --grid: rgba(29, 37, 48, 0.18);
  --edge: #1d2530;
  --tile: #1f2735;
  --tile-hi: #3a465a;
  --pip: #f6f0e2;
  --x: rgba(29, 37, 48, 0.6);
  --x-auto: rgba(29, 37, 48, 0.28);
  --shadow: rgba(30, 50, 40, 0.22);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161a;
    --bg-2: #182025;
    --panel: rgba(32, 41, 47, 0.75);
    --panel-solid: #1f282e;
    --ink: #eef3ef;
    --muted: #9aa7a8;
    --line: rgba(230, 245, 238, 0.11);
    --accent: #2cc79f;
    --accent-deep: #13906f;
    --accent-ink: #062018;
    --jade: #4fd8b0;
    --gold: #f6c945;
    --gold-dim: rgba(230, 245, 238, 0.17);
    --bad: #ff5d68;
    --bad-soft: rgba(255, 93, 104, 0.28);
    --dim: rgba(17, 22, 26, 0.62);
    --c0: #7a4741;
    --c1: #7a5f32;
    --c2: #64672e;
    --c3: #3f6b48;
    --c4: #2f6670;
    --c5: #3f5283;
    --c6: #5f4a80;
    --c7: #6d5a48;
    --grid: rgba(5, 8, 10, 0.4);
    --edge: #070a0c;
    --tile: #f1e9d6;
    --tile-hi: #ffffff;
    --pip: #1b2029;
    --x: rgba(255, 255, 255, 0.78);
    --x-auto: rgba(255, 255, 255, 0.36);
    --shadow: rgba(0, 0, 0, 0.5);
  }
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(110% 55% at 50% -12%, rgba(255, 255, 255, 0.8), transparent 62%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
}
@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(70% 40% at 18% -8%, rgba(44, 199, 159, 0.14), transparent 70%),
      radial-gradient(60% 34% at 88% -10%, rgba(241, 233, 214, 0.08), transparent 70%),
      linear-gradient(180deg, var(--bg), var(--bg-2));
    background-attachment: fixed;
  }
}
.app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------------------------------------------------------------- header */
.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 2.1rem;
  line-height: 1;
  letter-spacing: -0.01em;
}
.logo span { color: var(--jade); }
.day { margin: 4px 0 0; font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }

/* ---------------------------------------------------------------- HUD */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; }
.hud-day { display: flex; flex-direction: column; line-height: 1.15; }
.hud-day b { font-family: var(--display); font-weight: 800; font-size: 1.2rem; }
.hud-day span { font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.counts { display: flex; align-items: center; gap: 16px; }
.count { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.count b { font-family: var(--display); font-weight: 600; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.count small { font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-top: 3px; }
#timer { min-width: 3.1em; text-align: right; transition: color 0.4s ease; }
#timer.over { color: var(--muted); }

/* ---------------------------------------------------------------- board */
.stage { position: relative; display: flex; justify-content: center; }
.board {
  --size: 340px;
  position: relative;
  width: var(--size);
  height: var(--size);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  border-radius: 14px;
  transition: filter 0.35s ease, opacity 0.35s ease;
}
.board:focus-visible { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--jade); }
.map { width: 100%; height: 100%; overflow: visible; }
.board > .map { position: absolute; inset: 0; filter: drop-shadow(0 10px 22px var(--shadow)); }
.map .rf { transition: filter 0.6s ease; }
.rf.c0 { fill: var(--c0); } .rf.c1 { fill: var(--c1); } .rf.c2 { fill: var(--c2); } .rf.c3 { fill: var(--c3); }
.rf.c4 { fill: var(--c4); } .rf.c5 { fill: var(--c5); } .rf.c6 { fill: var(--c6); } .rf.c7 { fill: var(--c7); }
.map .gl { fill: none; stroke: var(--grid); stroke-width: 1.6; }
.map .edge { fill: none; stroke: var(--edge); stroke-width: 7; stroke-linecap: round; }
.map .frame { fill: none; stroke: var(--edge); stroke-width: 9; }
.cells {
  position: absolute;
  inset: var(--inset, 1.5%);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  cursor: pointer;
}
.row { display: contents; }
.cell { position: relative; display: grid; place-items: center; }
.cell::before { content: ''; position: absolute; inset: 7%; border-radius: 22%; pointer-events: none; z-index: 2; }

/* a tile: a rounded square that stretches to meet its partner, so a pair reads as one domino */
.cell .tl {
  --m: 10%;
  position: absolute;
  top: var(--m); right: var(--m); bottom: var(--m); left: var(--m);
  display: none;
  place-items: center;
  border-radius: 20%;
  background: linear-gradient(160deg, var(--tile-hi), var(--tile) 55%);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  z-index: 1;
}
.cell.t .tl { display: grid; animation: tilein 0.22s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes tilein { from { transform: scale(0.55); opacity: 0; } }
.cell.t.jr .tl { right: -2px; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.cell.t.jl .tl { left: -2px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cell.t.jd .tl { bottom: -2px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.cell.t.ju .tl { top: -2px; border-top-left-radius: 0; border-top-right-radius: 0; }
.cell.t.jr .tl, .cell.t.jd .tl { animation: none; }
.pip {
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pip);
  transform: scale(0);
  transition: transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.cell.t.pr .pip { transform: scale(1); }
/* the divider line down the middle of a domino */
.cell.t.pr.jr .tl::after, .cell.t.pr.jd .tl::after {
  content: '';
  position: absolute;
  background: var(--pip);
  opacity: 0.35;
  border-radius: 2px;
}
.cell.t.pr.jr .tl::after { right: 0; top: 22%; bottom: 22%; width: 2px; }
.cell.t.pr.jd .tl::after { bottom: 0; left: 22%; right: 22%; height: 2px; }

.cell .xm { display: none; grid-area: 1 / 1; }
.xm { position: relative; width: 30%; aspect-ratio: 1; color: var(--x); }
.xm::before, .xm::after {
  content: '';
  position: absolute;
  left: -14%; top: 42%;
  width: 128%; height: 16%;
  border-radius: 99px;
  background: currentColor;
  transform: rotate(45deg);
}
.xm::after { transform: rotate(-45deg); }
.cell.x .xm { display: block; animation: xin 0.16s cubic-bezier(0.2, 1.6, 0.4, 1); }
.cell.ax .xm { display: block; width: 20%; color: var(--x-auto); animation: axin 0.3s ease both; }
@keyframes xin { from { transform: scale(0.3); opacity: 0; } }
@keyframes axin { from { transform: scale(0); opacity: 0; } }

/* rule breaks, dead regions, hints, keyboard cursor */
.cell.dead::before { background: repeating-linear-gradient(45deg, var(--bad-soft) 0 3px, transparent 3px 8px); z-index: 0; }
.board.spot .cell:not(.hl):not(.tgt)::before { inset: 0; border-radius: 0; background: var(--dim); box-shadow: none; animation: dimin 0.35s ease both; }
@keyframes dimin { from { opacity: 0; } }
.cell.tgt::before { box-shadow: inset 0 0 0 3px var(--jade); animation: ring 0.9s ease-in-out 3; }
@keyframes ring { 50% { box-shadow: inset 0 0 0 5px var(--jade); } }
.cell.bad .tl { background: var(--bad); animation: shake 0.45s ease both; }
.cell.bad::before { box-shadow: 0 0 14px var(--bad); animation: glow 1.1s ease-in-out infinite alternate; z-index: 0; }
@keyframes glow { from { opacity: 0.4; } to { opacity: 1; } }
@keyframes shake { 20% { transform: translateX(-6%); } 45% { transform: translateX(5%); } 70% { transform: translateX(-3%); } }
.board.kbd .cell.cur { outline: 3px solid var(--jade); outline-offset: -3px; border-radius: 6px; z-index: 3; }
/* the win */
.board.won .cells { cursor: default; }
.board.won .rf { filter: saturate(1.25) brightness(1.04); }
.board.won .cell.t .tl { animation: tilewin 0.6s cubic-bezier(0.2, 1.5, 0.35, 1) var(--w, 0ms) both; }
.board.won .cell.t .pip { background: var(--gold); box-shadow: 0 0 8px var(--gold); transition-delay: var(--w, 0ms); }
@keyframes tilewin { 0% { transform: none; } 40% { transform: translateY(-12%); } 100% { transform: none; } }
.board.shine::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 240, 0.6) 50%, transparent 65%) no-repeat;
  background-size: 300% 100%;
  animation: sheen 1.4s ease-in-out 0.25s both;
  mix-blend-mode: soft-light;
}
@keyframes sheen { from { background-position: 120% 0; } to { background-position: -20% 0; } }
.fx { position: absolute; inset: var(--inset, 1.5%); pointer-events: none; z-index: 4; }
.spark {
  position: absolute;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: spark 0.9s ease-out both;
}
.spark:nth-child(2n) { background: var(--gold); }
@keyframes spark {
  from { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  60% { opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1); opacity: 0; }
}

/* the curtain over an unstarted or paused board */
.stage.veiled .board { filter: blur(12px) saturate(0.6); opacity: 0.55; pointer-events: none; }
.curtain {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(88%, 330px);
  padding: 20px 20px 22px;
  border-radius: 22px;
  text-align: center;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px var(--shadow);
  animation: rise 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  z-index: 5;
}
.curtain[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, calc(-50% + 16px)) scale(0.96); } }
.cu-kicker { margin: 0; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--jade); }
.cu-title { margin: 4px 0 6px; font-family: var(--display); font-weight: 800; font-size: 2rem; line-height: 1.05; }
.cu-line { margin: 0 0 16px; font-weight: 600; color: var(--muted); line-height: 1.4; font-size: 0.95rem; }
.curtain .btn { min-width: 150px; }

/* ---------------------------------------------------------------- hints + buttons */
.hintbar {
  margin: 0;
  min-height: 2.9em;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--muted);
  border-radius: 14px;
  text-wrap: balance;
  transition: background 0.25s ease, color 0.25s ease;
}
.hintbar.on { display: block; text-align: left; color: var(--ink); background: var(--panel); border: 1px solid var(--line); animation: hintin 0.3s ease; }
.hintbar b { color: var(--jade); }
@keyframes hintin { from { opacity: 0; transform: translateY(-4px); } }
.controls { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.btn { position: relative; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 44px; padding: 0; }
.badge {
  min-width: 20px; height: 20px;
  padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: 99px;
  background: var(--jade);
  color: var(--panel-solid);
  font-size: 0.72rem;
  font-weight: 800;
}
.badge[hidden] { display: none; }
.toggle .sw {
  position: relative;
  width: 30px; height: 18px;
  border-radius: 99px;
  background: var(--gold-dim);
  transition: background 0.2s ease;
}
.toggle .sw::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--panel-solid);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.toggle[aria-pressed='true'] .sw { background: var(--jade); }
.toggle[aria-pressed='true'] .sw::after { transform: translateX(12px); }

/* ---------------------------------------------------------------- dialogs */
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
.help-grid { display: grid; grid-template-columns: 128px 1fr; gap: 14px; align-items: center; }
.example .map { filter: drop-shadow(0 4px 10px var(--shadow)); }
.ex-t { fill: var(--tile); }
.ex-pip { fill: var(--pip); }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rules li { line-height: 1.4; font-size: 0.93rem; padding-left: 18px; position: relative; }
.rules li::before { content: ''; position: absolute; left: 0; top: 0.45em; width: 9px; height: 9px; border-radius: 3px; background: var(--tile); }
.how-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.how-list li { display: flex; gap: 12px; align-items: center; line-height: 1.4; font-size: 0.93rem; }
.mini {
  flex: none;
  width: 46px; height: 34px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  border-radius: 9px;
  background: var(--c4);
  box-shadow: inset 0 0 0 2px var(--edge);
  font-family: var(--display); font-weight: 800; font-size: 1.1rem; color: var(--ink);
}
.mini.drag { background: var(--c3); }
.mini.hint { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.mini .mt { width: 16px; height: 16px; border-radius: 4px; background: var(--tile); }
.mini .mt.wide { width: 30px; }
.rule-note { margin: 0 0 10px; line-height: 1.45; font-size: 0.92rem; }
.keys { margin: 4px 0 16px; font-size: 0.82rem; color: var(--muted); line-height: 1.9; }
/* results */
.kicker { color: var(--jade); }
.res-hero { display: flex; align-items: baseline; gap: 14px; margin: -2px 0 6px; }
.res-time { font-family: var(--display); font-weight: 800; font-size: 2.8rem; line-height: 1; font-variant-numeric: tabular-nums; }
.res-stars { display: flex; gap: 2px; font-size: 1.6rem; }
.res-stars span { color: var(--gold-dim); }
.res-stars span.on { color: var(--gold); animation: star 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
.res-line { margin: 0 0 4px; font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.res-actions .btn { flex: 1; }
.section-h { margin: 18px 0 10px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.wd.done i { border: 0; background: var(--gold-dim); color: var(--ink); }
.wd.clean i { border: 0; background: var(--accent); color: var(--accent-ink); }
.wd.today i { border-style: solid; border-color: var(--jade); color: var(--ink); }
.legend { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 10px 0 0; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.lg { width: 12px; height: 12px; border-radius: 4px; display: inline-block; margin-left: 8px; }
.lg.clean { background: var(--accent); }
.lg.done { background: var(--gold-dim); }
.countdown b { font-family: var(--display); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.progress-note { margin: 0 0 6px; font-weight: 700; }
.toast { z-index: 10; }
@media (max-width: 420px) {
  .logo { font-size: 1.8rem; }
  .icon-btn { width: 36px; height: 36px; border-radius: 11px; }
  .counts { gap: 12px; }
  .count b { font-size: 1.3rem; }
  .hud-day b { font-size: 1.05rem; }
  .controls { gap: 6px; }
  .controls .btn { padding: 0 12px; font-size: 0.9rem; gap: 5px; }
  .controls .btn.icon { width: 44px; padding: 0; }
  .controls .btn svg { width: 16px; height: 16px; }
  .toggle .sw { width: 26px; height: 16px; }
  .toggle .sw::after { width: 12px; height: 12px; }
  .toggle[aria-pressed='true'] .sw::after { transform: translateX(10px); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .help-grid { grid-template-columns: 104px 1fr; gap: 12px; }
  .hintbar { font-size: 0.84rem; }
}
@media (max-width: 380px) {
  .controls { gap: 5px; }
  .controls .btn { padding: 0 9px; gap: 4px; font-size: 0.86rem; }
  .controls .btn.icon { width: 42px; padding: 0; }
  .badge { min-width: 18px; height: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-delay: 0ms !important; }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-delay: 0ms !important; }

/* Landscape phones and other short screens: the board fills the left at full height, and the
   header, status, hint and controls stack on the right. layout() in game.js sizes the board from
   the height alone here. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    max-width: 960px; display: grid; column-gap: 20px; row-gap: 8px; align-content: start;
    grid-template-columns: minmax(0, calc(100vh - 24px)) minmax(240px, 1fr);
    grid-template-rows: repeat(5, auto) 1fr;
    grid-template-areas: "stage top" "stage banner" "stage hud" "stage hint" "stage controls" "stage .";
  }
  .app > .top { grid-area: top; }
  .app > .banner { grid-area: banner; }
  .app > .hud { grid-area: hud; }
  .app > .stage { grid-area: stage; align-self: start; }
  .app > .hintbar { grid-area: hint; }
  .app > .controls { grid-area: controls; }
}
