:root {
  color-scheme: light;
  --page: #f3f3f1;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76756f;
  --grid: #e4e3df;
  --axis: #c9c8c2;
  --temp: #e34948;
  --hum: #2a78d6;
  --fire-1: #f6c46a;
  --fire-2: #e8862a;
  --fire-3: #b8451a;
  --fan-1: #c9c8c2;
  --fan-2: #96958e;
  --fan-3: #5c5b56;
  --sun: #d9a400;
  --wind: #1f9a8a;
  --band-alpha: 0.16;
  --accent: #d4621f;
  --danger: #c4312f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #111110;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9b9a92;
    --grid: #2c2c2a;
    --axis: #45443f;
    --temp: #e66767;
    --hum: #3987e5;
    --fire-1: #8a5a17;
    --fire-2: #d97a22;
    --fire-3: #f7b25a;
    --fan-1: #5a5953;
    --fan-2: #8b8a83;
    --fan-3: #bdbcb4;
  --sun: #f0cc4a;
  --wind: #4cc3b2;
    --sun: #f0cc4a;
    --wind: #4cc3b2;
    --band-alpha: 0.24;
    --accent: #e8862a;
    --danger: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111110;
  --surface: #1a1a19;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9b9a92;
  --grid: #2c2c2a;
  --axis: #45443f;
  --temp: #e66767;
  --hum: #3987e5;
  --fire-1: #8a5a17;
  --fire-2: #d97a22;
  --fire-3: #f7b25a;
  --fan-1: #5a5953;
  --fan-2: #8b8a83;
  --fan-3: #bdbcb4;
  --band-alpha: 0.24;
  --accent: #e8862a;
  --danger: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.95rem; margin: 0 0 8px; color: var(--text-2); font-weight: 600; }
