/* =========================================================================
   中华舆图 · Atlas UI  (V2 Redesign)
   -------------------------------------------------------------------------
   Layered on top of css/style.css (map cartography + base tokens).
   This file owns the application chrome: top bar, map overlays, cards,
   chronicle pane, timeline and every responsive breakpoint.

   Design notes
   - Warm paper ground, single white surface family, hairline rules.
   - Vermilion is the only saturated accent; gold/sage stay decorative.
   - Motion is limited to transform/opacity and honours reduced-motion.
   - No backdrop-filter on large surfaces; small floating layers only.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. Tokens
   ---------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Shared palette (also consumed by the map cartography in style.css) */
  --bg-parchment: #ede5d6;
  --bg-parchment-alt: #e4d9c5;
  --water-fill: #d8e2df;
  --text-main: #1f1b16;
  --text-secondary: #51493f;
  --text-muted: #7a7165;
  --vermilion: #a63e2c;
  --amber-gold: #ad8137;
  --hairline: rgba(31, 27, 22, 0.1);
  --card-shadow: 0 1px 2px rgba(45, 34, 22, 0.05), 0 14px 34px -16px rgba(45, 34, 22, 0.32);
  --corner-radius: 16px;
  --dynasty-accent: #2a241d;

  /* UI-specific */
  --ui-surface: #fcf8ef;
  --ui-surface-soft: #f5eedf;
  --ui-paper: #ede5d6;
  --ui-paper-2: #e2d6c1;
  --ui-ink: #1a150f;
  --ui-ink-2: #4d4438;
  --ui-ink-3: #71675a;
  --ui-accent: #a63e2c;
  --ui-accent-ink: #8c2f1f;
  --ui-accent-soft: rgba(166, 62, 44, 0.09);
  --ui-accent-line: rgba(166, 62, 44, 0.34);
  --ui-gold: #b58a4a;
  --ui-gold-soft: rgba(181, 138, 74, 0.42);
  --ui-gold-line: rgba(181, 138, 74, 0.28);
  --ui-sage: #3f6659;
  --ui-line: rgba(31, 27, 22, 0.11);
  --ui-line-soft: rgba(31, 27, 22, 0.07);
  --ui-line-strong: rgba(31, 27, 22, 0.18);
  --ui-shadow-xs: 0 1px 2px rgba(45, 34, 22, 0.06);
  --ui-shadow-sm: 0 1px 2px rgba(45, 34, 22, 0.05), 0 3px 10px -5px rgba(45, 34, 22, 0.28);
  --ui-shadow-md: 0 2px 4px rgba(45, 34, 22, 0.04), 0 14px 30px -14px rgba(45, 34, 22, 0.34);
  --ui-shadow-lg: 0 3px 8px rgba(45, 34, 22, 0.05), 0 26px 60px -26px rgba(45, 34, 22, 0.45);
  --ui-radius-xs: 8px;
  --ui-radius-sm: 10px;
  --ui-radius: 14px;
  --ui-radius-lg: 18px;
  --ui-radius-xl: 22px;
  --ui-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ui-nav-h: 64px;
  --ui-pane-w: 360px;
  --ui-gutter: 12px;

  /* Lacquer frame */
  --ui-lacquer: #17130f;
  --ui-lacquer-2: #211a13;
  --ui-cream: #f5ebd8;
  --ui-cream-2: rgba(245, 235, 216, 0.68);
  --ui-cream-3: rgba(245, 235, 216, 0.42);
}

/* -------------------------------------------------------------------------
   2. Base
   ---------------------------------------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--ui-paper);
  color: var(--ui-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

button,
input,
select,
textarea {
  font-family: var(--sans-stack);
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input {
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

::selection {
  background: rgba(166, 62, 44, 0.18);
}

/* Thin, quiet scrollbars */
#chronicle-pane,
.genealogy-body,
.search-results-list,
#map-key,
.layers-popover {
  scrollbar-width: thin;
  scrollbar-color: rgba(31, 27, 22, 0.22) transparent;
}

#chronicle-pane::-webkit-scrollbar,
.genealogy-body::-webkit-scrollbar,
.search-results-list::-webkit-scrollbar,
#map-key::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#chronicle-pane::-webkit-scrollbar-thumb,
.genealogy-body::-webkit-scrollbar-thumb,
.search-results-list::-webkit-scrollbar-thumb,
#map-key::-webkit-scrollbar-thumb {
  background: rgba(31, 27, 22, 0.18);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

#chronicle-pane::-webkit-scrollbar-thumb:hover,
.genealogy-body::-webkit-scrollbar-thumb:hover {
  background: rgba(31, 27, 22, 0.34);
  background-clip: content-box;
}

/* -------------------------------------------------------------------------
   3. App shell
   ---------------------------------------------------------------------- */
#atlas-shell {
  grid-template-rows: calc(var(--ui-nav-h) + env(safe-area-inset-top, 0px)) minmax(0, 1fr) auto;
  background:
    radial-gradient(1100px 520px at 16% -8%, rgba(255, 252, 245, 0.55), transparent 62%),
    radial-gradient(900px 520px at 108% 108%, rgba(199, 209, 202, 0.32), transparent 62%),
    var(--ui-paper);
}

/* -------------------------------------------------------------------------
   4. Top bar
   ---------------------------------------------------------------------- */
#nav-bar {
  height: calc(var(--ui-nav-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0 18px;
  gap: 14px;
  border-bottom: 1px solid var(--ui-gold-line);
  background:
    radial-gradient(120% 160% at 12% -40%, rgba(181, 138, 74, 0.16), transparent 58%),
    linear-gradient(180deg, #241d16 0%, #1a1510 58%, #14100c 100%);
  color: var(--ui-cream);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* 回纹 mounting border along the lacquer frame */
#nav-bar::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='6' viewBox='0 0 24 6'%3E%3Cpath d='M1 5.2V1h6.2v3.2h7V1H22' fill='none' stroke='%23b58a4a' stroke-width='.55'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  opacity: 0.38;
  pointer-events: none;
}

.brand-group {
  min-width: 0;
}

.brand-group h1 {
  align-items: center;
  gap: 14px;
}

.brand-group .home-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 3px 5px 3px 0;
  border-radius: 10px;
  color: inherit;
  transition: opacity 0.15s ease;
}

.brand-group .home-link:hover {
  opacity: 0.86;
}

.brand-seal {
  display: inline-flex;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 2px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(181, 138, 74, 0.28),
    0 3px 10px -2px rgba(0, 0, 0, 0.55);
}

.brand-seal svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-wordmark {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-width: 0;
}

.brand-group .seal-mark {
  font-family: var(--calligraphy-stack);
  font-size: 25px;
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--ui-cream);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.brand-latin {
  font-family: var(--sans-stack);
  font-size: 7.5px;
  font-weight: 600;
  letter-spacing: 0.34em;
  line-height: 1;
  color: var(--ui-gold);
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-group .subtitle-mark {
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--ui-cream-2);
  padding-left: 14px;
  border-left: 1px solid rgba(181, 138, 74, 0.38);
  line-height: 1.5;
  white-space: nowrap;
}

/* --- Tool cluster --- */
.control-strip {
  gap: 6px;
  overflow: visible;
}

.toolbar-divider {
  display: none;
}

.action-btn {
  height: 34px;
  padding: 0 11px;
  gap: 6px;
  border-radius: var(--ui-radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ui-cream-2);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease,
    box-shadow 0.15s ease;
}

.action-btn:active {
  transform: translateY(1px);
}

.action-btn.subtle {
  background: rgba(245, 235, 216, 0.055);
  border: 1px solid rgba(245, 235, 216, 0.15);
  color: var(--ui-cream-2);
  box-shadow: none;
}

.action-btn.subtle:hover {
  background: rgba(245, 235, 216, 0.12);
  border-color: rgba(181, 138, 74, 0.55);
  color: var(--ui-cream);
  box-shadow: 0 0 0 1px rgba(181, 138, 74, 0.12);
}

.action-btn.subtle.is-active {
  background: var(--ui-accent);
  border-color: #c2543e;
  color: #fff8ec;
}

.btn-svg {
  opacity: 0.9;
}

.action-btn.subtle:hover .btn-svg {
  opacity: 1;
}

.layers-trigger-btn.is-active {
  background: var(--ui-accent) !important;
  border-color: #c2543e !important;
  color: #fff8ec !important;
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(214, 132, 108, 0.25);
}

.layers-trigger-btn .caret-mark {
  font-size: 9px;
  opacity: 0.6;
  margin-left: -2px;
}

/* Language trigger */
.locale-trigger {
  gap: 7px;
}

.locale-trigger .caret-mark {
  font-size: 9px;
  opacity: 0.6;
  margin-left: -1px;
}

.locale-trigger.is-active {
  background: rgba(245, 235, 216, 0.14) !important;
  border-color: rgba(181, 138, 74, 0.6) !important;
  color: var(--ui-cream) !important;
}

.locale-full {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.locale-code {
  display: none;
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.08em;
}

/* Language popover (rice-paper panel on the lacquer bar) */
.locale-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 16px;
  z-index: 55;
  width: 388px;
  padding: 14px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-lg);
  animation: uiPopIn 0.18s var(--ui-ease);
}

