:root {
  --bg: #eef0e6;
  --card: #ffffff;
  --ink: #262b1e;
  --muted: #6b7160;
  --primary: #6c7d17;
  --primary-dark: #55630f;
  --ok: #4f8a10;
  --bad: #dc2626;
  --bad-bg: #fde2e2;
  --road: #3b4452;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 40, 80, .08);
}
* { box-sizing: border-box; }
:root { accent-color: #6c7d17; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 Raleway, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  max-width: 1400px; margin: 0 auto; min-height: 80px;
  padding: 6px 28px; background: #fff; border-top: 17px solid var(--primary);
  box-shadow: 0 .8px 16px rgba(0,0,0,.15);
}
.topbar::after { content: ""; }   /* leere rechte Spalte, damit der Titel genau in der Mitte steht */
.school { display: flex; align-items: center; gap: 10px; grid-column: 1; justify-self: start; }
.school-logo { height: 52px; width: auto; display: block; }
.school-name {
  display: flex; flex-direction: column; color: var(--primary);
  font-family: Helvetica, Tahoma, Geneva, Arial, sans-serif; font-weight: 300;
  font-size: 15px; line-height: 1; text-transform: uppercase; letter-spacing: .02em;
}
.school-name span, .school-name b { font-weight: 300; padding-right: 22px; }
.school-name span { border-bottom: 1px solid var(--primary); padding-bottom: 4px; margin: 4px 0 5px; }
.app-title { font-weight: 800; font-size: 1.3rem; color: var(--ink); text-align: center; grid-column: 2; }
.app-title small { display: block; font-weight: 500; font-size: .85rem; color: var(--muted); }
main { max-width: 1000px; margin: 28px auto; padding: 0 16px; }

