/* ==========================================================================
   QUANTUM ECHO: THE REWIND PROTOCOL — styles
   Midnight navy + electric cyan (quantum energy) + amber (objectives, rewards).
   Builds on the original stylesheet: star field, moving grid, orbit rings,
   rise-in animation and reduced-motion support are kept and refined.
   ========================================================================== */

:root {
  --bg-0: #02050c;
  --bg-1: #050b18;
  --bg-2: #0a1528;
  --panel: rgba(8, 18, 36, 0.78);
  --panel-solid: #08142a;
  --panel-raised: rgba(14, 30, 56, 0.85);
  --line: rgba(0, 229, 255, 0.16);
  --line-strong: rgba(0, 229, 255, 0.42);

  --cyan: #00e5ff;
  --cyan-soft: #7fe9ff;
  --teal: #1de9b6;
  --amber: #ffb627;
  --gold: #ffd166;
  --violet: #7c4dff;
  --danger: #ff5a6e;

  --text: #e2f1ff;
  --text-dim: #a9bfd6;
  --muted: #7590ad;

  --glow-cyan: 0 0 18px rgba(0, 229, 255, 0.35);
  --glow-amber: 0 0 18px rgba(255, 182, 39, 0.35);

  --radius: 14px;
  --radius-sm: 8px;
  --font-ui: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
}

/* ==========================================================================
   Base Styles & Resets
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg-0);
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(0, 229, 255, 0.10), transparent 45%),
    radial-gradient(ellipse at 90% 100%, rgba(255, 182, 39, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 70%);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

body.has-overlay {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

/* Hide inactive screens */
.hidden {
  display: none !important;
}

.ket {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ket.big { font-size: 1.6rem; color: var(--cyan); }
.ket.huge { font-size: 2.1rem; font-weight: 600; color: var(--cyan); text-shadow: var(--glow-cyan); }
.ket.amber { color: var(--amber); text-shadow: var(--glow-amber); }

.kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--cyan-soft);
  opacity: 0.85;
}

