/* Fahrschul-Training SRDK – Layout & Farben (Grundfarbe #009C98) */
:root {
  --brand: #009c98;
  --brand-dark: #007572;
  --brand-light: #e0f4f3;
  --ink: #12302f;
  --muted: #5b7271;
  --panel: rgba(255, 255, 255, 0.96);
  --hud-bg: rgba(8, 40, 40, 0.62);
  --ok: #1fae6a;
  --warn: #e8a317;
  --bad: #d64040;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0d2b2b; color: var(--ink);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
.hidden { display: none !important; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: linear-gradient(180deg, rgba(0, 60, 58, 0.35), rgba(0, 30, 30, 0.6));
  overflow-y: auto;
}
#help { z-index: 30; }
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  width: 100%; max-width: 980px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  margin: auto;
}
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; color: var(--brand-dark); text-transform: uppercase; letter-spacing: 0.06em; }

.brand { display: flex; align-items: center; gap: 16px; padding-bottom: 16px; border-bottom: 3px solid var(--brand); margin-bottom: 20px; }
.brand-logo { width: 58px; height: 58px; flex: none; }
.brand h1 { margin: 0; font-size: clamp(1.4rem, 3.5vw, 2rem); color: var(--brand); }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }

.menu-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }
.scen-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scen-card {
  text-align: left; cursor: pointer; font: inherit; color: inherit;
  border: 2px solid #d5e5e4; background: #fff; border-radius: 12px;
  padding: 14px; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 4px;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.scen-card:hover { border-color: var(--brand); }
.scen-card.active { border-color: var(--brand); background: var(--brand-light); box-shadow: 0 0 0 3px rgba(0, 156, 152, 0.25); }
.scen-icon { grid-row: span 3; font-size: 1.6rem; line-height: 1; }
.scen-title { font-weight: 700; }
.scen-desc { font-size: 0.86rem; color: var(--muted); }
.scen-best { font-size: 0.78rem; color: var(--brand-dark); }

.settings { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 600; }
.field span { display: flex; justify-content: space-between; }
.field output { font-weight: 400; color: var(--brand-dark); }
.field select, .field input[type=range] { width: 100%; font: inherit; font-weight: 400; }
.field select { padding: 8px; border: 1px solid #c4d6d5; border-radius: 8px; background: #fff; }
input[type=range] { accent-color: var(--brand); }
input[type=range]:disabled { opacity: 0.45; }
.check { font-size: 0.86rem; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { accent-color: var(--brand); width: 18px; height: 18px; }

.menu-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 700; border-radius: 10px; padding: 12px 22px; cursor: pointer;
  border: 2px solid var(--brand); background: #fff; color: var(--brand-dark);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--brand-light); }

.small-panel { max-width: 340px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; color: #fff; }
#hud button, #hud .objective, #touch * { pointer-events: auto; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 46px;
  display: flex; align-items: center; justify-content: space-between; padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(90deg, var(--brand), rgba(0, 156, 152, 0.75));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.tb-left { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.tb-logo { width: 28px; height: 28px; }
.tb-title { opacity: 0.85; }
#hud-scenario { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-timer { font-variant-numeric: tabular-nums; font-size: 1.25rem; font-weight: 700; }
.tb-right { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 34px; border-radius: 8px; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 1.05rem;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

.objective {
  position: absolute; top: 56px; left: 10px; max-width: min(430px, calc(100% - 220px));
  background: var(--hud-bg); border-left: 4px solid var(--brand); border-radius: 8px;
  padding: 10px 12px; font-size: 0.9rem; line-height: 1.35; cursor: pointer;
  backdrop-filter: blur(4px);
}
.objective b { display: block; color: #7fe3df; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.objective.min span { display: none; }
.objective.min::after { content: " (antippen)"; font-size: 0.75rem; opacity: 0.7; }

.center-msgs { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(440px, 60vw); }
.hint { background: rgba(0, 0, 0, 0.55); padding: 8px 16px; border-radius: 20px; font-weight: 600; text-align: center; }
.hold { width: 220px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.3); overflow: hidden; }
#hud-hold-bar { height: 100%; width: 0; background: var(--ok); }
#toasts { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  background: rgba(0, 0, 0, 0.6); padding: 6px 14px; border-radius: 8px; font-size: 0.9rem;
  border-left: 4px solid var(--brand); transition: opacity .5s, transform .5s;
}
.toast.warn { border-left-color: var(--warn); }
.toast.ok { border-left-color: var(--ok); }
.toast.alarm { background: var(--bad); border-left-color: #fff; font-size: 1.15rem; font-weight: 800; padding: 10px 18px; animation: blink .5s 4 alternate; }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes blink { from { opacity: 1; } to { opacity: 0.6; } }

#minimap {
  position: absolute; top: 56px; right: 10px; width: 180px; height: 180px;
  border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.7); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.instruments {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: stretch;
  background: var(--hud-bg); border-radius: 12px; padding: 8px 10px;
  border-top: 3px solid var(--brand); backdrop-filter: blur(4px);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.inst { min-width: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 6px; }
.inst + .inst { border-left: 1px solid rgba(255, 255, 255, 0.15); }
.inst small { font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.05em; }
.inst b { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.levers { flex-direction: row; flex-wrap: wrap; gap: 8px; width: 92px; }
.lv { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lv-track { position: relative; width: 10px; height: 40px; border-radius: 5px; background: rgba(255, 255, 255, 0.2); }
.lv-track::after { content: ""; position: absolute; left: -3px; right: -3px; top: 50%; height: 2px; background: rgba(255, 255, 255, 0.6); }
.lv-mark { position: absolute; left: -4px; width: 18px; height: 8px; margin-bottom: -4px; border-radius: 3px; bottom: 50%; }
.lv-mark.port { background: #e04848; }
.lv-mark.stbd { background: #2ecc71; }
.lv-label { width: 100%; text-align: center; }
.gear { font-weight: 800; font-size: 0.85rem; width: 22px; text-align: center; border-radius: 4px; }
.gear.fwd { background: var(--ok); }
.gear.rev { background: var(--warn); color: #111; }
.gear.neu { background: rgba(255, 255, 255, 0.25); }
.rudder { width: 120px; }
.rudder-track { position: relative; width: 100%; height: 10px; margin: 8px 0 2px; border-radius: 5px; background: linear-gradient(90deg, #e04848 0 48%, rgba(255,255,255,.6) 48% 52%, #2ecc71 52%); opacity: 0.85; }
#i-rudder-needle { position: absolute; top: -5px; width: 4px; height: 20px; margin-left: -2px; background: #fff; border-radius: 2px; left: 50%; box-shadow: 0 0 4px rgba(0,0,0,.6); }
.rudder-scale { display: flex; justify-content: space-between; width: 100%; }
.wind-rose { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); margin: 2px 0; }
#i-wind-arrow { position: absolute; inset: 0; display: flex; align-items: flex-start; justify-content: center; font-size: 1rem; font-weight: 900; color: #7fe3df; }
.boat-mini { position: absolute; left: 50%; top: 50%; width: 8px; height: 18px; margin: -9px 0 0 -4px; background: #fff; border-radius: 50% 50% 2px 2px; }
.info { min-width: 120px; max-width: 170px; }
.info small { text-transform: none; font-size: 0.8rem; opacity: 1; text-align: center; }

/* ---------- Touch-Steuerung ---------- */
#touch { display: none; }
body.touch-on #touch {
  display: flex; justify-content: space-between; align-items: flex-end;
  position: absolute; left: 0; right: 0; bottom: 0; padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.tc-left, .tc-right { display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.tc-wheel {
  position: relative; width: min(42vw, 280px); height: 64px; border-radius: 32px; touch-action: none;
  background: rgba(0, 0, 0, 0.35); border: 2px solid rgba(255, 255, 255, 0.5);
}
.tc-wheel-mid { position: absolute; left: 50%; top: 8px; bottom: 8px; width: 2px; background: rgba(255, 255, 255, 0.5); }
.tc-wheel .knob {
  position: absolute; top: 50%; left: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: var(--brand); border: 3px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; pointer-events: none;
}
.tc-levers { display: flex; gap: 14px; }
.tc-lever {
  position: relative; width: 62px; height: min(36vh, 220px); border-radius: 31px; touch-action: none;
  background: rgba(0, 0, 0, 0.35); border: 2px solid rgba(255, 255, 255, 0.5);
}
.tc-lever.port { border-color: rgba(224, 72, 72, 0.9); }
.tc-lever.stbd { border-color: rgba(46, 204, 113, 0.9); }
.tc-n { position: absolute; left: 6px; right: 6px; top: 44%; height: 12%; border-radius: 6px; background: rgba(255, 255, 255, 0.18); }
.tc-lever .knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 40px; margin: -20px 0 0 -27px; border-radius: 12px;
  background: #fff; color: #111; font-weight: 800; display: flex; align-items: center; justify-content: center; pointer-events: none;
}
.tc-lever.port .knob { box-shadow: inset 0 -5px 0 #e04848; }
.tc-lever.stbd .knob { box-shadow: inset 0 -5px 0 #2ecc71; }
.tc-row { display: flex; gap: 8px; align-items: center; font-size: 0.8rem; font-weight: 700; text-shadow: 0 1px 3px #000; }
.tc-btn { font: inherit; font-weight: 700; padding: 8px 12px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, 0.85); color: var(--ink); }
#tc-link.on { background: var(--brand); color: #fff; }

/* Bei Touch-Steuerung Instrumente nach oben, Karte kleiner */
body.touch-on .instruments { top: 52px; bottom: auto; transform: translateX(-50%) scale(0.86); transform-origin: top center; padding-bottom: 8px; }
body.touch-on .center-msgs { top: 150px; }
body.touch-on #minimap { width: 130px; height: 130px; }
body.touch-on .objective { top: auto; bottom: calc(100px + min(36vh, 220px)); max-width: 300px; }

/* ---------- Resultat ---------- */
.result-panel { max-width: 620px; }
.res-scen { margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.08em; }
.res-head { display: flex; gap: 20px; align-items: center; margin-bottom: 16px; }
.res-head h2 { font-size: 1.7rem; text-transform: none; letter-spacing: 0; color: var(--bad); margin: 0 0 4px; }
#result.passed .res-head h2 { color: var(--ok); }
.res-head p { margin: 0; color: var(--muted); }
.ring {
  --p: 0; flex: none; width: 116px; height: 116px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(closest-side, #fff 78%, transparent 79% 100%),
    conic-gradient(var(--bad) calc(var(--p) * 1%), #e5ecec 0);
}
#result.passed .ring { background: radial-gradient(closest-side, #fff 78%, transparent 79% 100%), conic-gradient(var(--ok) calc(var(--p) * 1%), #e5ecec 0); }
.ring span { font-size: 2.1rem; font-weight: 800; }
.ring small { color: var(--muted); font-size: 0.75rem; }
.res-items { list-style: none; margin: 0; padding: 0; border-top: 1px solid #e0e8e8; }
.res-items li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-bottom: 1px solid #e0e8e8; font-size: 0.92rem; }
.res-items li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.res-items li.minus b { color: var(--bad); }
.res-items li.base { font-weight: 700; }
.res-note { color: var(--muted); font-size: 0.8rem; margin: 12px 0 0; }

/* ---------- Hilfe ---------- */
.help-panel { max-width: 860px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; font-size: 0.9rem; }
.help-grid h3 { margin: 0 0 8px; color: var(--brand); font-size: 0.95rem; }
.help-grid table { border-collapse: collapse; width: 100%; }
.help-grid td { padding: 5px 4px; border-bottom: 1px solid #e3eded; vertical-align: top; }
.help-grid td:first-child { white-space: nowrap; }
.help-grid ul { margin: 0 0 14px; padding-left: 18px; }
.help-grid li { margin-bottom: 4px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid #b9cccb; border-bottom-width: 3px; border-radius: 5px; background: #f6fafa; font-family: inherit; font-size: 0.8rem; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .panel { padding: 16px; }
  .menu-grid, .help-grid { grid-template-columns: 1fr; }
  .scen-list { grid-template-columns: 1fr; }
  .tb-title { display: none; }
  .instruments { gap: 2px; padding: 6px; }
  .inst { min-width: 52px; padding: 0 3px; }
  .inst b { font-size: 1.15rem; }
  .rudder { width: 84px; }
  .info, .wind { display: none; }
  #minimap { width: 120px; height: 120px; }
  .objective { max-width: calc(100% - 150px); font-size: 0.8rem; }
  .center-msgs { width: 90vw; }
}
@media (max-height: 500px) {
  .objective { display: none; }
  body.touch-on .instruments { transform: translateX(-50%) scale(0.72); }
  body.touch-on .center-msgs { top: 120px; }
}

/* Schmale Touch-Geräte (Smartphone hochkant) */
@media (max-width: 560px) {
  .icon-btn { width: 32px; }
  .tb-right { gap: 4px; }
  .tc-btn { padding: 7px 9px; font-size: 0.75rem; }
  .tc-right .tc-row { flex-wrap: wrap; justify-content: center; max-width: 140px; }
  .tc-levers { gap: 10px; }
  .tc-lever { width: 56px; }
  .tc-wheel { width: min(44vw, 220px); }
  body.touch-on .instruments { left: 8px; right: 8px; transform: none; justify-content: center; }
  body.touch-on #minimap { top: auto; bottom: calc(150px + min(36vh, 220px)); right: 10px; width: 110px; height: 110px; }
  body.touch-on .objective { bottom: calc(150px + min(36vh, 220px)); max-width: calc(100% - 140px); }
  body.touch-on .center-msgs { top: 175px; }
}
