/* =============================================================================
   Vokabel-Knights — Stylesheet (Spiel + Login). Admin ergänzt admin.css.
   Stil übernommen aus Task Knights: Pergament/Holz-Palette, 9-slice-Rahmen,
   Pixel-Sprites. Zielgerät: iPad im Querformat (1024×768 bis 1366×1024).
   ============================================================================= */

@font-face {
  font-family: 'GameFont';
  src: url('/assets/fonts/text_font.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #359595;
  --parch: #d6c7a4;
  --parch2: #cbba90;
  --wood: #b5713b;
  --accent: #ffce40;
  --good: #7fb83f;
  --bad: #d94a3d;
  --text: #f3eeff;
  --ink: #3a2a16;
  --muted: #6f5d3e;
  --frame-wood: url('/assets/ui/panel_wood.png');
  --frame-slot: url('/assets/ui/frame_slot.png');
  --app-h: 100dvh;           /* per JS auf visualViewport-Höhe gesetzt (Tastatur) */
  --hero-size: 720px;       /* Figurengröße in Arena-Designkoordinaten (Sheets: 40 % Luft unter den Füßen) */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: clamp(16px, 1.45vw, 22px); }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'GameFont', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}
button, input { font-family: inherit; }
.hidden { display: none !important; }

/* ---- Grundbausteine ---- */
.panel {
  border: 20px solid transparent;
  border-image: var(--frame-wood) 18 fill / 20px repeat;
  image-rendering: pixelated;
}
.slot {
  border: 14px solid transparent;
  border-image: var(--frame-slot) 14 fill / 14px repeat;
  image-rendering: pixelated;
}

.btn {
  background: none;
  color: #2a2336;
  border: 9px solid transparent;
  border-image: url('/assets/ui/btn_default.png') 7 fill / 9px repeat;
  border-radius: 0;
  image-rendering: pixelated;
  padding: 0.2rem 0.8rem;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); filter: brightness(0.92); }
