/*
  Kamishibai – Corporate Design der Katholischen KiTa gGmbH Saarland
  (wie gruppe7.ministo.de / kita-picturemod): Blau #003885, Dunkelblau
  #00265C, Gelb #FFD302, Schrift Carlito (metrisch gleich zu Calibri).
  Bedienung nach den Apple Human Interface Guidelines: Tippflächen ≥ 44 pt,
  sichere Bereiche, Bewegung reduzieren, Zustände sichtbar.
*/

@font-face {
  font-family: "Carlito";
  src: url("/fonts/carlito-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Carlito";
  src: url("/fonts/carlito-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --blue: #003885;
  --blue-dark: #00265c;
  --blue-link: #3d6fb4;
  --yellow: #ffd302;
  --tint-blue: #eaf0fa;
  --bg-grey: #f5f7fa;
  --ink: #2a2a2a;
  --ink-soft: #5c6672;
  --line: #d7deea;
  --white: #ffffff;
  --red: #c4291c;
  --radius: 0.75rem;
  --tap: 2.75rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

/*
  Skalierung: Alle Maße sind in rem und hängen an der Grundschriftgröße.
  Sie wächst mit dem Bildschirm (iPad ≈ 16 px, großes Display mehr) und
  wird mit --zoom multipliziert: automatisch größer auf großen
  Touch-Bildschirmen (Whiteboard), sonst über „Darstellung“ wählbar
  (html[data-groesse], gespeichert im Gerät, auch per ?groesse=… setzbar).
*/
html {
  --zoom: 1;
  font-size: calc(clamp(16px, 0.6vmin + 11px, 22px) * var(--zoom));
  -webkit-text-size-adjust: 100%;
}
@media (pointer: coarse) and (min-width: 1600px) {
  html { --zoom: 1.5; } /* Whiteboard / großes Touch-Display */
}
html[data-groesse="normal"] { --zoom: 1; }
html[data-groesse="gross"] { --zoom: 1.35; }
html[data-groesse="sehr-gross"] { --zoom: 1.75; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-grey);
  color: var(--ink);
  font-family: "Carlito", "Calibri", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue-link); }
img { display: block; }
[hidden] { display: none !important; }

/* ---------- Markenleiste / Fußzeile ---------- */

.brandbar {
  background: var(--blue);
  color: var(--white);
  padding: calc(0.625rem + var(--safe-top)) calc(1.25rem + var(--safe-right)) 0.625rem calc(1.25rem + var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brandbar .org { display: flex; align-items: center; gap: 0.625rem; color: inherit; text-decoration: none; min-height: var(--tap); }
.brandbar .mark {
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--yellow); color: var(--blue);
  font-weight: 700; font-size: 0.8125rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brandbar .marks { display: flex; }
@media (max-width: 30rem) { .brandbar .group-tag { display: none; } }
.brandbar .marks .mark + .mark { margin-left: -0.5rem; box-shadow: 0 0 0 2px var(--blue); }
.brandbar .org-name { font-size: 0.8125rem; line-height: 1.3; }
.brandbar .org-name strong { display: block; font-size: 0.875rem; }
.brand-right { display: flex; align-items: center; gap: 0.375rem; }
.brandbar .group-tag {
  background: var(--yellow); color: var(--blue-dark);
  font-weight: 700; font-size: 0.75rem; padding: 5px 0.75rem; border-radius: 1.25rem; white-space: nowrap;
}
.icon-btn {
  -webkit-appearance: none; appearance: none; border: none; background: none; cursor: pointer; padding: 0;
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--white);
}
.icon-btn svg { width: 1.375rem; height: 1.375rem; fill: currentColor; opacity: .85; }
.icon-btn:active { background: rgba(255,255,255,.15); }

.brandfooter {
  background: var(--blue);
  color: var(--white);
  border-top: 4px solid var(--yellow);
  padding: 1.25rem calc(1.25rem + var(--safe-right)) calc(1.25rem + var(--safe-bottom)) calc(1.25rem + var(--safe-left));
  font-size: 0.8125rem;
  line-height: 1.6;
}
.brandfooter .inner { max-width: 68.75rem; margin: 0 auto; }
.brandfooter .tagline { font-style: italic; opacity: .85; }
.brandfooter .tool-note { margin-top: 0.625rem; font-size: 0.75rem; opacity: .75; }

.offline-banner {
  background: var(--yellow);
  color: var(--blue-dark);
  font-weight: 700;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* ---------- Seite ---------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 68.75rem;
  margin: 0 auto;
  padding: 1.75rem calc(1.25rem + var(--safe-right)) 3rem calc(1.25rem + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.loading, .empty-note { color: var(--ink-soft); text-align: center; padding: 1.5rem 0; }
.hero { display: flex; flex-direction: column; gap: 0.375rem; }
.hero-row { display: flex; flex-direction: row; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.eyebrow {
  font-size: 0.8125rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--blue-link);
}
h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 2.3rem); color: var(--blue); line-height: 1.15; text-wrap: balance; }
h2 { margin: 0 0 0.75rem; font-size: 1.25rem; color: var(--blue); }
.lede { margin: 0; color: var(--ink-soft); max-width: 60ch; }
.hint { color: var(--ink-soft); font-size: .9rem; margin: 0.375rem 0 0; }
.hint.error, .error-text { color: var(--red); }
.back {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap);
  font-weight: 700; text-decoration: none; color: var(--blue-link);
}
.back::before { content: "‹"; font-size: 1.6em; line-height: 1; margin-top: -2px; }

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ---------- Schaltflächen (HIG: ≥ 44 pt, sichtbarer Druckzustand) ---------- */

.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.625rem;
  background: var(--blue);
  color: var(--white);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.secondary { background: var(--tint-blue); color: var(--blue); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid currentColor; }
.btn.small { min-height: 2.25rem; padding: 0.375rem 0.875rem; font-size: .95rem; }
.btn.yellow { background: var(--yellow); color: var(--blue-dark); }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.625rem; align-items: center; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- Formulare ---------- */

.field { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 1rem; }
.field label { font-weight: 700; color: var(--blue-dark); font-size: .95rem; }
input[type=text], input[type=search], input[type=password], textarea {
  font: inherit;
  font-size: 1.0625rem; /* ≥ 16 px: iOS zoomt sonst beim Fokussieren */
  min-height: var(--tap);
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: var(--white);
  color: var(--ink);
  width: 100%;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--blue-link); box-shadow: 0 0 0 3px var(--tint-blue); }
