/* ============================
   AP World History Modern
   Interactive Learning Site
   ============================ */

:root {
  --bg:            #0f1117;
  --bg-surface:    #1a1d27;
  --bg-elevated:   #242836;
  --text:          #e8eaf0;
  --text-muted:    #8b90a0;
  --text-dim:      #565b6e;
  --accent:        #6c63ff;
  --accent-light:  #8b85ff;
  --accent-glow:   rgba(108, 99, 255, 0.25);
  --gold:          #f0b429;
  --red:           #e74c6f;
  --green:         #34d399;
  --blue:          #3b82f6;
  --orange:        #f59e0b;
  --cyan:          #22d3ee;
  --sidebar-w:     280px;
  --topbar-h:      60px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 24px rgba(0,0,0,.35);
  --transition:    .25s cubic-bezier(.4,0,.2,1);
}

[data-theme="light"] {
  --bg:            #f0f2f8;
  --bg-surface:    #ffffff;
  --bg-elevated:   #e4e6f0;
  --text:          #12112b;
  --text-muted:    #55577a;
  --text-dim:      #9899b8;
  --accent:        #5b4fcf;
  --accent-light:  #7c72e8;
  --accent-glow:   rgba(91, 79, 207, 0.13);
  --shadow:        0 4px 24px rgba(0,0,0,.10);
}

/* Light mode explicit overrides for elements with hardcoded dark colours */
[data-theme="light"] body                  { background: var(--bg); }
[data-theme="light"] #sidebar              { background: var(--bg-surface); border-right-color: var(--bg-elevated); }
[data-theme="light"] #topBar               { background: var(--bg-surface); border-bottom-color: var(--bg-elevated); }
[data-theme="light"] .map-legend           { background: var(--bg-surface); border-color: var(--bg-elevated); }
[data-theme="light"] .map-info-panel       { background: var(--bg-surface); border-color: var(--bg-elevated); }
[data-theme="light"] .timeline-container   { background: var(--bg-surface); }
[data-theme="light"] .study-container      { background: var(--bg-surface); }
[data-theme="light"] .flashcard            { background: var(--bg-surface); border-color: var(--bg-elevated); }
[data-theme="light"] .flashcard-front,
[data-theme="light"] .flashcard-back       { background: var(--bg-surface); color: var(--text); }
[data-theme="light"] .era-chip             { background: var(--bg-elevated); color: var(--text-muted); border-color: var(--bg-elevated); }
[data-theme="light"] .era-chip.active      { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="light"] .tl-event            { background: var(--bg-elevated); border-left-color: var(--accent); }
[data-theme="light"] .tl-year             { color: var(--accent); }
[data-theme="light"] .tl-desc             { color: var(--text-muted); }
[data-theme="light"] .view-btn            { color: var(--text-muted); }
[data-theme="light"] .view-btn:hover      { background: var(--bg-elevated); color: var(--text); }
[data-theme="light"] .view-btn.active     { color: var(--accent); background: var(--accent-glow); border-color: var(--accent); }
[data-theme="light"] .unit-item:hover     { background: var(--bg-elevated); }
[data-theme="light"] .unit-item.active    { background: var(--accent-glow); }
[data-theme="light"] .unit-num            { background: var(--bg-elevated); }
[data-theme="light"] .welcome-overlay     { background: rgba(240,242,248,0.97); }
[data-theme="light"] .sim-bar             { background: var(--bg-surface); border-top-color: var(--bg-elevated); }
[data-theme="light"] .sim-slider          { accent-color: var(--accent); }
[data-theme="light"] .territory-label    { background: rgba(255,255,255,0.92) !important; color: #12112b !important; border: 1px solid rgba(0,0,0,0.12) !important; }
[data-theme="light"] .leaflet-popup-content-wrapper { background: #fff; color: #12112b; }
[data-theme="light"] .leaflet-popup-tip  { background: #fff; }
[data-theme="light"] .custom-marker      { box-shadow: 0 2px 8px rgba(0,0,0,0.18); }

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 3px; }

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-elevated);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition), background var(--transition);
}
#sidebar.collapsed { transform: translateX(calc(var(--sidebar-w) * -1)); min-width: 0; width: 0; }

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--bg-elevated);
}
.logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent); }
.tagline { font-size: .75rem; color: var(--text-muted); margin-top: 4px; letter-spacing: 1px; text-transform: uppercase; }