/* ==========================================================================
   Backdrop: twinkling stars + moving grid (from the original polish passes)
   ========================================================================== */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 8% 18%, #ffffff 50%, transparent 51%),
    radial-gradient(2px 2px at 22% 72%, #9fe8ff 50%, transparent 51%),
    radial-gradient(1px 1px at 35% 30%, #ffffff 50%, transparent 51%),
    radial-gradient(2px 2px at 48% 88%, #ffe2a8 50%, transparent 51%),
    radial-gradient(1px 1px at 61% 12%, #ffffff 50%, transparent 51%),
    radial-gradient(2px 2px at 74% 58%, #9fe8ff 50%, transparent 51%),
    radial-gradient(1px 1px at 86% 26%, #ffffff 50%, transparent 51%),
    radial-gradient(2px 2px at 93% 80%, #ffe2a8 50%, transparent 51%),
    radial-gradient(1px 1px at 15% 92%, #ffffff 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 45%, #9fe8ff 50%, transparent 51%);
  opacity: 0.6;
  animation: twinkle 4s ease-in-out infinite alternate;
}

.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 229, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, #000 90%);
  mask-image: radial-gradient(ellipse at center, transparent 30%, #000 90%);
  animation: gridMove 14s linear infinite;
}

@keyframes twinkle {
  from { opacity: 0.3; }
  to   { opacity: 0.75; }
}

@keyframes gridMove {
  from { background-position: 0 0; }
  to   { background-position: 48px 48px; }
}

/* ==========================================================================
   Top bar / HUD
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 24px;
  background: rgba(3, 8, 18, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  text-align: left;
}

.brand:hover .brand-mark { filter: drop-shadow(0 0 8px var(--cyan)); }

.brand-mark {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1.4;
  transition: filter 0.2s;
}

.brand-mark circle { fill: var(--cyan); stroke: none; }
.brand-mark ellipse:last-child { stroke: var(--amber); }

.brand-text {
  display: flex;
  flex-direction: column;
  font-weight: 800;
  letter-spacing: 0.2em;
  font-size: 0.95rem;
  line-height: 1.1;
}

.brand-text small {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--amber);
}

.hud {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.hud-item {
  display: flex;
  flex-direction: column;
  min-width: 70px;
  padding: 4px 12px;
  border-left: 1px solid var(--line);
}

.hud-item dt {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-item dd {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

#hud-xp { color: var(--amber); }
#hud-streak { color: var(--cyan); }
.hud-unit { color: var(--muted); margin-left: 1px; }

.storage-warning {
  position: relative;
  z-index: 5;
  max-width: 1200px;
  margin: 12px auto 0;
  padding: 10px 16px;
  border: 1px solid rgba(255, 182, 39, 0.4);
  border-radius: var(--radius-sm);
  background: rgba(255, 182, 39, 0.08);
  color: var(--gold);
  font-size: 0.9rem;
}

.fatal-banner {
  position: relative;
  z-index: 50;
  padding: 12px 20px;
  background: #3a0d16;
  border-bottom: 1px solid var(--danger);
  color: #ffd5db;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ==========================================================================
   App container and screens
   ========================================================================== */
#app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Each screen slides in, one piece after another (original effect) */
.screen:not(.hidden) > * {
  animation: riseIn 0.5s ease both;
}

.screen:not(.hidden) > *:nth-child(2) { animation-delay: 0.06s; }
.screen:not(.hidden) > *:nth-child(3) { animation-delay: 0.12s; }
.screen:not(.hidden) > *:nth-child(4) { animation-delay: 0.18s; }
.screen:not(.hidden) > *:nth-child(n+5) { animation-delay: 0.24s; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 18px 40px rgba(0, 0, 0, 0.35);
}

/* Corner brackets: a console-frame motif instead of plain cards */
.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--line-strong);
  border-style: solid;
  pointer-events: none;
}

.panel::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; border-top-left-radius: var(--radius); }
.panel::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; border-bottom-right-radius: var(--radius); }

.panel-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

h3 {
  font-size: 1.05rem;
  color: var(--cyan-soft);
}

p {
  line-height: 1.55;
}

/* ==========================================================================
   Buttons & Controls
   ========================================================================== */
.button-group, .utility-buttons, .gate-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  position: relative;
  background: rgba(11, 30, 61, 0.8);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 22px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s, transform 0.12s, border-color 0.18s;
}

.btn:hover:not(:disabled) {
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(90deg, #00b8d4, #00e5ff);
  border: none;
  color: #02121a;
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.35);
  overflow: hidden;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(90deg, #22d6f0, #7ff3ff);
  box-shadow: 0 0 26px rgba(0, 229, 255, 0.6);
}

/* A light sweeps across primary buttons (original effect) */
.btn-primary::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-20deg);
  animation: sweep 3.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes sweep {
  0%   { left: -60%; }
  60%  { left: 130%; }
  100% { left: 130%; }
}

.btn-secondary {
  border-color: rgba(255, 182, 39, 0.55);
  color: var(--gold);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--amber);
  background: rgba(255, 182, 39, 0.1);
  box-shadow: var(--glow-amber);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(0, 229, 255, 0.06);
}

.btn-danger {
  background: transparent;
  border-color: rgba(255, 90, 110, 0.45);
  color: #ff98a5;
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: rgba(255, 90, 110, 0.12);
  box-shadow: 0 0 16px rgba(255, 90, 110, 0.35);
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.72rem;
}

/* ==========================================================================
   1. Title screen
   ========================================================================== */
.screen-start {
  align-items: center;
  text-align: center;
  max-width: 720px;
  margin: 4vh auto 0;
}

.title-orb {
  width: 150px;
  height: 150px;
}

.title-orb svg { width: 100%; height: 100%; overflow: visible; }

.orb-ring {
  fill: none;
  stroke-width: 1.5;
  transform-origin: 100px 100px;
}

.orb-ring.r1 { stroke: rgba(0, 229, 255, 0.25); stroke-dasharray: 4 8; animation: orbit 30s linear infinite; }
.orb-ring.r2 { stroke: var(--cyan); animation: orbit 9s linear infinite; }
.orb-ring.r3 { stroke: var(--amber); animation: orbit 13s linear infinite reverse; }

.orb-core {
  fill: var(--cyan);
  filter: drop-shadow(0 0 16px var(--cyan)) drop-shadow(0 0 36px rgba(0, 229, 255, 0.5));
  transform-origin: 100px 100px;
  animation: pulse 2.6s ease-in-out infinite alternate;
}

@keyframes orbit {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  from { transform: scale(0.88); opacity: 0.85; }
  to   { transform: scale(1.06); opacity: 1; }
}

.main-title {
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  font-weight: 900;
  letter-spacing: 0.18em;
  background: linear-gradient(90deg, var(--cyan), #e9fdff, var(--cyan));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(0, 229, 255, 0.45));
}

/* Keep the title shimmering as well as sliding in */
.screen:not(.hidden) > .main-title {
  animation: riseIn 0.5s ease both, shine 5s linear infinite;
}

@keyframes shine {
  to { background-position: 200% center; }
}

.subtitle {
  margin-top: -12px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--amber);
}

.story-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 18px 22px;
  text-align: left;
  background: linear-gradient(90deg, rgba(0, 229, 255, 0.07), rgba(0, 229, 255, 0.01));
  border-left: 3px solid var(--cyan);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1.02rem;
  color: var(--text-dim);
}