.screen { display: none; }
.screen.active { display: block; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
h1 { margin: 0 0 20px; font-size: 1.6rem; }

/* ---------- Einleitung ---------- */
.intro {
  margin: -4px 0 24px; padding: 16px 20px; border-radius: 12px;
  background: linear-gradient(135deg, #e3e8cc, #f4f6ec); border-left: 5px solid var(--primary);
}
.intro p { margin: 0; color: #3d4430; }
.intro .intro-lead { font-size: 1.35rem; font-weight: 800; color: var(--ink); margin-bottom: 6px; }

/* ---------- Formular ---------- */
.field { display: block; margin-bottom: 20px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=number], select {
  font: inherit; padding: 10px 12px; border: 2px solid #d6dacb; border-radius: 10px;
  width: 100%; background: #fff; color: var(--ink);
}
input[type=number] { width: 130px; }
input:focus, select:focus { outline: none; border-color: var(--primary); }
.hint { color: var(--muted); font-size: .9rem; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.center { justify-content: center; margin-top: 24px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.presets button {
  font: inherit; padding: 6px 14px; border-radius: 999px; border: 2px solid #d6dacb;
  background: #fff; cursor: pointer;
}
.presets button.active { border-color: var(--primary); background: #eef2dc; color: var(--primary-dark); font-weight: 600; }
.segmented { display: inline-flex; border: 2px solid #d6dacb; border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.segmented label { cursor: pointer; }
.segmented input { display: none; }
.segmented span { display: block; padding: 8px 16px; }
.segmented input:checked + span { background: var(--primary); color: #fff; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.error-msg { color: var(--bad); font-weight: 600; }

.btn {
  font: inherit; font-weight: 600; padding: 10px 20px; border-radius: 10px; cursor: pointer;
  border: 2px solid #d6dacb; background: #fff; color: var(--ink);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.big { font-size: 1.15rem; padding: 14px 32px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Rennstrecke ---------- */
.track {
  position: relative; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  background:
    radial-gradient(ellipse at 50% -40%, rgba(255,255,255,.10), transparent 60%),
    linear-gradient(180deg, #2b313b, #20252d);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.05);
  overflow: hidden;
}
/* rot-weiße Randsteine oben und unten */
.track::before, .track::after {
  content: ""; position: absolute; left: 0; right: 0; height: 6px;
  background: repeating-linear-gradient(90deg, #e53935 0 18px, #f5f5f5 18px 36px);
}
.track::before { top: 0; }
.track::after { bottom: 0; }

.lane { position: relative; height: 70px; display: flex; align-items: center; }
.lane .stripes {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.45) 0 32px, transparent 32px 64px);
}
.lane:last-child .stripes { display: none; }
.lane.me { background: linear-gradient(90deg, rgba(255,204,0,.10), rgba(255,204,0,0) 70%); border-radius: 8px; }
.lane .finish {
  position: absolute; right: 0; top: 4px; bottom: 4px; width: 16px; border-radius: 2px;
  background: repeating-conic-gradient(#fff 0 25%, #111 0 50%) 0 0 / 8px 8px;
  box-shadow: 0 0 10px rgba(255,255,255,.25);
}
.lane .road { position: absolute; left: 0; right: 24px; top: 0; bottom: 0; }

.car {
  position: absolute; top: 50%; left: 0; width: 120px; height: 42px;
  transform: translate(0, -50%); will-change: transform;
}
.car .body { position: relative; width: 100%; height: 100%; transform-origin: 30% 80%; z-index: 2; }
.car svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 3px 3px rgba(0,0,0,.45)); }
.car .wheel, .car .leg { transform-box: view-box; }

/* Fahrtwind-Linien hinter dem Auto */
.car .speedlines { position: absolute; right: 100%; top: 0; bottom: 0; width: 70px; opacity: 0; z-index: 1; }
.car .speedlines i {
  position: absolute; right: -6px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.75));
  animation: whoosh .35s linear infinite;
}
.car .speedlines i:nth-child(1) { top: 22%; width: 46px; }
.car .speedlines i:nth-child(2) { top: 50%; width: 66px; animation-delay: -.12s; }
.car .speedlines i:nth-child(3) { top: 74%; width: 38px; animation-delay: -.24s; }
@keyframes whoosh { from { transform: translateX(10px); opacity: 1; } to { transform: translateX(-26px); opacity: 0; } }

/* Auspuff-Flamme */
.car .flame {
  position: absolute; right: calc(100% - 8px); top: 60%; width: 18px; height: 7px; opacity: 0;
  transform-origin: right center; border-radius: 50% 0 0 50%; z-index: 1;
  background: radial-gradient(ellipse at right, #fff 0 20%, #ffd54a 35%, #ff7a00 60%, transparent 75%);
  filter: blur(.4px);
}

/* Wackeln bei Tippfehler */
.lane.hit .car .body { animation: carhit .3s; }
@keyframes carhit {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-4deg) translateX(-3px); }
  60% { transform: rotate(3deg) translateX(2px); }
}

.lane .label {
  position: absolute; top: 50%; left: 0; transform: translate(126px, -50%);
  color: #fff; font-size: .85rem; font-weight: 700; white-space: nowrap; pointer-events: none;
  background: rgba(0,0,0,.35); padding: 1px 8px; border-radius: 999px; transition: opacity .2s;
}
.lane.me .label { color: #1d2a3a; background: #ffcc00; }
.lane .place-tag {
  position: absolute; right: 30px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 1rem; color: #1d2a3a; background: #cfd6df;
  box-shadow: 0 2px 6px rgba(0,0,0,.45), inset 0 -2px 0 rgba(0,0,0,.15); z-index: 3;
}
.lane .place-tag:empty { display: none; }
.lane .place-tag.p1 { background: linear-gradient(180deg, #ffe680, #f5b800); }
.lane .place-tag.p2 { background: linear-gradient(180deg, #f2f4f7, #aab4c0); }
.lane .place-tag.p3 { background: linear-gradient(180deg, #f0b98a, #c2763a); }
.lane .place-tag.p4 { background: linear-gradient(180deg, #8b95a3, #5d6774); color: #fff; }
.lane .place-tag.done::after {
  content: "🏁"; position: absolute; right: -18px; top: -8px; font-size: .8rem;
}
.lane .place-tag.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: translateY(-50%) scale(1.6); } 100% { transform: translateY(-50%) scale(1); } }

/* ---------- Statistik ---------- */
.stats-bar, .result-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px;
}
.stats-bar > div, .result-grid > div {
  background: var(--card); border-radius: 12px; padding: 10px; text-align: center; box-shadow: var(--shadow);
}
.stats-bar b, .result-grid b { display: block; font-size: 1.4rem; }
.stats-bar span, .result-grid span { color: var(--muted); font-size: .8rem; }
.stats-bar.six { grid-template-columns: repeat(6, 1fr); }
.place-box { transition: background .3s; }
.place-box[hidden] { display: none; }
.place-box.p1 { background: linear-gradient(180deg, #fff6cc, #ffe27a); }
.place-box.p2 { background: linear-gradient(180deg, #f7f8fa, #dde3ea); }
.place-box.p3 { background: linear-gradient(180deg, #fbe7d6, #f0c39c); }
.place-box.p4 { background: linear-gradient(180deg, #eef0f3, #cfd5dc); }

/* ---------- Tippfeld ---------- */
.typing { position: relative; cursor: text; }
.text-display {
  font-family: "Consolas", "Menlo", "DejaVu Sans Mono", monospace; font-size: 1.45rem; line-height: 1.9;
  max-height: calc(1.9em * 4); overflow: hidden; word-break: normal; overflow-wrap: anywhere;
  user-select: none;
}
.text-display .w { white-space: nowrap; display: inline; }
.text-display span.c { border-radius: 3px; }
.text-display .done { color: var(--ok); }
.text-display .cur { background: #e3ebbf; box-shadow: inset 0 -3px 0 var(--primary); }
.text-display .cur.err { background: var(--bad-bg); box-shadow: inset 0 -3px 0 var(--bad); color: var(--bad); animation: shake .18s; }
.text-display .wasErr { text-decoration: underline wavy var(--bad); text-decoration-thickness: 1px; text-underline-offset: 5px; }
.text-display .todo { color: var(--ink); }
@keyframes shake { 0%,100% { transform: translateX(0); } 33% { transform: translateX(-2px); } 66% { transform: translateX(2px); } }

.hidden-input { position: absolute; opacity: 0; left: 0; top: 0; width: 1px; height: 1px; border: 0; padding: 0; }
.focus-hint, .countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.85); border-radius: var(--radius); font-weight: 700; font-size: 1.2rem;
}
.focus-hint[hidden], .countdown[hidden] { display: none; }
.countdown { font-size: 4rem; color: var(--primary); }
.race-actions { margin-top: 12px; text-align: right; }

/* ---------- Bildschirmtastatur ---------- */
.kb {
  margin-top: 14px; padding: 12px; background: #262b1e; border-radius: var(--radius); box-shadow: var(--shadow);
  user-select: none;
}
.kb[hidden] { display: none; }
.kb-row { display: flex; gap: 5px; margin-bottom: 5px; }
.key {
  position: relative; min-width: 0; height: 44px; border-radius: 7px;
  background: #f3f5f8; color: #2a3442; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 1rem; transition: transform .1s;
}
.key .b { font-size: 1.05rem; }
.key .s { position: absolute; left: 6px; top: 3px; font-size: .7rem; opacity: .7; }
.key .a { position: absolute; right: 6px; bottom: 4px; font-size: .65rem; opacity: .55; }
.key .s + .b { position: absolute; left: 6px; bottom: 4px; font-size: .9rem; }
.key .m { font-size: .72rem; font-weight: 600; opacity: .75; white-space: nowrap; overflow: hidden; }
.key.home::after {
  content: ""; position: absolute; bottom: 7px; left: 50%; width: 12px; height: 2px; margin-left: -6px;
  background: currentColor; border-radius: 2px; opacity: .6;
}
/* dezente Fingerfarben (links und rechts gleich) */
.f-lp, .f-rp { --fc: #fde2e4; }
.f-lr, .f-rr { --fc: #fff1c9; }
.f-lm, .f-rm { --fc: #d9f2df; }
.f-li, .f-ri { --fc: #dbe9ff; }
.f-th { --fc: #ece3fb; }
.key { background: var(--fc, #f3f5f8); }
.key.mod { background: #c9d0da; }
/* nächste Taste */
.key.next {
  background: var(--primary); color: #fff; transform: translateY(-2px);
  box-shadow: 0 0 0 3px rgba(255,255,255,.9), 0 0 16px 4px rgba(108,125,23,.8);
  z-index: 1;
}
.key.next .s, .key.next .a, .key.next .m { opacity: 1; }
.key.next.err { background: var(--bad); box-shadow: 0 0 0 3px #fff, 0 0 16px 4px rgba(220,38,38,.7); animation: keyshake .25s; }
@keyframes keyshake { 0%,100% { transform: translate(0,-2px); } 33% { transform: translate(-3px,-2px); } 66% { transform: translate(3px,-2px); } }
.kb-legend { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; font-size: .78rem; }
.kb-legend span { background: var(--fc); color: #2a3442; padding: 2px 10px; border-radius: 999px; font-weight: 600; }
@media (max-width: 700px) {
  .key { height: 34px; font-size: .8rem; }
  .key .m, .key .s, .key .a { display: none; }
}

/* ---------- Ergebnis ---------- */
#screen-result { text-align: center; }
.place { font-size: 3.6rem; line-height: 1; margin-bottom: 8px; }
.result-grid { grid-template-columns: repeat(3, 1fr); margin: 20px 0; }
.ranking { max-width: 420px; margin: 0 auto 16px; text-align: left; }
.ranking ol { padding-left: 24px; margin: 6px 0; }
.ranking li.me { font-weight: 700; color: var(--primary-dark); }
.errchars { color: var(--muted); }
.errchars kbd {
  display: inline-block; min-width: 28px; padding: 2px 8px; margin: 2px; border-radius: 6px;
  background: var(--bad-bg); color: var(--bad); font-family: monospace; font-size: 1rem; font-weight: 700;
}

@media (max-width: 700px) {
  .stats-bar, .stats-bar.six { grid-template-columns: repeat(3, 1fr); }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .text-display { font-size: 1.15rem; }
}

/* =========================================================
   SZENARIEN
   ========================================================= */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.themes label { cursor: pointer; }
.themes input { display: none; }
.themes span {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px;
  border: 2px solid #d6dacb; border-radius: 12px; font-weight: 600; transition: transform .1s;
}
.themes span b { font-size: 2rem; line-height: 1; }
.themes input:checked + span { border-color: var(--primary); background: #eef2dc; color: var(--primary-dark); transform: translateY(-2px); }

.snowfall { display: none; }

/* ---------- Pferderennen ---------- */
.track.theme-horse {
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0 60px, rgba(0,0,0,.05) 60px 120px),
    linear-gradient(180deg, #4f9a3c, #3d8030);
}
.track.theme-horse::before, .track.theme-horse::after {
  height: 7px; background:
    repeating-linear-gradient(90deg, #6b4a2a 0 4px, transparent 4px 46px),
    linear-gradient(#fff, #e7e7e7);
}
.theme-horse .lane .stripes { background: repeating-linear-gradient(90deg, rgba(255,255,255,.35) 0 20px, transparent 20px 64px); height: 2px; }
.theme-horse .lane.me { background: linear-gradient(90deg, rgba(255,230,120,.22), rgba(255,230,120,0) 70%); }
.theme-horse .car { width: 122px; height: 64px; }
.theme-horse .car .flame {      /* aufgewirbelter Staub */
  right: calc(100% - 46px); top: auto; bottom: -2px; width: 34px; height: 14px; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(214,190,140,.95) 0 30%, rgba(190,160,110,.5) 55%, transparent 72%);
  filter: blur(1px); transform-origin: right bottom;
}
.theme-horse .car .speedlines i { background: linear-gradient(90deg, transparent, rgba(255,255,255,.6)); }

/* ---------- Schlittenrennen ---------- */
.track.theme-sleigh {
  background:
    radial-gradient(ellipse at 20% -20%, rgba(255,255,255,.9), transparent 55%),
    linear-gradient(180deg, #eaf4fd, #cfe3f5);
}
.track.theme-sleigh::before, .track.theme-sleigh::after {
  height: 8px; background: repeating-linear-gradient(-45deg, #d62828 0 8px, #fff 8px 16px);
}
.theme-sleigh .lane .stripes {      /* Kufenspuren im Schnee */
  height: 5px; bottom: 0;
  background:
    repeating-linear-gradient(90deg, rgba(120,150,185,.45) 0 44px, transparent 44px 64px) top / 100% 1.5px no-repeat,
    repeating-linear-gradient(90deg, rgba(120,150,185,.45) 0 44px, transparent 44px 64px) bottom / 100% 1.5px no-repeat;
}
.theme-sleigh .lane.me { background: linear-gradient(90deg, rgba(255,210,0,.25), rgba(255,210,0,0) 70%); }
.theme-sleigh .car { width: 150px; height: 56px; }
.theme-sleigh .car .flame {        /* Schnee-Glitzer hinter den Kufen */
  right: calc(100% - 10px); top: auto; bottom: 0; width: 40px; height: 14px; border-radius: 50%;
  background: radial-gradient(ellipse at right, #fff 0 25%, rgba(255,255,255,.7) 45%, transparent 72%);
  filter: drop-shadow(0 0 4px #bfe3ff); transform-origin: right bottom;
}
.theme-sleigh .car .speedlines i { background: linear-gradient(90deg, transparent, rgba(80,130,190,.55)); }
.theme-sleigh .finish { box-shadow: 0 0 10px rgba(80,120,170,.4); }
.theme-sleigh .snowfall {
  display: block; position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background-image:
    radial-gradient(3px 3px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(4px 4px at 80px 120px, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 140px 70px, #fff 50%, transparent 51%),
    radial-gradient(3.5px 3.5px at 200px 180px, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 260px 20px, #fff 50%, transparent 51%),
    radial-gradient(2.5px 2.5px at 110px 200px, #fff 50%, transparent 51%),
    radial-gradient(4px 4px at 240px 100px, #fff 50%, transparent 51%);
  background-size: 300px 220px;
  filter: drop-shadow(0 0 1.5px rgba(70,110,160,.9));
  animation: snow 6s linear infinite;
}
@keyframes snow { from { background-position: 0 0; } to { background-position: -120px 220px; } }

@media (max-width: 700px) {
  .themes span b { font-size: 1.5rem; }
  .theme-sleigh .car { width: 120px; height: 45px; }
}

/* =========================================================
   IMPRESSUM / DATENSCHUTZ / FUSSZEILE
   ========================================================= */
a.school { text-decoration: none; }
.sitefooter {
  text-align: center; padding: 18px 16px 28px; color: var(--muted); font-size: .9rem;
}
.sitefooter a { color: var(--primary); text-decoration: none; font-weight: 600; }
.sitefooter a:hover { text-decoration: underline; }

.legal { max-width: 860px; margin: 0 auto; line-height: 1.6; }
.legal h1 { color: var(--primary); }
.legal h2 { font-size: 1.25rem; margin: 28px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--primary); color: var(--primary); }
.legal h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.legal p, .legal ul { margin: 0 0 10px; }
.legal a { color: var(--primary-dark); }
.legal .back { margin: 0 0 8px; }
.legal .back a { text-decoration: none; font-weight: 600; }
.legal table.contact { border-collapse: collapse; margin: 6px 0 12px; }
.legal table.contact th { text-align: left; font-weight: 600; padding: 2px 20px 2px 0; color: var(--muted); vertical-align: top; }
.legal table.contact td { padding: 2px 0; }
.legal .summary {
  background: linear-gradient(135deg, #e3e8cc, #f4f6ec); border-left: 5px solid var(--primary);
  border-radius: 10px; padding: 12px 16px; margin: 4px 0 8px;
}
.legal .tip { background: #fff8db; border-radius: 10px; padding: 10px 14px; }
.legal .todo { background: #fff3b0; outline: 2px dashed #e0b000; border-radius: 4px; padding: 0 4px; }

@media (max-width: 700px) {
  .topbar { grid-template-columns: 1fr; justify-items: center; padding: 10px 16px; }
  .topbar::after { display: none; }
  .school, .app-title { grid-column: 1; justify-self: center; }
}
.app-name { display: inline-flex; align-items: center; gap: 12px; color: var(--primary-dark); }
.app-flag { height: 1.5em; width: auto; display: block; }
