:root {
  color-scheme: light;
  --bg: #fff6e5;
  --bg-dots: #ffe9c4;
  --ink: #2b1d14;
  --muted: #7a6656;
  --card: #ffffff;
  --line: #2b1d14;
  --orange: #ff8a3d;
  --yellow: #ffd23f;
  --teal: #2ec4b6;
  --purple: #7b5cff;
  --pink: #ff5d8f;
  --green: #3dbe6b;
  --red: #ff5a5f;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --shadow: 0 4px 0 var(--line);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 2px, transparent 2px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
h1, h2, h3 { margin: 0; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-block: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-bottom, 0px) + 24px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
}

/* ---------- Sticky header (top bar + Herbert) ----------
   Spans the side gutters so scrolled content never peeks out beside it. */
.head {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  margin-left: calc(-1 * max(16px, env(safe-area-inset-left, 0px)));
  margin-right: calc(-1 * max(16px, env(safe-area-inset-right, 0px)));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
  border-bottom: 3px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--bg);
}
body.scrolled .head { border-bottom-color: var(--line); box-shadow: 0 4px 0 rgba(43, 29, 20, .08); }
body.scrolled .herbert { min-height: 0; margin: 0 0 8px; align-items: center; }
body.scrolled .herbert-dog, body.scrolled[data-screen="home"] .herbert-dog { width: 66px; }
body.scrolled .bubble { font-size: 13px; line-height: 1.25; padding: 5px 10px; margin: 0; box-shadow: 0 3px 0 var(--line); }
body.scrolled .bubble span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
body.scrolled .bubble::before, body.scrolled .bubble::after { bottom: 50%; transform: translateY(50%); }
#screen { padding-top: 2px; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.topbar h1 { font-family: var(--pixel); font-size: 13px; line-height: 1.5; flex: 1; letter-spacing: .5px; }
.topbar .back {
  width: 48px; height: 48px; flex: none;
  border: 3px solid var(--line); border-radius: 14px; background: var(--card);
  font-size: 22px; font-weight: 900; box-shadow: 0 3px 0 var(--line);
}
.topbar .back:active { transform: translateY(3px); box-shadow: none; }
.streak {
  font-weight: 900; background: var(--yellow); border: 3px solid var(--line);
  border-radius: 999px; padding: 4px 12px; box-shadow: 0 3px 0 var(--line);
}

/* ---------- Herbert ---------- */
.herbert {
  display: flex; align-items: flex-end; gap: 10px;
  margin: 6px 0 12px; min-height: 92px;
  transition: min-height .25s ease;
}
.herbert-dog {
  flex: none; border: 0; background: none; padding: 0;
  width: 116px; transition: width .25s ease;
}
.herbert-svg { width: 100%; display: block; overflow: visible; }
.h-tail, .h-body, .h-head, .h-ear, .h-legs-front, .h-legs-back { transform-box: view-box; }
.h-tail { transform-origin: 44px 66px; animation: wag .5s ease-in-out infinite alternate; }
.h-body { transform-origin: 100px 100px; }
.h-head { transform-origin: 140px 80px; }
.h-ear { transform-origin: 138px 24px; }

[data-mood="idle"] .h-body { animation: breathe 2.4s ease-in-out infinite; }
[data-mood="idle"] .h-head { animation: tilt 6s ease-in-out infinite; }
[data-mood="idle"] .eye { animation: blink 4.5s infinite; transform-box: fill-box; transform-origin: center; }
[data-mood="happy"] .herbert-svg { animation: hop .45s ease-in-out 3; }
[data-mood="happy"] .h-tail { animation-duration: .12s; }
[data-mood="happy"] .h-tongue { display: block; }
[data-mood="happy"] .h-ear { animation: flap .22s ease-in-out infinite alternate; }
[data-mood="happy"] .h-legs-front { animation: trot .15s steps(1) infinite alternate; }
[data-mood="happy"] .h-legs-back { animation: trot .15s steps(1) infinite alternate-reverse; }
[data-mood="sad"] .h-tail { animation: none; transform: rotate(-95deg); }
[data-mood="sad"] .h-tear { display: block; animation: drip 1s ease-in infinite; }
[data-mood="sad"] .h-head { transform: rotate(8deg) translateY(4px); transition: transform .3s; }
[data-mood="sad"] .h-ear { transform: rotate(10deg); }
[data-mood="sad"] .herbert-svg { animation: shake .4s ease-in-out 1; }
[data-mood="sleepy"] .eye { display: none; }
[data-mood="sleepy"] .h-closed { display: block; }
[data-mood="sleepy"] .h-tail { animation: none; transform: rotate(-60deg); }
[data-mood="sleepy"] .h-head { transform: rotate(12deg) translateY(6px); transition: transform .6s; }
[data-mood="sleepy"] .h-body { animation: breathe 3.5s ease-in-out infinite; }

