/* ===== CSS Variables / Theme ===== */
:root {
  --bg-primary: #0F0F1A;
  --bg-secondary: #1A1A2E;
  --bg-card: #22223A;
  --text-primary: #EAEAEA;
  --text-secondary: #A0A0B0;
  --accent: #F72585;
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  --radius: 8px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ===== Header ===== */
#site-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  background: linear-gradient(135deg, #1A1A2E 0%, #16213E 100%);
  border-bottom: 2px solid rgba(247, 37, 133, 0.3);
}

#site-header h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 4vw, 3rem);
  background: linear-gradient(90deg, #F72585, #7209B7, #3A0CA3, #4361EE, #4CC9F0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#site-header .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

/* ===== Sections ===== */
section {
  position: relative;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.5rem 0.5rem;
  background: var(--bg-secondary);
}

.section-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.zoom-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== Timeline Section ===== */
#timeline-section {
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

#timeline-container {
  width: 100%;
  height: 50vh;
  min-height: 320px;
  cursor: grab;
  overflow: hidden;
}

#timeline-container:active {
  cursor: grabbing;
}

#timeline-container svg {
  display: block;
}

/* D3 axis styling */
#timeline-container .tick text {
  fill: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 11px;
}

#timeline-container .tick line,
#timeline-container .domain {
  stroke: rgba(255,255,255,0.1);
}

/* Dynasty bars */
.dynasty-bar {
  rx: 4;
  ry: 4;
  cursor: pointer;
  transition: filter 0.2s;
}

.dynasty-bar:hover {
  filter: brightness(1.3) drop-shadow(0 0 6px rgba(255,255,255,0.3));
}

.dynasty-label {
  fill: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Event ticks ABOVE bar */
.event-line {
  opacity: 0.85;
}

.event-marker {
  opacity: 1;
}

.event-label {
  fill: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  text-anchor: start;
  paint-order: stroke;
  stroke: var(--bg-secondary);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* Ruler ticks BELOW bar */
.ruler-line {
  opacity: 0.85;
}

.ruler-marker {
  opacity: 1;
}

.ruler-label {
  fill: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  text-anchor: start;
  paint-order: stroke;
  stroke: var(--bg-secondary);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* Detail groups transitions */
.rulers-group, .events-group {
  transition: opacity 0.3s ease;
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: var(--text-primary);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 280px;
  line-height: 1.4;
}

.tooltip.visible {
  opacity: 1;
}

.tooltip .tt-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.tooltip .tt-date {
  color: var(--accent);
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.tooltip .tt-detail {
  color: var(--text-secondary);
  font-size: 0.78rem;
}

/* ===== Map Section ===== */
#map-section {
  background: var(--bg-primary);
}

#territory-map {
  width: 100%;
  height: 50vh;
  min-height: 320px;
  background: var(--bg-primary);
}

/* Override Leaflet tile background */
.leaflet-container {
  background: var(--bg-primary) !important;
}

/* ===== Map Controls ===== */
.map-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255,255,255,0.05);
}

#play-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

#play-btn:hover {
  background: #d91a70;
}

#play-btn.playing {
  background: #457B9D;
}

/* Custom range slider */
#time-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg,
    #F4A261 0%, #2A9D8F 8%, #E63946 12%,
    #9B5DE5 18%, #457B9D 25%, #F9C74F 35%,
    #06D6A0 42%, #EF476F 60%, #F77F00 68%,
    #80B918 72%, #7209B7 82%, #4361EE 100%
  );
  outline: none;
  cursor: pointer;
}

#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 6px rgba(247, 37, 133, 0.6);
  cursor: pointer;
  border: 2px solid var(--accent);
}

#time-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 6px rgba(247, 37, 133, 0.6);
  cursor: pointer;
  border: 2px solid var(--accent);
}

#slider-label {
  min-width: 200px;
  text-align: right;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .section-header {
    flex-direction: column;
    gap: 0.2rem;
  }

  .map-controls {
    flex-wrap: wrap;
  }

  #slider-label {
    width: 100%;
    text-align: center;
    min-width: unset;
  }

  #time-slider {
    width: 100%;
    order: 3;
  }
}

@media (max-height: 700px) {
  #timeline-container {
    height: 60vh;
  }
  #territory-map {
    height: 60vh;
  }
}
