:root {
  --teal: #0C4444;
  --teal-2: #0f5555;
  --burg: #6F222A;
  --sand: #D0B28E;
  --cream: #FFFAF3;
  --sage: #8FA797;
  --ink: #1d2a2a;
  --muted: #5e6b69;
  --line: #e6dccd;
  --bg: #f4efe6;
  --scr: #0b2424;
  --scr-2: #123333;
  --scr-line: rgba(208, 178, 142, 0.18);
  --ok: #8FD3A8;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 22px 28px 12px;
}
.eyebrow { font-family: "DM Mono", monospace; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--burg); }
.brand h1 { margin: 4px 0 0; font-family: "Playfair Display", serif; font-weight: 500; font-size: 30px; color: var(--teal); }
.brand h1 em { font-style: normal; color: var(--muted); font-size: 20px; }
.top-controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; color: var(--muted); font-size: 13px; }
.seg button.on { background: var(--teal); color: var(--cream); }
.load { display: flex; flex-direction: column; align-items: flex-end; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; min-width: 110px; }
.load-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.load-val { font-family: "DM Mono", monospace; font-size: 16px; color: var(--teal); }

.home-scenes { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 0 28px 14px; }
.hs-label { font-family: "DM Mono", monospace; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.home-scenes button {
  border: 1px solid var(--sand); background: var(--cream); color: var(--teal);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  transition: background .2s, color .2s;
}
.home-scenes button:hover { background: var(--teal); color: var(--cream); border-color: var(--teal); }
.home-scenes button.flash { background: var(--teal); color: var(--cream); }

/* ---------- stage ---------- */
.stage {
  display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 28px;
  padding: 0 28px 20px; align-items: start;
}
.plan-wrap { display: flex; flex-direction: column; align-items: center; min-width: 0; }
#plan {
  width: 100%; max-height: calc(100vh - 170px); min-height: 420px;
  border-radius: 18px; background: #efe9df;
  box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px rgba(12, 68, 68, .45);
  user-select: none; -webkit-user-select: none;
}
.plan-hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* svg layers */
.dark-layer { transition: none; }
.zone-dark { transition: fill-opacity .9s ease; }
.glow { mix-blend-mode: screen; transition: opacity .9s ease; pointer-events: none; }
.zone-hit { fill: transparent; cursor: pointer; }
.zone-sel { fill: none; stroke: var(--sand); stroke-width: 6; stroke-dasharray: 18 12; opacity: 0; transition: opacity .3s; pointer-events: none; }
.zone-sel.on { opacity: .95; }
.zone-label { font-family: "DM Mono", monospace; font-size: 24px; letter-spacing: 3px; fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 4px; opacity: .0; transition: opacity .4s; pointer-events: none; text-transform: uppercase; }
.zone-label.show { opacity: .85; }