.search { max-width: 22.5rem; }

/* ---------- Auswahlliste ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.625rem), 1fr));
  gap: 1.25rem;
}
.story {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 2px rgba(0, 38, 92, .06);
  transition: transform .12s ease, box-shadow .12s ease;
}
.story:active { transform: scale(.97); }
@media (hover: hover) {
  .story:hover { box-shadow: 0 6px 18px rgba(0, 38, 92, .14); border-color: var(--blue-link); }
}
.story .cover {
  aspect-ratio: 4 / 3;
  background: var(--tint-blue) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem;
}
.story .cover img { width: 100%; height: 100%; object-fit: cover; }
.story .meta { padding: 0.875rem 1rem 1rem; display: flex; flex-direction: column; gap: 4px; }
.story .meta strong { font-size: 1.2rem; color: var(--blue); line-height: 1.2; }
.story .meta span { color: var(--ink-soft); font-size: .95rem; }
.story .meta .count { font-size: .85rem; font-weight: 700; color: var(--blue-link); }

/* ---------- Lesemodus ---------- */

body.lesen { overflow: hidden; background: #000; }
body.lesen .brandbar, body.lesen .brandfooter, body.lesen .offline-banner { display: none; }
body.lesen .page { padding: 0; max-width: none; }

.leser {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.spur {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.spur::-webkit-scrollbar { display: none; }
.spur:focus { outline: none; }
.seite {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.seite img {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
}
.seite.ende { flex-direction: column; gap: 1.75rem; text-align: center; }
.seite.ende h2 { color: var(--yellow); font-size: clamp(2.5rem, 8vw, 4.5rem); margin: 0; }
.seite.ende p { margin: 0; opacity: .8; font-size: 1.2rem; }
.seite.ende .btn { min-height: 3.5rem; font-size: 1.15rem; padding: 0.75rem 1.75rem; }

.leiste {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  pointer-events: none;
  transition: opacity .25s ease;
}
.leiste > * { pointer-events: auto; }
.leiste.oben {
  top: 0;
  padding-top: calc(0.75rem + var(--safe-top));
  padding-bottom: 1.75rem;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.leiste.unten {
  bottom: 0;
  justify-content: center;
  padding-bottom: calc(0.875rem + var(--safe-bottom));
  padding-top: 1.75rem;
  background: linear-gradient(transparent, rgba(0,0,0,.5));
}
.leiste .titel {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leser-btn {
  -webkit-appearance: none; appearance: none;
  min-width: var(--tap); min-height: var(--tap);
  padding: 0.5rem 0.875rem;
  border: none;
  border-radius: 1.375rem;
  background: rgba(0,0,0,.45);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
}
.leser-btn:active { background: rgba(0,0,0,.7); }
.leser-btn svg { width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.zaehler { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 4.5em; text-align: right; }

.pfeil {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 4rem; height: 4rem;
  border-radius: 50%;
  padding: 0;
}
.pfeil svg { width: 1.875rem; height: 1.875rem; }
.pfeil.zurueck { left: calc(0.875rem + var(--safe-left)); }
.pfeil.weiter { right: calc(0.875rem + var(--safe-right)); }
.pfeil:disabled { opacity: 0; pointer-events: none; }

.punkte { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; max-width: 80%; }
.punkte span { width: 0.5625rem; height: 0.5625rem; border-radius: 50%; background: rgba(255,255,255,.4); transition: background .2s, transform .2s; }
.punkte span.aktiv { background: var(--yellow); transform: scale(1.35); }

.leser.ruhig .leiste, .leser.ruhig .pfeil { opacity: 0; pointer-events: none; }
.leser.ruhig .leiste > * { pointer-events: none; }

/* ---------- Verwaltung ---------- */

.rows { display: flex; flex-direction: column; gap: 0.75rem; }
.row-item {
  display: flex; align-items: center; gap: 0.875rem;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.625rem 0.875rem; text-decoration: none; color: inherit; min-height: 4.5rem;
}
.row-item .thumb { width: 4.5rem; height: 3.375rem; border-radius: 0.375rem; object-fit: cover; background: var(--tint-blue); flex-shrink: 0; }
.row-item .text { flex: 1; min-width: 0; }
.row-item strong { display: block; color: var(--blue); }
.row-item span { color: var(--ink-soft); font-size: .9rem; }
.row-item .go { color: var(--blue-link); font-weight: 700; font-size: 1.4rem; }

.bilder {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.625rem), 1fr));
  gap: 0.875rem;
}
.bild {
  position: relative;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.bild img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #222; }
.bild .nr {
  position: absolute; top: 0.375rem; left: 0.375rem;
  background: var(--blue); color: #fff; font-weight: 700; font-size: .85rem;
  min-width: 1.625rem; height: 1.625rem; border-radius: 0.8125rem; padding: 0 0.4375rem;
  display: flex; align-items: center; justify-content: center;
}
.bild .aktionen { display: flex; justify-content: space-between; }
.bild .aktionen button {
  flex: 1; min-height: var(--tap);
  border: none; background: none; font-size: 1.2rem; color: var(--blue); cursor: pointer;
}
.bild .aktionen button:active { background: var(--tint-blue); }
.bild .aktionen button:disabled { opacity: .25; }
.bild .aktionen .loeschen { color: var(--red); }

.upload-liste { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; font-size: .95rem; }
.upload-liste .ok { color: #1e7b34; }
.upload-liste .fehler { color: var(--red); }

.adresse {
  display: flex; flex-wrap: wrap; gap: 0.625rem; align-items: center;
  background: var(--tint-blue); border-radius: 0.625rem; padding: 0.625rem 0.875rem;
}
.adresse .btn.secondary { background: var(--white); }
.adresse code { font-size: 1rem; word-break: break-all; flex: 1; min-width: 12.5rem; color: var(--blue-dark); }

/* ---------- Darstellung (Größe) ---------- */

.segmente { display: flex; flex-direction: column; gap: 0.5rem; }
.segmente label {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: var(--tap); padding: 0.5rem 0.875rem;
  border: 1px solid var(--line); border-radius: 0.625rem; cursor: pointer;
}
.segmente input { width: 1.25rem; height: 1.25rem; accent-color: var(--blue); }
.segmente label:has(input:checked) { border-color: var(--blue); background: var(--tint-blue); font-weight: 700; }

/* ---------- Dialoge (Anmeldung, Neu, QR) ---------- */

dialog {
  border: none;
  border-radius: 1rem;
  padding: 0;
  width: min(26.25rem, calc(100vw - 2rem));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 38, 92, .45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dlg-head { padding: 1.25rem 1.375rem 4px; font-size: 1.25rem; font-weight: 700; color: var(--blue); }
.dlg-body { padding: 0.75rem 1.375rem; }
.dlg-foot { padding: 0.5rem 1.375rem 1.25rem; display: flex; gap: 0.625rem; justify-content: flex-end; flex-wrap: wrap; }
.pin-input { text-align: center; font-size: 1.6rem !important; letter-spacing: .25em; }
.qr { display: flex; justify-content: center; padding: 0.5rem; background: #fff; }
.qr svg { width: 100%; max-width: 17.5rem; height: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  background: var(--blue-dark);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  font-weight: 700;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.error { background: var(--red); }

.spinner {
  width: 1.125rem; height: 1.125rem; border-radius: 50%;
  border: 3px solid currentColor; border-right-color: transparent;
  display: inline-block; animation: drehen .8s linear infinite;
}
@keyframes drehen { to { transform: rotate(360deg); } }

/* HIG: „Bewegung reduzieren“ respektieren */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .001ms !important; scroll-behavior: auto !important; }
}

@media print {
  .brandbar, .brandfooter, .btn, .back { display: none !important; }
}
