:root {
  --bg: #070b14;
  --bg-elev: rgba(15, 23, 42, 0.78);
  --bg-card: rgba(17, 26, 46, 0.84);
  --border: rgba(148, 163, 184, 0.16);
  --border-glow: rgba(52, 211, 153, 0.35);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --emerald: #34d399;
  --cyan: #38bdf8;
  --rose: #fb7185;
  --amber: #fbbf24;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.lab-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.13), transparent 45%),
    radial-gradient(circle at 85% 25%, rgba(52, 211, 153, 0.12), transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(251, 113, 133, 0.08), transparent 45%),
    linear-gradient(to right, rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.04) 1px, transparent 1px);
  background-size: auto, auto, auto, 28px 28px, 28px 28px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--emerald);
  background: rgba(52, 211, 153, 0.1);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ---------------- Lock Screen ---------------- */
.lock-screen {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.lock-shell {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.signal-pill {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 0.04em;
}

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
  animation: pulseDot 1.8s infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}

.handshake-canvas-wrap {
  position: relative;
  height: 196px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, rgba(15, 23, 42, 0.9), rgba(7, 11, 20, 0.95));
  overflow: hidden;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
}

#handshake-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-hud {
  position: absolute;
  inset: auto 12px 12px 12px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hud-node {
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(8px);
}

.hud-city {
  font-size: 12px;
  font-weight: 600;
}

.hud-left .hud-city { color: var(--cyan); }
.hud-right .hud-city { color: var(--emerald); }

.hud-node small,
.hud-distance small {
  font-size: 10px;
  color: var(--muted);
}

.hud-distance {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-distance span {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.28);
  padding: 2px 8px;
  border-radius: 999px;
}

.lock-card {
  border-radius: 22px;
  padding: 22px 18px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.lock-title {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0.02em;
}

.lock-title span {
  background: linear-gradient(120deg, var(--cyan), var(--emerald));
  -webkit-background-clip: text;
  color: transparent;
}

.lock-epigraph {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.prompt-label {
  display: block;
  font-size: 12px;
  color: var(--cyan);
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="password"],
input[type="url"] {
  width: 100%;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.85);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.16);
}

.btn-primary {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #041219;
  background: linear-gradient(135deg, var(--emerald), var(--cyan));
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s, opacity 0.2s;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary.small {
  padding: 10px 14px;
  font-size: 13px;
}

.btn-ghost {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.lock-error {
  margin: 8px 0 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--rose);
}

.demo-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
  background: rgba(56, 189, 248, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.28);
  padding: 7px 10px;
  border-radius: 10px;
}

/* ---------------- Main App Shell ---------------- */
.app-shell {
  position: relative;
  z-index: 2;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 12px 14px calc(86px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin: 0 -4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(9, 14, 27, 0.86);
  backdrop-filter: blur(14px);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 15px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(52, 211, 153, 0.22));
  border: 1px solid var(--border-glow);
  flex-shrink: 0;
}

.brand-title {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.brand-sub {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--emerald);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.pulse-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid rgba(251, 113, 133, 0.45);
  background: rgba(251, 113, 133, 0.14);
  color: #fecdd3;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pulse-btn b {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #fff;
  background: rgba(251, 113, 133, 0.35);
  padding: 1px 6px;
  border-radius: 999px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rose);
  box-shadow: 0 0 8px var(--rose);
}

.demo-banner {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px dashed rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
  color: #fde68a;
  font-size: 11px;
}

.telemetry-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tele-item {
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  text-align: center;
}

.tele-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.tele-value {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--cyan);
}

/* ---------------- Views & Cards ---------------- */
.view {
  display: none;
  flex-direction: column;
  gap: 12px;
  animation: fadeUp 0.25s ease;
}

.view.active {
  display: flex;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  border-radius: 18px;
  padding: 15px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  backdrop-filter: blur(14px);
}

.hero-quote-card {
  background: linear-gradient(145deg, rgba(17, 29, 52, 0.92), rgba(14, 23, 42, 0.85));
  border-color: rgba(56, 189, 248, 0.24);
}

.card-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--cyan);
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.hero-quote {
  margin: 4px 0 0;
  font-size: 14px;
  color: #f1f5f9;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.card-title {
  margin: 0;
  font-size: 16px;
}

.card-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.badge-emerald,
.badge-cyan {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-emerald {
  color: var(--emerald);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.28);
}