.unit-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}
.unit-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}
.unit-item:hover { background: var(--bg-elevated); }
.unit-item.active { background: var(--accent-glow); }
.unit-item.active .unit-num { background: var(--accent); color: #fff; }
.unit-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.unit-name {
  font-size: .82rem;
  font-weight: 500;
  line-height: 1.3;
}
.unit-period {
  font-size: .68rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--bg-elevated);
  display: flex; justify-content: center;
}

/* ===== BUTTONS ===== */
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 8px; border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { color: var(--text); background: var(--bg-elevated); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 32px;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }

.btn-study {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--text-dim);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.btn-study:hover { background: var(--accent-glow); border-color: var(--accent); }

.btn-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--text-muted);
  font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.btn-close:hover { color: var(--text); }

/* ===== MAIN ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin var(--transition);
}

/* ===== TOP BAR ===== */
#topBar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-elevated);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 50;
}
.top-bar-title { flex: 1; }
.top-bar-title h2 { font-size: 1.05rem; font-weight: 700; }
.period-badge {
  display: inline-block;
  font-size: .7rem;
  color: var(--accent-light);
  font-weight: 600;
  letter-spacing: .5px;
}

.view-toggles { display: flex; gap: 4px; }
.view-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: .8rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.view-btn:hover { color: var(--text); background: var(--bg-elevated); }
.view-btn.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-color: var(--accent);
}

/* ===== VIEW PANELS ===== */
.view-panel {
  display: none;
  flex: 1;
  overflow: hidden;
  position: relative;
}
.view-panel.active { display: flex; }

/* ===== MAP ===== */
#map {
  flex: 1;
  z-index: 1;
  position: relative;
}

/* Match Voyager ocean exactly so the noWrap edge is invisible:
   Light Voyager ocean ≈ #a8cfe2
   Dark  Voyager ocean = #a8cfe2 × brightness(0.46) ≈ #4d5f68            */
#map,
.leaflet-container {
  background: #a8cfe2 !important;
}
#map[data-map-theme="dark"],
#map[data-map-theme="dark"] .leaflet-container {
  background: #4d5f68 !important;
}

/* Dim only the raster tile layer in dark mode so vectors stay vivid */
#map[data-map-theme="dark"] .leaflet-tile-pane {
  filter: brightness(0.46) contrast(1.12) saturate(0.9);
}


.map-legend {
  position: absolute;
  bottom: 24px; left: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-elevated);
  border-radius: var(--radius);
  padding: 14px 18px;
  z-index: 1000;
  box-shadow: var(--shadow);
  max-width: 260px;
  max-height: 320px;
  overflow-y: auto;
}
.map-legend h4 {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: .8rem;
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 4px;
  transition: background var(--transition);
}
.legend-item:hover { background: var(--bg-elevated); }
.legend-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.map-info-panel {
  position: absolute;
  top: 16px; right: 16px;
  width: 340px;
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--bg-elevated);
  border-radius: var(--radius);
  padding: 20px;
  z-index: 1000;
  box-shadow: var(--shadow);
  animation: slideIn .3s ease;
}
.map-info-panel.hidden { display: none; }
.map-info-panel h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; padding-right: 28px; }
.map-info-panel p { font-size: .85rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 12px; }
#mapInfoDetails { font-size: .82rem; line-height: 1.65; }
#mapInfoDetails strong { color: var(--accent-light); }
#mapInfoDetails ul { padding-left: 18px; margin: 6px 0; }
#mapInfoDetails li { margin-bottom: 4px; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== TIMELINE ===== */
.timeline-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 60px;
  position: relative;
}
.timeline-era-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 32px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 8px 0 16px;
}
.era-chip {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--bg-elevated);
  background: var(--bg-surface);
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
}
.era-chip.active, .era-chip:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.timeline-track {
  position: relative;
  padding-left: 40px;
}
.timeline-track::before {
  content: '';
  position: absolute;
  left: 18px; top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--accent), var(--accent-light), var(--gold));
  border-radius: 1px;
}

.tl-event {
  position: relative;
  margin-bottom: 28px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-elevated);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  animation: fadeUp .4s ease both;
}
.tl-event:hover { border-color: var(--accent); transform: translateX(4px); }
.tl-event::before {
  content: '';
  position: absolute;
  left: -30px; top: 22px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}
