/* Prototype chrome. Colors come from the active theme via CSS variables (set by app.js). */
:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --fg: #16181d;
  --muted: #5b616b;
  --accent: #0b6bcb;
  --surface: rgba(255, 255, 255, 0.92);
  --border: #e3e5e8;
  --radius: 12px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; height: 100dvh; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  overflow: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

#map { position: fixed; inset: 0; z-index: 0; }

.top {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}
.search input {
  width: 100%;
  padding: 12px 16px;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.08);
  outline: none;
}
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.1);
}
.search-results li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--border); }
.search-results .kind { color: var(--muted); font-size: 12px; margin-left: 6px; }

.filters { position: relative; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip, .menu > button {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
}
.menu > button { font: inherit; font-size: 13px; color: var(--fg); cursor: pointer; }
.menu > button::after { content: " ▾"; color: var(--muted); }
.menu > button[aria-expanded="true"] { border-color: var(--accent); }
.chip.is-on { color: var(--accent); border-color: var(--accent); }
.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 3;
  width: min(280px, calc(100vw - 88px));
  max-height: 60vh;
  max-height: 60dvh;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
.menu-panel[hidden] { display: none; }
.menu-panel .actions { display: flex; gap: 6px; padding: 4px 6px 6px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
.menu-panel .actions button {
  flex: 1; padding: 5px 10px; font: inherit; font-size: 13px; color: var(--fg);
  background: transparent; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.menu-panel .actions button:hover { background: var(--border); }
.menu-panel .actions button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.menu-panel .row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.menu-panel .row:hover { background: var(--border); }
.menu-panel input[type="checkbox"], .menu-panel input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); }
.menu-panel .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.menu-panel .name { flex: 1; }
.menu-panel .num { color: var(--muted); font-size: 12px; }
.menu-panel .block { display: flex; align-items: center; gap: 8px; padding: 8px 10px 4px; font-size: 14px; cursor: pointer; }
.menu-panel input[type="number"], .menu-panel input[type="date"] {
  font: inherit; font-size: 14px; color: var(--fg); background: transparent;
  border: 1px solid var(--border); border-radius: 8px; padding: 3px 6px;
}
.menu-panel input[type="number"] { width: 56px; }
.menu-panel .quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 10px 10px 36px; }
.menu-panel .quick button {
  font: inherit; font-size: 12px; color: var(--fg); background: transparent;
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; cursor: pointer;
}
.menu-panel .quick button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.menu-panel .range { display: grid; gap: 6px; padding: 2px 10px 8px 36px; font-size: 14px; }
.menu-panel .range label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-panel .note { margin: 4px 10px 8px; font-size: 12px; color: var(--muted); }
.menu button:focus-visible, .menu-panel input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings button:focus-visible, .settings select:focus-visible, .settings input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.settings {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 4;
  font-size: 13px;
}
.settings > button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.settings-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 260px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
.settings-panel[hidden] { display: none; }
.settings-panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}
.settings-panel .row + .row { border-top: 1px solid var(--border); }
.settings-panel select { font: inherit; color: var(--fg); background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 2px 6px; }
.settings-panel input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.toggle button { font: inherit; color: var(--fg); background: transparent; border: 0; padding: 4px 12px; cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
.settings-panel input:disabled + * , .settings-panel .row:has(input:disabled) { opacity: 0.5; }

.popup {
  position: fixed;
  z-index: 3;
  width: min(340px, calc(100vw - 24px));
  max-height: 60vh;
  overflow-y: auto;
  padding: 16px;
  background: var(--popup-bg, #fff);
  color: var(--popup-fg, #16181d);
  border: 1px solid var(--popup-border, #e3e5e8);
  border-radius: var(--popup-radius, 14px);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
.popup[hidden] { display: none; }
.lore { top: 64px; right: 12px; left: auto; }
.lore .why-title { margin: 14px 0 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.lore p { margin: 4px 0; }
.lore .note { margin-top: 12px; font-size: 12px; color: var(--muted); }
.popup h2 { margin: 6px 0 4px; font-size: 17px; line-height: 1.35; }
.popup .meta { color: var(--muted); font-size: 13px; margin: 2px 0; }
.popup .source {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--popup-border, #e3e5e8);
  font-size: 12px;
  color: var(--muted);
}
.popup .source a { color: var(--accent); }
.popup .verify { margin: 8px 0 0; font-size: 12px; font-style: italic; color: var(--muted); }
.popup .close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted);
}
.popup .tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--tag-bg, #eef3f8); color: var(--tag-fg, #16181d);
}
.popup .group { margin: 8px 0; }
.popup .stack { display: grid; gap: 2px; max-height: 50vh; max-height: min(50dvh, calc(100dvh - 190px)); overflow-y: auto; margin-top: 8px; }
.popup .stack-item {
  display: grid; grid-template-columns: 10px 1fr; gap: 2px 10px; align-items: baseline;
  width: 100%; padding: 8px; font: inherit; font-size: 14px; color: inherit; text-align: left;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.popup .stack-item:hover { background: var(--border); }
.popup .stack-item .dot { width: 10px; height: 10px; border-radius: 50%; }
.popup .stack-item .when { grid-column: 2; color: var(--muted); font-size: 12px; }
.popup .back { font: inherit; font-size: 13px; color: var(--accent); background: none; border: 0; padding: 0; margin-bottom: 6px; cursor: pointer; }
.popup .group summary { cursor: pointer; }

.data-error {
  position: fixed;
  left: 16px;
  bottom: 48px;
  z-index: 4;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--fg);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: var(--grain-image);
  background-size: 128px 128px;
  opacity: var(--grain-opacity, 0);
  mix-blend-mode: var(--grain-blend, multiply);
}

/* Quick filters, saved events, the list of events in view, and the popup's action buttons. */
.chips { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips > button, .chips .menu > button {
  padding: 4px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chips > button[aria-pressed="true"], .chips > button[aria-expanded="true"], .chips .menu > button[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.chips button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips > button[aria-busy="true"] { opacity: 0.6; }

.saved-row { display: flex; align-items: center; gap: 4px; }
.saved-row .open {
  flex: 1; display: grid; gap: 1px; padding: 8px 10px; font: inherit; font-size: 14px; color: var(--fg);
  text-align: left; background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.saved-row .open:hover { background: var(--border); }
.saved-row .open .when { color: var(--muted); font-size: 12px; }
.saved-row .remove {
  flex: none; padding: 4px 8px; font: inherit; font-size: 12px; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.saved-export {
  width: calc(100% - 12px); margin: 6px; padding: 6px 10px; font: inherit; font-size: 13px; color: var(--accent);
  background: transparent; border: 1px solid var(--accent); border-radius: 8px; cursor: pointer;
}

.list-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 210px);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
.list-panel[hidden] { display: none; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; }
.list-head h2 { flex: 1; margin: 0; font-size: 14px; }
.list-head button {
  padding: 2px 10px; font: inherit; font-size: 12px; color: var(--fg);
  background: transparent; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.list-head button:focus-visible, .list-items button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.list-panel .note { margin: 2px 12px 6px; font-size: 12px; color: var(--muted); }
.list-items { list-style: none; margin: 0; padding: 0 6px 6px; overflow-y: auto; }
.list-items button {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 2px 10px; align-items: baseline;
  width: 100%; padding: 8px; font: inherit; font-size: 14px; color: var(--fg); text-align: left;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.list-items button:hover { background: var(--border); }
.list-items .dot { width: 10px; height: 10px; border-radius: 50%; }
.list-items .away { color: var(--muted); font-size: 12px; }
.list-items .when { grid-column: 2 / 4; color: var(--muted); font-size: 12px; }

.popup-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 2px; }
.act, .cal summary {
  display: inline-block; padding: 5px 12px; font: inherit; font-size: 13px; line-height: 1.4;
  color: var(--popup-fg, #16181d); text-decoration: none; background: transparent;
  border: 1px solid var(--popup-border, #e3e5e8); border-radius: 999px; cursor: pointer;
}
.act:hover, .cal summary:hover { border-color: var(--accent); }
.act[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.act:focus-visible, .cal summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal { flex-basis: 100%; }
.cal summary { list-style: none; }
.cal summary::-webkit-details-marker { display: none; }
.cal[open] summary { color: var(--accent); border-color: var(--accent); }
.cal .cal-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(44px + env(safe-area-inset-bottom, 0px));
  z-index: 6;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 10px 16px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
}
.toast[hidden] { display: none; }

.here {
  width: 18px; height: 18px; border-radius: 50%; background: #2d7ff9; border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgb(45 127 249 / 0.5), 0 1px 4px rgb(0 0 0 / 0.4);
  animation: here-pulse 2s ease-out infinite;
}
@keyframes here-pulse { to { box-shadow: 0 0 0 16px rgb(45 127 249 / 0), 0 1px 4px rgb(0 0 0 / 0.4); } }

/* Per-theme art frames for popups, lore cards, and dropdown panels. */
:root[data-art="linework"] .popup,
:root[data-art="linework"] .settings-panel,
:root[data-art="linework"] .menu-panel,
:root[data-art="linework"] .list-panel {
  border: 1.5px solid #0f5c4e;
  box-shadow: inset 0 0 0 2px var(--popup-bg, #fff), inset 0 0 0 3px rgba(184, 146, 74, 0.45), 0 8px 24px rgb(15 92 78 / 0.12);
}

:root[data-art="watercolor"] .popup,
:root[data-art="watercolor"] .settings-panel,
:root[data-art="watercolor"] .menu-panel,
:root[data-art="watercolor"] .list-panel {
  border-color: rgba(45, 111, 132, 0.22);
  box-shadow: 0 12px 32px rgb(40 54 61 / 0.12), inset 0 0 18px rgb(216 207 190 / 0.35);
}

:root[data-art="flat"] .popup,
:root[data-art="flat"] .settings-panel,
:root[data-art="flat"] .menu-panel,
:root[data-art="flat"] .list-panel {
  border: 0;
  box-shadow: 0 12px 28px rgb(47 61 76 / 0.12);
}

:root[data-art="crayon"] .popup,
:root[data-art="crayon"] .settings-panel,
:root[data-art="crayon"] .menu-panel,
:root[data-art="crayon"] .list-panel {
  border: 2px solid #3c3026;
  border-radius: 20px 14px 22px 16px / 15px 22px 14px 20px;
  box-shadow: 3px 4px 0 rgba(60, 48, 38, 0.22);
}

:root[data-art="riso"] .popup,
:root[data-art="riso"] .settings-panel,
:root[data-art="riso"] .menu-panel,
:root[data-art="riso"] .list-panel {
  border: 1.5px solid #1f2438;
  box-shadow: 4px 4px 0 rgba(255, 79, 147, 0.55), -2px -2px 0 rgba(45, 91, 227, 0.25);
}

:root[data-art="lantern"] .popup,
:root[data-art="lantern"] .settings-panel,
:root[data-art="lantern"] .menu-panel,
:root[data-art="lantern"] .list-panel {
  border: 1px solid rgba(255, 210, 125, 0.45);
  box-shadow: 0 0 22px rgba(255, 179, 71, 0.18), 0 12px 30px rgb(0 0 0 / 0.45);
}

.attribution {
  position: fixed;
  right: 8px;
  bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 6px;
  z-index: 2;
  max-width: calc(100vw - 16px);
}
.attribution a { color: inherit; }

@media (max-width: 767px) {
  .top { right: 64px; }
  .list-panel { max-height: 38dvh; }
  .popup {
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 50vh;
    max-height: 50dvh;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Cover the page until the themed map is drawn, so the plain basemap never shows first. Dark to
   match the default Night Market theme, so a first visit doesn't flash white. */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #0f1a2e;
  color: #b9c4d6;
  font-size: 14px;
  transition: opacity 0.4s ease;
}
.boot.done {
  opacity: 0;
  pointer-events: none;
}
.boot p {
  margin: 0;
}
.boot-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.6;
  animation: boot-spin 0.9s linear infinite;
}
@keyframes boot-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .boot-spinner {
    animation-duration: 3s;
  }
}