/* ---------- Herbert tricks (tap) and fidgets (idle) ---------- */
.herbert { position: relative; }
.herbert-dog { position: relative; z-index: 2; transform-origin: 50% 100%; }
[data-mood="trick"] .h-tail { animation-duration: .12s; }
[data-mood="trick"] .h-tongue { display: block; }
[data-trick="spin"] .herbert-dog { transform-origin: 50% 50%; animation: t-spin .9s ease-in-out; }
[data-trick="backflip"] .herbert-dog { transform-origin: 50% 50%; animation: t-backflip 1s cubic-bezier(.3, .1, .3, 1); }
[data-trick="stretch"] .herbert-dog { transform-origin: 0 100%; animation: t-stretch 1.5s ease-in-out; }
[data-trick="zoomies"] .herbert-dog { animation: t-zoomies 1.7s ease-in-out; }
[data-trick="zoomies"] .h-legs-front { animation: trot .09s steps(1) infinite alternate; }
[data-trick="zoomies"] .h-legs-back { animation: trot .09s steps(1) infinite alternate-reverse; }
[data-trick="zoomies"] .h-ear { animation: flap .1s infinite alternate; }
[data-trick="hearts"] .herbert-dog { animation: t-nuzzle 1.5s ease-in-out; }
[data-trick="hearts"] .eye { display: none; }
[data-trick="hearts"] .h-closed { display: block; }
[data-trick="bark"] .herbert-dog { animation: t-bark .9s ease-in-out; }
[data-trick="bark"] .h-head { animation: t-barkhead .3s ease-in-out 3; }
[data-trick="sneeze"] .herbert-dog { animation: t-sneeze 1s ease-in-out; }
[data-trick="shakeoff"] .herbert-dog { animation: t-shakeoff 1.1s linear; }
[data-trick="shakeoff"] .h-ear { animation: flap .08s infinite alternate; }
[data-trick="beg"] .herbert-dog { transform-origin: 20% 100%; animation: t-beg 1.6s ease-in-out; }
[data-trick="beg"] .h-legs-front { animation: trot .2s ease-in-out infinite alternate; }
[data-trick="chase"] .herbert-dog { transform-origin: 50% 70%; animation: t-chase 1.5s linear; }
[data-trick="dig"] .herbert-dog { transform-origin: 70% 100%; animation: t-dig 1.4s ease-in-out; }
[data-trick="dig"] .h-legs-front { animation: trot .07s steps(1) infinite alternate; }
[data-trick="highfive"] .herbert-dog { transform-origin: 30% 100%; animation: t-beg 1.1s ease-in-out; }
[data-trick="highfive"] .h-legs-front { transform-origin: 120px 80px; animation: t-paw 1.1s ease-in-out; }
[data-trick="sing"] .herbert-dog { transform-origin: 40% 100%; animation: t-sing 1.5s ease-in-out; }
[data-trick="sing"] .eye { display: none; }
[data-trick="sing"] .h-closed { display: block; }

/* Props: hidden by default, shown by the trick that uses them. */
[data-prop="wurst"] .p-wurst, [data-prop="bone"] .p-bone, [data-prop="ball"] .p-ball, [data-prop="stick"] .p-stick,
[data-prop="slipper"] .p-slipper, [data-prop="paper"] .p-paper, [data-prop="flower"] .p-flower, [data-prop="shades"] .p-shades,
[data-prop="hat"] .p-hat, [data-prop="noseball"] .p-noseball, [data-prop="book"] .p-book, [data-prop="book"] .p-glasses { display: block; }
.prop { transform-box: view-box; }
[data-prop="shades"] .eye { display: none; }
/* No tongue while something is in his mouth. */
[data-prop="wurst"] .h-tongue, [data-prop="bone"] .h-tongue, [data-prop="ball"] .h-tongue, [data-prop="stick"] .h-tongue,
[data-prop="slipper"] .h-tongue, [data-prop="paper"] .h-tongue, [data-prop="flower"] .h-tongue { display: none !important; }

