/* Freier Tahoma-Nachbau aus dem Wine-Projekt, siehe fonts/LIZENZ.txt */
@font-face {
  font-family: "Karten Tahoma";
  src: url("fonts/tahoma.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Karten Tahoma";
  src: url("fonts/tahomabd.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f3f1ea;
  --surface: #ffffff;
  --ink: #20231e;
  --muted: #5f6459;
  --line: #dcd9ce;
  --accent: #3c7a1b;
  --accent-soft: #e7f0dc;
  --tap: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 "Karten Tahoma", Tahoma, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { display: block; flex: none; }

/* Auswahlseite */
.home {
  max-width: 880px;
  margin: 0 auto;
  padding: calc(28px + var(--safe-t)) calc(16px + var(--safe-r)) calc(28px + var(--safe-b)) calc(16px + var(--safe-l));
}
/* Das Logo hat einen weißen Hintergrund; multiply lässt ihn im App-Hintergrund verschwinden. */
.logo { display: block; flex: none; width: auto; height: 40px; mix-blend-mode: multiply; }
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.home-head .logo { height: 44px; }
.home h1 { margin: 0; font-size: 26px; line-height: 1.15; }
.home header p { margin: 4px 0 20px; color: var(--muted); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  box-shadow: 0 1px 2px rgb(0 0 0 / .12), 0 6px 18px rgb(0 0 0 / .08);
}
.tile-bild { display: block; width: 100%; aspect-ratio: 2000 / 1326; }
.tile-icon { display: grid; place-items: center; font-weight: 700; letter-spacing: .06em; }
.tile-gruppe { background: var(--accent-soft); color: var(--accent); }
.tile-bald { box-shadow: inset 0 0 0 1px var(--line); background: transparent; color: var(--muted); }
.tile-bald .tile-icon { background: #e8e5dc; }
.tile-text { display: block; padding: 10px 12px 12px; }
.tile-text strong { display: block; font-size: 16px; line-height: 1.25; }
.tile-text small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; line-height: 1.3; }

/* Gruppenseiten */
[hidden] { display: none !important; }
.page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.page .bar { max-width: 880px; margin: 0 auto; }
.page-body { max-width: 560px; margin: 0 auto; padding: 4px 16px 32px; }
.hint { margin: 0 0 16px; color: var(--muted); }
.hint.klein { margin-top: 14px; font-size: 14px; text-align: center; }
.hint.mitte { margin-top: 14px; text-align: center; }
.label { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.choices { display: grid; gap: 12px; }
.choices.zwei { grid-template-columns: 1fr 1fr; }
.choice {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 88px;
  padding: 16px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  text-decoration: none;
  box-shadow: 0 1px 2px rgb(0 0 0 / .12), 0 6px 18px rgb(0 0 0 / .08);
}
.choice strong { font-size: 18px; }
.choice small { color: var(--muted); font-size: 14px; line-height: 1.3; }
.choice .gross { font-size: 30px; font-weight: 700; line-height: 1.1; }
.segment {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 12px;
  background: #e8e5dc;
}
.segment button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
}
.segment button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .18); }
.btn, .btn-sec {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.btn { background: var(--accent); color: #fff; }
.btn-sec { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn:disabled, .btn-sec:disabled { opacity: .4; cursor: default; }
.stack { display: grid; gap: 10px; }
.stack.schmal { max-width: 340px; margin: 16px auto 0; }
.hint.gross-abstand { margin-top: 48px; font-size: 18px; }
.choice:disabled { opacity: .5; cursor: default; }
.qr-info { margin: 0 0 12px; color: var(--muted); text-align: center; }
.qr-info strong { display: block; color: var(--ink); font-size: 22px; }
.qr-box {
  width: min(100%, 340px, 56dvh);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 6px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / .12), 0 6px 18px rgb(0 0 0 / .08);
}
.qr-box svg { display: block; width: 100%; height: auto; }
.qr-nav { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; max-width: 340px; margin: 16px auto 0; }
.scanner {
  position: relative;
  width: min(100%, 420px);
  height: min(62dvh, 520px);
  margin: 0 auto;
  overflow: hidden;
  border-radius: 14px;
  background: #1d1f1c;
}
.scanner video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scan-rahmen {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 62%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid rgb(255 255 255 / .9);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgb(0 0 0 / .28);
}
.install {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}
.install p { margin: 0; }
.install button {
  min-height: var(--tap);
  margin-bottom: 10px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Kartenansicht */
.viewer {
  display: grid;
  grid-template: "bar" auto "track" minmax(0, 1fr) "pos" auto "controls" auto / minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 72px;
  padding: 6px 8px;
}
.bar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0 4px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.bar .logo { margin: 0 6px 0 2px; }

.track {
  grid-area: track;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.track::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%;
  display: grid;
  place-items: center;
  container-type: size;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.card {
  display: block;
  width: min(100cqw - 24px, (100cqh - 16px) * 1.5083);
  aspect-ratio: 2000 / 1326;
  padding: 0;
  border: 0;
  background: none;
  perspective: 1400px;
}
.card-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.3, .7, .3, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / .18), 0 8px 24px rgb(0 0 0 / .14);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-user-drag: none;
  user-select: none;
}
.face.back { transform: rotateY(180deg); }

.pos {
  grid-area: pos;
  margin: 0;
  padding: 4px 16px 2px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  gap: 8px;
  padding: 8px 12px 12px;
}
.flip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.controls .icon-btn { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.controls.einzeln { grid-template-columns: minmax(0, 1fr); }

/* Handy quer: Karte maximal groß, Bedienung seitlich */
@media (orientation: landscape) and (max-height: 520px) {
  .viewer {
    grid-template: "bar track controls" minmax(0, 1fr) "bar track pos" auto / auto minmax(0, 1fr) auto;
  }
  .viewer .bar { flex-direction: column; justify-content: space-between; padding: 8px 0 8px 8px; }
  .viewer .bar h1, .flip-btn span, .pos .seite { display: none; }
  .controls.einzeln { grid-template-rows: var(--tap); }
  .viewer .bar .logo {
    position: fixed;
    top: calc(12px + var(--safe-t));
    right: calc(8px + var(--safe-r));
    width: var(--tap);
    height: auto;
    margin: 0;
  }
  .controls {
    grid-template-columns: var(--tap);
    grid-template-rows: var(--tap) var(--tap) var(--tap);
    align-content: center;
    padding: 8px 8px 0 0;
  }
  .pos { padding: 0 8px 8px 0; }
  .card { width: min(100cqw - 12px, (100cqh - 8px) * 1.5083); }
}

/* Inhaltsverzeichnis */
#toc {
  width: min(100%, 560px);
  max-width: none;
  max-height: min(86dvh, 720px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
}
#toc[open] { display: flex; flex-direction: column; }
#toc::backdrop { background: rgb(20 22 18 / .5); }
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 4px 16px;
  border-bottom: 1px solid var(--line);
}
.toc-head h2 { margin: 0; font-size: 18px; }
.toc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 6px 6px calc(10px + var(--safe-b));
  list-style: none;
}
.toc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.toc-item[aria-current] { background: var(--accent-soft); }
.toc-item img {
  flex: none;
  width: 72px;
  height: 48px;
  border-radius: 5px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .1);
}
.toc-item strong { display: block; font-size: 15px; font-weight: 600; line-height: 1.25; }
.toc-item small { display: block; margin-top: 1px; color: var(--muted); font-size: 13px; line-height: 1.25; }

@media (orientation: landscape) and (max-height: 520px) {
  #toc { max-height: 100dvh; margin: auto auto 0; border-radius: 18px 18px 0 0; }
}

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