:root {
  --bg: #0d1424;
  --panel: #16203a;
  --panel-2: #1d2a4a;
  --text: #eef3ff;
  --muted: #b4c0dc;
  --line: #3a4a75;
  --accent: #66d9ef;
  --good: #7ee787;
  --bad: #ff8b8b;
  --warn: #ffd166;
  --focus: #ffd166;
}

* { box-sizing: border-box; }

/* Leave room for the sticky control bar when the browser scrolls a focused control into view. */
html { scroll-padding-bottom: 6rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 1rem; }

code, .acl code, .mirror { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.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; top: 0; background: var(--warn); color: #000; padding: .5rem 1rem;
}
.skip:focus { left: 0; z-index: 10; }

/* Every interactive thing gets a visible focus ring. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.top {
  display: flex; flex-wrap: wrap; gap: .5rem 2rem; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.status { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; color: var(--muted); }
.health { display: inline-flex; gap: .6rem; align-items: center; color: var(--text); font-weight: bold; }
.hearts { color: #ff6b81; font-size: 1.4rem; letter-spacing: .1rem; }

main { padding: 1rem; max-width: 80rem; margin: 0 auto; }

.panel, #screen:not(:empty) {
  background: var(--panel); border: 1px solid var(--line); border-radius: .5rem; padding: 1rem;
}
#screen:not(:empty) { margin-bottom: 1rem; max-width: 46rem; }
#screen p { max-width: 62ch; white-space: pre-line; }
#screen .plain { white-space: normal; }
.note { color: var(--muted); margin: 0 0 .5rem; }

/* Results: a big banner says at a glance whether the wave was cleared or failed. */
#screen.results:not(:empty) { max-width: 72rem; }
.banner { display: flex; align-items: center; gap: 1rem; padding: .9rem 1.1rem; border-radius: .6rem; border: 3px solid; margin-bottom: 1rem; flex-wrap: wrap; }
.banner.pass { background: #0e3b22; border-color: var(--good); }
.banner.fail { background: #461520; border-color: var(--bad); }
.banner-icon { display: grid; place-items: center; width: 3.4rem; height: 3.4rem; border-radius: 50%; font-size: 2.2rem; font-weight: bold; color: #08140d; flex: none; }
.banner.pass .banner-icon { background: var(--good); }
.banner.fail .banner-icon { background: var(--bad); }
.banner-text { flex: 1 1 14rem; }
.banner-text h2 { font-size: 1.8rem; margin: 0; }
.banner-text p { margin: .15rem 0 0; color: var(--text); }
.banner .primary { font-size: 1.05rem; padding: .6rem 1.2rem; }

.tiles { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .6rem; padding: 0; margin: 0 0 1rem; }
.tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: .5rem; padding: .5rem .75rem; display: flex; flex-direction: column; }
.tile .lbl { color: var(--muted); font-size: .85rem; }
.tile .num { font-size: 1.4rem; font-weight: bold; }

#screen h3 { margin: 1rem 0 .5rem; }
.nothing { color: var(--good); font-weight: bold; }
.wrong { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
details.miss { background: var(--panel-2); border: 1px solid var(--line); border-left: 6px solid var(--bad); border-radius: .4rem; }
details.miss summary { cursor: pointer; padding: .55rem .75rem; display: grid; grid-template-columns: auto 1fr; gap: .1rem .6rem; align-items: baseline; }
details.miss summary:hover { background: #24345c; }
.miss-icon { color: var(--bad); font-weight: bold; grid-row: 1 / span 3; font-size: 1.3rem; }
.miss-main { font-size: 1rem; }
.miss-main .pk { font-weight: bold; }
.miss-what { color: var(--bad); font-weight: bold; margin-left: .4rem; }
.miss-fix { grid-column: 2; }
.miss-fix strong { color: var(--warn); }
.miss-why { grid-column: 2; color: var(--muted); }
details.miss .why { padding: 0 .75rem .6rem 2.6rem; }
details.miss .why ul { margin: .25rem 0 .25rem 1.1rem; padding: 0; }
details.sources ul { margin: .4rem 0 0 1.1rem; padding: 0; }
details.sources li { margin: .3rem 0; }

/* Briefing: short cards side by side, so the start screen is not a wall of text. */
#screen.wide:not(:empty) { max-width: 72rem; }
.brief { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: .75rem; margin: .5rem 0 1rem; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: .5rem; padding: .75rem 1rem; }
.card h3 { margin: 0 0 .4rem; color: var(--accent); font-size: 1.05rem; }
.card ul { margin: .25rem 0; padding-left: 1.1rem; }
.card li { margin: .2rem 0; }
.card p { margin: .4rem 0; }
.example { background: #0a1020; border: 1px solid var(--line); border-radius: .35rem; padding: .4rem .6rem; margin: .4rem 0; }
.example code { display: block; white-space: pre-wrap; }
.start-row { display: flex; gap: .75rem; align-items: center; margin: .5rem 0; }
.start-row .note { margin: 0; }
details.sources { color: var(--muted); font-size: .9rem; }
details.sources summary { cursor: pointer; }

/* Wide windows: the access list and the feedback share the left column, so an explanation is
   always visible beside the playfield instead of below the fold. */
#game {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 26rem) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "acl field" "feedback field";
  margin-bottom: 1rem;
  align-items: start;
}
#game[hidden] { display: none; }
#acl-panel { grid-area: acl; }
#field-panel { grid-area: field; }
#feedback-panel { grid-area: feedback; }

.scroll { max-height: 22rem; overflow: auto; border: 1px solid var(--line); border-radius: .25rem; }
.acl { list-style: none; margin: 0; padding: 0; }
.acl li { padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
.acl li:last-child { border-bottom: 0; }
.acl li.implicit { color: var(--muted); font-style: italic; }
.acl li.decider { background: #3b3410; outline: 2px solid var(--warn); outline-offset: -2px; }
.acl li.decider::after { content: "  ◀ decided"; color: var(--warn); font-weight: bold; }
.review { padding-left: 1.25rem; }
.review > li { margin-bottom: .75rem; }

/* The whole playfield must fit on screen above the control bar, so its height is capped to the window. */
#field { width: 100%; max-width: 46rem; height: auto; max-height: calc(100vh - 17rem); margin-inline: auto; background: #070c1a; border: 1px solid var(--line); border-radius: .25rem; display: block; }
#field-panel .note { margin-bottom: .25rem; }
#field-panel h2 { margin-bottom: .25rem; }
.star { fill: #3b4a7a; }
.network { fill: #0f3a22; }
.network-label { fill: #9be7b0; font: bold 14px system-ui, sans-serif; }
.network-line { stroke: #2f8f5b; stroke-width: 2; stroke-dasharray: 8 6; }
.ship { fill: var(--accent); stroke: #0b3c47; stroke-width: 2; }
.ship-label { fill: var(--muted); font: 11px system-ui, sans-serif; }
.bullet { fill: var(--warn); }
.packet rect { fill: #2a3b6d; stroke: var(--accent); stroke-width: 2; }
.packet text { fill: var(--text); font: 12px ui-monospace, Consolas, monospace; }
.fx { fill: none; stroke-width: 4; }
.fx-ok { stroke: var(--good); }
.fx-bad { stroke: var(--bad); }
.paused-veil { fill: #000; fill-opacity: .55; }
.paused-text { fill: #fff; font: bold 40px system-ui, sans-serif; }

.mirror { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.mirror li { padding: .25rem 0; border-bottom: 1px dotted var(--line); }

.fb { border-left: 6px solid var(--line); padding: .5rem .75rem; background: var(--panel-2); border-radius: .25rem; }
.fb-good { border-left-color: var(--good); }
.fb-bad { border-left-color: var(--bad); }
.fb-hint { border-left-color: var(--accent); }
.fb p { margin: .25rem 0; }
.fb ul { margin: .25rem 0 .25rem 1.25rem; padding: 0; }
.fb .tag { font-weight: bold; }
.fb-good .tag { color: var(--good); }
.fb-bad .tag { color: var(--bad); }
.fb-hint .tag { color: var(--accent); }
.fb .src { color: var(--muted); font-size: .85rem; }
#screen .src { font-size: .9rem; }

.controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0 0 1rem; position: sticky; bottom: 0; background: var(--bg); padding: .5rem 0; }
button, select {
  font: inherit; color: var(--text); background: var(--panel-2); border: 2px solid var(--line);
  border-radius: .4rem; padding: .5rem .9rem; min-height: 2.5rem; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.7); }
button.primary, button.fire { background: #0e5a6b; border-color: var(--accent); font-weight: bold; }
.speed { display: inline-flex; gap: .5rem; align-items: center; color: var(--muted); }

.keys { color: var(--muted); max-width: 46rem; }
.keys h2 { font-size: 1rem; margin-bottom: .25rem; }
.keylist { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; margin: 0; padding: 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: .3rem; padding: 0 .4rem; font: inherit; font-size: .9rem; color: var(--text); }

table { border-collapse: collapse; margin: .5rem 0 1rem; }
th, td { border: 1px solid var(--line); padding: .35rem .6rem; text-align: left; }
th { background: var(--panel-2); }

dialog { background: var(--panel); color: var(--text); border: 2px solid var(--accent); border-radius: .5rem; max-width: 26rem; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Narrow windows: stack the panels, keep the ACL in its own scroll box, keep the controls visible. */
@media (max-width: 52rem) {
  #game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "acl" "field" "feedback"; }
  .scroll { max-height: 12rem; }
}

/* Motion is only ever decoration; it is removed when the user asks for reduced motion. */
@media (prefers-reduced-motion: reduce) { .fx, .star { display: none; } }
@media (prefers-reduced-motion: no-preference) {
  .fb { animation: arrive .25s ease-out; }
  @keyframes arrive { from { opacity: .3; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* The banner title receives focus when a results screen opens (so screen readers announce it), but it is
   not a control, so it does not need a focus ring. Buttons and links keep theirs. */
.banner-text h2:focus { outline: none; }

#screen code { background: #0a1020; border: 1px solid var(--line); border-radius: .25rem; padding: 0 .35rem; }

/* The wave's access list sits beside the mistakes on the results page, so the rules they name are in view. */
.results-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); gap: 1rem; align-items: start; }
.aclbox { background: var(--panel-2); border: 1px solid var(--line); border-radius: .5rem; padding: .75rem 1rem; position: sticky; top: .5rem; }
.aclbox h3 { margin: 0 0 .5rem; }
.aclbox .acl { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: .3rem; }
.aclbox .acl li { padding: .4rem .6rem; border-bottom: 1px solid var(--line); border-left: 5px solid transparent; }
.aclbox .acl li:last-child { border-bottom: 0; }
.aclbox .acl li.implicit { color: var(--muted); font-style: italic; }
.aclbox .acl li.hit { background: #3a1c26; border-left-color: var(--bad); }
.aclbox .badge { display: block; color: var(--bad); font-weight: bold; font-size: .85rem; font-style: normal; margin-top: .1rem; }
.aclbox .acl li.hl { outline: 3px solid var(--warn); outline-offset: -3px; background: #3b3410; }
.aclbox .acl li.hl::after { content: "  ◀ this rule"; color: var(--warn); font-weight: bold; font-style: normal; }
.miss-why .entry { background: #0a1020; border: 1px solid var(--line); border-radius: .25rem; padding: 0 .35rem; color: var(--text); margin-left: .25rem; }
@media (max-width: 52rem) {
  .results-grid { grid-template-columns: minmax(0, 1fr); }
  .aclbox { position: static; order: -1; }
  .results-grid > :first-child { order: 1; }
}

.volume { display: inline-flex; gap: .5rem; align-items: center; color: var(--muted); }
.volume input[type="range"] { width: 7rem; accent-color: var(--accent); }

details.sources a { color: var(--accent); font-weight: bold; margin-left: .5rem; }
details.sources li { margin: .5rem 0; }
