/* MacCready – Clean-Flat */
:root {
  --sky-top: #4f8fd1;
  --sky-mid: #8cc0ea;
  --sky-low: #dcecf8;
  --ink: #1d2733;
  --muted: #6b7785;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff6a00;
  --good: #2e9d4f;
  --bad: #d64545;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-low) 100%);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* nicht 100vh: iOS Safari rechnet 100vh ohne Browserleiste, der Boden läge dann unter der Leiste */
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#safeProbe { position: fixed; visibility: hidden; pointer-events: none; padding-bottom: env(safe-area-inset-bottom); }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; }
button.primary { background: var(--accent); color: #fff; font-weight: 700; padding: 0.7em 1.6em; font-size: 1.15rem; box-shadow: 0 3px 0 #c45200; }
button.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #c45200; }
button.primary:disabled { background: #b9c1ca; box-shadow: none; cursor: default; }
button.link { background: none; color: var(--muted); text-decoration: underline; padding: 0.3em; }
button.icon { background: rgba(255, 255, 255, 0.85); padding: 0.35em 0.55em; font-size: 1.2rem; }
button.floating { position: fixed; z-index: 30; }
.dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; vertical-align: -0.05em; }

.plabel {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font-size: 13px; font-weight: 600; padding: 1px 6px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.82); color: var(--ink);
}
.plabel .dot { width: 8px; height: 8px; margin-right: 4px; }
.plabel .st { color: var(--bad); font-weight: 700; margin-left: 3px; }
.plabel.off { opacity: 0.75; }
.plabel.self { background: #fff; outline: 2px solid var(--ink); }
.kmlabel {
  position: absolute; left: 0; top: 0; font-size: 11px; font-weight: 600;
  color: rgba(255, 255, 255, 0.95); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ------------------------------------------------------------ Race */
body.race #mute { right: 14px; bottom: 14px; }
.panel {
  position: fixed; z-index: 20; background: var(--panel); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(20, 40, 70, 0.25);
}
#lobby { inset: 4vh 4vw; padding: 2.5vh 3vw; overflow: auto; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr); gap: 3vw; height: 100%; }
.join { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.join h1 { font-size: clamp(2rem, 4.5vw, 4rem); margin: 0; letter-spacing: -0.02em; }
.join .sub { margin: 0 0 1.5vh; color: var(--muted); font-size: 1.2rem; }
#qr { width: min(40vh, 30vw); aspect-ratio: 1; background: #fff; border-radius: 10px; padding: 6px; }
#qr svg { width: 100%; height: 100%; display: block; }
.code-line { font-size: clamp(1.4rem, 2.6vw, 2.4rem); margin-top: 1.5vh; font-weight: 600; }
#code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.15em; background: var(--ink); color: #fff; padding: 0.05em 0.35em; border-radius: 8px; }
.url { color: var(--muted); margin-top: 0.5vh; font-size: 1.1rem; word-break: break-all; }
.warn { margin-top: 1.5vh; background: #fff3cd; color: #7a5b00; padding: 0.6em 1em; border-radius: 10px; max-width: 34em; }
.side { display: flex; flex-direction: column; min-height: 0; }
.side h2 { margin: 1.2vh 0 0.6vh; font-size: 1.3rem; }
#plist { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 1.2em; min-height: 2.2em; }
#plist li { display: flex; align-items: center; gap: 0.5em; padding: 0.25em 0; break-inside: avoid; font-size: 1.1rem; }
#plist .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#plist .st { font-size: 0.8em; }
#plist .st.on { color: var(--good); }
#plist .st.off { color: var(--bad); }
#plist .kick { background: none; color: var(--muted); padding: 0 0.3em; }
.form { display: grid; gap: 0.8em; margin-bottom: 1.5vh; }
.form > label, .form > .field, details > label { display: grid; gap: 0.25em; font-weight: 600; }
.form .val { font-weight: 400; color: var(--muted); }
.form select, .form input[type=number] { font: inherit; padding: 0.35em 0.5em; border: 1px solid #c8d0d9; border-radius: 8px; background: #fff; }
.form input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; gap: 1.2em; font-weight: 400; }
.seg label, .seedrow label { display: inline-flex; align-items: center; gap: 0.3em; }
.seedrow { display: flex; gap: 0.5em; align-items: center; font-weight: 400; }
.seedrow input[type=number] { width: 8em; }
details { color: var(--muted); }
details summary { cursor: pointer; }
details > label { font-weight: 400; margin: 0.5em 0; }
#start { align-self: flex-start; font-size: 1.5rem; padding: 0.6em 2.4em; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.chip { background: rgba(255, 255, 255, 0.88); border-radius: 12px; padding: 0.4em 0.8em; box-shadow: 0 2px 10px rgba(20, 40, 70, 0.15); }
#clock { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
#clock.urgent { color: var(--bad); }
#wind { position: absolute; left: 14px; bottom: 14px; font-size: 1.2rem; font-weight: 600; }
#wind .arrow { display: inline-block; color: var(--accent); }
#ranking { position: absolute; top: 14px; right: 14px; border-collapse: collapse; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
#ranking th { font-size: 0.75em; color: var(--muted); text-align: left; font-weight: 600; padding: 0 0.35em; }
#ranking td { padding: 0.12em 0.35em; }
#ranking .nm { font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ranking tr.landed td { color: var(--muted); }
#ranking .offl { color: var(--bad); font-size: 0.8em; font-weight: 700; }
.r { text-align: right; }
#kbhint { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 11; }

#countdown {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 25;
  font-size: 30vh; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35); pointer-events: none;
}
#countdown.pop { animation: pop 0.6s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#results { left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 3vh 4vw; min-width: min(560px, 90vw); max-height: 90vh; overflow: auto; text-align: center; }
#results h1 { margin-top: 0; }
#final { margin: 0 auto 2vh; border-collapse: collapse; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
#final th { font-size: 0.6em; color: var(--muted); }
#final td { padding: 0.25em 0.6em; text-align: left; }
#final td.r { text-align: right; }
#final tr.gold td { font-weight: 800; }
#results .row { display: flex; gap: 1em; justify-content: center; }
#export { margin-top: 1.5vh; opacity: 0.5; }

/* ------------------------------------------------------------ Pilot */
body.pilot { touch-action: none; overscroll-behavior: none; position: fixed; inset: 0; }
body.pilot * { touch-action: none; }
#circleZone {
  position: fixed; left: 0; top: 0; bottom: 0; width: 50%; z-index: 5;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6vh;
  color: rgba(255, 255, 255, 0.9); font-weight: 700; font-size: 1.1rem; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  border-right: 1px dashed rgba(255, 255, 255, 0.35);
}
#circleZone .ring {
  position: absolute; left: 50%; top: 58%; width: 26vh; height: 26vh; transform: translate(-50%, -50%);
  border-radius: 50%; border: 4px dashed rgba(255, 255, 255, 0.45);
}
#circleZone.active { background: rgba(255, 140, 0, 0.22); }
#circleZone.active .ring { border: 6px solid var(--accent); animation: spin 1.6s linear infinite; background: rgba(255, 106, 0, 0.15); }
#circleZone.active span { color: #fff; }
#circleZone.active span::after { content: " · KREISEN"; color: var(--accent); }
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

#barZone { position: fixed; right: 0; top: 0; bottom: 0; width: 50%; z-index: 5; }
#barTrack {
  position: absolute; right: max(26px, env(safe-area-inset-right)); top: 22vh; top: 22dvh; bottom: 10vh; bottom: 10dvh; width: 44px;
  border-radius: 22px; background: rgba(255, 255, 255, 0.35); border: 2px solid rgba(255, 255, 255, 0.8); overflow: visible;
}
#barFill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 20px; background: linear-gradient(0deg, #ffb066, var(--accent)); }
#barThumb { position: absolute; left: -10px; right: -10px; height: 28px; border-radius: 14px; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
#barPct {
  position: absolute; right: calc(max(26px, env(safe-area-inset-right)) + 60px); bottom: 10vh; bottom: 10dvh;
  font-size: 2.6rem; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); font-variant-numeric: tabular-nums;
}
#barZone .cap { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: 3vh; color: #fff; font-size: 0.8rem; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

