/* AEROKIT — Oberfläche.
   Hochformat zuerst; §14 hält die Frage Hoch- oder Querformat offen, aber
   der Builder ist im Hochformat eindeutig besser, und der Flug funktioniert
   in beiden. Querformat bekommt deshalb nur Anpassungen, keine eigene Welt. */

:root {
  --accent: #d9502c;
  --accent-soft: rgba(217, 80, 44, 0.14);
  --good: #2f9e63;
  --edge: #d79a21;
  --bad: #c0392b;
  --info: #1f6feb;

  --bg: #f2efe6;
  --panel: #ffffff;
  --ink: #232b30;
  --ink-soft: #6b7780;
  --line: #d8d2c4;
  --shadow: 0 1px 3px rgba(30, 36, 40, .10), 0 8px 24px rgba(30, 36, 40, .06);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171b;
    --panel: #1a2228;
    --ink: #e6edf1;
    --ink-soft: #93a1ab;
    --line: #2b363d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

body { overflow: hidden; }

#video {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  min-width: 100%; min-height: 100%;
  width: auto; height: auto;
  object-fit: cover;
  z-index: 0; display: none;
  background: #000;
}

#gl {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 1; display: none;
  touch-action: none;
}

.screen {
  position: fixed; inset: 0;
  z-index: 2;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px);
}
.screen.bare { overflow: hidden; padding: 0; pointer-events: none; background: none; }
.screen.bare > * { pointer-events: auto; }

/* --------------------------------------------------------- Bedienelemente */

button {
  font: inherit; color: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
button:active { transform: scale(.985); }
button.primary {
  background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600;
}
button.primary:disabled { opacity: .6; }
button.ghost { background: transparent; }
button.big { width: 100%; padding: 15px; font-size: 17px; border-radius: 12px; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--line);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
  margin-top: -9px; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
}

/* ---------------------------------------------------------------- Start */

.intro-inner { max-width: 460px; margin: 0 auto; padding-top: 8vh; }
.logo {
  font-size: 34px; letter-spacing: .22em; margin: 0 0 6px;
  font-weight: 700;
}
.tagline { color: var(--ink-soft); margin: 0 0 26px; }
.intro-notes { margin-top: 26px; color: var(--ink-soft); font-size: 14px; }
.intro-notes p { margin: 0 0 12px; }
.intro-notes b { color: var(--ink); }
.small { font-size: 13px; }

/* ------------------------------------------------------------ Werkstatt */

.builder { display: flex; flex-direction: column; gap: 10px; padding-bottom: calc(var(--safe-b) + 76px); }

.b-head { display: flex; align-items: baseline; gap: 10px; }
.b-head h1 { font-size: 19px; letter-spacing: .18em; margin: 0; font-weight: 700; }
.b-sub { color: var(--ink-soft); font-size: 13px; flex: 1; }
.b-headright { margin-left: auto; }