[data-trick="eat"] .p-wurst { transform-origin: 184px 76px; animation: p-bites 2.6s steps(1) forwards; }
[data-trick="eat"] .h-head, [data-trick="chew"] .h-head { animation: chew .22s ease-in-out infinite alternate; }
[data-trick="eat"] .herbert-dog { animation: t-nuzzle 2.6s ease-in-out; }
[data-trick="fetch"] .herbert-dog { animation: t-fetch 2.4s ease-in-out; }
[data-trick="fetch"] .prop { animation: p-appear 2.4s steps(1); }
[data-trick="fetch"] .h-legs-front { animation: trot .1s steps(1) infinite alternate; }
[data-trick="fetch"] .h-legs-back { animation: trot .1s steps(1) infinite alternate-reverse; }
[data-trick="liedown"] .h-legs-front, [data-trick="liedown"] .h-legs-back { transform-origin: 0 82px; animation: lie-legs 3.2s ease-in-out forwards; }
[data-trick="liedown"] .h-body { animation: lie-body 3.2s ease-in-out forwards; }
[data-trick="liedown"] .h-head { transform-origin: 140px 80px; animation: lie-head 3.2s ease-in-out forwards; }
[data-trick="liedown"] .eye { display: none; }
[data-trick="liedown"] .h-closed { display: block; }
[data-trick="liedown"] .h-tail { animation: wag 1.2s ease-in-out infinite alternate; }
[data-trick="rollover"] .herbert-dog { transform-origin: 50% 65%; animation: t-rollover 1.7s ease-in-out; }
[data-trick="rollover"] .h-legs-front, [data-trick="rollover"] .h-legs-back { animation: trot .12s steps(1) infinite alternate; }
[data-trick="cool"] .p-shades { animation: p-drop .5s cubic-bezier(.3, 1.5, .5, 1); }
[data-trick="cool"] .herbert-dog { animation: t-cool 2.4s ease-in-out; }
[data-trick="party"] .p-hat { animation: p-drop .45s cubic-bezier(.3, 1.6, .5, 1); }
[data-trick="party"] .herbert-dog { animation: f-hop .4s ease-in-out 4; }
[data-trick="balance"] .h-head { transform-origin: 140px 80px; animation: look-up 2.4s ease-in-out; }
[data-trick="balance"] .p-noseball { animation: p-bounce .4s ease-in-out infinite alternate; }
[data-trick="study"] .h-head { transform-origin: 140px 80px; animation: read 2.6s ease-in-out; }
[data-trick="study"] .p-book { animation: p-appear-up .4s ease-out; }
[data-trick="dance"] .herbert-dog { animation: t-dance .38s ease-in-out 5 alternate; }
[data-trick="dance"] .h-legs-front { animation: trot .19s steps(1) infinite alternate; }
[data-trick="dance"] .h-legs-back { animation: trot .19s steps(1) infinite alternate-reverse; }
[data-trick="dance"] .h-ear { animation: flap .19s infinite alternate; }

[data-fidget="look"] .h-head { animation: f-look 1.6s ease-in-out; }
[data-fidget="earflap"] .h-ear { animation: flap .16s ease-in-out 6 alternate; }
[data-fidget="sniff"] .h-head { animation: f-sniff .2s ease-in-out 6 alternate; }
[data-fidget="wagburst"] .h-tail { animation-duration: .1s; }
[data-fidget="smallhop"] .herbert-dog { animation: f-hop .5s ease-in-out 2; }
[data-fidget="scratch"] .h-legs-back { animation: trot .07s steps(1) infinite alternate; }
[data-fidget="scratch"] .h-head { animation: f-look 1.6s ease-in-out reverse; }

.h-particle {
  position: absolute; z-index: 3; pointer-events: none; font-size: 18px; line-height: 1;
  animation: h-float 1.4s ease-out forwards;
}

.bubble {
  position: relative; flex: 1; min-width: 0;
  background: var(--card); border: 3px solid var(--line); border-radius: 16px;
  padding: 10px 14px; margin-bottom: 26px;
  font-size: 15px; line-height: 1.35; font-weight: 800;
  box-shadow: var(--shadow);
  opacity: 0; transform-origin: 0 100%;
}
.bubble::before {
  content: ""; position: absolute; left: -12px; bottom: 10px;
  border: 9px solid transparent; border-right: 12px solid var(--line); border-left: 0;
}
.bubble::after {
  content: ""; position: absolute; left: -7px; bottom: 12px;
  border: 7px solid transparent; border-right: 9px solid var(--card); border-left: 0;
}
.bubble.show { opacity: 1; }
.bubble.pop { animation: pop .35s cubic-bezier(.3, 1.6, .5, 1); }

body[data-screen="home"] .herbert-dog { width: 150px; }
body[data-screen="home"] .herbert { min-height: 110px; }
/* ---------- Generic blocks ---------- */
#screen { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.panel, .deck-card, .prompt, .done, .result, .test-start, .stats {
  background: var(--card); border: 3px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.panel h3, .result h3 { font-size: 17px; margin-bottom: 10px; }

.btn {
  min-height: 52px; padding: 10px 16px;
  border: 3px solid var(--line); border-radius: 16px; background: var(--card);
  font-weight: 900; font-size: 16px; box-shadow: var(--shadow);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--line); }
