:root {
  --bg: #f6f4ef;
  --fg: #1d1b24;
  --muted: #77727f;
  --cell: #ffffff;
  --cell-line: #e6e1d8;
  --thread: #ff5a36;
  --thread-soft: #ffe1d6;
  --num-bg: #1d1b24;
  --num-fg: #ffffff;
  --win: #18a058;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161d;
    --fg: #f2f0f6;
    --muted: #9a95a6;
    --cell: #22212b;
    --cell-line: #2f2d3a;
    --thread: #ff6b4a;
    --thread-soft: #3a2420;
    --num-bg: #f2f0f6;
    --num-fg: #16161d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
.top {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}
.top h1 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  font-weight: 800;
}
.logo-dot {
  display: inline-block;
  width: .42em; height: .42em;
  margin-left: .12em;
  border-radius: 50%;
  background: var(--thread);
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--cell-line);
  background: var(--cell);
  color: var(--fg);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}
main {
  width: 100%;
  max-width: 520px;
  padding: 0 16px;
  flex: 1;
}
.meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin: 8px 2px 10px;
}
.board-wrap { position: relative; }
.board {
  --n: 6;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 0;
  aspect-ratio: 1;
  width: 100%;
  background: var(--cell);
  border: 2px solid var(--cell-line);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: relative;
  border-right: 1px solid var(--cell-line);
  border-bottom: 1px solid var(--cell-line);
  transition: background-color .12s;
}
.cell.on { background: var(--thread-soft); }
.board.solved .cell.on { background: color-mix(in srgb, var(--win) 18%, var(--cell)); }
.num {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 62%;
  height: 62%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--num-bg);
  color: var(--num-fg);
  font-weight: 800;
  font-size: clamp(14px, 4.4vw, 22px);
  z-index: 3;
  pointer-events: none;
}
.cell.on .num { background: var(--thread); color: #fff; }
.board.solved .cell.on .num { background: var(--win); }
.thread {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
.thread polyline {
  fill: none;
  stroke: var(--thread);
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke .3s;
}
.board.solved .thread polyline { stroke: var(--win); }
.board.shake { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.hint {
  text-align: center;
  color: var(--muted);
  min-height: 1.4em;
  margin: 14px 0 6px;
}
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 18px;
}
.btn {
  border: 1.5px solid var(--cell-line);
  background: var(--cell);
  color: var(--fg);
  padding: 10px 20px;
  border-radius: 999px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); width: 100%; }
.btn.ghost { border: none; background: none; color: var(--muted); width: 100%; margin-top: 4px; }
.btn:active { transform: scale(.97); }
.foot {
  color: var(--muted);
  font-size: .85rem;
  padding: 10px 16px 22px;
  text-align: center;
}
.foot a { color: inherit; font-weight: 600; }
.dlg {
  border: none;
  border-radius: 20px;
  padding: 24px;
  width: min(92vw, 380px);
  background: var(--bg);
  color: var(--fg);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dlg::backdrop { background: rgba(10, 10, 15, .45); backdrop-filter: blur(3px); }
.dlg h2 { margin: 0 0 12px; letter-spacing: -0.02em; }
.rules { text-align: left; padding-left: 1.2em; }
.rules li { margin: 6px 0; }
.small { color: var(--muted); font-size: .9rem; }
.big-time {
  font-size: 3rem;
  font-weight: 800;
  margin: 0 0 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 10px 0 18px;
}
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .75rem; color: var(--muted); }
.confetti { font-size: 2.4rem; animation: pop .5s ease-out; }
@keyframes pop { from { transform: scale(.2) rotate(-30deg); opacity: 0; } }
