:root {
  --sun: #f5a524;
  --sun-strong: #e08a00;
  --part: #f7cf6b;
  --tree: #a9c25d;
  --shade: #8d97a8;
  --night: #3d4458;
  --bg: #fffaf0;
  --surface: #ffffff;
  --ink: #2a2a2e;
  --muted: #6c6f78;
  --line: #ece5d6;
  --chip: #f4eee2;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(60, 45, 10, .12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b1a;
    --surface: #262523;
    --ink: #f2efe9;
    --muted: #a9a49a;
    --line: #3a3834;
    --chip: #33312d;
    --shade: #6f7889;
    --shadow: 0 6px 24px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1b1a; --surface: #262523; --ink: #f2efe9; --muted: #a9a49a;
  --line: #3a3834; --chip: #33312d; --shade: #6f7889; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
}

/* ---------- header ---------- */
#top {
  padding: calc(env(safe-area-inset-top) + 10px) 12px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}
.searchrow { display: flex; gap: 8px; }
#search {
  flex: 1; min-width: 0;
  height: 42px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 21px;
  background: var(--surface); outline: none;
}
#search:focus { border-color: var(--sun); }
.iconbtn {
  width: 42px; height: 42px; flex: none;
  border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}
.iconbtn.on { color: #fff; background: #3b82f6; border-color: #3b82f6; }

.timerow { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#slider { flex: 1; min-width: 60px; accent-color: var(--sun-strong); }
.timelabel { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; text-align: right; }
#date {
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  height: 32px; padding: 0 4px; width: 112px; min-width: 0; font-size: 13px; flex: none;
}
#now { flex: none; }

.chip {
  border: 1px solid var(--line); background: var(--chip);
  border-radius: 16px; padding: 5px 12px; cursor: pointer; white-space: nowrap; font-size: 14px;
}
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.weather {
  margin-top: 8px; padding: 7px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--chip);
}
.weather.cloudy { background: #e6e9ef; color: #3a4252; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .weather.cloudy { background: #343a46; color: #dfe4ee; } }

/* ---------- map ---------- */
#map { min-height: 0; background: #e9e4da; }
.leaflet-container { font: inherit; }
.you-dot { width: 16px; height: 16px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59,130,246,.25); }

/* ---------- panel ---------- */
#panel {
  background: var(--surface);
  border-top-left-radius: 18px; border-top-right-radius: 18px;
  box-shadow: var(--shadow);
  height: 46vh; display: flex; flex-direction: column;
  margin-top: -16px; z-index: 1000; position: relative;
  padding-bottom: env(safe-area-inset-bottom);
  transition: height .25s ease;
}
#panel.tall { height: 78vh; }
#panel.short { height: 20vh; }
#handle {
  width: 44px; height: 5px; border-radius: 3px; background: var(--line);
  margin: 8px auto 4px; flex: none; cursor: grab;
  padding: 8px 0; background-clip: content-box; box-sizing: content-box;
}
#listview, #detail { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#listview[hidden], #detail[hidden] { display: none; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 12px 6px; flex: none; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.summary { padding: 0 14px 6px; color: var(--muted); font-size: 13px; flex: none; }

#list { list-style: none; margin: 0; padding: 0 0 12px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
#list li {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
#list li:active { background: var(--chip); }
.badge {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #3a2a00;
}
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.right b { color: var(--ink); font-weight: 600; }
#list li.empty { display: block; padding: 24px 16px; color: var(--muted); text-align: center; cursor: default; }

/* ---------- detail ---------- */
#detail { overflow-y: auto; padding: 0 16px 20px; }
#detail > * { flex-shrink: 0; }
.back { align-self: flex-start; background: none; border: 0; color: var(--muted); padding: 4px 0 8px; cursor: pointer; }
.d-title { font-size: 21px; font-weight: 700; margin: 0; }
.d-sub { color: var(--muted); margin: 2px 0 12px; }
.d-now { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius); background: var(--chip); }
.d-now .big { font-size: 28px; font-weight: 800; min-width: 74px; text-align: center; }
.d-now .txt b { display: block; font-size: 16px; }
.d-h { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 6px; }
.timeline { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.facts { font-size: 14px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions a {
  text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--surface);
  padding: 8px 14px; border-radius: 20px; font-size: 14px;
}
.note { color: var(--muted); font-size: 12.5px; margin-top: 16px; }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #app { grid-template-columns: 400px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  #top { grid-column: 1; grid-row: 1; border-right: 1px solid var(--line); }
  #panel { grid-column: 1; grid-row: 2; height: auto !important; margin: 0; border-radius: 0; box-shadow: none; border-right: 1px solid var(--line); }
  #map { grid-column: 2; grid-row: 1 / span 2; }
  #handle { display: none; }
}