.btn:disabled { filter: grayscale(0.7) brightness(0.9); opacity: 0.7; }
.btn.brown { border-image-source: url('/assets/ui/btn_ghost.png'); color: #3a2a14; }
.btn.green { border-image-source: url('/assets/ui/btn_good.png'); color: #1f3010; }
.btn.red   { border-image-source: url('/assets/ui/btn_attack.png'); color: #fff; }
.btn.big   { font-size: 1.25rem; padding: 0.4rem 1.4rem; }

.ico {
  display: inline-block;
  width: 1.2em; height: 1.2em;
  background: center / contain no-repeat;
  image-rendering: pixelated;
  vertical-align: -0.25em;
}
.ico-check { background-image: url('/assets/ui/icons/icon_check.png'); }
.ico-cross { background-image: url('/assets/ui/icons/icon_cross.png'); }
.ico-exit  { background-image: url('/assets/ui/icons/icon_exit.png'); }
.ico-home  { background-image: url('/assets/ui/icons/icon_home.png'); }
.ico-heart { background-image: url('/assets/ui/icons/icon_heart.png'); }
.ico-shop  { background-image: url('/assets/ui/icons/icon_characters.png'); }
.coin-ico { width: 1.4em; height: 1.4em; image-rendering: pixelated; vertical-align: -0.35em; object-fit: contain; }

.input {
  background: #e6d8b8;
  border: 3px solid var(--wood);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  color: var(--ink);
  font-size: 1.2rem;
  min-height: 48px;
  -webkit-user-select: text;
  user-select: text;
}
.input:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--bad); font-weight: 700; min-height: 1.3em; text-align: center; }

.title {
  font-size: 2.6rem;
  color: var(--accent);
  text-shadow: 0 3px 0 #7a4a1c, 0 0 12px rgba(0,0,0,0.35);
  letter-spacing: 1px;
  margin: 0;
}

/* ---- Sprites ---- */
.sprite {
  --w: 100px;
  --frames: 6;
  width: var(--w);
  height: var(--w);
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-size: calc(var(--w) * var(--frames)) var(--w);
  image-rendering: pixelated;
  animation: sheet 0.8s steps(6) infinite;
}
/* Monster-Sheets schauen nach rechts -> zum Helden hin spiegeln */
.sprite.flip, .sprite-wrap.flip { transform: scaleX(-1); }

/* ---- Held mit Farbe/Aura (Technik aus Task Knights) ----
   .sprite-wrap legt Schichten deckungsgleich übereinander: Aura hinten, Held,
   Farbtönung (Maske *-Color.png, Overlay-Blend), Aura vorn. --w kommt vom Wrapper. */
.sprite-wrap { position: relative; display: inline-block; width: var(--w); height: var(--w); flex-shrink: 0; }
.sprite-wrap > .sprite { position: absolute; inset: 0; }
.sprite-tint {
  position: absolute; inset: 0; --frames: 6;
  width: var(--w); height: var(--w);
  isolation: isolate;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-size: calc(var(--w) * var(--frames)) var(--w);
  mask-size: calc(var(--w) * var(--frames)) var(--w);
  -webkit-mask-position: 0 0; mask-position: 0 0;
  image-rendering: pixelated; pointer-events: none;
  animation: sheet-mask 0.8s steps(6) infinite;
}
@keyframes sheet-mask {
  from { -webkit-mask-position: 0 0; mask-position: 0 0; }
  to   { -webkit-mask-position: calc(var(--w) * -1 * var(--frames)) 0; mask-position: calc(var(--w) * -1 * var(--frames)) 0; }
}
.sprite-tint-grey, .sprite-tint-hue { position: absolute; inset: 0; }
.sprite-tint-grey {
  background-repeat: no-repeat;
  background-size: calc(var(--w) * var(--frames)) var(--w);
  image-rendering: pixelated;
  animation: sheet 0.8s steps(6) infinite;
}
.sprite-tint-hue { background-color: var(--tint, transparent); mix-blend-mode: overlay; }

/* Aura: 2-zeiliges Sheet (obere Zeile hinter, untere vor dem Helden), Frames quadratisch */
.aura-layer {
  --aura-scale: 0.4;
  --aura-rows: 2;
  --aura-row-y: 0;
  position: absolute; left: 50%; top: 45%;
  width: calc(var(--w) * var(--aura-scale)); height: calc(var(--w) * var(--aura-scale));
  transform: translate(-50%, -50%);
  isolation: isolate;
  mask-repeat: no-repeat; -webkit-mask-repeat: no-repeat;
  mask-size: calc(var(--w) * var(--aura-scale) * var(--aura-frames)) calc(var(--w) * var(--aura-scale) * var(--aura-rows));
  -webkit-mask-size: calc(var(--w) * var(--aura-scale) * var(--aura-frames)) calc(var(--w) * var(--aura-scale) * var(--aura-rows));
  mask-position: 0 var(--aura-row-y); -webkit-mask-position: 0 var(--aura-row-y);
  image-rendering: pixelated; pointer-events: none;
  animation: aura-sheet-mask 2s steps(var(--aura-frames)) infinite;
}
.aura-layer-grey, .aura-layer-hue { position: absolute; inset: 0; }
.aura-layer-grey {
  background-repeat: no-repeat;
  background-size: calc(var(--w) * var(--aura-scale) * var(--aura-frames)) calc(var(--w) * var(--aura-scale) * var(--aura-rows));
  image-rendering: pixelated;
  animation: aura-sheet-bg 2s steps(var(--aura-frames)) infinite;
}
.aura-layer-hue { background-color: var(--tint, transparent); mix-blend-mode: overlay; }
.aura-back { --aura-row-y: 0; z-index: 0; }
.aura-front { --aura-row-y: calc(var(--w) * var(--aura-scale) * -1 * (var(--aura-rows) - 1)); z-index: 1; }
.aura-front .aura-layer-grey { background-position-y: calc(var(--w) * var(--aura-scale) * -1 * (var(--aura-rows) - 1)); }
@keyframes aura-sheet-mask {
  from { mask-position: 0 var(--aura-row-y); -webkit-mask-position: 0 var(--aura-row-y); }
  to   {
    mask-position: calc(var(--w) * var(--aura-scale) * -1 * var(--aura-frames)) var(--aura-row-y);
    -webkit-mask-position: calc(var(--w) * var(--aura-scale) * -1 * var(--aura-frames)) var(--aura-row-y);
  }
}
@keyframes aura-sheet-bg {
  from { background-position-x: 0; }
  to   { background-position-x: calc(var(--w) * var(--aura-scale) * -1 * var(--aura-frames)); }
}
@keyframes sheet {
  from { background-position: 0 0; }
  to   { background-position: calc(var(--w) * -1 * var(--frames)) 0; }
}

.hit-fx {
  position: absolute;
  left: 50%; top: 52%;
  width: 32px; height: 32px;
  margin: -16px 0 0 -16px;
  transform: scale(5);
  background: url('/assets/ui/vfx_hit.png') 0 0 / 192px 64px no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 5;
  animation: hitx 0.3s steps(6) 2 forwards, hity 0.6s steps(2, jump-none) 1 forwards;
}
@keyframes hitx { from { background-position-x: 0; } to { background-position-x: -192px; } }
@keyframes hity { from { background-position-y: 0; } to { background-position-y: -32px; } }

/* =============================================================================
   LOGIN
   ============================================================================= */
.login-screen {
  height: var(--app-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: url('/assets/bg/arena.png') center / cover no-repeat;
  image-rendering: pixelated;
}
.login-box { width: min(30rem, 46vw); display: flex; flex-direction: column; gap: 0.8rem; align-items: stretch; text-align: center; }
.login-box .title { font-size: 2.2rem; }
.login-sub { margin: 0 0 0.4rem; color: var(--muted); }
.login-deco { width: 220px; display: flex; justify-content: center; }
.login-deco .sprite { margin: -40% 0 0; }

/* =============================================================================
   SPIEL-SHELL (alle Screens füllen genau die sichtbare Höhe)
   ============================================================================= */
.screen {
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  padding: max(0.6rem, env(safe-area-inset-top)) max(0.8rem, env(safe-area-inset-right)) max(0.6rem, env(safe-area-inset-bottom)) max(0.8rem, env(safe-area-inset-left));
  gap: 0.6rem;
}
.screen-enter { animation: screen-in 0.35s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  flex: 0 0 auto;
}
.topbar .title { font-size: 1.7rem; margin-right: auto; }
.topbar .spacer { flex: 1; }
.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(30, 20, 10, 0.55);
  border: 3px solid var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.9rem 0.15rem 0.5rem;
  font-size: 1.3rem;
  color: var(--accent);
  font-weight: 700;
  min-height: 44px;
}
.coin-pill.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 50% { transform: scale(1.18); } }

