:root {
  --bg: #0b1026;
  --bg2: #141a3a;
  --line: #26305e;
  --ink: #e8ecff;
  --dim: #8d96c7;
  --star: #ffd166;
  --comet: #4cc9f0;
  --hole: #b5179e;
  --good: #06d6a0;
  --bad: #ef476f;
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 70% -10%, #1d2660 0%, var(--bg) 60%) fixed;
  display: flex; flex-direction: column; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Header */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(11, 16, 38, .75); backdrop-filter: blur(6px);
}
.brand { font-weight: 800; font-size: 22px; letter-spacing: .5px; }
.brand span, h1 span { color: var(--star); }
.stats { display: flex; gap: 18px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat small { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat b.bump { animation: bump .5s ease; }
@keyframes bump { 30% { transform: scale(1.35); color: var(--star); } }
.practice-tag { margin-left: auto; color: var(--comet); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.icon { display: grid; place-items: center; color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; font-size: 18px; }

/* Layout */
.layout {
  flex: 1; display: grid; gap: 16px; padding: 16px;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-content: start;
  max-width: 1280px; width: 100%; margin: 0 auto;
}
.board-wrap { display: flex; justify-content: center; align-items: flex-start; min-width: 0; }
.board {
  position: relative; width: 100%; max-width: calc(100dvh - 100px);
  aspect-ratio: 1; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: #070b1d;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}
canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.coords {
  position: absolute; pointer-events: none; padding: 3px 8px; border-radius: 8px;
  background: rgba(20, 26, 58, .9); border: 1px solid var(--line);
  font-size: 13px; font-variant-numeric: tabular-nums; transform: translate(12px, -130%);
}
.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px; font-weight: 700; text-align: center;
  background: rgba(20, 26, 58, .92); border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4); max-width: 90%;
  animation: drop .35s ease;
}
.toast.good { border-color: var(--good); color: var(--good); }
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.gold { border-color: var(--star); color: var(--star); }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -12px); } }

/* Panel */
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.eq {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.eq label { font-size: 22px; font-weight: 700; padding-left: 6px; color: var(--comet); white-space: nowrap; }
.eq input {
  flex: 1; min-width: 0; font: inherit; font-size: 22px; color: var(--ink);
  background: transparent; border: none; outline: none; padding: 6px 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.eq input::placeholder { color: #4a5490; }
.go {
  background: var(--star); color: #1a1300; border: none; border-radius: 10px;
  padding: 10px 16px; font-weight: 800; font-size: 16px;
}
.go:disabled { opacity: .4; cursor: default; }
.msg { min-height: 1.4em; color: var(--dim); font-size: 14px; padding: 0 4px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }

.ink { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); padding: 0 4px; }
.ink .bar { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.ink .bar div { height: 100%; width: 0; background: var(--comet); transition: width .15s; }
.ink .bar div.full { background: var(--bad); }
.ink span:last-child { width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }

.keypad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.keypad button {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 0; font-size: 16px; font-family: ui-monospace, Menlo, monospace;
}
.keypad button:active { background: var(--line); }
.keypad .del { color: var(--bad); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; color: var(--ink);
}
.ghost:hover { border-color: var(--dim); }
.ghost small { color: var(--dim); }
.ghost:disabled { opacity: .4; cursor: default; }

.hist-h { margin: 6px 4px 0; font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 34dvh; }
.history li {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px;
  background: var(--bg2); font-size: 14px;
}
.history code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; cursor: pointer; }
.history .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.history .pts.zero { color: var(--bad); }
.history .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.history .rm { background: none; border: none; color: var(--dim); font-size: 16px; padding: 0 4px; }
.history .empty { color: var(--dim); background: none; font-style: italic; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 22, .78); backdrop-filter: blur(4px); padding: 16px; overflow-y: auto;
}
.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; padding: 28px;
  max-width: 560px; width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); max-height: 100%; overflow-y: auto;
}
.title-card { text-align: center; }
h1 { font-size: clamp(44px, 10vw, 72px); margin: 0; letter-spacing: 1px; }
h2 { margin: 0 0 12px; }
h3 { margin: 18px 0 8px; font-size: 16px; color: var(--star); }
.tag { color: var(--dim); font-size: 17px; line-height: 1.5; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; margin: 20px 0 10px; }
.big {
  width: min(280px, 100%); padding: 14px; font-size: 20px; font-weight: 800; border-radius: 14px;
  border: none; background: var(--star); color: #1a1300;
}
.big.alt { background: var(--comet); color: #00202b; }
.settings { text-align: left; margin-top: 10px; color: var(--dim); font-size: 14px; }
.settings summary { cursor: pointer; text-align: center; }
.settings label { display: block; padding: 6px 0; }
.scores { margin-top: 14px; font-size: 14px; }
.scores h4 { margin: 0 0 6px; color: var(--dim); font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
.scores ol { margin: 0; padding: 0; list-style: none; }
.scores li { display: flex; justify-content: space-between; padding: 4px 8px; border-radius: 8px; }
.scores li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.scores li.me { color: var(--star); font-weight: 700; }
.how-card ol, .how-card ul { padding-left: 20px; line-height: 1.55; }
.examples code, .tip code { color: var(--comet); }
.ptable { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.ptable th { text-align: left; color: var(--dim); font-weight: 600; padding: 4px 6px; }
.ptable td { text-align: center; padding: 4px; border-left: 1px solid var(--line); }
.tip { color: var(--dim); font-size: 14px; line-height: 1.5; }
.how-card .big { display: block; margin: 18px auto 0; }
.over-card { text-align: center; }
.final { font-size: 56px; font-weight: 800; color: var(--star); font-variant-numeric: tabular-nums; }
.name-form { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.name-form input {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; width: 200px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
}

/* Mobile */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .board { max-width: 100%; }
  .stats { gap: 12px; }
  .stat.best { display: none; }
  .brand { font-size: 18px; }
  .history { max-height: none; }
}
@media (max-width: 420px) {
  .top { gap: 8px; padding: 8px 10px; }
  .stat b { font-size: 17px; }
  .icon { width: 34px; height: 34px; font-size: 15px; }
  .eq input, .eq label { font-size: 19px; }
}
