:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18202b;
  --line: #243041;
  --text: #dbe4ee;
  --muted: #7d8da1;
  --accent: #4fa8ff;
  --accent-dim: #4fa8ff26;
  --ok: #3ccf8e;
  --ok-dim: #3ccf8e22;
  --warn: #f0b44c;
  --rec: #ff4d4d;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 5px 10px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04111f; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.ghost { background: transparent; }
button.icon { background: transparent; border: 0; font-size: 16px; color: var(--muted); padding: 4px 8px; }
code { font-family: var(--mono); font-size: 12px; }

/* ------------------------------------------------------------ header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; padding: 12px 20px; background: #0b0f14ee; backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 16px; letter-spacing: .04em; text-transform: uppercase; }
.brand .sub { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 10px var(--rec); align-self: center; }
.progress { flex: 1; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; min-width: 0; }
.bar { flex: 0 1 220px; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); }
.tools { display: flex; align-items: center; gap: 12px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; user-select: none; }
#keyBtn.on { color: var(--ok); border-color: #3ccf8e55; }
.tools.grow { flex: 1; min-width: 0; }
.home { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.home:hover h1 { color: var(--accent); }
.crumb { color: var(--line); }
.game-name { font-weight: 600; }
a.btn { display: inline-block; text-decoration: none; color: inherit; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 5px 10px; }
a.btn.ghost { background: transparent; }
a.btn:hover { border-color: var(--accent); }
select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; max-width: 100%; }
select:focus { outline: none; border-color: var(--accent); }
a { color: var(--accent); }
kbd { font: 11px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; background: var(--panel-2); }
.hint { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
button.small { font-size: 12px; padding: 2px 8px; }

/* ------------------------------------------------------------ layout */
.layout { display: grid; grid-template-columns: 250px 1fr; max-width: 1200px; margin: 0 auto; }
nav { position: sticky; top: 53px; align-self: start; max-height: calc(100vh - 53px); overflow: auto; padding: 16px 8px 16px 16px; }
nav a { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 13px; }
nav a:hover { background: var(--panel); color: var(--text); }
nav a .n { font-family: var(--mono); font-size: 11px; }
nav a.done .n { color: var(--ok); }
main { padding: 16px 20px 80px; min-width: 0; }
.empty { color: var(--muted); }