.tl-year {
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.tl-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.tl-desc {
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.55;
}
.tl-tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tl-tag {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .68rem;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.tl-tag.war { background: rgba(231,76,111,.15); color: var(--red); }
.tl-tag.trade { background: rgba(240,180,41,.15); color: var(--gold); }
.tl-tag.expansion { background: rgba(59,130,246,.15); color: var(--blue); }
.tl-tag.culture { background: rgba(34,211,238,.15); color: var(--cyan); }
.tl-tag.revolution { background: rgba(245,158,11,.15); color: var(--orange); }
.tl-tag.empire { background: rgba(108,99,255,.15); color: var(--accent-light); }

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

/* ===== STUDY / FLASHCARDS ===== */
.study-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  overflow-y: auto;
}
.study-header {
  width: 100%;
  max-width: 600px;
  margin-bottom: 24px;
}
.study-header h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 10px; }
.study-progress { font-size: .8rem; color: var(--text-muted); }
.progress-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 2px;
  transition: width .4s ease;
  width: 0;
}

.flashcard-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}
.flashcard {
  width: 100%;
  max-width: 560px;
  height: 320px;
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: 12px;
}
.flashcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform .6s cubic-bezier(.4,0,.2,1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  line-height: 1.6;
}
.flashcard-front {
  background: linear-gradient(135deg, var(--accent), #4338ca);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 600;
}
.flashcard-back {
  background: var(--bg-surface);
  border: 2px solid var(--accent);
  color: var(--text);
  font-size: .95rem;
  transform: rotateY(180deg);
}
.flashcard-hint { font-size: .75rem; color: var(--text-dim); margin-bottom: 16px; }

.study-nav { display: flex; gap: 12px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  animation: fadeIn .3s ease;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--bg-elevated);
  border-radius: 16px;
  padding: 40px;
  max-width: 620px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.modal h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 12px;
}
.modal p { color: var(--text-muted); line-height: 1.6; margin-bottom: 28px; font-size: .92rem; }

.welcome-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}
.feature {
  padding: 20px 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.feature svg { color: var(--accent); margin-bottom: 10px; }
.feature h4 { font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.feature p { font-size: .75rem; margin-bottom: 0; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ===== CUSTOM MAP MARKERS ===== */
.custom-marker {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: .7rem; font-weight: 700; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  border: 2px solid rgba(255,255,255,.3);
  transition: transform .2s;
}
.custom-marker:hover { transform: scale(1.3); }

.trade-route-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-size: .7rem;
  font-weight: 600;
  color: var(--gold);
  white-space: nowrap;
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  background: var(--bg-surface) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--bg-elevated) !important;
}
.leaflet-popup-tip { background: var(--bg-surface) !important; }
.leaflet-popup-content { font-size: .85rem; line-height: 1.5; }
.leaflet-popup-content strong { color: var(--accent-light); }

/* ===== ANIMATED TRADE ROUTES ===== */
.animated-route {
  animation: flowDash 1.5s linear infinite;
}
@keyframes flowDash {
  to { stroke-dashoffset: -28; }
}

/* ===== TERRITORY LABELS ===== */
.territory-label {
  background: rgba(0,0,0,0.55) !important;
  border: none !important;
  color: #fff !important;
  font-size: .72rem !important;
  font-weight: 600 !important;
  padding: 2px 8px !important;
  border-radius: 4px !important;
  box-shadow: none !important;
  white-space: nowrap !important;
  letter-spacing: 0.3px;
  pointer-events: none;
}
.territory-label::before { display: none !important; }
[data-theme="light"] .territory-label {
  background: rgba(255,255,255,0.75) !important;
  color: #1a1d27 !important;
}

/* ===== SIMULATION PLAYBACK BAR ===== */
.sim-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: var(--bg-surface);
  border: 1px solid var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  min-width: 420px;
  max-width: 90vw;
  flex-wrap: wrap;
}
.sim-bar.hidden { display: none; }

.sim-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .15s, box-shadow .2s;
}
.sim-play-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.sim-slider {
  flex: 1;
  min-width: 120px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
.sim-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}

.sim-year {
  font-size: .85rem;
  font-weight: 700;
  color: var(--accent-light);
  min-width: 50px;
  text-align: center;
  white-space: nowrap;
}

.sim-speed-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--text-dim);
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.sim-speed-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.sim-event {
  width: 100%;
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: -4px;
}

/* Simulation polygon transition */
.sim-polygon {
  transition: fill-opacity 0.5s ease, stroke-opacity 0.5s ease;
}
.sim-label {
  font-size: .68rem !important;
}

/* ===== GLOBAL LIVING HISTORY TIMELINE BAR ===== */
.global-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  background: var(--bg-surface);
  border-top: 1px solid var(--bg-elevated);
  box-shadow: 0 -4px 20px rgba(0,0,0,.25);
  padding: 10px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.global-bar.hidden { display: none; }

