/* Neurisko console: a 1981 Lisp machine in phosphor green.
   Contrast of every colour token is checked by tests/web/test_palette.py. */
:root {
  --bg: #0b0f0b;
  --panel: #0e140e;
  --fg: #39ff7a;
  --dim: #2bb35a;
  --amber: #ffb000;
  --red: #ff5f5f;
  --line: #1d5c33;
  --focus: #ffffff;
  --font: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font: 13px/1.45 var(--font);
  min-height: 100vh;
}
.screen { max-width: 1400px; margin: 0 auto; padding: 10px 16px 24px; }

h1, h2, h3 { font-weight: 700; letter-spacing: 0.06em; margin: 0 0 6px; }
h1 { font-size: 15px; }
h2 { font-size: 13px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
h3 { font-size: 12px; margin-top: 10px; }
p { margin: 4px 0; }
a { color: var(--fg); }
a:hover { color: var(--amber); }
code { color: var(--fg); }
pre { margin: 0; font: inherit; white-space: pre; overflow-x: auto; }
.small { font-size: 12px; }
.dim { color: var(--dim); }
.amber { color: var(--amber); }
.red { color: var(--red); }
.fg { color: var(--fg); }
.logo { font-size: 18px; letter-spacing: 0.25em; text-shadow: 0 0 6px rgba(57, 255, 122, 0.6); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 10; background: var(--bg); padding: 4px 8px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

button, select, input {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--dim);
  padding: 2px 8px;
  border-radius: 0;
}
button { cursor: pointer; }
button:hover, button[aria-pressed="true"] { background: var(--line); }
button:disabled, input:disabled { opacity: 0.5; cursor: default; }
input[type="number"] { width: 6em; }
input[type="range"] { accent-color: var(--fg); width: min(360px, 40vw); padding: 0; border: 0; }
input[type="checkbox"] { accent-color: var(--fg); padding: 0; }

/* --- header and toolbar ----------------------------------------------------------------- */
.top { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; justify-content: space-between; }
.top h1 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.crt-toggle { font-size: 11px; }
.toolbar, .live, .live form, #tabs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
}
.toolbar { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px 0; margin: 6px 0 10px; }
#tabs { gap: 4px; }
.live { margin: 6px 0; }
.live label { display: inline-flex; gap: 4px; align-items: center; }
[role="tab"] { border-color: var(--line); letter-spacing: 0.1em; }
[role="tab"][aria-selected="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.scrubber { display: flex; gap: 6px; align-items: center; }

/* --- panels ----------------------------------------------------------------------------- */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 10px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 10px;
  min-width: 0;
  overflow-x: auto;
}
.panel.wide { grid-column: 1 / -1; margin-bottom: 10px; }
#panel-run .panel { max-height: 330px; overflow: auto; }
.chart { color: var(--fg); line-height: 1.15; }
.legend span { font-weight: 700; }

table { border-collapse: collapse; width: 100%; }
th { text-align: left; color: var(--dim); font-weight: 400; border-bottom: 1px solid var(--line); }
td, th { padding: 1px 6px 1px 0; vertical-align: top; }
tr.sep td { height: 4px; border-bottom: 1px dashed var(--line); }
.worth-table td.id, .id { color: var(--amber); white-space: nowrap; }
.worth-table td.worth { white-space: pre; }
.worth-table td.rule { overflow-wrap: anywhere; }
.bar { white-space: pre; }
.flag-cleared { color: var(--dim); border-style: dashed; }
tr.row-parasite td { color: var(--red); }

.flag {
  display: inline-block; padding: 0 4px; margin: 0 2px 2px 0;
  border: 1px solid currentColor; font-size: 11px; white-space: nowrap;
}
.flag-parasite, .flag-failed, .flag-dominant { color: var(--red); }
.flag-duplicate, .flag-non-replicating, .flag-underused { color: var(--amber); }
.flag-retired { color: var(--dim); }
.flag-effective { color: var(--fg); }
.legend-box { margin-top: 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 2px 16px; color: var(--dim); }

.teletype { list-style: none; margin: 0; padding: 0; white-space: pre-wrap; }
.teletype li { padding: 0; }
.audit-demoted .check, .check-parasite { color: var(--red); }
.audit-merged .check { color: var(--amber); }
.audit-passed, .audit-clean { color: var(--dim); }

