:root {
  color-scheme: dark;
  --bg: #0a171b;
  --surface: #10252b;
  --surface-2: #17343b;
  --line: #36525a;
  --text: #f4f7f5;
  --muted: #b8c8c6;
  --teal: #20b7aa;
  --blue: #4b91e2;
  --amber: #e0a536;
  --red: #db4545;
  --red-dark: #8d2424;
  --focus: #ffd166;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); overscroll-behavior: none; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); letter-spacing: 0; padding-bottom: max(5rem, env(safe-area-inset-bottom)); }
body.immersive-open { width: 100%; height: 100%; overflow: hidden; padding: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 100; background: #fff; color: #000; padding: .7rem; }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.app-header { min-height: 4.5rem; padding: .7rem clamp(1rem, 4vw, 3rem); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #0d2025; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; gap: .8rem; align-items: center; color: var(--text); text-decoration: none; }
.brand span { display: grid; }
.brand strong { font-size: 1.15rem; }
.brand small { color: var(--muted); font-size: .75rem; }
.header-actions { display: flex; gap: .45rem; }
.level-nav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.level-nav button, .level-nav a { min-width: 0; min-height: 3rem; display: flex; gap: .45rem; align-items: center; justify-content: center; border: 0; background: #0d2025; color: var(--muted); text-decoration: none; font-weight: 750; }
.level-nav span { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border: 1px solid var(--teal); border-radius: 50%; color: #81e3d9; font-size: .75rem; }
.level-nav button:hover, .level-nav a:hover { color: var(--text); background: var(--surface); }
.icon-button { border: 1px solid var(--line); border-radius: 50%; width: 2.75rem; height: 2.75rem; background: var(--surface); color: var(--text); display: inline-grid; place-items: center; font-weight: 800; }
.icon-button-primary { background: var(--blue); border-color: #8abaf0; color: #07131c; }

.status-strip { display: flex; gap: .45rem; overflow-x: auto; padding: .65rem clamp(1rem, 4vw, 3rem); scrollbar-width: thin; border-bottom: 1px solid var(--line); }
.status-chip { flex: 0 0 auto; border: 1px solid var(--line); padding: .36rem .68rem; border-radius: 999px; color: var(--muted); font-size: .8rem; }
.status-simulation { border-color: var(--blue); color: #bcdcff; }
.status-locked { border-color: var(--amber); color: #ffda8b; }
.status-ready { border-color: var(--teal); color: #81e3d9; }
.status-danger { border-color: var(--red); color: #ff9c9c; }
.message-bar, .offline-notice { padding: .7rem clamp(1rem, 4vw, 3rem); color: var(--muted); border-bottom: 1px solid var(--line); }
.offline-notice { background: #4a3610; color: #ffe4a5; }

main { width: min(1180px, 100%); margin: 0 auto; }
.robot-stage, .tab-panel { padding: clamp(1rem, 3vw, 2rem); border-bottom: 1px solid var(--line); }
.stage-heading, .section-title-row { display: flex; gap: 1rem; align-items: center; justify-content: space-between; }
.camera-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
.camera-peer select { min-height: 2.75rem; max-width: 15rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); padding: .55rem .7rem; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.35rem, 4vw, 2rem); margin-bottom: 0; }
h2 { font-size: 1.25rem; margin-bottom: .2rem; }
.eyebrow { color: #79d9cf; font-size: .75rem; font-weight: 800; text-transform: uppercase; margin-bottom: .25rem; }
.command-button, .secondary-button, .primary-button { min-height: 2.75rem; border-radius: 6px; padding: .55rem .9rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700; }
a.command-button, a.secondary-button, a.primary-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.primary-button { background: var(--teal); border-color: #69ddd2; color: #061815; }

.installation-main { width: min(960px, 100%); padding: clamp(1rem, 4vw, 3rem); }
.installation-hero { padding: clamp(1rem, 4vw, 2.5rem) 0; border-bottom: 1px solid var(--line); }
.installation-hero > p:not(.eyebrow) { max-width: 70ch; color: var(--muted); line-height: 1.6; }
.installation-downloads { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.25rem; }
.installation-band { display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); gap: 1rem; padding: clamp(1.25rem, 4vw, 2rem) 0; border-bottom: 1px solid var(--line); }
.installation-band > div { min-width: 0; }
.installation-phase { display: grid; place-items: center; align-self: start; width: 3rem; height: 3rem; border: 1px solid #69ddd2; border-radius: 50%; color: #81e3d9; font-size: 1.25rem; font-weight: 900; }
.installation-band p { max-width: 72ch; color: var(--muted); line-height: 1.55; }
.setup-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.setup-status { display: inline-flex; align-items: center; min-height: 1.8rem; border: 1px solid var(--line); border-radius: 999px; padding: .25rem .65rem; color: var(--muted); font-size: .78rem; font-weight: 800; }
.setup-status.status-ready { border-color: var(--teal); color: #81e3d9; }
.setup-status.status-manual { border-color: var(--amber); color: #ffda8b; }
.setup-status.status-locked { border-color: var(--red); color: #ff9c9c; }
.installation-band pre { max-width: 100%; overflow-x: auto; padding: 1rem; border: 1px solid var(--line); border-radius: 6px; background: #050d10; color: #d9f6f2; line-height: 1.55; }
.installation-warning { padding: .85rem 1rem; border-left: .3rem solid var(--amber); background: #35290d; color: #ffe4a5 !important; }

.visual-stage { min-height: clamp(210px, 42vw, 390px); display: grid; place-items: center; margin-top: 1rem; background: #050d10; border-block: 1px solid #1b3a42; overflow: hidden; }
.eyes { display: grid; place-items: center; width: min(900px, 96%); }
.eye-design-image { display: block; width: 100%; height: auto; max-height: 370px; object-fit: contain; transform-origin: center; transition: filter .2s ease, transform .2s ease; }
.eyes.is-listening .eye-design-image { filter: brightness(1.16) saturate(1.12) drop-shadow(0 0 1.2rem #4b91e2aa); transform: scale(1.025); }
.eyes.is-alert .eye-design-image { filter: saturate(.85) drop-shadow(0 0 1.1rem #db4545cc); }
#cameraPreview, #remoteCameraPreview { width: 100%; max-height: 390px; object-fit: contain; background: #000; }
#cameraPreview.is-selfie, #cameraFullscreenPreview.is-selfie { transform: scaleX(-1); }
.voice-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .55rem; margin-top: 1rem; }
.icon-command { min-height: 3rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 6px; padding: .55rem .85rem; }
.icon-command[aria-pressed="true"] { background: var(--teal); color: #061815; }
.speech-field input { width: 100%; height: 100%; min-height: 3rem; border: 1px solid var(--line); background: #081418; color: var(--text); padding: .7rem; border-radius: 6px; }

.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: .7rem clamp(1rem, 3vw, 2rem) 0; border-bottom: 1px solid var(--line); }
.tab { flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; padding: .75rem 1rem; font-weight: 800; }
.tab.is-active { color: var(--text); border-bottom-color: var(--teal); }
.control-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .7fr); gap: clamp(1rem, 4vw, 2.5rem); }
.drive-section, .safety-section { min-width: 0; }
.speed-control { color: var(--muted); font-weight: 700; }
#speedRange { width: 100%; accent-color: var(--teal); }
.drive-pad { width: min(430px, 100%); margin: 1.1rem auto; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-areas: ". forward ." "left stop right" ". back ."; gap: .55rem; }
.drive-button { aspect-ratio: 1; min-width: 0; border: 1px solid #54717a; border-radius: 6px; background: var(--surface-2); color: var(--text); font-size: clamp(1.5rem, 8vw, 3rem); font-weight: 800; touch-action: none; user-select: none; -webkit-user-select: none; }
.drive-button:active, .drive-button.is-pressed { background: var(--teal); color: #061815; transform: scale(.97); }
.drive-button:disabled { cursor: not-allowed; opacity: .35; }
.role-readonly .control-hint::before { content: "Nur gekoppelte Steuergeräte dürfen fahren. "; color: #ffda8b; }
.drive-forward { grid-area: forward; }.drive-left { grid-area: left; }.drive-stop { grid-area: stop; background: #543535; }.drive-right { grid-area: right; }.drive-back { grid-area: back; }
.control-hint, .safety-section p, .tab-panel > p { color: var(--muted); line-height: 1.5; }
.safety-section { border-left: 1px solid var(--line); padding-left: clamp(1rem, 3vw, 2rem); }
.emergency-stop { width: 100%; min-height: 7rem; border: 3px solid #ff9494; border-radius: 6px; background: var(--red); color: #fff; font-weight: 900; display: grid; place-items: center; align-content: center; box-shadow: inset 0 -8px 0 var(--red-dark); }
.emergency-stop span { font-size: 1.55rem; }.emergency-stop small { font-weight: 700; }
.safety-actions { display: grid; gap: .5rem; margin-top: .8rem; }

.telemetry-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.telemetry-grid div { background: var(--surface); padding: 1rem; min-width: 0; }
.telemetry-grid dt { color: var(--muted); font-size: .8rem; }.telemetry-grid dd { margin: .25rem 0 0; font-weight: 800; overflow-wrap: anywhere; }
.event-log { max-height: 440px; overflow: auto; margin: 1rem 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.event-log li { display: grid; grid-template-columns: 6rem 1fr; gap: .75rem; padding: .6rem .2rem; border-bottom: 1px solid var(--line); color: var(--muted); }
.event-log strong { color: var(--text); }

.floating-stop { position: fixed; z-index: 30; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); width: 4.8rem; height: 4.8rem; border-radius: 50%; border: 3px solid #ffc0c0; background: var(--red); color: white; font-weight: 900; box-shadow: 0 .5rem 1.4rem #0009; }
.connection-dialog { width: min(600px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #0d2025; color: var(--text); padding: 1rem; }
.connection-dialog::backdrop { background: #000b; backdrop-filter: blur(3px); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: .7rem; }
.connection-dialog label { display: grid; gap: .35rem; color: var(--muted); margin: .8rem 0; }
.connection-dialog input, .connection-dialog select { width: 100%; min-height: 2.75rem; border: 1px solid var(--line); border-radius: 5px; background: #081418; color: var(--text); padding: .55rem; }
.connection-dialog output { min-height: 2.75rem; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 5px; background: #081418; color: var(--text); padding: .55rem; }
.settings-group { margin-top: .8rem; padding: .7rem; border: 1px solid var(--line); border-radius: 6px; }
.settings-group summary { cursor: pointer; color: var(--text); font-weight: 800; }
.settings-group p { color: var(--muted); line-height: 1.5; }
.settings-group a { color: #81e3d9; }
.eye-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin: .8rem 0 0; padding: 0; border: 0; }
.eye-picker legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.connection-dialog .eye-option { display: grid; grid-template-columns: 1.2rem minmax(0, 1fr); grid-template-areas: "preview preview" "radio text"; gap: .5rem; align-items: center; margin: 0; padding: .55rem; border: 1px solid var(--line); border-radius: 7px; background: #081418; color: var(--text); cursor: pointer; }
.connection-dialog .eye-option:hover, .connection-dialog .eye-option:focus-within { border-color: #69ddd2; }
.connection-dialog .eye-option.is-selected { border-color: var(--teal); background: #12343a; box-shadow: 0 0 0 1px #20b7aa55; }
.connection-dialog .eye-option input { grid-area: radio; width: 1.15rem; min-height: 1.15rem; height: 1.15rem; margin: 0; padding: 0; accent-color: var(--teal); }
.eye-option-preview { grid-area: preview; display: grid; place-items: center; height: 5.2rem; overflow: hidden; border-radius: 5px; background: #02080b; }
.eye-option > span:last-child { grid-area: text; min-width: 0; }
.eye-option input:is([value="sketch"], [value="focused"]) + .eye-option-preview { background: #f3f5f4; }
.eye-option-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.eye-option strong, .eye-option small { display: block; }
.eye-option small { margin-top: .15rem; color: var(--muted); font-size: .75rem; line-height: 1.25; }
.settings-group .eye-design-status { margin: .65rem 0 0; color: #81e3d9; font-size: .82rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.dialog-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.pairing-qr { margin: 1rem auto; width: min(260px, 100%); padding: .7rem; background: white; }
.pairing-qr svg { display: block; width: 100%; height: auto; }
.installer-link { margin: 1rem 0 0; color: var(--muted); }
.installer-link a { color: #81e3d9; }
.eyes-fullscreen { position: fixed; inset: 0; z-index: 60; width: 100dvw; height: 100dvh; background: #02080b; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); overflow: hidden; }
.eyes-fullscreen[hidden] { display: none; }
.eyes-fullscreen:fullscreen, .eyes-fullscreen:-webkit-full-screen { width: 100vw; height: 100vh; }
.eyes-large { width: min(1500px, 96vw); max-height: calc(100dvh - 12rem); }
.eyes-large .eye-design-image { max-height: calc(100dvh - 12rem); }
body[data-eye-design="sketch"] .eyes, body[data-eye-design="focused"] .eyes { overflow: hidden; border-radius: 1rem; background: #f3f5f4; }
.fullscreen-close { position: absolute; top: max(1rem, env(safe-area-inset-top)); right: max(1rem, env(safe-area-inset-right)); width: 3.5rem; height: 3.5rem; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: white; font-size: 2rem; }
#fullscreenStatus { color: var(--muted); }
.face-status { width: min(680px, 100%); text-align: center; color: var(--muted); }
.face-status p { margin-bottom: .55rem; }
.face-actions { display: flex; gap: .7rem; align-items: stretch; justify-content: center; }
.emergency-stop-compact { width: auto; min-width: 8rem; min-height: 3rem; box-shadow: none; }

.camera-fullscreen { position: fixed; inset: 0; z-index: 70; width: 100dvw; height: 100dvh; overflow: hidden; background: #000; }
.camera-fullscreen[hidden] { display: none; }
.camera-fullscreen:fullscreen, .camera-fullscreen:-webkit-full-screen { width: 100vw; height: 100vh; }
.camera-fullscreen video { display: block; width: 100%; height: 100%; object-fit: cover; background: #000; }
.camera-fullscreen-shade { position: absolute; inset: auto 0 0; height: min(32vh, 13rem); background: linear-gradient(transparent, #000c); pointer-events: none; }
.camera-fullscreen-toolbar { position: absolute; z-index: 1; left: max(1rem, env(safe-area-inset-left)); right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.camera-fullscreen-toolbar p { margin: 0; color: #fff; text-shadow: 0 2px 8px #000; font-weight: 800; }
.camera-fullscreen-toolbar > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; }

@media (max-width: 760px) {
  .brand small { display: none; }
  .control-layout { grid-template-columns: 1fr; }
  .safety-section { border-left: 0; border-top: 1px solid var(--line); padding: 1rem 0 0; }
  .voice-row { grid-template-columns: 1fr auto; }.voice-row .icon-command { grid-column: 1 / -1; }
  .telemetry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-heading { align-items: flex-start; }
  .camera-actions { justify-content: flex-start; }
  .level-nav { grid-template-columns: repeat(5, minmax(4.2rem, 1fr)); overflow-x: auto; }
  .level-nav button, .level-nav a { flex-direction: column; gap: .2rem; font-size: .72rem; }
  .camera-fullscreen-toolbar { align-items: stretch; flex-direction: column; }
  .camera-fullscreen-toolbar > div { justify-content: stretch; }
  .camera-fullscreen-toolbar button { flex: 1; }
}

@media (max-width: 430px) {
  .app-header { padding-inline: .75rem; }.status-strip { padding-inline: .75rem; }
  .robot-stage, .tab-panel { padding: 1rem .75rem; }
  .visual-stage { min-height: 210px; }
  .eyes { width: 100%; }
  .eye-picker { grid-template-columns: 1fr; }
  .form-grid, .telemetry-grid { grid-template-columns: 1fr; }
  .dialog-actions > button { width: 100%; }
  .floating-stop { width: 4.2rem; height: 4.2rem; }
  .installation-band { grid-template-columns: 1fr; }
  .installation-phase { width: 2.6rem; height: 2.6rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
