:root {
  --grund: #16171b;
  --flaeche: #23252b;
  --rand: #34373f;
  --text: #ecebe6;
  --leise: #9a9ca3;
  --akzent: #c8c6bd;
  --rot: #c23a3a;
  --blau: #3456b8;
  --taste: #2e3038;
  --taste-hell: #3d404a;
  --taste-an: #575b67;
  --ab: #8f2448;
  --ab-an: #b8345f;
  --ok: #7fbf7f;
  --warn: #e0b04f;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--grund);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.im-spiel { overflow: hidden; position: fixed; inset: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; letter-spacing: -.01em; }
.leise { color: var(--leise); }
.klein { font-size: .9rem; max-width: 34em; }

.ansicht { min-height: 100%; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.zentriert { display: flex; align-items: center; justify-content: center; text-align: center; }

/* Anmelden */
.karte { width: min(100%, 340px); display: grid; gap: 14px; text-align: left; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 18px; padding: 28px 24px; }
.karte h1 { text-align: center; margin: 0 0 6px; }
.logo { width: 56px; height: 56px; justify-self: center; }
label { display: grid; gap: 6px; font-size: .9rem; color: var(--leise); }
input { font: inherit; font-size: 17px; color: var(--text); background: var(--grund); border: 1px solid var(--rand); border-radius: 10px; padding: 11px 12px; }
input:focus { outline: 2px solid var(--akzent); outline-offset: 1px; }
.haupt { background: var(--text); color: var(--grund); border: 0; border-radius: 10px; padding: 12px; font-weight: 600; margin-top: 4px; }
.haupt:disabled { opacity: .6; }
.fehler { color: #f08a8a; min-height: 1.3em; margin: 0; font-size: .9rem; }
.schlicht { background: none; border: 1px solid var(--rand); border-radius: 9px; padding: 6px 12px; color: var(--leise); }
.schlicht:active { background: var(--flaeche); }

/* Auswahl: zwei Module */
.auswahl { display: grid; justify-items: center; gap: 8px; }
.module { display: flex; gap: clamp(16px, 5vw, 40px); margin: 8px 0 18px; flex-wrap: wrap; justify-content: center; }
.modul {
  width: clamp(130px, 34vw, 190px); aspect-ratio: 57 / 65; border: 0; border-radius: 8px 22px 8px 8px;
  background: #8b8d93; position: relative; padding: 0;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.18), 0 10px 24px rgba(0,0,0,.35);
  transition: transform .12s ease;
}
.modul::before { /* Rillen oben */
  content: ""; position: absolute; left: 10%; right: 22%; top: 6%; height: 7%;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.18) 0 3px, transparent 3px 7px); border-radius: 2px;
}
.modul-etikett {
  position: absolute; left: 9%; right: 9%; top: 20%; bottom: 12%; border-radius: 6px;
  display: flex; align-items: flex-end; padding: 10px 12px; text-align: left;
  font-weight: 800; font-size: clamp(15px, 3.6vw, 20px); line-height: 1.1; color: #fff; letter-spacing: .01em;
}
.modul.rot .modul-etikett { background: linear-gradient(160deg, #e2574c, var(--rot) 60%, #8e2424); }
.modul.blau .modul-etikett { background: linear-gradient(160deg, #5a7fe0, var(--blau) 60%, #22397f); }
.modul:active { transform: translateY(3px) scale(.98); }
.modul:focus-visible { outline: 3px solid var(--akzent); outline-offset: 4px; }

/* Spiel */
#ansicht-spiel {
  height: 100%; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: grid; grid-template-rows: auto 1fr auto; grid-template-areas: "leiste" "bild" "steuer"; gap: 8px;
}
.leiste { grid-area: leiste; display: flex; align-items: center; gap: 10px; min-height: 36px; }
.leiste-rechts { margin-left: auto; display: flex; gap: 8px; }
.umschalter { min-width: 44px; min-height: 36px; padding: 4px 10px; font-size: 18px; line-height: 1; }
.umschalter[aria-pressed="true"]#schnell { background: var(--taste-hell); color: var(--text); }
.status { font-size: .85rem; color: var(--leise); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status[data-art="ok"] { color: var(--ok); }
.status[data-art="warn"] { color: var(--warn); }

.bildschirm-rahmen { grid-area: bild; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; overflow: hidden; }
#bildschirm {
  image-rendering: pixelated; image-rendering: crisp-edges; background: #000;
  border-radius: 6px; box-shadow: 0 0 0 10px #0d0e10, 0 0 0 11px var(--rand);
  max-width: calc(100% - 24px); max-height: calc(100% - 24px);
}
.tasten-hilfe { margin: 6px 0 0; font-size: .8rem; color: var(--leise); text-align: center; }
body.touch .tasten-hilfe { display: none; }
body:not(.touch) .steuerung { display: none; }

/* Steuerung */
.steuerung {
  grid-area: steuer; --g: clamp(150px, min(42vw, 30vh), 230px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 4px;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
.block-links, .block-mitte, .block-rechts { touch-action: none; }
.block-links { justify-self: start; }
.block-rechts { justify-self: end; }
.block-mitte { align-self: end; }

.kreuz { position: relative; width: var(--g); height: var(--g); }
.kreuz .arm, .kreuz .mitte { position: absolute; background: var(--taste); pointer-events: none; }
.kreuz .hoch, .kreuz .runter { left: 33.5%; width: 33%; height: 35%; }
.kreuz .links, .kreuz .rechts { top: 33.5%; height: 33%; width: 35%; }
.kreuz .hoch { top: 0; border-radius: 8px 8px 0 0; }
.kreuz .runter { bottom: 0; border-radius: 0 0 8px 8px; }
.kreuz .links { left: 0; border-radius: 8px 0 0 8px; }
.kreuz .rechts { right: 0; border-radius: 0 8px 8px 0; }
.kreuz .mitte { left: 33.5%; top: 33.5%; width: 33%; height: 33%; }
.kreuz .mitte::after { content: ""; position: absolute; inset: 28%; border-radius: 50%; background: var(--grund); opacity: .35; }
.kreuz .arm.an { background: var(--taste-an); }
.kreuz::before { /* große Trefferfläche, unsichtbar */ content: ""; position: absolute; inset: -12%; }

.ab { position: relative; width: calc(var(--g) * 1.05); height: calc(var(--g) * .8); }
.rund-wrap { position: absolute; width: 50%; display: grid; justify-items: center; }
.rund-wrap.b { left: 0; bottom: 0; }
.rund-wrap.a { right: 0; top: 0; }
.rund {
  width: calc(var(--g) * .4); height: calc(var(--g) * .4); border-radius: 50%;
  background: var(--ab); display: grid; place-items: center; font-weight: 800; font-size: calc(var(--g) * .11); color: rgba(255,255,255,.75);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.25);
}
.rund.an { background: var(--ab-an); box-shadow: inset 0 2px 0 rgba(0,0,0,.25); }

.klein-tasten { display: flex; gap: clamp(10px, 3vw, 22px); padding-bottom: 6px; }
.pille-wrap { display: grid; justify-items: center; gap: 6px; }
.pille-wrap small { font-size: 10px; letter-spacing: .12em; color: var(--leise); pointer-events: none; }
.pille { width: clamp(46px, 11vw, 64px); height: 18px; border-radius: 9px; background: var(--taste-hell); transform: rotate(-22deg); }
.pille.an { background: var(--taste-an); }
/* größere Trefferfläche für Start/Select */
.pille { position: relative; }
.pille::after { content: ""; position: absolute; inset: -14px -6px; }

/* Querformat (iPad quer, Handy quer): Kreuz links, Bild Mitte, Tasten rechts */
@media (orientation: landscape) {
  body.touch #ansicht-spiel {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-rows: auto 1fr;
    grid-template-areas: "leiste leiste leiste" "links bild rechts";
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  }
  body.touch .block-links, body.touch .block-rechts, body.touch .block-mitte { --g: clamp(120px, min(19vw, 36vh), 220px); }
  body.touch .steuerung { display: contents; }
  body.touch .block-links { grid-area: links; justify-self: center; align-self: center; }
  body.touch .block-rechts { grid-area: rechts; justify-self: center; align-self: center; display: grid; gap: 40px; justify-items: center; }
  body.touch .block-mitte { grid-area: rechts; align-self: end; justify-self: center; margin-bottom: 12px; }
  body.touch .bildschirm-rahmen { width: min(56vw, calc((100vh - 70px) * 160 / 144)); }
}

/* Spielfarbe als feiner Akzent */
body[data-spiel="rot"] #bildschirm { box-shadow: 0 0 0 10px #0d0e10, 0 0 0 11px #5a2a2a; }
body[data-spiel="blau"] #bildschirm { box-shadow: 0 0 0 10px #0d0e10, 0 0 0 11px #2a375a; }

@media (prefers-reduced-motion: reduce) { .modul { transition: none; } }
