@font-face {
  font-family: "Plex Condensed";
  src: url("/vendor/fonts/ibm-plex-sans-condensed-latin-400-normal.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Plex Condensed";
  src: url("/vendor/fonts/ibm-plex-sans-condensed-latin-600-normal.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}

/* Colours encode the light phases used throughout the app. */
:root {
  --night: #1E2638;
  --blue: #4E6FA8;
  --golden: #E8A33D;
  --sun: #D9821A;
  --day: #F1E4BE;

  --ink: #1E2638;
  --muted: #646C80;
  --paper: #FBFBFC;
  --line: #E1E4EA;
  --field: #FFFFFF;
  --focus: #4E6FA8;
  --halo: #FFFFFF;

  --font: "Plex Condensed", "IBM Plex Sans Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E8EBF2;
    --muted: #9AA3B6;
    --paper: #141A27;
    --line: #2A3347;
    --field: #1C2334;
    --focus: #8FAAE0;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout: mobile first ---------- */
.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "map" "panel";
}
.map { grid-area: map; min-height: 0; background: #DDE2E8; }
.panel {
  grid-area: panel;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  z-index: 2;
}

.search {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px; right: 10px;
  z-index: 1000;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 2px 10px rgba(20, 26, 39, 0.18);
}
.search input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  padding: 6px 8px;
  font-size: 16px; /* prevents iOS zoom */
}
.search input:focus-visible { outline: none; }
.search:focus-within { border-color: var(--focus); }
.icon-btn {
  flex: none; width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm);
  background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--line); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.icon-btn.is-busy svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 6px 18px rgba(20, 26, 39, 0.2);
  max-height: 50vh; overflow: auto;
}
.results li { margin: 0; }
.results button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: var(--r-sm);
  background: transparent; cursor: pointer;
}
.results button:hover, .results button:focus-visible { background: var(--line); outline: none; }
.results small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results .heading { padding: 6px 10px 2px; font-size: 12px; color: var(--muted); }
.results .message { padding: 8px 10px; color: var(--muted); }

.notice {
  position: absolute;
  top: calc(66px + env(safe-area-inset-top));
  left: 10px; right: 10px;
  z-index: 999;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--night); color: #fff;
  font-size: 13px;
}

/* ---------- Panel content ---------- */
.place h1 {
  margin: 0;
  font-size: 18px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .sep { padding: 0 0.4em; opacity: 0.6; }

.when { display: flex; gap: 6px; align-items: stretch; }
.field { flex: 1; min-width: 0; display: flex; }
.field input {
  width: 100%; min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--field);
  font-size: 16px; font-weight: 600;
}
.field:first-child { flex: 1.35; }
.text-btn {
  flex: none; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--field); cursor: pointer; font-weight: 600;
}
.text-btn:hover { border-color: var(--muted); }