.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 24px rgb(0 0 0 / 0.05);
}
.muted { color: var(--muted); }
.quiet { color: var(--text-2); font-size: 0.9rem; text-decoration: none; }
.quiet:hover { text-decoration: underline; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.now { padding-top: 28px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.hero-num {
  font-size: clamp(4.5rem, 18vw, 6.5rem); font-weight: 300; line-height: 1; letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
#now-updated { font-size: 0.85rem; min-height: 1.2em; }
.tiles { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 16px 0 0; }
.tiles div {
  min-width: 120px; padding: 10px 18px; border-radius: 16px; background: var(--page); text-align: center;
}
.tiles dt { color: var(--text-2); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tiles dd { margin: 4px 0 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
#devices { margin-bottom: 12px; }
.chips button, .chip-btn {
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.chips button[aria-pressed="true"], .chip-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 16px; height: 0; border-top: 2px solid; }
.key-dash { width: 16px; height: 0; border-top: 2px dashed var(--text-2); }
.key-band { width: 12px; height: 12px; border-radius: 3px; }

.chart { position: relative; width: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .empty { fill: var(--muted); font-size: 13px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--grid); border-radius: 12px;
  padding: 8px 10px; font-size: 0.82rem; min-width: 140px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.15);
}
.tip .t { color: var(--text-2); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r .lbl { color: var(--text-2); }

.table-wrap { max-height: 420px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: min(340px, 100%); display: grid; gap: 10px; }
.login h1 { margin-bottom: 6px; }
.login label { color: var(--text-2); font-size: 0.9rem; }
.login input {
  font: inherit; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--page); color: var(--text);
}
.login button {
  font: inherit; padding: 9px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.error { color: var(--danger); margin: 0; font-size: 0.9rem; }


.seg {
  display: inline-flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--page);
  width: fit-content; max-width: 100%;
}
.seg button {
  font: inherit; font-size: 0.95rem; padding: 8px 16px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-2); cursor: pointer; transition: background 0.15s, color 0.15s;
}
.seg button[aria-pressed="true"] { box-shadow: 0 1px 4px rgb(0 0 0 / 0.15); background: var(--text-2); color: var(--surface); }
.seg.fire button[data-v="low"][aria-pressed="true"] { background: var(--fire-1); color: #1a1a19; }
.seg.fire button[data-v="medium"][aria-pressed="true"] { background: var(--fire-2); color: #1a1a19; }
.seg.fire button[data-v="high"][aria-pressed="true"] { background: var(--fire-3); color: #fff; }
.seg.fan button[data-v="low"][aria-pressed="true"] { background: var(--fan-1); color: #1a1a19; }
.seg.fan button[data-v="medium"][aria-pressed="true"] { background: var(--fan-2); color: #fff; }
.seg.fan button[data-v="high"][aria-pressed="true"] { background: var(--fan-3); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .seg.fire button[data-v="low"][aria-pressed="true"],
  :root:not([data-theme="light"]) .seg.fan button[data-v="low"][aria-pressed="true"] { color: #f0efec; }
  :root:not([data-theme="light"]) .seg.fire button[data-v="high"][aria-pressed="true"],
  :root:not([data-theme="light"]) .seg.fan button[data-v="high"][aria-pressed="true"] { color: #1a1a19; }
}

.hero .fire-dot { display: inline-block; width: 0.35em; height: 0.35em; border-radius: 50%; margin-right: 0.15em; vertical-align: 0.25em; }
.hero-num { font-size: clamp(3.2rem, 14vw, 4.8rem); }
.tiles.left { justify-content: flex-start; margin: 0 0 12px; }
.tiles dd small { color: var(--muted); font-weight: 400; font-size: 0.8rem; margin-left: 4px; }

.entry { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--grid); display: grid; gap: 12px; justify-items: center; }
.entry-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.entry-row .lbl { color: var(--text-2); font-size: 0.9rem; min-width: 3em; text-align: right; }
.entry input[type="datetime-local"], .entry input[type="text"] {
  font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--axis);
  background: var(--page); color: var(--text); min-width: 0;
}
.entry input[type="text"] { width: min(320px, 70vw); }
.entry-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.entry.editing { background: var(--page); border-radius: 16px; padding: 16px 12px; border-top-color: transparent; }
.msg { margin: 0; font-size: 0.9rem; color: var(--danger); }
.msg.ok { color: var(--text-2); }
.btn-primary {
  font: inherit; padding: 9px 26px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.35; cursor: default; }
.icon-btn {
  border: 1px solid var(--axis); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.icon-btn.danger { color: var(--danger); }
.key-sw { width: 12px; height: 12px; border-radius: 3px; }
.key-dot { width: 9px; height: 9px; border-radius: 50%; }
.chart .lane { fill: var(--text-2); font-size: 11px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
#log td.note, #log th.note { text-align: left; white-space: normal; min-width: 8em; }
#log tr.sel td, #factor-table tr.sel td { background: var(--page); }
#log button { padding: 3px 10px; font-size: 0.8rem; }
#daily td.partial { color: var(--muted); }

.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.plan-head h2 { margin: 0; }
.target { display: flex; align-items: center; gap: 6px; }
.target .lbl { color: var(--text-2); font-size: 0.9rem; }
.target input {
  width: 3.4em; padding: 6px 4px; border-radius: 10px; border: 1px solid var(--axis); background: var(--page);
  color: var(--text); font: inherit; font-size: 1.15rem; font-weight: 600; text-align: center;
  -moz-appearance: textfield; appearance: textfield;
}
.target input::-webkit-outer-spin-button, .target input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.target .unit { color: var(--text-2); }
.target .icon-btn { width: 34px; height: 34px; padding: 0; font-size: 1.1rem; }
.steps { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.steps li { display: grid; grid-template-columns: 7.5em 1fr; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: var(--page); }
.steps li .tm { color: var(--text-2); font-variant-numeric: tabular-nums; }
.steps li.now { box-shadow: inset 0 0 0 1.5px var(--accent); }
.steps li .set { font-weight: 600; }
.set .fan { font-weight: 400; color: var(--text-2); margin-left: 6px; }
.steps li .act { font-weight: 600; margin-right: 8px; }
.steps li .act.after { font-weight: 400; color: var(--text-2); margin: 0 0 0 8px; }
.chip-btn:disabled { opacity: 0.4; cursor: default; }
h2.sub { margin-top: 18px; }
#plan-table, #combo-table { margin-top: 12px; }
#plan-table td:first-child, #combo-table td:first-child { white-space: nowrap; }
#plan-table tr.best td { font-weight: 600; }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
#factor-table { margin-top: 12px; }
