:root {
  --text: #fff;
  --muted: rgba(255, 255, 255, .68);
  --faint: rgba(255, 255, 255, .16);
  --card: rgba(255, 255, 255, .13);
  --card-line: rgba(255, 255, 255, .16);
  --track: rgba(0, 0, 0, .2);
  --dialog: rgba(26, 30, 38, .94);
  --field: rgba(255, 255, 255, .1);
  --accent: #6ab0ff;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: #2f6fb5;
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#sky { position: fixed; inset: 0; z-index: -1; background: linear-gradient(180deg, #2f6fb5, #6aa6dc); transition: background 1.2s ease; }
a { color: inherit; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.app { max-width: 1080px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 32px; }

/* top bar */
.topbar { display: flex; gap: 8px; align-items: center; }
.search { position: relative; flex: 1; }
.search-ico { position: absolute; left: 11px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 36px; border: 0; border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-size: 16px;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.search input::placeholder { color: var(--muted); }
#results {
  position: absolute; z-index: 1000; left: 0; right: 0; top: 46px; margin: 0; padding: 6px; list-style: none;
  background: var(--dialog); border: 1px solid var(--card-line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
}
#results li { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
#results li small { color: var(--muted); margin-left: 6px; }
#results li[aria-selected="true"], #results li:hover { background: var(--faint); }
.icon-btn {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 12px;
  background: var(--card); color: var(--text); cursor: pointer;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small { width: 34px; height: 34px; background: var(--field); }
.icon-btn.pill { width: auto; display: flex; gap: 6px; padding: 0 12px 0 10px; font: inherit; font-size: 14px; font-weight: 600; }
.icon-btn:hover { background: rgba(255, 255, 255, .22); }

/* hero */
.hero { text-align: center; padding: 30px 0 26px; text-shadow: 0 1px 12px rgba(0, 0, 0, .12); }
.hero h1 { margin: 0; font-size: 32px; font-weight: 500; letter-spacing: -.01em; }
.temp { font-size: 100px; font-weight: 200; line-height: 1; margin: 4px 0 2px .18em; letter-spacing: -.03em; }
.cond { font-size: 20px; font-weight: 500; color: rgba(255, 255, 255, .9); }
.hilo { font-size: 19px; font-weight: 500; margin-top: 2px; }
.notice { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: rgba(120, 20, 20, .45); }

/* cards */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.card {
  min-width: 0; padding: 12px 14px 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--card-line);
  -webkit-backdrop-filter: blur(24px) saturate(140%); backdrop-filter: blur(24px) saturate(140%);
}
.span-4 { grid-column: span 4; }
.span-2 { grid-column: span 2; }
.row-2 { grid-row: span 2; }
.card h2 {
  display: flex; align-items: center; gap: 6px; margin: 0 0 8px; padding-bottom: 8px;
  border-bottom: 1px solid var(--faint); color: var(--muted);
  font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
}
.card h2 svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.summary { margin: 0 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--faint); font-size: 15px; }
.headline { margin: 0 0 8px; font-size: 15px; font-weight: 500; }

/* hourly */
.hours { display: flex; gap: 2px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; padding-bottom: 2px; }
.hours::-webkit-scrollbar { display: none; }
.hour { flex: none; width: 58px; display: flex; flex-direction: column; align-items: center; gap: 4px; scroll-snap-align: start; font-weight: 500; }
.hour .t { font-size: 14px; }
.hour .pop { height: 15px; font-size: 12px; font-weight: 700; }
.hour .tmp { font-size: 18px; }
.wx-ico { width: 30px; height: 30px; }
.hour.event .tmp { font-size: 13px; color: var(--muted); }

/* daily */
.day { display: grid; grid-template-columns: 4.2em 40px 2.6em minmax(60px, 1fr) 2.6em; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--faint); font-size: 17px; font-weight: 500; }
.day:first-child { border-top: 0; }
.day .ic { display: flex; flex-direction: column; align-items: center; }
.day .ic .pop { font-size: 11px; font-weight: 700; margin-top: -2px; }
.day .lo { text-align: right; color: var(--muted); }
.day .hi { text-align: right; }
.track { position: relative; height: 5px; border-radius: 3px; background: var(--track); }
.track .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.track .dot { position: absolute; top: 50%; width: 9px; height: 9px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); transform: translate(-50%, -50%); }

/* precipitation chart */
.pchart svg { width: 100%; height: auto; overflow: visible; }
.pchart text { fill: var(--muted); font-size: 11px; font-weight: 600; }
.pchart .guide { stroke: var(--faint); stroke-dasharray: 3 4; }

