:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --text: #1c1f2a;
  --muted: #6b7280;
  --border: #e3e6ee;
  --accent: #f59e0b;
  --rise-bg: #fff4d6;
  --rise-fg: #8a4b06;
  --set-bg: #ece8fb;
  --set-fg: #4c2ea3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --panel-w: 400px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --panel: #171a23;
    --text: #e6e8ef;
    --muted: #9aa1b1;
    --border: #2a2f3d;
    --rise-bg: #3a2a0c;
    --rise-fg: #fcd34d;
    --set-bg: #261c48;
    --set-fg: #c9b8ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout: map on top + scrolling panel on phones, side-by-side on wide screens ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.map-wrap {
  order: -1;
  flex: 0 0 46%;
  min-height: 240px;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
  background: #cfe3f5;
}

.panel {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (min-width: 820px) {
  .app { flex-direction: row; }
  .map-wrap { order: 0; flex: 1 1 auto; min-height: 0; }
  .panel {
    flex: 0 0 var(--panel-w);
    border-top: 0;
    border-right: 1px solid var(--border);
    padding: 22px 20px;
    box-shadow: var(--shadow);
    z-index: 1;
  }
}

/* ---- Header ---- */
.panel__header h1 {
  margin: 0;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel__header h1 svg { width: 26px; height: 26px; color: var(--accent); }

.tagline { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }

/* ---- Controls ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  transition: border-color 0.15s, background-color 0.15s;
}

.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--accent); }
.btn:active { background: var(--bg); }
.btn--text { padding: 0 12px; font-weight: 600; }
.btn--wide { flex: 1; gap: 8px; }

.btn:focus-visible,
input:focus-visible,
.search__results li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="search"],
input[type="date"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 40px;
  padding: 0 12px;
  min-width: 0;
}

input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }
input[type="date"] { color-scheme: light dark; }

.search { position: relative; margin: 0; }
.search__row { display: flex; gap: 8px; }
.search__row input { flex: 1; }

.search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 5;
  max-height: 260px;
  overflow-y: auto;
}

.search__results li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
}

.search__results li:hover,
.search__results li:focus { background: var(--bg); }

.date-row { display: flex; gap: 8px; align-items: center; }
.date-row input { flex: 1; }

.status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.status:empty { display: none; }

/* ---- Results ---- */
.results { display: flex; flex-direction: column; gap: 14px; }

.empty {
  text-align: center;
  padding: 28px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty svg { width: 44px; height: 44px; color: var(--accent); }
.empty p { margin: 6px 0 0; }

.muted { color: var(--muted); font-size: 0.88rem; }

.place {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.coords {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

@media (max-width: 360px) {
  .tiles { grid-template-columns: 1fr; }
}

.tile { border-radius: var(--radius); padding: 14px 16px; }
.tile--rise { background: var(--rise-bg); color: var(--rise-fg); }
.tile--set { background: var(--set-bg); color: var(--set-fg); }

.tile__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.9;
}

.tile__label svg { width: 18px; height: 18px; }

.tile__time {
  margin-top: 4px;
  font-size: clamp(1.55rem, 5.5vw, 1.95rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tile__sub { font-size: 0.8rem; opacity: 0.85; min-height: 1.2em; }

.polar {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.facts > div {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}

.facts dt {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.facts dd {
  margin: 2px 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.viewer-tz {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.panel__footer { margin-top: auto; padding-top: 8px; }
.panel__footer p { margin: 0; font-size: 0.78rem; }
.panel__footer a { color: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Map marker + dark-mode tiles ---- */
.pin { background: none; border: 0; }
.pin svg { display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); }

@media (prefers-color-scheme: dark) {
  #map { background: #0d1320; }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9); }
}