.story-stamp {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--amber);
}

.start-footnote {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ==========================================================================
   2. Tutorial
   ========================================================================== */
.tutorial-panel {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tutorial-body {
  min-height: 300px;
}

.tutorial-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--text-dim);
  animation: riseIn 0.35s ease both;
}

.tutorial-step h3 {
  font-size: 1.25rem;
  color: var(--text);
}

.tutorial-step strong { color: var(--text); }

.formula {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--cyan);
  padding: 12px 16px;
  background: rgba(0, 229, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: nowrap;
}

.tut-visual {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.tut-ket {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 229, 255, 0.04);
  font-size: 0.9rem;
}

.tut-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 20px;
}

.keys-line {
  font-size: 0.85rem;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
  text-align: center;
}

.tutorial-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.dot {
  width: 26px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 229, 255, 0.15);
  transition: background 0.2s;
}

.dot.is-done { background: rgba(0, 229, 255, 0.45); }
.dot.is-active { background: var(--amber); box-shadow: var(--glow-amber); }

.tutorial-nav {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.tutorial-nav .btn-primary { margin-left: auto; }

/* ==========================================================================
   3. Mission control
   ========================================================================== */
.control-grid {
  display: grid;
  grid-template-columns: minmax(260px, 330px) 1fr;
  gap: 20px;
  align-items: start;
}

.core-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-title {
  margin-top: -8px;
  font-size: 1.35rem;
}

.core-visual svg {
  width: 100%;
  max-width: 260px;
  display: block;
  margin: 0 auto;
  overflow: visible;
}

.core-grid {
  fill: none;
  stroke: rgba(0, 229, 255, 0.12);
  stroke-dasharray: 2 6;
}

.core-seg {
  fill: none;
  stroke: rgba(0, 229, 255, 0.14);
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke 0.4s, filter 0.4s;
}

.core-seg.is-done {
  stroke: var(--amber);
  filter: drop-shadow(0 0 6px rgba(255, 182, 39, 0.8));
}

.core-orbits ellipse {
  fill: none;
  stroke: rgba(0, 229, 255, 0.5);
  stroke-width: 1.2;
}

.core-orbits {
  transform-origin: 120px 120px;
  animation: orbit 24s linear infinite;
}

.core-heart {
  transform-origin: 120px 120px;
  animation: pulse 2.4s ease-in-out infinite alternate;
}

.core-trace {
  fill: none;
  stroke: var(--teal);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
  opacity: 0.7;
  animation: traceFlow 2s linear infinite;
}

@keyframes traceFlow {
  to { stroke-dashoffset: -20; }
}

.daily-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.status-line strong {
  font-family: var(--font-mono);
  color: var(--amber);
}

.meter {
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid var(--line);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--amber), var(--gold));
  box-shadow: var(--glow-amber);
  transition: width 0.5s ease;
}