.badge-cyan {
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric-box {
  padding: 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}

.metric-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.metric-num {
  display: block;
  margin: 4px 0 2px;
  font-family: var(--font-mono);
  font-size: 21px;
  background: linear-gradient(120deg, #fff, var(--emerald));
  -webkit-background-clip: text;
  color: transparent;
}

.metric-box small {
  font-size: 11px;
  color: var(--muted);
}

.paradox-card {
  border-color: rgba(52, 211, 153, 0.24);
  background: linear-gradient(155deg, rgba(16, 30, 50, 0.9), rgba(11, 18, 33, 0.88));
}

.paradox-insight {
  margin: 2px 0 10px;
  font-size: 13px;
  color: #dbeafe;
}

.paradox-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.paradox-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(7, 11, 20, 0.65);
  color: var(--muted);
}

.paradox-pill.peak {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}

.paradox-pill.quiet {
  color: var(--emerald);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.1);
}

.chart-wrap {
  position: relative;
  height: 175px;
  border-radius: 14px;
  background: rgba(7, 11, 20, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.12);
  overflow: hidden;
}

.chart-wrap.short {
  height: 145px;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.milestone-box {
  margin-top: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.22);
  font-size: 12.5px;
}

.milestone-box strong {
  color: var(--emerald);
}

.milestone-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--cyan);
  margin-bottom: 4px;
}

/* ---------------- Token Cloud & Bubbles ---------------- */
.token-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.token-chip {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s;
}

.token-chip small {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

.token-chip.active {
  border-color: var(--emerald);
  background: rgba(52, 211, 153, 0.18);
  color: #fff;
}

.quote-panel {
  border-radius: 14px;
  padding: 12px;
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.14);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quote-panel-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.bubble-row {
  display: flex;
}

.bubble-row.him { justify-content: flex-end; }
.bubble-row.her { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.45;
}

.bubble-row.him .bubble {
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-bottom-right-radius: 4px;
}

.bubble-row.her .bubble {
  background: rgba(52, 211, 153, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-bottom-left-radius: 4px;
}

.legend-inline {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}

.lg-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.lg-dot.him { background: var(--cyan); }
.lg-dot.her { background: var(--emerald); }

/* ---------------- Memories & Map ---------------- */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip-btn {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.75);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.chip-btn.active {
  color: var(--emerald);
  border-color: var(--emerald);
  background: rgba(52, 211, 153, 0.12);
}

.memory-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.memory-card {
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  overflow: hidden;
}

.memory-media {
  position: relative;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(20, 35, 62, 0.9));
  min-height: 170px;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--border);
}

.memory-media img,
.memory-media video {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  object-position: center 24%;
  display: block;
}

.media-placeholder {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

.media-placeholder span {
  display: block;
  font-size: 26px;
  margin-bottom: 6px;
}

.media-tag {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(7, 11, 20, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.25);
  backdrop-filter: blur(6px);
}

.video-switch-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(52, 211, 153, 0.45);
  background: rgba(7, 11, 20, 0.82);
  color: var(--emerald);
  font-size: 11px;
  cursor: pointer;
}

.memory-body {
  padding: 14px;
}

.memory-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.memory-head h3 {
  margin: 0;
  font-size: 15px;
}

.memory-head time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.dual-perspective {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cv-box,
.gt-box {
  padding: 9px 11px;
  border-radius: 12px;
  font-size: 12.5px;
}

.cv-box {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.22);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #bae6fd;
}

.gt-box {
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.24);
  color: #ecfdf5;
}

.gt-box strong,
.cv-box strong {
  display: block;
  font-size: 10.5px;
  margin-bottom: 3px;
  opacity: 0.85;
}

.memory-quote {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------------- Mini RAG AI Chat ---------------- */
.ai-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.ai-mode-desc {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.chat-messages {
  min-height: 210px;
  max-height: 36dvh;
  overflow-y: auto;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.72);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-msg {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 15px;
  font-size: 13.5px;
  line-height: 1.5;
}

.ai-msg.user {
  align-self: flex-end;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-bottom-right-radius: 4px;
}

.ai-msg.bot {
  align-self: flex-start;
  background: rgba(17, 26, 46, 0.95);
  border: 1px solid rgba(52, 211, 153, 0.28);
  border-bottom-left-radius: 4px;
}

.rag-sources {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px dashed rgba(148, 163, 184, 0.2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--emerald);
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-chip {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  color: var(--cyan);
  font-size: 11.5px;
  cursor: pointer;
}

.rag-form {
  display: flex;
  gap: 8px;
}

/* ---------------- Bottom Nav ---------------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 456px;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(9, 14, 27, 0.92);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 6px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
}

.nav-btn.active {
  background: rgba(52, 211, 153, 0.14);
  color: var(--emerald);
  font-weight: 600;
}

.nav-ico {
  font-size: 16px;
}

/* ---------------- Dialog & Toast ---------------- */
.lab-dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #0d1526;
  color: var(--text);
  padding: 16px;
}

.lab-dialog::backdrop {
  background: rgba(2, 6, 15, 0.72);
  backdrop-filter: blur(5px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.dialog-head h3 {
  margin: 0;
  font-size: 16px;
}

.dialog-tip {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%) translateY(-10px);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-glow);
  color: var(--text);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
