/* Shared theme for the map/ pages: the fonts and the light/dark palette of sai-series1.html
   (light = series1-news.css paper palette, dark = sai-3d.css dark tokens). theme.js sets data-theme
   from localStorage 'sai3d-theme' before first paint. Pages map their own variables onto these. */
:root {
  --f-head: "Kanit", "IBM Plex Sans Thai", system-ui, sans-serif;
  --f-th: "IBM Plex Sans Thai", system-ui, sans-serif;
  --f-en: "Oswald", "Arial Narrow", sans-serif;
}
:root:not([data-theme="dark"]) {
  --bg: #f6f7f3; --bg2: #eceee6; --surface: #f6f7f3; --surface2: #eceee6;
  --panel: rgba(250, 251, 247, 0.95); --map-bg: #e5e8de;
  --ink: #151515; --ink2: #2e2e2e; --muted: #5e5e5e;
  --line: rgba(21, 21, 21, .2); --line2: rgba(21, 21, 21, .1);
  --accent: #1d4f91; --accent-soft: rgba(29, 79, 145, .07); --on-accent: #f6f7f3;
  --cyan: #1d4f91; --hot: #c1121f; --red: #c1121f;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0c29; --bg2: #12143a; --surface: #101238; --surface2: #151845;
  --panel: rgba(12, 13, 42, 0.94); --map-bg: #0b0c29;
  --ink: #f4eee3; --ink2: #dcd6ea; --muted: #b5b1ce;
  --line: rgba(220, 214, 255, .18); --line2: rgba(220, 214, 255, .09);
  --accent: #f29a3f; --accent-soft: rgba(242, 154, 63, .15); --on-accent: #1d0e02;
  --cyan: #f29a3f; --hot: #ff6b57; --red: #ff6b57;
  color-scheme: dark;
}

/* toggle button injected by theme.js on pages without their own #theme-btn (same look as the reference's) */
.site-theme-btn {
  position: fixed; right: 16px; bottom: 16px; z-index: 1000;
  display: grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: #161845; color: #ffd86b; box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
:root[data-theme="dark"] .site-theme-btn { background: #f1edd5; color: #1b1c45; box-shadow: 0 0 16px rgba(241, 237, 213, .3); }
.site-theme-btn svg { width: 18px; height: 18px; }
.site-theme-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* text that pages colour inline (popups, panels) is tuned for a light surface: lift it on dark surfaces, hue kept */
:root[data-theme="dark"] .maplibregl-popup-content [style*="color"]:not([style*="color:#fff"]),
:root[data-theme="dark"] #panel [style*="color"]:not([style*="color:#fff"]),
:root[data-theme="dark"] #detail-html [style*="color"]:not([style*="color:#fff"]) { filter: brightness(1.7); }

/* MapLibre chrome */
:root .maplibregl-popup-content { background: var(--surface); color: var(--ink); }
:root .maplibregl-popup-anchor-top .maplibregl-popup-tip, :root .maplibregl-popup-anchor-top-left .maplibregl-popup-tip, :root .maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--surface); }
:root .maplibregl-popup-anchor-bottom .maplibregl-popup-tip, :root .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip, :root .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--surface); }
:root .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface); }
:root .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface); }
:root .maplibregl-popup-close-button { color: var(--muted); }
:root[data-theme="dark"] .maplibregl-ctrl-group { background: var(--surface); }
:root[data-theme="dark"] .maplibregl-ctrl-group button + button { border-top-color: var(--line); }
:root[data-theme="dark"] .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1); }
:root[data-theme="dark"] .maplibregl-ctrl-attrib, :root[data-theme="dark"] .maplibregl-ctrl-scale { background: rgba(11, 12, 41, .75); color: var(--ink2); }
:root[data-theme="dark"] .maplibregl-ctrl-attrib a { color: var(--ink2); }

/* Leaflet chrome */
:root .leaflet-container { font-family: var(--f-head); }
:root[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-attribution { background: rgba(11, 12, 41, .75); color: var(--ink2); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--ink2); }

/* sai-3d.html analysis tables: same fix as series1-news.css (the source grey #a39a8c is 2.8:1 on paper) */
:root .nx td .cell-na, :root .nx .cell-na { color: var(--muted); }

/* theme switch: the reference's sunrise / sunset View Transition (theme.js adds vt-sunrise / vt-sunset) */
@property --sun { syntax: "<length>"; inherits: false; initial-value: 0px; }
:root.vt-sunrise::view-transition-old(root), :root.vt-sunrise::view-transition-new(root),
:root.vt-sunset::view-transition-old(root), :root.vt-sunset::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
:root.vt-sunrise::view-transition-new(root), :root.vt-sunset::view-transition-old(root) {
  -webkit-mask-image: radial-gradient(circle at 50% 118%, #000 calc(var(--sun) - 14vmax), transparent var(--sun));
  mask-image: radial-gradient(circle at 50% 118%, #000 calc(var(--sun) - 14vmax), transparent var(--sun));
}
:root.vt-sunrise::view-transition-new(root) { animation: vt-sunrise 0.9s ease-in-out both; }
:root.vt-sunset::view-transition-old(root) { z-index: 2; animation: vt-sunset 0.9s ease-in-out both; }
@keyframes vt-sunrise {
  0% { --sun: 6vmax; filter: sepia(0.85) saturate(1.9) hue-rotate(-18deg) brightness(0.75); }
  45% { filter: sepia(0.4) saturate(1.4) hue-rotate(-8deg) brightness(0.92); }
  100% { --sun: 140vmax; filter: none; }
}
@keyframes vt-sunset {
  0% { --sun: 140vmax; filter: none; }
  55% { filter: sepia(0.5) saturate(1.5) hue-rotate(-10deg) brightness(0.85); }
  100% { --sun: 6vmax; filter: sepia(0.85) saturate(1.9) hue-rotate(-18deg) brightness(0.65); }
}

/* entrance: the reference's moPop fade plus the chart fade-up rise; pages list their panels under
   @media (prefers-reduced-motion: no-preference) { ... { animation: moEnter .5s ease-out var(--mo-d,0s) both } }.
   A CSS animation always runs, so nothing can stay hidden; `translate` moves paint only (no layout shift). */
@keyframes moEnter { from { opacity: 0; translate: 0 14px; } to { opacity: 1; translate: none; } }