.bonus-text {
  font-size: 0.82rem;
  color: var(--muted);
}

.bonus-text.is-claimed {
  color: var(--gold);
}

.core-stats {
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.core-stats div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
}

.core-stats dt { color: var(--muted); }
.core-stats dd { font-family: var(--font-mono); color: var(--text); text-align: right; }

.streak-note {
  font-size: 0.8rem;
  color: var(--cyan-soft);
}

.board-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.board-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.board-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.daily-board {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Mission slot — a console bay rather than a generic card */
.mission-slot {
  --tier: var(--cyan);
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--tier);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.mission-slot:hover {
  border-color: var(--line-strong);
  border-left-color: var(--tier);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.08);
}

.mission-slot.diff-easy { --tier: var(--teal); }
.mission-slot.diff-intermediate { --tier: var(--cyan); }
.mission-slot.diff-hard { --tier: var(--amber); }

.mission-slot.is-complete {
  background: linear-gradient(90deg, rgba(255, 182, 39, 0.06), var(--panel) 40%);
}

.slot-tier {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 14px 8px;
  background: rgba(0, 0, 0, 0.25);
  border-right: 1px solid var(--line);
  text-align: center;
}

.tier-glyph {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--tier);
  text-shadow: 0 0 12px var(--tier);
}

.tier-label {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tier-xp {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--amber);
}

.slot-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  min-width: 0;
}

.slot-sector {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.slot-title {
  font-size: 1.15rem;
  color: var(--text);
}

.slot-objective {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.slot-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.slot-action {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
}

.slot-status {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--cyan-soft);
  white-space: nowrap;
}

.slot-status.is-done { color: var(--gold); }

.slot-empty {
  grid-column: 1 / -1;
  padding: 16px;
  color: var(--muted);
}

.chip-row {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(0, 229, 255, 0.04);
}

.chip-gate {
  min-width: 24px;
  text-align: center;
  color: var(--cyan);
  border-color: rgba(0, 229, 255, 0.35);
  font-weight: 700;
}

.chip-rule {
  color: var(--gold);
  border-color: rgba(255, 182, 39, 0.3);
  background: rgba(255, 182, 39, 0.05);
}

.chip-today {
  color: var(--amber);
  border-color: rgba(255, 182, 39, 0.45);
}

.chip-rewind {
  color: var(--amber);
  border-color: rgba(255, 182, 39, 0.45);
}

.chip-sep {
  color: var(--amber);
  font-size: 0.9rem;
  padding: 0 2px;
}

.chip-empty {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* Archive */
.archive-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.archive-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.archive-title { font-size: 1.15rem; }

.archive-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
}

.tab {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  background: rgba(0, 229, 255, 0.12);
  color: var(--cyan);
}

.archive-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.archive-row {
  --tier: var(--cyan);
  display: grid;
  grid-template-columns: 110px 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 10px 6px;
  border-bottom: 1px solid rgba(0, 229, 255, 0.07);
}

.archive-row:last-child { border-bottom: none; }
.archive-row.diff-easy { --tier: var(--teal); }
.archive-row.diff-hard { --tier: var(--amber); }

.archive-tier {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tier);
}

.archive-tier::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--tier);
  box-shadow: 0 0 8px var(--tier);
  vertical-align: middle;
}

.archive-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.archive-name { font-weight: 600; }

.archive-sector {
  font-size: 0.75rem;
  color: var(--muted);
}

.archive-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.archive-best {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.control-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==========================================================================
   4. Puzzle chamber
   ========================================================================== */
.screen-game {
  --tier: var(--cyan);
}

.screen-game[data-difficulty="easy"] { --tier: var(--teal); }
.screen-game[data-difficulty="hard"] { --tier: var(--amber); }

.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}

