@font-face {
  font-family: "JetBrains Mono";
  src: url("vendor/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("vendor/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Chakra Petch";
  src: url("vendor/fonts/chakra-petch-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Chakra Petch";
  src: url("vendor/fonts/chakra-petch-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #03040a;
  --ink: #d6ecff;
  --dim: #7b93ad;
  --faint: #3a4b60;
  --cyan: #5cf0ff;
  --cyan-glow: rgba(92, 240, 255, 0.45);
  --violet: #c46bff;
  --amber: #ffb547;
  --red: #ff5c7a;
  --panel: rgba(6, 12, 24, 0.55);
  --line: rgba(92, 240, 255, 0.22);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Chakra Petch", "JetBrains Mono", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--display);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.mono { font-family: var(--mono); }

#tunnel, #stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#tunnel { z-index: 0; }
#stars { z-index: 1; }
/* Darken the middle while in hyperspace so the readouts stay legible. */
.veil {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s;
  background: radial-gradient(ellipse 34rem 30rem at 50% 50%, rgba(3,4,10,0.82) 0%, rgba(3,4,10,0.55) 45%, transparent 75%);
}
body[data-phase="transit"] .veil, body[data-phase="arrived"] .veil, body[data-phase="spool"] .veil { opacity: 1; }
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

/* ---------- top bar ---------- */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--cyan); }
.brand-mark { width: 22px; height: 22px; filter: drop-shadow(0 0 6px var(--cyan-glow)); }
.brand-name {
  font-weight: 700;
  letter-spacing: 0.42em;
  font-size: 14px;
  color: var(--ink);
  text-shadow: 0 0 12px var(--cyan-glow);
}
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 5px 10px;
  background: rgba(3, 8, 18, 0.6);
  backdrop-filter: blur(6px);
}
.status-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: blink 1.4s ease-in-out infinite;
}
body[data-phase="fault"] .status-pill { color: var(--red); border-color: rgba(255,92,122,0.35); }
body[data-phase="transit"] .status-pill { color: var(--violet); border-color: rgba(196,107,255,0.4); }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- panels ---------- */
main {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 72px 16px 150px;
  overflow-y: auto;
}
.panel {
  display: none;
  width: min(440px, 100%);
  text-align: center;
  animation: panel-in 0.6s cubic-bezier(.2,.8,.2,1);
}
body[data-phase="boot"] .phase-boot,
body[data-phase="beacon"] .phase-beacon,
body[data-phase="cargo"] .phase-cargo,
body[data-phase="spool"] .phase-spool,
body[data-phase="transit"] .phase-transit,
body[data-phase="arrived"] .phase-arrived,
body[data-phase="fault"] .phase-fault { display: block; }
@keyframes panel-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

.eyebrow {
  margin: 0 0 18px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan-glow);
}
.eyebrow.warn { color: var(--red); text-shadow: 0 0 10px rgba(255,92,122,0.5); }
.title {
  margin: 18px 0 6px;
  font-size: clamp(22px, 5vw, 30px);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sub { margin: 6px 0; color: var(--dim); font-size: 14px; line-height: 1.5; }
.sub.mono { font-size: 12px; letter-spacing: 0.04em; overflow-wrap: anywhere; }
.fine { margin: 18px auto 0; max-width: 34ch; color: var(--faint); font-size: 12px; line-height: 1.5; font-family: var(--mono); }

/* ---------- rings ---------- */
.ring-wrap { position: relative; width: 190px; height: 190px; margin: 0 auto; }
.ring-wrap.big-ring { width: min(250px, 62vw); height: min(250px, 62vw); }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring circle { fill: none; }
.ring-track { stroke: rgba(92,240,255,0.12); stroke-width: 3; }
.ring-ticks { stroke: rgba(92,240,255,0.35); stroke-width: 6; stroke-dasharray: 1 9.05; }
.ring-fill {
  stroke: var(--cyan);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 552.9;
  stroke-dashoffset: 552.9;
  filter: drop-shadow(0 0 6px var(--cyan));
  transition: stroke-dashoffset 0.25s linear;
}
.phase-transit .ring-fill { stroke: var(--violet); filter: drop-shadow(0 0 8px var(--violet)); }
.ring-arc {
  stroke: var(--cyan);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 120 432.9;
  filter: drop-shadow(0 0 6px var(--cyan));
}
.ring-wrap.spin .ring { animation: spin 1.1s linear infinite; }
.ring-wrap .ring-ticks { animation: spin-plain 24s linear infinite reverse; transform-origin: 100px 100px; }
@keyframes spin { to { transform: rotate(270deg); } }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-center .big {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(30px, 9vw, 44px);
  letter-spacing: -0.02em;
  text-shadow: 0 0 18px var(--cyan-glow);
}
.ring-center .small {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--dim);
  margin-top: 2px;
}

