:root {
  --bg-page: #101215;
  --panel: #191c21;
  --line: #262b33;
  --text: #e7ebf0;
  --muted: #9aa4b2;
  --accent: #6dff6d;

  /* Set from the settings by app.js. */
  --columns: 7;
  --slot: 60px;
  --gap: 0px;
  --radius: 0px;
  --term-bg: #1a1a1a;
  --order1: #6dff6d;
  --order2: #379a37;
  --order3: #1c591c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2028, var(--bg-page));
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: rgba(15, 17, 21, 0.72);
  border-bottom: 1px solid var(--line);
}

.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.stats { display: flex; gap: 18px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; min-width: 76px; }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.stat .value { font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 600; }
#time.running { color: var(--accent); }
#best.fresh { color: var(--accent); }

.actions { display: flex; gap: 8px; }

button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #212630;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
button:hover { background: #29303c; }
button.ghost { background: transparent; }
button.icon { border: 0; background: none; font-size: 22px; line-height: 1; padding: 0 6px; }

kbd {
  margin-left: 6px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #11141a;
  color: var(--muted);
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- terminal ---------- */

.stage { flex: 1; display: grid; place-items: center; padding: 32px 20px 56px; overflow: auto; }
.terminal-wrap { position: relative; }

.terminal {
  display: grid;
  grid-template-columns: repeat(var(--columns, 7), var(--slot));
  gap: var(--gap);
  padding: calc(var(--slot) * 0.18);
  border-radius: calc(var(--radius) + 6px);
  background: var(--term-bg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  user-select: none;
}

.slot {
  position: relative;
  width: var(--slot);
  height: var(--slot);
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f4f7fa;
  touch-action: manipulation;
  transition: background-color 40ms linear;
}

/* An unclicked pane the solver isn't highlighting - and a clicked one, which keeps the same
   background instead of dropping out of the grid. */
.slot.pane { background: rgba(255, 255, 255, 0.11); }
.slot.done { background: rgba(255, 255, 255, 0.11); color: transparent; cursor: default; }
.slot.next-1 { background: var(--order1); color: #0d1a0d; }
.slot.next-2 { background: var(--order2); color: #0d1a0d; }
.slot.next-3 { background: var(--order3); color: #eaf7ea; }
.slot.wrong { animation: wrong 260ms ease-out; }
.slot .count { font-size: calc(var(--slot) * 0.34); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

@keyframes wrong {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 3px #ff5555; }
}

/* Vanilla-style chest look. */
.terminal.normal {
  background: #c6c6c6;
  padding: calc(var(--slot) * 0.22);
  border-radius: 0;
  box-shadow: inset -2px -2px 0 #555, inset 2px 2px 0 #fff, 0 18px 50px rgba(0, 0, 0, 0.55);
}
.terminal.normal .slot { border-radius: 0; background: #8b8b8b; box-shadow: inset 2px 2px 0 #373737, inset -2px -2px 0 #fff; }
.terminal.normal .slot .count { position: absolute; right: 6%; bottom: 2%; color: #fff; }
.terminal.normal .slot .pane-item {
  position: absolute;
  inset: 12%;
  background: #b02020;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
}
.terminal.normal .slot.done .pane-item { background: #55dd55; }
.terminal.normal .slot.done { color: #fff; }
.terminal.normal .slot.next-1 .pane-item { outline: 3px solid var(--order1); outline-offset: -3px; }
.terminal.normal .slot.next-2 .pane-item { outline: 3px solid var(--order2); outline-offset: -3px; }
.terminal.normal .slot.next-3 .pane-item { outline: 3px solid var(--order3); outline-offset: -3px; }

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: calc(var(--radius) + 6px);
  background: rgba(8, 10, 13, 0.72);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
  pointer-events: none;
}
.message[hidden] { display: none; }
.message small { display: block; margin-top: 6px; font-size: 13px; font-weight: 500; color: var(--muted); text-align: center; }

/* ---------- settings ---------- */

.settings {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 100vw);
  height: 100vh;
  overflow-y: auto;
  padding: 18px 20px 40px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
}
.settings[hidden] { display: none; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; font-size: 16px; }
.settings h3 {
  margin: 22px 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.settings .row {
  display: grid;
  grid-template-columns: 1fr 120px 42px;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 13.5px;
}
.settings .row.switch { grid-template-columns: 1fr auto; }
.settings .row output { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; text-align: right; }
.settings select, .settings input[type="color"] { width: 120px; }
.settings select {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11141a;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.settings input[type="color"] { height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #11141a; }
.settings input[type="range"] { width: 120px; }
.settings .keybind {
  width: 120px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11141a;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.settings .keybind.listening { border-color: var(--accent); color: var(--accent); }
.settings input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.settings-foot { display: flex; gap: 8px; margin-top: 26px; }

/* ---------- leaderboard ---------- */

.leaderboard {
  position: fixed;
  top: 0;
  right: 0;
  width: min(400px, 100vw);
  height: 100vh;
  overflow-y: auto;
  padding: 18px 20px 40px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
}
.leaderboard[hidden] { display: none; }

.lb-name { margin-top: 16px; }
.lb-name label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.lb-name-row { display: flex; gap: 8px; }
.lb-name input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11141a;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.lb-name input:focus { outline: none; border-color: var(--accent); }
.lb-name button:disabled { opacity: 0.6; cursor: default; }

.lb-note, .lb-status { margin: 6px 0 0; min-height: 1.2em; color: var(--muted); font-size: 12.5px; }
.lb-note[data-tone="bad"], .lb-status[data-tone="bad"] { color: #ff7a7a; }
.lb-note[data-tone="good"], .lb-status[data-tone="good"] { color: var(--accent); }

.lb-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 18px; }
.lb-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.lb-tabs button, .lb-chips button { padding: 6px 10px; }
.lb-chips button { border-radius: 999px; font-size: 12.5px; }
.lb-tabs button.active, .lb-chips button.active { border-color: var(--accent); color: var(--accent); background: rgba(109, 255, 109, 0.08); }

.lb-list { margin-top: 14px; }
.lb-list table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lb-list th { padding: 6px 4px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; text-align: left; }
.lb-list td { padding: 7px 4px; border-top: 1px solid rgba(255, 255, 255, 0.05); font-variant-numeric: tabular-nums; }
.lb-list td:first-child { width: 28px; color: var(--muted); }
.lb-list td:nth-child(2) { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list tr:nth-child(-n+3) td:first-child { color: var(--accent); font-weight: 700; }
.lb-list tr.me td { background: rgba(109, 255, 109, 0.07); }
.lb-list td:nth-child(5) { color: var(--muted); font-size: 12.5px; }
.lb-mode { padding: 1px 7px; border-radius: 999px; background: #232935; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.lb-mode.drop { color: #9ecbff; }
.lb-mode.hover { color: #ffcf7a; }
.lb-empty { margin: 18px 0; color: var(--muted); font-size: 13.5px; }
.lb-updated { margin: 12px 0 0; color: var(--muted); font-size: 11.5px; }
.lb-fine { margin: 18px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

@media (max-width: 720px) {
  .stats { width: 100%; margin-left: 0; justify-content: space-between; }
  .settings, .leaderboard { width: 100vw; }
}