.game-meta { min-width: 0; }

.game-meta h2 {
  font-size: 1.6rem;
}

.game-meta .kicker #game-difficulty { color: var(--tier); }

.game-header-actions {
  display: flex;
  gap: 8px;
}

.briefing {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 18px;
  border-left: 3px solid var(--tier);
  background: linear-gradient(90deg, rgba(0, 229, 255, 0.06), transparent 80%);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.mission-intro {
  color: var(--text-dim);
}

.mission-objective {
  font-weight: 600;
}

.objective-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 8px;
  border-radius: 4px;
  background: rgba(255, 182, 39, 0.14);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  vertical-align: 2px;
}

.chamber {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 1.35fr) minmax(220px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.chamber-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Target */
.target-readout {
  display: flex;
  justify-content: center;
  padding: 14px 0;
  border: 1px dashed rgba(255, 182, 39, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(255, 182, 39, 0.04);
}

.target-condition {
  font-size: 0.84rem;
  color: var(--text-dim);
}

.rules-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.82rem;
}

.rule-label { color: var(--muted); }
.rule-detail { font-family: var(--font-mono); color: var(--text); text-align: right; }
.rule.is-next { border-color: rgba(255, 182, 39, 0.5); }
.rule.is-next .rule-detail { color: var(--amber); }
.rule.is-done { border-color: rgba(29, 233, 182, 0.4); }
.rule.is-done .rule-detail { color: var(--teal); }

.start-readout {
  margin-top: auto;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Centre: state circle */
.chamber-core {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background:
    radial-gradient(circle at 50% 45%, rgba(0, 229, 255, 0.10), transparent 60%),
    var(--panel);
}

.core-head {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
}

.phase-badge {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  color: var(--cyan);
}

.phase-badge.is-rewind { color: var(--amber); border-color: var(--amber); box-shadow: var(--glow-amber); }
.phase-badge.is-locked { color: var(--danger); border-color: var(--danger); }
.phase-badge.is-stabilised { color: #02121a; background: var(--gold); border-color: var(--gold); box-shadow: var(--glow-amber); }

.core-container {
  width: 100%;
  max-width: 360px;
}

.bloch {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.bloch-circle {
  fill: rgba(0, 229, 255, 0.03);
  stroke: rgba(0, 229, 255, 0.55);
  stroke-width: 1.5;
}

.bloch-axis {
  stroke: rgba(0, 229, 255, 0.18);
  stroke-dasharray: 3 5;
}

.bloch-band {
  stroke: var(--amber);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.55;
  filter: drop-shadow(0 0 6px var(--amber));
}

.bloch-label {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 16px;
  text-anchor: middle;
}

.orbit-dash {
  fill: none;
  stroke: rgba(0, 229, 255, 0.12);
  stroke-dasharray: 2 10;
  transform-origin: 180px 180px;
  animation: orbit 60s linear infinite;
}

.orbit-tilt {
  fill: none;
  stroke: rgba(255, 182, 39, 0.16);
  transform-origin: 180px 180px;
  animation: orbit 40s linear infinite reverse;
}

.bloch-target line {
  stroke: var(--amber);
  stroke-width: 2;
  stroke-dasharray: 6 6;
  opacity: 0.7;
}

.bloch-target circle {
  fill: none;
  stroke: var(--amber);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px var(--amber));
}

.bloch-target,
.bloch-arrow {
  transform-origin: 180px 180px;
  transform-box: view-box;
}

.bloch-arrow {
  transition: transform 0.55s cubic-bezier(0.5, 0, 0.2, 1.2);
}

.bloch-arrow.no-anim { transition: none; }

.bloch-arrow line {
  stroke: var(--cyan);
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--cyan));
}

.bloch-arrow circle {
  fill: #e9fdff;
  stroke: var(--cyan);
  stroke-width: 3;
  filter: drop-shadow(0 0 10px var(--cyan));
}

.bloch-heart {
  transform-origin: 180px 180px;
  transform-box: view-box;
  animation: pulse 2.4s ease-in-out infinite alternate;
}

.trail-dot {
  fill: rgba(0, 229, 255, 0.35);
}

.waypoint rect {
  fill: rgba(5, 11, 24, 0.9);
  stroke: var(--muted);
  stroke-width: 1.5;
}

.waypoint text {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  text-anchor: middle;
}

.waypoint.is-next rect { stroke: var(--amber); filter: drop-shadow(0 0 6px var(--amber)); }
.waypoint.is-next text { fill: var(--amber); }
.waypoint.is-done rect { stroke: var(--teal); fill: rgba(29, 233, 182, 0.2); }
.waypoint.is-done text { fill: var(--teal); }

.bloch.is-pulse .bloch-circle {
  animation: circlePulse 0.6s ease;
}

@keyframes circlePulse {
  0%   { stroke-width: 1.5; stroke: rgba(0, 229, 255, 0.55); }
  30%  { stroke-width: 5; stroke: var(--cyan); }
  100% { stroke-width: 1.5; stroke: rgba(0, 229, 255, 0.55); }
}

.screen-game.is-won .bloch-arrow line { stroke: var(--gold); filter: drop-shadow(0 0 10px var(--gold)); }
.screen-game.is-won .bloch-arrow circle { stroke: var(--gold); }
.screen-game.is-won .bloch-circle { stroke: var(--gold); filter: drop-shadow(0 0 12px var(--amber)); }
.screen-game.is-rewind .bloch-circle { stroke: var(--amber); }

.state-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 82px;
}

