:root {
  color-scheme: light;
  --bg: #0f172a;
  --ink: #f1f5f9;
  --line: #334155;
  --cage: #f8fafc;
  --accent: #fbbf24;
  --given: #e2e8f0;
  --user: #38bdf8;
  --bad: #f87171;
  --pad: #1e293b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.topbar { display: flex; align-items: center; gap: 8px; padding: 2px 2px 6px; }
.title { font-weight: 800; font-size: 20px; }
.title small { font-weight: 500; font-size: 12px; color: #94a3b8; }
.spacer { flex: 1; }
.hud { font-size: 15px; background: rgba(255,255,255,.08); border-radius: 999px; padding: 4px 12px; }
.hud .sep { color: #64748b; margin: 0 4px; }
.hud .opt { color: #fca5a5; }

#status { font-size: 14px; color: #fde68a; min-height: 20px; margin: 0 2px 6px; }

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: var(--line);
  gap: 0;
  border: 3px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
}

.cell {
  aspect-ratio: 1;
  background: var(--bg);
  border: 1px dotted #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.cell .clue {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
}
.cell.given { color: var(--given); cursor: default; }
.cell.entered { color: var(--user); }
.cell.selected { background: #1e3a5f; }
.cell.same-cage { background: #16283f; }
.cell.err { animation: shake .25s; }
.cell.err .val { color: var(--bad); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.cell.edge-t { border-top: 2px solid var(--cage); }
.cell.edge-b { border-bottom: 2px solid var(--cage); }
.cell.edge-l { border-left: 2px solid var(--cage); }
.cell.edge-r { border-right: 2px solid var(--cage); }
.cell.box-t { border-top: 2px solid #94a3b8; }
.cell.box-b { border-bottom: 2px solid #94a3b8; }
.cell.box-l { border-left: 2px solid #94a3b8; }
.cell.box-r { border-right: 2px solid #94a3b8; }

#padbar { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
#pad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.digit {
  background: var(--pad);
  border: 1px solid rgba(255,255,255,.15);
  color: #fff;
  border-radius: 10px;
  padding: 10px 0;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.digit.done { opacity: .3; }
.pad-actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0f172a; }

#win.hidden { display: none; }
#win {
  margin-top: 10px;
}
.win-card {
  background: rgba(56,189,248,.1);
  border: 1px solid var(--user);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.win-label { font-weight: 800; font-size: 18px; }
.win-line { margin: 6px 0 10px; font-size: 14px; }
.win-line .sep { color: #64748b; margin: 0 6px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: #fff;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: 92vw;
  text-align: center;
}
#toast.show { opacity: 1; }

html.touch .cell { font-size: 22px; }
html.touch .digit { padding: 12px 0; }
