/* The class database: a small tool, not a website. RocketHour's canonical tokens (shared/design/CANONICAL.md) in the
   dashboard grammar: warm neutrals, tight radii, soft shadows, Bricolage for words, JetBrains Mono for code and values.
   Violet only at identity points (the logo, the live dot's ring); Volt only on Run. Light and dark from one set. */

@font-face { font-family: 'Bricolage Grotesque'; src: url('fonts/bricolage-variable.woff2') format('woff2'); font-weight: 200 800; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('fonts/jetbrains-500.woff2') format('woff2'); font-weight: 400 600; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('fonts/jetbrains-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --brand: #BB24ED;
  --volt: #C7F900;
  --volt-on: #141210;
  --live: #00D97E;
  --danger: #DC2837;
  --success: #16A22D;
  --warning: #D97706;
  --r1: 4px;
  --r2: 6px;
  --r3: 10px;
  --ui: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
:root[data-theme='light'] {
  color-scheme: light;
  --canvas: #F5F2EE;
  --panel: #FFFFFF;
  --raised: #EEEAE5;
  --line: #E2DDD7;
  --line-strong: #C2BEBA;
  --muted: #6E6B66;
  --ink: #141210;
  --locked: #F3F0EC;
  --locked-ink: #6E6B66;
  --select: rgba(187, 36, 237, 0.14);
  --shadow: 0 1px 2px rgba(20, 18, 16, 0.06), 0 4px 16px rgba(20, 18, 16, 0.06);
  --pass: #16A22D;
  --cm-key: #8A1BB0;
  --cm-string: #0B7A3B;
  --cm-number: #B45309;
  --cm-tag: #1F5FB8;
  --cm-attr: #8A5A00;
  --cm-comment: #8C8782;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --canvas: #141210;
  --panel: #1C1A18;
  --raised: #252321;
  --line: #302E2B;
  --line-strong: #4A4743;
  --muted: #A39E98;
  --ink: #F5F2EE;
  --locked: #191715;
  --locked-ink: #8C8782;
  --select: rgba(187, 36, 237, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
  --pass: #3ECF5A;
  --cm-key: #D58BF2;
  --cm-string: #8BD9A6;
  --cm-number: #F2B46B;
  --cm-tag: #7FB2F0;
  --cm-attr: #E6C27A;
  --cm-comment: #7D7873;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 500 14px/1.45 var(--ui);
  font-synthesis: none;
  font-variation-settings: 'wdth' 100;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); }

.shell { height: 100vh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.top {
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-name { font-weight: 750; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.parts { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.parts::-webkit-scrollbar { display: none; }
.part-tab {
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: var(--r2);
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.part-tab:hover { background: var(--raised); color: var(--ink); }
.part-tab[aria-current='true'] { background: var(--raised); color: var(--ink); }
.part-tab[disabled] { opacity: 0.45; cursor: not-allowed; }
.part-tab .count { font: 600 11px/1 var(--mono); color: var(--muted); }
.part-tab .lvl { font: 700 10px/1 var(--mono); letter-spacing: 0.08em; padding: 3px 5px; border-radius: var(--r1); border: 1px solid var(--line-strong); color: var(--muted); }
.top-side { display: flex; align-items: center; gap: 6px; flex: none; }
.conn { display: inline-flex; align-items: center; gap: 6px; font: 600 11px/1 var(--mono); letter-spacing: 0.04em; color: var(--muted); padding: 5px 8px; border-radius: var(--r2); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.conn[data-state='up'] .dot { background: var(--live); box-shadow: 0 0 0 3px rgba(0, 217, 126, 0.18); }
.conn[data-state='down'] .dot, .conn[data-state='connecting'] .dot { background: var(--warning); }
.icon-btn { border: 1px solid transparent; background: none; width: 30px; height: 30px; border-radius: var(--r2); display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--raised); color: var(--ink); }

/* ---------- the work area ---------- */
.work { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(360px, 46%) 1fr; }
.code-col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.right-col { display: grid; grid-template-rows: minmax(240px, 1.45fr) minmax(160px, 1fr); min-height: 0; min-width: 0; }

.job { padding: 12px 16px 10px; border-bottom: 1px solid var(--line); flex: none; }
.job-row { display: flex; align-items: baseline; gap: 10px; }
.step-no { font: 700 11px/1 var(--mono); letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; white-space: nowrap; }
.job h1 { margin: 0; font-size: 18px; line-height: 1.2; font-weight: 750; letter-spacing: -0.01em; }
.how { margin: 6px 0 0; color: var(--ink); max-width: 68ch; }
.how .chip {
  font: 600 12px/1 var(--mono);
  border: 1px solid var(--line-strong);
  background: var(--raised);
  border-radius: var(--r1);
  padding: 3px 5px;
  cursor: pointer;
  color: var(--ink);
}
.how .chip:hover { border-color: var(--ink); }
.steps { display: flex; gap: 4px; margin: 10px 0 0; flex-wrap: wrap; }
.step-dot {
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--r1);
  border: 1px solid var(--line-strong);
  background: none;
  font: 600 11px/1 var(--mono);
  color: var(--muted);
  cursor: pointer;
}
.step-dot.done { border-color: transparent; background: var(--raised); color: var(--pass); }
.step-dot[aria-current='true'] { border-color: var(--ink); color: var(--ink); background: var(--panel); box-shadow: inset 0 0 0 1px var(--ink); }
.step-dot[disabled] { opacity: 0.4; cursor: not-allowed; }
.run-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.btn { border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--r2); padding: 7px 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.btn:hover { border-color: var(--ink); }
.btn.run { background: var(--volt); color: var(--volt-on); border-color: var(--volt); }
.btn.run:hover { filter: brightness(0.96); border-color: var(--volt); }
.btn.run[disabled] { opacity: 0.6; cursor: progress; }
.btn.next { margin-left: auto; }
.checks { display: inline-flex; gap: 5px; align-items: center; }
.checks .c { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.checks .c.pass { background: var(--pass); border-color: var(--pass); }
.checks .c.fail { background: var(--danger); border-color: var(--danger); }
.checks .c.busy { border-color: var(--muted); border-top-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .checks .c.busy { animation: none; } }
.verdict { margin: 8px 0 0; min-height: 0; font-weight: 600; }
.verdict:empty { display: none; }
.verdict.fail { color: var(--danger); }
.verdict.pass { color: var(--pass); }
.verdict.info { color: var(--muted); font-weight: 500; }

.help { display: flex; align-items: flex-start; gap: 10px; margin-top: 8px; }
.help-btn { flex: none; font-size: 13px; padding: 5px 10px; }
.help-text { margin: 0; padding: 6px 10px; border-left: 3px solid var(--brand); background: var(--raised); border-radius: 0 var(--r2) var(--r2) 0; max-width: 62ch; }
.help-text:empty { display: none; }
.help-text.waiting { color: var(--muted); border-left-color: var(--line-strong); }
.help-text code { font: 600 12.5px/1 var(--mono); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r1); padding: 1px 4px; }
.editor-wrap { flex: 1; min-height: 0; overflow: auto; position: relative; }
#editor .CodeMirror { height: auto; font: 500 13.5px/1.6 var(--mono); background: var(--panel); color: var(--ink); }
#editor .CodeMirror-gutters { background: var(--panel); border-right: 1px solid var(--line); }
#editor .CodeMirror-linenumber { color: var(--muted); opacity: 0.7; padding: 0 8px 0 6px; }
#editor .CodeMirror-cursor { border-left: 2px solid var(--ink); }
#editor .CodeMirror-selected, #editor .CodeMirror-focused .CodeMirror-selected { background: var(--select); }
#editor .locked-line { background: var(--locked); }
#editor .cm-locked { color: var(--locked-ink); }
#editor .cm-locked .cm-keyword, #editor .cm-locked .cm-string, #editor .cm-locked .cm-number, #editor .cm-locked .cm-tag, #editor .cm-locked .cm-attribute, #editor .cm-locked .cm-def, #editor .cm-locked .cm-variable, #editor .cm-locked .cm-property { opacity: 0.85; }
#editor .cm-keyword { color: var(--cm-key); }
#editor .cm-string, #editor .cm-string-2 { color: var(--cm-string); }
#editor .cm-number, #editor .cm-atom { color: var(--cm-number); }
#editor .cm-tag, #editor .cm-bracket { color: var(--cm-tag); }
#editor .cm-attribute, #editor .cm-qualifier { color: var(--cm-attr); }
#editor .cm-comment { color: var(--cm-comment); font-style: normal; }
#editor .cm-def, #editor .cm-variable, #editor .cm-variable-2, #editor .cm-property { color: var(--ink); }
#editor .CodeMirror-matchingbracket { color: var(--ink) !important; background: var(--select); }
#editor .err-line { background: rgba(220, 40, 55, 0.12) !important; }
.band {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 4px 2px;
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.band .given { font-weight: 600; letter-spacing: 0.06em; text-transform: none; opacity: 0.8; }
.band .yours { color: var(--ink); letter-spacing: 0.06em; text-transform: none; }

.dev { display: flex; gap: 6px; align-items: center; padding: 6px 12px; border-top: 1px dashed var(--line-strong); background: var(--raised); flex: none; }
.dev-tag { font: 700 10px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--brand); margin-right: 4px; }
.dev button { border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--r1); padding: 4px 8px; font-weight: 650; cursor: pointer; font-size: 12px; }

/* ---------- boxes on the right ---------- */
.players-box, .db-box { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.players-box { border-bottom: 1px solid var(--line); }
.box-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; flex-wrap: wrap; }
.box-title { font: 700 11px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-right: auto; }
.seg { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r2); padding: 2px; background: var(--canvas); }
.seg-label { font: 600 11px/1 var(--mono); color: var(--muted); padding: 0 6px 0 4px; }
.seg button { border: 0; background: none; border-radius: var(--r1); padding: 4px 9px; font-weight: 650; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed='true'] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.seg button[disabled] { opacity: 0.4; cursor: not-allowed; }

.players { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px; background: var(--canvas); }
.players[data-n='1'] { grid-template-columns: 1fr; }
.players[data-n='2'] { grid-template-columns: 1fr 1fr; }
.players[data-n='3'], .players[data-n='4'] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.player { display: flex; flex-direction: column; min-height: 0; min-width: 0; border: 1px solid var(--line); border-radius: var(--r3); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.player-label { display: flex; gap: 6px; align-items: center; padding: 4px 8px; font: 600 11px/1.2 var(--mono); color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line); }
.player-label b { color: var(--ink); font-weight: 700; }
.player iframe { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; display: block; }
.app-note { margin: 0; padding: 0 10px 8px; color: var(--danger); font-weight: 600; background: var(--canvas); }
.app-note:empty { display: none; }
.app-note.info { color: var(--muted); font-weight: 500; }

body.players-full .players-box { position: fixed; inset: 0; z-index: 50; background: var(--canvas); }
body.players-full .db-box { display: none; }

/* ---------- the database ---------- */
.db-box { background: var(--panel); }
.db-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); flex: none; flex-wrap: wrap; }
.db-head select { font: 600 12.5px/1 var(--mono); border: 1px solid var(--line); background: var(--canvas); color: var(--ink); border-radius: var(--r2); padding: 5px 8px; max-width: 220px; }
.db-meta { font: 500 11px/1.2 var(--mono); color: var(--muted); }
.db-actions { margin-left: auto; display: flex; gap: 6px; }
.db-actions button { border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--r1); padding: 4px 8px; font-weight: 650; font-size: 12px; cursor: pointer; }
.db-actions button.danger { color: var(--danger); }
.db-actions button.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
.db-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.grid-wrap, .hist-wrap { overflow: auto; min-height: 0; }
.grid-wrap { border-right: 1px solid var(--line); }
table.rows { width: 100%; border-collapse: collapse; font: 500 12.5px/1.35 var(--mono); }
table.rows th { position: sticky; top: 0; background: var(--panel); text-align: left; font: 700 10px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); padding: 7px 10px; border-bottom: 1px solid var(--line); }
table.rows td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: break-word; }
table.rows td.v { color: var(--ink); font-weight: 600; }
table.rows td.v.text { color: var(--cm-string); }
table.rows td.v.number { color: var(--cm-number); }
table.rows td.dim { color: var(--muted); white-space: nowrap; }
table.rows td.k, table.rows td.t { white-space: nowrap; }
table.rows th:nth-child(3), table.rows th:nth-child(4), table.rows th:nth-child(5) { white-space: nowrap; width: 1%; }
table.rows tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: rgba(199, 249, 0, 0.35); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { table.rows tr.flash td { animation: none; } }
.type { font: 600 10px/1 var(--mono); padding: 2px 5px; border-radius: var(--r1); border: 1px solid var(--line); color: var(--muted); }
.empty { padding: 16px 12px; color: var(--muted); }
.hist { list-style: none; margin: 0; padding: 4px 0; font: 500 12px/1.4 var(--mono); }
.hist li { padding: 5px 10px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: auto auto 1fr; gap: 0 8px; align-items: baseline; }
.hist .when { color: var(--muted); font-size: 11px; }
.hist .op { font-weight: 700; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; padding: 2px 5px; border-radius: var(--r1); }
.hist .op.created { background: rgba(22, 162, 45, 0.14); color: var(--pass); }
.hist .op.updated { background: rgba(217, 119, 6, 0.14); color: var(--warning); }
.hist .op.deleted { background: rgba(220, 40, 55, 0.12); color: var(--danger); }
.hist .op.read { background: var(--raised); color: var(--muted); }
.hist .what { grid-column: 3; overflow-wrap: anywhere; }
.hist .who { color: var(--ink); font-weight: 700; }
.people { display: flex; gap: 4px; flex-wrap: wrap; }
.people span { font: 600 11px/1 var(--mono); padding: 3px 6px; border-radius: 999px; background: var(--raised); color: var(--muted); }