.locale-pop-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--ui-line-soft);
}

.locale-pop-heading span {
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--ui-ink-3);
  text-transform: uppercase;
}

.locale-pop-heading em {
  font-family: var(--serif-stack);
  font-style: normal;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ui-accent);
}

.locale-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.locale-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface-soft);
  color: var(--ui-ink-2);
  font-family: var(--sans-stack);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease;
}

.locale-item em {
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ui-ink-3);
  opacity: 0.75;
}

.locale-item:hover {
  background: #fff;
  border-color: var(--ui-line);
  color: var(--ui-ink);
}

.locale-item.is-active {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-line);
  color: var(--ui-accent-ink);
  font-weight: 600;
}

.locale-item.is-active em {
  color: var(--ui-accent);
  opacity: 1;
}

.locale-item.is-active::after {
  content: '';
  width: 6px;
  height: 6px;
  margin-left: 4px;
  flex: none;
  border-radius: 50%;
  background: var(--ui-accent);
}

.layers-trigger-btn.is-active .caret-mark {
  opacity: 0.9;
}

/* Lacquered music group */
.music-pill-group {
  border-radius: var(--ui-radius-sm);
  background: rgba(245, 235, 216, 0.055);
  border: 1px solid rgba(245, 235, 216, 0.15);
  box-shadow: none;
  overflow: hidden;
}

.music-pill-group .music-btn,
.music-pill-group .music-next-btn {
  height: 32px;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent;
  box-shadow: none;
  color: var(--ui-cream-2);
}

.music-pill-group .music-btn {
  padding: 0 11px;
}

.music-pill-group .music-next-btn {
  padding: 0 8px;
  border-left: 1px solid rgba(245, 235, 216, 0.14) !important;
}

.music-pill-group .music-btn:hover,
.music-pill-group .music-next-btn:hover {
  background: rgba(245, 235, 216, 0.12);
  color: var(--ui-cream);
}

.music-pill-group .music-btn.is-active {
  background: var(--ui-accent);
  color: #fffaf0;
}

.music-pill-group .music-btn.is-active .btn-svg {
  opacity: 1;
}

/* --- Layers popover --- */
.layers-popover {
  top: calc(100% + 8px);
  width: 304px;
  padding: 14px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-lg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  animation: uiPopIn 0.18s var(--ui-ease);
}

@keyframes uiPopIn {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.layers-pop-section + .layers-pop-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ui-line-soft);
  border-top-style: solid;
}

.layers-pop-heading {
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--ui-ink-3);
}

.layers-pop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.layer-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--ui-radius-sm);
  border: 1px solid var(--ui-line-soft);
  background: var(--ui-surface-soft);
  color: var(--ui-ink-2);
  font-size: 12.5px;
  font-weight: 500;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.layer-chip:hover {
  background: #fff;
  border-color: var(--ui-line-strong);
  color: var(--ui-ink);
}

.layer-chip:has(input:focus-visible) {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

.layer-chip::before {
  content: '';
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 4px;
  border: 1.5px solid var(--ui-line-strong);
  background: #fff;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.layer-chip:has(input:checked) {
  background: rgba(166, 62, 44, 0.055);
  border-color: var(--ui-accent-line);
  color: var(--ui-accent-ink);
  font-weight: 600;
}

.layer-chip:has(input:checked)::before {
  content: '';
  border-color: var(--ui-accent);
  background:
    var(--ui-accent)
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.6 6.3l2.1 2.1 4.7-4.7' fill='none' stroke='%23fff8ec' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 12px no-repeat;
}

/* -------------------------------------------------------------------------
   5. Workspace & map surface
   ---------------------------------------------------------------------- */
#workspace-body {
  grid-template-columns: minmax(0, 1fr) var(--ui-pane-w);
  gap: var(--ui-gutter);
  padding: var(--ui-gutter) var(--ui-gutter) 0;
  background: var(--ui-paper);
}

#viewport-frame {
  border: 1px solid var(--ui-gold-line);
  border-radius: var(--ui-radius-xl);
  background: var(--water-fill);
  box-shadow:
    var(--ui-shadow-sm),
    0 0 0 1px rgba(31, 27, 22, 0.04);
}

/* Inner mounting frame, like the silk border of a hanging scroll. */
#viewport-frame::before {
  content: '';
  position: absolute;
  inset: 7px;
  z-index: 4;
  border: 1px solid rgba(181, 138, 74, 0.24);
  border-radius: calc(var(--ui-radius-xl) - 7px);
  pointer-events: none;
}

#viewport-frame.is-camera-moving {
  will-change: transform;
}

/* Promote the SVG stage only while the camera is actually moving. */
#svg-stage-wrap {
  will-change: auto;
}

#viewport-frame.is-camera-moving #svg-stage-wrap {
  will-change: transform;
}

/* -------------------------------------------------------------------------
   6. Floating search
   ---------------------------------------------------------------------- */
#map-search-box {
  top: 14px;
  left: 14px;
  width: 248px;
  z-index: 12;
}

#map-search-box:focus-within,
#map-search-box:has(#map-search-results:not(.is-hidden)) {
  width: min(400px, calc(100% - 28px));
}

.search-input-wrap {
  height: 42px;
  padding: 0 14px;
  gap: 9px;
  border-radius: var(--ui-radius-sm);
  border: 1px solid var(--ui-line);
  background: rgba(255, 253, 248, 0.93);
  box-shadow: var(--ui-shadow-md);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

#map-search-box:focus-within .search-input-wrap {
  border-color: var(--ui-accent-line);
  background: var(--ui-surface);
  box-shadow:
    0 0 0 3px rgba(166, 62, 44, 0.1),
    var(--ui-shadow-md);
}

.search-ico {
  color: var(--ui-ink-3);
  transition: color 0.15s ease;
}

#map-search-box:focus-within .search-ico {
  color: var(--ui-accent);
}

#inp-map-search {
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--ui-ink);
  line-height: 1.4;
}

#inp-map-search::placeholder {
  color: var(--ui-ink-3);
  opacity: 0.9;
}

/* Search results */
.search-results-list {
  margin-top: 8px;
  padding: 6px;
  border-radius: var(--ui-radius);
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-lg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  max-height: min(64vh, 440px);
  gap: 1px;
}

.search-results-list li {
  padding: 9px 10px;
  border-radius: var(--ui-radius-xs);
  gap: 10px;
  font-size: 12.5px;
  transition: background 0.12s ease;
}

.search-results-list li:hover,
.search-results-list li.is-active {
  background: var(--ui-surface-soft);
}

.sr-main {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sr-sub {
  margin-left: 6px;
  font-size: 11px;
  color: var(--ui-ink-3);
}

.sr-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-size: 10px;
  letter-spacing: 0.02em;
}

.sr-eg-pill {
  padding: 1px 6px;
  margin-right: 7px;
  border-radius: 4px;
  border: 1px solid rgba(140, 90, 43, 0.2);
  background: rgba(140, 90, 43, 0.09);
  color: #7c4d1e;
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

.sr-section-head {
  padding: 9px 10px 5px !important;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ui-ink-3);
  background: transparent;
  border-bottom: 1px solid var(--ui-line-soft) !important;
}

.sr-search-guide {
  border-top: 1px solid var(--ui-line-soft);
}

.sr-guide-label {
  font-size: 10.5px;
  color: var(--ui-ink-3);
}

.sr-chip-btn {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface-soft);
  color: var(--ui-ink-2);
  font-size: 11px;
}

.sr-chip-btn:hover {
  border-color: var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
}

.sr-cycle-btn {
  width: 22px;
  height: 22px;
  border-color: var(--ui-line);
  background: var(--ui-surface);
  color: var(--ui-ink-3);
}

.sr-quiz-link {
  color: var(--ui-accent-ink);
  font-size: 11px;
}

/* -------------------------------------------------------------------------
   7. Map legend
   ---------------------------------------------------------------------- */
#map-key {
  left: 14px;
  bottom: 14px;
  max-width: 352px;
  padding: 10px 12px 11px;
  gap: 8px;
  border-radius: var(--ui-radius);
  border: 1px solid var(--ui-line);
  background: rgba(255, 253, 248, 0.93);
  box-shadow: var(--ui-shadow-md);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  backdrop-filter: blur(12px) saturate(1.15);
  font-size: 11.5px;
  color: var(--ui-ink-2);
}

