@font-face { font-family: "Space Grotesk"; src: url(fonts/space-grotesk-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url(fonts/space-grotesk-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url(fonts/space-grotesk-700.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* one pair: emerald field, tangerine marks and buttons */
  --field: #0b8f62;
  --field-deep: #06603f;
  --field-deeper: #034a30;
  --tile: #16b47e;
  --tile-hi: #2fd197;
  --ink: #04281a;
  --mark: #ff6a24;
  --mark-hi: #ffa064;
  --paper: #f3fff9;
  --edge: rgba(2, 30, 19, .85);
  --top: 64px;
  --bottom: 76px;
  --gutter: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--field); color: var(--paper); }
body {
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- buttons */
.btn {
  border: 1.5px solid var(--edge); border-radius: 10px;
  background: rgba(0, 0, 0, .22); padding: 0 22px; min-height: 52px;
  font-weight: 700; font-size: 20px; letter-spacing: .01em;
  box-shadow: 0 4px 0 var(--edge); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn.primary { background: var(--mark); color: var(--ink); }
.btn.small { white-space: nowrap;  min-height: 44px; font-size: 16px; padding: 0 16px; }
.btn.on { background: var(--paper); color: var(--ink); }
.btn:focus-visible, .link:focus-visible, .cell:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }
.link { background: none; border: 0; font-size: 17px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; padding: 10px 8px; opacity: .92; }

/* ---------- home: a board playing itself behind a loud title */
#home { overflow: hidden; }
.home-grid {
  position: absolute; left: 50%; top: 50%;
  width: max(118vmax, 900px); aspect-ratio: 1; transform: translate(-50%, -50%) rotate(-8deg);
  display: grid; gap: 4px; opacity: .9;
}
.home-grid .cell { font-size: clamp(16px, 4vmax, 46px); border-radius: 6px; }
.home-front {
  position: relative; z-index: 2; margin: auto; padding: 24px var(--gutter);
  display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%;
}
.title {
  margin: 0; text-align: center; font-weight: 700; line-height: .84;
  font-size: clamp(84px, 26vw, 200px); letter-spacing: -.04em; color: var(--mark);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--ink), 0 0 60px rgba(3, 74, 48, .9);
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-8px) rotate(-1.5deg); } }
.home-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 100%); }
.home-buttons .btn { min-height: 60px; font-size: 22px; background: var(--field-deeper); }
.home-buttons .btn.primary { background: var(--mark); }
.home-status { margin: 0; min-height: 1.4em; font-weight: 700; font-size: 17px; text-align: center; background: var(--field-deeper); padding: 4px 12px; border-radius: 6px; }
.home-status:empty { visibility: hidden; }
.home-links { display: flex; gap: 6px; background: var(--field-deeper); border-radius: 8px; padding: 0 6px; }