.gb-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gb-btn {
  height: 34px;
  min-width: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--text-dim);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
  flex-shrink: 0;
  transition: all var(--transition);
}
.gb-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-light);
}
/* Play button is a circle */
#globalPlayBtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 1rem;
  padding: 0;
}
#globalPlayBtn:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
  transform: scale(1.08);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.gb-compare.active {
  background: rgba(231, 76, 111, 0.15);
  border-color: var(--red);
  color: var(--red);
}

.gb-year-wrap {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
}
.gb-year {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-light);
  min-width: 52px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  font-family: 'Playfair Display', serif;
}
.gb-ce {
  font-size: .7rem;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: .04em;
}

.gb-slider-wrap {
  flex: 1;
  position: relative;
  padding-bottom: 20px;
}

.gb-slider {
  width: 100%;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, var(--accent) 0%, var(--bg-elevated) 0%);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}
.gb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-surface);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(108,99,255,.4);
  transition: transform .1s;
}
.gb-slider::-webkit-slider-thumb:active { transform: scale(1.25); }
.gb-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-surface);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--accent);
}

/* Snap tick labels under the slider */
.gb-ticks {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 18px;
  pointer-events: none;
}
.gb-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: .62rem;
  color: var(--text-dim);
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: .02em;
}
/* Accent the major periodization ticks */
.gb-ticks span:nth-child(2),
.gb-ticks span:nth-child(3) {
  color: var(--accent-light);
}

.gb-event {
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

/* ===== MAP SPLIT VIEWPORT ===== */
#mapViewport {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
}

.map-pane {
  flex: 1;
  position: relative;
  min-width: 0;
  transition: flex .38s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.map-pane.hidden {
  flex: 0 0 0px;
}

#map, #map-compare {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-pane-divider {
  width: 4px;
  flex-shrink: 0;
  background: linear-gradient(to bottom,
    transparent 0%, var(--accent) 30%, var(--accent) 70%, transparent 100%);
  z-index: 1000;
  opacity: .7;
  cursor: col-resize;
}
.map-pane-divider.hidden { display: none; }

.map-pane-label {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1002;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: .68rem;
  font-weight: 700;
  color: var(--accent-light);
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: .04em;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.map-pane-label.hidden { display: none; }

/* ===== INLINE CONTEXT ROW (inside global bar) ===== */
.gb-context-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px 2px;
  border-top: 1px solid var(--bg-elevated);
  overflow: hidden;
}
.gb-context-row.hidden { display: none; }

.gb-ctx-year {
  font-size: .8rem;
  font-weight: 800;
  color: var(--accent-light);
  font-family: 'Playfair Display', serif;
  white-space: nowrap;
  flex-shrink: 0;
}

.gb-ctx-items {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.gb-ctx-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
  padding: 0 10px;
}
.gb-ctx-item:first-child { padding-left: 0; }

.gb-ctx-sep {
  width: 1px;
  background: var(--bg-elevated);
  flex-shrink: 0;
  align-self: stretch;
}

.gb-ctx-label {
  font-size: .56rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
  line-height: 1.2;
}
.gb-ctx-value {
  font-size: .7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

/* ===== SPICE-T LEGEND BADGES ===== */
.spice-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  font-size: .6rem;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: 0;
}
.spice-p { background: rgba(108,99,255,.22); color: #8b85ff; }
.spice-i { background: rgba(245,158,11,.22); color: #f59e0b; }
.spice-t { background: rgba(52,211,153,.22); color: #34d399; }

.legend-year-range {
  font-size: .6rem;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

/* Light mode overrides for new components */
[data-theme="light"] .global-bar {
  background: var(--bg-surface);
  border-top-color: var(--bg-elevated);
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}
[data-theme="light"] .gb-slider { accent-color: var(--accent); }
[data-theme="light"] .gb-year  { color: var(--accent); }
[data-theme="light"] .gb-ctx-year { color: var(--accent); }
[data-theme="light"] .gb-context-row { border-top-color: var(--bg-elevated); }
[data-theme="light"] .map-pane-label {
  background: var(--bg-surface);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] #map[data-map-theme="light"] { filter: none; }
[data-theme="light"] #map-compare { filter: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  #sidebar { position: fixed; left: 0; top: 0; }
  #sidebar:not(.collapsed) ~ #main { margin-left: var(--sidebar-w); }
  .welcome-features { grid-template-columns: 1fr; }
  .map-info-panel { width: 280px; }
}
@media (max-width: 600px) {
  :root { --sidebar-w: 240px; }
  .view-btn span { display: none; }
  .map-info-panel { width: calc(100% - 32px); top: 8px; right: 8px; }
  .flashcard { height: 260px; }
  .modal { padding: 24px; }
  .modal h2 { font-size: 1.4rem; }
}
