:root {
  color-scheme: light;
  --ink: #102039;
  --muted: #69768a;
  --line: #dbe2ea;
  --surface: #ffffff;
  --page: #f4f7fa;
  --navy: #0a2b58;
  --blue: #2563eb;
  --teal: #0f9f94;
  --amber: #d97706;
  --coral: #ef5b5b;
  --purple: #7c4dcc;
  --shadow: 0 14px 40px rgba(27, 42, 68, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% -10%, rgba(37, 99, 235, 0.08), transparent 28rem),
    var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select, input { font: inherit; }
button, select { color: inherit; }

.page-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 38px 0 64px;
}

.demo-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(2rem, 4vw, 3.6rem); letter-spacing: -0.045em; }
h1 span { color: var(--blue); font-weight: 500; }
h2 { margin-bottom: 0; font-size: 1.2rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 0; font-size: 0.92rem; }
.lede { margin-bottom: 0; color: var(--muted); }
.muted { color: var(--muted); }

.environment-switch {
  display: flex;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.8);
  box-shadow: 0 8px 24px rgba(27,42,68,0.05);
}

.env-button, .icon-button {
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.env-button { min-width: 84px; padding: 10px 17px; font-weight: 700; }
.env-button.active { color: white; background: var(--navy); }

.demo-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.72fr);
  gap: 18px;
}

.viewer-card, .memory-card, .timeline-card, .qa-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.viewer-toolbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  font-size: 0.84rem;
}

.viewer-toolbar > div:first-child { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 5px rgba(15,159,148,0.12); }
.viewer-actions { display: flex; gap: 6px; }
.icon-button { padding: 7px 10px; border: 1px solid var(--line); background: white; font-size: 0.76rem; font-weight: 700; }
.icon-button:hover { border-color: var(--blue); color: var(--blue); }
.icon-button.accent { color: white; border-color: var(--blue); background: var(--blue); }

