/* NZ theme overrides (Phase 8).
 * Loaded only by nz.html, after css/style.css, so the China app is untouched.
 * A restrained Aotearoa palette (warm paper, bush green, sea teal) and
 * Western-friendly fonts; hides China-only controls.
 */
:root {
  --bg-parchment: #efece1;
  --water-fill: #cddcd6;
  --province-fill: #e7e4d4;
  --ocean-fill: #efece1;
  --text-main: #23302a;
  --text-secondary: #4f5d55;
  --text-muted: #8a9088;
  --vermilion: #a6402f;
  --amber-gold: #b8863b;
  --hairline: rgba(35, 48, 42, 0.12);
  --surface-nav: rgba(243, 238, 228, 0.92);
  --surface-popover: rgba(251, 248, 241, 0.98);
  --surface-panel: rgba(250, 246, 237, 0.97);
  --surface-soft: rgba(243, 238, 228, 0.85);
  --surface-bright: rgba(255, 252, 245, 0.72);
  --surface-input: rgba(255, 255, 255, 0.85);
  --surface-chip: rgba(255, 255, 255, 0.7);
  --surface-hover: #ffffff;
  --overlay-backdrop: rgba(28, 22, 17, 0.5);
  --serif-stack: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --sans-stack: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --calligraphy-stack: var(--serif-stack);
}

/* The brand seal now shows Latin letters ("NZ"). */
.seal-mark {
  font-family: var(--serif-stack) !important;
  letter-spacing: 0.02em;
}

/* China-only controls hidden in the NZ build (guqin music is not on-theme). */
.music-pill-group {
  display: none !important;
}

/* Slightly cooler ocean backdrop. */
#ocean-bg {
  fill: var(--ocean-fill);
}

/* NZ ships English (+ te reo later): hide the Chinese locales in the picker. */
.locale-pop-item[data-locale="zh"],
.locale-pop-item[data-locale="zh-tw"] {
  display: none !important;
}

/* China-only 'more' links (Chinese blog posts). */
#lnk-more-story,
#lnk-more-about {
  display: none !important;
}

/* Layers with no NZ data yet (prefecture mesh / silk-road corridors). */
label.layer-chip:has(#chk-prefectures),
label.layer-chip:has(#chk-corridors) {
  display: none !important;
}
/* Dashed route between sequential person/storyline stops (added by nz_search.js). */
.nz-route {
  fill: none;
  stroke: var(--vermilion);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: 0.85;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* Numbered pins for the active NZ chronicle (added by nz_search.js). */
.nz-ppin { fill: #fff; stroke: var(--vermilion); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.nz-pnum { font-family: var(--serif-stack, Georgia, serif); font-size: 9px; fill: var(--vermilion);
  text-anchor: middle; dominant-baseline: central; pointer-events: none; }

/* Per-stop Wikipedia link appended in the person card. */
.nz-stop-wiki { color: var(--vermilion); text-decoration: none; font-size: 11px; }
.nz-stop-wiki:hover { text-decoration: underline; }

/* Place-name labels next to chronicle pins. */
.nz-plabel {
  font-family: var(--serif-stack, Georgia, serif);
  fill: #3a332b;
  paint-order: stroke;
  stroke: #efece1;
  stroke-width: 2px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

/* Prominent Wikipedia link in the genealogy/person card header. */
.nz-card-wiki {
  color: var(--vermilion);
  font-size: 0.5em;
  font-weight: 400;
  margin-left: 8px;
  text-decoration: none;
  vertical-align: middle;
}
.nz-card-wiki:hover { text-decoration: underline; }

/* The whole pin + label is a link to the stop's Wikipedia article. */
.nz-plink { cursor: pointer; }
.nz-plink:hover .nz-ppin { fill: var(--vermilion); }
.nz-plink:hover .nz-pnum { fill: #fff; }

/* Enriched milestone/event callout. */
.nz-ep-extra { margin-top: 8px; border-top: 1px solid var(--hairline); padding-top: 7px; }
.nz-ep-extract { font-size: 12px; line-height: 1.45; color: var(--text-secondary); margin-bottom: 6px; }
.nz-ep-src { color: var(--text-muted); font-size: 10px; white-space: nowrap; }
.nz-ep-wiki { font-size: 12px; color: var(--vermilion); text-decoration: none; }
.nz-ep-wiki:hover { text-decoration: underline; }

/* Short biography under the person name in the card. */
.nz-card-bio {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0 0 10px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--hairline);
}

/* ---------------- Theme picker ---------------- */
.theme-trigger-btn .theme-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--vermilion);
  border: 1.5px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 0 0 1px var(--hairline);
  flex-shrink: 0;
}

.theme-trigger-btn.is-active {
  background: var(--surface-hover) !important;
  color: var(--vermilion) !important;
  border-color: rgba(181, 69, 47, 0.35) !important;
  font-weight: 600;
}

.theme-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 12px;
  width: 216px;
  background: var(--surface-popover);
  border: 1px solid rgba(181, 69, 47, 0.32);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(43, 38, 34, 0.18);
  padding: 5px;
  z-index: 50;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-pop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.theme-pop-item:hover {
  background: rgba(181, 69, 47, 0.09);
  color: var(--vermilion);
}

.theme-pop-item.is-selected {
  background: rgba(181, 69, 47, 0.07);
  color: var(--vermilion);
  font-weight: 700;
}

.theme-pop-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(43, 38, 34, 0.25);
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
}