/* ---------- QR reticle ---------- */
.reticle {
  position: relative;
  width: 280px;
  height: 280px;
  max-width: 78vw;
  max-height: 78vw;
  margin: 0 auto;
  display: grid;
  place-items: center;
}
#qr {
  width: 74%;
  height: 74%;
  border-radius: 10px;
  image-rendering: pixelated;
  box-shadow: 0 0 0 1px rgba(92,240,255,0.5), 0 0 40px rgba(92,240,255,0.35);
  animation: qr-in 0.9s cubic-bezier(.2,.8,.2,1);
}
@keyframes qr-in { from { opacity: 0; transform: scale(0.6) rotate(-8deg); filter: blur(10px) brightness(3); } }
.reticle-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px dashed rgba(92,240,255,0.35);
  animation: spin-plain 30s linear infinite;
}
.reticle-ring.r2 {
  inset: 14px;
  border: 2px solid transparent;
  border-top-color: var(--cyan);
  border-bottom-color: rgba(196,107,255,0.8);
  animation-duration: 6s;
  animation-direction: reverse;
  filter: drop-shadow(0 0 6px var(--cyan));
}
@keyframes spin-plain { to { transform: rotate(360deg); } }
.corner { position: absolute; width: 18px; height: 18px; border: 2px solid var(--cyan); filter: drop-shadow(0 0 4px var(--cyan)); }
.corner.tl { top: 8%; left: 8%; border-right: 0; border-bottom: 0; }
.corner.tr { top: 8%; right: 8%; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 8%; left: 8%; border-right: 0; border-top: 0; }
.corner.br { bottom: 8%; right: 8%; border-left: 0; border-top: 0; }