.key-phase-bar {
  padding-bottom: 7px;
  border-bottom: 1px solid var(--ui-line-soft);
  gap: 6px;
}

.key-phase-badge {
  font-family: var(--serif-stack);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ui-accent-ink);
}

.key-phase-dots {
  gap: 5px;
}

.phase-dot {
  width: 6px;
  height: 6px;
  background: rgba(31, 27, 22, 0.18);
}

.phase-dot:hover {
  background: var(--ui-accent-line);
  transform: scale(1.2);
}

.phase-dot.is-active {
  background: var(--ui-accent);
  transform: scale(1.25);
}

.key-heading {
  padding: 0;
  border: 0;
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  color: var(--ui-ink-3);
  text-transform: uppercase;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 12px;
  margin-top: -1px;
}

.key-entry {
  gap: 7px;
  min-width: 0;
  padding: 2px 0;
  color: var(--ui-ink-2);
  font-size: 11.5px;
  line-height: 1.35;
}

.key-entry.is-interactive {
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 6px;
}

.key-entry.is-interactive:hover {
  background: var(--ui-accent-soft);
  color: var(--ui-ink);
}

.key-entry.is-interactive.is-active {
  background: var(--ui-accent-soft);
  color: var(--ui-ink);
  box-shadow: inset 0 0 0 1px var(--ui-accent-line);
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border-width: 1.5px;
  flex: none;
}

.key-note {
  gap: 6px;
  font-size: 10.5px;
  color: var(--ui-ink-3);
  line-height: 1.4;
  padding-top: 1px;
}

.key-corridors-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 2px;
}

.key-corridors-grid .key-entry {
  font-size: 10.5px;
  color: var(--ui-ink-3);
}

.key-mobile-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  margin-left: auto;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  color: var(--ui-ink-2);
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition:
    border-color 0.14s ease,
    color 0.14s ease,
    background 0.14s ease;
}

.key-mobile-toggle:hover {
  border-color: var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
}

/* The legend starts as a slim era chip everywhere; details on demand. */
#map-key:not(.is-mobile-expanded) .key-heading,
#map-key:not(.is-mobile-expanded) .key-note,
#map-key:not(.is-mobile-expanded) .key-corridors-grid,
#map-key:not(.is-mobile-expanded) .key-polities-grid,
#map-key:not(.is-mobile-expanded) .key-phase-dots {
  display: none;
}

#map-key:not(.is-mobile-expanded) {
  max-width: min(352px, calc(100% - 20px));
  padding: 7px 9px;
}

#map-key:not(.is-mobile-expanded) .key-phase-bar {
  flex-wrap: nowrap;
  gap: 8px;
  padding-bottom: 0;
  border-bottom: 0;
}

#map-key:not(.is-mobile-expanded) .key-phase-badge {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Single-phase eras still need the era chip + toggle, even though the phase
   dots are meaningless there. */
#map-key .key-phase-bar.is-single-phase {
  display: flex;
}

#map-key.is-mobile-expanded {
  max-width: min(380px, calc(100% - 20px));
}

/* One floating layer at a time: a card/tooltip never fights the legend or
   search dropdown for the same pixels. */
#viewport-frame:has(#map-search-box:focus-within) #milestone-balloon,
#viewport-frame:has(#map-search-box.is-expanded) #milestone-balloon,
#viewport-frame:has(#map-search-results:not(.is-hidden)) #milestone-balloon,
#viewport-frame:has(#map-key.is-mobile-expanded) #milestone-balloon {
  opacity: 0;
  pointer-events: none;
}

#viewport-frame:has(#map-key.is-mobile-expanded) #start-guide {
  opacity: 0;
  pointer-events: none;
}

/* -------------------------------------------------------------------------
   8. Canvas utilities (scale / reset / pane toggle / hints)
   ---------------------------------------------------------------------- */
#canvas-br-dock {
  right: 14px;
  bottom: 14px;
  gap: 10px;
  z-index: 6;
}

.canvas-reset-btn {
  height: 36px;
  padding: 0 12px;
  gap: 6px;
  border-radius: var(--ui-radius-sm);
  border: 1px solid var(--ui-line);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--ui-shadow-sm);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-ink-2);
}

.canvas-reset-btn:hover {
  background: #fff;
  border-color: var(--ui-accent-line);
  color: var(--ui-accent);
}

#scale-bar-box {
  gap: 3px;
  padding-bottom: 2px;
}

.scale-label {
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ui-ink-2);
  text-shadow:
    0 0 3px rgba(255, 253, 246, 1),
    0 0 6px rgba(255, 253, 246, 0.9);
}

.scale-ruler {
  height: 5px;
  border-bottom-width: 1.5px;
  border-left-width: 1.5px;
  border-right-width: 1.5px;
  color: var(--ui-ink-2);
}

#act-toggle-pane {
  right: 0;
  top: 50%;
  width: 26px;
  min-height: 76px;
  padding: 10px 0;
  gap: 4px;
  border: 1px solid var(--ui-line);
  border-right: none;
  border-radius: 12px 0 0 12px;
  background: rgba(255, 253, 248, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ui-ink-2);
  box-shadow: -4px 0 16px rgba(45, 34, 22, 0.08);
  transition:
    background 0.16s ease,
    color 0.16s ease,
    border-color 0.16s ease,
    width 0.16s ease;
}

#act-toggle-pane .tp-arrow {
  font-size: 12px;
  color: var(--ui-accent);
  line-height: 1;
}

#act-toggle-pane .tp-label {
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  writing-mode: vertical-rl;
}

#act-toggle-pane:hover {
  width: 30px;
  background: var(--ui-surface);
  color: var(--ui-accent);
  border-color: var(--ui-accent-line);
}

#viewport-frame.is-camera-moving #act-toggle-pane,
#viewport-frame.is-camera-moving #start-guide {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* Immersive modes own the map canvas; the pane toggle would sit under the card. */
#viewport-frame.has-active-person #act-toggle-pane,
#viewport-frame.has-active-challenge #act-toggle-pane {
  display: none;
}

#gesture-guide {
  right: 14px;
  top: 14px;
  max-width: min(560px, 46%);
  padding: 6px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.84);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ui-ink-3);
  font-size: 10.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* First-visit guide */
#start-guide {
  right: 14px;
  top: 14px;
  gap: 8px;
  padding: 6px 8px 6px 13px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-sm);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--ui-shadow-md);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

#start-guide .sg-head {
  font-family: var(--sans-stack);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--ui-ink-3);
}

#start-guide .sg-item {
  padding: 4px 2px;
  font-family: var(--serif-stack);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ui-accent);
  text-underline-offset: 3px;
}

#start-guide .sg-sep {
  color: var(--ui-line-strong);
}

#start-guide .sg-close {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--ui-ink-3);
  font-size: 15px;
}

#start-guide .sg-close:hover {
  background: var(--ui-surface-soft);
  color: var(--ui-ink);
}

#viewport-frame.is-camera-moving #start-guide {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Hover tooltip */
#hover-tip {
  padding: 8px 12px;
  border-radius: var(--ui-radius-sm);
  background: rgba(28, 24, 19, 0.94);
  box-shadow: 0 10px 26px -10px rgba(0, 0, 0, 0.55);
  font-size: 12px;
  line-height: 1.5;
  max-width: 260px;
}

#hover-tip .tt-sub {
  display: block;
  margin-top: 2px;
  color: rgba(250, 244, 233, 0.68);
  font-size: 10.5px;
}

#hover-tip .tt-trace-btn {
  margin-top: 8px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 240, 220, 0.28);
  background: rgba(255, 248, 236, 0.12);
  color: #fff7e8;
  font-size: 11px;
  font-weight: 600;
}

#hover-tip .tt-trace-btn:hover {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
}

/* -------------------------------------------------------------------------
   9. Chronology pane
   ---------------------------------------------------------------------- */
#chronicle-pane {
  padding: 0 22px 18px;
  gap: 16px;
  border: 1px solid var(--ui-line);
  border-top: 2px solid var(--ui-gold-soft);
  border-radius: var(--ui-radius-xl);
  background:
    url('../assets/brand-watermark.svg') no-repeat right 18px bottom 14px / 118px auto,
    var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

#chronicle-pane::-webkit-scrollbar {
  width: 10px;
}

.polity-backbar {
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface-soft);
  font-family: var(--sans-stack);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ui-ink-2);
}

.polity-backbar:hover {
  color: var(--ui-accent);
  border-color: var(--ui-accent-line);
}