.theme-pop-name {
  flex: 1 1 auto;
}

.theme-pop-check {
  font-size: 12px;
  font-weight: 700;
  color: var(--vermilion);
  opacity: 0;
}

.theme-pop-item.is-selected .theme-pop-check {
  opacity: 1;
}

/* ---------------- Theme palettes ---------------- */
:root[data-theme="slate"] {
  --bg-parchment: #e8ebef;
  --water-fill: #cfd8e0;
  --province-fill: #e2e6ea;
  --ocean-fill: #e8ebef;
  --text-main: #232a33;
  --text-secondary: #4c5560;
  --text-muted: #828b96;
  --vermilion: #3f6fae;
  --amber-gold: #b08a3e;
  --hairline: rgba(35, 42, 51, 0.12);
  --card-shadow: 0 10px 30px rgba(35, 42, 51, 0.14), 0 1px 2px rgba(35, 42, 51, 0.08);
  --surface-nav: rgba(232, 235, 239, 0.92);
  --surface-popover: rgba(248, 250, 252, 0.98);
  --surface-panel: rgba(242, 245, 248, 0.97);
  --surface-soft: rgba(232, 235, 239, 0.85);
  --surface-bright: rgba(255, 255, 255, 0.7);
  --surface-input: rgba(255, 255, 255, 0.85);
  --surface-chip: rgba(255, 255, 255, 0.7);
  --surface-hover: #ffffff;
  --app-bg: radial-gradient(1200px 600px at 20% -10%, rgba(255, 255, 255, 0.9), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(207, 216, 224, 0.6), transparent 60%),
    var(--bg-parchment);
}

:root[data-theme="sage"] {
  --bg-parchment: #e9ede3;
  --water-fill: #cbd8cf;
  --province-fill: #e1e7d9;
  --ocean-fill: #e9ede3;
  --text-main: #253026;
  --text-secondary: #4e5b4d;
  --text-muted: #86907f;
  --vermilion: #5f7d3f;
  --amber-gold: #b8863b;
  --hairline: rgba(37, 48, 38, 0.12);
  --card-shadow: 0 10px 30px rgba(37, 48, 38, 0.14), 0 1px 2px rgba(37, 48, 38, 0.08);
  --surface-nav: rgba(233, 237, 227, 0.92);
  --surface-popover: rgba(248, 251, 246, 0.98);
  --surface-panel: rgba(242, 246, 238, 0.97);
  --surface-soft: rgba(233, 237, 227, 0.85);
  --surface-bright: rgba(255, 255, 250, 0.7);
  --surface-input: rgba(255, 255, 255, 0.85);
  --surface-chip: rgba(255, 255, 255, 0.7);
  --surface-hover: #ffffff;
  --app-bg: radial-gradient(1200px 600px at 20% -10%, rgba(255, 255, 250, 0.9), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(203, 216, 207, 0.6), transparent 60%),
    var(--bg-parchment);
}

