/* Air out?: a modern dial hygrometer. */
:root {
  color-scheme: light dark;
  --bg: #f2f4f7;
  --face: #ffffff;
  --ink: #111a24;
  --muted: #5f6b78;
  --line: #d5dbe2;
  --track: #e3e8ee;
  --rim: #a3adb8;
  --dry: #138a72;    /* teal-green: air out */
  --wait: #c27f00;   /* amber: later */
  --humid: #2a64d6;  /* blue: too humid */
  --warn: #c2410c;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "SF Pro Text", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dark: follows the device unless the switch says light; the switch can also force it. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c2638;
    --face: #26334a;
    --ink: #e8edf3;
    --muted: #a3afbe;
    --line: #3a4a64;
    --track: #33425c;
    --rim: #7a8aa0;
    --dry: #3cc3a2;
    --wait: #f0b429;
    --humid: #6b9cff;
    --warn: #fb8b5a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c2638;
  --face: #26334a;
  --ink: #e8edf3;
  --muted: #a3afbe;
  --line: #3a4a64;
  --track: #33425c;
  --rim: #7a8aa0;
  --dry: #3cc3a2;
  --wait: #f0b429;
  --humid: #6b9cff;
  --warn: #fb8b5a;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 30rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  display: grid;
  gap: 1.5rem;
}

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--humid); outline-offset: 2px; }
a { color: inherit; text-underline-offset: 0.15em; }
h1, h2, h3 { margin: 0; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
h1 { font-size: 1rem; font-weight: 600; }
.place {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: none; border: 0; padding: 0.25rem 0; color: var(--muted); cursor: pointer;
}
.place svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.4; }
.place:hover { color: var(--ink); }
.top-actions { display: flex; align-items: center; gap: 0.5rem; }
.top-actions .place { margin-right: 0.25rem; }
.theme-switch, .icon-button {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem;
  background: none; border: 1px solid var(--line); border-radius: 50%; padding: 0; color: var(--muted); cursor: pointer;
}
.theme-switch:hover, .icon-button:hover { color: var(--ink); border-color: var(--muted); }
.theme-switch svg, .icon-button svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.theme-switch .sun { display: none; }
.theme-switch[data-showing="dark"] .sun { display: block; }
.theme-switch[data-showing="dark"] .moon { display: none; }
.bell .slash { display: none; }
.bell[data-state="on"] { color: var(--humid); border-color: var(--humid); }
.bell[data-state="on"] path:first-child { fill: currentColor; fill-opacity: 0.2; }
.bell[data-state="blocked"] { opacity: 0.55; }
.bell[data-state="blocked"] .slash { display: block; }

.status { margin: 0; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.75rem; text-align: center; }

.content, .details { display: grid; gap: 1.5rem; }
.gauge { display: grid; gap: 0.75rem; justify-items: center; }
.result { display: grid; gap: 1.75rem; }

/* Wide screens: dial on the left, advice on the right, centred vertically. */
@media (min-width: 56rem) {
  main { max-width: 62rem; min-height: 100vh; min-height: 100dvh; grid-template-rows: auto 1fr auto; padding-inline: 2rem; }
  .content { grid-template-columns: 21rem minmax(0, 1fr); column-gap: 3.5rem; align-items: center; align-self: center; }
  .gauge .dial { width: 100%; }
}

