:root {
  --bg: #EEF1F7;
  --surface: #FFFFFF;
  --ink: #172038;
  --muted: #6B7591;
  --line: #CDD4E3;
  --line-strong: #4C5878;
  --accent: #2F54EB;
  --on-accent: #FFFFFF;
  --peer: #EFF2FB;
  --same: #CFD9FF;
  --selected: #B4C4FF;
  --error: #D93643;
  --error-soft: #FFE0E3;
  --track: #DFE4EF;
  --win: #19B98A;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1322;
    --surface: #171E33;
    --ink: #E9EDFA;
    --muted: #8E98B5;
    --line: #2B3452;
    --line-strong: #5B6690;
    --accent: #8DA2FF;
    --on-accent: #0E1322;
    --peer: #1D2540;
    --same: #303E75;
    --selected: #41549F;
    --error: #FF6B74;
    --error-soft: #4A1F2A;
    --track: #1C243C;
    --win: #3DD6A3;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1322;
  --surface: #171E33;
  --ink: #E9EDFA;
  --muted: #8E98B5;
  --line: #2B3452;
  --line-strong: #5B6690;
  --accent: #8DA2FF;
  --on-accent: #0E1322;
  --peer: #1D2540;
  --same: #303E75;
  --selected: #41549F;
  --error: #FF6B74;
  --error-soft: #4A1F2A;
  --track: #1C243C;
  --win: #3DD6A3;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  height: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
}
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  --board-max: calc(min(100vw, 500px) - 28px);
  height: 100vh;
  height: calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-width: 500px;
  margin: 0 auto;
  padding: 12px 14px 8px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 18px);
}

/* Top row */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.mark {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
  text-decoration: none;
  border-radius: 6px;
}
.mark .so { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.seg {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--track);
}
.seg button {
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: background-color .15s, color .15s;
}
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(23, 32, 56, .12);
}

/* Status row */
.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  color: var(--muted);
  min-height: 32px;
}
.mistakes { display: flex; align-items: center; gap: 9px; }
.dots { display: flex; gap: 6px; }
.dots i {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--line);
  transition: background-color .2s, transform .2s;
}
.dots i.on { background: var(--error); transform: scale(1.1); }
.clock { display: flex; align-items: center; gap: 6px; }
#time {
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 3.2em;
  text-align: right;
}
#pause {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--ink);
}
#pause:disabled { opacity: .3; }
#pause svg { width: 18px; height: 18px; }