:root[data-theme="sepia"] {
  --bg-parchment: #efe4cf;
  --water-fill: #d8cbb2;
  --province-fill: #ecdfc6;
  --ocean-fill: #efe4cf;
  --text-main: #3a2f22;
  --text-secondary: #665847;
  --text-muted: #94836c;
  --vermilion: #9c4a2f;
  --amber-gold: #b07d2c;
  --hairline: rgba(58, 47, 34, 0.14);
  --card-shadow: 0 10px 30px rgba(58, 47, 34, 0.16), 0 1px 2px rgba(58, 47, 34, 0.08);
  --surface-nav: rgba(239, 228, 207, 0.92);
  --surface-popover: rgba(253, 248, 239, 0.98);
  --surface-panel: rgba(249, 242, 229, 0.97);
  --surface-soft: rgba(239, 228, 207, 0.85);
  --surface-bright: rgba(255, 250, 238, 0.72);
  --surface-input: rgba(255, 255, 255, 0.82);
  --surface-chip: rgba(255, 255, 255, 0.68);
  --surface-hover: #fffaf0;
  --app-bg: radial-gradient(1200px 600px at 20% -10%, rgba(255, 250, 238, 0.9), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(216, 203, 178, 0.6), transparent 60%),
    var(--bg-parchment);
}

/* Night = dark chrome around a paper-lit atlas page, so map labels stay legible. */
:root[data-theme="night"] {
  --bg-parchment: #14171c;
  --ocean-fill: #e7e2d6;
  --text-main: #e9e3d7;
  --text-secondary: #bdb5a7;
  --text-muted: #8c8578;
  --vermilion: #e0795f;
  --amber-gold: #d3a55c;
  --hairline: rgba(233, 227, 215, 0.14);
  --card-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), 0 1px 2px rgba(0, 0, 0, 0.35);
  --surface-nav: rgba(24, 28, 34, 0.92);
  --surface-popover: rgba(30, 35, 42, 0.98);
  --surface-panel: rgba(27, 32, 38, 0.97);
  --surface-soft: rgba(27, 32, 38, 0.88);
  --surface-bright: rgba(255, 255, 255, 0.06);
  --surface-input: rgba(255, 255, 255, 0.08);
  --surface-chip: rgba(255, 255, 255, 0.07);
  --surface-hover: rgba(255, 255, 255, 0.12);
  --overlay-backdrop: rgba(0, 0, 0, 0.62);
  --app-bg: radial-gradient(1200px 600px at 20% -10%, rgba(70, 84, 102, 0.45), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(20, 42, 46, 0.55), transparent 60%),
    var(--bg-parchment);
}

:root[data-theme="night"] #chronicle-pane {
  background: linear-gradient(180deg, rgba(30, 35, 42, 0.85), rgba(20, 23, 28, 0.85));
}

:root[data-theme="night"] .theme-pop-swatch,
:root[data-theme="night"] .theme-trigger-btn .theme-dot {
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}

@media (max-width: 640px) {
  .theme-trigger-btn .theme-label {
    display: none;
  }
  .theme-popover {
    width: min(216px, calc(100vw - 24px));
  }
}

/* Compact theme picker used on the static support pages (terms/contact/license). */
.theme-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
}

.theme-pick-label {
  font-size: 12px;
  color: var(--muted, var(--text-muted));
}

.theme-pick select {
  font: inherit;
  font-size: 12.5px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line, var(--hairline));
  background: var(--surface-input);
  color: var(--ink, var(--text-main));
  cursor: pointer;
}

.theme-pick select:focus-visible {
  outline: 2px solid var(--accent, var(--vermilion));
  outline-offset: 2px;
}

/* Labels that only appear in the phone bottom action bar. */
.mab-label {
  display: none;
}