/* Narrow: the rows and the history take turns, and the time column goes (the history has it). */
.db-view { display: none; }
@media (max-width: 1180px) {
  .db-view { display: inline-flex; }
  .db-body { grid-template-columns: 1fr; }
  .grid-wrap { border-right: 0; }
  .db-box:not([data-view='hist']) .hist-wrap { display: none; }
  .db-box[data-view='hist'] .grid-wrap { display: none; }
  table.rows th:nth-child(5), table.rows td:nth-child(5) { display: none; }
}

/* ---------- the explanation pop ---------- */
.pop { position: fixed; z-index: 80; max-width: 360px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow); padding: 12px 14px; }
.pop h3 { margin: 0 0 6px; font: 700 13px/1.3 var(--mono); }
.pop p { margin: 0 0 8px; }
.pop pre { margin: 0; font: 500 12.5px/1.5 var(--mono); background: var(--canvas); border-radius: var(--r2); padding: 8px 10px; white-space: pre-wrap; }

.check-bay { position: fixed; left: -10000px; top: 0; width: 600px; height: 400px; overflow: hidden; }
.check-bay iframe { width: 600px; height: 400px; border: 0; }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100vh; }
  .work { grid-template-columns: 1fr; }
  .code-col { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-wrap { max-height: 60vh; }
  .right-col { grid-template-rows: 380px 320px; }
  .brand-name { display: none; }
}
