:root {
  --bg: #050812;
  --panel: #0b1030;
  --line: #24306e;
  --text: #e8ebff;
  --muted: #9aa3d8;
  --gold: #e8a33a;
  --red: #c8352b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #0f1a5a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
h1 { margin: 0; display: flex; align-items: baseline; gap: 10px; font-size: 18px; line-height: 1.1; font-weight: 800; }
.t1 { color: var(--gold); letter-spacing: 0.16em; text-transform: uppercase; }
.t2 { color: var(--text); font-weight: 500; letter-spacing: 0.06em; }
#note { flex: 1; text-align: center; color: var(--gold); font-weight: 600; min-height: 1.5em; }
.actions { display: flex; gap: 14px; }
.link {
  background: none; border: 0; padding: 4px 0;
  color: var(--muted); text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { color: var(--text); }
.link:disabled { opacity: 0.4; cursor: default; }
#speed[aria-pressed="true"] { color: var(--gold); }
body[data-screen="menu"] :is(#save, #load, #speed),
body[data-screen="loading"] :is(#save, #load, #speed) { visibility: hidden; }

#stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  min-height: 0;
}
#view {
  display: block;
  border-radius: 10px;
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 80px rgba(53, 84, 200, 0.18);
  touch-action: none;
  cursor: none;              /* the ST draws its own pointer */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
body[data-screen="menu"] #view, body[data-screen="loading"] #view { visibility: hidden; }

.panel {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(580px, calc(100% - 32px));
  height: fit-content;
  max-height: calc(100% - 24px);
  overflow: auto;
  background: rgba(11, 16, 48, 0.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.panel h2 { margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
.panel h2 .t1 { font-size: 40px; letter-spacing: 0.2em; }
.panel h2 .t2 { font-size: 16px; letter-spacing: 0.3em; text-transform: uppercase; }
.lede { color: var(--muted); margin: 0 auto 22px; max-width: 46ch; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.choices button {
  border: 1px solid var(--line);
  background: #141a4a;
  border-radius: 10px;
  padding: 14px 12px;
  font-weight: 600;
  font-size: 16px;
}
.choices button[hidden] { display: none; }
.choices button small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 4px; }
.primary { background: linear-gradient(180deg, #e8a33a, #b97418) !important; border-color: #ffd08a !important; color: #1a1000; }
.primary small { color: #3b2600 !important; }
.choices button:hover { filter: brightness(1.15); }

.spinner {
  width: 42px; height: 42px; margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#banner {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #1d2766;
  border: 1px solid #3b4cb0;
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  pointer-events: none;
}
#banner.bad { background: #5a1d1d; border-color: #a33; }

#help {
  position: fixed; inset: 0;
  background: rgba(3, 4, 16, 0.75);
  display: flex; justify-content: center; align-items: flex-start;
  overflow: auto;
  padding: 24px 16px;
  z-index: 10;
}
#help[hidden] { display: none; }
.help-inner {
  position: relative;
  max-width: 680px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 28px;
}
.help-inner h2 { margin-top: 0; letter-spacing: 0.1em; text-transform: uppercase; }
.help-inner h3 { margin: 20px 0 6px; color: var(--gold); font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; }
.help-inner ul { padding-left: 20px; }
.help-inner li { margin: 4px 0; }
.help-inner dt { font-weight: 700; margin-top: 8px; }
.help-inner dd { margin: 0; color: #c8cbf2; }
.close { position: absolute; top: 18px; right: 22px; }

footer {
  padding: 8px 16px 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
footer p { margin: 2px auto; max-width: 90ch; }
footer a { color: var(--muted); }

@media (max-width: 560px) {
  header { gap: 8px; }
  h1 { font-size: 15px; flex-wrap: wrap; }
  .actions { gap: 12px; flex-wrap: wrap; }
  #note { order: 3; flex-basis: 100%; }
  .panel { padding: 20px; }
  .panel h2 .t1 { font-size: 30px; }
  #stage { padding: 8px; }
}

/* phones in landscape: the game gets the whole height */
@media (max-height: 500px) {
  body[data-screen="game"] footer { display: none; }
  header { padding: 6px 16px; }
  #stage { padding: 6px; }
}

/* ---------- ship's computer ---------- */
#computer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
  z-index: 8;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.4);
}
#computer[hidden] { display: none; }
@media (min-width: 1000px) { body.pc-open { padding-right: 420px; } }
.pc-inner { padding: 14px 18px 28px; }
.pc-head { display: flex; align-items: center; justify-content: space-between; }
.pc-head h2 { margin: 0; font-size: 18px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
#computer h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); }
#computer h4 { margin: 12px 0 4px; font-size: 14px; }
.pc-muted { color: var(--muted); font-size: 13px; margin: 2px 0 6px; }
.pc-row { display: flex; gap: 10px; align-items: center; margin: 6px 0; font-size: 14px; }
.pc-row select { flex: 1; background: #070b24; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; }
.pc-stat { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.pc-stat b { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.pc-bar { height: 6px; border-radius: 3px; background: #141a4a; overflow: hidden; margin-top: 6px; }
.pc-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--red)); }
.pc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pc-table th { text-align: left; color: var(--muted); font-weight: 500; }
.pc-table td, .pc-table th { padding: 3px 6px 3px 0; border-bottom: 1px solid #161d52; vertical-align: top; }
.pc-table .link { padding: 0; font-variant-numeric: tabular-nums; }
.pc-slot { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid #161d52; font-size: 13px; }
.pc-slot img, .pc-empty { width: 96px; height: 60px; border-radius: 6px; background: #070b24; border: 1px solid var(--line); flex: none; object-fit: cover; }
.pc-slot .link { margin-right: 12px; }
.pc-rewind { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pc-shot { padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #070b24; overflow: hidden; font-size: 11px; color: var(--muted); }
.pc-shot img { display: block; width: 100%; }
.pc-shot span { display: block; padding: 2px 4px; }
.pc-shot:hover { border-color: var(--gold); }
.pc-btn { border: 1px solid var(--line); background: #141a4a; border-radius: 8px; padding: 8px 12px; }
#pc-notes { width: 100%; background: #070b24; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: 14px/1.4 system-ui, sans-serif; resize: vertical; }
body[data-screen="menu"] #computer-btn, body[data-screen="loading"] #computer-btn { visibility: hidden; }
