:root {
    --bg: #070d18;
    --card: #121a2b;
    --card-on: #17304a;
    --line: rgba(160, 190, 230, 0.14);
    --text: #e8eef8;
    --muted: #8ea0bb;
    --gold: #7eb6ff;
    --gold-2: #d6e8ff;
    --ink: #071018;
    --teal: #5ee0c2;
    --alert: #f0b45a;
    --ok: #3ddc97;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    --sans: "Segoe UI", system-ui, sans-serif;
    --serif: "Segoe UI", system-ui, sans-serif;
    --pad: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    touch-action: manipulation;
}

body {
    background:
        radial-gradient(900px 420px at 10% -10%, rgba(61, 139, 253, 0.16), transparent 60%),
        radial-gradient(680px 360px at 110% 0%, rgba(62, 198, 224, 0.08), transparent 55%),
        var(--bg);
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.stage {
    flex: 1;
    min-width: 0;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}

input, textarea { user-select: text; }

.boot {
    margin: auto;
    color: var(--muted);
    letter-spacing: 0.04em;
}

.frame {
    height: 100%;
    height: 100dvh;
    display: flex;
    overflow: hidden;
}

.rail {
    width: 84px;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: calc(10px + env(safe-area-inset-top)) 6px 12px;
    background: #0b1220;
    border-right: 1px solid var(--line);
    overflow: auto;
    scrollbar-width: none;
}

.rail::-webkit-scrollbar { display: none; }

.rail button {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 14px;
    padding: 8px 2px 7px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    line-height: 1.1;
}

.rail button svg { width: 22px; height: 22px; }

.rail button.active {
    color: #fff;
    background: #163056;
}

.top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) var(--pad) 8px;
}

.top-row, .status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    margin: 0;
    font-size: 13px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--gold);
}

.hello {
    text-align: right;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    align-items: center;
}
.hello .greet, .hello .subgreet { width: 100%; }
.pill { margin-top: 8px; }

.greet {
    margin: 0;
    font-size: 18px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.subgreet {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.clock {
    margin: 0;
    font-weight: 650;
    font-size: 32px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.date-line {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    margin-top: 8px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--alert);
}

.pill.online .dot { background: var(--ok); }
.pill.online { color: var(--ok); }

.icon-btn, .text-btn, .ghost, .solid, .mini {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 14px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
}

.icon-btn svg { width: 18px; height: 18px; }

.text-btn, .ghost, .solid, .mini {
    min-height: 42px;
    padding: 0 14px;
}

.text-btn.on, .solid {
    background: var(--gold);
    color: var(--ink);
    border-color: transparent;
    font-weight: 650;
}

.rooms {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px var(--pad) 12px;
    scrollbar-width: none;
}

.rooms::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
}

.chip.active {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--ink);
    font-weight: 650;
}

.scroll {
    flex: 1;
    overflow: auto;
    padding: 0 var(--pad) 18px;
    scrollbar-width: none;
}

.scroll::-webkit-scrollbar { display: none; }

.charts {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}

.chart-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 14px 14px 10px;
}