.dynasty-banner {
  position: sticky;
  top: 0;
  z-index: 3;
  padding-top: 22px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-line);
  padding-bottom: 14px;
}

.dynasty-title-row {
  align-items: center;
  gap: 12px;
  row-gap: 6px;
  flex-wrap: wrap;
  border-bottom: 0;
  padding-bottom: 0;
}

#dynasty-title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--calligraphy-stack);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: 0.01em;
  color: var(--dynasty-accent);
  white-space: nowrap;
}

#dynasty-title.is-long {
  font-size: 28px;
  letter-spacing: 0;
}

.span-label {
  flex: none;
  margin-left: auto;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface-soft);
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ui-ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.seat-row {
  margin-top: 12px;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ui-ink-2);
}

.seat-tag {
  flex: none;
  margin-top: 1px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

#dynasty-seat {
  min-width: 0;
}

.dynasty-desc {
  margin: 0;
  font-family: var(--serif-stack);
  font-size: 13.8px;
  line-height: 1.85;
  color: var(--ui-ink-2);
  letter-spacing: 0.01em;
}

.milestone-section {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 0;
}

.milestone-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ui-ink-3);
}

.milestone-section h3::before {
  content: '';
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--ui-accent);
}

#milestone-list {
  gap: 2px;
  margin: 0 -8px;
}

#milestone-list li {
  grid-template-columns: 76px 1fr;
  gap: 10px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--ui-radius-xs);
  background: transparent;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ui-ink-2);
  transition:
    background 0.14s ease,
    border-color 0.14s ease;
}

#milestone-list li:hover {
  background: var(--ui-surface-soft);
  border-color: var(--ui-line-soft);
}

#milestone-list li.is-current {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-line);
}

#milestone-list .ev-yr {
  font-family: var(--sans-stack);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ui-accent-ink);
  font-variant-numeric: tabular-nums;
  padding-top: 1px;
}

#milestone-list .ev-map-tag {
  margin-left: 5px;
  font-size: 10px;
  color: var(--ui-ink-3);
  opacity: 1;
}

#milestone-list .ev-seal-tag {
  border-color: #9e2218;
  background: #b4281e;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 236, 0.5);
}

.disclaimer-box {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-line-soft);
  font-size: 10px;
  line-height: 1.6;
  color: var(--ui-ink-3);
  opacity: 0.9;
}

/* Polity focus block */
.polity-extra {
  gap: 10px;
}

.polity-row {
  gap: 9px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ui-ink-2);
}

.polity-rulers {
  font-family: var(--serif-stack);
  color: var(--ui-ink);
}

.polity-stages {
  gap: 5px;
}

.polity-stage-chip {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface-soft);
  font-family: var(--sans-stack);
  font-size: 11px;
  color: var(--ui-ink-2);
}

.polity-stage-chip:hover,
.polity-stage-chip.is-current {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-line);
  color: var(--ui-accent-ink);
}

/* -------------------------------------------------------------------------
   10. Floating cards (genealogy / person / challenge / journey)
   ---------------------------------------------------------------------- */
#genealogy-card {
  top: 14px;
  right: 14px;
  width: 372px;
  max-height: calc(100% - 28px);
  padding: 14px 16px;
  gap: 0;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--ui-shadow-lg);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  backdrop-filter: blur(16px) saturate(1.1);
  z-index: 14;
}

.genealogy-header {
  gap: 10px;
  align-items: flex-start;
  padding-bottom: 10px;
}

.genealogy-heading-group {
  min-width: 0;
}

.genealogy-tag {
  font-family: var(--sans-stack);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ui-accent);
  text-transform: uppercase;
}

.genealogy-title {
  margin-top: 5px;
  font-family: var(--serif-stack);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: var(--ui-ink);
}

.genealogy-header-actions {
  gap: 4px;
  margin-top: -2px;
}

.icon-close {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ui-ink-3);
  font-size: 14px;
  transition:
    background 0.14s ease,
    color 0.14s ease;
}

.icon-close:hover {
  background: var(--ui-surface-soft);
  border-color: var(--ui-line-soft);
  color: var(--ui-ink);
}

.gen-expand-btn {
  display: none;
}

.genealogy-sub {
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--ui-line-soft);
  border-bottom-style: solid;
  font-size: 11px;
  color: var(--ui-ink-3);
  gap: 8px;
}

.gen-filter-pill {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 600;
}

.gen-filter-pill.is-active {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff8ec;
}

.genealogy-body {
  gap: 0;
}

.genealogy-list {
  gap: 2px;
}

.genealogy-list li {
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 8px;
  border-radius: var(--ui-radius-xs);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ui-ink-2);
}

.genealogy-list li:hover {
  background: var(--ui-surface-soft);
}

.genealogy-list li.is-current {
  background: var(--ui-accent-soft);
  box-shadow: inset 2px 0 0 var(--ui-accent);
}

.genealogy-list .t-era {
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ui-accent-ink);
  font-variant-numeric: tabular-nums;
}

.genealogy-list li.is-current .t-era {
  color: var(--ui-accent-ink);
}

.genealogy-list .t-val {
  color: var(--ui-ink);
  line-height: 1.55;
}

.genealogy-list .t-sub {
  margin-top: 2px;
  font-size: 10.8px;
  color: var(--ui-ink-3);
}

.t-cap-badge {
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-size: 9.5px;
  vertical-align: 1px;
}

.t-events {
  margin-top: 6px;
  padding: 1px 0 1px 9px;
  border-left: 1.5px solid var(--ui-line);
  gap: 1px;
}

.t-ev-row {
  padding: 3px 5px;
  margin-left: -5px;
  border-radius: 5px;
  font-size: 11.2px;
  line-height: 1.5;
}

.t-ev-row:hover {
  background: var(--ui-accent-soft);
}

.t-ev-yr {
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ui-accent-ink);
  font-variant-numeric: tabular-nums;
}

.t-ev-txt {
  color: var(--ui-ink-2);
}

.pass-lore-banner,
#genealogy-lore {
  padding: 9px 11px;
  margin-bottom: 8px;
  border-radius: var(--ui-radius-xs);
  border: 1px solid var(--ui-accent-line);
  background: linear-gradient(135deg, rgba(166, 62, 44, 0.07), rgba(163, 123, 48, 0.06));
  gap: 4px;
}

.pass-lore-badge {
  border-radius: 4px;
  background: var(--ui-accent);
  font-family: var(--sans-stack);
  font-size: 9.5px;
  letter-spacing: 0.06em;
}

.pass-lore-range {
  font-size: 11px;
  color: var(--ui-accent-ink);
}

.pass-lore-desc {
  font-size: 11.2px;
  line-height: 1.55;
  color: var(--ui-ink-2);
}

.genealogy-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--ui-line-soft);
}

.gen-foot-prev,
.gen-foot-next {
  padding: 7px 2px;
  font-family: var(--sans-stack);
  font-size: 12px;
  font-weight: 600;
}

.gen-foot-next {
  color: var(--ui-accent);
}

.ev-journey-btn {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-family: var(--sans-stack);
  font-size: 10px;
  font-weight: 600;
}

.ev-journey-btn:hover {
  background: var(--ui-accent);
  color: #fff8ec;
}

/* Person chronicle specifics */
.genealogy-list li.person-ev-row {
  grid-template-columns: 82px 1fr;
}

.person-ev-copy {
  margin-top: 4px;
  font-family: var(--serif-stack);
  font-size: 11.8px;
  line-height: 1.6;
  color: var(--ui-ink-2);
}

.person-ev-quote {
  margin-top: 5px;
  padding-left: 8px;
  border-left: 2px solid var(--ui-accent-line);
  font-size: 11px;
  line-height: 1.55;
  color: #6b4332;
}

.person-track-tag {
  font-family: var(--sans-stack);
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

.person-yr-sub {
  font-size: 9.8px;
  color: var(--ui-ink-3);
}

.cr-stop-num {
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
}

.genealogy-list li.person-ev-row.is-current .cr-stop-num {
  background: var(--ui-accent);
  color: #fff8ec;
}

/* --- Challenge card --- */
#challenge-card {
  top: 14px;
  left: 14px;
  width: min(440px, calc(100% - 28px));
  padding: 14px 16px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--ui-shadow-lg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  z-index: 14;
}

.challenge-top {
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11.5px;
}

.mode-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ui-ink-3);
}

.mode-pill.is-active {
  background: var(--ui-accent);
  color: #fff8ec;
}

.pill-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ui-surface-soft);
  border: 1px solid var(--ui-line-soft);
  color: var(--ui-ink-2);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-readout {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ui-ink);
  font-variant-numeric: tabular-nums;
}

.challenge-prompt {
  font-family: var(--serif-stack);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ui-ink);
}

.challenge-prompt b {
  color: var(--ui-accent);
}

