:root {
  --bg: #0f1117;
  --panel: #1a1d27;
  --panel-border: #2c3040;
  --text: #e8eaf0;
  --muted: #9aa0b4;
  --accent: #ffb300;
  --accent-text: #1a1200;
  --plus: #3ddc84;
  --minus: #ff5470;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#board {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:hover { background: #242838; }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 700;
}
button.primary:hover { background: #ffc233; }
button.small { padding: 2px 8px; font-size: 12px; border-radius: 6px; }
button:disabled { opacity: 0.5; cursor: default; }
button.muted { opacity: 0.6; text-decoration: line-through; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

/* HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-left { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-right {
  text-align: right; font-size: 13px; color: var(--muted);
  background: rgba(15, 17, 23, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  backdrop-filter: blur(4px);
}
.hud-right .stat { margin-bottom: 4px; }
.hud-right strong { color: var(--text); }
.seed-row { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }


/* Result banner */
#result {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 10, 0.55);
  backdrop-filter: blur(2px);
  animation: fade-in 0.3s ease-out;
}
.result-card {
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  max-width: min(90vw, 720px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: pop-in 0.35s cubic-bezier(.2,1.4,.4,1);
}
.result-label { color: var(--muted); font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }
.result-text {
  font-size: clamp(36px, 7vw, 80px);
  font-weight: 800;
  margin: 12px 0 8px;
  word-break: break-word;
}
.result-text.plus { color: var(--plus); }
.result-text.minus { color: var(--minus); }
.result-meta { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Settings panel */
#settings {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 10, 0.6);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  width: min(92vw, 560px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.panel h2 { margin: 0; font-size: 20px; }
.panel textarea {
  font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  background: #0c0e14;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  min-height: 160px;
}
.panel-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.help { color: var(--muted); font-size: 14px; margin: 0; }
.help.small { font-size: 12px; }
.plus { color: var(--plus); font-weight: 700; }
.minus { color: var(--minus); font-weight: 700; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 640px) {
  .hud-right { display: none; }
}

/* Settings grid */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  font-size: 14px;
}
.settings-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.settings-grid label.check { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--text); }
.settings-grid input[type="number"], .settings-grid select {
  font: inherit;
  color: var(--text);
  background: #0c0e14;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 8px;
}
.settings-grid input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* Picture-in-picture: bins under the ball */
#pip {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(440px, calc(100vw - 32px));
  background: rgba(15, 17, 23, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  pointer-events: none;
}
.pip-title {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}
.pip-sign { font-size: 16px; font-weight: 800; }
.pip-sign.plus { color: var(--plus); }
.pip-sign.minus { color: var(--minus); }
.pip-category { font-size: 12px; font-weight: 700; margin: 4px 0 2px; min-height: 14px; }
#pip ol { list-style: none; margin: 4px 0 0; padding: 0; }
#pip li {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 3px 8px; border-radius: 6px;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.1s;
}
#pip li .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #3a4058; }
#pip li .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
#pip li .tail { font-weight: 800; flex: none; }
#pip li .tail.plus { color: var(--plus); }
#pip li .tail.minus { color: var(--minus); }
#pip li.centre { background: rgba(255, 179, 0, 0.18); color: var(--text); font-weight: 600; }
#pip li.centre::before { content: "▶"; color: var(--accent); font-size: 10px; }
#pip li.empty { opacity: 0.25; }

/* Multi-ball result list */
.result-list { list-style: none; margin: 8px 0 4px; padding: 0 4px; text-align: left; max-height: 50vh; overflow-y: auto; }
.result-list li {
  display: flex; gap: 12px; align-items: baseline;
  font-size: clamp(18px, 2.6vw, 28px); font-weight: 700; padding: 6px 0;
  border-bottom: 1px solid var(--panel-border);
}
.result-list li:last-child { border-bottom: none; }
.result-list .n { color: var(--muted); font-size: 0.7em; font-weight: 600; min-width: 2.2em; }
.result-list .plus { color: var(--plus); }
.result-list .minus { color: var(--minus); }
.result-list .cat { color: var(--muted); font-size: 0.6em; font-weight: 600; margin-left: auto; }
.result-category { color: var(--muted); font-size: 14px; margin-top: -4px; margin-bottom: 10px; }

@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
  #pip { width: calc(100vw - 32px); font-size: 12px; }
}
