:root {
  --bg: #15130f;
  --panel: #1f1c17;
  --panel-2: #29251e;
  --line: #3a342a;
  --text: #ece4d4;
  --muted: #a79d8a;
  --gold: #d9a441;
  --gold-2: #f0c060;
  --missing: #d0533f;
  --review: #e0a028;
  --done: #4caf6a;
  --source: #7c8aa5;
  --focus: #f0c060;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-2); }

/* --- header -------------------------------------------------------------------------------- */
header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header.top .brand { font-weight: 700; color: var(--gold); letter-spacing: .02em; margin-right: 8px; }
header.top nav { display: flex; gap: 4px; }
header.top .spacer { flex: 1; }
.tab {
  background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 12px; cursor: pointer; color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold-2); border-color: var(--line); background: var(--panel-2); }

/* --- controls ------------------------------------------------------------------------------ */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: #4a3812; border-color: var(--gold); color: var(--gold-2); }
.btn.primary:hover:not(:disabled) { background: #5c4516; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.danger { border-color: #6d2e24; }
input[type=text], input[type=password], input[type=search], select, textarea {
  background: #100e0b; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; color: var(--gold); }
.card h3 { margin: 16px 0 8px; font-size: 14px; }

/* --- status flag --------------------------------------------------------------------------- */
.flag {
  width: 18px; height: 18px; flex: none; border: 0; padding: 0; background: none; cursor: pointer;
  display: inline-grid; place-items: center;
}
.flag svg { width: 16px; height: 16px; }
.flag[data-s=missing] { color: var(--missing); }
.flag[data-s=review] { color: var(--review); }
.flag[data-s=done] { color: var(--done); }
.flag[data-s=source] { color: var(--source); cursor: default; }
.flag:disabled { cursor: default; }
.legend { display: inline-flex; gap: 12px; align-items: center; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; gap: 4px; align-items: center; }

/* --- table --------------------------------------------------------------------------------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; }
.toolbar input[type=search] { width: 240px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 2px 10px; cursor: pointer;
  font-size: 12px; color: var(--muted);
}
.chip.on { color: var(--text); border-color: var(--gold); background: #3a2d12; }
.chip .count { color: var(--review); margin-left: 4px; }
.tablewrap { overflow: auto; height: calc(100vh - 150px); border-top: 1px solid var(--line); }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.grid th, table.grid td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  vertical-align: top; padding: 5px 8px; text-align: left;
}
table.grid thead th {
  position: sticky; top: 0; background: var(--panel-2); z-index: 5; font-weight: 600; white-space: nowrap;
}
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--gold-2); }
table.grid th .sortmark { color: var(--gold); margin-left: 4px; }
table.grid td.key, table.grid th.key {
  position: sticky; left: 0; background: var(--panel); z-index: 3; font-family: var(--mono); font-size: 12px;
  width: 230px; max-width: 230px; word-break: break-all;
}
table.grid thead th.key { z-index: 6; }
table.grid td.cell { width: 240px; max-width: 320px; min-width: 180px; }
table.grid td.cell .wrap { display: flex; gap: 6px; align-items: flex-start; }
table.grid td.cell .txt { flex: 1; white-space: pre-wrap; word-break: break-word; cursor: text; min-height: 1.4em; }
table.grid td.cell .txt.empty::before { content: '—'; color: var(--muted); }
table.grid td.cell.readonly .txt { cursor: default; }
table.grid td.cell .hist { visibility: hidden; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; }
table.grid td.cell:hover .hist { visibility: visible; }
table.grid td.cell textarea { width: 100%; min-height: 60px; resize: vertical; }
table.grid td.src { background: #1a1813; }
table.grid tr:hover td { background: #231f19; }
table.grid tr:hover td.key { background: #26221b; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* --- one by one ---------------------------------------------------------------------------- */
.obo { max-width: 1320px; margin: 0 auto; padding: 16px; }
.obo .progress { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.stage {
  /* As wide as possible while the editor below still fits on screen. */
  position: relative; width: min(100%, calc((100vh - 360px) * 16 / 9)); min-width: min(100%, 480px); margin: 0 auto; aspect-ratio: 16 / 9; background: #0c0b09; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden;
}
.stage iframe {
  position: absolute; left: 0; top: 0; width: 1280px; height: 720px; border: 0; transform-origin: 0 0;
  pointer-events: none;   /* screenshot source only: the game must never get the mouse or keyboard */
}
.stage img.shot { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; z-index: 2; }
.stage .overlay { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.stage .hl {
  position: absolute; border: 2px solid var(--gold-2); border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35), 0 0 12px var(--gold-2);
}
.stage .hl + .hl { box-shadow: 0 0 12px var(--gold-2); }
.stage .badge {
  position: absolute; z-index: 4; right: 8px; top: 8px; background: rgba(0, 0, 0, .7); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--muted);
}
.stage .note {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; text-align: center; padding: 32px;
  color: var(--muted); background: rgba(12, 11, 9, .92);
}
.obo .info { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.obo .info .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.obo .source-text { white-space: pre-wrap; background: #100e0b; border: 1px solid var(--line); border-radius: 6px; padding: 8px; min-height: 80px; }
.obo textarea.editor { width: 100%; min-height: 80px; resize: vertical; }
.obo .problems { color: var(--missing); font-size: 13px; }
.obo .context { background: #221d12; border-left: 3px solid var(--gold); padding: 6px 10px; border-radius: 4px; }
.obo .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.obo .kbd { font-size: 11px; color: var(--muted); }
.langpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.langpick button { text-align: left; padding: 12px; }
@media (max-width: 800px) { .obo .info { grid-template-columns: 1fr; } }

/* --- admin --------------------------------------------------------------------------------- */
.admin { display: grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr)); gap: 16px; padding: 16px; }
@media (max-width: 600px) { .admin { grid-template-columns: 1fr; } }
table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; }
.diff-from { color: #e48a7a; text-decoration: line-through; }
.diff-to { color: #9fd8a9; }
.scroll { max-height: 420px; overflow: auto; }
progress { width: 100%; }

/* --- modal / toast / login ----------------------------------------------------------------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--gold); border-radius: 10px; padding: 18px; width: min(760px, 100%); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; color: var(--gold); font-size: 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; max-width: 90vw;
}
.toast.error { border-color: var(--missing); }
.login { max-width: 360px; margin: 12vh auto; }
.login input { width: 100%; }