/* radar */
.map { height: 300px; border-radius: 12px; overflow: hidden; background: #1d2633; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(0, 0, 0, .45) !important; color: #ddd; }
.leaflet-control-attribution a { color: #fff; }
.radar-tile { image-rendering: auto; }
.basemap { filter: grayscale(1) contrast(.85) brightness(1.04); }
.night .basemap { filter: grayscale(1) invert(1) contrast(.8) brightness(.78); }
.here-dot { width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(0, 120, 255, .9), 0 2px 6px rgba(0, 0, 0, .5); }
.radar-controls { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.play { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--faint); color: #fff; cursor: pointer; }
.play svg { width: 16px; height: 16px; fill: currentColor; }
#frame { flex: 1; accent-color: #fff; }
.frame-time { flex: none; min-width: 5.5em; text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: grid; gap: 6px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.legend .lrow { display: grid; grid-template-columns: 3.4em 1fr; align-items: center; gap: 8px; }
.legend .bar { display: flex; gap: 2px; }
.legend .seg { flex: 1; min-width: 0; text-align: center; }
.legend .seg i { display: block; height: 8px; border-radius: 3px; margin-bottom: 3px; }
.mode-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--faint); font-size: 13px; font-weight: 600; }
.mode-row label { flex: none; }
.mode-row select { flex: 1; min-width: 150px; width: auto; height: 32px; font-size: 13px; }
.text-btn.small { margin: 0; padding: 6px 10px; font-size: 13px; font-weight: 600; }

/* map expand button (Leaflet control) */
.map-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; cursor: pointer;
  background: rgba(20, 24, 32, .78); color: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.map-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.map-btn:hover { background: rgba(40, 46, 58, .9); }

/* full-screen radar */
body.noscroll { overflow: hidden; }
.radar-card.radar-full {
  position: fixed; inset: 0; z-index: 3000; display: flex; flex-direction: column; margin: 0; border: 0; border-radius: 0;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: #10151d; -webkit-backdrop-filter: none; backdrop-filter: none;
}
.radar-full .map { flex: 1; height: auto; min-height: 0; }
.radar-full .legend, .radar-full .mode-row { max-width: 760px; width: 100%; margin-left: auto; margin-right: auto; }
.radar-card:fullscreen { width: 100%; height: 100%; }

/* detail tiles */
.tile { min-height: 158px; display: flex; flex-direction: column; }
.tile .big { font-size: 32px; font-weight: 500; line-height: 1.1; }
.tile .big small { font-size: 17px; font-weight: 500; }
.tile .sub { font-size: 15px; font-weight: 500; }
.tile .note { margin-top: auto; padding-top: 8px; font-size: 13px; color: rgba(255, 255, 255, .85); }
.tile .scale { position: relative; height: 5px; margin: 10px 0 2px; border-radius: 3px; }
.tile .scale .dot { position: absolute; top: 50%; width: 9px; height: 9px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0, 0, 0, .4); transform: translate(-50%, -50%); }
.compass { width: 92px; height: 92px; margin: 0 auto; }
.compass text { fill: var(--muted); font-size: 9px; font-weight: 700; text-anchor: middle; }
.sunarc { width: 100%; height: 54px; margin-top: 6px; }

.credits { margin-top: 22px; text-align: center; font-size: 12px; color: var(--muted); }

/* settings dialog */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: min(86vh, 900px); padding: 0; border: 1px solid var(--card-line); border-radius: 18px;
  background: var(--dialog); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.settings { padding: 16px 18px 20px; }
.s-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.s-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.s-block { margin: 14px 0 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--faint); }
.s-block legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.row-label { display: block; margin-bottom: 6px; font-size: 14px; }
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
select {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--card-line); border-radius: 10px;
  background: var(--field); color: var(--text); font: inherit;
}
select option { background: #222830; }
.units { display: grid; gap: 10px; }
.unit-row { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 10px; font-size: 14px; }
.seg-ctl { display: flex; padding: 2px; border-radius: 9px; background: var(--field); }
.seg-ctl label { flex: 1; position: relative; }
.seg-ctl input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-ctl span { display: block; padding: 6px 4px; border-radius: 7px; text-align: center; font-size: 13px; font-weight: 600; }
.seg-ctl input:checked + span { background: rgba(255, 255, 255, .24); }
.seg-ctl input:focus-visible + span { outline: 2px solid #fff; }
.cgroup { margin-top: 16px; }
.cgroup h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); text-align: center; cursor: pointer; }
.swatch input[type="color"] {
  width: 100%; height: 34px; padding: 0; border: 1px solid var(--card-line); border-radius: 9px; background: none; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.swatch input[type="color"]::-moz-color-swatch { border: 0; border-radius: 8px; }
.gradient-preview { height: 8px; margin-top: 8px; border-radius: 4px; }
.text-btn { margin-top: 16px; padding: 8px 12px; border: 1px solid var(--card-line); border-radius: 10px; background: var(--field); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }

/* colour-vision simulation (preview only) */
html.sim-protanopia #app, html.sim-protanopia #sky { filter: url(#sim-protanopia); }
html.sim-deuteranopia #app, html.sim-deuteranopia #sky { filter: url(#sim-deuteranopia); }
html.sim-tritanopia #app, html.sim-tritanopia #sky { filter: url(#sim-tritanopia); }
html.sim-achromatopsia #app, html.sim-achromatopsia #sky { filter: url(#sim-achromatopsia); }

@media (max-width: 899px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-4, .span-2 { grid-column: span 2; }
  .row-2 { grid-row: auto; }
}
@media (max-width: 420px) {
  .temp { font-size: 88px; }
  .day { grid-template-columns: 3.8em 34px 2.3em minmax(40px, 1fr) 2.3em; gap: 8px; font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  #sky { transition: none; }
}