#inst {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 6; pointer-events: none;
  display: flex; align-items: stretch; gap: 6px; background: rgba(20, 30, 45, 0.72); color: #fff; border-radius: 14px; padding: 6px 10px;
  font-variant-numeric: tabular-nums;
}
#inst .vario, #inst .cell { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 4.6em; }
#inst .vario { min-width: 5.6em; }
#inst b { font-size: 1.7rem; line-height: 1.1; }
#inst .vario b { font-size: 2.4rem; }
#inst small { font-size: 0.7rem; opacity: 0.75; }
#inst .mini { display: flex; flex-direction: column; justify-content: center; font-size: 0.8rem; opacity: 0.9; padding-left: 6px; border-left: 1px solid rgba(255, 255, 255, 0.25); gap: 1px; }
body.pilot #pmute { left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); z-index: 7; }
#conn { position: fixed; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 8; background: var(--bad); color: #fff; padding: 4px 12px; border-radius: 10px; font-weight: 600; }

.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(30, 60, 100, 0.35); padding: 16px; touch-action: auto;
}
.overlay * { touch-action: manipulation; }
.overlay.clear { background: none; pointer-events: none; }
.card { background: var(--panel); border-radius: var(--radius); padding: 18px 26px; text-align: center; max-width: 440px; width: 100%; box-shadow: 0 10px 40px rgba(20, 40, 70, 0.3); }
.card h1 { margin: 0 0 12px; }
.card h2 { margin: 6px 0; }
.card label { display: grid; gap: 4px; text-align: left; font-weight: 600; margin-bottom: 10px; }
.card input { font: inherit; font-size: 1.2rem; padding: 0.45em 0.6em; border: 1px solid #c8d0d9; border-radius: 10px; -webkit-user-select: text; user-select: text; }
.card .err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.swatch { width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 6px; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.huge { font-size: 2.6rem; font-weight: 800; }
#screen-msg { background: rgba(30, 60, 100, 0.2); }
#screen-cd #cd-num { font-size: 40vh; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35); }
.phone-icon { font-size: 3rem; }
#rotate { display: none; z-index: 60; background: #4f8fd1; }
@media (orientation: portrait) and (max-width: 900px) {
  body.pilot #rotate { display: flex; }
}
@media (max-height: 380px) {
  #inst b { font-size: 1.35rem; }
  #inst .vario b { font-size: 1.9rem; }
  #barPct { font-size: 2rem; }
}