/* The dial */
.dial { width: min(100%, 16.5rem); justify-self: center; display: block; overflow: visible; }
.dial-face { fill: var(--face); stroke: var(--rim); stroke-width: 2.5; }
.dial-track, .dial-dry, .dial-humid { fill: none; stroke-width: 8; }
.dial-track { stroke: var(--track); }
.dial-dry { stroke: var(--dry); }
.dial-humid { stroke: var(--humid); }
.dial-tick { stroke: var(--muted); stroke-width: 0.8; }
.dial-tick.major { stroke: var(--ink); stroke-width: 1.3; }
.dial-label { fill: var(--muted); font: 500 9px var(--sans); text-anchor: middle; dominant-baseline: central; }
.dial-room { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.dial-needle { fill: var(--ink); transform-box: view-box; transform-origin: 100px 100px; transition: transform 0.9s cubic-bezier(0.3, 1.35, 0.5, 1); }
.dial-hub { fill: var(--ink); }
.dial-pin { fill: var(--face); }
.dial-value { fill: var(--ink); font: 600 27px var(--sans); letter-spacing: -0.02em; text-anchor: middle; }
.dial-caption { fill: var(--muted); font: 8.5px var(--sans); text-anchor: middle; }

@media (prefers-reduced-motion: reduce) {
  .dial-needle { transition: none; }
  .dial.loading .dial-needle { animation: pulse 1s ease-in-out infinite alternate; }
}
@keyframes pulse { to { opacity: 0.3; } }

/* The advice */
.advice { --kind: var(--muted); border-left: 4px solid var(--kind); padding: 0.1rem 0 0.1rem 1rem; }
.advice[data-kind="ventilate"] { --kind: var(--dry); }
.advice[data-kind="wait"] { --kind: var(--wait); }
.advice[data-kind="dehumidify"] { --kind: var(--humid); }
.advice h2 { font-size: clamp(1.6rem, 6.5vw, 2rem); font-weight: 650; line-height: 1.15; letter-spacing: -0.02em; text-wrap: balance; }
.advice p { margin: 0.6rem 0 0; color: var(--muted); max-width: 36em; }
.advice .warning { color: var(--warn); font-weight: 600; }
.advice .rule { font-size: 0.85rem; margin-top: 0.4rem; opacity: 0.7; } /* deliberately faint: secondary hint */

/* 24-hour band */
h3 { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-bottom: 0.6rem; }
.strip, .strip-labels { display: grid; grid-template-columns: repeat(var(--n, 25), 1fr); }
.strip { height: 1.75rem; border-radius: 0.5rem; overflow: hidden; background: var(--track); }
.cell { border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer; border-right: 1px solid var(--bg); }
.cell:last-child { border-right: 0; }
.cell.good { background: var(--dry); }
.cell.best { background: var(--dry); box-shadow: inset 0 -4px 0 var(--ink); }
.cell:hover, .cell.selected, .cell:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ink); }
.strip-labels { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }
.hour-detail { font-size: 0.9rem; color: var(--muted); margin: 0.6rem 0 0; min-height: 1.55em; }

/* Figures */
.numbers { margin: 0; display: grid; gap: 0.4rem; }
.numbers div { display: flex; justify-content: space-between; gap: 1rem; }
.numbers dt { color: var(--muted); }
.numbers dd { margin: 0; text-align: right; font-weight: 500; }
.source { margin: -1.25rem 0 0; font-size: 0.82rem; color: var(--muted); }

/* Drop-down panels (location, settings) */
.panel {
  inset: 0; margin: 3.75rem auto auto; width: min(28rem, calc(100vw - 2rem)); max-height: calc(100vh - 5rem); overflow: auto;
  padding: 1.1rem 1.25rem 1.25rem; border: 1px solid var(--line); border-radius: 0.75rem;
  background: var(--face); color: var(--ink); box-shadow: 0 12px 32px rgb(15 22 33 / 0.18);
}
.panel:popover-open { display: grid; gap: 0.75rem; justify-items: start; }
.panel::backdrop { background: rgb(15 22 33 / 0.25); }
.panel-title { font-size: 1rem; font-weight: 600; }
.panel .fields { width: 100%; }

/* Indoor reading under the dial */
.room-reading { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 0.6rem; }
.room-reading > span:first-child { color: var(--muted); }
.room-reading small { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 0.8rem; }
.room-reading input { width: 4rem; }

.fields { display: grid; gap: 0.9rem; }
.fields label { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.fields small { display: block; color: var(--muted); font-size: 0.82rem; }
.field { white-space: nowrap; color: var(--muted); }
input { background: var(--face); border: 1px solid var(--line); border-radius: 0.45rem; padding: 0.3rem 0.5rem; color: var(--ink); }
input:focus { border-color: var(--humid); outline: none; }
input[type="number"] { width: 4.75rem; text-align: right; }

/* Location dropdown: one search field, then a list */
.location-panel:popover-open { padding: 0; gap: 0; overflow: hidden; }
.search { display: flex; align-items: center; gap: 0.55rem; width: 100%; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
.search svg { width: 1rem; height: 1rem; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; border: 0; padding: 0.2rem 0; background: transparent; font-size: 1rem; }
.search input:focus { border: 0; }
.button {
  background: var(--face); border: 1px solid var(--line); border-radius: 0.45rem;
  padding: 0.3rem 0.9rem; cursor: pointer; font-weight: 500;
}
.button:hover { border-color: var(--ink); }
.hint { margin: 0; color: var(--muted); }
.results { width: 100%; padding: 0.35rem 0; }
.results ul { list-style: none; margin: 0; padding: 0; }
.result-row {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  background: none; border: 0; padding: 0.55rem 1rem; cursor: pointer;
}
.result-row:hover, .result-row:focus-visible { background: var(--track); outline: none; }
.use-location { color: var(--humid); font-weight: 500; }
.use-location svg { width: 1rem; height: 1rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; }
.results .hint { padding: 0.55rem 1rem; }

/* Footer */
footer { font-size: 0.85rem; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
footer p { margin: 0; }
.link { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 0.15em; }
.link:hover { color: var(--ink); }