.readout-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.state-note {
  font-size: 0.76rem;
  color: var(--gold);
  text-align: center;
}

/* Amplitudes and probabilities */
.amplitudes-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.amp-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
}

.amp-name {
  font-size: 0.95rem;
  color: var(--text);
}

.amp-name small {
  color: var(--muted);
  font-size: 0.72rem;
}

.amp-value {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--cyan);
  text-align: right;
}

.amp-value.is-negative { color: var(--amber); }
.amp-phase .amp-value { font-size: 0.85rem; color: var(--text-dim); }

.probabilities-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prob-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.prob-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.prob-top span:last-child {
  font-family: var(--font-mono);
  color: var(--text);
}

/* Probability bars (original) */
.bar-container {
  height: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0090a8, var(--cyan));
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.6);
  transition: width 0.45s ease-in-out;
}

.bar-1 {
  background: linear-gradient(90deg, #a86a00, var(--amber));
  box-shadow: 0 0 10px rgba(255, 182, 39, 0.6);
}

.prob-sum {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}

/* Gate console */
.console {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.console-status {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  color: var(--text);
}

.stat-limit {
  font-size: 0.8rem;
  color: var(--amber);
}

.history-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  min-height: 26px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.btn-gate {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 16px 10px 12px;
  background:
    radial-gradient(circle at 50% 0%, rgba(0, 229, 255, 0.18), transparent 70%),
    var(--panel-raised);
  border: 1px solid rgba(0, 229, 255, 0.45);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, border-color 0.2s;
}

.btn-gate:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: var(--cyan);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.4);
}

.btn-gate:active:not(:disabled) {
  transform: scale(0.95);
}

.gate-glyph {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(0, 229, 255, 0.8);
}

.gate-name {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.gate-key {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--muted);
}

.btn-gate:disabled {
  cursor: not-allowed;
  opacity: 0.35;
  border-style: dashed;
  box-shadow: none;
}

.btn-gate.is-offline .gate-glyph { color: var(--muted); text-shadow: none; }

.btn-gate.is-echo-locked {
  border-color: rgba(255, 182, 39, 0.5);
  border-style: dashed;
}

.btn-gate.is-echo-locked .gate-glyph { color: var(--amber); text-shadow: none; opacity: 0.6; }

.btn-gate.is-fired {
  animation: gateFire 0.45s ease;
}

