:root {
  --space: #0d1638;
  --ink: #eef1f4;
  --dim: #9fb0d0;
  --orange: #ff7a1a;
  --brass: #c9a24a;
  --good: #5fe08a;
  --warn: #ffb347;
  --bad: #ff5a4f;
  --hud: "Chakra Petch", ui-monospace, "SF Mono", Menlo, monospace;
}

html, body { margin: 0; height: 100%; background: var(--space); color: var(--ink); overflow: hidden; }
body { font-family: var(--hud); }

#game {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--mc-top);
  width: 100%;
  height: calc(100dvh - var(--mc-top));
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#hud { position: fixed; inset: var(--mc-top) 0 0 0; pointer-events: none; }
#hud[hidden] { display: none; }

.panel {
  position: absolute;
  background: rgba(10, 16, 40, 0.78);
  border: 2px solid #26345f;
  border-radius: 10px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  padding: 8px 12px;
}

.readout { top: 12px; left: 12px; display: grid; grid-template-columns: repeat(5, auto); gap: 4px 16px; }
.readout .wide { grid-column: span 3; }
.readout .wide2 { grid-column: span 2; }
.readout b.hull.many { font-size: 13px; letter-spacing: 1px; line-height: 24px; }
.readout b.hull { color: #7ff0a0; letter-spacing: 2px; }
.readout b.hull.warn { color: var(--bad); }
.readout div { display: flex; flex-direction: column; min-width: 54px; }
.readout small { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; }
.readout b { font-size: 20px; font-variant-numeric: tabular-nums; }
.readout i { font-style: normal; color: var(--dim); font-size: 11px; }
.readout b.warn { color: var(--bad); }

.time { top: 12px; right: 12px; text-align: right; display: flex; flex-direction: column; gap: 2px; }
.time b { font-size: 22px; color: var(--ink); }
.time b.plan { color: var(--good); }
.time b.fast { color: var(--warn); }
.time small { color: var(--dim); font-size: 11px; }
.mode {
  pointer-events: auto;
  align-self: flex-end;
  margin: 3px 0;
  font: 600 12px var(--hud);
  color: #0d1638;
  background: #9ff0ff;
  border: 0;
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}
.mode.real { background: var(--orange); color: #1a1206; }
.rules em { font-style: normal; color: #9ff0ff; }

.toasts { position: absolute; top: 144px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.toast {
  display: flex; flex-direction: column; align-items: flex-end;
  background: rgba(10, 16, 40, 0.86); border: 2px solid var(--brass); border-radius: 8px;
  padding: 4px 10px; min-width: 170px; text-align: right;
  animation: toast-in 0.25s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast b { font-size: 13px; letter-spacing: 0.08em; color: #ffd25a; }
.toast span { font-size: 12px; color: #cfd8ee; font-variant-numeric: tabular-nums; }
.toast.salvage { border-color: #7ff0a0; }
.toast.salvage b { color: #7ff0a0; }
.toast.down { border-color: #26345f; }
.toast.down b { color: #ff9a4a; }
.toast.bad { border-color: var(--bad); }
.toast.bad b { color: var(--bad); }
.toast.out { opacity: 0; transform: translateX(20px); }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
.radio { left: 12px; bottom: 12px; width: min(560px, 58vw); padding: 6px 10px; border-color: var(--brass); display: flex; gap: 10px; align-items: flex-start; }
.radio .face { width: 52px; height: 52px; object-fit: contain; flex: none; border-radius: 8px; background: #1b2756; }
.radio-body { flex: 1; min-width: 0; }
.radio-top, .radio-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.radio .goal-tag { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; text-align: right; }
.radio-foot b { color: var(--brass); font-size: 13px; }
/* A fixed three-line height, so the card never grows over the altitude ladder. */
.radio p { height: 3.9em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.radio p.standing { color: #cfd8ee; }
.portrait { display: block; width: 150px; height: 150px; object-fit: contain; margin: -6px auto 6px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #2a3a72, #121c44 70%); }
.kicker { display: block; color: var(--brass); letter-spacing: 0.14em; font-size: 12px; margin-bottom: 4px; }
.brief .rules { margin: 4px 0 16px; }
.starts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.radio .who { color: var(--brass); font-size: 11px; letter-spacing: 0.12em; }
.radio p { margin: 2px 0 1px; font-size: 14px; line-height: 1.3; }
.radio .dismiss { color: var(--dim); font-size: 10px; }
.radio .dismiss[hidden] { display: none; }

.overlay {
  position: fixed;
  inset: var(--mc-top) 0 0 0;
  /* Flex with auto margins centres the card but scrolls from the top when
     it's taller than the window (grid centring would cut the top off). */
  display: flex;
  padding: 16px;
  background: rgba(6, 10, 28, 0.72);
  z-index: 5;
  overflow: auto;
}
.overlay[hidden] { display: none; }
.card {
  max-width: 560px;
  margin: auto;
  padding: 22px 26px;
  background: #121c44;
  border: 2px solid #2c3b6c;
  border-radius: 14px;
  text-align: center;
}
.card h1, .card h2 { margin: 0; font-size: 40px; letter-spacing: 0.02em; }
.card h2 { font-size: 32px; }
.results { display: grid; grid-template-columns: auto auto; gap: 4px 18px; justify-content: center; margin: 12px 0 18px; font-size: 16px; }
.results dt { color: var(--dim); text-align: right; }
.results dd { margin: 0; text-align: left; font-weight: 700; }
.depot-top { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 6px; }
.depot-top small { color: var(--brass); font-size: 11px; letter-spacing: 0.1em; }
.depot-top b { color: #ffd36a; font-size: 18px; }
.depot { display: grid; gap: 6px; margin-bottom: 16px; }
.upgrade {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font: 500 14px var(--hud); color: var(--ink); text-align: left;
  background: #0d1638; border: 2px solid #26345f; border-radius: 8px;
  padding: 6px 10px; cursor: pointer;
}
.upgrade:hover, .upgrade:focus { border-color: #ffd36a; outline: none; }
.upgrade b { color: var(--ink); }
.upgrade i { font-style: normal; color: #ffd36a; letter-spacing: 2px; font-size: 11px; }
.upgrade small { display: block; color: var(--dim); font-size: 12px; }
.upgrade em { font-style: normal; color: #ffd36a; font-weight: 700; white-space: nowrap; }
.upgrade.poor { opacity: 0.5; }
.primary:focus { outline: 3px solid var(--ink); outline-offset: 3px; }
.card h1::after { content: ""; display: block; width: 64px; height: 6px; margin: 8px auto 0; background: var(--orange); border-radius: 3px; }
.card .sub { margin: 8px 0 0; color: var(--brass); letter-spacing: 0.1em; text-transform: uppercase; font-size: 13px; }
.card .lede { color: var(--dim); line-height: 1.45; }
.rules { text-align: left; margin: 0; padding-left: 18px; color: var(--ink); line-height: 1.4; font-size: 14px; }
.rules li { margin: 4px 0; }
.rules b { color: var(--brass); }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0 16px; text-align: left; }
.keys th { color: var(--dim); font-weight: 500; font-size: 12px; padding: 0 6px 4px; }
.keys td { padding: 3px 6px; border-top: 1px solid #22305a; }
.keys td:first-child { color: var(--dim); }
.primary {
  font: 700 18px var(--hud);
  color: #1a1206;
  background: var(--orange);
  border: 0;
  border-radius: 10px;
  padding: 10px 26px;
  cursor: pointer;
}
.primary:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.hint { color: var(--dim); font-size: 12px; margin: 10px 0 0; }

@media (max-width: 720px) {
  .readout { grid-template-columns: repeat(3, auto); }
  .card h1 { font-size: 30px; }
}

/* Classes above set display, which would beat the hidden attribute. */
.results[hidden], .depot[hidden], .depot-top[hidden] { display: none; }

/* The welcome card: short, with the rules and controls folded away. */
.title-card { max-width: 520px; }
.title-card .lede { margin: 10px 0 18px; }
.more { display: flex; gap: 8px; justify-content: center; margin: 14px 0 0; }
.more { flex-wrap: wrap; }
.toggle {
  appearance: none; -webkit-appearance: none;
  font: 600 13px var(--hud); color: #dfe7ff; background: transparent;
  border: 1.5px solid #6f84c4; border-radius: 8px; padding: 5px 12px; cursor: pointer;
}
.toggle:hover, .toggle:focus { color: #fff; border-color: #fff; background: rgba(255, 255, 255, 0.06); outline: none; }
.toggle.on { color: #9ff0ff; border-color: #9ff0ff; background: rgba(159, 240, 255, 0.1); }
.drawer { margin-top: 12px; max-height: min(40vh, 340px); overflow: auto; text-align: left; }
.drawer .keys { margin: 0; font-size: 13px; }
.drawer .rules { font-size: 13px; }

/* Go plus a small outline Skip beside it. */
.brief-btns { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.brief-btns .toggle[hidden] { display: none; }

/* Restart and skip, on the radio card during training. */
.lesson-btns { display: flex; gap: 6px; margin-left: auto; pointer-events: auto; }
.lesson-btns[hidden] { display: none; }
.mini {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  font: 600 11px var(--hud); color: #dfe7ff; background: transparent;
  border: 1px solid #6f84c4; border-radius: 6px; padding: 2px 8px;
}
.mini:hover, .mini:focus-visible { color: #fff; border-color: #fff; background: rgba(255, 255, 255, 0.06); outline: none; }

/* Replay a sector: one small button per sector you've reached. */
.drawer-note { margin: 0 0 8px; color: var(--dim); font-size: 13px; text-align: center; }
.replay-list { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.toggle.danger { border-color: #c46f6f; }
.toggle.danger.on { color: #ff9a8a; border-color: #ff9a8a; background: rgba(255, 120, 100, 0.1); }

/* The sector result: wider, with the stats and the depot in two columns. */
#result .card { max-width: 780px; }
@media (min-width: 720px) {
  #result .results { grid-template-columns: auto auto auto auto; }
  #result .depot { grid-template-columns: 1fr 1fr; }
}
#result .portrait { width: 96px; height: 96px; margin-bottom: 2px; }
#result .results { margin: 8px 0 12px; }
