/* UI chrome. The board itself is drawn in js/art.js. */
:root {
  --bg: #12161c; --panel: #1a2029; --line: #2a3340; --text: #e8edf2; --dim: #8b97a5;
  --bad: #e5484d; --good: #46c28a; --accent: #ffe14d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  display: flex; flex-direction: column; height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, sans-serif;
  position: relative; user-select: none; -webkit-user-select: none; touch-action: pan-x pan-y;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer;
}

header { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.stat { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.stat.big b { color: var(--accent); font-size: 21px; }
.stat.bad b { color: var(--bad); }
header button { width: 40px; height: 40px; padding: 0; flex: none; }

#goal {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 8px; width: 100%; text-align: left;
  padding: 6px 10px 7px; font-size: 12px; background: #151a21; color: var(--text);
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
}
/* The director's call next to what is actually reaching Program Out. */
#monitors { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 5px 10px; background: #151a21; border-bottom: 1px solid var(--line); border-left: 4px solid transparent; }
#monitors[hidden] { display: none; }
#monitors.bad { border-left-color: var(--bad); background: #24161a; }
/* Each screen takes half the strip on a phone, and no more than a fixed width on a wide
   screen, so the two stay side by side for comparison. */
#monitors .mon { flex: 1; max-width: 220px; min-width: 0; display: flex; align-items: center; gap: 8px; }
#monitors canvas { width: 54px; height: 38px; flex: none; }
#monitors .mon > div { min-width: 0; display: flex; flex-direction: column; font-size: 12px; line-height: 1.25; }
#monitors .cap { font-size: 9px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
#monitors b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* What is being recorded: one chip per recording the level asks for. A row of its own on a phone. */
#recs { flex: 1 1 100%; display: flex; align-items: center; gap: 6px; min-width: 0; }
#recs[hidden] { display: none; }
#rec-chips { display: flex; gap: 4px; flex-wrap: wrap; }
#rec-chips span { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--bad); color: #ff9a9d; white-space: nowrap; }
#rec-chips span.ok { border-color: var(--good); color: var(--good); }
@media (min-width: 760px) { #recs { flex: 0 1 auto; margin-left: 12px; } }
#mon-called-extra { font-style: normal; font-size: 11px; color: var(--dim); white-space: nowrap; }
#mon-status { font-style: normal; font-size: 11px; color: var(--good); white-space: nowrap; }
#monitors.wait #mon-status { color: var(--dim); }
#monitors.bad #mon-status { color: #ff9a9d; font-weight: 700; }
#goal .badge { background: var(--accent); color: #111; font-weight: 800; font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .04em; }
#goal-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#goal-status { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#goal .bar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: #2a3340; overflow: hidden; }
#goal .bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 3px; transition: width .3s; }
#goal.faulted .bar i { background: var(--bad); }
#goal.faulted #goal-status { color: #ff9a9d; }
#goal.done #goal-status { color: var(--good); }
#next-level {
  width: 100%; padding: 9px 10px; border: 0; border-radius: 0; font-size: 13px; font-weight: 700;
  background: var(--accent); color: #111; animation: nudge 1.6s ease-in-out infinite;
}
#next-level[hidden] { display: none; }
@keyframes nudge { 50% { filter: brightness(.82); } }
#log {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 5px 10px; font-size: 12px; line-height: 15px; height: 41px; flex: none; overflow: hidden; background: #0e1116; color: var(--dim);
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
}
/* Fixed two-line strip: long messages are cut off here and shown in full in the log. */
#log-text { flex: 1; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
#log .more { flex: none; font-size: 11px; opacity: .8; }
#log.fault { color: #fff; background: #7a1f23; }
#log .tick { color: var(--good); }
#log.lost, #log.refused { color: #f0b35a; }

#board { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; }

#info { padding: 6px 10px; min-height: 58px; font-size: 12px; color: var(--dim); background: var(--panel); border-top: 1px solid var(--line); }
#info b { color: var(--text); font-size: 13px; }
#info .spec { color: var(--accent); font-size: 11px; }

