:root {
  color-scheme: light dark;
  --bg: light-dark(#FFF8F3, #14163A);
  --ink: light-dark(#20235A, #FFF8F3);
  --mut: light-dark(#5B5F86, #C9CBF2);
  --card: light-dark(#FFFFFF, #20235A);
  --line: light-dark(#F3E3DA, #3A3E7A);
  --coral: #E8553A;
  --btn: #C93F26;
  --tint: light-dark(#FDE7E1, #3A2440);
  --tintInk: light-dark(#A8331C, #FFC2B3);
  --orange: #FF9A2E;
  --hl: light-dark(#FFD8A8, #7A4A12);
  --ok: light-dark(#E6F4EA, #1E3A2A);
  --okInk: light-dark(#1F6B3A, #9BE0B1);
  --hint: light-dark(#FFF6E5, #3A3020);
  --hintInk: light-dark(#5A3D00, #FFE2A8);
}

:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }

*, *::before, *::after {
  box-sizing: border-box;
  min-width: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, system-ui, sans-serif;
  overflow-x: clip;
}

#app {
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 20px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1, h2, .serif {
  font-family: Nunito, system-ui, sans-serif;
  font-weight: 800;
  margin: 0;
  line-height: 1.15;
  text-wrap: balance;
}

h1 { font-size: 34px; }
h2 { font-size: 26px; }

.mut { color: var(--mut); font-size: 15px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 45px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.brand, .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  font-family: Nunito, sans-serif;
  font-weight: 900;
  font-size: 24px;
}

.brand img { border-radius: 9px; }
.header-actions { flex-wrap: wrap; justify-content: flex-end; }
.header-actions .ghost { padding-inline: 10px; }
.app-header a.ghost { color: var(--ink); text-decoration: none; }

/* Fortschrittsbalken */
.prog {
  flex: 1;
  height: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.prog i {
  display: block;
  height: 100%;
  background: var(--coral);
  border-radius: 99px;
  transition: width 0.3s;
}
@media (prefers-reduced-motion: reduce) {
  .prog i { transition: none; }
}

/* Karte */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
}

/* Gisti-Blase */
.gisti {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.gisti .say {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  font-size: 15px;
}
.gisti .say b { font-weight: 600; }

/* Sprechblasen (Gegenseite und eigene) */
.bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px 20px 20px 6px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bubble .es {
  font-family: Nunito, sans-serif;
  font-weight: 800;
  font-size: 23px;
}
.me {
  align-self: flex-end;
  background: var(--tint);
  color: var(--tintInk);
  border-radius: 20px 20px 6px 20px;
  padding: 12px 16px;
  font-weight: 600;
  max-width: 85%;
}

/* Optionsknopf */
button { font: inherit; color: inherit; cursor: pointer; }

.opt {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 8px 14px;
  font-weight: 600;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.opt .k {
  font-size: 12px;
  color: var(--mut);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  flex: none;
}
.opt.big {
  justify-content: center;
  font-family: Nunito, sans-serif;
  font-size: 22px;
  font-weight: 800;
}
.opt.right {
  border: 3px solid var(--okInk);
  background: var(--ok);
  color: var(--okInk);
}
.opt.wrong {
  border: 2px dashed var(--coral);
  opacity: 0.75;
}

/* Raster für Optionen */
.opts { display: grid; gap: 10px; }
.opts.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opts.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* Haupt-Aktionsknopf */
.cta {
  min-height: 56px;
  border: 0;
  border-radius: 16px;
  background: var(--btn);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  width: 100%;
}
.cta[disabled] { opacity: 0.45; cursor: default; }

/* Nebenknopf */
.ghost {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 14px;
  font-weight: 500;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Fokus-Rahmen */
.opt:focus-visible,
.cta:focus-visible,
.ghost:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

/* Stempel */
.stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--ink);
  color: var(--ink);
  border-radius: 99px;
  font-weight: 700;
  letter-spacing: 0.5px;
  transform: rotate(-10deg);
}
.pop { animation: pop 0.45s ease-out; }
@keyframes pop {
  0% { transform: scale(1.8) rotate(-25deg); opacity: 0; }
  100% { transform: scale(1) rotate(-10deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .pop { animation: none; }
}

/* Hinweis-Kärtchen */
.hint {
  background: var(--hint);
  color: var(--hintInk);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.audio-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--mut);
  align-self: flex-start;
}
.word-hint { text-align: center; margin: 0; }
.tag {
  flex: none;
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  background: var(--hintInk);
  color: var(--hint);
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

/* Markierung (Schlüsselwort) */
.hl { background: var(--hl); border-radius: 6px; padding: 0 4px; font-weight: 600; }

/* Satz-Lego */
.frame {
  font-family: Nunito, sans-serif;
  font-weight: 800;
  font-size: 23px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.slot {
  border: 2px dashed var(--coral);
  color: var(--tintInk);
  border-radius: 12px;
  padding: 2px 12px;
  min-width: 90px;
  text-align: center;
}
.slot.full { border-style: solid; background: var(--tint); }

/* Audio-Radar */
.wave { display: flex; align-items: center; gap: 3px; height: 40px; flex: 1; }
.wave i { display: block; width: 4px; border-radius: 2px; background: var(--line); }
.wave i.c { background: var(--coral); }
.play {
  width: 56px;
  height: 56px;
  border-radius: 99px;
  border: 0;
  background: var(--btn);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  cursor: pointer;
}
.play:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* Hilfslayout */
.top { display: flex; align-items: center; gap: 12px; }

/* Stadtkarte */
.scene-list { display: flex; flex-direction: column; gap: 10px; }

.scene-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--card);
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}

.scene-card.next {
  background: var(--tint);
  border-color: var(--coral);
}
button.scene-card { cursor: pointer; }
button.scene-card:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

.scene-card.later { opacity: 0.5; cursor: default; }

.scene-card.done {
  background: var(--ok);
  border-color: var(--okInk);
  opacity: 0.85;
  cursor: default;
}

.scene-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scene-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--tintInk);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.scene-title {
  font-family: Nunito, sans-serif;
  font-weight: 800;
  font-size: 19px;
}

.scene-status { font-size: 13px; color: var(--mut); white-space: nowrap; }

/* Schritt-Liste */
.steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li { display: flex; gap: 10px; align-items: center; font-size: 15px; }

.steps li span {
  width: 26px;
  height: 26px;
  border-radius: 99px;
  background: var(--tint);
  color: var(--tintInk);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex: none;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chat { display: flex; flex-direction: column; gap: 6px; }
.chat .bubble, .chat .me { padding: 6px 12px; font-size: 15px; }
.talk-history .chat { margin-top: 10px; }
.grow { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.end {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0 max(12px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 8px -4px var(--bg);
}
.nb { white-space: nowrap; display: inline-flex; align-items: center; }
.keys { font-size: 13px; color: var(--mut); }

/* Lektion 1 und Hilfe-Knopf */
.intro-card p { margin: 0 0 10px; line-height: 1.5; }
.intro-card p:last-child { margin-bottom: 0; }
.intro-list { margin: 0; padding-left: 20px; line-height: 1.5; display: flex; flex-direction: column; gap: 8px; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 16px 0; }
.dots i { width: 8px; height: 8px; border-radius: 99px; background: var(--line, #E8DDD3); }
.dots i.on { background: var(--coral, #E8553A); width: 22px; }

/* Szenenabschluss */
.next-rep { text-align: center; color: var(--mut); margin: 4px 0 12px; }
.takeaway { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-weight: 600; line-height: 1.4; }

.legal-menu { position: relative; }
.legal-menu summary { cursor: pointer; }
.legal-menu-links {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  display: grid;
  gap: 8px;
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 40px);
  background: #fff;
  box-shadow: 0 6px 24px rgba(32, 35, 90, 0.18);
}
.legal-menu-links .ghost {
  width: 100%;
  min-height: 44px;
  justify-content: flex-start;
  white-space: nowrap;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 8px 14px;
}
/* Tippen neben das Menü schliesst es (unsichtbare Fläche über der Summary) */
.legal-menu[open] > summary::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
}
.word-card {
  display: grid;
  justify-items: start;
  gap: 10px;
}
.word-tools {
  display: flex;
  align-items: stretch;
  gap: 4px;
  width: 100%;
}
.word-tools .ghost {
  gap: 4px;
  padding: 4px 6px;
  font-size: 13px;
  text-align: left;
  line-height: 1.25;
}
.word-tools svg { flex: none; border-radius: 2px; }
.word-tools .ghost[aria-expanded="true"] {
  background: var(--tint);
  color: var(--tintInk);
}

.translation-help summary { cursor: pointer; }
.translation-help p { margin: 4px 0 0; }

.studio-stack { display: grid; gap: 12px; }
.studio label { display: grid; gap: 4px; font-weight: 600; }
.studio select {
  max-width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
.studio .studio-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.studio input { accent-color: var(--btn); }
.studio-line { display: flex; align-items: start; gap: 10px; }
.studio-line img {
  width: min(26%, 96px);
  max-height: 100px;
  object-fit: contain;
  border-radius: 12px;
}
.studio-selection > .card { margin-top: 8px; }
.studio-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.studio .ghost:disabled { opacity: .55; cursor: default; }
.studio meter, .studio audio { width: 100%; }
.studio [hidden] { display: none; }
.studio-karaoke { position: relative; }
#studio-words { font-size: 24px; line-height: 1.4; }
#studio-words span {
  display: inline-block;
  margin-top: 9px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--hl) var(--fill, 0%), transparent var(--fill, 0%));
}
#studio-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
  transform: translate(-50%, -100%);
  pointer-events: none;
}

#app:has(.area-tabs, .story-step) {
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

:root:has(.area-tabs, .story-step) {
  scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.area-tabs, .story-step {
  position: fixed;
  z-index: 2;
  inset: auto 0 0;
  width: min(100%, 430px);
  margin-inline: auto;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  gap: 8px;
}
.area-tabs { grid-template-columns: 1fr 1fr; }
.area-tabs button { justify-content: center; }
.area-tabs [aria-current="page"] {
  color: var(--tintInk);
  background: var(--tint);
  font-weight: 600;
}
.story-reading, .story-controls {
  display: grid;
  gap: 12px;
}
.story-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}
.story-heading .ghost { flex: none; }
.story-heading h1 { font-size: 26px; }
/* Fester Platz für alle Einzelbilder, damit der Satz beim Wechsel ruhig bleibt. */
.story-picture {
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  display: grid;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 38dvh;
}
.story-picture img {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px;
}
.story-picture-frame { visibility: hidden; }
/* Drei Einzelbilder, jeweils eine Viertelsekunde sichtbar. */
@keyframes story-picture-frame {
  from { visibility: visible; }
  33.3333%, to { visibility: hidden; }
}
@media (prefers-reduced-motion: no-preference) {
  .story-picture-moving .story-picture-frame {
    animation: story-picture-frame 750ms steps(1, end) 250ms infinite;
  }
  .story-picture-moving .story-picture-frame:last-child { animation-delay: 500ms; }
}
@media (prefers-reduced-motion: reduce) {
  .story-controls .story-motion-toggle { display: none; }
}
.story-text {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  font-size: clamp(20px, 6vw, 24px);
  line-height: 1.55;
}
.story-word {
  border-radius: 4px;
  box-decoration-break: clone;
  background: linear-gradient(to right, var(--hl) var(--fill, 0%), transparent var(--fill, 0%));
}
.story-glossary-word {
  min-width: 44px;
  min-height: 44px;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--tintInk);
  text-decoration: underline dotted;
  text-underline-offset: 4px;
}
.story-definition:not(:empty) {
  display: grid;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--tint);
  color: var(--tintInk);
}
.story-progress {
  width: 100%;
  height: 12px;
  accent-color: var(--btn);
}
.story-sentence { flex: 1; min-width: 0; }
.story-step { grid-template-columns: auto 1fr auto; }
.story-step .story-arrow { width: 52px; padding: 0; }
.story-step .story-play { gap: 8px; font-size: 17px; min-height: 52px; white-space: nowrap; }
.story-step button {
  justify-content: center;
  min-height: 44px;
  padding: 4px 8px;
  font-size: 14px;
}
.story-step .cta { border-radius: 12px; }
.story-step .ghost:disabled { opacity: .55; cursor: default; }
@media (max-height: 450px) {
  #app:has(.story-step) { padding-top: 8px; gap: 8px; }
  .story-reading { padding: 10px 14px; gap: 6px; }
  .story-text { font-size: 20px; line-height: 1.35; }
}
@media (orientation: landscape), (min-width: 900px) {
  .story-text { flex-direction: row; align-items: flex-start; }
  .story-picture { width: 48%; }
}
.story-controls { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.story-languages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.story-languages button { justify-content: center; min-height: 44px; padding: 4px 6px; font-size: 14px; }
.story-languages [aria-pressed="true"] { background: var(--tint); color: var(--tintInk); border-color: var(--coral); font-weight: 700; }
.story-settings summary { list-style: none; cursor: pointer; display: flex; justify-content: center; width: 100%; }
.story-step .story-play:not([hidden]) { display: flex; align-items: center; justify-content: center; }
.story-step .story-arrow:last-child { grid-column: 3; }
.story-settings summary::-webkit-details-marker { display: none; }
.story-field { display: grid; gap: 4px; }
.story-controls label { font-weight: 600; }
.story-controls select {
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
.story-controls .story-picture-toggle {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  min-width: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.story-controls .story-picture-toggle input { width: 22px; height: 22px; margin: 0; }
.story-controls input { accent-color: var(--btn); }

/* Übungen: Schrittbalken der Szene (V17) */
.scene-steps { list-style: none; margin: -6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.scene-steps li { font-size: 12px; font-weight: 600; color: var(--mut); }
.scene-steps li > *, .scene-steps button { display: grid; gap: 4px; width: 100%; min-height: 44px; align-content: center; text-align: left; font: inherit; color: inherit; background: none; border: 0; padding: 0; }
.scene-steps button { cursor: pointer; }
.scene-steps i { display: block; height: 6px; border-radius: 99px; background: var(--line); }
.scene-steps li.done i { background: var(--ink); }
.scene-steps li.on i { background: linear-gradient(90deg, var(--coral, #E8553A) var(--p, 100%), var(--line) var(--p, 100%)); }
.scene-steps li.on { color: var(--ink); }
.scene-steps li.locked i { background: repeating-linear-gradient(90deg, var(--line) 0 4px, transparent 4px 7px); }
.scene-steps li.locked { cursor: not-allowed; }
.top-progress { color: var(--ink); font-size: 15px; font-weight: 700; }

/* Übungen: «Wiiter» immer an derselben Stelle (V17) */
#app:has(> .end) { padding-bottom: 0; }

/* Rückfrage vor dem Verlassen einer Szene (V17) */
.confirm-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(32, 35, 90, .45); display: flex; align-items: flex-end; justify-content: center; padding: 20px; }
.confirm { width: min(100%, 390px); display: grid; gap: 14px; margin-bottom: env(safe-area-inset-bottom); }
.confirm-actions { display: grid; gap: 10px; }

/* Übersicht: geschaffte Szenen (V20) */
.scene-card.done { background: var(--card); border-color: var(--okInk); opacity: 1; cursor: pointer; }
.scene-check { flex: none; color: var(--okInk); }
.scene-state { font-size: 13px; font-weight: 700; color: var(--okInk); }
.scene-state.start { margin: -8px 0 0; font-size: 15px; }

/* Lektion 1: Punkte und Hauptknopf unten wie «Szene starte» (V22) */
.intro { flex: 1; display: flex; flex-direction: column; gap: 16px; }
#app:has(> .intro > .end) { padding-bottom: 0; }

.scene-steps-line { font-size: 13px; color: var(--mut); }
.story-step .story-finish { grid-column: 1 / -1; min-height: 48px; }
.story-def-label { font-weight: 700; opacity: .8; }
.story-controls-hint { margin: 0; }
.story-controls select:disabled { opacity: .55; }
.legal-menu summary { white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; }

.audio-note.mini { font-size: 0; gap: 0; }
.audio-note.mini span { display: none; }
.audio-note.mini svg { display: block; }
.opt.right.reveal { outline: 3px solid var(--okInk); outline-offset: 1px; }

/* Textentwürfe im Aufnahmestudio */
.label-editor > p, .label-card > p {
  margin: 0;
}
.label-editor > label {
  font-weight: 600;
}
.label-editor input, .label-card textarea {
  border: 1px solid var(--mut);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  min-height: 44px;
  padding: 8px 12px;
}
.label-editor #label-results {
  display: grid;
  gap: 12px;
}
.label-card:not([hidden]) {
  display: grid;
  gap: 8px;
}
.label-card label {
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.label-card textarea {
  width: 100%;
  resize: vertical;
}
.label-card [role=status]:empty {
  display: none;
}
.label-card .ghost {
  justify-self: start;
}
.label-card textarea[aria-invalid=true] {
  border-color: var(--tintInk);
}
