/* Startplatz Evolution – Oberfläche. Ruhige Farbwelt, alles über der 3D-Ansicht. */
:root {
  /* Sicherheitsränder: quer gehalten liegen links und rechts Kamera-Aussparung und Rundung. */
  --left: max(5.2vw, calc(env(safe-area-inset-left) + 14px));
  --right: max(4vw, calc(env(safe-area-inset-right) + 14px));
  --edge-left: max(22px, calc(env(safe-area-inset-left) + 10px));
  --edge-right: max(22px, calc(env(safe-area-inset-right) + 10px));
  --top: max(23px, calc(env(safe-area-inset-top) + 8px));
  --bottom: max(18px, calc(env(safe-area-inset-bottom) + 6px));
}
* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; height: 100dvh; overflow: hidden;
  background: #152320; color: #f6f3e9; font-family: Arial, "Helvetica Neue", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { cursor: pointer; border: 0; color: inherit; }
button:disabled { cursor: wait; opacity: .65; }
button:hover { filter: brightness(1.12); }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid #f4c675; outline-offset: 4px; }
[hidden] { display: none !important; }

#scene, #shade { position: fixed; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#shade {
  pointer-events: none; transition: opacity .45s;
  background: linear-gradient(90deg, rgba(8,20,22,.88) 0%, rgba(8,20,22,.66) 29%, rgba(8,20,22,.06) 68%),
    linear-gradient(0deg, rgba(8,18,21,.65), transparent 35%);
}