.champion { font-size: 14px; }
.unit { color: var(--fg); font-weight: 700; }
.battles button { display: block; margin: 3px 0; text-align: left; white-space: normal; }
details summary { cursor: pointer; color: var(--dim); }

/* --- report ----------------------------------------------------------------------------- */
.shares th[scope="row"] { color: var(--fg); }
tr.row-dominant th, tr.row-dominant td { color: var(--red); }
tr.row-underused th { color: var(--amber); }
tr.row-effective td { color: var(--fg); font-weight: 700; }
.patches caption { text-align: left; color: var(--dim); padding: 6px 0; }
.summary p { font-size: 14px; max-width: 110ch; }
.llm-summary { margin: 10px 0 0; border-left: 3px solid var(--amber); padding-left: 10px; }
.llm-summary blockquote { margin: 4px 0 0; max-width: 110ch; }
.evidence li, .kept li { margin: 2px 0; }

/* --- LLM --------------------------------------------------------------------------------- */
.prompt { white-space: pre-wrap; max-height: 260px; overflow: auto; border: 1px solid var(--line); padding: 6px; margin: 4px 0; }
.llm-calls { padding-left: 0; list-style: none; }
.llm-calls > li { border-bottom: 1px dashed var(--line); padding: 4px 0; }

/* --- battle dialog ----------------------------------------------------------------------- */
dialog { color: var(--fg); width: min(860px, 94vw); max-height: 88vh; padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
.dialog-body { padding: 10px 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.battle-log { max-height: 52vh; overflow: auto; border: 1px solid var(--line); padding: 6px; }
.ev-death { color: var(--red); }
.ev-heal { color: var(--fg); }
.ev-summon, .ev-synergy_on, .ev-synergy_off { color: var(--amber); }
.ev-dodge { color: var(--dim); }
.result { font-weight: 700; margin-top: 6px; }

/* --- battle arena (visual replay above the log) --------------------------------------- */
.arena { position: relative; border: 1px solid var(--line); background: var(--panel); margin: 6px 0; padding: 10px 8px; overflow: hidden; }
.arena ~ .battle-log { max-height: 24vh; }
.arena-monster { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; min-height: 150px; }
.arena .vs { font-size: 18px; font-weight: 700; color: var(--dim); letter-spacing: 0.1em; }
.wing { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.side { display: flex; gap: 6px; align-items: flex-end; min-height: 112px; }
.side-A { flex-direction: row-reverse; } /* A's front rank sits next to the centre */
.syn { display: flex; gap: 4px; flex-wrap: wrap; min-height: 18px; }
.wing:last-child .syn { justify-content: flex-start; }
.wing:first-child .syn { justify-content: flex-end; }
.chip { font-size: 11px; border: 1px solid var(--amber); color: var(--amber); padding: 0 5px; text-transform: uppercase; }
.u { position: relative; flex: 0 1 76px; min-width: 46px; border: 1px solid var(--line); background: var(--bg);
     padding: 4px 3px 3px; text-align: center; transition: opacity .4s, filter .4s, flex-basis .4s, min-width .4s; }
.u-A { border-color: var(--dim); }
.u-B { border-color: var(--amber); }
.u.front { box-shadow: 0 0 0 1px var(--fg), 0 0 10px rgba(255, 255, 255, 0.12); }
.u .ico { font-size: 30px; line-height: 1.1; }
.u .nm { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u .hp { height: 5px; border: 1px solid var(--line); margin: 3px 0 1px; }
.u .hp i { display: block; height: 100%; background: var(--fg); transition: width .2s; }
.u-B .hp i { background: var(--amber); }
.u .hp i.low { background: var(--red); }
.u .hpn { font-size: 10px; color: var(--dim); }
.u.dead { opacity: 0.18; filter: grayscale(1); flex-basis: 0; min-width: 0; padding: 0; border-width: 0; overflow: hidden; }
.u.lunge.u-A { animation: lungeA .22s; } .u.lunge.u-B { animation: lungeB .22s; }
@keyframes lungeA { 50% { transform: translateX(-10px) scale(1.05); } }
@keyframes lungeB { 50% { transform: translateX(10px) scale(1.05); } }
.u.cast { animation: cast .3s; }
@keyframes cast { 50% { box-shadow: 0 0 14px var(--amber); } }
.u.hit { animation: hit .25s; }
@keyframes hit { 25% { transform: translateX(3px); background: rgba(255, 95, 95, 0.35); } 75% { transform: translateX(-3px); } }
.u.healed { animation: healed .4s; }
@keyframes healed { 50% { box-shadow: 0 0 14px var(--fg); } }
.spawn { animation: spawn .35s ease-out; }
@keyframes spawn { from { transform: scale(0.2); opacity: 0; } }
.pop { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); font-weight: 700; font-size: 14px;
       pointer-events: none; animation: pop .9s ease-out forwards; text-shadow: 0 0 4px #000; }
.pop.dmg { color: var(--red); } .pop.heal { color: var(--fg); } .pop.miss { color: var(--dim); }
@keyframes pop { to { transform: translate(-50%, -26px); opacity: 0; } }

.arena-fleet { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; min-height: 160px; }
.fleet { min-width: 0; transition: opacity .6s; }
.fleet.out { opacity: 0.45; }
.fleet-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-bottom: 4px; }
.fleet-A .fleet-head b { color: var(--fg); } .fleet-B .fleet-head b { color: var(--amber); }
.fleet .count { color: var(--dim); }
.ships { display: flex; flex-wrap: wrap; gap: 1px 3px; align-content: flex-start; line-height: 1; }
.fleet-B .ships { flex-direction: row-reverse; }
.ship { display: inline-block; transition: color .3s, opacity .5s, transform .5s; }
.fleet-A .ship { color: var(--fg); } .fleet-B .ship { color: var(--amber); }
.ship.hull0 { font-size: 15px; } .ship.hull1 { font-size: 20px; } .ship.hull2 { font-size: 27px; } .ship.hull3 { font-size: 36px; }
.fleet .ship.disabled { color: var(--red); opacity: 0.75; transform: rotate(25deg); }
.fleet .ship.destroyed { color: var(--red); opacity: 0.12; }
.fleet .ship.scuttled { opacity: 0.05; transform: translateY(6px) scale(0.6); }
.ship.boom { animation: boom .45s; }
@keyframes boom { 30% { transform: scale(1.8); text-shadow: 0 0 8px var(--red); } }
.banner { margin-top: 6px; font-weight: 700; letter-spacing: 0.15em; color: var(--red); min-height: 1.2em; }
.banner.flash { animation: flash .6s 2; }
@keyframes flash { 50% { opacity: 0.2; } }
.tracers { position: absolute; inset: 0; pointer-events: none; }
.tracer { position: absolute; width: 22px; height: 2px; border-radius: 2px; opacity: 0; }
.tracer.from-A { left: 30%; background: var(--fg); box-shadow: 0 0 6px var(--fg); animation: shotA .45s ease-in forwards; }
.tracer.from-B { right: 30%; background: var(--amber); box-shadow: 0 0 6px var(--amber); animation: shotB .45s ease-in forwards; }
@keyframes shotA { 10% { opacity: 1; } to { left: 78%; opacity: 0.2; } }
@keyframes shotB { 10% { opacity: 1; } to { right: 78%; opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) {
  .arena *, .arena { animation: none !important; transition: none !important; }
  .tracers { display: none; }
}

footer { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 6px; }

/* --- CRT effect (off under prefers-reduced-motion unless the user turns it on) --------- */
body.crt::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px);
}
body.crt .screen { text-shadow: 0 0 2px rgba(57, 255, 122, 0.45); animation: flicker 6s infinite; }
@keyframes flicker { 0%, 96%, 100% { opacity: 1; } 97% { opacity: 0.93; } 98% { opacity: 1; } 99% { opacity: 0.96; } }
@media (prefers-reduced-motion: reduce) {
  body.crt .screen { animation: none; }
}

/* --- small screens ----------------------------------------------------------------------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  #panel-run .panel { max-height: none; }
  .top h1 .dim { display: block; }
}
@media (max-width: 600px) {
  .worth-table .origin, .worth-table th:nth-child(3), .worth-table .worth .bar { display: none; }
}