/* ------------------------------------------------------------ events */
.event { margin-bottom: 28px; scroll-margin-top: 70px; }
.ev-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.ev-head h2 { margin: 0; font-size: 17px; }
.ev-key { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.ev-when { color: var(--muted); margin: 0 0 10px; }
.same { color: var(--muted); font-style: italic; }
.same a { color: var(--accent); }

.line { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.line.has { border-left-color: var(--ok); }
.line-head { display: flex; gap: 12px; align-items: flex-start; }
.line-text { flex: 1; min-width: 0; }
.quote { font-size: 15px; font-weight: 500; }
.meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meta b { font-weight: 500; color: #a9b8c9; }

.files { margin-top: 10px; display: grid; gap: 4px; }
.frow { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 6px; }
.frow:hover { background: var(--panel-2); }
.frow .tag { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); width: 64px; flex: none; }
.frow.main .tag { color: var(--ok); }
.fname { font-family: var(--mono); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nofile { color: var(--muted); font-style: italic; flex: 1; }
.frow button.small { font-size: 12px; padding: 2px 8px; }
.badge-main { font-size: 11px; color: var(--ok); background: var(--ok-dim); border-radius: 10px; padding: 1px 8px; }
.danger:hover:not(:disabled) { border-color: var(--rec) !important; color: var(--rec); }

/* the list's play buttons: a ring that fills as it plays */
.pbtn { --p: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 10px;
  background: radial-gradient(var(--panel-2) 60%, transparent 61%), conic-gradient(var(--accent) calc(var(--p) * 1turn), var(--line) 0); border: 0; }
.pbtn:hover { color: var(--accent); }
.pbtn.playing { color: var(--accent); }

/* ------------------------------------------------------------ dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(620px, calc(100vw - 32px)); box-shadow: 0 20px 60px #000a; }
dialog::backdrop { background: #000a; }
.dlg-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; margin: 0; }
.dlg-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.dlg-title { font-size: 17px; font-weight: 600; margin-top: 2px; }
.dlg-meta { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.pane { padding: 16px 18px; min-height: 150px; }

.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 118px; border: 1.5px dashed var(--line); border-radius: var(--radius); cursor: pointer; text-align: center; padding: 10px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-dim); }
.drop-big { font-weight: 600; }
.drop-small { color: var(--muted); font-size: 12px; word-break: break-all; }
.drop.picked .drop-small { color: var(--text); font-family: var(--mono); }

.rec { display: grid; grid-template-columns: auto auto 110px 1fr; align-items: center; gap: 14px; }
.rec-btn, .stop-btn { width: 54px; height: 54px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: var(--panel-2); }
.rec-btn span { width: 22px; height: 22px; border-radius: 50%; background: var(--rec); }
.rec-btn.live { border-color: var(--rec); animation: pulse 1.2s infinite; }
.stop-btn span { width: 18px; height: 18px; border-radius: 3px; background: var(--text); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px #ff4d4d22; } }
.rec-time { font-family: var(--mono); font-size: 20px; }
.rec-state { color: var(--muted); font-size: 12px; }
.rec-state.err { color: var(--rec); }
.scope { width: 100%; height: 70px; background: var(--bg); border-radius: 6px; }

.strip { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--panel-2); border-top: 1px solid var(--line); }
.strip .play { width: 38px; height: 38px; border-radius: 50%; padding: 0; flex: none; }
.wave-wrap { position: relative; flex: 1; height: 56px; min-width: 0; }
.wave { width: 100%; height: 100%; display: block; cursor: pointer; }
.wave-empty[hidden] { display: none; }
.wave-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; pointer-events: none; border: 1px dashed var(--line); border-radius: 6px; }
.dur { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.dlg-status { min-height: 0; padding: 0 18px; font-size: 12px; }
.dlg-status:not(:empty) { padding: 8px 18px 12px; }
.dlg-status.err { color: var(--rec); }

.key-form { padding: 18px; display: grid; gap: 10px; }
.key-form p { margin: 0; color: var(--muted); }
.key-form input { font: 13px var(--mono); background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.key-form input:focus { outline: none; border-color: var(--accent); }
.key-err { color: var(--rec); font-size: 12px; min-height: 1em; }
.key-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; pointer-events: none; z-index: 20; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--rec); color: #ffb3b3; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  nav { display: none; }
  .top { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .progress { order: 3; flex-basis: 100%; }
  main { padding: 12px 16px 60px; }
  .rec { grid-template-columns: auto auto 1fr; }
  .scope { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------ admin: disabled things, forms */
.ev-actions { margin-left: auto; display: flex; gap: 6px; }
.ev-actions button, .line-head .acts button { font-size: 12px; padding: 2px 8px; }
.line-head .acts { display: flex; gap: 6px; flex: none; align-items: center; }
.chip.off { color: var(--warn); border-color: #f0b44c55; }
.event.off > .ev-head h2, .event.off > .ev-when { opacity: .5; }
.event.off .line, .line.off { opacity: .45; }
.event.off .line:hover, .line.off:hover { opacity: .8; }
.line.off { border-left-color: var(--warn); border-style: dashed; }
.add-line { width: 100%; border-style: dashed; background: transparent; color: var(--muted); padding: 8px; }
.add-line:hover { color: var(--text); }
nav a.off span:first-child { text-decoration: line-through; opacity: .6; }
.fields { display: grid; gap: 12px; margin-top: 6px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.field small { color: var(--muted); font-size: 11px; }
.field input, .field textarea, .field select { font: inherit; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); }

.field textarea.code { font: 12px/1.5 var(--mono); min-height: 160px; }
.chip.warn { color: var(--warn); border-color: #f0b44c55; }

/* ------------------------------------------------------------ home: the games */
main.home { max-width: 1000px; margin: 0 auto; padding: 28px 20px 80px; display: block; }
.home-title { margin: 0 0 4px; font-size: 22px; }
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.game-card { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.game-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.gc-title { font-size: 17px; font-weight: 600; }
.gc-id { font: 12px var(--mono); color: var(--muted); }
.gc-desc { color: #a9b8c9; margin: 6px 0 10px; flex: 1; white-space: pre-line; }
.gc-desc.err { color: var(--rec); }
.gc-stats { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.gc-stats .bar { flex: none; width: 100%; }
.api-doc { margin-top: 36px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px; }
.api-doc summary { cursor: pointer; font-weight: 600; }
.api-doc p { color: var(--muted); }
.api-doc table { border-collapse: collapse; width: 100%; }
.api-doc td { padding: 6px 12px 6px 0; border-top: 1px solid var(--line); vertical-align: top; color: #a9b8c9; }
.api-doc td:first-child { white-space: nowrap; color: var(--text); }

/* ------------------------------------------------------------ demo */
.vol { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.vol input { width: 90px; accent-color: var(--accent); }
.demo-layout { display: grid; grid-template-columns: 1fr 380px; max-width: 1300px; margin: 0 auto; }
.demo-layout main { padding: 18px 20px 80px; }
.demo-layout aside { position: sticky; top: 53px; align-self: start; height: calc(100vh - 53px); display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); }
.ev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; align-items: start; }
.ev-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ev-card.off { opacity: .45; }
.ev-fire { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; padding: 12px 14px 8px; }
.ev-fire:hover:not(:disabled) { background: var(--accent-dim); }
.ev-fire:active:not(:disabled) { background: #4fa8ff44; }
.ev-title { font-weight: 600; }
.ev-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 14px 10px; }
.ev-foot .lines-btn { margin-left: auto; }
.ev-lines { border-top: 1px solid var(--line); padding: 6px; display: grid; gap: 2px; }
.ev-line { text-align: left; border: 0; background: transparent; padding: 5px 8px; font-size: 13px; }
.ev-line:hover { background: var(--panel-2); }
.ev-line.nofile { color: var(--muted); font-style: italic; }
.who { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-right: 4px; font-style: normal; }
.ev-card.flash { animation: flash .7s; }
.ev-card.miss { animation: miss .5s; }
@keyframes flash { 0% { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); } }
@keyframes miss { 0% { border-color: var(--warn); } 30% { transform: translateX(-3px); } 60% { transform: translateX(3px); } }

.feed-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.feed-head h2 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.feed { flex: 1; overflow: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.fitem { border-radius: 8px; padding: 8px 10px; background: var(--panel-2); border: 1px solid transparent; animation: fin .25s; }
@keyframes fin { from { opacity: 0; transform: translateY(-4px); } }
.fitem.trig { background: transparent; padding: 4px 10px; font-size: 12px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.fitem.trig .fres { margin-left: auto; color: var(--ok); }
.fitem.trig.miss .fres { color: var(--warn); }
.ftime { font: 11px var(--mono); color: var(--muted); }
.fitem.said.live { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.fline { display: flex; gap: 8px; align-items: baseline; }
.fline .ton { color: var(--muted); font-size: 11px; }
.ffile { font: 11px var(--mono); color: var(--muted); }
.ffile.none { color: var(--warn); font-family: inherit; font-style: italic; }
.snippet { border-top: 1px solid var(--line); padding: 10px 16px 14px; }
.snippet summary { cursor: pointer; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.snippet pre { margin: 8px 0 0; padding: 10px; background: var(--bg); border-radius: 6px; overflow: auto; max-height: 220px; }
.snippet code { font-size: 11px; line-height: 1.5; color: #a9b8c9; }

@media (max-width: 900px) {
  .demo-layout { grid-template-columns: 1fr; }
  .demo-layout aside { position: static; height: auto; max-height: none; border-left: 0; border-top: 1px solid var(--line); }
  .feed { max-height: 50vh; }
  .top .tools { flex-wrap: wrap; }
  .tools.grow { flex-basis: 100%; order: 3; }
}

/* ------------------------------------------------------------ new proposals, review */
.frow.new .tag { color: var(--accent); font-weight: 600; }
.frow.new { background: var(--accent-dim); }
.frow.current { box-shadow: 0 0 0 2px var(--accent); }
.line.has-new { border-left-color: var(--accent); }
nav a .new-n { margin-left: auto; font: 600 10px var(--mono); color: #04111f; background: var(--accent); border-radius: 8px; padding: 1px 6px; align-self: center; }
#reviewBtn .count { font: 600 11px var(--mono); margin-left: 4px; padding: 0 6px; border-radius: 8px; background: var(--line); color: var(--muted); }
#reviewBtn .count.on { background: var(--accent); color: #04111f; }

.review { position: fixed; right: 20px; bottom: 20px; z-index: 6; width: min(400px, calc(100vw - 32px)); max-height: calc(100vh - 100px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 20px 60px #000a; }
.review[hidden] { display: none; }
body.reviewing main { padding-bottom: 360px; }
.rv-head { display: flex; align-items: center; gap: 10px; padding: 10px 8px 4px 16px; }
.rv-pos { font: 12px var(--mono); color: var(--muted); }
.rv-head .icon { margin-left: auto; }
.rv-body { padding: 4px 16px 10px; }
.rv-ev { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.rv-done { color: var(--ok); margin: 6px 0; }
.rv-acts { display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.rv-list { border-top: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.rv-list summary { cursor: pointer; padding: 8px 16px; color: var(--muted); font-size: 12px; }
.rv-keys { float: right; font: 10px var(--mono); opacity: .7; }
#rvList { overflow: auto; max-height: 220px; padding: 0 8px 8px; display: grid; gap: 2px; }
.rv-item { display: grid; text-align: left; border: 0; background: transparent; padding: 5px 8px; }
.rv-item:hover { background: var(--panel-2); }
.rv-item.on { background: var(--accent-dim); }
.rv-item-ev { font-size: 11px; color: var(--muted); }
.rv-item-txt { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) { .review { right: 16px; bottom: 16px; } }
.rv-body .files { grid-template-columns: minmax(0, 1fr); }

/* ------------------------------------------------------------ languages */
#langSel { max-width: 220px; }
.lchips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lchip { font: 600 10px var(--mono); letter-spacing: .04em; padding: 1px 7px; border-radius: 10px; color: var(--muted); background: transparent; border: 1px dashed var(--line); display: inline-flex; align-items: center; gap: 4px; }
.lchip.has { color: var(--ok); border: 1px solid #3ccf8e55; background: var(--ok-dim); }
.lchip.cur { box-shadow: 0 0 0 1.5px var(--accent); }
.lchip i { font-style: normal; color: #04111f; background: var(--accent); border-radius: 6px; padding: 0 4px; }
.chip.lang { color: var(--accent); border-color: #4fa8ff55; }
.lang-note { color: var(--muted); background: var(--accent-dim); border: 1px solid #4fa8ff44; border-radius: var(--radius); padding: 8px 12px; margin: 0 0 18px; }
.legacy { max-width: 620px; margin: 40px auto; padding: 22px 24px; background: var(--panel); border: 1px solid var(--warn); border-radius: 12px; }
.legacy h2 { margin: 0 0 8px; font-size: 18px; }
.legacy p { color: #a9b8c9; }
.gc-langs { display: flex; flex-wrap: wrap; gap: 4px; }
.progress span { white-space: nowrap; }
.progress .bar { min-width: 60px; }
