:root {
  --bg: #0b1026;
  --bg2: #141b3d;
  --panel: #1c2550;
  --panel2: #253066;
  --line: #3a4687;
  --ink: #f4f6ff;
  --muted: #aab3dd;
  --accent: #ffd23f;
  --good: #3ddc84;
  --bad: #ff4d5e;
  --blue: #4da3ff;
  --radius: 18px;
  --tap: 60px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  font-family: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom on iPad */
}
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
h1, h2, h3 { margin: 0.2em 0; line-height: 1.1; }
h2 { font-size: clamp(24px, 4vw, 34px); }
h3 { font-size: 20px; }
.sub { color: var(--muted); margin: 0.4em 0; }
.red { color: var(--bad); }

.stars {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1.5px 1.5px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 25% 70%, #cfe 50%, transparent 51%),
    radial-gradient(2px 2px at 40% 35%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 85%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70% 15%, #ffd 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 55%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 92% 88%, #cdf 50%, transparent 51%),
    radial-gradient(1px 1px at 5% 92%, #fff 50%, transparent 51%),
    radial-gradient(ellipse at 20% 0%, #26306b 0%, transparent 55%),
    radial-gradient(ellipse at 100% 100%, #3a1d5c 0%, transparent 50%),
    var(--bg);
  background-size: 300px 300px, 260px 260px, 410px 410px, 330px 330px, 370px 370px, 290px 290px, 450px 450px, 240px 240px, 100% 100%, 100% 100%, 100% 100%;
}

#app { min-height: 100dvh; }
/* No long-press text selection or callout menus mid-game on iPad. */
.screen.game, .overlay { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.screen {
  max-width: 1100px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }

.logo {
  font-size: clamp(40px, 8vw, 76px); font-weight: 700; letter-spacing: -1px; text-align: center;
  text-shadow: 0 5px 0 #000, 0 0 30px rgba(255, 77, 94, 0.35);
}
.logo span { color: var(--bad); }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 10px 22px; border-radius: var(--radius);
  border: 3px solid #0a0e22; background: var(--panel2); box-shadow: var(--shadow);
  font-size: 20px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.08s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1a1400; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.big { min-height: 76px; font-size: 24px; padding: 12px 28px; flex-direction: column; gap: 2px; }
.btn.big small { font-size: 15px; font-weight: 500; opacity: 0.8; }
.btn.small { min-height: 50px; padding: 6px 14px; font-size: 18px; }
.btn.tiny { min-height: 44px; padding: 4px 12px; font-size: 16px; border-radius: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.icon-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 3px solid #0a0e22; background: var(--panel2);
  font-size: 24px; cursor: pointer; box-shadow: var(--shadow); flex: none;
}
.chip { min-height: 48px; padding: 6px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); font-size: 18px; cursor: pointer; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }

.topbar { display: flex; align-items: center; gap: 12px; width: 100%; }
.topbar .coins { margin-left: auto; }
.coins { font-size: 22px; font-weight: 600; background: rgba(0,0,0,.3); padding: 6px 14px; border-radius: 999px; white-space: nowrap; }

.panel { background: var(--panel); border: 3px solid var(--line); border-radius: 24px; padding: 18px; margin: 14px 0; }
.bar { height: 16px; background: #0a0e22; border-radius: 999px; overflow: hidden; border: 2px solid #0a0e22; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #3ddc84, #8cf5b5); border-radius: 999px; transition: width 0.6s; }

/* ---------- profiles ---------- */
.profile-list { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.profile-card {
  width: 160px; min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel); border: 3px solid var(--line); border-radius: 22px; cursor: pointer; padding: 12px;
}
.profile-card:active { transform: scale(0.97); }
.profile-card .p-name { font-size: 22px; font-weight: 600; }
.profile-card small { color: var(--muted); }
.profile-card .plus { font-size: 64px; line-height: 1; color: var(--accent); }
.new-profile { width: min(520px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 18px; width: 100%; text-align: left; }
.field input {
  font: inherit; font-size: 24px; padding: 12px 16px; border-radius: 14px; border: 3px solid var(--line);
  background: #0e1433; color: var(--ink); width: 100%;
}
.swatches { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.swatch {
  width: 54px; height: 54px; border-radius: 50%; background: var(--c); border: 4px solid #0a0e22; cursor: pointer;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.25);
}
.swatch.on { outline: 4px solid #fff; outline-offset: 2px; }

/* ---------- home ---------- */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: center; margin-top: 8px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rank-card { background: var(--panel); border: 3px solid var(--line); border-radius: 22px; padding: 16px 20px; width: min(420px, 100%); text-align: center; }
.rank-title { font-size: 26px; }
.rank-title strong { color: var(--accent); }
.rank-sub { color: var(--muted); margin: 4px 0 10px; font-size: 18px; }
.rank-card small { display: block; margin-top: 8px; color: var(--muted); }
.menu { display: flex; flex-direction: column; gap: 16px; }
.floaty { animation: floaty 3.5s ease-in-out infinite; }
@keyframes floaty { 50% { transform: translateY(-10px) rotate(-3deg); } }

/* ---------- tables ---------- */
.table-chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: min(520px, 100%); margin: 10px 0; }
.table-chip {
  min-height: 84px; border-radius: 20px; border: 3px solid #0a0e22; background: var(--panel); font-size: 32px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.table-chip.on { background: var(--accent); color: #1a1400; }

/* ---------- wardrobe ---------- */
.wardrobe { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.wardrobe .preview { display: flex; justify-content: center; padding-top: 30px; }
.wardrobe .swatches { justify-content: flex-start; }
.hats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.hat-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; min-height: 140px;
  background: var(--panel); border: 3px solid var(--line); border-radius: 18px; cursor: pointer;
}
.hat-card.on { border-color: var(--accent); background: var(--panel2); }
.hat-card.locked { opacity: 0.5; }
.hat-card small { color: var(--accent); font-weight: 600; }

/* ---------- star map grid ---------- */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 10px 0; color: var(--muted); }
.legend .cell { width: 28px; height: 28px; display: inline-grid; }
.starmap-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.fact-grid { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 3px; max-width: 640px; }
.fact-grid .head, .fact-grid .corner { display: grid; place-items: center; font-weight: 700; color: var(--accent); aspect-ratio: 1; font-size: clamp(11px, 2vw, 17px); }
.cell {
  position: relative; aspect-ratio: 1; border-radius: 7px; display: grid; place-items: center;
  background: #121a3d; border: 2px solid #232d5e; color: #5c6899; font-size: clamp(10px, 1.8vw, 15px); padding: 0; cursor: default;
}
button.cell { cursor: pointer; }
.cell i { font-style: normal; position: absolute; top: 0; right: 3px; font-size: 0.7em; }
.cell.dim { opacity: 0.35; }
.cell.m-practicing { background: #3a2f10; border-color: #9a7a1d; color: #ffd98a; }
.cell.m-confident { background: #134a33; border-color: #3ddc84; color: #c9ffe0; }
.cell.m-star { background: #ffd23f; border-color: #fff3b0; color: #3a2b00; box-shadow: 0 0 12px rgba(255,210,63,.6); }
.cell.sel { outline: 3px solid #fff; }
.cell-tip { background: var(--panel); border: 3px solid var(--line); border-radius: 20px; padding: 16px; position: sticky; top: 16px; }

/* ---------- game ---------- */
.screen.game { max-width: none; height: 100dvh; display: flex; flex-direction: column; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.hud { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.taskbar { flex: 1 1 220px; min-width: 180px; }
.taskbar span { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: var(--muted); }
.taskbar .bar { height: 22px; border-color: var(--line); background: #060918; }
.sab-banner {
  margin-top: 8px; padding: 10px 16px; border-radius: 14px; background: var(--bad); color: #fff; font-weight: 700; font-size: 20px; text-align: center;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { to { background: #a3122a; } }
.game-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr; gap: 12px; margin-top: 10px; }
.tasklist { background: rgba(20, 27, 61, 0.85); border: 3px solid var(--line); border-radius: 18px; padding: 10px; overflow: auto; }
.tasklist h3 { margin: 0 0 6px 6px; }
.tasklist ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tasklist button {
  width: 100%; text-align: left; min-height: 52px; padding: 8px 10px; border-radius: 12px; border: 0; background: var(--panel2);
  font-size: 17px; font-weight: 600; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
}
.tasklist small { color: var(--muted); font-weight: 500; font-size: 14px; }
.tasklist li.done button { opacity: 0.55; text-decoration: line-through; background: transparent; }
.tasklist li.sab button { background: var(--bad); color: #fff; }
.tasklist li.sab small { color: #ffe0e4; }
.map-host { min-height: 0; display: flex; align-items: center; justify-content: center; border-radius: 22px; transition: box-shadow 0.3s; }
.map-host.alarm { box-shadow: inset 0 0 0 6px var(--bad), 0 0 40px rgba(255, 77, 94, 0.5); animation: alarm 1s infinite alternate; }
@keyframes alarm { to { box-shadow: inset 0 0 0 6px #7a0f1d, 0 0 10px rgba(255, 77, 94, 0.2); } }

.ship { width: 100%; height: 100%; max-height: 100%; display: block; }
.ship .hull { fill: #10163a; stroke: #2c3772; stroke-width: 6; rx: 40; }
.ship .corridors line { stroke: #0a0e22; stroke-width: 58; stroke-linecap: round; }
.ship .corridors-inner line { stroke: #4a5068; stroke-width: 44; stroke-linecap: round; }
.room { cursor: pointer; outline: none; }
.room-floor { fill: #6b7189; stroke: #0a0e22; stroke-width: 8; transition: fill 0.2s; }
.room:focus-visible .room-floor { stroke: var(--blue); }
.room.has-task .room-floor { fill: #7b7f64; }
.room.has-sabotage .room-floor { fill: #9a4150; animation: roomalarm 0.8s infinite alternate; }
@keyframes roomalarm { to { fill: #c44456; } }
.room-label { fill: #fff; font-size: 21px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: #0a0e22; stroke-width: 6px; pointer-events: none; }
.marker circle { fill: var(--accent); stroke: #0a0e22; stroke-width: 4; }
.marker circle.ok { fill: var(--good); }
.marker circle.bad { fill: var(--bad); }
.marker text { font-size: 22px; font-weight: 700; text-anchor: middle; fill: #1a1400; pointer-events: none; }
.marker text.ok, .marker text.bad { fill: #fff; }
.marker.task { animation: bounce 1.2s ease-in-out infinite; transform-box: fill-box; }
@keyframes bounce { 50% { translate: 0 -6px; } }
.actor { pointer-events: none; }
.actor .shadow { fill: rgba(0, 0, 0, 0.35); }
.actor.walking .bob { animation: walkbob 0.32s ease-in-out infinite; }
@keyframes walkbob { 50% { transform: translateY(-4px); } }
.actor .you { fill: #fff; font-size: 16px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: #0a0e22; stroke-width: 5px; }
.darkness { fill: #000; opacity: 0; transition: opacity 0.8s; pointer-events: none; }
.ship.lights-out .darkness { opacity: 0.9; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 22, 0.72); padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  overflow: auto;
}
.overlay[hidden] { display: none; }
#modal { z-index: 30; }
.modal-card {
  width: min(560px, 100%); max-height: 100%; overflow: auto; background: var(--bg2); border: 4px solid var(--line); border-radius: 28px;
  padding: 22px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); animation: pop 0.25s ease-out;
}
.modal-card.wide { width: min(980px, 100%); }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.modal-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.modal-card.wide .modal-actions { position: sticky; bottom: -22px; background: var(--bg2); padding: 10px 0 14px; margin-bottom: -8px; }
.modal-card.wide .modal-actions:empty { display: none; }
.lineup { display: flex; justify-content: center; align-items: flex-end; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.steps { text-align: left; font-size: 19px; line-height: 1.5; max-width: 420px; margin: 10px auto; }
.pill { display: inline-block; background: var(--accent); color: #1a1400; font-weight: 700; border-radius: 50%; width: 28px; height: 28px; text-align: center; line-height: 28px; }
.settings { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.toggle { min-height: var(--tap); border-radius: 16px; border: 3px solid var(--line); background: var(--panel); font-size: 20px; display: flex; justify-content: space-between; align-items: center; padding: 0 18px; cursor: pointer; }
.toggle.on b { color: var(--good); }

.clue-card { background: #fff7d6; color: #2a2100; border-radius: 20px; padding: 18px; border: 4px solid #0a0e22; transform: rotate(-1deg); }
.clue-card.small { padding: 10px 14px; }
.clue-kicker { font-weight: 700; letter-spacing: 1px; color: #8a6b00; }
.clue-text { font-size: 24px; font-weight: 600; margin: 8px 0 0; }
.clue-card.small .clue-text { font-size: 19px; }
.why { font-size: 20px; background: var(--panel); border-radius: 14px; padding: 12px; }

.board { display: grid; grid-template-columns: 300px 1fr; gap: 16px; text-align: left; margin-top: 12px; }
.clue-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.clue-list li { background: #fff7d6; color: #2a2100; border-radius: 14px; padding: 10px 12px; font-size: 18px; font-weight: 500; border: 3px solid #0a0e22; }
.clue-list li.locked { background: var(--panel); color: var(--muted); border-color: var(--line); }
.suspects { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.suspect {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--panel); border: 3px solid var(--line); border-radius: 18px; padding: 8px 10px; position: relative;
}
.suspect.crossed .crew, .suspect.crossed .s-info { opacity: 0.35; }
.suspect.crossed::after {
  content: ''; position: absolute; left: 10px; top: 50%; width: 70px; height: 6px; background: var(--bad); border-radius: 3px; transform: rotate(-35deg);
}
.s-name { font-size: 20px; font-weight: 700; }
.s-badge {
  display: inline-block; font-size: 26px; font-weight: 700; background: #0a0e22; color: var(--accent);
  padding: 0 10px; border-radius: 10px; margin: 2px 0; min-width: 52px; text-align: center;
}
.s-hat { color: var(--muted); font-size: 15px; }
.s-actions { display: flex; flex-direction: column; gap: 6px; }
.s-tag { color: var(--good); font-weight: 700; }

.splash { text-align: center; animation: pop 0.3s ease-out; }
.splash h1 {
  font-size: clamp(44px, 9vw, 96px); color: #fff; text-shadow: 0 6px 0 var(--bad), 0 0 40px var(--bad); letter-spacing: 2px;
  animation: shakeX 0.4s 2;
}
.splash p { font-size: 26px; }
.eject { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.eject::before { content: ''; position: absolute; inset: 0; background: inherit; }
.drifter { position: absolute; top: 30%; left: -120px; animation: drift 4.5s linear forwards; }
@keyframes drift { to { left: calc(100% + 40px); transform: rotate(720deg); } }
.eject-text { position: relative; font-size: clamp(24px, 4vw, 40px); font-weight: 600; margin-top: 180px; padding: 0 16px; text-align: center; }

#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(560px, 92vw); }
.toast { background: #0a0e22; border: 3px solid var(--accent); padding: 12px 20px; border-radius: 16px; font-size: 19px; font-weight: 600; text-align: center; animation: pop 0.2s; transition: opacity 0.4s; }
.toast.out { opacity: 0; }

/* ---------- task panel ---------- */
.task-panel {
  width: min(900px, 100%); max-height: 100%; overflow: auto; background: #1a2148; border: 5px solid #0a0e22; border-radius: 28px;
  box-shadow: 0 0 0 4px var(--line), 0 30px 80px rgba(0,0,0,.6); padding: 14px 18px 20px; position: relative; animation: pop 0.2s;
}
.task-panel.sabotage { box-shadow: 0 0 0 4px var(--bad), 0 0 60px rgba(255, 77, 94, 0.5); }
.task-head { display: flex; align-items: center; gap: 12px; }
.task-head h2 { font-size: 26px; margin: 0; }
.task-blurb { margin: 0; color: var(--muted); }
.task-icon { font-size: 38px; }
.task-steps { margin-left: auto; display: flex; gap: 6px; }
.task-steps i { width: 16px; height: 16px; border-radius: 50%; background: #0a0e22; border: 2px solid var(--line); }
.task-steps i.on { background: var(--good); border-color: var(--good); }
.btn-close { width: 52px; height: 52px; border-radius: 50%; border: 3px solid #0a0e22; background: var(--bad); color: #fff; font-size: 24px; font-weight: 700; cursor: pointer; flex: none; }
.task-body { margin-top: 12px; display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: start; }
.task-body > :not(.q):not(.keypad) { grid-column: 1 / -1; }
/* Board-style tasks: play area plus a side column for feedback and hints (landscape). */
.task-body.split { grid-template-columns: minmax(0, 1fr) 290px; }
.task-body.split > .play, .task-body.split > .side { grid-column: auto; }
.play { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.side { display: flex; flex-direction: column; gap: 10px; }
.side .hint { flex-direction: column; }
.side-help { color: var(--muted); font-size: 18px; margin: 0; }
.task-head { position: sticky; top: -14px; z-index: 2; background: #1a2148; padding: 6px 0; }
.task-complete {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 14, 34, 0.75); border-radius: 22px;
  font-size: clamp(36px, 7vw, 64px); font-weight: 700; color: var(--good); text-shadow: 0 4px 0 #000; animation: pop 0.3s;
}

.q { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.q-visual { display: flex; flex-direction: column; align-items: center; width: 100%; }
.q-prompt { font-size: clamp(40px, 7vw, 64px); font-weight: 700; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.q-prompt.small { font-size: clamp(30px, 5vw, 44px); }
.op { color: var(--accent); }
.entry {
  min-width: 2.2em; padding: 0 12px; border-radius: 16px; background: #0a0e22; border: 4px solid var(--line); text-align: center; color: #fff;
}
.entry.empty { color: #4a5590; }
.entry.right { border-color: var(--good); color: var(--good); }
.shake { animation: shakeX 0.35s; }
@keyframes shakeX { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.q-feedback { min-height: 1.4em; font-size: 22px; font-weight: 600; text-align: center; }
.q-feedback.good { color: var(--good); }
.q-feedback.oops { color: #ffb86b; }
.hint { background: #0f1538; border: 3px dashed #5b6bd0; border-radius: 18px; padding: 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.hint[hidden] { display: none; }
.hint-tip { font-size: 20px; flex: 1 1 240px; }
.q .hint { flex-direction: column; width: 100%; max-width: 520px; }
.q .hint-tip, .side .hint-tip { flex: none; text-align: center; }
.hint-array { margin: 0; text-align: center; }
.hint-array figcaption { font-size: 16px; }
.array .dot1 { fill: #4da3ff; }
.array .dot2 { fill: #ff9f43; }
.c1 { color: #4da3ff; font-weight: 700; }
.c2 { color: #ff9f43; font-weight: 700; }

.keypad { display: grid; grid-template-columns: repeat(3, 84px); gap: 10px; }
.keypad button {
  height: 76px; border-radius: 18px; border: 3px solid #0a0e22; background: #e8ecff; color: #0a0e22; font-size: 34px; font-weight: 700;
  box-shadow: 0 5px 0 #7f88b8; cursor: pointer;
}
.keypad button:active { transform: translateY(4px); box-shadow: 0 1px 0 #7f88b8; }
.keypad .ok { background: var(--good); box-shadow: 0 5px 0 #1b7a47; }
.keypad .hint-btn { grid-column: 1 / -1; height: 56px; font-size: 22px; background: #2d3a7a; color: #fff; box-shadow: 0 5px 0 #0a0e22; }

/* visuals inside tasks */
.card-reader { width: min(360px, 100%); background: #3b4252; border: 4px solid #0a0e22; border-radius: 16px; padding: 10px; }
.reader-screen { background: #0f2a17; color: #7dff9f; font-family: ui-monospace, Menlo, monospace; padding: 6px 10px; border-radius: 8px; font-size: 16px; }
.slot-track { position: relative; height: 44px; margin-top: 10px; background: #1b1f29; border-radius: 10px; overflow: hidden; }
.keycard { position: absolute; left: 6px; top: 2px; font-size: 32px; transition: left 0.6s ease-in; }
.card-reader.swiped .keycard { left: calc(100% - 50px); }
.scanner { position: relative; width: 150px; height: 130px; display: flex; justify-content: center; align-items: flex-end; }
.scan-pad { position: absolute; bottom: 0; width: 130px; height: 26px; border-radius: 50%; background: #1f6fd1; border: 4px solid #0a0e22; z-index: 0; }
.scanner .crew { position: relative; z-index: 1; margin-bottom: 8px; }
.scan-beam { position: absolute; left: 20px; right: 20px; height: 8px; background: rgba(77, 255, 160, 0.8); box-shadow: 0 0 16px #4dffa0; z-index: 2; animation: scan 1.6s ease-in-out infinite alternate; }
@keyframes scan { from { top: 10px; } to { top: 110px; } }
.scanner.scanned .scan-pad { background: var(--good); }
.shield-grid { display: grid; grid-template-columns: repeat(var(--cols), min(24px, calc((100vw - 400px) / var(--cols)), calc((100dvh - 430px) / var(--cols)))); gap: 3px; }
.shield-grid i { aspect-ratio: 1; background: #283275; border: 2px solid #4353a8; clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.shield-grid i.lit { animation: litup 0.3s forwards; }
@keyframes litup { to { background: #4dffa0; border-color: #fff; } }
.visual-caption { color: var(--muted); font-size: 18px; margin: 6px 0 0; }
.fuel-groups { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 480px; }
.can { display: grid; grid-template-columns: repeat(4, 12px); gap: 3px; padding: 8px; background: #3a3f55; border: 3px solid #0a0e22; border-radius: 10px 10px 6px 6px; }
.can b { width: 12px; height: 12px; border-radius: 50%; background: #ff9f43; }
.fuel-groups.loaded .can { background: #2d6b47; }
.switches { display: flex; gap: 18px; }
.switch { width: 40px; height: 74px; border-radius: 10px; background: #2a2f45; border: 3px solid #0a0e22; position: relative; }
.switch::after { content: ''; position: absolute; left: 4px; right: 4px; height: 30px; bottom: 4px; background: #666c85; border-radius: 6px; transition: all 0.25s; }
.switch.up::after { bottom: 34px; background: var(--good); }
.meltdown { width: min(360px, 100%); text-align: center; }
.melt-label { color: var(--bad); font-weight: 700; letter-spacing: 3px; font-size: 22px; animation: pulse 0.6s infinite alternate; }
.melt-bar { height: 24px; background: #0a0e22; border-radius: 999px; overflow: hidden; border: 3px solid #0a0e22; }
.melt-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff9f43, var(--bad)); transition: width 0.5s; }

/* wiring */
.wiring { width: 100%; max-height: calc(100dvh - 190px); touch-action: none; display: block; }
.wiring .board { fill: #2a2f45; stroke: #0a0e22; stroke-width: 6; }
.wiring rect:not(.board) { fill: #e8ecff; stroke: #0a0e22; stroke-width: 4; }
.wiring text { font-size: 34px; font-weight: 700; text-anchor: middle; fill: #0a0e22; pointer-events: none; }
.wiring .stub { stroke-width: 18; }
.wire-right .stub { stroke: #8a90a8; }
.wiring .plug { stroke: #0a0e22; stroke-width: 4; }
.wiring .plug.empty { fill: #8a90a8; }
.wiring .wire { stroke-width: 16; stroke-linecap: round; }
.wiring .temp { stroke-dasharray: 2 0; opacity: 0.85; }
.wire-left.selected rect { fill: #fff6c7; stroke: var(--accent); stroke-width: 6; }
.wire-left.connected rect { fill: #c9ffe0; }
.wiring.zap .board { animation: zap 0.3s; }
@keyframes zap { 50% { fill: #5a2230; } }
.wiring-help { color: var(--muted); text-align: center; margin: 6px 0 0; }

/* asteroids */
.asteroid-field {
  position: relative; height: min(calc(100dvh - 250px), 420px); border-radius: 20px; overflow: hidden; border: 4px solid #0a0e22;
  background: radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%) 0 0 / 120px 120px, radial-gradient(1.5px 1.5px at 70% 60%, #fff 50%, transparent 51%) 0 0 / 170px 170px, #05081a;
}
.asteroid {
  position: absolute; width: 96px; height: 96px; border-radius: 46% 54% 50% 50%; border: 4px solid #0a0e22; cursor: pointer;
  background: radial-gradient(circle at 30% 30%, #6f5d4c 10%, transparent 11%), radial-gradient(circle at 65% 65%, #6f5d4c 14%, transparent 15%), #9c8671;
  font-size: 34px; font-weight: 700; color: #fff; text-shadow: 0 2px 0 #000, 0 0 6px #000;
  left: var(--x); animation: fly var(--dur) linear infinite; animation-delay: var(--delay);
}
@keyframes fly { from { left: -110px; } to { left: 100%; } }
.asteroid-field.still .asteroid { animation: none; }
.asteroid.boom { animation: boom 0.5s forwards !important; background: #ffd23f; }
@keyframes boom { to { transform: scale(1.8); opacity: 0; } }
.asteroid.bonk { outline: 5px solid var(--bad); }
.cannon { position: absolute; right: 10px; bottom: 6px; font-size: 40px; transform: scaleX(-1); }

/* chart course */
.course-strip { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; font-size: 24px; font-weight: 700; }
.course-strip span { min-width: 52px; padding: 4px 8px; text-align: center; border-radius: 10px; background: #0a0e22; color: #4a5590; }
.course-strip span.on { color: var(--accent); }
.course-strip b { color: var(--muted); }
.course-help { text-align: center; font-size: 19px; margin: 8px 0; }
.starmap-nav { width: 100%; max-height: calc(100dvh - 330px); background: #05081a; border-radius: 20px; border: 4px solid #0a0e22; display: block; }
.star { cursor: pointer; }
.star .hit { fill: transparent; }
.star path { fill: #5a6290; stroke: #0a0e22; stroke-width: 3; transition: fill 0.2s; }
.star text { fill: #fff; font-size: 24px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: #05081a; stroke-width: 5px; pointer-events: none; }
.star.lit path { fill: var(--accent); }
.star.pulse path { fill: #8cf5b5; animation: pulse 0.5s infinite alternate; }
.star.bonk path { fill: var(--bad); }
.route line { stroke: var(--accent); stroke-width: 5; stroke-dasharray: 10 8; }

/* ---------- results ---------- */
.results { text-align: center; }
.victory { font-size: clamp(44px, 9vw, 84px); color: var(--blue); text-shadow: 0 5px 0 #000; }
.winners { gap: 0; }
.stats { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.stats div { background: var(--panel); border: 3px solid var(--line); border-radius: 18px; padding: 12px 18px; min-width: 140px; display: flex; flex-direction: column; }
.stats b { font-size: 40px; color: var(--accent); }
.fact-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fact-chip { background: #0a0e22; border: 2px solid #9a7a1d; color: #ffd98a; border-radius: 999px; padding: 6px 14px; font-size: 20px; font-weight: 600; }
.fact-chip.good { border-color: var(--good); color: #c9ffe0; }
.results .fact-grid { margin: 0 auto; max-width: 480px; }
/* Keep "Next mission" on screen: kids don't scroll to find it. */
.results { padding-bottom: 0; }
.results-actions {
  position: sticky; bottom: 0; z-index: 5; margin: 16px -16px 0; padding: 14px 16px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(11, 16, 38, 0));
}
.results-actions .btn.primary { animation: nudge 1.6s ease-in-out 2.5s infinite; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }


/* ---------- stakes: crew status, threat meter, ghosts ---------- */
.hud2 { display: flex; align-items: center; gap: 14px; margin-top: 8px; flex-wrap: wrap; }
.crew-row { display: flex; gap: 4px; align-items: flex-end; background: rgba(0,0,0,.3); border-radius: 14px; padding: 4px 10px; }
.crew-row .mini { position: relative; display: inline-flex; }
.crew-row .mini.lost .crew { opacity: 0.3; filter: grayscale(1); }
.crew-row .mini i { position: absolute; right: -6px; top: -4px; font-style: normal; font-size: 16px; }
.threat { flex: 1 1 240px; display: flex; align-items: center; gap: 10px; }
.threat span { font-size: 14px; font-weight: 700; letter-spacing: 1px; color: #ff9aa6; white-space: nowrap; }
.threat .bar { flex: 1; height: 18px; border-color: #5a1f2c; background: #1a0710; }
.threat .bar i { background: linear-gradient(90deg, #ff9f43, var(--bad)); transition: width 0.3s linear; }
.threat.hot .bar { animation: throb 0.6s ease-in-out infinite alternate; }
@keyframes throb { to { box-shadow: 0 0 16px var(--bad); } }
.calm-tag { color: var(--muted); font-weight: 600; }
.crew.ghost { opacity: 0.5; filter: grayscale(0.6) drop-shadow(0 0 8px #bfe6ff); }
.lineup.zapped .crew { animation: floaty 2.5s ease-in-out infinite; }
.actor.ghost { opacity: 0.45; }
.actor.ghost .bob { animation: floaty 2.5s ease-in-out infinite; }
.actor.gone { display: none; }
.suspect.lost { opacity: 0.8; }
.s-tag { font-size: 15px; text-align: center; }
.toggle small { color: var(--muted); font-size: 14px; margin-right: auto; margin-left: 10px; }

/* ---------- results: stars, level, defeat ---------- */
.star-rating { display: flex; justify-content: center; gap: 10px; margin: 4px 0; }
.big-star { font-size: clamp(56px, 10vw, 88px); color: #2a3160; text-shadow: 0 4px 0 #000; line-height: 1; }
.big-star.on { color: var(--accent); animation: starpop 0.5s both; text-shadow: 0 4px 0 #000, 0 0 24px rgba(255, 210, 63, 0.7); }
@keyframes starpop { 0% { transform: scale(0); } 70% { transform: scale(1.3) rotate(10deg); } 100% { transform: scale(1); } }
.star-reasons { list-style: none; padding: 0; margin: 4px 0 10px; display: flex; justify-content: center; gap: 8px 18px; flex-wrap: wrap; color: var(--muted); font-size: 18px; }
.star-reasons li.ok { color: var(--accent); font-weight: 600; }
.level-row { display: flex; align-items: center; gap: 12px; font-size: 20px; }
.level-row .bar { flex: 1; }
.level-row .bar i { background: linear-gradient(90deg, #4da3ff, #9ad0ff); }
.level-card { margin-top: 12px; }
.level-panel.leveled { border-color: var(--accent); box-shadow: 0 0 30px rgba(255, 210, 63, 0.35); }
.level-up { font-size: 30px; font-weight: 700; color: var(--accent); animation: pop 0.4s; margin-bottom: 6px; }
.unlock { font-size: 20px; margin-bottom: 8px; }
.unlock-panel { border-color: var(--good); box-shadow: 0 0 30px rgba(61, 220, 132, 0.3); }
.unlock-panel .level-up { color: var(--good); }
.defeat { font-size: clamp(44px, 9vw, 84px); color: var(--bad); text-shadow: 0 5px 0 #000; }
.big-line { font-size: 26px; }
.crew.impostor { filter: drop-shadow(0 0 18px var(--bad)); }
.clue-recap { text-align: left; max-width: 560px; margin: 8px auto; font-size: 19px; line-height: 1.6; }

/* ---------- ship themes (unlocked by level) ---------- */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.theme-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px; min-height: 120px; background: var(--panel); border: 3px solid var(--line); border-radius: 18px; cursor: pointer; }
.theme-card.on { border-color: var(--accent); }
.theme-card.locked { opacity: 0.5; }
.theme-card small { color: var(--accent); font-weight: 600; }
.swatch-ship { width: 90px; height: 50px; border-radius: 12px; border: 4px solid #0a0e22; background: var(--floor); box-shadow: inset 0 0 0 10px var(--hull); }
.theme-starship { --floor: #6b7189; --hull: #10163a; --hall: #4a5068; --task: #7b7f64; }
.theme-polar { --floor: #a9c9e0; --hull: #0d2a44; --hall: #6d8fae; --task: #c9d98a; }
.theme-jungle { --floor: #5e8a4f; --hull: #11261a; --hall: #3f5e36; --task: #9aa850; }
.theme-lava { --floor: #7a4a42; --hull: #2a0d0a; --hall: #5a302a; --task: #a8743a; }
.map-host .ship .hull { fill: var(--hull); }
.map-host .ship .corridors-inner line { stroke: var(--hall); }
.map-host .room-floor { fill: var(--floor); }
.map-host .room.has-task .room-floor { fill: var(--task); }
.map-host .room:hover .room-floor { filter: brightness(1.12); }

/* ---------- responsive: iPad portrait & phones ---------- */
@media (max-width: 900px) {
  .game-main { grid-template-columns: 1fr; grid-template-rows: auto auto; align-content: start; }
  .map-host { align-items: flex-start; }
  .ship { height: auto; }
  .tasklist { order: 2; max-height: 34dvh; }
  .tasklist ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .board { grid-template-columns: 1fr; }
  .starmap-wrap { grid-template-columns: 1fr; }
  .cell-tip { position: static; }
}
@media (max-width: 760px) {
  .home-grid, .wardrobe { grid-template-columns: 1fr; }
}
/* Stack a task's picture above its keypad only where there's vertical room: iPad portrait, or phones. */
@media (orientation: portrait) and (min-height: 900px), (max-width: 520px) {
  .task-body, .task-body.split { grid-template-columns: 1fr; justify-items: center; }
  .task-body > * { width: 100%; }
  .task-body > .keypad { width: auto; }
  .keypad { grid-template-columns: repeat(3, minmax(70px, 96px)); }
  .shield-grid { grid-template-columns: repeat(var(--cols), min(24px, calc((100vw - 90px) / var(--cols)))); }
  .wiring { max-height: 46dvh; }
  .asteroid-field { height: min(40dvh, 420px); }
  .starmap-nav { max-height: 42dvh; }
}
/* Narrow side-by-side (Split View): slimmer keypad. */
@media (max-width: 700px) and (orientation: portrait) and (max-height: 899px) {
  .keypad { grid-template-columns: repeat(3, 70px); gap: 8px; }
  .keypad button { height: 64px; font-size: 28px; }
  .task-body.split { grid-template-columns: 1fr; }
}
@media (max-height: 700px) and (orientation: landscape) {
  .keypad button { height: 60px; font-size: 28px; }
  .keypad .hint-btn { height: 46px; }
  .q-prompt { font-size: 40px; }
}

/* ---------- reduced motion ---------- */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important;
}
.reduce-motion .asteroid { animation: none !important; }
.reduce-motion .drifter { left: 50%; transform: translateX(-50%); }
