:root {
  color-scheme: dark;
  --bg: #131a33;
  --bg-deep: #0d1328;
  --panel: rgba(27, 34, 58, 0.82);
  --panel-soft: rgba(38, 46, 74, 0.72);
  --line: rgba(226, 207, 154, 0.22);
  --text: #f4eddc;
  --muted: #b9bfd3;
  --dim: #858ca5;
  --gold: #e8be73;
  --gold-strong: #f4d48d;
  --violet: #9b90dd;
  --green: #8ec9a4;
  --danger: #f19a83;
  --shadow-gold: rgba(232, 190, 115, 0.32);
  --font-serif: "Noto Serif SC", "Songti SC", SimSun, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  letter-spacing: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 12%, rgba(86, 98, 148, 0.28), transparent 28rem),
    radial-gradient(circle at 84% 8%, rgba(139, 127, 209, 0.18), transparent 24rem),
    linear-gradient(180deg, #192142 0%, var(--bg) 46%, var(--bg-deep) 100%);
  overflow-x: hidden;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.star-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.5) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(232,190,115,0.42) 0 1px, transparent 1.4px);
  background-size: 140px 140px, 210px 210px;
  background-position: 12px 28px, 80px 60px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.88), rgba(0,0,0,0.32));
}

.brand-bar {
  position: relative;
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding-top: max(32px, env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.brand-copy { max-width: 620px; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}
.brand-copy h1, .map-toolbar h2, .modal-card h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: 0;
}
.brand-copy h1 {
  max-width: 620px;
  font-size: 30px;
  line-height: 1.5;
}

.studio-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 206px;
  padding: 10px 12px;
  border: 1px solid rgba(232, 190, 115, 0.20);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(18, 25, 49, 0.74), rgba(31, 38, 64, 0.54));
  backdrop-filter: blur(14px);
  pointer-events: auto;
}
.studio-brand img {
  width: 68px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
  background: rgba(7, 10, 22, 0.38);
}
.studio-brand strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.studio-brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 32px 24px 40px;
}
.question-panel, .map-panel {
  width: min(1180px, 100%);
  margin: 0 auto;
  border: 1px solid rgba(232, 190, 115, 0.16);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(18px);
}
.question-panel {
  padding: 32px;
  box-shadow: none;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}
.progress-track {
  flex: 1;
  height: 3px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}
.progress-track i {
  display: block;
  height: 100%;
  width: 12.5%;
  border-radius: inherit;
  background: var(--gold);
  transition: width 220ms ease;
}
.question-title {
  margin: 0 0 10px;
  font-family: var(--font-sans);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.5;
}
.question-desc {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.75;
  font-size: 16px;
}
.input-field, .textarea-field {
  width: 100%;
  border: 1px solid rgba(232, 190, 115, 0.20);
  border-radius: 8px;
  background: rgba(9, 14, 31, 0.58);
  color: var(--text);
  outline: none;
  padding: 14px 15px;
  font-size: 16px;
}
.input-field:focus, .textarea-field:focus {
  border-color: rgba(232, 190, 115, 0.58);
  box-shadow: 0 0 0 4px rgba(232, 190, 115, 0.10);
}
.textarea-field { min-height: 96px; resize: vertical; line-height: 1.65; }
.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.option-pill {
  min-height: 48px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  padding: 10px 14px;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.option-pill:hover { transform: translateY(-1px); border-color: rgba(232,190,115,0.38); }
.option-pill.is-selected {
  border-color: rgba(232,190,115,0.72);
  background: rgba(232,190,115,0.15);
}
.option-pill.is-stable.is-selected {
  border-color: rgba(142,201,164,0.74);
  background: rgba(142,201,164,0.14);
}
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: 999px;
  color: #151a2e;
  background: var(--gold);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}
.inline-note {
  margin: 14px 0 0;
  color: var(--dim);
  font-size: 14px;
  line-height: 1.65;
}
.panel-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}
.primary-btn, .ghost-btn {
  border-radius: 999px;
  min-height: 44px;
  padding: 10px 18px;
  line-height: 1.5;
  text-align: center;
  border: 1px solid transparent;
  font-weight: 650;
}
.primary-btn {
  color: #151a2e;
  background: var(--gold-strong);
  box-shadow: none;
}
.ghost-btn {
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
}
.ghost-btn[disabled] { opacity: 0.35; cursor: default; }

