:root {
  --bg: #0b0b0b;
  --surface: #121212;
  --surface-2: #1b1b1b;
  --line: #2a2a2a;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --accent: #ffd600;
  --accent-soft: rgba(255, 214, 0, .14);
  --heat: #ff8a00;
  --danger: #ff6b6b;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  background-image:
    radial-gradient(900px 500px at 15% -10%, rgba(255, 214, 0, .08), transparent 60%),
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  background-attachment: fixed;
}
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.small { font-size: .78rem; }
.muted { color: var(--muted); }
.label { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .14em; font-family: var(--mono); }
h1, h2 { margin: 0; }
h1 { font-size: 1.2rem; font-weight: 650; }
h2 { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); font-family: var(--mono); }
p { margin: 0; }

.screen {
  max-width: 1080px; margin: 0 auto; min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.screen.narrow { max-width: 440px; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.logo { display: block; height: 36px; width: auto; }
.brand-url { color: var(--muted); font-size: .8rem; border-left: 1px solid var(--line); padding-left: 10px; }
.top-actions { display: flex; gap: 8px; }
.ghost { background: var(--surface-2); border: 1px solid var(--line); padding: 9px 14px; border-radius: 10px; min-height: 42px; min-width: 42px; }
.ghost:hover { border-color: var(--accent); }

.titlebar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.updated { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: .85rem; }
.chip {
  display: inline-block; margin-top: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .78rem; border: 1px solid var(--line);
}
.chip.heating { background: rgba(255, 138, 0, .16); color: var(--heat); border-color: rgba(255, 138, 0, .4); }
.chip.ok { background: var(--accent-soft); color: var(--accent); border-color: rgba(255, 214, 0, .3); }
.chip.off { color: var(--danger); background: rgba(255, 107, 107, .1); border-color: rgba(255, 107, 107, .35); }

.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.card {
  position: relative; background: linear-gradient(180deg, var(--surface), #0f0f0f);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.card::before, .card::after {
  content: ""; position: absolute; width: 14px; height: 14px; pointer-events: none;
  border: 2px solid var(--accent); opacity: .7;
}
.card::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: var(--radius); }
.card::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: var(--radius); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.hero { align-items: center; }
.gauge-wrap { position: relative; width: min(82vw, 340px); aspect-ratio: 1; }
.gauge { width: 100%; height: 100%; overflow: visible; }
.gauge .track { fill: none; stroke: var(--surface-2); stroke-width: 12; stroke-linecap: round; }
.gauge .progress { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray .4s ease, stroke .3s; filter: drop-shadow(0 0 6px rgba(255, 214, 0, .55)); }
.hero.heating .gauge .progress { stroke: var(--heat); filter: drop-shadow(0 0 8px rgba(255, 138, 0, .7)); }
.gauge .tick { stroke: #3a3a3a; stroke-width: 2; }
.gauge .tick.major { stroke: #666; stroke-width: 3; }
.gauge .scale { fill: var(--muted); font: 600 11px var(--mono); }
.gauge .now-dot { fill: #fff; stroke: var(--bg); stroke-width: 3; transition: cx .4s, cy .4s; }
.gauge .knob { fill: var(--accent); stroke: var(--bg); stroke-width: 4; transition: cx .4s, cy .4s; }
.hero.heating .gauge .knob { fill: var(--heat); }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; }
.current { font-family: var(--mono); font-size: clamp(3.4rem, 19vw, 4.8rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.current sup { font-size: .32em; vertical-align: top; position: relative; top: .5em; margin-left: 2px; color: var(--muted); }
.target-line { color: var(--accent); font-size: .95rem; }
.flame { margin-top: 6px; color: var(--heat); font: 600 .78rem var(--mono); text-transform: uppercase; letter-spacing: .14em; animation: pulse 1.6s ease-in-out infinite; }
.flame::before { content: "● "; }
@keyframes pulse { 50% { opacity: .45; } }

.stepper { display: flex; justify-content: center; gap: 26px; }
.round {
  width: 68px; height: 68px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 2rem; line-height: 1; touch-action: manipulation;
}
.round.small { width: 46px; height: 46px; font-size: 1.5rem; }
.round:active { background: var(--accent); color: #000; border-color: var(--accent); }
.segmented { display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); padding: 5px; border-radius: 12px; width: 100%; }
.segmented button { flex: 1; padding: 11px 8px; border-radius: 8px; background: transparent; min-height: 44px; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #000; font-weight: 650; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; width: 100%; }
.switch-row.inline { width: auto; }
input[role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; cursor: pointer;
  width: 54px; height: 30px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #777; transition: transform .2s, background .2s;
}
input[role="switch"]:checked { background: var(--accent-soft); border-color: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(24px); background: var(--accent); box-shadow: 0 0 10px rgba(255, 214, 0, .6); }

.ideal { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ideal-value { display: flex; flex-direction: column; align-items: center; }
.big { font-size: 2.4rem; font-weight: 700; line-height: 1.05; }
.outdoor { display: flex; align-items: baseline; gap: 10px; }
.chart { width: 100%; height: auto; }
.chart .grid-line { stroke: #232323; stroke-width: 1; }
.chart .out { fill: none; stroke: #fff; stroke-width: 2.5; }
.chart .in { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .pt-out { fill: #fff; }
.chart .pt-in { fill: var(--accent); }
.chart text { fill: var(--muted); font: 600 10px var(--mono); }
.chart text.val { fill: #fff; }
.legend { color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; row-gap: 2px; }
.key { display: inline-block; width: 18px; height: 3px; background: #fff; margin-left: 8px; }
.key.in { background: var(--accent); }

.ai-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ai-list li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.ai-list .v { font-family: var(--mono); color: var(--accent); text-align: right; white-space: nowrap; }
.plan { display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.plan-text { font-size: .95rem; }
.time { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: 1rem var(--mono); min-height: 42px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.learn { display: flex; flex-direction: column; gap: 6px; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; max-height: 360px; overflow: auto; }
.history li { display: grid; grid-template-columns: 112px 100px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; font-size: .92rem; }
.history .when { font: .8rem var(--mono); color: var(--muted); white-space: nowrap; }
.badge { justify-self: start; padding: 2px 9px; border-radius: 99px; font: 600 .72rem var(--mono); text-transform: uppercase; letter-spacing: .06em; border: 1px solid var(--line); background: var(--surface-2); }
.badge.app { color: var(--accent); border-color: rgba(255, 214, 0, .4); }
.badge.auto { color: #fff; background: rgba(255, 214, 0, .18); border-color: rgba(255, 214, 0, .5); }
.badge.presence { color: #8fd3ff; border-color: rgba(143, 211, 255, .4); }
.empty { color: var(--muted); padding: 10px 0; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: max(20px, env(safe-area-inset-bottom));
  max-width: 428px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid #333; z-index: 5;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

.login { margin: auto 0; display: flex; flex-direction: column; gap: 10px; }
.login .logo { height: 50px; margin-bottom: 6px; }
.login label { margin-top: 8px; font-size: .9rem; color: var(--muted); }
.login input {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; font-size: 1rem; width: 100%;
}
.primary { background: var(--accent); color: #000; font-weight: 700; padding: 14px; border-radius: 12px; min-height: 48px; margin-top: 8px; }
.error { color: var(--danger); }

.card { min-width: 0; }
.wide { grid-column: 1 / -1; }
@media (min-width: 680px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-column: 1 / -1; }
}
@media (min-width: 1040px) {
  .grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr); grid-auto-flow: dense; }
  .hero { grid-column: auto; grid-row: span 2; }
}
@media (max-width: 520px) {
  .history li { grid-template-columns: 70px 1fr; }
  .history .badge { grid-column: 2; grid-row: 1; justify-self: end; }
  .history .what { grid-column: 1 / -1; }
  .logo { height: 32px; }
}
@media (prefers-reduced-motion: reduce) { .flame { animation: none; } .gauge .progress, .meter span { transition: none; } }
