:root {
  color-scheme: dark;
  color: #f1f2ea;
  background: #171b17;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  --surface: #19201bee;
  --ink: #f1f2ea;
  --muted: #c1c9bd;
  --rule: #b8c4b333;
  --accent: #d9edb4;
  --accent-ink: #222b1b;
  --pad: clamp(16px, 2.5vw, 38px);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button { color: inherit; font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
button:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.experience {
  position: relative;
  isolation: isolate;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.viewport { position: absolute; inset: 0; background: #363e37; }
.viewport:focus-visible { outline-offset: -3px; }
.viewport canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.viewport canvas:active { cursor: grabbing; }
.kitchen-portfolio-link { display: inline-block; text-decoration: none; pointer-events: auto; }
.kitchen-portfolio-link:hover { text-decoration: underline; text-underline-offset: .2em; }
.scene-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.experience::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, #101710b8, #1017104d 100px, #10171000 220px),
    linear-gradient(0deg, #10171070, #10171000 145px);
}

.top-overlay, .bottom-overlay {
  position: absolute;
  inset-inline: max(var(--pad), env(safe-area-inset-left)) max(var(--pad), env(safe-area-inset-right));
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  pointer-events: none;
}
.top-overlay { top: max(var(--pad), env(safe-area-inset-top)); align-items: flex-start; }
.bottom-overlay { bottom: max(var(--pad), env(safe-area-inset-bottom)); align-items: flex-end; }
.scene-heading { position: relative; isolation: isolate; max-width: 490px; text-shadow: 0 1px 4px #10191080; }
.scene-heading::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: calc(-1 * max(var(--pad), env(safe-area-inset-top))) -54px -12px calc(-1 * max(var(--pad), env(safe-area-inset-left)));
  background: linear-gradient(90deg, #171e18ee, #171e18d9 calc(100% - 78px), transparent);
  mask-image: linear-gradient(#000 calc(100% - 22px), transparent);
}
.scene-heading:has(#scene-intro[hidden])::before { display: none; }
.lab-name {
  margin: 0 0 .45rem;
  color: var(--accent);
  font-size: .76rem;
  font-weight: 720;
  letter-spacing: .09em;
}
.scene-heading h1 {
  margin: 0;
  font-size: clamp(1.9rem, 4.2vw, 4.25rem);
  line-height: .97;
  font-weight: 580;
  letter-spacing: -.065em;
}
.scene-description, .scene-lab-context { margin: .55rem 0 0; max-width: 52ch; color: #e3e7dd; font-size: .92rem; line-height: 1.35; }
.scene-lab-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  color: var(--accent);
  font-size: .85rem;
  font-weight: 650;
  text-underline-offset: .2em;
  pointer-events: auto;
}
.scene-lab-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.scene-toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.scene-toolbar button, .controls, .scene-tools button {
  border: 1px solid var(--rule);
  background: var(--surface);
  pointer-events: auto;
}
.segmented {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  pointer-events: auto;
}
.scene-toolbar .segmented button {
  min-height: 38px;
  padding: 6px 11px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
}
.scene-toolbar button, .scene-tools { font-size: .83rem; }
.scene-toolbar .segmented button[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 675;
}
.toolbar-button {
  min-height: 46px;
  border-radius: 8px;
  padding: 5px 11px;
  white-space: nowrap;
}
.toolbar-button:hover, .scene-toolbar .segmented button[aria-pressed="false"]:hover {
  background: #344237;
}

.scene-tools { align-self: end; color: #e0e5da; }
.scene-hint {
  width: fit-content;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--surface);
  line-height: 1.35;
}
.walk-controls {
  width: max-content;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(3, 43px);
  gap: 4px;
}
.walk-controls button {
  min-height: 43px;
  border-radius: 6px;
  font-size: 1.18rem;
  touch-action: none;
  user-select: none;
}
.walk-controls button:hover, .walk-controls button:active { background: #4d604a; }
.walk-controls button:first-child { grid-column: 2; }
.walk-controls button:nth-child(2) { grid-column: 1; }

.controls {
  width: min(100%, 304px);
  flex: 0 0 auto;
  max-height: calc(100dvh - 147px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  border-radius: 12px;
  box-shadow: 0 12px 28px #080e0960;
  backdrop-filter: blur(10px);
}
.display, .appliances { padding: 13px 15px; }
.display { border-bottom: 1px solid var(--rule); }
.display-top { display: flex; justify-content: space-between; align-items: center; gap: 7px; }
.section-label {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 575;
  line-height: 1.25;
}
.display-head { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.display-head h2 { margin: 0; line-height: 1.08; font-size: 1.43rem; letter-spacing: -.045em; font-weight: 580; }
.signal { width: 8px; height: 8px; border-radius: 50%; background: #899688; flex: none; }
.signal[data-mode=alert] { background: #ffa36c; }
.signal[data-mode=confirm] { background: #b7ed9c; }
.signal[data-mode=coffee] { background: #e7b27c; }
.signal[data-mode=dishwasher], .signal[data-mode=dishwasherComplete] { background: #6ea9ff; }
.display-detail { margin: 6px 0 0; color: var(--muted); font-size: .83rem; line-height: 1.3; min-height: 2.6em; }
.tile-preview { display: grid; grid-template-columns: repeat(9, 11px); gap: 2px; align-items: start; min-height: 19px; }
.tile-preview i { display: block; width: 13px; height: 11px; background: #4a5548; clip-path: polygon(50% 0%, 100% 100%, 0% 100%); }
.tile-preview .down { transform: rotate(180deg); }
.tile-preview .lower { margin-top: 8px; }
.tile-preview [data-current] { animation: dishwasher-pulse .54s ease-in-out infinite alternate; }
@keyframes dishwasher-pulse { from { opacity: 0.45; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tile-preview [data-current] { animation: none; } }

.appliances { padding-block: 1px; }
.device-list { margin: 0; }
.device { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; padding: 10px 0; }
.device + .device { border-top: 1px solid var(--rule); }
.device dt { font-size: .92rem; font-weight: 620; }
.device-name { display: flex; align-items: center; gap: 4px; }
.device-info {
  display: inline-grid;
  place-items: center;
  width: 24px;
  min-height: 25px;
  border: 0;
  padding: 0;
  color: var(--accent);
  background: transparent;
  font: 650 .72rem Georgia, serif;
  position: relative;
}
.device-info::before { content: ""; position: absolute; width: 14px; height: 14px; border: 1px solid currentColor; border-radius: 50%; }
.device-info:hover, .device-info[aria-expanded="true"] { background: #43543c; border-radius: 4px; }
.device dd { margin: 0; }
.device-state { grid-column: 1; font-size: .79rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.device-action { grid-column: 2; grid-row: 1 / span 2; }
.device-action button, .text-button {
  min-height: 39px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 5px 9px;
  background: #323d31;
  font-size: .8rem;
}
.device-action button { min-width: 84px; }
.device-action button:hover, .text-button:hover { background: #455743; }
.dishwasher-actions { display: grid; gap: 4px; }
.dishwasher-load {
  position: absolute;
  z-index: 3;
  left: var(--load-x);
  top: var(--load-y);
  transform: translate(-50%, -50%);
  min-height: 44px;
  padding: 7px 13px;
  border: 1px solid #f1f4d7;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 16px #11181180;
  font-size: .85rem;
  font-weight: 680;
  white-space: nowrap;
}
.dishwasher-load:hover, #dishwasher-load-fallback:hover { background: #e8f6ce; }
#dishwasher-load-fallback { background: var(--accent); color: var(--accent-ink); font-weight: 680; }
.meter-shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding-top: 8px; border-top: 1px solid var(--rule); }
.meter-shortcuts button { min-height: 36px; padding: 3px 2px; border-radius: 6px; border: 1px solid var(--rule); background: transparent; color: var(--muted); font-size: .78rem; }
.meter-shortcuts button:hover, .meter-shortcuts button[aria-expanded="true"] { color: var(--accent); background: #344237; }
#fridge-button { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 680; }
#fridge-button:hover { background: #e8f6ce; }
.activity { border-top: 1px solid var(--rule); }
.activity summary {
  display: flex;
  align-items: center;
  min-height: 43px;
  gap: 8px;
  padding: 4px 15px;
  cursor: pointer;
  font-size: .81rem;
  font-weight: 585;
  list-style: none;
}
.activity summary::-webkit-details-marker { display: none; }
.activity summary::before { content: "+"; width: 11px; color: var(--accent); font-size: 1rem; font-weight: 400; }
.activity[open] summary::before { content: "−"; }
.activity summary:hover { background: #39463878; }
.activity summary:focus-visible { outline-offset: -3px; }
.latest-event {
  margin-inline-start: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .77rem;
  font-weight: 400;
}
.activity[open] .latest-event { visibility: hidden; }
.activity-body { padding: 0 15px 11px; }
.activity ol { margin: 0 0 5px; padding: 0; list-style: none; color: var(--muted); font-size: .8rem; line-height: 1.40; }
.activity li { margin-bottom: 4px; }
.activity time { margin-inline-end: 7px; color: var(--accent); font: .75rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.activity .text-button { margin-inline-start: -5px; border-color: transparent; background: transparent; color: var(--muted); }
.activity .text-button:hover { background: #39463878; color: var(--ink); }

.telemetry-card {
  position: absolute;
  z-index: 3;
  left: var(--card-x, 12px);
  top: var(--card-y, 12px);
  width: min(248px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px 15px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 30px #080e0980;
  font-size: .84rem;
  pointer-events: none;
}
.telemetry-card[data-pinned] { pointer-events: auto; }
.telemetry-card[data-appliance="server"] { width: min(278px, calc(100% - 24px)); }
.telemetry-card[data-appliance="server"] .section-label { display: none; }
.telemetry-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.telemetry-top h2 { margin: 4px 0 0; font-size: 1.25rem; line-height: 1.12; font-weight: 610; letter-spacing: -.034em; }
.telemetry-close { padding: 0; min-width: 36px; min-height: 36px; font-size: 1.22rem; }
.telemetry-readings { margin: 11px 0 0; }
.telemetry-readings > div { display: flex; justify-content: space-between; gap: 9px; padding: 7px 0; border-top: 1px solid var(--rule); }
.telemetry-readings dt { color: var(--muted); }
.telemetry-readings dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 620; }
.telemetry-card[data-appliance="server"] .telemetry-readings dd { white-space: nowrap; }
.telemetry-energy { border-top: 1px solid var(--rule); }
.telemetry-energy summary { padding: 10px 0; color: var(--accent); cursor: pointer; }
.telemetry-energy .telemetry-readings { margin: 0; }
.telemetry-history { padding: 10px 0; border-top: 1px solid var(--rule); }
.telemetry-history h3 { margin: 0 0 8px; font-size: .79rem; font-weight: 620; }
.telemetry-history p { margin: 6px 0 0; color: var(--muted); font-size: .68rem; }
.telemetry-chart {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 7px;
  color: var(--muted);
  font-size: .65rem;
  font-variant-numeric: tabular-nums;
}
.telemetry-chart-scale, .telemetry-chart-times { display: flex; justify-content: space-between; gap: 4px; }
.telemetry-chart-scale { flex-direction: column; text-align: right; }
.telemetry-chart-times { grid-column: 2; }
.telemetry-chart-bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: end;
  height: 64px;
  gap: 2px;
  border-block: 1px solid var(--rule);
  background: linear-gradient(var(--rule), var(--rule)) center / 100% 1px no-repeat;
}
.telemetry-chart-bars span { height: var(--power-level, 0%); border-radius: 2px 2px 0 0; background: var(--accent); }
.telemetry-status { padding-top: 8px; border-top: 1px solid var(--rule); margin: 0; color: var(--muted); font-size: .75rem; line-height: 1.4; }
.telemetry-status[data-status="live"] { color: var(--accent); }
.telemetry-status[data-status="stale"] { color: #f1bb84; }

@media (max-width: 720px) {
  :root { --pad: 12px; }
  .top-overlay { flex-direction: column; gap: 9px; }
  .scene-heading { padding: 4px 1px 0; }
  .scene-heading::before {
    inset-inline-end: calc(-1 * max(var(--pad), env(safe-area-inset-right)));
    background: #171e18de;
  }
  .lab-name { margin-bottom: .35rem; }
  .scene-description, .scene-lab-context { margin-top: .35rem; font-size: .82rem; }
  .scene-toolbar { gap: 4px; justify-content: flex-start; }
  .wide-label { display: none; }
  .scene-toolbar .segmented button, .toolbar-button { padding-inline: 7px; font-size: .77rem; }
  .scene-toolbar .segmented button { min-height: 36px; }
  .toolbar-button { min-height: 44px; }
  .bottom-overlay { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; }
  .controls { width: 100%; max-height: calc(100dvh - 156px); }
  .scene-hint { display: none; }
  .walk-controls { display: flex; gap: 5px; margin: 0; }
  .walk-controls button { min-width: 44px; }
  .display { padding: 9px 11px 7px; }
  .display-top { min-height: 12px; }
  .display-head { margin-top: 3px; }
  .display-head h2 { font-size: 1.19rem; }
  .display-detail { font-size: .78rem; min-height: 0; margin-top: 4px; }
  .appliances { padding: 0; }
  .device-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .device { display: flex; min-width: 0; flex-direction: column; align-items: stretch; gap: 3px; padding: 7px 6px; }
  .device + .device { border-top: 0; border-left: 1px solid var(--rule); }
  .device dt, .device-state { padding-inline: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .device dt { font-size: .82rem; }
  .device-info { width: 31px; min-height: 25px; }
  .device-state { font-size: .73rem; }
  .device-action button { width: 100%; min-width: 0; min-height: 44px; margin-top: 2px; }
  .meter-shortcuts { padding: 5px 6px; }
  .meter-shortcuts button { min-height: 44px; }
  .activity summary { min-height: 42px; padding-inline: 11px; }
  .activity-body { padding-inline: 11px; }
  .telemetry-close { min-width: 44px; min-height: 44px; }
  .telemetry-energy summary { min-height: 44px; padding-block: 13px; }
}

@media (max-height: 580px) and (max-width: 720px) {
  .scene-heading h1 { font-size: 1.65rem; }
  .lab-name:not(.kitchen-portfolio-link), .scene-lab-context, .display-detail { display: none; }
  .controls { max-height: calc(100dvh - 120px); }
}

@media (max-width: 355px) {
  .scene-toolbar .segmented button, .toolbar-button { padding-inline: 5px; }
  .scene-toolbar { gap: 3px; }
}