/* Board */
.stage {
  flex: 1 1 0;
  min-height: 0;
  max-height: var(--board-max);
  container-type: size;
  display: grid;
  place-items: center;
}
.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  container-type: inline-size;
}
.board {
  width: 100%; height: 100%;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 2px;
  background: var(--line-strong);
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  overflow: hidden;
}
.box {
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--surface);
  font-size: 22px;
  font-size: 6.6cqw;
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  border-radius: 0;
  transition: background-color .1s;
}
.cell:focus-visible { outline-offset: -2px; z-index: 1; }
.cell.given { color: var(--ink); font-weight: 500; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.sel { background: var(--selected); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.wrong { color: var(--error); background: var(--error-soft); }
.cell.wrong.sel { box-shadow: inset 0 0 0 2px var(--error); }
.veiled .cell > * { visibility: hidden; }

.notes {
  position: absolute;
  inset: 7%;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  place-items: center;
  font-size: 9px;
  font-size: 2.7cqw;
  font-weight: 400;
  color: var(--muted);
}
.notes b { font-weight: 600; color: var(--accent); }

@keyframes shake {
  20% { transform: translateX(-9%); }
  40% { transform: translateX(8%); }
  60% { transform: translateX(-5%); }
  80% { transform: translateX(3%); }
}
@keyframes pop {
  0% { transform: scale(.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.cell.shake .val { animation: shake .35s ease; }
.cell.pop .val { animation: pop .22s ease-out; }
.val { display: block; }

/* Completion effects: a wave that travels out from the cell just placed */
@keyframes fx-flash {
  35% { background: var(--accent); }
}
@keyframes fx-flash-win {
  30% { background: var(--accent); }
  65% { background: var(--win); }
}
@keyframes fx-line {
  35% { transform: translateY(-16%) scale(1.3); color: var(--on-accent); }
  70% { transform: translateY(4%) scale(.96); }
}
@keyframes fx-box {
  35% { transform: scale(1.45) rotate(-10deg); color: var(--on-accent); }
  70% { transform: scale(.92) rotate(4deg); }
}
@keyframes fx-win {
  30% { transform: translateY(-22%) scale(1.45); color: var(--on-accent); }
  65% { transform: translateY(0) scale(1.1); color: var(--on-accent); }
}
.cell[data-fx] { animation: fx-flash .6s ease-out var(--fx-delay, 0ms); }
.cell[data-fx] .val { animation: fx-line .6s ease-out var(--fx-delay, 0ms); }
.cell[data-fx="box"] .val { animation-name: fx-box; }
.cell[data-fx="win"] { animation: fx-flash-win .8s ease-out var(--fx-delay, 0ms); }
.cell[data-fx="win"] .val { animation: fx-win .8s ease-out var(--fx-delay, 0ms); }
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

/* Overlay on the board */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 14px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
}
.overlay[hidden] { display: none; }
.overlay h2 {
  margin: 0;
  font-size: 26px;
  font-size: min(30px, 7.4cqw);
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.overlay p {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--muted);
  max-width: 26ch;
}
.overlay .primary {
  min-width: 200px;
  padding: 13px 22px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 16px;
  font-weight: 500;
}
.overlay .secondary {
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  border-radius: 999px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 4;
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Tools */
.tools {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.tools button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 0 6px;
  border-radius: 12px;
  font-size: 13px;
  color: var(--muted);
  transition: background-color .15s, color .15s, opacity .15s;
}
.tools svg { width: 22px; height: 22px; color: var(--ink); transition: color .15s; }
.tools button:disabled { opacity: .35; }
.tools button:active:not(:disabled) { background: var(--track); }
.tools button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.tools button[aria-pressed="true"] svg { color: var(--on-accent); }

.sos-letters { font-weight: 600; letter-spacing: .08em; color: var(--accent); }
.sos-letters i { font-style: normal; transition: opacity .25s; }
.sos-letters i.used { opacity: .28; }
#sos svg { color: var(--accent); }

/* Number pad */
.pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
}
.pad button {
  height: clamp(52px, 8.5vh, 68px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
  transition: transform .08s, opacity .15s, background-color .15s;
}
.pad .d {
  font-size: 27px;
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  transition: font-size .12s, color .12s;
}
.pad .left {
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pad button:active:not(:disabled) { transform: scale(.94); background: var(--same); }
.pad button:disabled { opacity: .28; box-shadow: none; }
.pad.notes-mode button { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.pad.notes-mode .d { font-size: 20px; color: var(--muted); }
.pad.notes-mode .left { visibility: hidden; }

@media (hover: hover) {
  .cell:hover:not(.sel):not(.same):not(.wrong) { background: var(--peer); }
  .tools button:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--track); }
  .seg button:hover { color: var(--ink); }
}
@media (max-height: 560px) {
  .mark { font-size: 20px; }
  .tools button { gap: 1px; padding: 3px 0; font-size: 11px; }
  .tools svg { width: 18px; height: 18px; }
  .pad button { height: 46px; }
  .pad .d { font-size: 23px; }
}
@media (max-width: 360px) {
  .mark { font-size: 22px; }
  .top { gap: 8px; }
}
@media (max-width: 340px) {
  .seg button { padding: 7px 10px; font-size: 13px; }
  .pad { gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Link from the game down to the text below it */
.more {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 999px;
}
.more svg { width: 14px; height: 14px; }
@media (hover: hover) { .more:hover { color: var(--ink); } }
@media (max-height: 560px) { .more { display: none; } }
@media (display-mode: standalone) { .more { display: none; } }

/* Text below the game */
.info {
  max-width: 500px;
  margin: 0 auto;
  padding: 44px 20px 28px;
  font-size: 17px;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
}
.info h1 {
  margin: 0 0 10px;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.info h2 {
  margin: 44px 0 12px;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}
.info h3 { margin: 22px 0 4px; font-size: 17px; font-weight: 600; }
.info p { margin: 0 0 12px; color: var(--muted); }
.info .lead { font-size: 19px; color: var(--ink); }
.info a { color: var(--accent); text-underline-offset: 3px; }
.info dl { margin: 0; }
.info dt { margin-top: 16px; font-weight: 600; }
.info dd { margin: 2px 0 0; color: var(--muted); }
.info kbd {
  font: inherit;
  font-size: 15px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--track);
  color: var(--ink);
}
.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.levels a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}
.levels a span { font-size: 15px; font-weight: 400; color: var(--muted); }
.levels a[aria-current="page"] { box-shadow: inset 0 0 0 2px var(--accent); }
@media (hover: hover) { .levels a:hover { box-shadow: inset 0 0 0 2px var(--line); } }
.foot {
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

