/* 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;
}
#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.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. */
dialog .scroll { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; margin-bottom: 10px; outline: none; }
dialog h2 { margin: 0 0 6px; color: var(--accent); }
dialog h3 { margin: 14px 0 4px; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
dialog 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, #level-close { width: 100%; flex: none; }
dialog p.done { color: var(--good); font-weight: 600; }
dialog p.goalbox { color: var(--text); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; }
#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: 8px; 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; }
