:root {
  --bg: #0d1022;
  --panel: #171b36;
  --panel-2: #1f2446;
  --line: #3b4580;
  --text: #ece8d8;
  --dim: #9aa0c0;
  --gold: #e8c840;
  --red: #e04848;
  --blue: #4a7cf0;
  --bad: #ff8a7a;
  --code-bg: #0a0c1a;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.45;
}

.top {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 20px 10px;
  border-bottom: 2px solid var(--line);
}
.top h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold);
}
.tag { color: var(--dim); }
/* Who is signed in, at the right end of the header. */
.account { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.account-name { color: var(--dim); }
.account a.button { color: var(--text); background: var(--panel-2); border: 1px solid var(--line); padding: 6px 12px; text-decoration: none; }
.account a.button:hover { border-color: var(--gold); }
.dev-sign-in { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0; }
.error.inline { margin: 0; }
.account button.quiet { border-color: transparent; background: none; color: var(--dim); padding: 6px 4px; }
.account button.quiet:hover { color: var(--text); }

/* The first sign-in and deleting the account. */
.welcome { max-width: 560px; margin: 24px auto; }
.welcome label, dialog label { display: block; color: var(--gold); font-weight: 700; letter-spacing: 1px; margin: 12px 0 4px; }
.welcome label.check { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-weight: 400; letter-spacing: 0; }
.welcome input[type="text"], dialog input[type="text"] { width: 100%; box-sizing: border-box; }
.welcome a { color: var(--gold); }
.welcome .note.good { color: var(--good, #7fd18b); }
.welcome .note.bad { color: var(--bad); }
/* Messages to a player about what a moderator did. */
.notices { border-color: var(--gold); }
.notices .notice { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-top: 8px; }
.notices .notice:first-of-type { margin-top: 0; }
.notices .notice button { flex: none; white-space: nowrap; }

/* The moderation page. */
.moderation { margin-bottom: 14px; }
.moderation label { display: block; color: var(--gold); font-weight: 700; letter-spacing: 1px; margin: 0 0 4px; }
.moderation input[type="text"] { width: 100%; box-sizing: border-box; }
.mod-row { display: flex; gap: 8px; margin: 0; }
.mod-row input[type="text"] { flex: 1; width: auto; }
.mod-account { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.mod-account h3 { margin: 0; font-size: 14px; }
.mod-sub { color: var(--dim); margin-top: 10px; }
.mod-log { list-style: none; margin: 8px 0; padding: 0; }
.mod-log li { border-top: 1px solid var(--line); padding: 6px 0; overflow-wrap: anywhere; }
.mod-log li:first-child { border-top: 0; }
.mod-log .kind { margin-left: 0; }
.mod-action { color: var(--gold); font-weight: 700; }
button.danger { border-color: var(--bad); color: var(--bad); }
.moderation .char-actions { flex-wrap: wrap; }

dialog.panel { color: var(--text); max-width: 480px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

/* ---- shared controls ---- */

button, select, input[type="text"] {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 6px 12px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--gold); }
button.primary { background: var(--gold); color: #1a1608; border-color: var(--gold); font-weight: 700; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 12px 14px;
}
.panel h2, .character-head h2 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
}
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

.dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; flex: none; }
.dot.a { background: var(--red); }
.dot.b { background: var(--blue); }
.dot.c { background: #3fae5a; }
.room-switch { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.room-panels { display: flex; flex-direction: column; gap: 12px; }
.versus.many { flex-wrap: wrap; gap: 10px 22px; max-width: 520px; }
.versus.many .versus-side { flex: 0 0 44%; }
.versus.many .versus-name { font-size: 16px; }
.versus-name.c { color: #6fd088; }
.versus-name.d { color: #f0c850; }
.dot.d { background: #e0b030; }
.dot.water { background: #6a98e0; }
.dot.fire { background: #f08020; }
.error { color: var(--bad); margin: 8px 0 0; overflow-wrap: anywhere; }
.note { color: var(--dim); margin: 8px 0 0; }
.note.first { margin-top: 0; }
.note.inline { margin: 0; }
.who { display: inline-flex; align-items: center; font-weight: 700; }
.kind { color: var(--dim); margin-left: 8px; }

/* ---- the match viewer ---- */

.board-wrap {
  position: relative;
  border: 2px solid var(--line);
  background: #000;
  line-height: 0;
}
.board {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  display: block;
}
.banner {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  max-width: 86%;
  padding: 12px 18px;
  background: rgba(13, 16, 34, 0.94);
  border: 2px solid var(--gold);
  color: var(--text);
  line-height: 1.45;
  text-align: center;
}
.banner strong { display: block; font-size: 18px; color: var(--gold); margin-bottom: 4px; }

.caption { min-height: 24px; padding: 8px 2px 0; }
.debug-line { color: #8fd0a0; padding: 2px 2px 0; overflow-wrap: anywhere; }
.hover { color: var(--dim); min-height: 22px; padding: 4px 2px 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.controls label { color: var(--dim); display: inline-flex; align-items: center; gap: 6px; }
.controls .check { margin-left: auto; }
.scrub { width: 100%; margin: 10px 0 2px; accent-color: var(--gold); }
.progress { color: var(--dim); }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card { background: var(--panel-2); border: 1px solid var(--line); padding: 10px; min-height: 112px; }
.card.active { border-color: var(--gold); }
.card .name { font-weight: 700; display: flex; align-items: center; }
.card .bot { color: var(--dim); margin-bottom: 6px; }
.card .row { display: flex; justify-content: space-between; gap: 8px; }
.card .row span:first-child { color: var(--dim); }
.pips { display: inline-flex; gap: 2px; align-items: center; }
.pips i { width: 8px; height: 10px; background: #3a3f66; display: inline-block; }
.pips i.on { background: #6fd060; }
.pips i.water.on { background: #6a98e0; }
.pips i.fire.on { background: #f08020; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  color: var(--dim);
  font-size: 13px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend canvas { width: 20px; height: 20px; image-rendering: pixelated; border: 1px solid var(--line); }

/* ---- the break between two games ---- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: rgba(13, 16, 34, 0.84);
  line-height: 1.3;
  text-align: center;
}
.break-last { color: var(--gold); font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.break-title { color: var(--dim); font-size: 13px; letter-spacing: 3px; text-transform: uppercase; }
.break-map { color: var(--gold); font-size: 16px; font-weight: 700; margin: 6px 0 10px; }
.break-hint { color: var(--dim); font-size: 13px; margin-top: 8px; }
.break-hint.new-map { margin: -6px 0 10px; }

/* The banner for GPUFlight under the rankings. */
.sponsor { display: block; text-decoration: none; text-align: center; }
.sponsor:hover { border-color: var(--gold); }
.sponsor-by { display: block; color: var(--dim); font-size: 12px; }
.sponsor-name { display: block; color: var(--gold); font-size: 20px; font-weight: 700; letter-spacing: 2px; margin: 2px 0; }
.sponsor-line { display: block; color: var(--text); font-size: 13px; }

/* The footer of the game page, and the pages with the terms and the privacy notice. */
.site-footer { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; padding: 18px 16px 26px; color: var(--dim); font-size: 13px; }
.site-footer a, .legal a, .home { color: var(--gold); text-decoration: none; }
.site-footer a:hover, .legal a:hover { text-decoration: underline; }
.home { color: inherit; }
.legal { max-width: 760px; margin: 0 auto; padding: 8px 20px 40px; }
.legal h2 { color: var(--gold); font-size: 15px; margin: 26px 0 8px; }
.legal p, .legal li { color: var(--text); }
.legal ul { padding-left: 20px; }
.legal li { margin-bottom: 6px; }
.legal table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.legal th, .legal td { text-align: left; vertical-align: top; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.legal th { color: var(--dim); font-weight: 400; }
.legal .draft { border: 1px solid var(--bad); color: var(--bad); padding: 10px 12px; margin-top: 16px; }
.legal .legal-links { margin-top: 30px; color: var(--dim); }
.version-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.version-row label { color: var(--dim); display: inline-flex; align-items: center; gap: 6px; }
.practice-setup #practice-cards { margin-top: 14px; }
.practice-setup .queue { margin-top: 12px; }
.queue li.computer .who { font-weight: 400; color: var(--dim); }
.versus { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 20px; }
.versus-name { font-size: 28px; font-weight: 700; }
.versus-name.a { color: #ff7070; }
.versus-name.b { color: #7fa4ff; }
.versus-kind { color: var(--dim); font-size: 13px; }
.versus-vs { color: var(--gold); font-size: 16px; letter-spacing: 2px; text-transform: uppercase; }
.break-wait { margin-top: 10px; }
.break-count { color: var(--gold); font-size: 76px; font-weight: 700; line-height: 1; animation: count-pop 0.9s ease-out; }
@keyframes count-pop {
  from { transform: scale(1.6); opacity: 0.3; }
  30% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .break-count { animation: none; }
}

/* ---- the battle view ---- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 660px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.characters { list-style: none; margin: 0; padding: 0; }
.characters li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.characters li:first-child { border-top: 0; padding-top: 0; }
.char-info { min-width: 0; }
.char-status { color: var(--dim); }
.char-actions { display: flex; gap: 8px; }

.queue { margin: 6px 0 0; padding-left: 26px; }
.queue li { padding: 2px 0; }
.queue li.mine .who, .ranking tr.mine td { color: var(--gold); }

.ranking { width: 100%; border-collapse: collapse; }
.ranking th {
  text-align: left;
  color: var(--dim);
  font-weight: 400;
  padding: 2px 8px 4px 0;
  border-bottom: 1px solid var(--line);
}
.ranking td { padding: 3px 8px 3px 0; }
.ranking th:nth-child(n+4), .ranking td:nth-child(n+4) { text-align: right; padding-right: 0; padding-left: 8px; }
.ranking .who { font-weight: 400; }
.ranking .champ { color: var(--dim); margin-left: 8px; }
.by-map tr.map-first td { padding-top: 8px; }
.by-map .map-name { display: block; font-weight: 700; }
.by-map .map-games { display: block; color: var(--dim); font-size: 12px; }
.by-map td:first-child { vertical-align: top; }

/* ---- the character page ---- */

.character-page { padding: 16px 20px 24px; max-width: 1400px; margin: 0 auto; }
.character-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.character-head h2 { margin: 0; font-size: 16px; }

.character-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 12px; }
.character-form label { color: var(--dim); display: inline-flex; align-items: center; gap: 8px; }
.character-form input { width: 220px; }
.character-form .error { flex-basis: 100%; margin: 0; }
.fixed-element { color: var(--dim); }

.workbench { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); gap: 16px; align-items: start; }
.simulate { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.simulate label { color: var(--dim); display: inline-flex; align-items: center; gap: 8px; }

/* The editor: a transparent textarea on top of a coloured copy of its text.
   Both layers must share every text metric, or the caret drifts. */
.code-editor {
  position: relative;
  height: 640px;
  background: var(--code-bg);
  border: 1px solid var(--line);
}
.code-editor .code-layer, .code-editor .code-input {
  position: absolute;
  inset: 0;
  margin: 0;
  border: 0;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0;
  font-variant-ligatures: none;
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
}
.code-editor .code-layer {
  overflow: hidden;
  pointer-events: none;
  color: #dfe6ff;
  padding-bottom: 48px;
}
.code-editor .code-layer code { font: inherit; color: inherit; }
.code-editor .code-input {
  width: 100%;
  height: 100%;
  overflow: auto;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: #ffffff;
  outline-offset: -2px;
}
.code-editor .code-input::selection { background: rgba(110, 140, 255, 0.4); color: transparent; }

.tok-comment { color: #7f8aa8; }
.tok-string { color: #a5d6a0; }
.tok-number { color: #f0a868; }
.tok-keyword { color: #c792ea; }
.tok-game { color: #f0d060; }
.tok-helper { color: #7fd4f0; }
.tok-call { color: #82aaff; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button { border-bottom: 0; color: var(--dim); }
.tabs button[aria-selected="true"] { background: var(--gold); border-color: var(--gold); color: #1a1608; font-weight: 700; }

.guide { font-size: 13px; max-height: 688px; overflow-y: auto; padding-right: 6px; }
.guide details { border-top: 1px solid var(--line); }
.guide details:first-child { border-top: 0; }
.guide summary { cursor: pointer; padding: 8px 0; color: var(--gold); font-weight: 700; letter-spacing: 1px; }
.guide-body { padding-bottom: 10px; }
.guide p { margin: 0 0 8px; }
.guide ul { margin: 0 0 8px; padding-left: 18px; }
.guide li { margin-bottom: 3px; }
.guide table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.guide td, .guide th { text-align: left; vertical-align: top; padding: 4px 8px 4px 0; border-top: 1px solid #2a3160; }
.guide th { color: var(--dim); font-weight: 400; padding-top: 10px; border-top: 0; }
.guide td:first-child { white-space: nowrap; }
.guide code { color: #dfe6ff; font-family: var(--mono); }
.snippet {
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  color: #dfe6ff;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
}
.snippet code { color: inherit; }

#pane-sim .cards { margin-top: 10px; }

@media (max-width: 1000px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 20px; }
  .character-page { padding: 12px 16px 20px; }
  .controls .check { margin-left: 0; }
  .guide td:first-child { white-space: normal; }
  .character-form input { width: 100%; }
}

/* The simulation controls sit above the practice map. */
#pane-sim .simulate { margin-bottom: 8px; }
#sim-result { margin: 0 0 10px; min-height: 20px; }

/* ---- the AI help tab ---- */

.ai-help { font-size: 13px; }
.ai-help p { margin: 0 0 8px; }
.ai-help ol { margin: 0 0 12px; padding-left: 20px; }
.ai-help li { margin-bottom: 3px; }
.ai-help label { display: block; color: var(--gold); font-weight: 700; letter-spacing: 1px; margin: 10px 0 4px; }
.ai-help textarea {
  width: 100%;
  resize: vertical;
  background: var(--code-bg);
  color: #dfe6ff;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.ai-questions { border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 4px; }
.ai-questions label:first-child { margin-top: 0; }
.ai-questions .ai-restart { margin-top: 8px; }

/* ---- flags ---- */

.flag { image-rendering: pixelated; border: 1px solid #000; flex: none; vertical-align: middle; margin-right: 8px; }
.card .name .flag { margin-right: 6px; }
.versus-name { display: flex; align-items: center; justify-content: center; }
.versus-name .flag { margin-right: 12px; }
.flag-button { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px 4px 4px; }
.flag-button .flag { margin-right: 6px; }

.flag-editor { font-size: 13px; }
.flag-editor p { margin: 0 0 8px; }
.flag-editor h4 { margin: 12px 0 6px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold); }
.flag-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.flag-preset { padding: 4px; line-height: 0; }
.flag-preset .flag { margin: 0; }
.flag-draw { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.flag-grid { width: 250px; height: 250px; border: 1px solid var(--line); cursor: crosshair; touch-action: none; }
.flag-tools { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.flag-palette { display: grid; grid-template-columns: repeat(8, 26px); gap: 4px; }
.flag-color { width: 26px; height: 26px; padding: 0; border: 2px solid var(--line); }
.flag-color[aria-pressed="true"] { border-color: #ffffff; outline: 2px solid var(--gold); }
.flag-preview { display: flex; align-items: center; gap: 10px; color: var(--dim); }
.flag-preview-slot { display: inline-flex; align-items: center; gap: 10px; }
.flag-preview .flag { margin: 0; }

/* ---- test results on the character page ---- */

.test-results { flex-basis: 100%; font-size: 13px; }
.test-title { font-weight: 700; margin-bottom: 4px; }
.test-results ul { list-style: none; margin: 0; padding: 0; }
.test-results li { padding: 2px 0; }
.test-state { display: inline-block; min-width: 72px; font-weight: 700; color: var(--dim); }
.test-passed .test-state { color: #6fd060; }
.test-failed .test-state, .test-failed .test-detail { color: var(--bad); }
.test-running .test-state { color: var(--gold); }
.test-detail { padding-left: 72px; overflow-wrap: anywhere; }

/* ---- versions and recorded battles ---- */

.ver { margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); color: var(--dim); font-size: 12px; font-weight: 400; }
.versus-name .ver { margin-left: 10px; font-size: 14px; }
.versus-name.open { color: var(--dim); }
.battles { font-size: 13px; }
.battles-list { list-style: none; margin: 8px 0 12px; padding: 0; }
.battles-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.battles-list .kind { margin-left: 0; }
.battle-won { color: #6fd060; font-weight: 700; }
.battle-lost { color: var(--bad); font-weight: 700; }
.ai-help select { width: 100%; }
#pane-battles .cards { margin-top: 10px; }
