:root {
  --panel: rgba(20, 40, 29, 0.92);
  --panel-soft: rgba(20, 40, 29, 0.78);
  --accent: #f2c14e;
  --text: #fdf8ec;
  --muted: #bcd3c2;
  --line: rgba(255, 255, 255, 0.14);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1c2a20;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

h1 { font-size: clamp(34px, 6vw, 64px); margin: 0; letter-spacing: 0.5px; }
h2 { margin: 0 0 12px; font-size: clamp(22px, 3vw, 30px); }
.sub { color: var(--muted); margin: 4px 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: #ff8a80; }
.green { color: #5be38d; font-weight: 700; }
.red { color: #ff7b72; font-weight: 700; }

/* ---------- Bildschirme ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(10, 20, 14, 0.35);
  overflow: auto;
  z-index: 10;
}
.screen.active { display: flex; }
#screen-menu, #screen-login { background: transparent; align-items: flex-start; }

.panel {
  margin: auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 28px);
  width: 100%;
  max-width: 820px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.panel.wide { max-width: 1100px; }
.panel.narrow { max-width: 520px; }
.panel.center { text-align: center; }
.panel.menu { max-width: 440px; margin: 4vh auto auto 4vw; background: var(--panel-soft); backdrop-filter: blur(4px); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; align-items: center; }
.actions.center { justify-content: center; }
.actions.column { flex-direction: column; align-items: stretch; }
.actions .grow { flex: 1; }
.menu .actions { display: grid; grid-template-columns: 1fr 1fr; }
.menu .actions .btn:first-child { grid-column: 1 / -1; }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  border: 0;
  border-radius: 12px;
  padding: 12px 22px;
  min-height: 50px;
  background: var(--accent);
  color: #2a1d05;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.btn[hidden] { display: none; }

.icon {
  font: inherit;
  font-size: 22px;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  cursor: pointer;
  flex: none;
}

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--c, #fff); border: 2px solid rgba(255, 255, 255, 0.7); vertical-align: middle; flex: none; }

h3 { margin: 18px 0 8px; font-size: 18px; }

/* ---------- Anmelden und Verwaltung ---------- */

.login-tabs { margin: 14px 0 4px; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.login-form[hidden] { display: none; }
.login-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; }
.login-form label small { color: var(--muted); font-weight: 400; }
.login-form input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Lockfeld gegen Bots: für Menschen unsichtbar, aber kein display:none, das erkennen manche Bots */
.lockfeld { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.hinweis { color: var(--accent); }
.hinweis:empty, .error:empty { display: none; }
.konto-zeile { margin: 16px 0 0; color: var(--muted); font-size: 15px; }
.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

.admin-row td { vertical-align: middle; }
.admin-row .nachricht { color: var(--muted); font-size: 14px; max-width: 320px; }
.admin-row .knoepfe { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.admin-row .btn { font-size: 14px; min-height: 36px; padding: 6px 12px; }
.status { font-size: 13px; padding: 3px 10px; border-radius: 20px; background: rgba(255, 255, 255, 0.1); white-space: nowrap; }
.status.wartet { background: #b07d12; color: #fff; }
.status.frei { background: #2b9348; }
.status.gesperrt { background: #b23a48; }

/* ---------- Steuerung ---------- */

kbd {
  display: inline-block;
  min-width: 34px;
  padding: 4px 8px;
  border-radius: 7px;
  background: #f4efe2;
  color: #2a1d05;
  font: 700 15px/1.2 system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 3px 0 #b8ab8c;
}
kbd.wide { min-width: 96px; }
.controls { text-align: left; background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 4px 14px 12px; margin: 14px 0; }
.controls h3 { font-size: 16px; color: var(--accent); }
.ctl { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; margin: 8px 0; font-size: 15px; }
.ctl .keys { display: flex; gap: 6px; flex-wrap: wrap; }
.ctl .tb {
  font-style: normal;
  font-weight: 800;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.12);
}
.ctl .tb.jump { width: 76px; height: 76px; font-size: 14px; background: rgba(242, 193, 78, 0.6); }
.ctl .tb.small { width: 40px; height: 40px; border-radius: 10px; }
.ctl-note { margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.only-touch { display: none; }
body.touch .only-touch { display: block; }
body.touch-only .only-keys { display: none; }

.help { padding-left: 20px; line-height: 1.5; }
.help li { margin-bottom: 8px; }

.portrait-hint { display: none; color: var(--muted); }
@media (orientation: portrait) and (max-width: 1000px) { .portrait-hint { display: block; } }

/* ---------- Setup ---------- */

.course-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 22px; }
.course {
  font: inherit;
  color: var(--text);
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.course.sel { border-color: var(--accent); background: rgba(242, 193, 78, 0.12); }
.course b { font-size: 18px; }
.course small { color: var(--muted); }
.course p { margin: 2px 0 0; font-size: 14px; }
.stars { color: var(--accent); letter-spacing: 2px; }

.player-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.player { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 12px; border-top: 4px solid var(--c); }
.p-head { display: flex; align-items: center; gap: 8px; }
.p-name {
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
.horse-pick { display: flex; align-items: center; gap: 6px; margin: 8px 0 4px; }
.p-canvas { flex: 1; min-width: 0; height: 130px; }
.h-name { text-align: center; margin-bottom: 8px; }
.h-name small { color: var(--muted); display: block; }
.skills { display: grid; gap: 4px; font-size: 13px; }
.skill { display: grid; grid-template-columns: 86px 1fr; align-items: center; gap: 8px; }
.sbar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.sbar i { display: block; height: 100%; background: var(--c); }
.h-text { font-size: 13px; color: var(--muted); margin: 8px 0 0; min-height: 3em; }

.turn-canvas { width: 240px; height: 170px; display: block; margin: 0 auto; }

/* ---------- Ergebnis ---------- */

.big-points { font-size: 56px; font-weight: 900; color: var(--accent); margin: 6px 0 12px; }
.big-points small { font-size: 18px; margin-left: 8px; color: var(--muted); font-weight: 600; }
.breakdown, .table { width: 100%; border-collapse: collapse; }
.breakdown td, .table td, .table th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.breakdown td:last-child { text-align: right; white-space: nowrap; }
.breakdown small { color: var(--muted); }
.table th { color: var(--muted); font-weight: 600; font-size: 14px; }
.table tr.winner td { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 20px; background: rgba(255, 255, 255, 0.1); }
.chip.perfekt { background: #2b9348; }
.chip.gut { background: #40916c; }
.chip.ok { background: #52796f; }
.chip.abwurf { background: #b23a48; }
.chip.verweigert { background: #8a4f1d; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab { font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.08); border: 0; border-radius: 20px; padding: 8px 14px; cursor: pointer; }
.tab.sel { background: var(--accent); color: #2a1d05; font-weight: 700; }

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

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; display: none; }
body.playing #hud { display: block; }
.hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.hud-box { background: rgba(15, 30, 20, 0.72); border-radius: 12px; padding: 7px 14px; }
.hud-box small { display: block; color: var(--muted); font-size: 12px; }
.hud-rider { display: flex; align-items: center; gap: 10px; }
.hud-time { margin: 0 auto; text-align: center; min-width: 110px; }
.hud-time b { font-size: 28px; font-variant-numeric: tabular-nums; }
.hud-score { display: flex; gap: 16px; text-align: center; }
.hud-score b { font-size: 22px; font-variant-numeric: tabular-nums; }
.hud-pause {
  pointer-events: auto;
  font: inherit;
  font-size: 16px;
  width: 52px;
  border: 0;
  border-radius: 12px;
  background: rgba(15, 30, 20, 0.72);
  color: var(--text);
  cursor: pointer;
}
.hud-meters {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 64px);
  left: max(10px, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.meter .bar { width: 150px; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.18); overflow: hidden; margin-top: 4px; }
.meter .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8bd17c, #f2c14e 70%, #e8590c); }
.meter .bar.drive { height: 5px; margin-top: 3px; }
.meter .bar.drive i { background: #ffd43b; transition: width 0.08s linear; }
.meter .bar.stamina i { background: #5bc0eb; }
.meter .bar.stamina.low i { background: #ff6b5e; }
.meter b { font-size: 18px; }
.keys-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(15, 30, 20, 0.72);
  font-size: 15px;
  white-space: nowrap;
}
.keys-hint kbd { font-size: 13px; min-width: 28px; padding: 2px 6px; margin-right: 4px; }
.keys-hint kbd.wide { min-width: 76px; }
body.touch-only .keys-hint { display: none; }
/* Touchscreen-Laptop: Hinweis nach oben, damit er nicht unter den Knöpfen liegt */
body.touch .keys-hint { bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 130px); }

@media (max-width: 700px) {
  .hud-top { gap: 6px; }
  .hud-box { padding: 5px 9px; }
  .hud-time b { font-size: 22px; }
  .hud-rider small { display: none; }
  .meter .bar { width: 90px; }
}

/* ---------- Touch-Knöpfe ---------- */

#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 6;
}
body.playing.touch #touch { display: flex; }
.t-left { display: flex; gap: 14px; }
#touch button {
  pointer-events: auto;
  touch-action: none;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(20, 40, 29, 0.45);
  backdrop-filter: blur(4px);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
#touch .t-jump { width: 140px; height: 140px; font-size: 22px; background: rgba(242, 193, 78, 0.6); }
#touch button.pressed { transform: scale(0.93); background: rgba(255, 255, 255, 0.4); }

/* ---------- Einblendung ---------- */

#banner {
  position: fixed;
  left: 50%;
  top: 36%;
  transform: translate(-50%, -50%);
  max-width: 92vw;
  text-align: center;
  font-size: clamp(36px, 8vw, 84px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 7;
}
#banner.pop { animation: pop 1.3s ease-out forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}

/* Vergleich mit dem Geisterpferd im Ergebnis */
.geist-vergleich { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; background: rgba(159, 180, 200, 0.15); }
.geist-vergleich.besser { background: rgba(242, 193, 78, 0.2); color: var(--accent); font-weight: 600; }

/* Stall */
.taler { font-size: 18px; color: var(--accent); margin-left: 10px; font-weight: 700; }
.kaufen { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .kaufen { grid-template-columns: 1fr; } }
.rassen { display: grid; gap: 8px; }
.rasse .preis { float: right; color: var(--accent); font-weight: 700; }
.rasse.gesperrt { opacity: 0.6; }
.konfig { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 12px 16px; }
.konfig h3 { font-size: 15px; margin: 14px 0 4px; color: var(--muted); }
.konfig-canvas { width: 100%; height: 200px; display: block; }
.chips.wahl { margin: 4px 0; }
.chips.wahl .chip { font: inherit; font-size: 14px; color: var(--text); border: 2px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.chips.wahl .chip.sel { border-color: var(--accent); background: rgba(242, 193, 78, 0.18); }
.name-feld { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; font-weight: 600; }
.name-feld input, .sattel-wahl select {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px;
}
.sattel-wahl { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }
.sattel-wahl select { flex: 1; }
.sattel-wahl option { color: #222; }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.taler-plus { color: var(--accent); font-weight: 700; }

/* Filter der Bestenliste */
.score-filter { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 12px; }
.score-filter .tabs { margin: 0; }
.score-filter label { display: flex; align-items: center; gap: 8px; }
.score-filter select { font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.score-filter option, .score-filter optgroup { color: #222; }

/* Profil */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kachel { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 12px 14px; }
.kachel b { display: block; font-size: 28px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kachel small { color: var(--muted); }
#screen-profil h3 { margin: 18px 0 6px; }

/* Siegerpodium im Endstand */
.podium { display: block; width: 100%; height: 280px; margin: 4px 0 12px; }
.podium[hidden] { display: none; }