footer { display: flex; background: var(--panel); border-top: 1px solid var(--line); }
#tools { display: flex; padding: 5px 6px 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
#tools .group { flex: none; display: flex; flex-direction: column; gap: 4px; }
#tools .group + .group { margin-left: 8px; padding-left: 8px; border-left: 1px solid var(--line); }
/* The label sticks to the left edge while its group scrolls past. */
#tools .group > span {
  position: sticky; left: 0; align-self: flex-start; font-size: 9.5px; font-weight: 700; color: var(--dim);
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; padding: 0 2px;
}
#tools .group > div { display: flex; gap: 6px; }
#tools::-webkit-scrollbar { display: none; }
footer button {
  flex: none; width: 64px; padding: 5px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
footer button i {
  font-style: normal; font-weight: 700; font-size: 18px; width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center; background: #2a3340;
}
footer button canvas { display: block; }
footer button span { font-size: 9.5px; line-height: 1.1; color: var(--dim); text-align: center; height: 21px; overflow: hidden; }
footer button { position: relative; }
footer button em {
  position: absolute; top: -1px; right: -1px; font-style: normal; font-size: 8.5px; font-weight: 800; text-transform: uppercase;
  background: var(--accent); color: #111; padding: 1px 4px; border-radius: 0 7px 0 6px; letter-spacing: .03em;
}
footer button.on { border-color: var(--accent); background: #2a2f1e; }
footer button.on span { color: var(--text); }

/* Dialogs are opened with show(), not showModal(): the top layer would escape
   the zoom compensation applied to <body>. The huge shadow is the backdrop. */
dialog {
  position: absolute; top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%);
  margin: 0; max-height: 88%; z-index: 10; flex-direction: column;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  width: min(92%, 380px); padding: 16px; box-shadow: 0 0 0 200vmax #000b;
}
dialog[open] { display: flex; }
/* The title and Close button stay put; only the middle scrolls. */
:is(dialog, #level) .scroll { scrollbar-width: thin; scrollbar-color: var(--line) transparent; flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; margin-bottom: 10px; outline: none; }
:is(dialog, #level) h2 { margin: 0 0 6px; color: var(--accent); }
:is(dialog, #level) h3 { margin: 14px 0 4px; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
:is(dialog, #level) p { margin: 0 0 10px; color: var(--dim); }
dialog .row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
dialog .row > * { flex: 1; }
dialog input { font: inherit; font-size: 16px; /* below 16px iOS zooms the page on focus */ min-width: 0; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
#scores { margin: 0 0 10px; padding-left: 26px; }
#scores .none { list-style: none; margin-left: -26px; color: var(--dim); }
#close, #events-close { width: 100%; flex: none; }
:is(dialog, #level) p.done { color: var(--good); font-weight: 600; }
:is(dialog, #level) p.goalbox { color: var(--text); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; }
/* The level instructions live in a drawer on the right edge. It slides over the
   board without blocking it, and its tab stays on screen when it is closed. */
#level {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 9; width: min(86%, 340px);
  display: flex; flex-direction: column; padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease;
}
@media (prefers-reduced-motion: reduce) { #level { transition: none; } }
#level.open { transform: none; box-shadow: -12px 0 30px #0009; }
/* On a wide screen there is room for both: the open drawer takes its own column
   and everything else narrows to sit beside it. */
@media (min-width: 900px) {
  body.brief-open { padding-right: calc(340px + env(safe-area-inset-right)); }
  #level.open { box-shadow: none; }
}
#level-tab {
  position: absolute; right: 100%; top: 42%; width: 30px; padding: 12px 0; margin-right: -1px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border-radius: 10px 0 0 10px; border-right: none; background: var(--panel); color: var(--accent); font-weight: 700;
}
#level-tab .word { writing-mode: vertical-rl; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--text); }
#level-new { list-style: none; margin: 0 0 4px; padding: 0; font-size: 12px; color: var(--dim); }
#level-new li { margin-bottom: 8px; min-height: 34px; }
#level-new canvas { float: left; margin: 1px 8px 2px 0; }
#level-new b { color: var(--text); font-size: 13px; }
#level-new .spec { color: var(--accent); font-size: 11px; white-space: nowrap; }
#roadmap { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--dim); }
#roadmap li { padding: 6px 0 6px 10px; border-left: 3px solid var(--line); margin-bottom: 6px; }
#roadmap li b { color: var(--text); font-size: 13px; }
#roadmap .spec { color: var(--accent); font-size: 11px; white-space: nowrap; }
#roadmap li.current { border-left-color: var(--accent); }
#roadmap li.done { border-left-color: var(--good); }
#roadmap li.done b { color: var(--good); }
#roadmap li.locked { opacity: .6; }
#roadmap li button { float: right; margin: 0 0 4px 8px; padding: 4px 10px; font-size: 12px; }
#level-next { width: 100%; flex: none; margin-bottom: 0; background: var(--accent); color: #111; font-weight: 700; border-color: var(--accent); }
#summary, #history { list-style: none; margin: 0 0 10px; padding: 0; font-size: 12px; }
#summary li, #history li { padding: 5px 0 5px 44px; text-indent: -44px; border-bottom: 1px solid var(--line); color: var(--dim); }
#summary li.fault, #history li.fault { color: #ff9a9d; }
#summary li.lost, #history li.lost, #summary li.refused, #history li.refused { color: #f0b35a; }
#summary .lead, #history .lead { display: inline-block; width: 44px; text-indent: 0; color: var(--dim); font-variant-numeric: tabular-nums; }
#summary .spec, #history .spec { color: var(--accent); font-size: 11px; white-space: nowrap; }
#summary .none { padding-left: 0; text-indent: 0; }

#goal .tally { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); vertical-align: 0; }
dialog .hint { font-size: 12px; opacity: .7; margin: -4px 0 8px; }
dialog button.danger { border-color: var(--bad); color: #ff9a9d; }