/* ---------- play */
.bar { flex: none; display: flex; align-items: center; padding: 0 var(--gutter); gap: 12px; }
.bar.top { height: var(--top); padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.bar.bottom { height: var(--bottom); padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box; justify-content: center; }
.icon { width: 44px; height: 44px; border: 0; background: none; display: grid; place-content: center; gap: 5px; padding: 0; }
.icon span { display: block; width: 24px; height: 3px; background: var(--paper); border-radius: 2px; }
.count { display: flex; align-items: baseline; gap: 6px; }
.count b { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count span { font-size: 15px; font-weight: 500; opacity: .85; }
.count.right { margin-left: auto; }
.count.low b { color: var(--mark-hi); }
.mode { font-weight: 500; font-size: 15px; opacity: .85; white-space: nowrap; }
.board-wrap { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 var(--gutter); }
.board {
  /* small viewport height: the board never changes size when the browser bar moves */
  --size: min(calc(100vw - 2 * var(--gutter)), calc(100svh - var(--top) - var(--bottom) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px), 820px);
  width: var(--size); height: var(--size);
  display: grid; gap: 3px; padding: 5px;
  background: var(--field-deeper); border: 1.5px solid var(--edge); border-radius: 10px;
  touch-action: none;
}
.board.n20 { gap: 2px; padding: 3px; }
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  background: var(--tile); border-radius: 5px; border: 0; padding: 0;
  box-shadow: inset 0 -3px 0 rgba(2, 40, 25, .35);
  font-weight: 700; font-variant-numeric: tabular-nums; color: var(--paper);
  font-size: calc(var(--size) / var(--n) * .52);
}
.n20 .cell { border-radius: 3px; box-shadow: inset 0 -2px 0 rgba(2, 40, 25, .35); }
@media (hover: hover) { .board .cell.hidden:hover { background: var(--tile-hi); } }
.cell.clue { background: var(--field-deep); box-shadow: none; }
.cell.clue.start { box-shadow: inset 0 0 0 2px rgba(243, 255, 249, .35); }
.cell.mark { background: var(--mark); box-shadow: inset 0 -3px 0 rgba(120, 30, 0, .45); animation: pop .42s cubic-bezier(.2, 1.6, .4, 1); z-index: 2; }
.cell.mark::after { content: ""; width: 46%; height: 46%; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 calc(var(--size) / var(--n) * .07) var(--paper); }
.cell.mark.lost { background: var(--field-deep); box-shadow: inset 0 0 0 2px var(--mark-hi); animation: pop .35s ease-out; }
.cell.mark.lost::after { background: transparent; box-shadow: 0 0 0 calc(var(--size) / var(--n) * .06) var(--mark-hi); }
@keyframes pop { 0% { transform: scale(.2); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.cell.dim { background: repeating-linear-gradient(135deg, rgba(3, 74, 48, .9) 0 4px, rgba(10, 130, 88, .9) 4px 8px); box-shadow: none; }
.cell.miss-new { animation: settle .25s ease-out; }
@keyframes settle { 0% { transform: scale(.85); } 100% { transform: scale(1); } }
.cell.x::before { content: "×"; color: var(--ink); opacity: .7; font-size: 1.3em; line-height: 1; }
.cell.dot::before { content: ""; width: 28%; height: 28%; border-radius: 50%; background: var(--mark); border: 1.5px solid var(--ink); }
/* clue cross highlight */
.cell.cleared { outline: none; }
.cell.cleared::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: rgba(4, 40, 26, .55); }
.cell.ring { box-shadow: inset 0 0 0 3px var(--paper); }
.n20 .cell.ring { box-shadow: inset 0 0 0 2px var(--paper); }
.cell.focus-src { background: var(--paper); color: var(--ink); }
.cell.kb { outline: 3px solid var(--mark-hi); outline-offset: 1px; z-index: 3; }
.cell.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.notes { display: flex; align-items: center; gap: 14px; width: 100%; }
.hint { font-size: 15px; font-weight: 500; opacity: .85; line-height: 1.2; }
.keys { display: flex; gap: 22px; font-size: 15px; font-weight: 500; flex-wrap: nowrap; white-space: nowrap; }
kbd { font: inherit; font-weight: 700; border: 1.5px solid var(--edge); border-bottom-width: 3px; border-radius: 6px; padding: 1px 7px; background: rgba(0, 0, 0, .2); }
.touch-only { display: none; }
@media (hover: none), (pointer: coarse) { .touch-only { display: flex; } .desk-only { display: none; } }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--bottom) + env(safe-area-inset-bottom) + 6px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); font-weight: 700; padding: 10px 16px; border-radius: 8px;
  transition: opacity .2s, transform .2s; white-space: nowrap; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- result, how, stats, credits */
