:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #151d32;
  --surface-soft: #1d2943;
  --text: #f4f7ff;
  --muted: #bdc8dd;
  --accent: #72e0ad;
  --accent-strong: #26b977;
  --focus: #ffd166;
  --danger: #ffb4ab;
  --border: #334564;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background:
    radial-gradient(circle at 15% -10%, rgba(88, 101, 242, .24), transparent 38rem),
    radial-gradient(circle at 100% 25%, rgba(38, 185, 119, .13), transparent 32rem),
    var(--bg);
  color: var(--text);
  font: 16px/1.58 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, textarea, input { font: inherit; }
button, label.choice { min-height: 48px; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  border-bottom: 1px solid rgba(255,255,255,.09);
  background: rgba(11, 16, 32, .91);
  backdrop-filter: blur(14px);
}
.brand { color: var(--text); font-size: 1.08rem; font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.progress-wrap { display: grid; min-width: min(54vw, 320px); gap: 4px; color: var(--muted); font-size: .78rem; text-align: right; }
progress { width: 100%; height: 8px; accent-color: var(--accent-strong); }

.mission-shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: 26px max(16px, env(safe-area-inset-right)) calc(40px + var(--safe-bottom)) max(16px, env(safe-area-inset-left));
}
.timeline { display: grid; gap: 18px; }
.bubble, .question-card, .state-card, .completion-card, .confirm-card {
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .18);
}
.bubble { padding: 20px; background: rgba(21, 29, 50, .92); }
.bubble h2 { margin: 0 0 12px; font-size: clamp(1.15rem, 4vw, 1.55rem); color: var(--accent); }
.bubble p { margin: 0 0 12px; white-space: pre-line; }
.bubble p:last-child { margin-bottom: 0; }

.question-card { padding: 20px; background: rgba(29, 41, 67, .96); }
.question-card.current { border-color: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent-strong), 0 18px 45px rgba(0,0,0,.2); }
.question-number { margin: 0 0 6px; color: var(--accent); font-size: .82rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.question-card h2 { margin: 0 0 16px; font-size: 1.06rem; line-height: 1.45; }
.optional { color: var(--muted); font-size: .86rem; font-weight: 500; }
.choices { display: grid; gap: 10px; border: 0; padding: 0; margin: 0 0 16px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #121a2d;
  cursor: pointer;
}
.choice:hover { border-color: #6680aa; }
.choice:has(input:checked) { border-color: var(--accent); background: rgba(38,185,119,.13); }
.choice input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent-strong); }
textarea {
  display: block;
  width: 100%;
  min-height: 116px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #0e1628;
  color: var(--text);
}
textarea.long { min-height: 180px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.button {
  min-height: 48px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: var(--accent-strong);
  color: #06160f;
  font-weight: 800;
  cursor: pointer;
}
.button:hover { filter: brightness(1.08); }
.button.secondary { border-color: var(--border); background: transparent; color: var(--text); }
.button:disabled { opacity: .55; cursor: wait; }
.save-state { min-height: 1.5em; margin: 10px 0 0; color: var(--muted); font-size: .88rem; }
.error { color: var(--danger); }

.state-card, .completion-card, .confirm-card { padding: clamp(24px, 6vw, 40px); background: rgba(21,29,50,.96); text-align: center; }
.state-card h1, .completion-card h1, .confirm-card h2 { margin-top: 0; }
.state-card a, .completion-card a { color: var(--accent); }
.artifact { display: block; width: min(100%, 480px); max-height: 52dvh; object-fit: contain; margin: 22px auto 12px; border-radius: 16px; border: 1px solid var(--border); }
.caption { color: var(--muted); }
.spinner { width: 34px; height: 34px; margin: 0 auto 18px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 600px), (max-height: 620px) {
  .topbar { position: static; align-items: flex-start; flex-direction: column; gap: 8px; }
  .progress-wrap { width: 100%; min-width: 0; text-align: left; }
  .mission-shell { padding-top: 18px; }
  .bubble, .question-card { border-radius: 16px; padding: 17px; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .spinner { animation: none; }
}