/* ---------- buttons ---------- */
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.btn {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 12px 20px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(6, 14, 28, 0.7);
  border: 1px solid var(--line);
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.btn:hover:not(:disabled) { border-color: var(--cyan); box-shadow: 0 0 18px rgba(92,240,255,0.25); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.btn.primary {
  color: #001318;
  font-weight: 700;
  background: linear-gradient(90deg, var(--cyan), #9af6ff);
  border-color: transparent;
  box-shadow: 0 0 24px rgba(92,240,255,0.45);
  min-width: 200px;
  padding: 15px 28px;
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 0 36px rgba(92,240,255,0.75); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
#engage:not(:disabled) { animation: engage-pulse 1.8s ease-in-out infinite; }
@keyframes engage-pulse { 50% { box-shadow: 0 0 44px rgba(92,240,255,0.85); } }

/* ---------- dropzone & manifest ---------- */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 30px 16px;
  border: 1px dashed rgba(92,240,255,0.45);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--cyan); background: rgba(10, 30, 50, 0.6); box-shadow: inset 0 0 40px rgba(92,240,255,0.12); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone svg { width: 40px; height: 40px; color: var(--cyan); filter: drop-shadow(0 0 6px var(--cyan-glow)); }
.dz-title { font-size: 18px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; }
.dz-sub { font-family: var(--mono); font-size: 11px; color: var(--dim); }

.manifest {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  text-align: left;
  max-height: 30vh;
  overflow-y: auto;
}
.manifest li {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel);
  border-left: 2px solid var(--line);
  backdrop-filter: blur(6px);
  overflow: hidden;
}
.manifest li .idx { color: var(--faint); }
.manifest li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manifest li .size { color: var(--dim); }
.manifest li .bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  width: 0;
  background: var(--violet);
  box-shadow: 0 0 8px var(--violet);
  transition: width 0.2s linear;
}
.manifest li.done { border-left-color: var(--cyan); }
.manifest li.done .bar { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.manifest li .rm { background: none; border: 0; color: var(--dim); cursor: pointer; font: inherit; padding: 0 2px; }
.manifest li .rm:hover { color: var(--red); }
.manifest.compact { max-height: 18vh; }
.manifest.cargo li { grid-template-columns: 44px 1fr auto; }
.manifest.cargo .thumb {
  width: 44px; height: 44px;
  border-radius: 4px;
  object-fit: cover;
  background: rgba(92,240,255,0.08);
  display: grid; place-items: center;
  color: var(--cyan);
  font-size: 10px;
  letter-spacing: 0.08em;
}
.manifest.cargo .meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.manifest.cargo .meta .name { color: var(--ink); }
.manifest.cargo .ops { display: flex; gap: 6px; }
.manifest.cargo .ops a, .manifest.cargo .ops button {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(92,240,255,0.08);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 3px;
  text-decoration: none;
  cursor: pointer;
}
.manifest.cargo li { animation: cargo-in 0.5s cubic-bezier(.2,.8,.2,1) both; }
@keyframes cargo-in { from { opacity: 0; transform: translateX(-24px); } }

/* ---------- transit readouts ---------- */
.readouts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 16px;
  font-size: 13px;
}
.readouts div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 4px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.readouts span:not(.k) { white-space: nowrap; font-size: 12px; }
.readouts .k { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
.spark { width: 100%; height: 44px; margin-top: 10px; display: block; }

/* ---------- hex stream ---------- */
.hex {
  position: fixed;
  z-index: 3;
  right: 18px;
  top: 64px;
  width: max-content;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 80%, transparent);
}
body[data-phase="transit"] .hex, body[data-phase="arrived"] .hex { opacity: 1; }
.hud-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.3em; color: var(--dim); padding: 12px 0 6px; }
#hexdump {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--cyan);
  white-space: pre;
  text-shadow: 0 0 8px rgba(92,240,255,0.35);
}
#hexdump .o { color: var(--faint); }
#hexdump .a { color: var(--violet); text-shadow: 0 0 8px rgba(196,107,255,0.4); }
#hexdump .z { color: #2a5566; text-shadow: none; }

/* ---------- bottom HUD ---------- */
.hud {
  position: fixed;
  z-index: 3;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 0 18px max(14px, env(safe-area-inset-bottom));
  pointer-events: none;
  font-size: 11px;
  padding-top: 40px;
  background: linear-gradient(to top, rgba(3,4,10,0.85), transparent);
}
.telemetry { margin: 0; display: grid; gap: 3px; }
.telemetry div { display: flex; gap: 10px; }
.telemetry dt { width: 46px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.12em; }
.telemetry dd { margin: 0; color: var(--dim); }
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 48ch;
  text-align: right;
  color: var(--faint);
  display: grid;
  gap: 2px;
}
.log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: log-in 0.3s ease-out; }
.log li:last-child { color: var(--dim); }
.log li .t { color: #2b3a4c; margin-right: 8px; }
@keyframes log-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 900px) {
  .hex {
    right: 0; left: 0; top: auto;
    bottom: 96px;
    width: 100%;
    padding: 0 16px;
    height: 74px;
    overflow: hidden;
    mask-image: linear-gradient(to bottom, transparent, #000 30%);
  }
  .hex .hud-label { display: none; }
  #hexdump { font-size: 10px; }
  .log { display: none; }
  main { padding-bottom: 190px; }
  body[data-phase="beacon"] main, body[data-phase="cargo"] main { padding-bottom: 110px; }
}
@media (max-width: 420px) {
  .telemetry dd { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .readouts { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  /* Darken the middle while in hyperspace so the readouts stay legible. */
.veil {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s;
  background: radial-gradient(ellipse 34rem 30rem at 50% 50%, rgba(3,4,10,0.82) 0%, rgba(3,4,10,0.55) 45%, transparent 75%);
}
body[data-phase="transit"] .veil, body[data-phase="arrived"] .veil, body[data-phase="spool"] .veil { opacity: 1; }
.scanlines { display: none; }
}
