/* Code Tank, in the browser.
 *
 * Dark, because the arena is dark and a bright page around it is unreadable on
 * a projector. One breakpoint at 1024px, which is the repo's second-most
 * common, because below that the editor and the arena cannot sit side by side
 * and a school Chromebook is usually right about there. */

:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-head: #18202b;
  --line: #243040;
  --text: #dde5ef;
  --dim: #8b9bb0;
  --accent: #5aa8e6;
  --warn: #e7c84b;
  --bad: #e2574c;
  --good: #5ad46a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

/* --- the bar across the top ------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--panel-head);
  flex-wrap: wrap;
}

/* The settings row. It wraps, but only between groups: a group is laid out
 * with nowrap so a label can never be parted from its dropdown. */
.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 7px 16px 9px;
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
}

.controls .group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  white-space: nowrap;
}

/* A thin rule between groups, so the eye can find the one it wants. */
.controls .group + .group:not(.actions)::before {
  content: "";
  width: 1px;
  height: 18px;
  background: var(--line);
  margin-right: 6px;
}

.controls .actions { gap: 8px; }

/* Nothing in the header moves when a mode hides a group. The field rule has
   to be here too: `.field` sets `display: flex`, which beats the browser's
   own `[hidden] { display: none }`, so a field the page hid went on showing.
   Survival kept offering Rounds that way. */
.controls .group[hidden],
.controls .field[hidden] { display: none; }

.bar h1 {
  font-size: 16px;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.01em;
}

.spacer { flex: 1 1 auto; }

.status {
  color: var(--dim);
  font-size: 12.5px;
}

.status.ready { color: var(--good); }
.status.busy { color: var(--warn); }
.status.failed { color: var(--bad); }

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--dim);
}

select, button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: #1d2634;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 10px;
}

button { cursor: pointer; }
button:hover:not(:disabled) { background: #26323f; }
button:disabled { opacity: 0.45; cursor: default; }

button#run {
  background: #1d4e78;
  border-color: #2d6fa8;
  font-weight: 600;
}

button#run:hover:not(:disabled) { background: #235c8d; }

/* The reference link. It is an anchor rather than a button because it opens
 * a page, and a student who wants it in a window of their own should be able
 * to get one the ordinary way. */
.reference {
  color: var(--accent);
  font-size: 12.5px;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 4px 9px;
}

.reference:hover {
  background: #1d2634;
  border-color: var(--line);
}

button.link {
  background: none;
  border: none;
  color: var(--dim);
  padding: 2px 4px;
  font-size: 12px;
  text-decoration: underline;
}

button.link:hover { color: var(--text); background: none; }

/* --- the two panes ---------------------------------------------------- */

/* Three columns: the editor, a gutter to drag, the arena. --editor-col is
 * set on the root element when the gutter is dragged and is remembered, so a
 * student who wants a wide editor keeps one. The narrow layout below
 * overrides the whole property, so the two never fight. */
main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns:
    var(--editor-col, minmax(380px, 1fr)) 6px minmax(420px, 1.15fr);
  background: var(--line);
  min-height: 0;
}

.gutter {
  background: var(--line);
  cursor: col-resize;
}

.gutter:hover, .gutter.dragging { background: var(--accent); }

/* While a drag is on, nothing else should be selecting text or catching the
 * pointer, the iframe-less equivalent of a modal drag. */
body.dragging { user-select: none; cursor: col-resize; }

.editor-pane, .arena-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hint { text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }

/* Whether this tank exists anywhere but the tab it is being typed in. The lab
 * machines wipe nightly, so this is worth a student's attention. */
.file-state {
  text-transform: none;
  letter-spacing: 0;
  color: var(--dim);
  font-size: 11.5px;
}

.file-state.unsaved { color: var(--warn); }
.file-state.saved { color: var(--good); }

.pane-head button:not(.link) {
  padding: 3px 9px;
  font-size: 12px;
}