.challenge-clue-box {
  margin-top: 10px;
  padding: 8px 11px;
  border-radius: var(--ui-radius-xs);
  border-left: 2.5px solid var(--ui-accent);
  background: var(--ui-surface-soft);
  font-size: 12.4px;
  line-height: 1.6;
}

.clue-tag {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-size: 9.5px;
  letter-spacing: 0.06em;
}

.challenge-feedback {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-line-soft);
  border-top-style: solid;
  gap: 12px;
  font-size: 12.5px;
}

/* --- Journey / route card --- */
#journey-card {
  left: 14px;
  bottom: 14px;
  width: min(560px, calc(100% - 28px));
  padding: 12px 14px;
  gap: 8px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--ui-shadow-lg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  z-index: 13;
}

.jc-top-bar {
  padding-bottom: 8px;
  gap: 8px;
  border-bottom: 1px solid var(--ui-line-soft);
}

.jc-step-badge {
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--ui-accent);
  color: #fff8ec;
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.jc-close-btn {
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  color: var(--ui-ink-2);
  font-size: 11px;
}

.jc-close-btn:hover {
  border-color: var(--ui-accent-line);
  color: var(--ui-accent);
}

.jc-nav-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-ink-2);
}

.jc-nav-btn.is-primary {
  background: var(--ui-accent-soft);
  border-color: var(--ui-accent-line);
  color: var(--ui-accent-ink);
}

.jc-nav-btn.is-primary:hover {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff8ec;
}

.cr-stop-pill {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-ink-2);
}

.cr-stop-pill:hover {
  border-color: var(--ui-accent-line);
  color: var(--ui-accent);
}

.cr-stop-pill.is-current {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff8ec;
}

.cr-stop-pill.is-current .cr-stop-num {
  background: rgba(255, 248, 236, 0.22);
  color: #fff8ec;
}

.cr-stop-num {
  width: 16px;
  height: 16px;
  font-size: 9.5px;
}

.cr-dist-label {
  color: var(--ui-ink-3);
  font-size: 11px;
}

/* --- Milestone balloon --- */
#milestone-balloon {
  max-width: min(340px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius);
  background: rgba(255, 253, 248, 0.97);
  box-shadow: var(--ui-shadow-md);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  font-size: 12px;
  line-height: 1.5;
  z-index: 15;
}

#milestone-balloon::before {
  background: rgba(255, 253, 248, 0.98);
  border-color: var(--ui-line);
}

#milestone-balloon .ep-year {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ui-accent-ink);
  font-variant-numeric: tabular-nums;
}

#milestone-balloon .ep-place {
  padding: 2px 8px;
  border-radius: 999px;
  border-color: var(--ui-accent-line);
  background: var(--ui-accent-soft);
  color: var(--ui-accent-ink);
  font-size: 10.5px;
}

#milestone-balloon .ep-text {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ui-ink);
}

#milestone-balloon .ep-close {
  top: 7px;
  right: 8px;
  width: 20px;
  height: 20px;
  background: transparent;
  color: var(--ui-ink-3);
}

/* -------------------------------------------------------------------------
   11. Timeline dock
   ---------------------------------------------------------------------- */
#scrubber-dock {
  position: relative;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin: var(--ui-gutter);
  padding: 11px 16px 12px;
  border: 1px solid var(--ui-gold-line);
  border-radius: var(--ui-radius-lg);
  background:
    radial-gradient(120% 180% at 50% -60%, rgba(181, 138, 74, 0.14), transparent 60%),
    linear-gradient(180deg, #211a13 0%, #17130f 62%, #13100c 100%);
  color: var(--ui-cream);
  box-shadow: 0 -12px 40px -28px rgba(0, 0, 0, 0.65), var(--ui-shadow-sm);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

#scrubber-dock::before {
  content: '';
  position: absolute;
  left: 14px;
  right: 14px;
  top: 0;
  height: 5px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='6' viewBox='0 0 24 6'%3E%3Cpath d='M1 5.2V1h6.2v3.2h7V1H22' fill='none' stroke='%23b58a4a' stroke-width='.55'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  opacity: 0.3;
  pointer-events: none;
}

#scrubber-dock.is-challenge-locked {
  opacity: 0.6;
}

.playback-controls-group {
  gap: 7px;
}

.round-btn {
  width: 42px;
  height: 42px;
  border: 1px solid #c2543e;
  border-radius: 12px;
  background: var(--ui-accent);
  color: #fff8ec;
  box-shadow:
    0 0 0 1px rgba(214, 132, 108, 0.18),
    0 4px 14px -4px rgba(0, 0, 0, 0.6);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease;
}

.round-btn:hover {
  background: #bd4a34;
  border-color: #d07159;
  color: #fff8ec;
}

.round-btn.is-playing {
  background: var(--ui-accent);
  border-color: #d07159;
  color: #fff8ec;
  box-shadow: 0 4px 16px -4px rgba(166, 62, 44, 0.8);
}

.play-speed-btn {
  min-width: 40px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(245, 235, 216, 0.18);
  background: rgba(245, 235, 216, 0.07);
  color: var(--ui-cream-2);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
}

.play-speed-btn:hover:not(:disabled) {
  border-color: rgba(181, 138, 74, 0.65);
  background: rgba(245, 235, 216, 0.13);
  color: var(--ui-cream);
}

.play-speed-btn.is-custom-speed {
  border-color: rgba(181, 138, 74, 0.6);
  background: rgba(181, 138, 74, 0.16);
  color: var(--ui-cream);
}

#scrubber-rail-wrap {
  padding-top: 26px;
}

#scrubber-Bubble {
  top: 2px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f2e4c9;
  color: #231a11;
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 10px -3px rgba(0, 0, 0, 0.55);
}

#scrubber-Bubble::after {
  border-top-color: #f2e4c9;
  bottom: -3px;
  border-width: 3.5px;
  border-bottom: 0;
}

#scrubber-track {
  height: 30px;
  border-radius: 9px;
  background: #2a2219;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.55);
  transition: box-shadow 0.15s ease;
}

#scrubber-track:hover {
  box-shadow:
    inset 0 1px 4px rgba(0, 0, 0, 0.55),
    0 0 0 3px rgba(181, 138, 74, 0.14);
}

#scrubber-track:focus-visible {
  box-shadow:
    inset 0 1px 4px rgba(0, 0, 0, 0.55),
    0 0 0 3px rgba(181, 138, 74, 0.42);
}

#dynasty-bands {
  border-radius: 9px;
  overflow: hidden;
}

.band-cell {
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 252, 244, 0.92);
  text-shadow: 0 1px 2px rgba(35, 22, 12, 0.45);
  border-right: 1px solid rgba(255, 252, 244, 0.24);
  opacity: 0.82;
  transition: opacity 0.18s ease;
}

.band-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.16) 0%,
    rgba(255, 255, 255, 0) 45%,
    rgba(42, 27, 15, 0.08) 100%
  );
  pointer-events: none;
}

.band-cell:hover,
.band-cell.is-active {
  opacity: 1;
}

.band-cell.is-active {
  box-shadow: inset 0 0 0 1.5px rgba(255, 252, 244, 0.72);
}

.band-cell.is-narrow {
  color: transparent;
  text-shadow: none;
}

.band-label {
  position: relative;
  z-index: 1;
}

.band-phase-tick {
  background: rgba(255, 252, 244, 0.34);
  width: 1px;
}

.band-ev-dot {
  background: rgba(255, 252, 244, 0.6);
  box-shadow: 0 0 0 1px rgba(35, 22, 12, 0.12);
}

#scrubber-handle {
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: #f2e4c9;
  box-shadow: none;
}

#scrubber-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #f2e4c9;
  border: 2.5px solid #17130f;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.65);
}

#scrubber-ticks {
  height: 15px;
  margin-top: 3px;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(245, 235, 216, 0.5);
}

#scrubber-ticks span {
  top: 2px;
  font-variant-numeric: tabular-nums;
}

.year-stepper {
  height: 38px;
  gap: 2px;
  padding: 3px 5px;
  border-radius: var(--ui-radius-sm);
  border: 1px solid rgba(245, 235, 216, 0.16);
  background: rgba(245, 235, 216, 0.06);
  color: var(--ui-cream);
  font-size: 12px;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.year-stepper:focus-within {
  background: rgba(245, 235, 216, 0.12);
  border-color: rgba(181, 138, 74, 0.65);
}

.step-nav-btn {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ui-cream-2);
  font-size: 16px;
  font-weight: 600;
}

.step-nav-btn:hover {
  background: rgba(245, 235, 216, 0.12);
  border-color: transparent;
  color: var(--ui-cream);
}