/* ---------------- Phone refinement: bottom action bar + larger tap targets ---------------- */
@media (max-width: 640px) {
  :root {
    --mab-h: 56px;
  }

  /* The toolbar moves to the screen bottom; drop the nav blur so fixed
     positioning resolves against the viewport, not the nav box. */
  #nav-bar {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  #atlas-shell {
    padding-bottom: calc(var(--mab-h) + env(safe-area-inset-bottom, 0px));
  }

  #nav-bar .control-strip {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: calc(var(--mab-h) + env(safe-area-inset-bottom, 0px));
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    gap: 2px;
    justify-content: space-between;
    align-items: stretch;
    background: var(--surface-nav);
    border-top: 1px solid var(--hairline);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: visible;
  }

  #nav-bar .control-strip .toolbar-divider {
    display: none !important;
  }

  #nav-bar .control-strip .action-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    flex-direction: column;
    gap: 2px;
    padding: 5px 2px;
    border-radius: 10px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.1;
  }

  #nav-bar .control-strip .action-btn:active {
    background: var(--surface-chip);
  }

  #nav-bar .control-strip .action-btn .btn-svg {
    width: 20px;
    height: 20px;
  }

  #act-challenge .btn-svg,
  #act-layers-menu .btn-svg {
    display: inline-flex !important;
  }

  .challenge-trigger-btn .chal-short,
  .theme-trigger-btn .theme-label,
  .mab-label {
    display: inline !important;
  }

  .theme-trigger-btn .theme-dot {
    width: 18px;
    height: 18px;
    box-shadow: none;
  }

  .more-menu-btn .more-dots-mark {
    font-size: 18px;
    line-height: 1;
  }

  .locale-menu-btn .btn-svg {
    width: 18px;
    height: 18px;
  }

  /* Menus become sheets directly above the bar. */
  #layers-popover,
  #locale-popover,
  #more-popover,
  #theme-popover {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(var(--mab-h) + env(safe-area-inset-bottom, 0px) + 8px);
    width: auto;
    max-width: none;
    max-height: min(60dvh, 420px);
    overflow-y: auto;
    z-index: 61;
  }

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

  .layer-chip {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .locale-pop-item,
  .more-pop-link,
  .theme-pop-item {
    min-height: 44px;
  }

  /* Scrubber: bigger controls; the bar now owns the safe-area. */
  #scrubber-dock {
    gap: 8px;
    padding-bottom: 8px;
  }

  .round-btn {
    width: 40px;
    height: 40px;
  }

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

  .play-speed-btn {
    min-width: 40px;
    height: 32px;
    font-size: 12px;
  }

  .step-nav-btn {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  #scrubber-track {
    height: 34px;
  }

  .mobile-chronicle-btn {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 13px;
  }

  .canvas-reset-btn {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 12px;
  }

  .icon-close {
    min-width: 34px;
    min-height: 34px;
  }

  .search-clear-btn {
    width: 30px;
    height: 30px;
  }

  /* Keep the legend clear of the reset/scale dock on narrow screens. */
  #map-key {
    max-width: calc(100% - 136px);
  }

  /* Free the screen while searching. */
  #atlas-shell.is-mobile-search-open .control-strip {
    display: none;
  }
}

/* Support pages (terms/contact/licence): keep the header from overflowing. */
@media (max-width: 640px) {
  .wrap > header {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .wrap > header .back {
    margin-left: 0;
  }
  .theme-pick {
    margin-left: auto;
  }
  .theme-pick select {
    min-height: 40px;
    max-width: 52vw;
  }
}

/* The event callout (milestone balloon) is suppressed at <=900px in style.css, so
   the map only shows pins. Re-enable it on phones/tablets, except when a
   conflicting overlay owns the screen. */
@media (max-width: 900px) {
  #milestone-balloon {
    display: block !important;
  }

  #milestone-balloon.is-hidden {
    display: none !important;
  }

  #viewport-frame.has-active-journey #milestone-balloon,
  #viewport-frame.has-active-challenge #milestone-balloon,
  #viewport-frame.has-active-genealogy #milestone-balloon,
  #workspace-body.is-mobile-chronicle-open #milestone-balloon,
  #atlas-shell.is-mobile-search-open #milestone-balloon {
    display: none !important;
  }

  #milestone-balloon .ep-close {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
}