/* Dropping a .py file anywhere on the editor opens it. */
.editor-pane.dropping {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

/* CodeMirror's own stylesheet is linked before this one, so these win on
 * order as well as on specificity. */
.editor-pane .CodeMirror {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  background: var(--panel);
  color: var(--text);
  /* --code-size is set from the A- and A+ buttons and remembered. */
  font: var(--code-size, 13px)/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* A- 13 A+, kept together so the number does not drift from its buttons. */
.sizer {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.sizer .hint {
  min-width: 18px;
  text-align: center;
  color: var(--dim);
}

button.icon {
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.2;
}

button.link.on {
  color: var(--accent);
  text-decoration: none;
  background: #1d2634;
  border-radius: 4px;
}

/* A panel head that is also a switch. The triangle says which way it goes. */
button.twist {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dim);
}

button.twist:hover { color: var(--text); background: none; }

button.twist::before {
  content: "\25be ";
  font-size: 9px;
  vertical-align: 1px;
}

.arena-pane.shut button.twist::before { content: "\25b8 "; }
.arena-pane.shut #console { display: none; }

.editor-pane .CodeMirror-gutters {
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.editor-pane .CodeMirror-linenumber { color: #4f6177; }
.editor-pane .CodeMirror-cursor { border-left-color: var(--accent); }
.editor-pane .CodeMirror-activeline-background { background: #161e28; }
.editor-pane .CodeMirror-selected { background: #2a3850; }
.editor-pane .cm-keyword { color: #c58fe0; }
.editor-pane .cm-def, .editor-pane .cm-variable-2 { color: #7fc4f0; }
.editor-pane .cm-string { color: #9bd98a; }
.editor-pane .cm-number { color: #e8b57a; }
.editor-pane .cm-comment { color: #647b93; font-style: italic; }
.editor-pane .cm-builtin { color: #6fd3c0; }
.editor-pane .cm-operator { color: #b7c4d4; }

/* --- the arena -------------------------------------------------------- */

#arena {
  flex: 1 1 auto;
  width: 100%;
  min-height: 240px;
  display: block;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.score .chip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.score .who { font-weight: 600; }

/* Which side a tank is on, in a team match. */
.score .side {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
}

.score .side.blue { background: rgba(77, 128, 255, 0.22); color: #9dc0ff; }
.score .side.red { background: rgba(255, 77, 77, 0.22); color: #ffa3a3; }
.score .nums { color: var(--dim); }
.score.out .who { color: var(--bad); text-decoration: line-through; }

/* --- what each tank did ------------------------------------------------
 *
 * main.gd pops this up in a modal when a match ends. A modal is the wrong
 * shape for a page a student fights twenty battles in, so it is a strip that
 * appears under the scoreboard and goes when the next battle starts. */

.results {
  border-top: 1px solid var(--line);
  padding: 7px 12px 9px;
  overflow-x: auto;
}

.results table {
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.results th {
  text-align: right;
  font-weight: 600;
  color: var(--dim);
  padding: 0 0 3px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.results td {
  text-align: right;
  padding: 2px 0 2px 14px;
  color: var(--text);
}

.results th:first-child, .results td:first-child {
  text-align: left;
  padding-left: 0;
}

.results td.who {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.results td.who .chip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.results td.none { color: var(--dim); }
.results tr.won td { color: var(--good); }
.results .note {
  color: var(--dim);
  font-size: 11.5px;
  padding-top: 5px;
}

/* --- the feed ---------------------------------------------------------
 *
 * Its own strip, not the output panel. The output panel belongs to whatever
 * the student's tank printed, and a wave of five enemies trading fire would
 * bury that in a few seconds. main.tscn gives it 50px and lets it scroll. */

.feed {
  height: 58px;
  min-height: 24px;
  max-height: 40vh;
  resize: vertical;
  overflow: auto;
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  background: #0e141b;
  font: 12px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--dim);
  overflow-wrap: anywhere;
}

.feed div { white-space: pre-wrap; }

/* Both of these can be dragged taller or shorter by their bottom edge, and
 * both remember where they were left. The arena takes whatever is over. */
#console {
  margin: 0;
  padding: 8px 12px;
  height: 148px;
  min-height: 40px;
  max-height: 60vh;
  resize: vertical;
  overflow: auto;
  font: 12.5px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: #b9c7d6;
  white-space: pre-wrap;
  word-break: break-word;
}

#console .err { color: var(--bad); }
#console .sys { color: var(--dim); }
#console .win { color: var(--good); }

@media (max-width: 1024px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 0.9fr) minmax(360px, 1fr);
  }
  .gutter { display: none; }
  #console { height: 110px; }
  .feed { height: 46px; }
}

/* --- the ladder ------------------------------------------------------- */

.ladder {
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--dim);
}

.ladder b { color: var(--text); font-weight: 600; }
.ladder .done { color: var(--good); }

.survival {
  display: flex;
  gap: 18px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}

.survival .big { font-size: 15px; font-weight: 650; color: var(--text); }
.survival .lives { letter-spacing: 2px; }
.survival .gone { color: var(--bad); }

/* Versus: the tanks lined up for a fight. */
.versus {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.versus .slot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  background: #1d2634;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}

.versus .slot .chip {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.versus .slot button {
  border: none;
  background: none;
  color: var(--dim);
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

.versus .slot button:hover { color: var(--bad); background: none; }
.versus .slot.mine { border-color: #2d6fa8; }

/* The side a tank is on in a team match, flipped by clicking it. */
.versus .slot .team {
  border: none;
  background: none;
  padding: 0 2px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 650;
}

.versus .slot .team.blue { color: #9dc0ff; }
.versus .slot .team.red { color: #ffa3a3; }
.versus .slot .team:hover { background: none; text-decoration: underline; }



/* The projector: the editor folds away and the arena takes the window.
 * main.gd:972 is the same button on the desktop build. */

/* The editor's own contents go; the column stays, and the words move into
 * it. The gutter goes too: there is nothing left to drag between. */
main.arena-only .editor-pane > .pane-head,
main.arena-only .editor-pane > .CodeMirror {
  display: none;
}

/* The gutter keeps its place in the grid even though there is nothing left
 * to drag: taking it out with display:none removes a grid item, and then the
 * arena pane lands in the empty middle track and is drawn no wider than it.
 * It is hidden rather than gone. */
main.arena-only .gutter {
  visibility: hidden;
  pointer-events: none;
}

main.arena-only {
  grid-template-columns: minmax(300px, 24%) 0 1fr;
}

/* The words, in the column the code was in, filling its height. */
main.arena-only .editor-pane > .said {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

main.arena-only .said .feed {
  flex: 1 1 auto;
  height: auto;
  min-height: 80px;
  resize: none;
}

main.arena-only .said #console {
  flex: 1 1 auto;
  height: auto;
  max-height: none;
  resize: none;
}

/* And with the words gone from under it, the arena takes what is left. */
main.arena-only .arena-pane { min-height: 0; }
main.arena-only #arena { height: 100%; }

.said {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Everything the room reads from the back of it gets bigger with the arena. */
main.arena-only .scoreboard { font-size: 15px; }
main.arena-only .score .chip { width: 12px; height: 12px; }
main.arena-only .feed { font-size: 14px; height: 76px; }
main.arena-only .ladder { font-size: 15px; }
main.arena-only .results table { font-size: 14px; }
main.arena-only .results th { font-size: 12.5px; }

/* --- the bracket -------------------------------------------------------
 *
 * Nearly the whole screen: this is the thing a class looks at between
 * matches, from the back of the room. */

#bracket-dialog {
  width: min(1500px, 96vw);
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

#bracket-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }

.bracket-scroll {
  overflow: auto;
  max-height: 82vh;
  padding: 12px;
}

#bracket { display: block; }

/* --- the tournament strip ---------------------------------------------- */

.tournament {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.tournament .big { font-size: 14px; font-weight: 650; color: var(--text); }
.tournament .versus-name { font-weight: 650; }
.tournament .problem { color: var(--warn); }
.tournament .done { color: var(--good); }

#reset-dialog {
  width: min(520px, 92vw);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

#reset-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog-body { padding: 14px; }
.dialog-body p { margin: 0 0 10px; }
.dialog-body ul { margin: 0 0 10px; padding-left: 22px; }
.dialog-body li { margin: 2px 0; }

/* The safe button first and wider, the one that cannot be undone last. */
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 4px;
}

button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

button.danger:hover { background: var(--bad); color: var(--panel); }

/* The strip is a line of text rather than a flex row, so this needs a gap of
   its own or it reads as part of the sentence before it. */
.reset-progress { margin-left: 14px; }

#source-dialog {
  width: min(860px, 92vw);
  max-height: 84vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

#source-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
}

#source {
  margin: 0;
  padding: 14px;
  max-height: 70vh;
  overflow: auto;
  font: 12.5px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre;
  color: #c3d1e0;
}