.b-plan {
  position: relative;
  height: 34vh; min-height: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.b-canvas { display: block; width: 100%; height: 100%; }
.b-preview { position: absolute; inset: 0; display: none; touch-action: none; }
.b-preview canvas { display: block; width: 100%; height: 100%; }

.b-tabs { display: flex; gap: 6px; }
.b-tab { flex: 1; padding: 8px; font-size: 13px; }
.b-tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Kennzahlen */
.b-metrics {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; box-shadow: var(--shadow);
}
.b-caption { font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.b-bar {
  position: relative; height: 14px; border-radius: 7px; overflow: hidden;
  background: linear-gradient(to right,
    var(--bad) 0%, var(--bad) 22%,
    var(--edge) 22%, var(--edge) 33%,
    var(--good) 33%, var(--good) 55%,
    #4d80b8 55%, #4d80b8 78%,
    var(--edge) 78%, var(--edge) 100%);
}
.b-marker {
  position: absolute; top: -3px; width: 3px; height: 20px;
  background: var(--ink); border-radius: 2px;
  box-shadow: 0 0 0 2px var(--panel);
  transform: translateX(-50%);
  transition: left .12s ease-out;
}
.b-scale {
  display: flex; justify-content: space-between;
  font: 10px/1 var(--mono); color: var(--ink-soft);
  margin-top: 4px; padding: 0 2px;
}
.b-stablabel { margin-top: 6px; font-size: 14px; font-weight: 600; }
.b-stablabel[data-level=good] { color: var(--good); }
.b-stablabel[data-level=ok] { color: #4d80b8; }
.b-stablabel[data-level=edge] { color: var(--edge); }
.b-stablabel[data-level=bad] { color: var(--bad); }

.b-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.b-tile { min-width: 0; }
.b-tilekey { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.b-tileval { font: 600 15px var(--mono); margin-top: 2px; }
.b-tilesub { font-size: 10px; color: var(--ink-soft); line-height: 1.25; margin-top: 1px; }

.b-warn {
  display: none; background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 10px; padding: 8px 11px; font-size: 13px;
}

/* Teileauswahl */
.b-palette { display: flex; flex-direction: column; gap: 10px; }
.b-cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.b-cats::-webkit-scrollbar { display: none; }
.b-cat { flex: 0 0 auto; padding: 7px 12px; font-size: 13px; border-radius: 999px; }
.b-cat.on { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 600; }

.b-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.b-part { text-align: left; padding: 10px 11px; border-radius: 10px; }
.b-part.on { border-color: var(--accent); background: var(--accent-soft); }
.b-part.off { opacity: .38; }
.b-partname { font-weight: 600; font-size: 14px; }
.b-partdesc { font-size: 11.5px; color: var(--ink-soft); line-height: 1.35; margin-top: 2px; }

.b-sliders {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px;
}
.b-slider + .b-slider { margin-top: 10px; }
.b-slabel { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 1px; }
.b-sval { font: 600 12px var(--mono); color: var(--accent); }
.b-note {
  font-size: 12px; color: var(--ink-soft); line-height: 1.45;
  border-left: 2px solid var(--line); padding-left: 9px; margin: 12px 0 8px;
}

.b-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 8px; padding: 10px 14px calc(var(--safe-b) + 10px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.b-foot button { flex: 1; }
.b-foot .primary { flex: 1.4; }

/* Overlays */
.b-overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(10, 14, 17, .55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 14px;
}
.b-sheet {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; width: 100%; max-width: 480px;
  max-height: 78vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow);
}
.b-sheet h2 { margin: 0 0 4px; font-size: 17px; }
.b-row { display: flex; flex-direction: column; gap: 2px; text-align: left; width: 100%; }
.b-row strong { font-size: 14px; }
.b-row span { font-size: 12px; color: var(--ink-soft); }
.b-rowwrap { display: flex; gap: 6px; }
.b-rowwrap .b-row { flex: 1; }
.b-del { width: 42px; color: var(--bad); font-size: 18px; padding: 0; }

.b-flash {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 88px);
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 9px 15px; border-radius: 999px; font-size: 13px;
  z-index: 30; transition: opacity .5s;
}
.b-flash.out { opacity: 0; }

/* -------------------------------------------------------------- Vorflug */

.setup-inner { max-width: 460px; margin: 0 auto; }
.back { margin-bottom: 10px; padding: 6px 12px; font-size: 13px; }
.setup-inner h2 { margin: 0 0 2px; font-size: 22px; }
.setup-inner h3 { margin: 22px 0 8px; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.setup-model { color: var(--ink-soft); margin: 0 0 12px; font-size: 13px; }
.setup-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.setup-stats li {
  font-size: 13.5px; padding: 8px 11px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
}
.setup-stats b { font-family: var(--mono); }

.modes { display: grid; gap: 7px; }
.mode { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.mode b { font-size: 14px; }
.mode span { font-size: 12px; color: var(--ink-soft); }
.mode.on { border-color: var(--accent); background: var(--accent-soft); }
.setup-note {
  font-size: 12.5px; color: var(--ink-soft); line-height: 1.5;
  border-left: 2px solid var(--line); padding-left: 10px; margin: 12px 0 20px;
}
.hint { color: var(--ink-soft); margin-top: 10px; }
.measured {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 9px 11px; margin: 0 0 14px;
}
.measured b { color: var(--ink); }

/* ----------------------------------------------------------------- HUD */

#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#hud > * { pointer-events: auto; }

.h-tele {
  position: absolute; left: 10px; top: calc(var(--safe-t) + 10px);
  font: 11.5px/1.55 var(--mono);
  background: rgba(12, 17, 21, .58);
  color: #dde6ec;
  backdrop-filter: blur(8px);
  padding: 8px 10px; border-radius: 9px;
  min-width: 116px;
}
.h-row { display: flex; justify-content: space-between; gap: 12px; }
.h-key { color: #8fa2ae; }
.h-val.bad, .h-row.bad .h-val { color: #ff6b52; font-weight: 700; }
.h-val.warn { color: #f0b429; }

.h-throttle {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  height: 46vh; width: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.h-throttle input[type=range] {
  width: 44vh; height: 54px;
  transform: rotate(-90deg);
  transform-origin: center;
  position: absolute;
}
.h-throttle input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: rgba(255,255,255,.28); }
.h-throttle input[type=range]::-webkit-slider-thumb { width: 34px; height: 34px; margin-top: -13px; }
.h-thrlabel {
  position: absolute; bottom: -22px;
  font: 600 12px var(--mono); color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}

.h-pointer {
  position: absolute; display: none;
  flex-direction: column; align-items: center; gap: 2px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.h-arrow { font-size: 26px; color: var(--accent); text-shadow: 0 1px 6px rgba(0,0,0,.7); line-height: 1; }
.h-pdist { font: 600 11px var(--mono); color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.9); }

.h-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 6px; justify-content: center;
  padding: 8px 10px calc(var(--safe-b) + 8px);
}
.h-btn {
  background: rgba(12, 17, 21, .62); color: #dde6ec;
  border-color: rgba(255,255,255,.14);
  backdrop-filter: blur(8px);
  padding: 9px 12px; font-size: 12.5px;
}
.h-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.h-btn.danger { color: #ff8a72; }

.h-banner {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 12px);
  transform: translateX(-50%);
  max-width: min(88vw, 460px); display: none;
  background: rgba(12, 17, 21, .8); color: #e8eef2;
  backdrop-filter: blur(10px);
  padding: 11px 14px; border-radius: 11px; font-size: 13px;
  border: 1px solid rgba(255,255,255,.12);
}
.h-banner p { margin: 0 0 6px; }
.h-banner p:last-child { margin: 0; }

.h-arm {
  position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 58px);
  display: none; flex-direction: column; align-items: center; gap: 12px;
  padding: 0 20px; pointer-events: none;
}
.h-arm > * { pointer-events: auto; }
.h-armtext {
  text-align: center; font-size: 14px; line-height: 1.45;
  color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.9);
  max-width: 320px;
}
.h-armtext span { font-size: 12.5px; opacity: .75; }
.h-armbtn {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: 700; font-size: 17px; letter-spacing: .04em;
  padding: 15px 46px; border-radius: 999px;
  box-shadow: 0 4px 20px rgba(217, 80, 44, .45);
  animation: armpulse 1.9s ease-in-out infinite;
}
@keyframes armpulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}
@media (prefers-reduced-motion: reduce) {
  .h-armbtn { animation: none; }
}

.h-toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 68px);
  transform: translateX(-50%) translateY(8px);
  background: rgba(12, 17, 21, .82); color: #fff;
  padding: 8px 15px; border-radius: 999px; font-size: 13px;
  opacity: 0; transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.h-toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.h-gui {
  position: absolute; right: 8px; top: calc(var(--safe-t) + 8px);
  max-height: 74vh; overflow-y: auto; z-index: 6;
}
.h-gui .lil-gui { --width: 292px; font-size: 12px; }

/* ------------------------------------------------------------ Querformat */

@media (orientation: landscape) and (max-height: 560px) {
  .b-plan { height: 46vh; }
  .b-tiles { grid-template-columns: repeat(4, 1fr); }
  .intro-inner { padding-top: 3vh; }
  .h-throttle { height: 62vh; }
  .h-throttle input[type=range] { width: 60vh; }
}

@media (min-width: 760px) {
  .builder { max-width: 900px; margin: 0 auto; }
  .b-foot { position: static; background: none; backdrop-filter: none; border: 0; padding: 4px 0 0; }
  .builder { padding-bottom: 20px; }
  .b-plan { height: 42vh; }
}
