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

:root {
  --topbar-height: 52px;
  --panel-width: 320px;
  --topbar-bg: rgba(20, 10, 5, 0.92);
  --topbar-border: #5c2a00;
  --text-light: #f5e6c8;
  --text-muted: #c8a97a;
  --panel-bg: rgba(250, 245, 235, 0.98);
  --accent: #8B1A1A;
  --font-serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-serif);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ── TOPBAR ─────────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  gap: 12px;
}

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

#globe-icon {
  width: 22px; height: 22px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#site-title {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-light);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

#topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 280px;
  margin: 0 auto;
}

#select-wrapper {
  position: relative;
  width: 100%;
}

#empire-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.08);
  color: var(--text-light);
  border: 1px solid rgba(245,230,200,0.25);
  border-radius: 4px;
  padding: 6px 30px 6px 10px;
  font-family: var(--font-serif);
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

#empire-select:focus {
  border-color: var(--text-muted);
}

#empire-select option {
  background: #1a0a05;
  color: var(--text-light);
}

.select-arrow {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px; height: 6px;
  color: var(--text-muted);
  pointer-events: none;
}

#topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#timeline-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 420px;
}

#timeline-controls.hidden {
  display: none;
}

#year-display {
  color: var(--text-light);
  font-size: 12px;
  min-width: 98px;
  text-align: right;
}

#year-slider {
  width: 130px;
}

#milestone-select {
  width: 170px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.08);
  color: var(--text-light);
  border: 1px solid rgba(245,230,200,0.25);
  border-radius: 4px;
  padding: 4px 6px;
  font-family: var(--font-serif);
  font-size: 12px;
  outline: none;
}

#milestone-select option {
  background: #1a0a05;
  color: var(--text-light);
}

#lang-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
}

.lang-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s;
}

.lang-btn.active {
  color: var(--text-light);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.lang-btn:hover:not(.active) {
  color: #e0c89a;
}

.lang-sep {
  color: rgba(245,230,200,0.3);
  font-size: 12px;
}

/* ── MAP CONTAINER ──────────────────────────────────────── */
#map-container {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  transition: right 0.25s ease;
}

#map-container.panel-open {
  right: var(--panel-width);
}

#map {
  width: 100%;
  height: 100%;
}

/* ── INFO PANEL ─────────────────────────────────────────── */
#info-panel {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  width: var(--panel-width);
  height: calc(100% - var(--topbar-height));
  background: var(--panel-bg);
  border-left: 1px solid #d4b896;
  overflow-y: auto;
  z-index: 900;
  transform: translateX(0);
  transition: transform 0.25s ease;
  padding: 16px;
}

#info-panel.hidden {
  transform: translateX(var(--panel-width));
}

#close-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: 1px solid #c8a060;
  color: #6b3a1f;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#close-panel:hover {
  background: rgba(139,26,26,0.1);
}

.panel-header {
  padding-top: 8px;
  padding-right: 30px;
  margin-bottom: 16px;
  border-bottom: 1px solid #d4b896;
  padding-bottom: 12px;
}

.panel-name {
  font-size: 20px;
  font-weight: 600;
  color: #2c1810;
  line-height: 1.2;
  margin-bottom: 4px;
}

.panel-latin {
  font-style: italic;
  color: #7a4a2a;
  font-size: 14px;
  margin-bottom: 6px;
}

.panel-type {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  padding: 2px 8px;
  border-radius: 3px;
}

.panel-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin-bottom: 16px;
  font-size: 14px;
}

.panel-details dt {
  color: #7a4a2a;
  font-weight: 600;
  white-space: nowrap;
}

.panel-details dd {
  color: #2c1810;
}

.panel-details dd em {
  color: #7a4a2a;
  font-size: 13px;
}

.panel-description h3 {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a4a2a;
  margin-bottom: 8px;
}

.panel-description p {
  font-size: 14px;
  color: #2c1810;
  line-height: 1.6;
}

.panel-source {
  margin: 10px 0 12px;
}

.panel-source a {
  color: #7a4a2a;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.panel-separator {
  border: 0;
  border-top: 1px solid #d4b896;
  margin: 14px 0;
}

#panel-hint {
  color: #7a4a2a;
  font-style: italic;
  font-size: 14px;
  margin-top: 40px;
  text-align: center;
}