.viewer { position: relative; min-height: 620px; background: #0b1220; }
.viewer canvas { display: block; width: 100%; height: 100%; }

.loader-panel {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  color: white;
  background: #0b1220;
}
.loader-panel small { color: #98a7be; }
.loader-panel.hidden { display: none; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,0.18); border-top-color: #5eead4; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.viewer-hint {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 8px 11px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 9px;
  color: #d7e1ee;
  background: rgba(8,16,30,0.72);
  backdrop-filter: blur(8px);
  font-size: 0.72rem;
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  min-height: 46px;
  align-items: center;
  padding: 0 18px;
  color: var(--muted);
  font-size: 0.74rem;
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.current { background: var(--coral); box-shadow: 0 0 0 4px rgba(239,91,91,0.16); }
.legend-dot.observed { background: var(--teal); }
.legend-dot.ghost { border: 2px dashed #9ca3af; }
.legend-line { width: 22px; height: 2px; background: var(--teal); }
.legend-trajectory {
  display: inline-block;
  width: 28px;
  height: 4px;
  border-radius: 999px;
  background: #ff1645;
  box-shadow: 0 0 0 1px #680018;
}
.legend strong { color: var(--ink); font-size: inherit; }

.memory-card { padding: 22px; }
.card-heading { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.card-heading select { max-width: 46%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 9px; background: white; font-size: 0.78rem; }
.event-badge { display: inline-flex; margin: 20px 0 12px; padding: 6px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 900; letter-spacing: 0.05em; }
.event-badge.appear { color: #167044; background: #dff7e9; }
.event-badge.move { color: #1759b5; background: #e1efff; }
.event-badge.disappear { color: #b93838; background: #ffe6e6; }
.event-badge.reappear { color: #6840a6; background: #eee5ff; }
.event-badge.none { color: #677386; background: #edf1f5; }

.observation-figure {
  position: relative;
  overflow: hidden;
  margin: 2px 0 16px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #0b1220;
}
.observation-figure.hidden { display: none; }
.observation-figure img { width: 100%; height: 100%; display: block; object-fit: cover; }
.observation-figure figcaption {
  position: absolute;
  left: 9px;
  bottom: 9px;
  padding: 5px 8px;
  border-radius: 7px;
  color: white;
  background: rgba(8, 16, 30, 0.76);
  font-size: 0.66rem;
  backdrop-filter: blur(7px);
}

.memory-facts { margin: 0; border-top: 1px solid var(--line); }
.memory-facts div { display: grid; grid-template-columns: 1fr 1.25fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.memory-facts dt { color: var(--muted); font-size: 0.76rem; }
.memory-facts dd { margin: 0; font-size: 0.8rem; font-weight: 750; text-align: right; }

.history-heading { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 0 10px; }
.history-heading span { color: var(--muted); font-size: 0.68rem; }
.history-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.history-list li { display: grid; grid-template-columns: 32px 82px 1fr; gap: 7px; align-items: center; padding: 8px 9px; border-radius: 9px; background: #f6f8fb; font-size: 0.7rem; }
.history-session { font-weight: 850; }
.history-event { color: var(--blue); font-weight: 850; }
.history-position { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.timeline-card, .qa-card { margin-top: 18px; padding: 22px 24px; }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 15px; }
.section-title > strong { color: var(--blue); }
#sessionRange { width: 100%; margin: 25px 0 9px; accent-color: var(--blue); }
.session-ticks { display: grid; grid-template-columns: repeat(10, 1fr); color: var(--muted); font-size: 0.72rem; text-align: center; }
.session-ticks button { justify-self: center; width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; background: white; cursor: pointer; }
.session-ticks button.active { color: white; border-color: var(--navy); background: var(--navy); }
.event-timeline { display: grid; grid-template-columns: repeat(10, 1fr); margin-top: 9px; min-height: 22px; text-align: center; }
.event-timeline span { justify-self: center; padding: 3px 5px; border-radius: 5px; color: var(--muted); background: #f1f4f7; font-size: 0.58rem; font-weight: 800; }

.static-label { padding: 6px 9px; border-radius: 999px; color: var(--muted); background: #f0f3f7; font-size: 0.68rem; }
.question-buttons { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.question-buttons button { padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; background: white; cursor: pointer; font-size: 0.78rem; font-weight: 650; }
.question-buttons button:hover, .question-buttons button.active { color: var(--blue); border-color: var(--blue); background: #f5f8ff; }
.answer-panel { display: flex; gap: 13px; margin-top: 16px; padding: 17px; border: 1px solid #d7e4ff; border-radius: 13px; background: #f8faff; }
.answer-icon { display: grid; flex: 0 0 34px; height: 34px; place-items: center; border-radius: 10px; color: var(--blue); background: #e4edff; }
.answer-panel span { color: var(--blue); font-size: 0.68rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; }
.answer-panel p { margin: 5px 0 0; line-height: 1.55; }

@media (max-width: 980px) {
  .demo-grid { grid-template-columns: 1fr; }
  .viewer { min-height: 540px; }
}

@media (max-width: 620px) {
  .page-shell { width: min(100% - 20px, 1480px); padding-top: 22px; }
  .demo-header { align-items: stretch; flex-direction: column; }
  .environment-switch { align-self: flex-start; }
  .viewer { min-height: 420px; }
  .viewer-toolbar { align-items: flex-start; flex-direction: column; padding-block: 12px; }
  .viewer-actions { width: 100%; }
  .memory-card, .timeline-card, .qa-card { padding: 17px; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .history-list li { grid-template-columns: 30px 72px 1fr; }
  .event-timeline span { font-size: 0; width: 7px; height: 7px; padding: 0; border-radius: 50%; }
}

/* Evidence-backed QA interaction */
.map-evidence-cue {
  position: absolute;
  z-index: 4;
  left: 14px;
  bottom: 14px;
  max-width: min(520px, calc(100% - 210px));
  padding: 9px 12px;
  border: 1px solid rgba(251, 191, 36, 0.7);
  border-radius: 9px;
  color: #fff7d6;
  background: rgba(68, 42, 4, 0.86);
  backdrop-filter: blur(8px);
  font-size: 0.72rem;
  font-weight: 750;
  pointer-events: none;
}
.map-evidence-cue.hidden { display: none; }

.qa-workspace { display: grid; grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1.7fr); gap: 18px; margin-top: 18px; }
.question-column { padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: #f8fafc; }
.qa-column-label { color: var(--muted); font-size: 0.68rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.question-buttons { display: grid; gap: 8px; margin-top: 10px; }
.question-buttons button { width: 100%; padding: 11px 12px; text-align: left; }
.question-buttons button::before { content: "→"; display: inline-block; width: 20px; color: var(--blue); }
.question-buttons button.active { box-shadow: inset 3px 0 0 var(--blue); }

.answer-panel { min-height: 250px; margin-top: 0; }
.answer-content { min-width: 0; flex: 1; }
.answer-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.answer-status { padding: 4px 7px; border-radius: 999px; color: #35616d !important; background: #e4f6f4; font-size: 0.61rem !important; letter-spacing: 0.04em !important; }
.answer-status.searching { color: #8a5b04 !important; background: #fff1cb; }
.answer-panel p { min-height: 48px; }
.evidence-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 15px 0 8px; padding-top: 12px; border-top: 1px solid #d7e4ff; }
.evidence-heading strong { font-size: 0.74rem; }
.evidence-heading small { color: var(--muted); font-size: 0.62rem; }
.answer-evidence { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 180px)); justify-content: start; gap: 9px; }
.evidence-card { overflow: hidden; padding: 0; border: 1px solid #d8e0ea; border-radius: 10px; background: white; cursor: pointer; text-align: left; transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease; }
.evidence-card:hover, .evidence-card.active { transform: translateY(-2px); border-color: var(--blue); box-shadow: 0 7px 16px rgba(37,99,235,0.13); }
.evidence-card img { width: 100%; height: 76px; display: block; object-fit: cover; background: #101827; }
.evidence-card .evidence-placeholder { height: 76px; display: grid; place-items: center; color: #9babbe; background: #101827; font-size: 0.65rem; }
.evidence-card-body { display: grid; gap: 3px; padding: 8px; }
.evidence-card-body strong { overflow: hidden; font-size: 0.69rem; text-overflow: ellipsis; white-space: nowrap; }
.evidence-card-body span { color: var(--muted); font-size: 0.6rem; }

.session-ticks button.evidence { border-color: #f2b62d; box-shadow: 0 0 0 4px rgba(242,182,45,0.18); }
.session-ticks button.active.evidence { border-color: #f6cf69; box-shadow: 0 0 0 4px rgba(242,182,45,0.26); }
.event-timeline span.evidence { outline: 2px solid #f2b62d; outline-offset: 2px; background: #fff7df; }

@media (max-width: 760px) {
  .qa-workspace { grid-template-columns: 1fr; }
  .map-evidence-cue { max-width: calc(100% - 28px); bottom: 52px; }
}
.evidence-loading { display: flex; align-items: center; gap: 9px; min-height: 96px; color: var(--muted); font-size: 0.7rem; }
.evidence-loading .spinner { width: 19px; height: 19px; border-color: rgba(37,99,235,0.18); border-top-color: var(--blue); }
.evidence-role { color: #9a6700; font-size: 0.57rem; font-style: normal; font-weight: 900; letter-spacing: 0.05em; text-transform: uppercase; }
.answer-text { margin-top: 7px; min-height: 48px; line-height: 1.5; }
.answer-result-title { display: block; color: var(--ink); font-size: 1rem; letter-spacing: -0.01em; }
.answer-result-subtitle { display: block; margin-top: 2px; color: var(--muted); font-size: 0.68rem; }
.answer-change-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 7px; margin-top: 12px; }
.answer-change-item { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 8px 9px; border: 1px solid #dfe6ef; border-radius: 8px; background: white; }
.answer-change-item > strong { overflow: hidden; font-size: 0.7rem; text-overflow: ellipsis; white-space: nowrap; }
.answer-event-pill { flex: 0 0 auto; padding: 3px 6px; border-radius: 999px; font-size: 0.55rem; font-weight: 900; }
.answer-event-pill.appear { color: #167044; background: #dff7e9; }
.answer-event-pill.move { color: #1759b5; background: #e1efff; }
.answer-event-pill.disappear { color: #b93838; background: #ffe6e6; }
.answer-event-pill.reappear { color: #6840a6; background: #eee5ff; }