/* =============================================================================
   HOME: Held links, Lektionen rechts
   ============================================================================= */
/* Home: Burg als breites Band oben, Missionsliste darunter */
.home-board { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 5fr) minmax(0, 6fr); gap: 0.8rem; }
.hero-panel { display: flex; flex-direction: column; align-items: center; min-height: 0; min-width: 0; }
.hero-stage {
  flex: 1;
  width: calc(100% + 16px);
  margin: -8px -8px 0;
  min-height: 0;
  background: url('/assets/bg/arena.png') center 40% / cover no-repeat;
  image-rendering: pixelated;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
/* Figur mittig auf die Wiese (der Klippenrand unten im Bild bleibt frei) */
.hero-stage { align-items: center; }
.hero-stage > .sprite, .hero-stage > .sprite-wrap { margin-top: 12%; }
/* Burg: eigener Held vorne in der Mitte, Freunde in zwei Reihen links/rechts. Jede
   Figur ist über ihren Fußpunkt (left/top in %) verankert; Sheets haben die Füße
   bei 60 % Höhe. --ch (Höhe der Bühne, per JS gesetzt) skaliert alle Figuren mit. */
/* isolation: z-Indizes der Figuren bleiben in der Burg (nicht über Dialogen) */
.castle { display: block; isolation: isolate; }
.castle .fig { position: absolute; width: 0; height: 0; }
.castle .fig > .sprite, .castle .fig > .sprite-wrap { position: absolute; left: 0; top: 0; margin: 0; transform: translate(-50%, -60%); }
.castle .fig > .sprite.flip, .castle .fig > .sprite-wrap.flip { transform: translate(-50%, -60%) scaleX(-1); }
.castle .fig-label { position: absolute; width: 0; height: 0; z-index: 200; pointer-events: none; }
.castle .fig-name {
  position: absolute; top: 4px; left: 0; transform: translateX(-50%);
  white-space: nowrap; font-size: 0.85rem; color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.castle .fig-label.me .fig-name { font-size: 1.25rem; font-weight: 700; color: var(--accent); top: 6px; }
.castle .fig-label.me .fig-class { position: absolute; top: 2.1rem; left: 0; transform: translateX(-50%); white-space: nowrap; font-size: 0.8rem; color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000; }
.castle .more-friends {
  position: absolute; right: 8px; top: 8px; color: #fff; font-size: 0.85rem;
  background: rgba(30, 20, 10, 0.55); border-radius: 8px; padding: 0.1rem 0.5rem;
}
.hero-panel > .hero-stage { margin-bottom: -8px; }

.lesson-panel { display: flex; flex-direction: column; min-height: 0; }
.lesson-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.3rem; }
.lesson-head h2 { margin: 0; font-size: 1.4rem; }
.lesson-head .btn { min-height: 44px; }
.lesson-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 0.3rem; }
.book-title { font-size: 0.9rem; color: var(--muted); margin: 0 0 0.2rem; }
.unit-title { font-size: 1.2rem; margin: 0.8rem 0 0.3rem; color: #5c3d1a; border-bottom: 2px dashed rgba(92, 61, 26, 0.35); }
.unit-title:first-of-type { margin-top: 0.2rem; }
.lesson-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.lesson-tile {
  background: none;
  border: 14px solid transparent;
  border-image: var(--frame-slot) 14 fill / 14px repeat;
  image-rendering: pixelated;
  padding: 0.1rem 0.2rem;
  min-height: 72px;
  font-size: 1.05rem;
  color: var(--ink);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
}
.lesson-tile:active { transform: scale(0.96); }
.lesson-tile .lt-name { font-weight: 700; }
.lesson-tile .lt-meta { font-size: 0.8rem; color: var(--muted); }
.lesson-tile .ico-check { position: absolute; top: 50%; right: 0.3rem; transform: translateY(-50%); width: 1.6em; height: 1.6em; }
.lesson-tile.done { filter: saturate(0.85); padding-right: 1.8rem; }

/* =============================================================================
   SHOP
   ============================================================================= */
.shop-board { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 0.8rem; }
.shop-grid-wrap { min-height: 0; display: flex; flex-direction: column; }
/* Einklappbare Kategorien (Helden / Farben / Auren) */
.shop-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 0.5rem; padding-right: 0.2rem; }
.cat-head {
  width: 100%; display: flex; align-items: center; gap: 0.6rem; min-height: 52px;
  background: var(--parch2); border: 3px solid var(--wood); border-radius: 10px;
  padding: 0.3rem 0.9rem; font-size: 1.2rem; font-weight: 700; color: var(--ink);
  text-align: left; cursor: pointer; touch-action: manipulation;
}
.cat-arrow {
  width: 0; height: 0; flex-shrink: 0;
  border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 10px solid var(--ink);
  transform: rotate(-90deg); transition: transform 0.15s;
}
.shop-cat.open .cat-arrow { transform: none; }
.cat-count { margin-left: auto; font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.cat-body { padding-top: 0.5rem; }
.shop-empty { margin: 0.3rem 0.5rem; }
.shop-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; align-content: start; }
.shop-card {
  background: none;
  border: 14px solid transparent;
  border-image: var(--frame-slot) 14 fill / 14px repeat;
  image-rendering: pixelated;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.95rem;
  position: relative;
  min-width: 0;
  touch-action: manipulation;
}
.shop-card .sprite-clip { width: 100%; height: 120px; overflow: hidden; display: flex; justify-content: center; align-items: flex-start; }
/* Füße sitzen bei 60 % der Frame-Höhe -> Frame so hochziehen, dass sie unten im Clip stehen */
.shop-card .sprite-clip > .sprite, .shop-card .sprite-clip > .sprite-wrap { margin-top: calc(var(--w) * -0.6 + 116px); }
.shop-card .sc-name { font-weight: 700; margin-top: 0.2rem; }
.shop-card .sc-price { font-size: 0.9rem; }
.shop-card.selected { outline: 4px solid var(--accent); outline-offset: -4px; }
.shop-card.locked .sprite-clip > * { filter: brightness(0.35); }
.shop-card .badge { position: absolute; top: -8px; right: -8px; width: 1.6em; height: 1.6em; }
.shop-detail { display: flex; flex-direction: column; align-items: center; text-align: center; min-height: 0; }
.shop-detail .hero-stage { flex: 1; }
.shop-detail h3 { margin: 0.4rem 0 0.2rem; font-size: 1.5rem; }
.shop-detail .sd-price { font-size: 1.2rem; margin-bottom: 0.5rem; }
.shop-detail .sd-hint { color: var(--muted); min-height: 1.3em; margin-bottom: 0.4rem; }