.map-panel {
  position: relative;
  width: min(1180px, 100%);
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr);
  column-gap: 24px;
  align-items: start;
}
.map-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}
.map-toolbar h2 { font-family: var(--font-sans); font-size: 24px; }
.map-toolbar, .map-hint, .summary-card, .cta-card, .sync-notice { grid-column: 1 / -1; }
.map-toolbar > div, .detail-head h3, .cta-card > div { min-width: 0; overflow-wrap: anywhere; }
.map-toolbar .ghost-btn, .cta-card .primary-btn { flex-shrink: 0; }
.map-hint {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid rgba(139,127,209,0.18);
  border-radius: 16px;
  color: var(--muted);
  line-height: 1.7;
  background: rgba(139,127,209,0.08);
}
.summary-card {
  margin-bottom: 14px;
  color: #efe6cf;
  line-height: 1.75;
  font-size: 16px;
}
.graph-wrap {
  position: relative;
  height: min(58vh, 560px);
  min-height: 420px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(5, 9, 22, 0.25);
}
#starMap { width: 100%; height: 100%; display: block; }
.link-line { stroke: rgba(226, 207, 154, 0.42); stroke-linecap: round; transition: opacity 180ms ease, stroke 180ms ease; }
.node-group { transition: opacity 180ms ease; }
.node-label {
  fill: #fff8e8;
  font-size: 12px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(0,0,0,0.72);
}
.node-ring { fill: none; stroke-width: 1.5; opacity: 0.72; }
.pulse circle.node-core { animation: birthPulse 720ms ease-out; }
@keyframes birthPulse {
  0% { transform: scale(0.72); filter: drop-shadow(0 0 0 rgba(232,190,115,0)); }
  42% { transform: scale(1.18); filter: drop-shadow(0 0 18px rgba(232,190,115,0.58)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(232,190,115,0.24)); }
}
.detail-card {
  position: relative;
  width: 100%;
  max-height: 560px;
  max-height: min(70dvh, 560px);
  min-height: 120px;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  overflow-y: auto;
  padding: 18px;
  border: 1px solid rgba(232, 190, 115, 0.18);
  border-radius: 8px;
  background: rgba(22, 29, 51, 0.92);
  backdrop-filter: blur(16px);
  box-shadow: none;
}
.empty-detail { color: var(--muted); margin: 0; line-height: 1.7; }
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.detail-head h3 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 24px;
  line-height: 1.5;
}
.status-chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  color: #11182b;
  background: var(--gold);
  font-size: 12px;
  font-weight: 700;
}
.status-chip.stable { background: var(--green); }
.detail-section { margin-top: 24px; }
.detail-section + .detail-section { padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.action-list li + li { margin-top: 10px; }
.inline-note + .textarea-field { margin-top: 12px; }
.detail-section h4 {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 16px;
}
.detail-section p, .detail-section li {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.75;
}
.detail-section p { margin: 0; }
.action-list { margin: 0; padding-left: 20px; }
.clue-list { display: grid; gap: 9px; }
.clue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}
.clue-name { color: var(--text); font-weight: 600; }
.clue-row > :last-child { grid-column: 1 / -1; }
.clue-row { overflow-wrap: anywhere; }
.strength-bar {
  position: relative;
  height: 8px;
  margin-top: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}
.strength-bar i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }
.cta-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 24px 0 0;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(232,190,115,0.45);
  border-radius: 8px;
  background: rgba(20, 24, 44, 0.86);
  opacity: 0;
  transform: translateY(12px);
  animation: ctaIn 520ms ease forwards;
}
.cta-card strong, .cta-card span { display: block; }
.cta-card span { color: var(--muted); margin-top: 3px; }
@keyframes ctaIn { to { opacity: 1; transform: translateY(0); } }
.sync-notice { color: var(--muted); font-size: 14px; line-height: 1.7; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 16, 0.72);
  backdrop-filter: blur(10px);
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid rgba(232,190,115,0.28);
  border-radius: 8px;
  background: #171e38;
  text-align: left;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}
.modal-card h2 { font-family: var(--font-sans); font-size: 24px; line-height: 1.5; padding-right: 24px; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  font-size: 24px;
  line-height: 1;
}
.qr-img {
  display: block;
  width: min(260px, 100%);
  margin: 18px auto 12px;
  border-radius: 14px;
  background: #fff;
}
.qr-tip { color: var(--muted); line-height: 1.7; margin: 0; }
.is-hidden { display: none !important; }

@media (max-width: 760px) {
  .brand-bar {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: calc(100% - 32px);
    padding: max(20px, env(safe-area-inset-top)) 0 0;
    flex-direction: column-reverse;
  }
  .studio-brand { align-self: flex-end; min-width: 0; max-width: 230px; }
  .studio-brand strong { font-size: 14px; }
  .app-shell { padding: 24px 16px; }
  .brand-copy h1 { font-size: 24px; }
  .question-title, .map-toolbar h2, .detail-head h3, .modal-card h2 { font-size: 22px; }
  .question-panel, .map-panel { padding: 20px; }
  .map-panel { display: block; }
  .question-panel, .map-panel { border-radius: 8px; }
  .option-grid { grid-template-columns: 1fr; }
  .panel-actions { position: static; }
  .panel-actions > button { flex: 1; }
  .map-toolbar { flex-direction: column; }
  .graph-wrap { min-height: 430px; height: 52vh; }
  .detail-card {
    position: relative;
    top: auto;
    right: auto;
    width: 100%;
    max-height: 52vh;
    margin-top: 14px;
  }
  .clue-row { gap: 8px; }
  .cta-card { flex-direction: column; align-items: stretch; }
}