.chart-head, .chart-times, .chart-legend {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.chart-kicker {
    display: block;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.chart-now {
    margin: 2px 0 0;
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1;
}

.chart-now.split {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-family: var(--sans);
    font-size: 16px;
    letter-spacing: 0;
    font-weight: 650;
}

.chart-range, .chart-times, .chart-empty {
    color: var(--muted);
    font-size: 12px;
}

.chart-card svg, svg.spark {
    width: 100%;
    height: 132px;
    display: block;
    margin-top: 8px;
}

.chart-card path,
.chart-card polyline {
    vector-effect: non-scaling-stroke;
}

.chart-times { margin-top: 2px; }

.chart-legend {
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 6px;
    color: var(--text);
    font-size: 13px;
}

.chart-legend i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.chart-empty { margin: 18px 0 12px; }

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.metric {
    padding: 10px 12px 12px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
}

.metric b {
    display: block;
    font-family: var(--serif);
    font-size: 30px;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1;
}

.metric span, .metric small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.metric small {
    letter-spacing: 0;
    text-transform: none;
    font-size: 12px;
}

.people {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 12px;
    scrollbar-width: none;
}

.people::-webkit-scrollbar { display: none; }

.person {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 5px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    white-space: nowrap;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #2c2820;
    color: var(--gold);
    font-size: 11px;
    font-weight: 700;
}

.person.home .avatar { background: var(--gold); color: var(--ink); }

.person em {
    font-style: normal;
    color: var(--muted);
    font-size: 12px;
}

.alerts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.alert, .quiet {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 14px;
}

.alert {
    margin: 0;
    background: rgba(231, 162, 122, 0.14);
    color: var(--alert);
}

.quiet { color: var(--ok); background: rgba(197, 221, 171, 0.08); }

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 14px;
    min-width: 0;
}

.card.wide { grid-column: 1 / -1; }

.card.is-on {
    background: var(--card-on);
    border-color: rgba(228, 194, 122, 0.45);
}

.card.is-alert { border-color: rgba(231, 162, 122, 0.7); }

.card.is-climate.is-on { border-color: rgba(158, 217, 207, 0.45); }

.hit {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    min-height: 52px;
}

.ico {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
}

.ico svg { width: 24px; height: 24px; }

.card.is-on .ico { background: var(--gold); color: var(--ink); }
.card.is-alert .ico { background: var(--alert); color: var(--ink); }
.card.is-climate.is-on .ico { background: var(--teal); color: var(--ink); }

.name {
    display: block;
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -0.015em;
    line-height: 1.15;
}

.sub {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.where {
    display: block;
    margin-top: 2px;
    color: var(--gold);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.extra { margin-top: 12px; }

.card:not(.is-on) .when-on { display: none; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 28px;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.16);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    margin-top: -8px;
    border-radius: 50%;
    background: var(--text);
    border: 0;
}

.range-ends, .thirds, .modes, .vac, .edit-actions {
    display: flex;
    gap: 8px;
}

.range-ends {
    justify-content: space-between;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.presets { display: flex; gap: 8px; margin-top: 8px; }

.swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.45);
    padding: 0;
}

.thirds { margin-top: 12px; }
.thirds button, .modes button, .vac button, .mini {
    flex: 1;
    min-height: 44px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
}

.modes { flex-wrap: wrap; margin-top: 12px; }
.modes button.on { background: var(--teal); color: var(--ink); border-color: transparent; }

.climate, .stepper { display: flex; align-items: center; }
.climate { justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.climate .ico { display: inline-grid; vertical-align: middle; margin-right: 8px; }
.stepper { gap: 8px; }
.stepper button {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    font-size: 24px;
}
.big, .set {
    font-family: var(--serif);
    font-weight: 500;
    letter-spacing: -0.03em;
}
.big { font-size: 42px; line-height: 1; }
.set { min-width: 64px; text-align: center; font-size: 28px; }

.cam { padding: 0; overflow: hidden; }
.cam img {
    display: block;
    width: 100%;
    height: 210px;
    object-fit: cover;
    background: #090807;
}
.cap { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px 12px; }

.scene-hit { justify-content: center; }
.scene-hit .name { text-align: center; }

.empty {
    padding: 28px 8px 10px;
    text-align: center;
    color: var(--muted);
}

.empty .solid { margin-top: 14px; }

.dock {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px var(--pad) calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(18, 17, 14, 0.92);
    scrollbar-width: none;
}

.dock::-webkit-scrollbar { display: none; }
.dock[hidden] { display: none; }

.scene {
    flex: 1 0 120px;
    min-height: 56px;
    border-radius: 16px;
    border: 1px solid rgba(228, 194, 122, 0.28);
    background: #2a261c;
    color: var(--gold-2);
}

.tools { margin-bottom: 12px; }
.tools[hidden] { display: none; }

.tools details {
    margin-bottom: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    padding: 10px 12px;
}

.tools summary { cursor: pointer; font-weight: 650; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.catalog-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.catalog-row span { flex: 1; min-width: 0; }
.catalog-row strong, .catalog-row small { display: block; }
.catalog-row small { color: var(--muted); font-size: 12px; }
.catalog-row .mini { flex: 0 0 auto; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 8px; }

.stack input, .stack select, .edit-row input, .edit-row select, .setup input {
    width: 100%;
    min-height: 46px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #16140f;
    padding: 0 12px;
}

.field span.token-line { display: flex; flex-wrap: nowrap; gap: 8px; margin-bottom: 0; }
.token-line input { width: auto; min-width: 0; flex: 1; }
.token-line .ghost { flex: 0 0 auto; }

.room-line { display: flex; gap: 8px; align-items: center; }
.room-line input { flex: 1; }

.edit-row {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 18px;
    background: var(--card);
    border: 1px solid var(--line);
}

.edit-row small { color: var(--muted); }

.edit-actions { flex-wrap: wrap; }
.edit-actions .mini { min-width: 70px; }

.banner {
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(231, 162, 122, 0.12);
    color: var(--alert);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 25;
    padding: 14px 16px;
    border-radius: 16px;
    background: #2c271e;
    border: 1px solid rgba(228, 194, 122, 0.4);
    box-shadow: var(--shadow);
    transform: translateY(140%);
    transition: transform 0.25s ease;
}

body.has-dock .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
.toast.show { transform: translateY(0); }

.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: end center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.55);
}

.modal[hidden] { display: none; }

.modal article {
    width: min(440px, 100%);
    margin-bottom: calc(8px + env(safe-area-inset-bottom));
    padding: 22px 18px 18px;
    border-radius: 24px;
    background: #121a2b;
    border: 1px solid var(--line);
}

.modal p {
    margin: 0 0 16px;
    font-family: var(--serif);
    font-size: 28px;
    line-height: 1.15;
}

.modal .row button { flex: 1; min-height: 48px; border-radius: 14px; }

.setup {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: flex;
    align-items: flex-end;
    overflow: auto;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(7, 13, 24, 0.97) 18%, rgba(7, 13, 24, 0.35));
}