.year-stepper input {
  width: 58px;
  font-family: var(--sans-stack);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  color: var(--ui-cream);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.year-stepper input::-webkit-outer-spin-button,
.year-stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.year-stepper .unit-label {
  margin-right: 3px;
  font-size: 11px;
  color: var(--ui-ink-3);
}

/* -------------------------------------------------------------------------
   12. Locale typography deltas
   ---------------------------------------------------------------------- */
/* Foreign-language map typography (longer Latin / Cyrillic labels) */
html.is-intl .polity-caption {
  font-size: 13px;
  letter-spacing: 0.04em;
}

html.is-intl .brand-group .subtitle-mark {
  letter-spacing: 0.04em;
}

html.is-intl .dynasty-desc {
  letter-spacing: 0;
}

html.is-intl .polity-caption.rival {
  font-size: 11px;
}

html.is-intl .polity-caption.protectorate,
html.is-intl .polity-caption.neighbor {
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

html.is-intl .region-caption {
  font-size: 7.5px;
  letter-spacing: 0.01em;
}

html.is-intl #act-toggle-pane .tp-label {
  font-family: var(--sans-stack);
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

html.is-intl #dynasty-title {
  font-family: var(--serif-stack);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: normal;
  text-wrap: balance;
}

html.is-intl .genealogy-title {
  font-size: 18px;
}

html.is-intl #milestone-list li {
  grid-template-columns: 84px 1fr;
}

html.is-intl .genealogy-list li {
  grid-template-columns: 76px 1fr;
}

html.is-intl .genealogy-list li.person-ev-row {
  grid-template-columns: 100px 1fr;
}

html.is-intl .band-cell {
  font-size: 9.5px;
  letter-spacing: 0;
}

/* -------------------------------------------------------------------------
   13. Responsive — large desktop
   ---------------------------------------------------------------------- */
@media (min-width: 1600px) {
  :root {
    --ui-pane-w: 400px;
  }

  #chronicle-pane {
    padding: 0 26px 20px;
    gap: 18px;
  }

  .dynasty-banner {
    padding-top: 26px;
  }

  #dynasty-title {
    font-size: 42px;
  }

  #dynasty-title.is-long {
    font-size: 34px;
  }

  .dynasty-desc {
    font-size: 14.6px;
    line-height: 1.9;
  }

  #milestone-list li {
    grid-template-columns: 82px 1fr;
    font-size: 13.2px;
  }

  #genealogy-card {
    width: 400px;
  }
}

/* -------------------------------------------------------------------------
   14. Responsive — tablet & narrow desktop
   ---------------------------------------------------------------------- */
@media (max-width: 1240px) {
  :root {
    --ui-pane-w: 338px;
  }

  #chronicle-pane {
    padding: 0 18px 16px;
  }

  .dynasty-banner {
    padding-top: 18px;
  }

  #dynasty-title {
    font-size: 34px;
  }

  .dynasty-desc {
    font-size: 13.2px;
  }
}

@media (max-width: 1080px) {
  :root {
    --ui-pane-w: 320px;
  }

  #nav-bar {
    padding: 0 10px 0 14px;
  }

  .brand-group .subtitle-mark {
    display: none;
  }

  #start-guide {
    top: 66px;
  }

  #chronicle-pane {
    padding: 0 16px 14px;
  }

  .dynasty-banner {
    padding-top: 16px;
  }

  #map-key {
    max-width: 320px;
  }
}

/* -------------------------------------------------------------------------
   15. Responsive — mobile & tablet portrait (matches the JS 900px pivot)
   ---------------------------------------------------------------------- */
@media (max-width: 900px) {
  :root {
    --ui-nav-h: 54px;
    --ui-gutter: 8px;
  }

  #nav-bar {
    padding: env(safe-area-inset-top, 0px) 10px 0;
    gap: 8px;
  }

  .brand-seal {
    width: 29px;
    height: 29px;
    border-radius: 7px;
  }

  .brand-group .home-link {
    gap: 8px;
  }

  .brand-group .seal-mark {
    font-size: 19px;
  }

  .brand-latin {
    font-size: 6.5px;
    letter-spacing: 0.28em;
  }

  .control-strip {
    gap: 5px;
    overflow: visible;
  }

  .action-btn {
    height: 32px;
    padding: 0 9px;
    font-size: 12px;
    border-radius: 9px;
  }

  .music-pill-group .music-btn,
  .music-pill-group .music-next-btn {
    height: 30px;
  }

  .locale-full {
    display: none;
  }

  .locale-code {
    display: inline;
  }

  .locale-trigger {
    gap: 5px;
    padding: 0 8px;
  }

  .locale-popover {
    left: 8px;
    right: 8px;
    width: auto;
    top: calc(100% + 6px);
    padding: 12px;
  }

  .locale-item {
    min-height: 38px;
    padding: 7px 9px;
    font-size: 12px;
  }

  #workspace-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0;
    padding: var(--ui-gutter) var(--ui-gutter) 0;
  }

  #viewport-frame {
    border-radius: var(--ui-radius-lg);
  }

  #chronicle-pane {
    border-radius: var(--ui-radius-lg);
    border: 1px solid var(--ui-line);
  }

  #gesture-guide {
    display: none;
  }

  /* Search: compact on tablet, full sheet when expanded */
  #map-search-box {
    top: 10px;
    left: 10px;
    width: 210px;
  }

  #map-search-box:focus-within,
  #map-search-box:has(#map-search-results:not(.is-hidden)),
  #map-search-box.is-expanded {
    width: calc(100% - 20px);
  }

  .search-input-wrap {
    height: 38px;
    border-radius: var(--ui-radius-sm);
  }

  /* Legend: compact chip row; expand on demand */
  #map-key {
    left: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
    padding: 8px 10px;
    gap: 6px;
  }

  .key-phase-bar {
    padding-bottom: 0;
    border-bottom: 0;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .key-phase-dots {
    display: none;
  }

  .key-mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    padding: 0 9px;
    margin-left: auto;
    border-radius: 999px;
    border: 1px solid var(--ui-line);
    background: var(--ui-surface);
    color: var(--ui-ink-2);
    font-family: var(--sans-stack);
    font-size: 10.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
  }

  #map-key:not(.is-mobile-expanded) .key-heading,
  #map-key:not(.is-mobile-expanded) .key-note,
  #map-key:not(.is-mobile-expanded) .key-corridors-grid,
  #map-key:not(.is-mobile-expanded) .key-neighbor-entry,
  #map-key:not(.is-mobile-expanded) .key-polities-grid {
    display: none;
  }

  #map-key:not(.is-mobile-expanded) {
    max-width: calc(100% - 76px);
    padding: 6px 8px;
  }

  #map-key.is-mobile-expanded {
    max-height: min(48vh, 320px);
    overflow-y: auto;
    padding: 10px 12px 12px;
    gap: 7px;
  }

  #map-key.is-mobile-expanded .key-heading {
    display: block;
  }

  #map-key.is-mobile-expanded .key-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-br-dock,
  #canvas-br-dock {
    right: 10px;
    bottom: 10px;
    gap: 6px;
  }

  .canvas-reset-btn {
    height: 32px;
    padding: 0 9px;
    font-size: 11px;
  }

  #scale-bar-box {
    display: none;
  }

  #act-toggle-pane {
    display: none;
  }

  /* Bottom-sheet chronicle: overlays the map instead of resizing it, so the
     camera never jumps when the reader opens the chronicle. */
  #workspace-body {
    position: relative;
  }

  #workspace-body.is-mobile-chronicle-open {
    grid-template-rows: minmax(0, 1fr) 0;
  }

  #workspace-body.is-pane-collapsed {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 24;
    height: min(62dvh, 540px);
    margin: 0;
    padding: 0 18px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: var(--ui-radius-lg);
    background: var(--ui-surface);
    box-shadow: 0 -18px 50px -20px rgba(45, 34, 22, 0.45);
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: uiSheetIn 0.26s var(--ui-ease);
  }

  #workspace-body.is-mobile-chronicle-open::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 23;
    background: rgba(28, 24, 19, 0.16);
    pointer-events: none;
    animation: uiScrimIn 0.26s var(--ui-ease);
  }

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

  #workspace-body.is-mobile-chronicle-open #start-guide {
    opacity: 0;
    pointer-events: none;
  }

  @keyframes uiSheetIn {
    from {
      opacity: 0;
      transform: translateY(18px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  /* Collapsed: single compact bar */
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane {
    margin-top: 8px;
    padding: 0 14px;
    min-height: 54px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    border-radius: var(--ui-radius);
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .dynasty-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0;
    border-bottom: 0;
    min-height: 54px;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .dynasty-title-row {
    flex: 1 1 auto;
    min-width: 0;
    align-items: baseline;
    gap: 8px;
    padding: 0;
    border: 0;
    display: flex;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-title {
    font-size: 19px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-span {
    padding: 3px 7px;
    font-size: 10px;
    flex: none;
  }

  html.is-intl #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-span {
    display: none;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .seat-row,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-summary,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .milestone-section,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .polity-backbar,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .polity-extra,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .disclaimer-box {
    display: none;
  }

  .mobile-chronicle-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: none;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--ui-accent-line);
    background: var(--ui-accent-soft);
    color: var(--ui-accent-ink);
    font-family: var(--sans-stack);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  /* Expanded sheet */
  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-banner {
    position: sticky;
    top: 0;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin: 0 -18px;
    padding: 12px 18px 10px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-line);
    cursor: pointer;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-banner::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    width: 34px;
    height: 4px;
    border-radius: 999px;
    background: var(--ui-line-strong);
    transform: translateX(-50%);
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-title-row {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 9px;
    padding: 0;
    border: 0;
    overflow: hidden;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-title {
    font-size: 24px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-span {
    font-size: 10px;
    padding: 3px 7px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .seat-row {
    order: 3;
    flex: 0 0 100%;
    margin-top: 2px;
    font-size: 11.5px;
    gap: 6px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .mobile-chronicle-btn {
    order: 2;
    margin-left: auto;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-summary {
    margin-top: 12px;
    font-size: 13.2px;
    line-height: 1.75;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .milestone-section h3 {
    margin-top: 4px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #milestone-list li {
    grid-template-columns: 70px 1fr;
    font-size: 12px;
  }

  html.is-intl #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-title {
    font-size: 15px;
  }

  html.is-intl #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-title {
    font-size: 19px;
  }

  /* Cards become bottom sheets over the map */
  #genealogy-card {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: min(64%, 460px);
    padding: 12px 14px;
    border-radius: var(--ui-radius-lg);
  }

  #viewport-frame.has-active-person #genealogy-card:not(.is-sheet-expanded) {
    max-height: min(62%, 520px);
  }

  #genealogy-card.is-sheet-expanded {
    top: 8px;
    bottom: 8px;
    max-height: none;
  }

  .gen-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-ink-2);
    font-size: 13px;
  }

  .gen-expand-btn.is-active {
    background: var(--ui-accent);
    border-color: var(--ui-accent);
    color: #fff8ec;
  }

  .genealogy-tag {
    font-size: 9.5px;
  }

  .genealogy-title {
    font-size: 17px;
  }

  .genealogy-sub {
    font-size: 10.5px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .genealogy-list li {
    grid-template-columns: 56px 1fr;
    gap: 8px;
    padding: 7px;
    font-size: 11.8px;
  }

  #challenge-card {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 46%;
    overflow-y: auto;
    padding: 12px 14px;
  }

  #journey-card,
  #journey-card.is-custom-route {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    padding: 10px 12px;
    gap: 6px;
  }

  #viewport-frame.has-active-genealogy #journey-card.is-custom-route {
    top: 8px;
    bottom: auto;
  }

  #start-guide {
    top: 10px;
    right: 10px;
    left: 56px;
    max-width: none;
    padding: 5px 6px 5px 11px;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
  }

  #start-guide::-webkit-scrollbar {
    display: none;
  }

  #start-guide .sg-head {
    display: none;
  }

  #start-guide .sg-item {
    font-size: 12px;
    flex-shrink: 0;
  }

  #start-guide .sg-close {
    margin-left: auto;
    flex-shrink: 0;
  }

  /* Compact timeline */
  #scrubber-dock {
    margin: 8px;
    padding: 8px 10px calc(9px + env(safe-area-inset-bottom, 0px));
    border-radius: var(--ui-radius);
    gap: 8px;
  }

  #scrubber-track {
    height: 28px;
    border-radius: 8px;
  }

  #dynasty-bands {
    border-radius: 8px;
  }

  .band-cell {
    font-size: 10px;
  }

  #scrubber-rail-wrap {
    padding-top: 22px;
  }

  #scrubber-Bubble {
    top: 0;
    font-size: 10.5px;
    padding: 2px 9px;
  }

  #scrubber-ticks {
    height: 13px;
    font-size: 9px;
  }

  .year-stepper {
    height: 34px;
  }
}

