:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #1d2027;
  --muted: #6b6f78;
  --line: #e2ddd2;
  --tile: #ffffff;
  --tile-ink: #1d2027;
  --sel: #2f6f5e;
  --sel-ink: #ffffff;
  --bad: #c8463d;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --g0: #f3c8a8; --g1: #b9dcc4; --g2: #c4cff0; --g3: #f1dc94; --g4: #e7bcd6;
  --g5: #a9dbe0; --g6: #d8c8ee; --g7: #f2b9b0; --g8: #cfe3a6; --g9: #e3d2bd;
  --shadow: 0 1px 0 rgba(0,0,0,.06), 0 2px 6px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d; --surface: #20232a; --ink: #eceae5; --muted: #9a9ea8; --line: #30343c;
    --tile: #262a32; --tile-ink: #eceae5; --sel: #5fb39b; --sel-ink: #0f1a16; --accent: #5fb39b; --accent-ink: #0f1a16;
    --g0: #7a5640; --g1: #3f6b52; --g2: #46527a; --g3: #7a6a2e; --g4: #74475f;
    --g5: #3a6b70; --g6: #5c4b7a; --g7: #7c4943; --g8: #56703a; --g9: #6b5a45;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.top { width: 100%; max-width: 440px; display: flex; align-items: center; justify-content: space-between; padding: 12px 0 4px; }
.title { text-align: center; }
.title h1 { margin: 0; font-size: 1.45rem; letter-spacing: -.02em; font-weight: 800; }
.title p { margin: 0; color: var(--muted); font-size: .85rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; display: grid; place-items: center; cursor: pointer;
}

main { width: 100%; max-width: 440px; flex: 1; display: flex; flex-direction: column; }
.status { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 12px; gap: 12px; }
.progress { display: flex; gap: 5px; }
.progress i { width: 14px; height: 14px; border-radius: 4px; background: var(--line); transition: background .2s, transform .2s; }
.progress i.on { transform: scale(1.08); }
.meta { display: flex; gap: 10px; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; }
.board {
  --cols: 5;
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 6px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.tile {
  aspect-ratio: 1; border-radius: 12px; background: var(--tile); color: var(--tile-ink);
  display: grid; place-items: center; font-weight: 750; font-size: clamp(1.25rem, 6.5vw, 1.8rem);
  box-shadow: var(--shadow); border: 1px solid var(--line); cursor: pointer;
  transition: background .15s, transform .12s, color .15s, border-color .15s;
}
.tile.sel { background: var(--sel); color: var(--sel-ink); border-color: var(--sel); transform: scale(.94); }
.tile.found { cursor: default; box-shadow: none; border-color: transparent; }
.tile.pop { animation: pop .35s ease; }
.tile.shake { animation: shake .4s ease; background: var(--bad); color: #fff; border-color: var(--bad); }
.tile.stranded { outline: 3px dashed var(--bad); outline-offset: -5px; animation: strand 1.2s ease 2; }
@keyframes strand { 50% { transform: scale(.92); } }
.tile.hinted { outline: 3px dashed var(--accent); outline-offset: -5px; }
.board.done .tile { animation: wave .6s ease both; animation-delay: calc(var(--i) * 18ms); }
@keyframes pop { 40% { transform: scale(1.1); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes wave { 50% { transform: translateY(-6px); } }

.sum {
  position: absolute; left: 50%; bottom: -10px; transform: translate(-50%, 100%);
  background: var(--ink); color: var(--bg); border-radius: 999px; padding: 2px 12px; font-weight: 700; font-size: .9rem;
  opacity: 0; transition: opacity .15s; pointer-events: none; font-variant-numeric: tabular-nums;
}
.sum.show { opacity: 1; }
.sum.over { background: var(--bad); color: #fff; }

.actions { display: flex; gap: 10px; justify-content: center; margin: 46px 0 8px; }
.btn { border-radius: 12px; padding: 11px 20px; border: 1px solid var(--line); background: var(--surface); font-weight: 650; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.loading { text-align: center; color: var(--muted); }

.foot { color: var(--muted); font-size: .78rem; display: flex; gap: 6px; padding: 14px 0 16px; }
.foot a { color: inherit; }

dialog.sheet {
  border: none; border-radius: 18px; padding: 20px; width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog h2 { margin: 0 0 12px; font-size: 1.25rem; }
dialog h3 { margin: 16px 0 6px; font-size: .95rem; }
.small { font-size: .88rem; color: var(--muted); }
.tiny { font-size: .74rem; color: var(--muted); }
.center { text-align: center; }

.howto { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.howto li { display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; }
.howto p { margin: 0; font-size: .93rem; }
.nw { white-space: nowrap; }
.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.mt { aspect-ratio: 1; display: grid; place-items: center; border-radius: 6px; background: var(--tile); border: 1px solid var(--line); font-weight: 700; font-size: .85rem; }
.mt.a { animation: demo 2.4s infinite; }
.mt.a + .mt.a { animation-delay: .35s; }
.mt.g1 { background: var(--g1); border-color: transparent; }
.mt.g2 { background: var(--g2); border-color: transparent; }
.mt.g3 { background: var(--g3); border-color: transparent; }
.mt.left { outline: 2px dashed var(--bad); outline-offset: -3px; }
.mt.bad { background: var(--bad); color: #fff; border-color: transparent; }
@keyframes demo { 0%, 15% { background: var(--tile); color: inherit; } 30%, 80% { background: var(--sel); color: var(--sel-ink); } 100% { background: var(--tile); } }

.card {
  background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 0;
  font: 1rem/1.5 system-ui, -apple-system, sans-serif; white-space: pre-wrap; word-break: break-word;
}
.nums { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.nums b { display: block; font-size: 1.5rem; }
.nums span { font-size: .75rem; color: var(--muted); }
.hist { display: grid; gap: 4px; }
.hist .row { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 6px; font-size: .8rem; }
.hist .bar { background: var(--line); border-radius: 4px; padding: 1px 6px; text-align: right; min-width: 22px; font-variant-numeric: tabular-nums; }
.hist .bar.today { background: var(--accent); color: var(--accent-ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10;
  max-width: calc(100vw - 32px); width: max-content; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