.btn-gate.is-denied {
  animation: gateDeny 0.35s ease;
}

@keyframes gateFire {
  0%   { box-shadow: 0 0 0 rgba(0, 229, 255, 0); }
  30%  { box-shadow: 0 0 34px rgba(0, 229, 255, 0.9); background: rgba(0, 229, 255, 0.25); }
  100% { box-shadow: 0 0 0 rgba(0, 229, 255, 0); }
}

@keyframes gateDeny {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.btn-utility {
  font-size: 0.75rem;
  padding: 9px 16px;
}

.btn-hint {
  border-color: rgba(255, 182, 39, 0.45);
  color: var(--gold);
}

.message-text {
  min-height: 1.6em;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--cyan-soft);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
}

.message-text::before {
  content: "VESTA › ";
  color: var(--muted);
}

.message-text.tone-good { color: var(--teal); }
.message-text.tone-warn { color: var(--gold); border-color: rgba(255, 182, 39, 0.35); }
.message-text.tone-win { color: #02121a; background: var(--gold); border-color: var(--gold); }
.message-text.tone-win::before { color: rgba(2, 18, 26, 0.6); }

.hint-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hint-list:empty { display: none; }

.hint-item {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  border-left: 2px solid var(--amber);
  background: rgba(255, 182, 39, 0.05);
  font-size: 0.88rem;
  color: var(--text-dim);
}

.hint-index {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber);
  padding-top: 2px;
}

/* ==========================================================================
   5. Results
   ========================================================================== */
.result-panel {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 182, 39, 0.12), transparent 55%),
    var(--panel);
  border-color: rgba(255, 182, 39, 0.3);
}

.result-emblem svg {
  width: 110px;
  height: 110px;
  overflow: visible;
}

.emblem-ring {
  fill: none;
  stroke: var(--amber);
  stroke-width: 2;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  filter: drop-shadow(0 0 8px var(--amber));
}

.emblem-ring.inner {
  stroke: var(--cyan);
  filter: drop-shadow(0 0 8px var(--cyan));
}

.emblem-check {
  fill: none;
  stroke: var(--gold);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 80;
  stroke-dashoffset: 80;
}

.screen-result:not(.hidden) .emblem-ring { animation: draw 0.9s ease forwards; }
.screen-result:not(.hidden) .emblem-ring.inner { animation-delay: 0.2s; }
.screen-result:not(.hidden) .emblem-check { animation: draw 0.5s 0.7s ease forwards; }

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

#result-kicker { color: var(--amber); }

#result-title {
  font-size: 2rem;
}

.result-narrative {
  max-width: 600px;
  color: var(--text-dim);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.result-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  border-right: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.result-stats div:last-child { border-right: none; }

.result-stats dt {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-stats dd {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  color: var(--text);
}

#result-xp { color: var(--amber); text-shadow: var(--glow-amber); }

.result-breakdown {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
}

.result-breakdown li {
  padding: 6px 12px;
  border-left: 2px solid var(--line-strong);
  font-size: 0.88rem;
  color: var(--text-dim);
}

.result-breakdown .tone-good { border-left-color: var(--teal); color: var(--text); }
.result-breakdown .tone-gold { border-left-color: var(--amber); color: var(--gold); background: rgba(255, 182, 39, 0.06); }
.result-breakdown .tone-muted { color: var(--muted); }

.result-sequence {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ==========================================================================
   Overlays: field notes and confirmation
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  background: rgba(1, 4, 10, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
}

.overlay-card {
  width: 100%;
  max-width: 980px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 0 60px rgba(0, 229, 255, 0.12);
  animation: riseIn 0.3s ease;
}

.overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.note-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 229, 255, 0.025);
  font-size: 0.88rem;
  color: var(--text-dim);
}

.note-block strong { color: var(--text); }

.note-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.note-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}

.note-table td {
  padding: 6px;
  border-bottom: 1px solid rgba(0, 229, 255, 0.06);
  vertical-align: top;
}

.gate-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--cyan);
}