/* Narrow desktop (901–1009): stack the welcome chip below the search field
   so the two floating layers never overlap. */
@media (min-width: 901px) and (max-width: 1009px) {
  #start-guide {
    top: 66px;
  }
}

/* Tablet: keep the quick-start chip clear of the search field */
@media (min-width: 641px) and (max-width: 900px) {
  #start-guide {
    left: auto;
    right: 10px;
    max-width: calc(100% - 240px);
  }
}

/* -------------------------------------------------------------------------
   16. Responsive — phone
   ---------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root {
    --ui-nav-h: 52px;
  }

  #nav-bar {
    padding: env(safe-area-inset-top, 0px) 8px 0;
    gap: 6px;
  }

  .brand-group .home-link {
    gap: 7px;
  }

  .brand-seal {
    width: 26px;
    height: 26px;
    border-radius: 6px;
  }

  .brand-group .seal-mark {
    font-size: 17.5px;
    letter-spacing: 0.05em;
  }

  .brand-latin {
    font-size: 6px;
    letter-spacing: 0.24em;
  }

  .control-strip {
    gap: 4px;
  }

  .action-btn {
    height: 34px;
    min-width: 32px;
    padding: 0 8px;
    font-size: 11.5px;
    justify-content: center;
  }

  .action-btn .btn-svg {
    width: 14px;
    height: 14px;
  }

  #lbl-layers-btn,
  .layers-trigger-btn .caret-mark,
  #lbl-music {
    display: none;
  }

  /* The legacy sheet hides this icon on phones; the icon is the button now. */
  #act-layers-menu .btn-svg {
    display: inline-block !important;
  }

  .music-pill-group .music-next-btn {
    padding: 0 7px;
  }

  .music-pill-group .music-btn {
    padding: 0 8px;
  }

  .locale-trigger {
    padding: 0 7px;
    gap: 4px;
  }

  .locale-code {
    font-size: 10px;
    letter-spacing: 0.04em;
  }

  .locale-grid {
    gap: 4px;
  }

  .locale-item {
    min-height: 36px;
    padding: 6px 8px;
    font-size: 11.5px;
  }

  .layers-popover {
    left: 8px !important;
    right: 8px !important;
    width: auto;
    top: calc(100% + 6px);
    padding: 12px;
  }

  .layers-pop-grid {
    gap: 6px;
  }

  .layer-chip {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 12px;
  }

  /* Search collapses to a round button */
  #map-search-box {
    top: 10px;
    left: 10px;
    width: 40px;
  }

  #map-search-box:not(:focus-within):not(.is-expanded):not(:has(#map-search-results:not(.is-hidden))) {
    width: 40px;
    height: 40px;
  }

  #map-search-box:not(:focus-within):not(.is-expanded):not(:has(#map-search-results:not(.is-hidden)))
    .search-input-wrap {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    cursor: pointer;
  }

  #map-search-box:not(:focus-within):not(.is-expanded):not(:has(#map-search-results:not(.is-hidden)))
    #inp-map-search {
    width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }

  #map-search-box:focus-within,
  #map-search-box.is-expanded,
  #map-search-box:has(#map-search-results:not(.is-hidden)) {
    width: calc(100% - 20px);
  }

  #map-search-box .search-input-wrap {
    box-shadow: var(--ui-shadow-md);
  }

  .search-results-list {
    max-height: 52vh;
  }

  .search-results-list li {
    padding: 10px 10px;
  }

  /* Legend sits above the reset button */
  #map-key {
    max-width: calc(100% - 62px);
    padding: 6px 8px;
  }

  #map-key:not(.is-mobile-expanded) {
    max-width: calc(100% - 62px);
    min-height: 34px;
  }

  .key-phase-badge {
    font-size: 10.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .key-mobile-toggle {
    height: 28px;
    padding: 0 9px;
  }

  #canvas-br-dock {
    right: 8px;
    bottom: 8px;
  }

  .canvas-reset-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
  }

  #lbl-reset-camera {
    display: none;
  }

  /* Timeline: 2 rows (controls + full-width track) */
  #scrubber-dock {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 32px auto;
    row-gap: 6px;
    column-gap: 8px;
    margin: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    border-radius: var(--ui-radius);
  }

  .playback-controls-group {
    grid-column: 1;
    grid-row: 1;
    gap: 6px;
  }

  .round-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .round-btn .ico-svg {
    width: 13px;
    height: 13px;
  }

  .play-speed-btn {
    min-width: 36px;
    height: 24px;
    padding: 0 7px;
    font-size: 10.5px;
  }

  .year-stepper {
    grid-column: 3;
    grid-row: 1;
    height: 30px;
    padding: 1px;
    gap: 1px;
    background: transparent;
    border-color: transparent;
  }

  .year-stepper:focus-within {
    background: var(--ui-surface-soft);
    border-color: var(--ui-line);
  }

  .year-stepper input {
    display: block;
    width: 48px;
    font-size: 12px;
    background: transparent;
  }

  .year-stepper .unit-label {
    display: inline;
    margin-right: 1px;
    font-size: 10px;
  }

  .step-nav-btn {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  #scrubber-rail-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    padding-top: 16px;
  }

  #scrubber-track {
    height: 26px;
    border-radius: 8px;
  }

  #dynasty-bands {
    border-radius: 8px;
  }

  .band-cell {
    font-size: 9.5px;
    letter-spacing: 0.02em;
  }

  #scrubber-Bubble {
    top: -6px;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    max-width: calc(100% - 8px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    padding: 1.5px 8px;
  }

  #scrubber-Bubble::after {
    display: none;
  }

  #scrubber-ticks {
    height: 12px;
    font-size: 8.5px;
  }

  #scrubber-handle::after {
    width: 12px;
    height: 12px;
    border-width: 2px;
  }

  /* Compact chronicle bar */
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane {
    min-height: 48px;
    padding: 0 12px;
    margin-top: 6px;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .dynasty-banner {
    min-height: 48px;
    gap: 6px;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-title {
    font-size: 17px;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-span {
    font-size: 9.5px;
    padding: 2px 6px;
  }

  .mobile-chronicle-btn {
    height: 33px;
    padding: 0 11px;
    font-size: 10.5px;
  }

  #workspace-body.is-mobile-chronicle-open {
    grid-template-rows: minmax(0, 1fr) 0;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane {
    left: 6px;
    right: 6px;
    bottom: 6px;
    height: min(64dvh, 560px);
    margin: 0;
    padding: 0 14px calc(12px + env(safe-area-inset-bottom, 0px));
    border-radius: var(--ui-radius);
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-banner {
    margin: 0 -14px;
    padding: 14px 14px 10px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-title {
    font-size: 21px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-summary {
    font-size: 12.8px;
    line-height: 1.7;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #milestone-list li {
    grid-template-columns: 64px 1fr;
    gap: 8px;
    padding: 7px;
    font-size: 11.5px;
  }

  #milestone-list {
    margin: 0 -6px;
  }

  /* Cards: full-width bottom sheets */
  #genealogy-card {
    left: 6px;
    right: 6px;
    bottom: 6px;
    max-height: min(70%, 480px);
    padding: 11px 12px;
  }

  #viewport-frame.has-active-person #genealogy-card:not(.is-sheet-expanded) {
    max-height: min(68%, 520px);
  }

  #genealogy-card.is-sheet-expanded {
    top: 6px;
    bottom: 6px;
  }

  .genealogy-title {
    font-size: 16px;
  }

  .genealogy-list li {
    grid-template-columns: 52px 1fr;
    font-size: 11.5px;
  }

  .genealogy-list li.person-ev-row {
    grid-template-columns: 72px 1fr;
  }

  .cr-stops-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-right: 10px;
  }

  .cr-stops-list::-webkit-scrollbar {
    display: none;
  }

  #journey-card,
  #journey-card.is-custom-route {
    left: 6px;
    right: 6px;
    bottom: 6px;
    padding: 9px 11px;
  }

  #challenge-card {
    top: 6px;
    left: 6px;
    right: 6px;
    padding: 11px 12px;
  }

  .challenge-prompt {
    font-size: 14px;
    line-height: 1.5;
  }

  .challenge-clue-box {
    padding: 6px 9px;
    font-size: 11.5px;
    max-height: 4.6em;
    overflow-y: auto;
  }

  #start-guide {
    top: 10px;
    left: 56px;
    right: 8px;
    padding: 6px 7px 6px 9px;
    flex-wrap: wrap;
    white-space: normal;
    background: rgba(166, 62, 44, 0.07);
    border-color: var(--ui-accent-line);
  }

  #start-guide .sg-item {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid var(--ui-accent-line);
    background: rgba(255, 253, 248, 0.72);
    line-height: 1.5;
  }

  #start-guide .sg-sep {
    display: none;
  }

  #start-guide .sg-sep {
    margin: 0 1px;
  }

  .dynasty-desc {
    font-size: 13px;
  }

  #milestone-balloon {
    max-width: calc(100vw - 20px);
    padding: 9px 11px;
  }
}

