:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101c1a;
  color: #f4f6ed;
  --surface: #182725;
  --line: #354b44;
  --muted: #b8c9bf;
  --green: #a6e4a9;
  --yellow: #f7d479;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.site-head { border-bottom: 1px solid #30443d; background: #132320; }
.site-inner, .lab { max-width: 1240px; margin-inline: auto; padding-inline: clamp(15px, 4vw, 42px); }
.site-inner { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; flex-shrink: 0; text-decoration: none; font-weight: 750; letter-spacing: -0.025em; }
.brand > span:last-child { color: var(--green); }
.brand-mark { color: var(--yellow); margin-right: 6px; }
nav { display: flex; align-items: center; gap: clamp(10px, 3vw, 28px); }
nav a { display: grid; min-height: 44px; align-items: center; color: var(--muted); font-size: 0.86rem; text-decoration: none; }
nav a:hover { color: #fff; text-decoration: underline; }

.lab { padding-block: clamp(22px, 4vw, 37px) 62px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 21px; }
.eyebrow { color: var(--green); font-size: 0.78rem; text-transform: uppercase; font-weight: 700; letter-spacing: 0.12em; }
h1 { margin-block: 4px 5px; font-size: clamp(2.6rem, 6vw, 4.15rem); line-height: 0.99; letter-spacing: -0.065em; }
.lead { color: var(--muted); line-height: 1.48; font-size: clamp(0.9rem, 2vw, 1.06rem); }
.clock { flex-shrink: 0; display: grid; text-align: right; color: var(--yellow); font-variant-numeric: tabular-nums; }
.clock span { color: var(--muted); font-size: 0.78rem; }
.clock time { font-size: clamp(1.65rem, 4vw, 2.8rem); line-height: 1.13; letter-spacing: -0.06em; font-weight: 700; }

.indicators { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.indicators > div { display: grid; align-content: start; min-height: 88px; padding: 11px 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.indicators dt, .component-values dt { color: var(--muted); font-size: 0.79rem; }
.indicators dd { margin: 3px 0 0; font-size: clamp(1.18rem, 3vw, 1.55rem); font-weight: 750; letter-spacing: -0.035em; font-variant-numeric: tabular-nums; line-height: 1.14; }
.indicators small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.72rem; }
[data-power="on"] { color: var(--green); }
[data-power="off"] { color: #ffb29f; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(292px, 0.45fr); grid-template-rows: auto auto 1fr; align-items: start; gap: 14px; }
.controls { grid-area: 1 / 2; }
.scene { grid-area: 1 / 1 / span 2; }
.inspector { grid-area: 2 / 2 / span 2; }
.history { grid-area: 3 / 1; }
.card { min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 15px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-head h2 { font-size: 1.02rem; letter-spacing: -0.015em; }
.card-head span { color: var(--muted); font-size: 0.77rem; }
.control-hint { margin-top: 8px; color: var(--muted); font-size: 0.86rem; line-height: 1.45; }
.tutorial-link { color: var(--green); font-weight: 680; text-underline-offset: 3px; white-space: nowrap; }
.tutorial-link:hover { color: #ecffe8; }
progress { display: block; appearance: none; width: 100%; height: 6px; margin-block: 13px 12px; border: 0; border-radius: 9px; overflow: hidden; background: #384a44; }
progress::-webkit-progress-bar { background: #384a44; }
progress::-webkit-progress-value { background: var(--yellow); }
progress::-moz-progress-bar { background: var(--yellow); }
.control-row { display: flex; gap: 8px; }
.control-row button { flex: 1; }
.primary, .secondary { min-height: 44px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: 0.87rem; font-weight: 720; cursor: pointer; }
.primary { background: var(--yellow); color: #1b241d; border-color: var(--yellow); }
.primary:hover:enabled { background: #ffe6a5; }
.secondary { background: #223531; color: #f3f7ed; border-color: #506961; }
.secondary:hover:enabled { background: #2c4740; }
button:disabled { cursor: default; opacity: 0.54; }
.load-control { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.load-control h3 { font-size: 0.93rem; }
.load-control p { margin-top: 1px; color: var(--muted); font-size: 0.78rem; }
.alert { margin-top: 12px; padding: 10px 11px; border: 1px solid #94753b; border-radius: 9px; background: #382f1d; color: #ffe3a0; font-size: 0.83rem; line-height: 1.4; }
.alert p { margin-top: 3px; color: #faead2; }
.alert[data-tone="safe"] { background: #213b2c; border-color: #4d775b; color: #bde8be; }
.alert[data-tone="safe"] p { color: #dfedde; }
.alert[data-tone="outage"] { background: #402e29; border-color: #955f4d; color: #ffc7b7; }
.warning-shortcut { position: fixed; z-index: 2; right: max(15px, env(safe-area-inset-right)); bottom: max(15px, env(safe-area-inset-bottom)); color: #221c0e; background: var(--yellow); border-color: var(--yellow); box-shadow: 0 3px 14px #101c1a90; }
.warning-shortcut:hover:enabled { background: #ffe6a5; }

.scene { padding: 0; overflow: hidden; }
.scene .card-head { padding: 14px 15px; }
.diorama {
  --darkness: 0.65;
  position: relative;
  height: clamp(315px, 37vw, 425px);
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 38% 37%, #d1e6b6, transparent 69%),
    linear-gradient(#729eaa 2%, #c6dfcb 55%, #9aad78);
}
.diorama::before { position: absolute; z-index: -1; inset: 0; content: ""; background: radial-gradient(ellipse at 56% 30%, #385b69, #14252e 78%); opacity: var(--darkness); }
.diorama::after { position: absolute; z-index: -1; inset: 34% 6% 5%; content: ""; background: radial-gradient(ellipse at 50% 78%, #283c34a8, transparent 66%); }
#scene-canvas, .scene-labels, .scene-fallback { position: absolute; inset: 0; width: 100%; height: 100%; }
#scene-canvas { cursor: pointer; }
.scene-labels { pointer-events: none; }
.scene-labels span { position: absolute; transform: translate(-50%, -111%); padding: 4px 8px; border-radius: 6px; border: 1px solid #bed1c980; background: #162d2dea; color: white; font-size: 0.72rem; line-height: 1.1; font-weight: 680; white-space: nowrap; }
.scene-labels [data-selected] { background: var(--yellow); color: #1b241d; border-color: var(--yellow); }
.diorama:not([data-renderer="3d"]) :is(#scene-canvas, .scene-labels) { visibility: hidden; }
.scene-fallback { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 8px; padding: 18px; }
.scene-fallback span { color: #e7f1eb; background: #18302e; border: 1px solid #6a8d81; border-radius: 8px; padding: 10px; font-size: 0.8rem; }
.component-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
.component-tabs button { min-height: 44px; padding: 5px 9px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: 0.78rem; font-weight: 650; cursor: pointer; }
.component-tabs button:hover { border-color: var(--line); color: #fff; }
.component-tabs [aria-pressed="true"] { color: var(--yellow); border-color: #8b7749; background: #3b3526; }

.inspector h3 { margin: 10px 0 3px; color: var(--green); font-size: 1.28rem; letter-spacing: -0.025em; }
.inspector p { color: var(--muted); font-size: 0.79rem; line-height: 1.4; }
.component-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 11px 0 0; }
.component-values div { min-width: 0; padding: 8px; border-radius: 8px; background: #111f1d; }
.component-values dd { margin: 2px 0 0; font-weight: 740; font-variant-numeric: tabular-nums; }
#battery-chart { display: block; width: 100%; height: 128px; margin-top: 7px; }

.results { margin-top: 14px; padding: clamp(15px, 2.5vw, 24px); }
.results .card-head h2 { font-size: 1.25rem; }
#result-state { color: var(--green); }
#result-state[data-outcome="failure"] { color: #ffb29f; }
.results p { margin-top: 7px; color: var(--muted); line-height: 1.45; }
.results table { table-layout: fixed; width: 100%; margin-top: 14px; border-collapse: collapse; font-size: clamp(0.73rem, 2.5vw, 0.93rem); }
.results td, .results th { border-bottom: 1px solid var(--line); padding: 9px 6px; text-align: left; }
.results th:first-child { width: 39%; }
.results td { font-variant-numeric: tabular-nums; }
.results th { color: #d6e5d9; font-weight: 650; }
.results .result-note { font-size: 0.82rem; }
.results button { margin-top: 13px; }

@media (max-width: 760px) {
  .workspace { display: flex; flex-direction: column; }
  .workspace > * { width: 100%; }
  .scene { order: 1; }
  .inspector { order: 2; }
  .history { order: 3; }
  .diorama { height: clamp(220px, 63vw, 390px); }
}

@media (max-width: 480px) {
  .site-inner { min-height: 52px; gap: 7px; }
  nav a { font-size: 0.77rem; }
  .brand { font-size: 0.91rem; }
  .intro { align-items: start; gap: 8px; margin-bottom: 14px; }
  .clock { margin-top: 4px; }
  .indicators { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 10px; }
  .indicators > div { min-height: 61px; padding: 8px 10px; }
  .workspace { gap: 10px; }
  .card { border-radius: 11px; }
  .scene-labels span { padding: 3px 4px; font-size: 0.61rem; }
  .component-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; }
  .component-tabs button { padding-inline: 3px; }
}

@media (max-width: 360px) {
  .scene-labels [data-label="battery"] { transform: translate(-50%, -245%); }
}

@media (prefers-reduced-motion: no-preference) {
  .diorama::before { transition: opacity 500ms ease; }
}
