/* Sudoku Today. Phones in portrait first (the portal puts games full screen there); the board sits beside the controls
   when the frame is wide (desktop, landscape). Sizes follow the frame, never the device. */
:root {
  --bg: #f4f3fb;
  --surface: #fff;
  --text: #111318;
  --muted: #5d5a73;
  --accent: #5b3df5;
  --accent-soft: #eeebff;
  --related: #e3ddff;
  --same: #c9bdff;
  --selected: #ffe27a;
  --wrong: #d92d4a;
  --thick: #2b2560;
  --line: #d3cfe8;
  --play: #ffd23f;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#app { height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.loading { display: grid; place-items: center; height: 100%; margin: 0; color: var(--muted); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.primary, .secondary {
  min-height: 48px; padding: 0 22px; border-radius: 999px; font-weight: 700;
}
.primary { border: 0; background: var(--play); color: #111318; }
.primary[aria-busy='true'] { opacity: 0.6; cursor: progress; }
.secondary { border: 1px solid var(--line); background: var(--surface); }
.link { min-height: 44px; border: 0; background: none; color: var(--accent); font-weight: 600; }
.icon { width: 44px; height: 44px; flex: none; border: 0; border-radius: 999px; background: none; font-size: 1.2rem; }
.icon:hover { background: var(--accent-soft); }

/* ---- home and archive */
.home, .archive, .done { max-width: 460px; height: 100%; margin: 0 auto; padding: 16px; overflow-y: auto; }
.home { display: flex; flex-direction: column; gap: 14px; justify-content: center; }
.home__head h1 { margin: 0; font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
.home__date { margin: 2px 0 0; color: var(--muted); }
.levels { display: grid; gap: 10px; }
.level {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 58px; padding: 0 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); text-align: left;
}
.level:hover { border-color: var(--accent); }
.level__name { font-weight: 700; font-size: 1.1rem; }
.level__status { color: var(--accent); font-weight: 600; white-space: nowrap; }
.level--done .level__status { color: #1d7a47; }
.countdown { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.home__streak { margin: 0; font-weight: 700; text-align: center; }
.challenge { display: grid; gap: 10px; padding: 14px 16px; border-radius: 16px; background: var(--thick); color: #fff; }
.challenge p { margin: 0; font-weight: 600; }

.bar { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.bar h2, .bar__title { flex: 1; margin: 0; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar__stat { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.timer { min-width: 4.2em; text-align: right; color: var(--text); }
.timer--penalty { animation: penalty 0.6s; }
@keyframes penalty { 0%, 60% { color: var(--wrong); } }
.days { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.day { display: grid; gap: 6px; padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.day__name { margin: 0; }
.day__levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.day__levels .level { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; min-height: 50px; padding: 4px 10px; border-radius: 12px; }
.day__levels .level__name { font-size: 0.9rem; }
.day__levels .level__status { font-size: 0.85rem; white-space: normal; }

/* ---- playing */
.play {
  display: grid; height: 100%; padding: 0 8px 8px;
  grid-template: 'bar' auto 'stage' minmax(0, 1fr) 'controls' auto / minmax(0, 1fr);
}
.play > .bar { grid-area: bar; }
.stage { grid-area: stage; position: relative; display: grid; place-items: center; min-height: 0; container-type: size; }
.board {
  display: grid; grid-template-rows: repeat(9, 1fr);
  width: min(96vw, 58vh); width: min(100cqw, 100cqh); aspect-ratio: 1;
  border: 2.5px solid var(--thick); border-radius: 8px; overflow: hidden; background: var(--surface);
  container-type: inline-size; user-select: none;
}
.board--hidden .cell { color: transparent !important; }
.board--hidden .notes { visibility: hidden; }
.row { display: grid; grid-template-columns: repeat(9, 1fr); min-height: 0; }
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 0;
  border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0;
  background: var(--surface); color: var(--accent); font-size: 6.4cqw; font-weight: 600; line-height: 1;
}
.cell:nth-child(3n) { border-right: 2.5px solid var(--thick); }
.cell:last-child { border-right: 0; }
.row:nth-child(3n) .cell { border-bottom: 2.5px solid var(--thick); }
.row:last-child .cell { border-bottom: 0; }
.cell--given { color: var(--text); font-weight: 700; }
.cell--related { background: var(--related); }
.cell--same { background: var(--same); }
.cell--selected { background: var(--selected); }
.cell--wrong { color: var(--wrong); }
.cell--shake { animation: shake 0.3s; }
@keyframes shake { 25% { translate: -2px 0; } 75% { translate: 2px 0; } }
.notes { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); width: 100%; height: 100%; padding: 1px; }
.notes i { display: grid; place-items: center; font-style: normal; font-size: 3.2cqw; font-weight: 600; line-height: 1; color: var(--muted); }
.overlay {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center;
  background: rgb(244 243 251 / 0.75); backdrop-filter: blur(2px);
}
.overlay p { margin: 0; font-size: 1.3rem; font-weight: 700; }

.controls { grid-area: controls; display: grid; gap: 8px; padding-top: 8px; width: 100%; max-width: 560px; margin: 0 auto; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tool {
  display: grid; justify-items: center; gap: 1px; min-height: 52px; padding: 4px 0; border: 0; border-radius: 12px;
  background: none; color: var(--muted); font-size: 0.78rem; font-weight: 600;
}
.tool span { font-size: 1.25rem; line-height: 1.2; color: var(--text); }
.tool:hover { background: var(--accent-soft); }
.tool[aria-pressed='true'] { background: var(--accent); color: #fff; }
.tool[aria-pressed='true'] span { color: #fff; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.digit {
  position: relative; display: grid; place-items: center; min-height: 56px; padding: 0; border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: 0 1px 0 var(--line); color: var(--accent); font-size: 1.6rem; font-weight: 600;
}
.digit small { position: absolute; top: 3px; right: 5px; font-size: 0.62rem; color: var(--muted); }
.digit:disabled { visibility: hidden; }
.digit:active { background: var(--accent-soft); }
.message { min-height: 1.4em; margin: 0; color: var(--muted); font-size: 0.9rem; text-align: center; }

/* Wide frames (desktop, phones in landscape): controls beside the board, digits as a 3×3 pad. */
@media (min-aspect-ratio: 5/4) {
  .play { grid-template: 'bar bar' auto 'stage controls' minmax(0, 1fr) / minmax(0, 1fr) minmax(220px, 300px); column-gap: 16px; padding: 0 16px 12px; }
  .controls { align-content: center; padding-top: 0; }
  .pad { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .digit { min-height: 0; aspect-ratio: 1.15; }
}
@media (max-height: 420px) and (min-aspect-ratio: 5/4) {
  .tool { min-height: 44px; font-size: 0; }
  .digit { aspect-ratio: 1.6; font-size: 1.3rem; }
}

/* ---- solved */
.done { display: flex; flex-direction: column; gap: 10px; text-align: center; }
.done .bar { text-align: left; }
.done h2 { margin: 8px 0 0; font-size: 1.9rem; font-weight: 800; }
.done__time { margin: 0; font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.done__detail { margin: 0; color: var(--muted); }
.done__stat { margin: 0; font-weight: 700; color: var(--accent); }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.versus p { display: grid; margin: 0; }
.versus span { color: var(--muted); font-size: 0.85rem; }
.versus strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.versus__verdict { grid-column: 1 / -1; font-weight: 700; }
.actions { display: grid; gap: 8px; margin-top: 8px; }