.sun-now {
  display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 8px;
  margin: 0;
}
.sun-now dt { font-size: 12px; color: var(--muted); }
.sun-now dd { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.25; white-space: nowrap; }
.sun-now dd small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.phase {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  font-size: 14px; font-weight: 600; line-height: 1.6;
  background: var(--line); color: var(--ink);
}
.phase-day { background: var(--day); color: #4A3A10; }
.phase-golden { background: var(--golden); color: #2A1A00; }
.phase-blue { background: var(--blue); color: #fff; }
.phase-night { background: var(--night); color: #E8EBF2; }
@media (prefers-color-scheme: dark) { .phase-night { box-shadow: inset 0 0 0 1px var(--line); } }

.times { width: 100%; border-collapse: collapse; font-size: 14px; }
.times th, .times td { padding: 3px 0; text-align: left; font-weight: 400; }
.times thead th { font-size: 12px; color: var(--muted); padding-top: 0; }
.times tbody tr + tr { border-top: 1px solid var(--line); }
.times tbody th { color: var(--muted); white-space: nowrap; }
.times td { font-weight: 600; white-space: nowrap; width: 31%; }
.times td.span { color: var(--muted); font-weight: 400; }
.key { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.key-sun { background: var(--day); box-shadow: inset 0 0 0 1px var(--sun); }
.key-golden { background: var(--golden); }
.key-blue { background: var(--blue); }

/* The day as a band of light: the slider track is painted from the actual sun elevation. */
.timeline { position: relative; padding-top: 2px; }
#slider {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 26px; margin: 0;
  background: transparent; cursor: pointer;
}
#slider::-webkit-slider-runnable-track {
  height: 16px; border-radius: 4px;
  background: var(--track, linear-gradient(90deg, var(--line), var(--line)));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
#slider::-moz-range-track {
  height: 16px; border-radius: 4px;
  background: var(--track, linear-gradient(90deg, var(--line), var(--line)));
}
#slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 8px; height: 26px; margin-top: -5px;
  border-radius: 3px; background: #fff;
  border: 2px solid var(--night);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
#slider::-moz-range-thumb {
  width: 6px; height: 24px; border-radius: 3px; background: #fff;
  border: 2px solid var(--night); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
#slider:disabled { cursor: default; opacity: 0.5; }
#slider:focus-visible { outline-offset: 0; }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 1px; padding: 0 1px; }

.more { font-size: 13px; }
.more summary { cursor: pointer; color: var(--muted); padding: 2px 0; }
.more[open] summary { margin-bottom: 4px; }
.extra { display: flex; gap: 18px; margin: 0 0 6px; }
.extra b { font-weight: 600; margin-left: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend svg { flex: none; width: 28px; height: 10px; overflow: visible; }
.lg-sun { stroke: var(--sun); stroke-width: 3; }
.lg-sun-head { fill: var(--sun); }
.lg-shadow { stroke: var(--ink); stroke-width: 3; stroke-dasharray: 5 4; }
.lg-path { stroke: var(--golden); stroke-width: 3; stroke-dasharray: 0 5; stroke-linecap: round; }
.lg-dot { fill: #FFD27A; stroke: var(--sun); stroke-width: 2; }
.lg-event { stroke: var(--ink); stroke-width: 1.3; stroke-dasharray: 2 3; opacity: 0.8; }
.fine { margin: 6px 0 0; font-size: 12px; color: var(--muted); max-width: 60ch; }

.actions { display: flex; gap: 8px; }
.btn {
  flex: 1; padding: 9px 12px;
  border: 1px solid var(--night); border-radius: var(--r-sm);
  background: var(--night); color: #fff;
  font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .btn { background: var(--ink); color: var(--paper); border-color: var(--ink); } }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
@media (prefers-color-scheme: dark) { .btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); } }
.btn:disabled { opacity: 0.45; cursor: default; }

/* Empty state */
.is-empty .sun-now, .is-empty .times, .is-empty .extra { opacity: 0.45; }

/* ---------- Map overlay ---------- */
.pin-icon {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--night); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.overlay-icon { pointer-events: none; }
.sun-overlay { display: block; overflow: visible; }
.ov-ring { fill: rgba(255, 255, 255, 0.14); stroke: rgba(30, 38, 56, 0.6); stroke-width: 1.5; }
.ov-tick { stroke: rgba(30, 38, 56, 0.7); stroke-width: 1.5; }
.ov-north, .ov-label {
  font-family: var(--font); font-weight: 600; fill: #1E2638;
  text-anchor: middle; dominant-baseline: central;
  paint-order: stroke; stroke: #fff; stroke-width: 3.5px; stroke-linejoin: round;
}
.ov-north { font-size: 13px; }
.ov-label { font-size: 11.5px; }
.ov-path { fill: none; stroke: var(--golden); stroke-width: 4; stroke-dasharray: 0 7; stroke-linecap: round; filter: drop-shadow(0 0 1px #fff); }
.ov-event { stroke: #1E2638; stroke-width: 1.3; stroke-dasharray: 2 3; opacity: 0.75; }
.ov-shadow-halo { stroke: rgba(255, 255, 255, 0.75); stroke-width: 7; stroke-linecap: round; }
.ov-shadow { stroke: #1E2638; stroke-width: 3.5; stroke-dasharray: 7 5; }
.ov-sun-halo { stroke: rgba(255, 255, 255, 0.85); stroke-width: 8; stroke-linecap: round; }
.ov-sun-line { stroke: var(--sun); stroke-width: 4; stroke-linecap: round; }
.ov-sun-head { fill: var(--sun); stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.ov-sun-dot { fill: #FFD27A; stroke: var(--sun); stroke-width: 3; }
.ov-sun.is-down { opacity: 0.6; }
.ov-sun.is-down .ov-sun-line { stroke: var(--blue); stroke-dasharray: 5 5; stroke-linecap: butt; }
.ov-sun.is-down .ov-sun-head { fill: var(--blue); }

.leaflet-container { font-family: var(--font); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: brightness(0.88) contrast(1.05); }
}

/* ---------- Desktop ---------- */
@media (min-width: 820px) {
  .app {
    grid-template-columns: 380px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "search map" "panel map";
  }
  .search {
    position: relative; top: auto; left: auto; right: auto;
    grid-area: search;
    margin: 16px 16px 0;
    box-shadow: none;
  }
  .notice { left: calc(380px + 16px); right: 16px; top: 16px; }
  .panel {
    border-top: 0; background: transparent;
    padding: 14px 16px 16px;
    align-content: start; gap: 14px;
    overflow-y: auto;
  }
  .app::before { /* full-height panel background behind the search box */
    content: ""; grid-row: 1 / 3; grid-column: 1;
    background: var(--paper); border-right: 1px solid var(--line);
  }
  .search, .panel { grid-column: 1; }
  body { font-size: 16px; }
  .place h1 { font-size: 22px; white-space: normal; }
  .meta { white-space: normal; }
  .sun-now dd { font-size: 24px; }
  .times { font-size: 15px; }
  .times th, .times td { padding: 6px 0; }
  .more summary { display: none; }
  .actions { margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn.is-busy svg { animation: none; opacity: 0.5; }
}
