:root {
  --bg: #f6f7f9;
  --fg: #1d2330;
  --muted: #5f6878;
  --card: #fff;
  --line: #d9dde4;
  --accent: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --fg: #e6e9ee; --muted: #9aa3b2; --card: #1d2128; --line: #323844; --accent: #6ea0ff; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--fg); }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
h1 { font-size: 18px; margin: 0; }
form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
input, button { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
/* iOS Safari gives date fields a minimum width from their native look, so in
   the phone grid they overflowed into each other: drop it and let them shrink */
input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; min-height: 2.1em; display: block; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
button:hover { border-color: var(--accent); }
#status { color: var(--muted); font-size: 13px; }
#range-label { font-size: 14px; border-radius: 4px; padding: 1px 4px; margin: 0 -4px; }
#range-label b { font-weight: 600; }
/* A value the page changed, or the range line after a change */
@keyframes flash { from { background: #ffe58a; box-shadow: 0 0 0 3px #ffe58a; } to { background: transparent; box-shadow: 0 0 0 3px transparent; } }
.flash { animation: flash 1.6s ease-out; }
input.flash { animation-name: flash-input; }
@keyframes flash-input { from { background: #ffe58a; border-color: #d9a400; } to { background: var(--bg); border-color: var(--line); } }
/* The date being picked (focused while its picker is open), and the end date
   after the start date was picked */
form label:focus-within, label.next { color: var(--accent); font-weight: 600; }
form label:focus-within input, label.next input { border-color: var(--accent); outline: none;
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
#map { height: 62vh; min-height: 320px; }
#summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 8px; padding: 12px 14px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.card dt { color: var(--muted); }
.card dd { margin: 0; font-variant-numeric: tabular-nums; }
.card .links { margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; }
.card .note { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.card .err { color: #d33; }
a { color: var(--accent); }
.legend { background: var(--card); color: var(--fg); padding: 6px 10px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.3); line-height: 1.7; }
.legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.legend .sw { display: inline-block; width: 18px; height: 4px; border-radius: 2px; background: var(--c); }
.legend .n { color: var(--muted); font-size: 12px; }
.leaflet-popup-content { font-size: 13px; }
.card .ago { font-weight: 600; }
button:disabled { opacity: .6; cursor: progress; }
/* Refresh cooldown: a ring that drains over the minute, with the seconds left */
#refresh { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
#refresh .cd, #refresh .cd-n { display: none; }
#refresh.cooling { opacity: 1; cursor: not-allowed; color: var(--muted); }
#refresh.cooling .cd { display: block; transform: rotate(-90deg); }
#refresh.cooling .cd-n { display: inline; font-variant-numeric: tabular-nums; font-size: 12px; min-width: 2ch; margin-left: -4px; }
#refresh .cd-track { fill: none; stroke: var(--line); stroke-width: 3; }
#refresh .cd-ring { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 100; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.panel { margin: 0 16px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.panel:empty { display: none; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel .sw, .chart-key .sw, .tip .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; }
.title-note { font-weight: 400; font-size: 13px; color: var(--muted); }
.chart-key { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hair { stroke: var(--muted); stroke-width: 1; }
.tip { position: absolute; top: 8px; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.15); white-space: nowrap; }
.tip-time { color: var(--muted); margin-bottom: 2px; }
.tip b { font-variant-numeric: tabular-nums; }
.stats-dev h3 { font-size: 14px; margin: 10px 0 4px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 100%; }
th, td { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 500; }
tbody th { font-weight: 400; }
tfoot th, tfoot td { font-weight: 600; border-bottom: 0; }
footer { padding: 4px 16px 24px; color: var(--muted); font-size: 13px; }
footer p { margin: 0; max-width: 70ch; }
.foot { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.locate-btn { width: 34px; height: 34px; display: grid; place-items: center; background: #fff; color: #333; border: 2px solid rgba(0,0,0,.2); border-radius: 4px; background-clip: padding-box; padding: 0; }
.locate-btn.on { color: #2a78d6; }
.slope-key { font-size: 12px; display: flex; gap: 8px; align-items: center; }
.slope-key i { display: inline-block; width: 12px; height: 12px; margin-right: 3px; vertical-align: -2px; opacity: .8; }

body.map-full { overflow: hidden; }
/* !important: Leaflet sets position: relative on the map element itself */
body.map-full #map { position: fixed !important; inset: 0; height: 100%; height: 100dvh; min-height: 0; z-index: 2000; }
#map:fullscreen { height: 100%; }

@media (max-width: 600px) {
  header { padding: 8px 12px; gap: 6px; }
  h1 { font-size: 16px; }
  form { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: 100%; }
  form label { grid-column: span 3; display: flex; flex-direction: column; font-size: 12px; color: var(--muted); min-width: 0; }
  /* 16px: smaller text makes iPhones zoom in when the field is tapped */
  form input { width: 100%; max-width: 100%; min-width: 0; color: var(--fg); padding: 4px 6px; font-size: 16px; }
  form button { grid-column: span 2; padding: 5px 4px; font-size: 14px; }
  #range-label { grid-column: span 6; margin: 0; }
  #status { grid-column: span 6; }
  #map { height: 55vh; }
  #summary { padding: 12px; gap: 10px; }
  .panel { margin: 0 12px 12px; padding: 10px; }
  th, td { padding: 4px 5px; }
  /* Positions: least useful, and the table must fit a phone */
  .stats-dev th:last-child, .stats-dev td:last-child { display: none; }
}