/* -------------------------------------------------------------------------
   17. Responsive — very small phones
   ---------------------------------------------------------------------- */
@media (max-width: 380px) {
  .brand-seal {
    width: 24px;
    height: 24px;
    border-radius: 5px;
  }

  .brand-group .seal-mark {
    font-size: 16px;
  }

  .brand-latin {
    display: none;
  }

  .action-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
  }

  .locale-trigger {
    padding: 0 6px;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .mobile-chronicle-btn {
    padding: 0 8px;
    font-size: 10px;
  }

  .year-stepper input {
    width: 42px;
  }

  #start-guide {
    padding-left: 8px;
    gap: 6px;
  }

  #start-guide .sg-item {
    font-size: 10.5px;
  }

  #start-guide .sg-sep {
    display: none;
  }
}

/* Long translated era names: keep the sticky header compact on narrow panes. */
@media (max-width: 1200px) {
  #dynasty-title.is-long {
    font-size: 24px;
  }
}

@media (max-width: 1080px) {
  #dynasty-title.is-long {
    font-size: 20px;
    line-height: 1.08;
  }

  html.is-intl #chronicle-pane .span-label {
    display: none;
  }
}

/* -------------------------------------------------------------------------
   18. Short viewports (landscape phones, small laptops)
   ---------------------------------------------------------------------- */
@media (max-height: 640px) and (min-width: 901px) {
  :root {
    --ui-nav-h: 48px;
  }

  #chronicle-pane {
    padding: 14px 16px 12px;
    gap: 10px;
  }

  #dynasty-title {
    font-size: 30px;
  }

  .dynasty-desc {
    font-size: 12.5px;
    line-height: 1.65;
  }

  #scrubber-dock {
    padding: 8px 14px;
    margin: 8px;
  }

  #scrubber-track {
    height: 26px;
  }

  #scrubber-rail-wrap {
    padding-top: 22px;
  }
}

@media (max-height: 560px) and (max-width: 900px) {
  .brand-group .seal-mark {
    font-size: 16px;
  }

  #start-guide {
    display: none;
  }
}

/* Landscape phones: compact chrome, side sheet, no wasted vertical space */
@media (max-height: 540px) and (min-width: 561px) and (max-width: 900px) {
  #workspace-body {
    grid-template-rows: minmax(0, 1fr) 0;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane {
    display: none;
  }

  #act-toggle-pane {
    display: flex !important;
    z-index: 16;
  }

  #viewport-frame.has-active-genealogy #act-toggle-pane,
  #viewport-frame.has-active-journey #act-toggle-pane,
  #viewport-frame.has-active-person #act-toggle-pane,
  #viewport-frame.has-active-challenge #act-toggle-pane {
    display: none !important;
  }

  #scrubber-dock {
    padding: 6px 12px 8px;
  }

  #scrubber-rail-wrap {
    padding-top: 0;
  }

  #scrubber-Bubble {
    display: none;
  }

  #scrubber-ticks {
    height: 13px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane {
    left: auto;
    top: 8px;
    right: 8px;
    bottom: 8px;
    width: min(440px, 54%);
    height: auto;
    border-radius: var(--ui-radius-lg);
  }

  #workspace-body.is-mobile-chronicle-open::before {
    display: none;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-banner {
    margin: 0 -14px;
    padding: 12px 14px 8px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-title {
    font-size: 20px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-summary {
    font-size: 12.6px;
    line-height: 1.7;
  }
}

@media (max-height: 540px) and (max-width: 560px) {
  #workspace-body.is-mobile-chronicle-open #chronicle-pane {
    left: 6px;
    right: 6px;
    top: 6px;
    bottom: 6px;
    height: auto;
    border-radius: var(--ui-radius-lg);
  }
}

/* -------------------------------------------------------------------------
   19. Motion & accessibility
   ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Hover effects only where hover exists */
@media (hover: none) {
  .action-btn.subtle:hover,
  .canvas-reset-btn:hover,
  .round-btn:hover,
  .genealogy-list li:hover,
  #milestone-list li:hover {
    transform: none;
  }

  /* Comfortable touch targets for overlay controls */
  .icon-close {
    width: 34px;
    height: 34px;
  }

  .phase-dot {
    width: 9px;
    height: 9px;
  }
}