.setup[hidden] { display: none; }

.setup form, .setup .db-error {
    width: min(560px, 100%);
    margin: 0 auto;
    padding: 22px 18px 18px;
    border-radius: 28px;
    background: #121a2b;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.setup h2 {
    margin: 0 0 6px;
    font-family: var(--serif);
    font-size: 34px;
    font-weight: 500;
}

.setup p, .hint { margin: 0 0 14px; color: var(--muted); line-height: 1.4; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--gold-2); }

.token-line { display: flex; gap: 8px; }
.token-line input { flex: 1; }

.setup .solid, .stack .solid { width: 100%; min-height: 50px; border-radius: 16px; margin-top: 4px; }

.db-error { color: var(--alert); }

.home {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.hcard {
    min-width: 0;
    padding: 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, #162033, #101826);
    border: 1px solid var(--line);
}

.span2 { grid-column: 1 / -1; }

.hhead {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.hhead .who {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
}

.hhead svg { width: 18px; height: 18px; color: var(--gold); }

.tag {
    font-size: 12px;
    color: var(--ok);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex: none;
}

.tag::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.tag.warn { color: var(--alert); }
.tag.muted { color: var(--muted); }

.hero-card { padding: 0; overflow: hidden; display: grid; grid-template-columns: 1.05fr 0.95fr; }
.hero-copy { padding: 16px 14px 8px; }
.place { margin: 0; color: var(--muted); font-size: 14px; }
.wx { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.wx b { font-size: 52px; letter-spacing: -0.04em; line-height: 0.9; font-weight: 650; }
.wx svg { width: 34px; height: 34px; color: #f6c453; }
.wx-label { margin: 8px 0 0; font-size: 15px; }
.wx-meta { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.hero-art { position: relative; min-height: 150px; background: linear-gradient(180deg, #1a3a62, #0c1c30 70%); }
.hero-art svg { width: 100%; height: 100%; display: block; }
.hours {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px 12px 12px;
    border-top: 1px solid var(--line);
}
.hour { text-align: center; color: var(--muted); font-size: 12px; }
.hour b { display: block; color: var(--text); font-size: 14px; margin-top: 2px; }
.hour svg { width: 16px; height: 16px; }

.pool-water, .car-art {
    height: 92px;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
}
.pool-water {
    background:
        radial-gradient(80px 30px at 20% 70%, rgba(255,255,255,0.2), transparent 70%),
        linear-gradient(180deg, #1f6f86, #0d3c4d 60%, #082833);
}
.car-art {
    background: radial-gradient(120px 60px at 70% 60%, rgba(80, 140, 220, 0.35), transparent 70%), #0d1726;
    display: grid;
    place-items: center;
}
.car-art svg { width: 86%; height: 70px; }

.trio, .duo {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.duo { grid-template-columns: 1fr 1fr; }
.stat { min-width: 0; }
.stat b { display: block; font-size: 15px; letter-spacing: -0.03em; }
.stat span, .stat small { display: block; color: var(--muted); font-size: 11px; line-height: 1.25; }
.stat small { margin-top: 1px; }

.big-num { margin: 0; font-size: 40px; letter-spacing: -0.04em; font-weight: 650; line-height: 1; white-space: nowrap; }
.big-num span { font-size: 18px; color: var(--muted); margin-left: 4px; font-weight: 500; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 78px; margin: 12px 0; }
.bars .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bars i { display: block; width: 70%; border-radius: 3px 3px 0 0; background: linear-gradient(#d7f5a2, #3f9a4e); }
.bars em { font-style: normal; font-size: 9px; color: var(--muted); height: 12px; margin-top: 3px; }

.meter { height: 10px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; margin: 8px 0 12px; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #1f8f4e, #3ddc97); }
.meter.warn i { background: linear-gradient(90deg, #a86a12, #f0b45a); }

.quick-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.quick {
    min-height: 64px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #121a2b;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    text-align: left;
    color: var(--text);
}
.quick svg { width: 20px; height: 20px; flex: none; color: var(--gold); }
.quick.on { background: #163056; border-color: #2d5f99; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list article {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #121a2b;
    border: 1px solid var(--line);
}
.list .bad { color: var(--alert); }
.scene-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scene-grid button {
    min-height: 64px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #121a2b;
}

#view[hidden], #board[hidden], #rooms[hidden], #hero[hidden], #alerts[hidden] { display: none; }

@media (max-width: 720px) {
    .rail { width: 68px; }
    .home { grid-template-columns: 1fr; }
    .hero-card { grid-template-columns: 1fr 0.8fr; }
    .big-num { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
