:root {
  --bg-primary: #000000; /* pure black = transparent on additive display, lets real world show through */
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --gold: #ffd166;
  --silver: #b8c4d0;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --warning: #ffaa00;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app { width: 100%; height: 100%; position: relative; }

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px; /* safe margin for additive display */
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 { font-size: 20px; font-weight: 600; flex: 1; }
.header-meta { font-size: 13px; color: var(--text-secondary); }
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}
.xp-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(255, 209, 102, 0.12);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

/* --- Compass strip --- */
.compass-strip {
  position: relative;
  height: 52px;
  margin-top: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
}
.compass-ticks { position: absolute; inset: 0; }
.compass-tick {
  position: absolute;
  top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  transform: translateX(-50%);
}
.compass-tick.cardinal { color: var(--text-secondary); font-weight: 700; font-size: 13px; }
.compass-poi {
  position: absolute;
  bottom: 4px;
  font-size: 16px;
  transform: translateX(-50%);
  transition: left 0.2s linear;
}
.compass-poi.discovered { opacity: 0.45; }
.compass-center-mark {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent-primary);
  opacity: 0.7;
}
.compass-heading {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-primary);
}

/* --- Guide character bar --- */
.guide-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin-top: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.guide-face { font-size: 26px; flex-shrink: 0; }
.guide-line {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* --- Gaze capture target --- */
.gaze-target {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 8px;
  padding: 10px 16px;
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.35);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.gaze-ring {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.gaze-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: var(--accent-primary);
  transition: height 0.1s linear;
}
.gaze-info { min-width: 0; }
.gaze-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gaze-meta { font-size: 13px; color: var(--accent-primary); }

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 12px 4px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}
.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

/* --- Focus States (critical for EMG/D-pad) --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 10px 4px;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary { background: var(--accent-primary); color: #0a0a0f; }
.nav-item.primary:focus { background: #33ddff; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 2px solid transparent;
}
.card-subtitle { font-size: 14px; color: var(--text-secondary); }
.agent-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* --- List Items --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 12px;
  flex-shrink: 0;
}
.list-item:focus { background: var(--bg-card); }
.list-item-icon { font-size: 22px; flex-shrink: 0; width: 32px; text-align: center; }
.list-item-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-meta { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.list-item-badge { font-size: 16px; flex-shrink: 0; }

/* in-front highlight on the ahead list */
.list-item.in-front {
  background: rgba(0, 212, 255, 0.1);
  border-color: rgba(0, 212, 255, 0.3);
}

/* --- Start overlay --- */
.start-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 8, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: var(--radius-lg);
}
.start-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
  max-width: 420px;
  padding: 28px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
}
.start-icon { font-size: 52px; }
.start-card h2 { font-size: 24px; }
.start-card p { font-size: 15px; color: var(--text-secondary); }
.start-card .nav-item { width: 100%; }

/* --- Guide speech (detail / trivia) --- */
.guide-speech {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 16px;
}
.guide-speech .guide-face { font-size: 32px; }
.speech-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.speech-lines p { font-size: 16px; line-height: 1.45; }
.detail-meta { font-size: 14px; color: var(--text-secondary); }
.stamp-badge { font-size: 20px; }

/* --- Trivia --- */
.trivia-question { font-weight: 600; }
.trivia-option { width: 100%; }
.trivia-option.correct {
  background: rgba(0, 255, 136, 0.18);
  border-color: var(--success);
}
.trivia-option.wrong {
  background: rgba(255, 68, 102, 0.18);
  border-color: var(--danger);
}
.trivia-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
}
.trivia-verdict { font-size: 20px; font-weight: 700; }
.trivia-verdict.gold { color: var(--gold); }
.trivia-verdict.silver { color: var(--silver); }
.trivia-fact { font-size: 14px; color: var(--text-secondary); line-height: 1.45; }

/* --- Passport --- */
.passport-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.stat-tile {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent-primary); }
.stat-value.gold { color: var(--gold); }
.stat-value.silver { color: var(--silver); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.stamp-grid { gap: 8px; }
.stamp-item .list-item-badge.gold { filter: none; }
.stamp-tier-gold { color: var(--gold); }
.stamp-tier-silver { color: var(--silver); }

/* --- Persona picker --- */
.persona-item.active {
  background: rgba(0, 212, 255, 0.1);
  border-color: rgba(0, 212, 255, 0.4);
}

/* --- Loading / skeleton --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-card) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-line { height: 16px; border-radius: 4px; }
.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }

/* --- Error States --- */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.error-message { font-size: 15px; color: var(--text-secondary); max-width: 400px; }

/* --- Toast --- */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  max-width: 536px;
  border: 1px solid var(--accent-primary);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
.toast.gold { border-color: var(--gold); }

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* --- Utility --- */
.hidden { display: none !important; }