/* =============================================================================
   MISSION: Arena oben, Frage + Antwort unten
   ============================================================================= */
.mission-top { display: flex; align-items: center; gap: 0.8rem; color: var(--text); }
.mission-top .lesson-name { font-size: 1.2rem; white-space: nowrap; }
.progress {
  flex: 1;
  height: 28px;
  position: relative;
  background: #3b2a1a;
  border: 3px solid #2a1c10;
  border-radius: 14px;
  overflow: hidden;
}
.progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(#ffe27a, #e9a92a); transition: width 0.4s; }
.progress-text { position: relative; z-index: 1; text-align: center; line-height: 22px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }

.arena-wrap { flex: 0 0 50%; min-height: 0; display: flex; transition: flex-basis 0.25s; }
.arena-wrap.panel { border-width: 14px; border-image: var(--frame-wood) 18 fill / 14px repeat; }
.arena-stage {
  --scene-scale: 1;
  position: relative;
  flex: 1;
  overflow: hidden;
  margin: -6px;
  background: #5fab62;      /* Wiesengrün: füllt die Seiten, falls die Szene schmaler als die Bühne ist */
}
.arena-stage::after { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 14px 5px rgba(40, 26, 14, 0.45); z-index: 6; }
/* Szene in festen Designmaßen (Hintergrund 384×288 ×3). fitScene() skaliert sie so,
   dass das Band um die Figuren (--band-center) immer sichtbar und mittig ist. */
.arena {
  --scene-w: 1536px;       /* breiter als das 4:3-Bild: cover schneidet nur oben/unten (Himmel/Wasser) ab */
  --scene-h: 864px;
  --band-center: 330px;     /* y-Mitte des Bereichs Namen/HP-Leisten … Füße */
  position: absolute;
  top: 50%; left: 50%;
  width: var(--scene-w);
  height: var(--scene-h);
  transform-origin: 50% 0;
  transform: translate(-50%, calc(var(--band-center) * var(--scene-scale) * -1)) scale(var(--scene-scale));
  background: url('/assets/bg/arena.png') center / cover no-repeat;
  image-rendering: pixelated;
}
/* Figuren absolut: Füße (40 % Luft unter den Füßen im Frame) auf die 50 %-Linie */
.fighter {
  position: absolute;
  bottom: calc(var(--scene-h) * 0.5 - var(--hero-size) * 0.4);
  width: var(--hero-size);
  height: var(--hero-size);
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
}
.fighter.hero { left: 34%; }
.fighter.monster { left: 66%; }
.fighter-info {
  position: absolute;
  left: 50%;
  bottom: calc(var(--hero-size) * 0.64);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: max-content;
  z-index: 4;
}
.fighter-name { font-size: 34px; font-weight: 700; color: #fff; text-shadow: 0 2px 3px #000, 0 0 4px #000; }
.fighter.monster .fighter-name { color: #ff9b8b; }
.hpbar { width: 260px; height: 26px; background: #4a2030; border: 4px solid #241018; border-radius: 13px; overflow: hidden; position: relative; }
.hpfill { height: 100%; transition: width 0.35s; }
.fighter.hero .hpfill { background: linear-gradient(#a8e06a, #5f9a2c); }
.fighter.monster .hpfill { background: linear-gradient(#ff8a6b, #c8352a); }
.hptext { position: absolute; inset: 0; text-align: center; font-size: 18px; line-height: 18px; color: #fff; text-shadow: 0 1px 2px #000; }
.fighter.hurt > .sprite, .fighter.hurt > .sprite-wrap { filter: sepia(1) saturate(6) hue-rotate(-30deg) brightness(0.9); }
.fighter.hurt .sprite, .fighter.hurt .sprite-tint, .fighter.hurt .sprite-tint-grey { animation: none; }
.fighter.hurt { animation: shake 0.45s; }
@keyframes shake {
  20% { transform: translateX(calc(-50% - 18px)); } 40% { transform: translateX(calc(-50% + 16px)); }
  60% { transform: translateX(calc(-50% - 10px)); } 80% { transform: translateX(calc(-50% + 6px)); }
}
.fighter.dead > .sprite, .fighter.dead > .sprite-wrap { transition: transform 0.6s, opacity 0.6s, filter 0.6s; transform: rotate(-80deg) translateY(30%); opacity: 0.5; filter: grayscale(1); transform-origin: 50% 60%; }

.quiz { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5rem; }
.quiz.panel { padding: 0.2rem 0.6rem; }
.question { text-align: center; }
.q-hint { font-size: 0.95rem; color: var(--muted); display: flex; justify-content: center; align-items: center; gap: 0.4rem; }
.q-hint img { height: 1.1em; image-rendering: pixelated; }
.q-word { font-size: clamp(1.6rem, 3.4vw, 2.8rem); font-weight: 700; line-height: 1.15; margin: 0.15rem 0; -webkit-user-select: text; user-select: text; }
.answers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.answers .btn { font-size: clamp(1rem, 1.8vw, 1.35rem); min-height: 72px; line-height: 1.15; padding: 0.3rem 0.6rem; }
.answers .btn.right { border-image-source: url('/assets/ui/btn_good.png'); }
.answers .btn.wrong { border-image-source: url('/assets/ui/btn_attack.png'); color: #fff; }
.type-row { display: flex; gap: 0.6rem; justify-content: center; }
.type-row .input { flex: 1; max-width: 32rem; font-size: 1.5rem; text-align: center; }
.feedback { text-align: center; font-size: 1.25rem; min-height: 1.6em; }
.feedback.good { color: #3d6b12; }
.feedback.bad { color: var(--bad); }
.feedback .solution { color: var(--ink); font-weight: 700; }
.feedback .btn { margin-left: 0.6rem; }

/* Tastatur offen (iPad): Arena schrumpft, Frage + Eingabe bleiben sichtbar */
.kb-open .arena-wrap { flex-basis: 30%; }
.kb-open .mission-top .lesson-name { display: none; }

/* =============================================================================
   ERGEBNIS
   ============================================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in 0.3s;
}
@keyframes fade-in { from { opacity: 0; } }
/* Gemeinsame Basis aller Pop-ups: Innenabstand, damit Inhalt nicht am 20px-Holzrahmen
   klebt, und keine Browser-Standardabstände an Überschriften/Absätzen. */
.overlay > .panel { padding: 0.9rem 1.4rem 1.1rem; }
.overlay > .panel h1, .overlay > .panel h2, .overlay > .panel p { margin: 0; }
.overlay > .panel p { line-height: 1.35; }
.result-box { width: min(46rem, 80vw); max-height: 92%; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.6rem; animation: result-in 0.4s ease-out; }
@keyframes result-in { from { transform: scale(0.8); opacity: 0; } }
.result-box .title { font-size: 3rem; }
.result-box.lost .title { color: #ff8a6b; text-shadow: 0 3px 0 #5a1c14; }
.result-stats { color: var(--muted); }
.reward-lines { display: grid; grid-template-columns: auto auto; gap: 0.15rem 1.2rem; font-size: 1.15rem; margin: 0.3rem 0; }
.reward-lines .amt { text-align: right; font-weight: 700; }
.reward-total { font-size: 2rem; font-weight: 700; color: #7a4a1c; display: flex; align-items: center; gap: 0.4rem; }
.result-box .btn { margin-top: 0.3rem; }
/* „Zum Üben": zentrierte Wortkarten unter der Belohnung, scrollt bei vielen Wörtern */
.practice { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; min-height: 0; margin-top: 0.2rem; }
.practice-title {
  display: flex; align-items: center; gap: 0.6rem; width: 70%;
  font-size: 0.85rem; color: var(--muted); letter-spacing: 1px; text-transform: uppercase;
}
.practice-title::before, .practice-title::after { content: ''; flex: 1; border-top: 2px dashed rgba(92, 61, 26, 0.35); }
.practice-list { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; width: 100%; max-height: 9.5rem; overflow-y: auto; padding: 0 0.3rem; }
.practice-row {
  max-width: 95%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(92, 61, 26, 0.25);
  border-radius: 8px;
  padding: 0.2rem 0.9rem;
  font-size: 1rem;
  line-height: 1.3;
}
.practice-row .pr-en { font-weight: 700; color: #5c3d1a; }
.practice-row .pr-sep { color: var(--muted); margin: 0 0.4rem; }

/* Bestätigungsdialog (Flucht) */
.confirm-box { width: min(32rem, 70vw); text-align: center; display: flex; flex-direction: column; gap: 1rem; }
.confirm-box .row { display: flex; gap: 1rem; justify-content: center; margin-top: 0.3rem; }
.confirm-box .row .btn { flex: 1; white-space: nowrap; }
.overlay .error:empty { display: none; }

/* Freunde-Dialog */
.friends-box { width: min(40rem, 80vw); max-height: 92%; display: flex; flex-direction: column; gap: 0.7rem; text-align: center; }
.friends-box h2 + .friend-list { margin-top: -0.2rem; }
.overlay > .friends-box h2:not(:first-child) { margin-top: 0.6rem; }
.my-code { font-size: 2.4rem; font-weight: 700; letter-spacing: 4px; color: #5c3d1a; -webkit-user-select: all; user-select: all; }
.code-row { display: flex; gap: 0.6rem; justify-content: center; }
.code-row .input { width: 12rem; text-align: center; font-size: 1.5rem; letter-spacing: 3px; text-transform: uppercase; }
.friend-list { overflow-y: auto; display: flex; flex-direction: column; gap: 0.3rem; min-height: 0; text-align: left; }
.friend-row { display: flex; align-items: center; gap: 0.6rem; background: rgba(255,255,255,0.25); border-radius: 8px; padding: 0 0.6rem 0 0; }
.friend-row .thumb { width: 64px; height: 56px; overflow: hidden; display: flex; justify-content: center; align-items: flex-start; flex-shrink: 0; }
.friend-row .thumb > .sprite, .friend-row .thumb > .sprite-wrap { margin-top: -50px; }
.friend-row .fr-name { flex: 1; font-weight: 700; font-size: 1.1rem; }
.friend-row .fr-hero { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.friend-row .btn { min-height: 40px; font-size: 0.85rem; }

.toast {
  position: fixed;
  left: 50%; top: 1rem;
  transform: translateX(-50%);
  background: rgba(30, 20, 10, 0.85);
  color: #fff;
  padding: 0.5rem 1.2rem;
  border-radius: 10px;
  z-index: 60;
  animation: fade-in 0.2s;
}


/* =============================================================================
   HOCHFORMAT (Tablet/Handy). Layout ist spaltenweise gestapelt gebaut; hier die
   Anpassungen für schmale Hochformat-Fenster. Touch-Geräte im Querformat sehen
   stattdessen den Hinweis „Bitte drehen" (orientation.js).
   ============================================================================= */
.rotate-overlay {
  display: none; position: fixed; inset: 0; z-index: 2000;
  background: var(--bg); align-items: center; justify-content: center; text-align: center;
}
body.need-portrait .rotate-overlay { display: flex; }
.rotate-icon {
  display: block; width: 110px; height: 110px; margin: 0 auto 1.2rem;
  background: url('/assets/ui/icons/icon_phone.png') center / contain no-repeat; image-rendering: pixelated;
  animation: rotate-hint 2.6s ease-in-out infinite;
}
@keyframes rotate-hint { 0%, 25% { transform: rotate(90deg); } 65%, 100% { transform: rotate(0deg); } }
.rotate-text { color: var(--text); font-size: 1.6rem; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }

@media (orientation: portrait) {
  html { font-size: clamp(16px, 2.3vw, 21px); }

  /* Login */
  .login-screen { flex-direction: column; gap: 1rem; }
  .login-deco { display: none; }
  .login-box { width: min(30rem, 90vw); }

  /* Mission: Arena oben, Frage + Antworten groß darunter (Touch-freundlich, 1 Spalte) */
  .arena-wrap { flex-basis: 44%; }
  .q-word { font-size: clamp(2rem, 7vw, 3.4rem); }
  .q-hint { font-size: 1.05rem; }
  .answers { grid-template-columns: 1fr; gap: 0.8rem; }
  .answers .btn { min-height: 84px; font-size: clamp(1.15rem, 3.4vw, 1.6rem); }
  .type-row .input { min-width: 0; }
  .quiz { gap: 0.9rem; }

  /* Shop: Vorschau oben (Bühne links, Infos rechts), Liste darunter */
  .shop-board { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 36%) minmax(0, 1fr); }
  .shop-detail { order: -1; flex-direction: row; align-items: stretch; gap: 0.6rem; }
  .shop-detail .hero-stage { flex: 0 0 50%; width: auto; margin: -8px 0 -8px -8px; }
  .sd-info { flex: 1; min-width: 0; justify-content: center; }
  .sd-info h3 { margin-top: 0; }
}

/* Info-Block der Shop-Vorschau (Querformat: unter der Bühne, zentriert) */
.sd-info { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* Schmale Geräte (Handy) */
@media (orientation: portrait) and (max-width: 640px) {
  .topbar { flex-wrap: wrap; row-gap: 0.3rem; gap: 0.4rem; }
  .topbar .title { flex: 1 1 100%; font-size: 1.3rem; }
  #shop .topbar .title { flex: 1 1 auto; font-size: 1.2rem; }
  .topbar .spacer { display: none; }
  .topbar .btn { padding: 0 0.4rem; font-size: 0.85rem; }
  .coin-pill { font-size: 1.1rem; min-height: 40px; }
  .lesson-head { flex-wrap: wrap; gap: 0.4rem; }
  .lesson-head .btn { width: 100%; }
  .lesson-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shop-board { grid-template-rows: minmax(0, 40%) minmax(0, 1fr); }
  .mission-top .lesson-name { display: none; }
  .mission-top .btn { white-space: nowrap; }
  .arena-wrap { flex-basis: 36%; }
  .answers .btn { min-height: 64px; }
  .q-word { font-size: 1.8rem; }
  /* Namen/Leisten in der (stark verkleinerten) Arena besser lesbar */
  .fighter-name { font-size: 54px; }
  .hpbar { width: 340px; height: 34px; }
  .hptext { font-size: 24px; line-height: 26px; }
  /* Burg: kleinere Namen, damit sie sich nicht überlappen */
  .castle .fig-name { font-size: 0.6rem; }
  .castle .fig-label.me .fig-name { font-size: 0.95rem; }
  .castle .fig-label.me .fig-class { font-size: 0.65rem; top: 1.7rem; }
  .topbar .lbl { display: none; }
  .type-row { flex-direction: column; align-items: stretch; padding: 0 0.4rem; }
  .type-row .input { max-width: none; width: 100%; font-size: 1.3rem; }
  .type-row .btn { width: 100%; }
  /* Dialoge */
  .friends-box, .result-box, .confirm-box { width: 92vw; }
  .code-row { flex-wrap: wrap; }
  .code-row .input { flex: 1 1 8rem; width: auto; min-width: 8rem; }
  .friend-row .fr-hero { display: none; }
  .friend-row .btn { padding: 0 0.4rem; flex-shrink: 0; }
  .login-box .title { font-size: 1.8rem; }
}
