@font-face {
  font-family: "Andika";
  src: url("/fonts/Andika-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Andika";
  src: url("/fonts/Andika-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #fdf3e4;
  --paper-2: #f7e6cc;
  --card: #fffaf2;
  --ink: #2d2442;
  --ink-soft: #6d6380;
  --line: #ead7b9;
  --blue: #3d8bfd;
  --blue-d: #2563c9;
  --green: #2fb36b;
  --green-d: #1f8a50;
  --orange: #ff9a3c;
  --orange-d: #d9741a;
  --purple: #8b5cf6;
  --purple-d: #6a3fd6;
  --new: #e8336b;
  --gold: #ffc23d;
  --radius: 28px;
  --font: "Andika", "Nunito", "Segoe UI", system-ui, sans-serif;
  --emoji: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 12% 18%, #fff7ea 0 18%, transparent 19%),
    radial-gradient(circle at 88% 85%, #fbe7c9 0 14%, transparent 15%),
    var(--paper);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; }

/* ---------- Bildschirme ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen.active { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 4px 24px;
}

/* ---------- Kopfzeile ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  margin-bottom: 8px;
}
.bar h2 {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: clamp(1.3rem, 3.6vmin, 2rem);
}
.bar-spacer { width: 64px; flex: none; }

.icon-btn {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 4px 0 var(--line);
  font-family: var(--emoji);
  font-size: 30px;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }

/* ---------- Startmenü ---------- */
#home { align-items: center; justify-content: center; gap: 4vmin; }

.home-title { display: flex; align-items: center; gap: 2.5vmin; }
.home-title h1 {
  margin: 0;
  font-size: clamp(2.6rem, 11vmin, 6rem);
  letter-spacing: .02em;
}
.logo {
  display: flex; align-items: baseline; justify-content: center;
  width: clamp(70px, 15vmin, 120px);
  aspect-ratio: 1;
  border-radius: 30%;
  background: var(--orange);
  box-shadow: 0 6px 0 var(--orange-d);
  color: #fff;
  font-weight: 700;
  font-size: clamp(2rem, 8vmin, 4rem);
  padding-top: 8%;
  transform: rotate(-6deg);
}
.logo span + span { color: #fff3c4; }

.home-buttons {
  display: flex;
  gap: 4vmin;
  width: min(100%, 980px);
  justify-content: center;
}
.big-btn {
  flex: 1;
  max-width: 440px;
  min-height: clamp(150px, 42vmin, 320px);
  border-radius: 40px;
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2vmin;
  transition: transform .08s;
}
.big-btn.practice { background: var(--blue); box-shadow: 0 10px 0 var(--blue-d); }
.big-btn.newletter { background: var(--purple); box-shadow: 0 10px 0 var(--purple-d); }
.big-btn:active { transform: translateY(8px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.big-btn:disabled { filter: grayscale(.8) opacity(.5); transform: none; }
.big-icon { font-family: var(--emoji); font-size: clamp(3rem, 15vmin, 7.5rem); line-height: 1; }
.big-label { font-weight: 700; font-size: clamp(1.5rem, 5.5vmin, 2.8rem); }

.home-info { margin: 0; color: var(--ink-soft); font-size: clamp(.95rem, 2.4vmin, 1.2rem); text-align: center; }

.gear {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  width: 64px; height: 64px;
  display: grid; place-items: center;
  font-family: var(--emoji);
  font-size: 30px;
  opacity: .55;
}
.gear > * { grid-area: 1 / 1; }
.gear-ring { width: 64px; height: 64px; transform: rotate(-90deg); }
.gear-ring circle {
  fill: none; stroke: var(--purple); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 132; stroke-dashoffset: 132;
}
.gear.holding { opacity: 1; }
.gear.holding .gear-ring circle { transition: stroke-dashoffset .9s linear; stroke-dashoffset: 0; }

/* ---------- Kacheln (Buchstaben) ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(76px, 11vmin, 104px), 1fr));
  gap: 12px;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 5px 0 var(--line);
  font-size: clamp(1.6rem, 5vmin, 2.4rem);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  gap: .12em;
}
.tile small { font-weight: 400; font-size: .85em; }
.tile:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.tile:disabled { opacity: .35; transform: none; box-shadow: 0 5px 0 var(--line); }
.tile .count {
  position: absolute;
  right: 6px; bottom: 4px;
  font-size: .9rem;
  font-weight: 400;
  color: var(--ink-soft);
}
.toggles .tile[aria-pressed="true"] {
  background: var(--green);
  color: #fff;
  box-shadow: 0 5px 0 var(--green-d);
}
#pick .tile { color: var(--new); }
.tiles.groups { grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 16vmin, 150px), 1fr)); }
.tiles.groups .tile { aspect-ratio: auto; height: clamp(76px, 11vmin, 104px); font-size: clamp(1.4rem, 4.2vmin, 2rem); }

.sub { margin: 22px 0 12px; font-size: 1.15rem; }
.sub small { font-weight: 400; color: var(--ink-soft); font-size: .85rem; }
.hint { color: var(--ink-soft); text-align: center; font-size: 1.05rem; margin: 18px 0 0; }

/* ---------- Übung ---------- */
.progress {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--paper-2);
  box-shadow: inset 0 2px 0 rgba(0,0,0,.06);
  transition: background .2s, transform .2s;
}
.dot.now { background: var(--orange); transform: scale(1.25); }
.dot.ok { background: var(--gold); }
.progress.many .dot { width: 14px; height: 14px; }

.new-badge {
  width: 64px; height: 64px;
  flex: none;
  border-radius: 20px;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 1.9rem;
  color: #fff;
  background: var(--new);
  box-shadow: 0 4px 0 #b11f4c;
  visibility: hidden;
}
.new-badge.show { visibility: visible; }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3vmin;
}
.word-box {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  max-height: 68vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border-radius: 40px;
  box-shadow: 0 8px 0 var(--line);
  padding: 2vmin 4vmin;
  transition: flex-basis .35s ease;
}
.word {
  font-weight: 400;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  letter-spacing: .04em;
}
.word.sentence { white-space: normal; letter-spacing: .02em; word-spacing: .15em; }
.word .hl { color: var(--new); font-weight: 700; }

.picture {
  flex: 0 0 0;
  width: 0;
  height: 100%;
  max-height: 68vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 40px;
  transition: flex-basis .35s ease;
}
.stage.revealed .picture {
  flex-basis: 38%;
  width: auto;
  background: #fff;
  box-shadow: 0 8px 0 var(--line);
}
.picture .emoji {
  font-family: var(--emoji);
  line-height: 1;
  font-size: min(30vh, 18vw);
  white-space: nowrap;
  animation: pop .45s cubic-bezier(.2, 1.6, .5, 1) both;
}
.picture .emoji.multi { font-size: min(20vh, 10vw); }
.picture .parent { width: 82%; max-height: 90%; animation: pop .45s cubic-bezier(.2, 1.6, .5, 1) both; }
@keyframes pop { from { transform: scale(.2) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }

.controls {
  display: flex;
  justify-content: center;
  gap: 3vmin;
  padding-top: 2.5vmin;
}
.ctrl {
  height: clamp(72px, 15vh, 120px);
  min-width: clamp(110px, 20vw, 220px);
  border-radius: 32px;
  font-weight: 700;
  font-size: clamp(1.8rem, 6vh, 3rem);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s, opacity .2s;
}
.ctrl:active:not(:disabled) { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.25) !important; }
.ctrl.case { background: var(--blue); box-shadow: 0 8px 0 var(--blue-d); letter-spacing: .03em; }
.ctrl.reveal { background: var(--orange); box-shadow: 0 8px 0 var(--orange-d); font-family: var(--emoji); font-size: clamp(2.2rem, 7vh, 3.6rem); }
.ctrl.next { background: var(--green); box-shadow: 0 8px 0 var(--green-d); font-size: clamp(2.4rem, 8vh, 4rem); }
.ctrl.reveal:disabled { opacity: .35; }
.ctrl.next:disabled { opacity: .18; filter: grayscale(1); box-shadow: none; }
.ctrl.next:not(:disabled) { animation: nudge 1.6s ease-in-out .6s infinite; }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateX(6px); } }

/* ---------- Rundenende ---------- */
#done { align-items: center; justify-content: center; }
.done-box { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2vmin; }
.done-star { font-family: var(--emoji); font-size: clamp(4rem, 20vmin, 9rem); line-height: 1; animation: pop .6s cubic-bezier(.2, 1.6, .5, 1) both, spin 6s linear .6s infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.done-box h2 { margin: 0; font-size: clamp(2rem, 8vmin, 4rem); }
.done-stars { font-family: var(--emoji); font-size: clamp(1.6rem, 6vmin, 3rem); max-width: 90vw; }
.done-stars span { display: inline-block; animation: pop .4s both; }
.done-buttons { display: flex; gap: 3vmin; margin-top: 1vmin; }
.mid-btn {
  min-width: clamp(160px, 26vw, 260px);
  height: clamp(70px, 14vh, 100px);
  border-radius: 28px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(1.3rem, 4vmin, 2rem);
}
.mid-btn.again { background: var(--green); box-shadow: 0 8px 0 var(--green-d); }
.mid-btn.menu { background: var(--blue); box-shadow: 0 8px 0 var(--blue-d); }
.mid-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.learned {
  margin-top: 1vmin;
  padding: 10px 18px;
  border-radius: 16px;
  color: var(--ink-soft);
  font-size: 1rem;
  border: 2px dashed var(--line);
}
.learned[hidden] { display: none; }
.learned.saved { border-style: solid; color: var(--green-d); }

/* ---------- Einstellungen ---------- */
.settings { max-width: 1000px; width: 100%; margin: 0 auto; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--line);
  padding: 20px 22px 24px;
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 1.25rem; }
.card .tile { background: var(--paper); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.mini-btns { display: flex; gap: 8px; }
.mini {
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--paper-2);
  font-size: 1rem;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 2px solid var(--paper-2);
}
.row:first-of-type { border-top: 0; }
.row-label { font-size: 1.1rem; }
.row-label small { color: var(--ink-soft); font-size: .85rem; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; background: var(--paper-2); padding: 5px; border-radius: 18px; }
.seg button {
  min-width: 56px;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  font-size: 1.1rem;
}
.seg button[aria-pressed="true"] { background: var(--purple); color: #fff; font-weight: 700; }
.switch {
  width: 76px; height: 44px; flex: none;
  border-radius: 22px;
  background: #cfc3b0;
  position: relative;
  transition: background .2s;
}
.switch span {
  position: absolute; top: 4px; left: 4px;
  width: 36px; height: 36px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
  transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"] span { transform: translateX(32px); }

/* ---------- Hochformat / kleine Geräte ---------- */
@media (orientation: portrait) {
  .home-buttons { flex-direction: column; align-items: center; }
  .big-btn { width: min(100%, 440px); min-height: 26vh; flex: none; }
  .stage { flex-direction: column; }
  .word-box { width: 100%; flex: 1 1 auto; max-height: none; }
  .picture { width: 100%; height: 0; flex: 0 0 0; }
  .stage.revealed .picture { flex-basis: 34%; width: 100%; height: auto; }
  .picture .emoji { font-size: min(22vh, 40vw); }
  .picture .emoji.multi { font-size: min(14vh, 22vw); }
  .ctrl { min-width: 0; flex: 1; height: clamp(72px, 11vh, 110px); }
  .row { flex-direction: column; align-items: flex-start; }
}

@media (max-height: 500px) {
  .bar { min-height: 52px; }
  .icon-btn, .new-badge { width: 52px; height: 52px; font-size: 24px; }
  .bar-spacer { width: 52px; }
}