.matrix {
  font-family: var(--font-mono);
  white-space: nowrap;
  color: var(--text);
}

.note-small {
  font-size: 0.78rem;
  color: var(--muted);
}

.rule-defs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
}

.rule-defs dt {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--amber);
  white-space: nowrap;
}

.confirm-card {
  max-width: 480px;
  margin-top: 15vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-color: rgba(255, 90, 110, 0.45);
}

.confirm-card p { color: var(--text-dim); }

.noscript {
  position: relative;
  z-index: 2;
  padding: 20px;
  text-align: center;
  color: var(--gold);
}

/* ==========================================================================
   Responsive Adjustments (laptop → phone)
   ========================================================================== */
@media (max-width: 1080px) {
  .chamber {
    grid-template-columns: 1fr 1fr;
  }

  .chamber-core {
    grid-column: 1 / -1;
    order: -1;
  }
}

@media (max-width: 860px) {
  .topbar {
    position: relative;
    flex-wrap: wrap;
    padding: 8px 16px;
    gap: 8px;
  }

  .hud {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .hud-item { min-width: 0; padding: 2px 8px; }
  .hud-item:first-child { border-left: none; padding-left: 0; }

  #btn-open-notes { margin-left: auto; }

  .control-grid {
    grid-template-columns: 1fr;
  }

  /* Compact core panel: visual beside the daily status */
  .core-panel {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 6px 18px;
    align-items: center;
  }

  .core-panel > .kicker,
  .core-panel > .control-title,
  .core-panel > .core-stats,
  .core-panel > .streak-note { grid-column: 1 / -1; }

  .core-visual svg { max-width: 150px; }

  .core-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .core-stats div {
    flex-direction: column;
    gap: 0;
  }

  .core-stats dd { text-align: left; }

  .result-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .result-stats div:nth-child(3) { border-right: none; }
  .result-stats div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 640px) {
  #app {
    padding: 16px 16px 40px;
  }

  .hud-rank { display: none; }

  .mission-slot {
    grid-template-columns: 82px 1fr;
  }

  .tier-label {
    font-size: 0.56rem;
    letter-spacing: 0.06em;
  }

  .core-panel { grid-template-columns: 110px 1fr; }
  .core-visual svg { max-width: 110px; }
  .core-stats { grid-template-columns: 1fr 1fr; }

  .slot-action {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--line);
    padding: 10px 14px;
  }

  .slot-body { padding: 12px 14px; }

  .archive-row {
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
  }

  .archive-tier { grid-column: 1 / -1; }
  .archive-meta { grid-column: 1; }
  .archive-row .btn { grid-column: 2; grid-row: 2 / span 2; }

  .game-header {
    grid-template-columns: 1fr auto;
  }

  #btn-game-back { justify-self: start; }

  .game-meta { grid-column: 1 / -1; grid-row: 2; }
  .game-meta h2 { font-size: 1.3rem; }

  /* Phone: state circle, then the gate console, then the detail panels */
  .chamber { display: contents; }
  .chamber-core { order: 1; }
  .console { order: 2; }
  .amp-panel { order: 3; }
  .target-panel { order: 4; }

  .console-status {
    grid-template-columns: 1fr 1fr;
  }

  .stat-history {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .gate-glyph { font-size: 1.8rem; }
  .gate-key { display: none; }
  .gate-name { font-size: 0.58rem; letter-spacing: 0.04em; }

  .ket.huge { font-size: 1.7rem; }

  .result-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-stats div { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .result-stats div:nth-child(2n) { border-right: none; }
  .result-stats div:nth-child(3) { border-right: 1px solid var(--line); }
  .result-stats div:last-child { grid-column: 1 / -1; border-bottom: none; }

  .tutorial-nav .btn { flex: 1 1 40%; }
  .tutorial-nav .btn-primary { margin-left: 0; }

  .button-group .btn { width: 100%; }
}

/* Turn movement off for people who ask their device for less motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .emblem-ring,
  .emblem-check {
    stroke-dashoffset: 0;
  }
}