.result-body, .page { flex: 1; overflow-y: auto; padding: 28px var(--gutter) 12px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.page { align-items: stretch; text-align: left; max-width: 640px; width: 100%; margin: 0 auto; }
h2 { margin: 0; font-size: clamp(34px, 9vw, 52px); line-height: 1; letter-spacing: -.02em; }
.res-big { font-size: clamp(64px, 20vw, 110px); font-weight: 700; line-height: .9; color: var(--mark); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.res-line { font-size: 20px; font-weight: 700; }
.strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.strip i { width: 22px; height: 22px; border-radius: 4px; border: 1.5px solid var(--edge); }
.mini { display: grid; gap: 2px; width: min(240px, 70vw); aspect-ratio: 1; padding: 3px; background: var(--field-deeper); border-radius: 6px; }
.mini i { border-radius: 2px; background: var(--tile); }
.mini i.c { background: var(--field-deep); }
.mini i.m { background: var(--mark); }
.mini i.lm { background: var(--paper); }
.hist { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.hist div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; font-size: 12px; font-weight: 700; height: 100%; }
.hist b { display: block; width: 20px; background: rgba(243, 255, 249, .6); border-radius: 3px 3px 0 0; min-height: 3px; }
.hist div.me b { background: var(--mark); }
.res-stats { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.res-stats div { display: flex; flex-direction: column; }
.res-stats b { font-size: 26px; }
.res-stats span { font-size: 13px; font-weight: 500; opacity: .85; }
.result-buttons { flex: none; display: flex; gap: 12px; justify-content: center; padding: 12px var(--gutter) calc(18px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
.result-buttons .btn { flex: 1 1 0; max-width: 220px; }

.how-row { display: flex; gap: 16px; align-items: center; }
.how-row p, .how-note { margin: 0; font-size: 18px; line-height: 1.35; font-weight: 500; }
.how-note { font-weight: 700; }
.how-pic { flex: none; width: 128px; aspect-ratio: 1; display: grid; gap: 2px; padding: 3px; background: var(--field-deeper); border-radius: 6px; --size: 128px; }
.how-pic .cell { font-size: 14px; border-radius: 2px; box-shadow: none; }
.how-pic .cell.mark::after { box-shadow: 0 0 0 2px var(--paper); }
.how-pic .cell.ring { box-shadow: inset 0 0 0 2.5px var(--paper); }
.credits { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; font-size: 18px; }
.credits a { color: var(--paper); }
.stat-block h3 { margin: 18px 0 8px; font-size: 22px; }

.menu { position: absolute; inset: 0; background: rgba(3, 40, 26, .78); display: grid; place-items: center; z-index: 30; }
.menu-card { display: flex; flex-direction: column; gap: 14px; width: min(300px, 80vw); }

.debug { position: absolute; right: 8px; top: calc(var(--top) + env(safe-area-inset-top) + 4px); background: rgba(0, 0, 0, .7); font: 12px ui-monospace, monospace; padding: 6px 8px; border-radius: 6px; z-index: 10; pointer-events: none; white-space: pre; }
.cell .p { position: absolute; left: 2px; top: 1px; font: 700 9px ui-monospace, monospace; color: #fff; opacity: .9; }
.cell.dbg-out { background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, .25) 0 3px, transparent 3px 6px); }
.cell.dbg-sure { box-shadow: inset 0 0 0 3px var(--mark); }
.cell.dbg-next { outline: 3px dashed #fff; z-index: 3; }

@media (max-width: 380px) { .mode { display: none; } }
@media (min-width: 900px) { :root { --top: 76px; } .count b { font-size: 36px; } }
.home-buttons .btn.big { min-height: 76px; font-size: 32px; }
.stat-page { justify-content: flex-start; gap: 32px; margin-top: 8px; }
.stat-page b { font-size: 40px; }
.gear {
  position: absolute; z-index: 3; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 52px; height: 52px; display: grid; place-items: center; padding: 0;
  border: 1.5px solid var(--edge); border-radius: 50%; background: var(--field-deeper); color: var(--paper);
  box-shadow: 0 3px 0 var(--edge);
}
.gear:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--edge); }
.gear:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }
.menu { background: rgba(3, 40, 26, .92); }
.menu-card .btn:not(.primary) { background: var(--field-deep); }
.result-buttons .btn { white-space: nowrap; padding: 0 14px; }