.fix { cursor: pointer; }
.fix .ring { fill: rgba(255,255,255,.92); stroke: var(--teal); stroke-width: 3; transition: fill .3s, stroke .3s; }
.fix .txt { font-family: "DM Mono", monospace; font-size: 17px; font-weight: 500; fill: var(--teal); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.fix.on .ring { fill: #ffd98a; stroke: #b5762b; }
.fix.on .txt { fill: #5b3a10; }
.fix.cool.on .ring { fill: #cfeaff; stroke: #3f7fae; }
.fix.cool.on .txt { fill: #18456a; }
.fix.hot.on .ring { fill: #ffc7b8; stroke: var(--burg); }
.fix.hot.on .txt { fill: var(--burg); }
.fix.fixed .ring { stroke: var(--sage); stroke-dasharray: 5 4; }
.fix.pending .ring { stroke: var(--sand); stroke-dasharray: 6 5; animation: spin 1s linear infinite; transform-box: fill-box; transform-origin: center; }
.fix:hover .ring { stroke-width: 5; }

.pulse { fill: none; stroke: var(--burg); stroke-width: 4; transform-box: fill-box; transform-origin: center; animation: pulse 1.6s ease-out infinite; }

.fan-blades { transform-box: fill-box; transform-origin: center; animation: spin var(--fan-dur, 1s) linear infinite; animation-play-state: paused; }
.fan-blades.on { animation-play-state: running; }
.fan-blades path { fill: rgba(255,255,255,.85); stroke: var(--teal); stroke-width: 2.5; }

.air path { fill: none; stroke: #9fd6ff; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 14 22; opacity: 0; transition: opacity .6s; animation: flow 1.1s linear infinite; }
.air.on path { opacity: .85; }
.tvglow { opacity: 0; transition: opacity .6s; pointer-events: none; }
.tvglow.on { opacity: 1; animation: flicker 2.4s steps(6) infinite; }

.curtain { fill: url(#fabric); stroke: rgba(111,34,42,.35); stroke-width: 1.5; transform-box: fill-box; transition: transform 1.6s cubic-bezier(.5,0,.2,1); }

.sos-flash { fill: none; stroke: #e2433b; stroke-width: 26; opacity: 0; pointer-events: none; }
.sos-flash.on { animation: sosflash 1s ease-in-out infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(2.2); opacity: 0; } }
@keyframes flow { to { stroke-dashoffset: -72; } }
@keyframes flicker { 0%,100% { opacity: .95; } 30% { opacity: .75; } 55% { opacity: 1; } 80% { opacity: .82; } }
@keyframes sosflash { 0%,100% { opacity: 0; } 50% { opacity: .8; } }

/* ---------- panel ---------- */
.panel-col { position: sticky; top: 14px; }
.room-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.room-tabs button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 7px 12px; border-radius: 10px; font-size: 13px;
}
.room-tabs button[aria-selected="true"] { background: var(--teal); border-color: var(--teal); color: var(--cream); }

.bezel {
  background: linear-gradient(160deg, #2b2b2b, #111 60%);
  border-radius: 26px; padding: 14px;
  box-shadow: 0 24px 50px -28px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.08);
}
.screen {
  background: radial-gradient(120% 80% at 0% 0%, var(--scr-2), var(--scr) 60%);
  border-radius: 14px; padding: 16px; color: var(--cream);
  min-height: 560px; display: flex; flex-direction: column; gap: 12px;
}
.scr-head { display: flex; justify-content: space-between; align-items: flex-start; }
.scr-room { font-family: "Playfair Display", serif; font-size: 24px; }
.scr-meta { font-family: "DM Mono", monospace; font-size: 12px; color: var(--sand); margin-top: 2px; }
.sos {
  border: 0; background: #c2362f; color: #fff; font-weight: 600; letter-spacing: .1em;
  width: 52px; height: 52px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(194,54,47,.25);
}
.sos:hover { box-shadow: 0 0 0 7px rgba(194,54,47,.3); }

.scr-scenes { display: flex; gap: 6px; flex-wrap: wrap; }
.scr-scenes button {
  border: 1px solid var(--scr-line); background: rgba(255,255,255,.04); color: var(--cream);
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
}
.scr-scenes button:hover, .scr-scenes button.flash { background: var(--sand); color: var(--teal); border-color: var(--sand); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; grid-auto-flow: row dense; }
.tile {
  background: rgba(255,255,255,.05); border: 1px solid var(--scr-line); border-radius: 12px;
  padding: 10px 11px; display: flex; flex-direction: column; gap: 7px; min-height: 92px;
  transition: background .3s, border-color .3s;
}
.tile.on { background: rgba(208,178,142,.16); border-color: rgba(208,178,142,.55); }
.tile.wide { grid-column: span 2; }
.t-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.t-name { font-size: 13.5px; font-weight: 600; line-height: 1.2; }
.t-cls { font-family: "DM Mono", monospace; font-size: 9.5px; letter-spacing: .08em; color: var(--sage); border: 1px solid rgba(143,167,151,.4); border-radius: 5px; padding: 1px 5px; white-space: nowrap; }
.t-state { font-family: "DM Mono", monospace; font-size: 11px; color: var(--sand); min-height: 14px; }
.t-state.ok { color: var(--ok); }
.tile.pending .t-state { color: #ffd98a; }
.t-ctl { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: auto; }

.pw {
  width: 40px; height: 24px; border-radius: 999px; border: 0; padding: 0; position: relative;
  background: rgba(255,255,255,.18); transition: background .25s; flex: none;
}
.pw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .25s; }
.pw.on { background: var(--sand); }
.pw.on::after { transform: translateX(16px); }

.rng { flex: 1; min-width: 60px; accent-color: var(--sand); }
.chip, .step {
  border: 1px solid var(--scr-line); background: transparent; color: var(--cream);
  font-size: 11.5px; padding: 3px 8px; border-radius: 7px;
}
.chip.on { background: var(--sand); color: var(--teal); border-color: var(--sand); }
.step { width: 26px; height: 26px; padding: 0; font-size: 15px; }
.tval { font-family: "DM Mono", monospace; font-size: 15px; min-width: 34px; text-align: center; }

.assistant { margin-top: auto; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--scr-line); padding-top: 12px; }
.bubble { background: rgba(208,178,142,.14); border: 1px solid rgba(208,178,142,.35); border-radius: 12px 12px 12px 4px; padding: 9px 12px; font-size: 13.5px; line-height: 1.4; }
.bubble .you { display: block; font-family: "DM Mono", monospace; font-size: 11px; color: var(--sand); margin-bottom: 4px; }
.bubble .thinking { color: var(--sand); animation: think 1.2s ease-in-out infinite; }
@keyframes think { 50% { opacity: .4; } }
.ask { display: flex; gap: 8px; }
.mic {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0;
  background: var(--sand); color: var(--teal); display: grid; place-items: center;
}
.mic.listening { background: #c2362f; color: #fff; animation: micpulse 1.2s ease-in-out infinite; }
@keyframes micpulse { 50% { box-shadow: 0 0 0 8px rgba(194,54,47,.25); } }
.ask input {
  flex: 1; min-width: 0; background: rgba(255,255,255,.07); border: 1px solid var(--scr-line); color: var(--cream);
  border-radius: 999px; padding: 0 14px; font: inherit; font-size: 13.5px; outline: none;
}
.ask input::placeholder { color: rgba(255,250,243,.45); }
.ask input:focus { border-color: var(--sand); }
.try { display: flex; gap: 6px; flex-wrap: wrap; }
.try button { border: 0; background: rgba(255,255,255,.06); color: rgba(255,250,243,.75); font-size: 11.5px; padding: 4px 9px; border-radius: 999px; }
.try button:hover { background: rgba(255,255,255,.14); color: var(--cream); }
.panel-note { font-size: 12.5px; color: var(--muted); text-align: center; margin: 10px 0 0; }

/* ---------- under the hood ---------- */
.hood { padding: 0 28px 40px; }
.hood details { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
.hood summary { cursor: pointer; font-weight: 600; color: var(--teal); }
.hood summary span { font-weight: 400; color: var(--muted); font-size: 13px; }
.log { list-style: none; margin: 12px 0 0; padding: 0; font-family: "DM Mono", monospace; font-size: 12px; max-height: 280px; overflow: auto; }
.log li { display: grid; grid-template-columns: 70px 20px minmax(180px, 300px) 1fr; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--line); color: var(--ink); }
.log .ts { color: var(--muted); }
.log .dir.out { color: var(--burg); }
.log .dir.in { color: var(--teal); }
.log .topic { color: var(--teal); overflow-wrap: anywhere; }
.log .pl { color: var(--muted); overflow-wrap: anywhere; }
.log li.alert .topic, .log li.alert .pl { color: #c2362f; }

/* ---------- SOS ---------- */
.sos-modal { position: fixed; inset: 0; background: rgba(20, 8, 8, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.sos-modal[hidden] { display: none; }
.sos-card { position: relative; background: var(--cream); border-radius: 18px; padding: 28px 26px 22px; max-width: 400px; text-align: center; overflow: hidden; }
.sos-card h2 { font-family: "Playfair Display", serif; font-weight: 500; color: #c2362f; margin: 8px 0 8px; font-size: 28px; }
.sos-card p { color: var(--ink); line-height: 1.5; font-size: 14.5px; }
.sos-card button { border: 0; background: var(--teal); color: var(--cream); padding: 11px 18px; border-radius: 999px; font-weight: 600; }
.sos-pulse { width: 18px; height: 18px; border-radius: 50%; background: #c2362f; margin: 0 auto; box-shadow: 0 0 0 0 rgba(194,54,47,.6); animation: sosdot 1.2s infinite; }
@keyframes sosdot { to { box-shadow: 0 0 0 22px rgba(194,54,47,0); } }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .stage { grid-template-columns: 1fr; }
  .panel-col { position: static; max-width: 520px; width: 100%; margin: 0 auto; }
  #plan { max-height: none; }
}
@media (max-width: 560px) {
  .top { padding: 16px 16px 10px; }
  .brand h1 { font-size: 24px; }
  .brand h1 em { font-size: 16px; }
  .home-scenes, .stage, .hood { padding-left: 16px; padding-right: 16px; }
  .home-scenes button { padding: 7px 11px; font-size: 12.5px; }
  .screen { padding: 12px; min-height: 0; }
  .bezel { padding: 10px; border-radius: 20px; }
  .log li { grid-template-columns: 60px 16px 1fr; }
  .log .pl { grid-column: 3; }
}
@media (prefers-reduced-motion: reduce) {
  .fan-blades.on, .air path, .tvglow.on, .pulse, .sos-flash.on { animation: none; }
}