.btn small { font-size: 13px; font-weight: 700; opacity: .85; }
.btn.big { min-height: 62px; font-size: 18px; width: 100%; }
.btn.primary { background: var(--orange); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn.accent { background: var(--purple); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn.next { background: var(--teal); }
.btn.danger.armed { background: var(--red); color: #fff; }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red); box-shadow: none; margin-top: 10px; }
.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.bar { height: 16px; border: 3px solid var(--line); border-radius: 99px; background: #fff; overflow: hidden; }
.bar span {
  display: block; height: 100%; background: repeating-linear-gradient(45deg, var(--green) 0 10px, #5bd88a 10px 20px);
  transition: width .6s cubic-bezier(.3, 1.4, .5, 1);
}
.bar.small { height: 14px; flex: 1; }

.pips { display: inline-flex; gap: 4px; }
.pips i { width: 12px; height: 12px; border: 2px solid var(--line); background: #fff; border-radius: 3px; }
.pips i.on { background: var(--yellow); }

/* ---------- Home ---------- */
.deck-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.deck-card h2 { font-size: 21px; font-weight: 900; }
.deck-card p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.deck-meta { font-weight: 800; }
.ring { position: relative; width: 78px; height: 78px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring-bg { stroke: #f1e3cc; }
.ring-fg { stroke: var(--green); stroke-linecap: round; transition: stroke-dashoffset 1s ease; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--pixel); font-size: 12px; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode {
  border: 3px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 10px; min-height: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  transition: transform .08s, box-shadow .08s;
}
.mode:active { transform: translateY(4px) scale(.98); box-shadow: 0 0 0 var(--line); }
.mode .ico { font-size: 40px; line-height: 1; }
.mode b { font-size: 17px; font-weight: 900; }
.mode small { font-size: 13px; opacity: .8; }
.m-cards { background: #ffe08a; }
.m-type { background: #a8ece4; }
.m-test { background: #ffb3c9; }
.m-prog { background: #cfc3ff; }
.modes .mode:nth-child(1) { animation-delay: .05s; }
.modes .mode:nth-child(2) { animation-delay: .1s; }
.modes .mode:nth-child(3) { animation-delay: .15s; }
.modes .mode:nth-child(4) { animation-delay: .2s; }

.home-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.home-actions .btn { flex-direction: row; gap: 8px; font-size: 15px; background: #fff; }
.ico-svg { width: 22px; height: 22px; flex: none; }

/* ---------- Bottom sheet (install help, share link) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(43, 29, 20, .45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade-in .2s ease-out;
}
.sheet-backdrop.closing { animation: fade-out .25s ease-in forwards; }
.sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 90dvh; overflow-y: auto;
  background: var(--bg); border: 3px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0;
  padding-block: 22px calc(env(safe-area-inset-bottom, 0px) + 18px);
  padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 14px; animation: sheet-up .35s cubic-bezier(.3, 1.3, .5, 1);
}
.sheet h2 { font-size: 20px; font-weight: 900; padding-right: 40px; text-wrap: balance; }
.sheet-lead, .sheet-note { margin: 0; line-height: 1.45; }
.sheet-note { font-size: 14px; color: var(--muted); }
.sheet-close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--line); background: var(--card); font-size: 16px; font-weight: 900; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; counter-reset: step; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 12px; background: var(--card); border: 2px solid #f0dcc4; border-radius: 14px; padding: 10px 12px; line-height: 1.4; }
.steps li::before { content: counter(step); flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--orange); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 14px; }
.step-icon { flex: none; min-width: 44px; padding: 0 8px; height: 44px; border-radius: 12px; background: #eef4ff; color: #0a7aff; display: grid; place-items: center; }
.step-icon .ico-svg { width: 26px; height: 26px; }
.step-txt { font-size: 12px; color: #0a7aff; }
.sheet-url { width: 100%; height: 52px; padding: 0 14px; font: inherit; font-size: 16px; border: 3px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink); }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ---------- Round ---------- */
.round-bar { display: flex; align-items: center; gap: 10px; font-family: var(--pixel); font-size: 11px; }
.german { font-size: 32px; font-weight: 900; line-height: 1.15; word-break: break-word; }
.german.small { font-size: 20px; color: var(--muted); }

/* ---------- Flashcards ---------- */
.card-zone { position: relative; perspective: 1000px; flex: 1; min-height: 280px; max-height: 380px; display: flex; }
.card {
  --dx: 0px;
  position: relative; flex: 1; outline: none;
  transform-style: preserve-3d;
  transform: translateX(var(--dx)) rotate(var(--rot, 0deg));
  transition: transform .5s cubic-bezier(.3, 1.3, .5, 1);
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.card.dragging { transition: none; }
.card .face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border: 3px solid var(--line); border-radius: 22px; box-shadow: 0 6px 0 var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 20px; text-align: center;
  transition: transform .5s cubic-bezier(.3, 1.3, .5, 1);
}
.card .front { background: #fffbe8; }
.card .back { transform: rotateY(180deg); background: #effcf9; }
.card.flipped .front { transform: rotateY(-180deg); }
.card.flipped .back { transform: rotateY(0deg); }
.card .hint { color: var(--muted); font-size: 14px; }
.card.enter { animation: deal .4s cubic-bezier(.3, 1.4, .5, 1); }
.card.leaving { pointer-events: none; transition: transform .38s ease-in, opacity .38s; opacity: 0; }
.card.out-right { transform: translateX(130%) rotate(25deg); }
.card.out-left { transform: translateX(-130%) rotate(-25deg); }
.card.out-down { transform: translateY(60%) scale(.8); }
.forms { margin: 0; width: 100%; display: grid; gap: 10px; }
.forms div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; border-bottom: 2px dashed #bfe9e2; padding-bottom: 8px; }
.forms dt { font-size: 13px; color: var(--muted); }
.forms dd { margin: 0; font-size: 24px; font-weight: 900; }
.swipe-label {
  position: absolute; top: 14px; z-index: 2; font-family: var(--pixel); font-size: 11px; padding: 8px;
  border: 3px solid var(--line); border-radius: 10px; opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none;
}
.swipe-label.left { left: 8px; background: var(--red); color: #fff; transform: rotate(-8deg); }
.swipe-label.right { right: 8px; background: var(--green); color: #fff; transform: rotate(8deg); }
.card-zone[data-swipe="left"] .swipe-label.left, .card-zone[data-swipe="right"] .swipe-label.right { opacity: 1; }

.rate { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; opacity: 0; transform: translateY(16px); pointer-events: none; transition: .25s; }
.rate.show { opacity: 1; transform: none; pointer-events: auto; }
.rate .btn { font-size: 26px; min-height: 76px; gap: 2px; padding: 8px 4px; }
.rate .btn span { font-size: 13px; }
.rate .bad { background: #ffc7c8; }
.rate .meh { background: #ffe9a8; }
.rate .good { background: #b9f0cb; }

/* ---------- Typing ---------- */
.prompt { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.prompt small { color: var(--muted); }
.type-form { display: flex; flex-direction: column; gap: 12px; }
/* The label sits inside the input, top left, and stays visible while typing. */
.field { display: block; position: relative; }
.field-label {
  position: absolute; left: 17px; top: 7px; z-index: 1; pointer-events: none;
  font-size: 11px; line-height: 1; font-weight: 800; letter-spacing: .3px; color: var(--muted);
}
.field input {
  width: 100%; height: 56px; padding: 15px 16px 0;
  font: inherit; font-size: 20px; font-weight: 800; color: var(--ink);
  background: #fff; border: 3px solid var(--line); border-radius: 14px; outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus { border-color: var(--purple); box-shadow: 0 0 0 4px #ddd3ff; }
.field.ok input { background: #d8f7e3; border-color: var(--green); }
.field.typo input { background: #fff2c2; border-color: #e0a800; }
.field.bad input { background: #ffe0e0; border-color: var(--red); text-decoration: line-through; animation: shake .4s; }
.field.ok .field-label::after { content: " ✔"; color: var(--green); }
.field.bad .field-label::after { content: " ✘"; color: var(--red); }
.solution { display: block; font-style: normal; font-weight: 900; margin: 4px 0 0 4px; font-size: 16px; }
.solution:empty { display: none; }
.field.bad .solution { color: #c4262b; }
.field.typo .solution { color: #8a6500; }

/* ---------- Test ---------- */
.test-start p { line-height: 1.45; }
.test-start .best, .result .best { font-weight: 800; background: #fff3c4; border-radius: 12px; padding: 8px 12px; }
.result { text-align: center; }
.grade {
  width: 130px; height: 130px; margin: 6px auto 10px; border: 4px solid var(--line); border-radius: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--pixel); font-size: 54px; box-shadow: 0 6px 0 var(--line);
  animation: stamp .6s cubic-bezier(.3, 1.6, .5, 1);
}
.grade small { font-family: var(--font); font-size: 14px; font-weight: 900; margin-bottom: 6px; }
.g1 { background: #7be3a0; } .g2 { background: #b4eb8a; } .g3 { background: #ffe27a; }
.g4 { background: #ffc27a; } .g5 { background: #ff9d8a; } .g6 { background: #ff7a85; }
.score { font-size: 18px; font-weight: 900; margin: 8px 0; }
.mistakes { list-style: none; margin: 0; padding: 0; text-align: left; display: grid; gap: 8px; }
.mistakes li { background: #fff7ee; border: 2px solid #f0dcc4; border-radius: 12px; padding: 10px 12px; }
.mrow { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; font-size: 15px; }
.mrow .ok { color: #1f8a47; font-weight: 800; }
.mrow .bad { color: #c4262b; font-weight: 900; }
.mrow s { color: var(--muted); font-weight: 600; }

/* ---------- Done / progress ---------- */
.done { text-align: center; }
.big-emoji { font-size: 64px; margin: 4px 0; animation: hop .6s ease-in-out 2; }
.stats { display: flex; align-items: center; gap: 16px; }
.stats .ring { width: 100px; height: 100px; }
.stats .ring span { font-size: 15px; }
.tiles { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: #fff7ee; border: 2px solid #f0dcc4; border-radius: 12px; padding: 8px; text-align: center; }
.tile b { display: block; font-size: 22px; font-weight: 900; }
.tile b small { font-size: 13px; color: var(--muted); }
.tile span { font-size: 12px; color: var(--muted); }
.trouble, .all { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.trouble li, .all li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 2px dashed #f0dcc4; }
.trouble li:last-child, .all li:last-child { border-bottom: 0; }
.miss { font-weight: 900; color: var(--red); white-space: nowrap; }
.all small { display: block; color: var(--muted); font-size: 13px; }
.tests { display: flex; align-items: flex-end; gap: 8px; height: 110px; }
.tests .t { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; background: none; }
.tests .t span { width: 100%; border: 2px solid var(--line); border-radius: 6px 6px 2px 2px; background: inherit; }
.tests .t small { font-family: var(--pixel); font-size: 10px; }
.tests .t.g1 span { background: #7be3a0; } .tests .t.g2 span { background: #b4eb8a; } .tests .t.g3 span { background: #ffe27a; }
.tests .t.g4 span { background: #ffc27a; } .tests .t.g5 span { background: #ff9d8a; } .tests .t.g6 span { background: #ff7a85; }
.tests .t { background: transparent !important; }

/* ---------- Small phones (iPhone mini, SE) ---------- */
@media (max-height: 700px) {
  .app { padding-top: calc(env(safe-area-inset-top, 0px) + 4px); }
  .topbar { min-height: 48px; }
  .herbert { min-height: 72px; margin: 2px 0 8px; }
  .herbert-dog { width: 92px; }
  body[data-screen="home"] .herbert { min-height: 88px; }
  body[data-screen="home"] .herbert-dog { width: 116px; }
  .bubble { font-size: 14px; padding: 8px 12px; margin-bottom: 16px; }
  #screen { gap: 10px; }
  .prompt { padding: 10px 12px; gap: 2px; }
  .german { font-size: 28px; }
  .type-form { gap: 8px; }
  .field input { height: 48px; }
  .card-zone { min-height: 230px; }
  .rate .btn { min-height: 64px; font-size: 22px; }
  .mode { min-height: 116px; padding: 12px 8px; }
  .mode .ico { font-size: 32px; }
}

/* ---------- Keyboard open ----------
   The app is pinned to the visible part of the screen (above the keyboard), Herbert stays at the top
   and the question scrolls below him if needed. With enough room (Safari) the normal layout is kept;
   only when space is short (vv-compact, vv-tiny set from JS) things get squeezed. */
body.kbd .app {
  position: fixed; left: 0; right: 0; top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh); min-height: 0;
  padding-block: 6px 8px;
  overflow: hidden;
}
body.kbd .topbar, body.kbd .prompt small { display: none; }
body.kbd .head { flex: none; position: static; border: 0; box-shadow: none; }
body.kbd .herbert { flex: none; min-height: 0; margin: 0 0 10px; align-items: center; }
body.kbd .herbert-dog { width: 92px; }
body.kbd .bubble { margin: 0; }
body.kbd .bubble::before, body.kbd .bubble::after { bottom: 50%; transform: translateY(50%); }
body.kbd #screen { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 2px 6px; -webkit-overflow-scrolling: touch; }

/* Short on space: compact rows, button next to the German word. */
body.kbd.vv-compact .round-bar, body.kbd.vv-compact .prompt small, body.kbd.vv-compact .prompt .pips { display: none; }
body.kbd.vv-compact .herbert { margin: 0 0 6px; gap: 8px; }
body.kbd.vv-compact .herbert-dog { width: 62px; }
body.kbd.vv-compact .bubble { font-size: 13px; line-height: 1.25; padding: 5px 10px; box-shadow: 0 3px 0 var(--line); }
body.kbd.vv-compact .bubble span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
body.kbd.vv-tiny .bubble span { -webkit-line-clamp: 2; }
body.kbd.vv-compact #screen { gap: 6px; }
body.kbd.vv-compact .prompt { flex: none; padding: 4px 10px; border-width: 2px; box-shadow: 0 2px 0 var(--line); }
body.kbd.vv-compact .german { font-size: 22px; }
body.kbd.vv-compact #screen:has(.type-form) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: start; }
body.kbd.vv-compact .type-form { display: contents; }
body.kbd.vv-compact .prompt { grid-column: 1; grid-row: 1; justify-content: center; }
body.kbd.vv-compact .type-form .btn.big { grid-column: 2; grid-row: 1; width: auto; min-height: 0; height: 100%; padding: 4px 14px; font-size: 15px; box-shadow: 0 2px 0 var(--line); border-width: 2px; }
body.kbd.vv-compact .field { grid-column: 1 / -1; }
body.kbd.vv-compact .field input { height: 44px; font-size: 17px; border-width: 2px; padding-top: 13px; }
body.kbd.vv-compact .field-label { top: 5px; left: 15px; font-size: 10px; }

/* ---------- Password splash ---------- */
body.locked { overflow: hidden; }
.splash {
  position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-height, 100dvh); z-index: 40;
  overflow-y: auto; display: flex; justify-content: center; align-items: flex-start;
  padding-block: calc(env(safe-area-inset-top, 0px) + 28px) 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 2px, transparent 2px), linear-gradient(180deg, #ffe7c2 0%, var(--bg) 55%);
  background-size: 22px 22px, 100% 100%;
}
.splash-inner { width: 100%; max-width: 400px; display: flex; flex-direction: column; align-items: center; gap: 14px; animation: pop-in .5s cubic-bezier(.3, 1.5, .5, 1) both; }
.splash-title { font-family: var(--pixel); font-size: 20px; line-height: 1.6; text-align: center; color: var(--ink); text-shadow: 3px 3px 0 var(--yellow); }
.splash-dog { width: 210px; cursor: pointer; margin-top: 6px; }
.splash-dog .herbert-svg { animation: none; }
[data-mood="idle"].splash-dog .herbert-svg, .splash-dog[data-mood="idle"] .herbert-svg { animation: f-hop 2.6s ease-in-out infinite; }
.splash-bubble {
  position: relative; margin: 6px 0 0; width: 100%;
  background: var(--card); border: 3px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px 16px; font-size: 16px; font-weight: 800; line-height: 1.35; text-align: center;
}
.splash-bubble::before { content: ""; position: absolute; top: -14px; left: 50%; transform: translateX(-50%); border: 11px solid transparent; border-bottom: 14px solid var(--line); border-top: 0; }
.splash-bubble::after { content: ""; position: absolute; top: -9px; left: 50%; transform: translateX(-50%); border: 8px solid transparent; border-bottom: 10px solid var(--card); border-top: 0; }
.splash-bubble.pop { animation: pop .35s cubic-bezier(.3, 1.6, .5, 1); }
.splash-form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.splash-form input { letter-spacing: 2px; }
.splash.wrong .splash-form { animation: shake .4s; }
.splash.wrong .splash-form input { border-color: var(--red); }
.splash.leaving { animation: splash-out .45s ease-in forwards; }
@keyframes splash-out { to { opacity: 0; transform: scale(1.06); } }
body.vv-compact .splash { padding-top: 10px; }
body.vv-compact .splash-inner { gap: 8px; }
body.vv-compact .splash-title { font-size: 14px; }
body.vv-compact .splash-dog { width: 130px; margin-top: 0; }
body.vv-compact .splash-bubble { font-size: 14px; padding: 8px 12px; }

/* ---------- Confetti ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#confetti i { position: absolute; width: 9px; height: 9px; animation: burst 1.3s cubic-bezier(.2, .7, .4, 1) forwards; }

/* ---------- Animations ---------- */
.pop-in { animation: pop-in .45s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes wag { from { transform: rotate(-22deg); } to { transform: rotate(18deg); } }
@keyframes breathe { 50% { transform: scaleY(1.035); } }
@keyframes tilt { 0%, 70%, 100% { transform: none; } 80%, 92% { transform: rotate(-6deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes flap { from { transform: rotate(-8deg); } to { transform: rotate(14deg); } }
@keyframes hop { 50% { transform: translateY(-14%); } }
@keyframes trot { to { transform: translateY(-4px); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes drip { from { transform: translateY(0); opacity: 1; } to { transform: translateY(10px); opacity: 0; } }
@keyframes deal { from { transform: translateY(40px) rotate(-6deg) scale(.9); opacity: 0; } }
@keyframes stamp { from { transform: scale(2.2) rotate(-12deg); opacity: 0; } }
@keyframes t-spin { 0% { transform: none; } 40% { transform: translateY(-18%) rotate(180deg); } 100% { transform: rotate(360deg); } }
@keyframes t-backflip { 0% { transform: none; } 20% { transform: translateY(6%) scaleY(.85); } 60% { transform: translateY(-55%) rotate(-300deg); } 85% { transform: translateY(0) rotate(-360deg) scaleY(.9); } 100% { transform: rotate(-360deg); } }
@keyframes t-stretch { 0%, 100% { transform: none; } 35%, 70% { transform: scaleX(1.45) scaleY(.92); } 80% { transform: scaleX(.95) scaleY(1.04); } }
@keyframes t-zoomies { 0% { transform: none; } 40% { transform: translateX(190px); } 45% { transform: translateX(190px) scaleX(-1); } 85% { transform: translateX(0) scaleX(-1); } 90%, 100% { transform: none; } }
@keyframes t-nuzzle { 0%, 100% { transform: none; } 20%, 60% { transform: rotate(-6deg) scale(1.06); } 40%, 80% { transform: rotate(4deg) scale(1.06); } }
@keyframes t-bark { 0%, 100% { transform: none; } 15%, 45%, 75% { transform: scale(1.12) translateY(-4%); } 30%, 60%, 90% { transform: scale(.97); } }
@keyframes t-barkhead { 50% { transform: rotate(-10deg) translateY(-3px); } }
@keyframes t-sneeze { 0% { transform: none; } 35% { transform: scale(1.04, .9) rotate(6deg); } 45% { transform: translateX(-10px) rotate(-10deg) scale(1.06); } 70% { transform: translateX(-4px); } 100% { transform: none; } }
@keyframes t-shakeoff { 0%, 100% { transform: none; } 10%, 30%, 50%, 70% { transform: rotate(-7deg) scaleX(.97); } 20%, 40%, 60%, 80% { transform: rotate(7deg) scaleX(1.03); } }
@keyframes t-beg { 0%, 100% { transform: none; } 25%, 75% { transform: rotate(-32deg) translateY(-4%); } 50% { transform: rotate(-28deg) translateY(-6%); } }
@keyframes t-paw { 0%, 100% { transform: none; } 30%, 70% { transform: rotate(-60deg) translate(6px, -10px); } }
@keyframes t-chase { 0% { transform: none; } 100% { transform: rotate(-1080deg); } }
@keyframes t-dig { 0%, 100% { transform: none; } 15%, 85% { transform: rotate(14deg) translateY(4%); } }
@keyframes t-sing { 0%, 100% { transform: none; } 20%, 80% { transform: rotate(-14deg); } 50% { transform: rotate(-18deg) translateY(-3%); } }
@keyframes p-bites { 0% { transform: none; } 25% { transform: scaleX(.72); } 50% { transform: scaleX(.42); } 75%, 100% { transform: scaleX(0); } }
@keyframes chew { to { transform: rotate(4deg) translateY(1.5px); } }
@keyframes t-fetch { 0% { transform: none; } 28% { transform: translateX(300px); } 29% { transform: translateX(-220px) scaleX(1); } 62%, 100% { transform: none; } }
@keyframes p-appear { 0% { opacity: 0; } 29%, 100% { opacity: 1; } }
@keyframes lie-legs { 0% { transform: none; } 20%, 85% { transform: scaleY(.25); } 100% { transform: none; } }
@keyframes lie-body { 0% { transform: none; } 20%, 85% { transform: translateY(13px); } 100% { transform: none; } }
@keyframes lie-head { 0% { transform: none; } 20%, 85% { transform: rotate(10deg) translateY(4px); } 100% { transform: none; } }
@keyframes t-rollover { 0% { transform: none; } 20% { transform: translateY(8%) scaleY(.85); } 70% { transform: translateX(30px) rotate(360deg); } 100% { transform: rotate(360deg); } }
@keyframes p-drop { from { transform: translateY(-40px); opacity: 0; } }
@keyframes t-cool { 0%, 100% { transform: none; } 20%, 80% { transform: rotate(-4deg) scale(1.05); } 50% { transform: rotate(3deg) scale(1.05); } }
@keyframes look-up { 0%, 100% { transform: none; } 15%, 85% { transform: rotate(-14deg); } }
@keyframes p-bounce { from { transform: translateY(0); } to { transform: translateY(-14px) rotate(25deg); } }
@keyframes read { 0%, 100% { transform: none; } 15%, 40% { transform: rotate(10deg); } 55%, 85% { transform: rotate(14deg) translateX(2px); } }
@keyframes p-appear-up { from { transform: translateY(20px); opacity: 0; } }
@keyframes t-dance { from { transform: rotate(-9deg) translateX(-6px); } to { transform: rotate(9deg) translateX(6px) translateY(-6%); } }
@keyframes f-look { 0%, 100% { transform: none; } 25% { transform: rotate(-10deg); } 60% { transform: rotate(8deg); } }
@keyframes f-sniff { to { transform: translate(2px, 2px) rotate(3deg); } }
@keyframes f-hop { 50% { transform: translateY(-10%); } }
@keyframes h-float { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(var(--px), var(--py)) scale(1.1); opacity: 0; } }
@keyframes burst {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--x), calc(var(--y) + 260px)) rotate(var(--r)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (min-width: 560px) {
  .topbar h1 { font-size: 15px; }
}