/* ---------- Titelbild ---------- */
#brand { position: absolute; top: max(34px, env(safe-area-inset-top)); left: var(--left); display: flex; gap: 15px; align-items: center; letter-spacing: 3px; font-size: 13px; font-weight: 700; }
#brand b { display: block; font-size: 17px; letter-spacing: 5px; margin-top: 4px; }
.mark { font-size: 26px; letter-spacing: -3px; font-weight: 900; font-style: italic; position: relative; padding-right: 7px; }
.mark span { position: absolute; height: 3px; width: 33px; bottom: -6px; left: 0; background: #e95844; transform: skewX(-30deg); }
#zurueck { position: absolute; top: max(35px, env(safe-area-inset-top)); right: var(--right); color: #dedfd9; font-size: 12px; text-decoration: none; min-height: 44px; padding: 12px; }
#intro { position: absolute; left: var(--left); top: 24%; max-width: 500px; width: 47%; }
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 2.4px; display: flex; align-items: center; gap: 10px; margin: 0 0 24px; color: #dedfca; }
.eyebrow i { width: 6px; height: 6px; background: #ea624c; border-radius: 50%; display: block; }
h1 { font-size: clamp(32px, 4.6vw, 70px); line-height: 1.06; font-weight: 650; letter-spacing: -2.2px; margin: 0; }
h1 em { font-style: normal; color: #f0b57a; }
.lead { font-size: 14px; line-height: 1.8; color: #cbd2cd; margin: 22px 0; }
.track-info { display: flex; gap: 27px; margin: 24px 0 28px; font-size: 10px; color: #c9cec6; }
.track-info strong { display: block; color: #f2f1e8; font-size: 22px; letter-spacing: -.7px; margin-bottom: 6px; font-weight: 500; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.primary { padding: 16px 25px; min-height: 48px; background: #f2b77a; color: #162322; font-size: 11px; font-weight: 800; letter-spacing: 1.2px; }
.secondary { background: #ffffff0d; border: 1px solid #ffffff50; min-height: 48px; padding: 14px 17px; font-size: 10px; font-weight: 700; letter-spacing: .9px; }
.text-button { display: block; background: none; padding: 14px 0; font-size: 10px; letter-spacing: 1px; color: #cbd1cd; min-height: 44px; }
.text-button:hover { color: #fff; }
#controls { font-size: 10px; color: #aebeb5; margin: 2px 0; }

footer { position: absolute; bottom: var(--bottom); left: var(--left); right: var(--right); display: flex; justify-content: space-between; align-items: center; color: #c7d0c9; font-size: 9px; letter-spacing: 1px; gap: 20px; }
footer > div { display: flex; gap: 10px; align-items: center; }
footer select { color: #e9eee8; background: #172b2bdc; border: 1px solid #7b8f8259; border-radius: 3px; font-size: 10px; min-height: 36px; padding: 0 6px; }
#sound { background: #172b2bdc; border: 1px solid #7b8f8259; padding: 12px; min-height: 44px; font-size: 10px; font-weight: 700; letter-spacing: .5px; }
#sound[aria-pressed=true] { color: #f2b77a; }
body:not(.driving) #sound { display: none; }
#steering-block[hidden] + .sound-heading { border-top: 0; margin-top: 0; padding-top: 0; }

/* ---------- Einstellungsfeld ---------- */
#start-settings {
  position: absolute; right: var(--right); bottom: 95px; width: 290px; max-height: calc(100dvh - 200px);
  overflow-y: auto; overscroll-behavior: contain; padding: 22px; background: #122623ed; border: 1px solid #d3dacc35;
  border-radius: 6px; box-shadow: 0 18px 45px #0003; scrollbar-width: thin; scrollbar-color: #83958a #182c28;
}
/* Weicher Verlauf unten, solange noch Inhalt folgt. */
#start-settings.more { -webkit-mask-image: linear-gradient(#000 calc(100% - 34px), transparent); mask-image: linear-gradient(#000 calc(100% - 34px), transparent); }
#start-settings .eyebrow { margin: 0 0 17px; color: #efb97e; font-size: 9px; }
.setting-heading { font-size: 13px; font-weight: 700; letter-spacing: .2px; }
.choice { display: flex; gap: 4px; margin: 10px 0 4px; padding: 4px; background: #071a1799; border-radius: 5px; }
.choice button { min-height: 44px; flex: 1; min-width: 0; background: transparent; border-radius: 3px; font-size: 11px; color: #c3d0c7; }
.choice button[aria-pressed=true] { background: #eeb57a; color: #172724; font-weight: 700; }
.range-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; margin-top: 12px; color: #d5ded5; }
.range-heading output { color: #f2be86; font-variant-numeric: tabular-nums; }
input[type=range] { display: block; width: 100%; min-width: 0; height: 30px; margin: 0; accent-color: #eeb57a; touch-action: pan-y; cursor: pointer; }
input:focus-visible { outline: 2px solid #f4c675; outline-offset: 2px; }
.range-ends { display: flex; justify-content: space-between; font-size: 9px; color: #a9bbaf; }
.sound-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 15px; padding-top: 13px; border-top: 1px solid #ced8c826; }
#start-sound { min-height: 44px; padding: 10px 14px; font-size: 10px; letter-spacing: .6px; background: #ffffff10; border: 1px solid #d3dacc35; border-radius: 4px; }
#start-sound[aria-pressed=true] { color: #f2be86; border-color: #eeb57a80; }
.setting-note { font-size: 11px; line-height: 1.5; color: #c1d0c4; margin: 7px 0 0; }
.setting-footnote { font-size: 9px; color: #91a99a; line-height: 1.5; margin: 13px 0 0; }
#calibrate { width: 100%; min-height: 44px; font-size: 9px; padding: 10px 6px; margin-top: 8px; }
#tilt-meter { display: flex; align-items: center; gap: 10px; height: 20px; margin-top: 8px; color: #a9bbaf; font-size: 12px; }
#tilt-meter > div { position: relative; flex: 1; height: 3px; background: #91a99a55; }
#tilt-meter > div:after { content: ''; position: absolute; left: 50%; top: -4px; height: 11px; border-left: 1px solid #dbe1cb99; }
#tilt-dot { position: absolute; left: 50%; top: -3px; width: 9px; height: 9px; border-radius: 50%; background: #f2be86; transform: translateX(-50%); z-index: 1; }
body.driving #start-settings { display: none; }

/* ---------- Fahrt ---------- */
body.driving #shade { opacity: 0; }
body.driving #brand, body.driving #zurueck, body.driving #version, body.driving footer label, body.driving #quality { display: none; }
body.driving footer { left: var(--edge-left); bottom: 19px; right: auto; }
#hud { position: absolute; inset: 0; pointer-events: none; text-shadow: 0 1px 8px #0009; }
#hud button { pointer-events: auto; min-height: 44px; }
.lap-panel { position: absolute; left: max(25px, calc(env(safe-area-inset-left) + 10px)); top: var(--top); background: linear-gradient(90deg, #132120d9, transparent); padding: 10px 26px 14px 0; }
.lap-panel > span { font-size: 9px; letter-spacing: 2px; color: #e9be91; display: block; margin-bottom: 9px; }
.lap-panel strong { font-size: 11px; letter-spacing: 2px; font-weight: 400; }
.lap-panel b { font-weight: 700; }
.lap-panel #lap-time { font-size: 28px; font-variant-numeric: tabular-nums; font-weight: 500; margin: 9px 0 4px; }
#lap-time.muted { color: #c7d0c9; font-size: 20px; letter-spacing: 3px; }
#lap-time.invalid { color: #f08a72; text-decoration: line-through; text-decoration-thickness: 2px; }
#delta { font-size: 12px; font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; min-height: 15px; margin-bottom: 6px; }
#delta.ahead { color: #8fe0a0; }
#delta.behind { color: #f3a081; }
.lap-panel small { display: block; font-size: 9px; color: #c0cbc2; letter-spacing: 1px; margin-top: 3px; }
.lap-panel small b { margin-left: 8px; font-variant-numeric: tabular-nums; color: white; }
.top-actions { position: absolute; right: var(--edge-right); top: var(--top); display: flex; gap: 8px; }
.top-actions button { background: #132120b8; border: 1px solid #ffffff33; padding: 12px 15px; font-size: 10px; letter-spacing: .7px; }
.map-panel { position: absolute; left: max(26px, calc(env(safe-area-inset-left) + 12px)); bottom: 85px; width: 105px; text-align: center; }
.map-panel svg { width: 100%; height: 140px; filter: drop-shadow(0 2px 3px #0008); }
#map-track { fill: none; stroke: #ffffff6e; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
#map-tunnel { fill: none; stroke: #102020; stroke-width: 4; stroke-dasharray: 3 3; }
#map-car { fill: #f3b77a; stroke: #202b24; stroke-width: 2; }
#map-ghost { fill: #cfe9ff99; stroke: #20343f; stroke-width: 1.5; }
.map-rival { stroke: #f6f3e9b0; stroke-width: 1; }
.map-panel span { font-size: 8px; letter-spacing: 2px; }
.speed-panel { position: absolute; right: max(30px, calc(env(safe-area-inset-right) + 12px)); bottom: max(30px, env(safe-area-inset-bottom)); width: 185px; }
.speed-line { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
#speed { font-size: 76px; line-height: 1; font-weight: 400; letter-spacing: -3px; font-variant-numeric: tabular-nums; }
.speed-line small { font-size: 9px; letter-spacing: 2px; }
.speed-line b { display: block; font-size: 27px; font-weight: 500; margin-top: 5px; color: #f3b77a; }
.rev { height: 4px; background: #ffffff35; margin: 13px 0 9px; overflow: hidden; }
.rev i { display: block; height: 100%; background: #f0b27a; transform-origin: left; width: 100%; transform: scaleX(0); }
.speed-caption { display: flex; justify-content: space-between; font-size: 8px; letter-spacing: 1.5px; }
/* Rennen: Platz mit Abstand nach vorn und hinten, Startampel. */
#position { position: absolute; right: var(--edge-right); top: calc(var(--top) + 58px); text-align: right; padding: 6px 0 10px 34px; min-width: 160px; background: linear-gradient(270deg, #132120d9, transparent); }
#position .place { display: flex; align-items: baseline; justify-content: flex-end; gap: 5px; }
#position .place small { font-size: 9px; letter-spacing: 2px; color: #e9be91; margin-right: 6px; }
#position .place b { font-size: 40px; line-height: 1; font-weight: 500; font-variant-numeric: tabular-nums; transition: color .3s; }
#position .place span { font-size: 14px; color: #c0cbc2; }
#position > small { display: block; min-height: 14px; margin-top: 4px; font-size: 10px; letter-spacing: 1px; white-space: pre; color: #dfe5dc; font-variant-numeric: tabular-nums; }
#position[data-change=up] .place b { color: #8fe0a0; }
#position[data-change=down] .place b { color: #f3a081; }
#lights { position: absolute; top: 8%; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; padding: 10px 14px; background: #0b1213e0; border-radius: 6px; box-shadow: 0 8px 30px #0006; }
#lights i { display: block; width: 26px; height: 26px; border-radius: 50%; background: #2c1513; box-shadow: inset 0 0 0 2px #0006; }
#lights i.on { background: #ff2d1c; box-shadow: 0 0 16px #ff3b2acc, inset 0 0 0 2px #0003; }
#message { position: absolute; top: 21%; left: 50%; transform: translateX(-50%); font-size: 13px; font-weight: 700; letter-spacing: 2px; text-align: center; max-width: 70%; padding: 13px 20px; background: #152321ce; opacity: 0; transition: opacity .2s; }
#message.visible { opacity: 1; }
#drive-hint { position: absolute; bottom: 27px; left: 50%; transform: translateX(-50%); font-size: 9px; letter-spacing: 1px; color: #edf0d9; white-space: nowrap; }
#brake, #touch-hint { display: none; }

/* ---------- Dialoge ---------- */
.overlay { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; background: #07141399; backdrop-filter: blur(7px); z-index: 20; }
.panel { background: #162825f5; border: 1px solid #bec9a62e; padding: 35px 40px; max-width: 520px; width: 90%; box-shadow: 0 30px 100px #0006; max-height: calc(100dvh - 24px); overflow-y: auto; }
.panel h2 { font-size: 42px; font-weight: 500; letter-spacing: -1.4px; margin: 12px 0 20px; }
.panel p { font-size: 14px; line-height: 1.7; color: #cfdbd0; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.panel .text-button { width: 100%; text-align: left; }
.records-row { display: grid; grid-template-columns: 3em 1fr auto; gap: 12px; padding: 13px 0; border-bottom: 1px solid #ffffff1c; font-size: 14px; font-variant-numeric: tabular-nums; }
.records-row span { color: #b3c2b3; }
.panel.wide { max-width: 760px; }
.panel .panel-lead { margin: -6px 0 18px; }
.panel-heading { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: #e9be91; margin: 26px 0 0; }
.panel .records-race { margin-top: 6px; }
/* Startaufstellung: ungerade Plätze links, gerade rechts und versetzt – wie auf dem Asphalt. */
.grid-table { display: grid; grid-template-columns: 1fr 1fr; column-gap: 26px; padding-bottom: 24px; }
.grid-cell, .result-row { display: grid; align-items: center; gap: 10px; padding: 8px 10px; border-left: 3px solid var(--team, #c71e25); font-size: 13px; font-variant-numeric: tabular-nums; }
.grid-cell { grid-template-columns: 1.6em 1fr auto; margin-bottom: 6px; background: #ffffff08; }
.grid-cell:nth-child(even) { transform: translateY(24px); }
.grid-cell .pos, .result-row .pos { color: #b3c2b3; font-weight: 700; }
.grid-cell .who b, .result-row .who b { font-weight: 600; }
.grid-cell .who small { display: block; margin-top: 2px; font-size: 8px; letter-spacing: 1.5px; color: #9fb0a4; }
.grid-cell .time { color: #dfe5dc; }
.grid-cell.you, .result-row.you { background: #f2b77a21; }
.grid-cell.you .who b, .result-row.you .who b { color: #f2b77a; }
/* Ergebnis: Platz, Fahrer, Zeit oder Abstand, beste Runde; die schnellste violett. */
.result-table { display: grid; }
.result-row { grid-template-columns: 1.6em 1fr auto 5.8em; padding: 6px 10px; }
.result-row:nth-child(odd):not(.you) { background: #ffffff08; }
.result-row .who small { margin-left: 8px; font-size: 8px; letter-spacing: 1.5px; color: #9fb0a4; }
.result-row .time, .result-row .lap { text-align: right; }
.result-row .lap { color: #b3c2b3; }
.result-row .lap.fastest { color: #c9a5ff; }
#pause-tilt-status { font-size: 12px; }
#portrait { display: none; position: absolute; inset: 0; z-index: 30; background: #102422; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 20px; }
.rotate-icon { font-size: 64px; color: #edb579; }
#portrait h2 { font-size: 25px; font-weight: 500; }
#portrait p { color: #b3c2b3; font-size: 14px; }

/* ---------- Flache Fenster und Telefone quer ---------- */
@media (max-height: 650px) {
  #brand { top: max(22px, env(safe-area-inset-top)); }
  #intro { top: 23%; }
  .eyebrow { margin-bottom: 14px; }
  h1 { font-size: clamp(31px, 4.6vw, 56px); }
  .lead { margin: 13px 0; line-height: 1.6; font-size: 12px; }
  .track-info { margin: 16px 0 19px; }
  .track-info strong { font-size: 19px; }
  .actions { gap: 8px; }
  .primary, .secondary { padding: 13px 18px; min-height: 44px; }
  .text-button { padding: 10px 0; font-size: 9px; }
  footer { bottom: max(12px, env(safe-area-inset-bottom)); }
  #controls { font-size: 9px; }
  #start-settings { top: 95px; bottom: 67px; max-height: none; padding: 17px; width: 280px; }
  .panel.wide { padding: 26px 32px; }
  .panel.wide h2 { font-size: 34px; margin: 8px 0 14px; }
  .result-table { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(5, auto); grid-auto-flow: column; column-gap: 20px; }
  .result-row .who small { display: none; }
  .result-row:nth-child(odd):not(.you) { background: none; }
  .result-row:not(.you) { background: #ffffff08; }
  .result-row { margin-bottom: 4px; }
}
@media (max-height: 470px) {
  #brand { top: max(15px, env(safe-area-inset-top)); font-size: 9px; gap: 10px; }
  #brand b { font-size: 12px; }
  .mark { font-size: 22px; }
  #zurueck { top: max(13px, env(safe-area-inset-top)); }
  #intro { top: 19%; max-width: 420px; width: 54%; }
  h1 { font-size: 30px; letter-spacing: -1px; }
  .eyebrow { font-size: 8px; margin-bottom: 8px; }
  .lead { display: none; }
  .track-info { margin: 10px 0 12px; font-size: 8px; gap: 25px; }
  .track-info strong { font-size: 16px; margin-bottom: 3px; }
  .primary, .secondary { font-size: 9px; padding: 12px 14px; }
  #controls { font-size: 8px; }
  .text-button { min-height: 29px; padding: 6px 0; font-size: 8px; }
  footer { font-size: 7px; bottom: max(9px, env(safe-area-inset-bottom)); }
  footer label { display: none; }
  footer select { font-size: 9px; min-height: 30px; }
  #sound { min-height: 44px; padding: 9px; font-size: 9px; }
  .lap-panel { top: max(12px, env(safe-area-inset-top)); padding-top: 0; }
  .lap-panel #lap-time { font-size: 23px; margin: 7px 0 3px; }
  #lap-time.muted { font-size: 16px; }
  #delta { font-size: 10px; margin-bottom: 3px; }
  .top-actions { top: max(12px, env(safe-area-inset-top)); }
  .top-actions button { font-size: 9px; padding: 9px; }
  .speed-panel { width: 145px; bottom: max(20px, env(safe-area-inset-bottom)); }
  #speed { font-size: 55px; }
  .map-panel { bottom: 65px; width: 65px; }
  .map-panel svg { height: 94px; }
  .map-panel span { font-size: 6px; }
  .panel { padding: 22px 30px; }
  .panel h2 { font-size: 32px; margin: 8px 0; }
  .panel .eyebrow { margin: 0; }
  .panel-actions { gap: 8px; margin-top: 12px; }
  #message { font-size: 10px; padding: 9px; top: 24%; }
  #position { top: calc(max(12px, env(safe-area-inset-top)) + 50px); padding-bottom: 6px; min-width: 130px; }
  #position .place b { font-size: 30px; }
  #position > small { font-size: 9px; margin-top: 2px; min-height: 12px; }
  #lights { top: max(12px, env(safe-area-inset-top)); gap: 7px; padding: 7px 10px; }
  #lights i { width: 18px; height: 18px; }
  .panel.wide { padding: 16px 24px; }
  .panel.wide h2 { font-size: 26px; margin: 4px 0 6px; }
  .panel .panel-lead { font-size: 11px; line-height: 1.45; margin: 0 0 8px; }
  .grid-table { padding-bottom: 14px; column-gap: 16px; }
  .grid-cell { padding: 3px 8px; margin-bottom: 4px; font-size: 11px; gap: 8px; }
  .grid-cell:nth-child(even) { transform: translateY(14px); }
  .grid-cell .who small { display: none; }
  .result-row { padding: 3px 8px; font-size: 11px; gap: 6px; grid-template-columns: 1.4em 1fr auto 5.2em; margin-bottom: 3px; }
  .panel.wide .panel-actions { margin-top: 8px; }
  .panel.wide .primary, .panel.wide .secondary { min-height: 40px; padding: 10px 14px; }
  body.driving footer { bottom: 12px; }
  #drive-hint { font-size: 8px; bottom: 18px; }
  #start-settings { top: 65px; bottom: 51px; width: 35%; padding: 12px 14px; }
  #start-settings .eyebrow { margin-bottom: 8px; }
  .setting-heading { font-size: 11px; }
  .choice { margin-top: 6px; }
  .choice button { font-size: 10px; }
  .sound-heading { margin-top: 10px; padding-top: 7px; }
  .range-ends { display: none; }
  .setting-footnote { margin-top: 8px; }
  #start-settings .setting-note { font-size: 10px; }
  .range-heading { margin-top: 7px; }
}
@media (pointer: coarse) {
  #controls { font-size: 9px; }
  body.driving #brake { display: block; position: absolute; right: max(24px, calc(env(safe-area-inset-right) + 10px)); bottom: 120px; background: #1a2b29a8; border: 1px solid #e9f0d563; width: 112px; height: 68px; font-size: 12px; letter-spacing: 2px; border-radius: 5px; touch-action: none; }
  #brake.active { background: #b34735bf; }
  #drive-hint { display: none; }
  #touch-hint { display: block; position: absolute; bottom: 23px; left: 45%; transform: translateX(-50%); font-size: 9px; letter-spacing: 1px; }
}
@media (pointer: coarse) and (max-height: 470px) { #controls { font-size: 8px; } }
@media (orientation: portrait) and (max-width: 820px) { #portrait { display: flex; } }
@media (max-width: 560px) {
  .grid-table, .result-table { grid-template-columns: 1fr; grid-auto-flow: row; grid-template-rows: none; }
  .grid-cell:nth-child(even) { transform: none; }
}
@media (max-width: 690px) and (orientation: landscape) {
  #intro { width: 53%; }
  #start-settings { width: 37%; padding: 10px; }
  #intro .actions { gap: 4px; }
  #intro .primary, #intro .secondary { font-size: 8px; padding: 10px; }
  #controls { max-width: 280px; line-height: 1.5; }
  .choice button { font-size: 9px; }
}