/* ── LEGEND ─────────────────────────────────────────────── */
.map-legend {
  background: rgba(20, 10, 5, 0.82);
  color: var(--text-light);
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid var(--topbar-border);
  font-family: var(--font-serif);
  font-size: 12px;
  min-width: 160px;
}

.legend-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.legend-swatch {
  display: inline-block;
  width: 18px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ── TOOLTIP ─────────────────────────────────────────────── */
.province-tooltip {
  font-family: var(--font-serif) !important;
  font-style: italic !important;
  background: rgba(20, 10, 5, 0.85) !important;
  color: #f5e6c8 !important;
  border: 1px solid #8B4513 !important;
  border-radius: 3px !important;
  padding: 4px 10px !important;
  font-size: 13px !important;
  white-space: nowrap !important;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.4) !important;
}

.province-tooltip::before {
  display: none !important;
}

.territory-label {
  pointer-events: none;
  white-space: nowrap;
  color: #2c1810;
  background: rgba(250, 245, 235, 0.84);
  border: 1px solid rgba(92, 42, 0, 0.35);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  text-shadow: 0 0 2px rgba(255,255,255,0.8);
}

/* ── LEAFLET OVERRIDES ──────────────────────────────────── */
.leaflet-control-zoom {
  border: 1px solid var(--topbar-border) !important;
  background: rgba(20, 10, 5, 0.82) !important;
}

.leaflet-control-zoom a {
  background: transparent !important;
  color: var(--text-light) !important;
  border-bottom: 1px solid var(--topbar-border) !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(255,255,255,0.1) !important;
}

.leaflet-control-attribution {
  background: rgba(20,10,5,0.6) !important;
  color: rgba(245,230,200,0.6) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

/* ── MOBILE ──────────────────────────────────────────────── */
@media (max-width: 767px) {
  :root {
    --topbar-height: 96px;
  }

  #site-title { display: none; }
  #globe-icon { display: none; }

  #topbar {
    height: var(--topbar-height);
    padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 8px;
    gap: 6px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-content: center;
  }

  #topbar-left {
    display: none;
  }

  #topbar-center {
    grid-row: 1;
    width: 100%;
    max-width: none;
    margin: 0;
  }

  #empire-select {
    height: 34px;
    font-size: 13px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  #topbar-right {
    grid-row: 2;
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    gap: 8px;
  }

  #timeline-controls {
    flex: 1;
    min-width: 0;
    max-width: none;
    gap: 5px;
  }

  #year-display {
    min-width: 0;
    font-size: 11px;
    text-align: left;
  }

  #year-slider {
    width: 100%;
    min-width: 72px;
    max-width: 150px;
  }

  #milestone-select {
    width: 44vw;
    max-width: 170px;
    min-width: 96px;
    font-size: 11px;
    padding: 3px 5px;
  }

  #lang-toggle {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(245,230,200,0.18);
    border-radius: 6px;
    padding: 2px 4px;
  }

  .lang-btn {
    font-size: 12px;
    padding: 4px 5px;
  }

  #map-container {
    transition: bottom 0.25s ease;
  }

  #map-container.panel-open {
    right: 0;
    bottom: 50vh;
  }

  #info-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 56vh;
    border-left: none;
    border-top: 2px solid #c8a060;
    transform: translateY(0);
    transition: transform 0.25s ease;
    padding: 14px;
  }

  #info-panel.hidden {
    transform: translateY(56vh);
  }

  .map-legend {
    display: none;
  }

  .panel-name {
    font-size: 18px;
  }

  .panel-details {
    gap: 5px 10px;
    font-size: 13px;
  }

  .panel-description p {
    font-size: 13px;
    line-height: 1.5;
  }

  .territory-label {
    font-size: 10px;
    padding: 1px 4px;
  }
}

@media (max-width: 420px) {
  :root {
    --topbar-height: 104px;
  }

  #topbar {
    padding-left: 8px;
    padding-right: 8px;
  }

  #timeline-controls {
    gap: 4px;
  }

  #year-display {
    display: none;
  }

  #year-slider {
    max-width: 110px;
    min-width: 64px;
  }

  #milestone-select {
    width: 46vw;
    min-width: 86px;
  }
}
