/* ===== Ninja Mathe – iPad-optimiert ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg-dark: #141b33;
  --panel: rgba(20, 27, 51, 0.82);
  --panel-light: rgba(255, 255, 255, 0.08);
  --red: #e63946;
  --gold: #ffc93c;
  --green: #4ade80;
  --text: #f4f6fb;
  --text-dim: #9aa5c4;
  --radius: 22px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "SF Pro Rounded", "Arial Rounded MT Bold", "Helvetica Neue", sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  width: 100vw;
  background: url("assets/dojo_bg.jpg") center/cover no-repeat fixed;
  position: relative;
}

#app::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(10, 14, 30, 0.35);
  pointer-events: none;
}

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: max(env(safe-area-inset-top), 16px) max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 16px) max(env(safe-area-inset-left), 20px);
  z-index: 1;
}
.screen.active { display: flex; }

/* ===== Startbildschirm ===== */
.home-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  height: 100%;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}
.home-left { flex: 0 0 32%; display: flex; justify-content: center; }
.hero-img {
  width: 100%;
  max-width: 300px;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.5));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-12px);} }

.home-right { flex: 1; max-width: 520px; display: flex; flex-direction: column; gap: 16px; }

.app-title {
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.app-title span { color: var(--red); }
.app-subtitle { color: var(--text-dim); font-size: 1.1rem; margin-top: -10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.wallet { display: flex; align-items: center; gap: 14px; padding: 14px 18px; }
.coin-icon { width: 56px; height: 56px; }
.wallet-amount { font-size: 1.5rem; font-weight: 800; color: var(--gold); }
.wallet-sub { color: var(--text-dim); font-size: 0.9rem; }

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mode-btn {
  padding: 20px 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--panel-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.mode-btn:active { transform: scale(0.95); border-color: var(--red); }
.mode-btn.wide { grid-column: 1 / -1; background: linear-gradient(135deg, #b5212e, #e63946); border-color: rgba(255,255,255,0.25); }

.minigame-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 16px;
  font-size: 1.15rem; font-weight: 800;
  color: var(--bg-dark);
  background: linear-gradient(135deg, #ffd76a, #ffc93c);
  border: none; border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.minigame-btn:active { transform: scale(0.96); }
.minigame-btn.locked { filter: grayscale(0.9); opacity: 0.55; }
.btn-shuriken { width: 32px; height: 32px; }
.minigame-hint { text-align: center; color: var(--text-dim); font-size: 0.95rem; }

/* ===== Training ===== */
.train-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
}
.icon-btn {
  width: 56px; height: 56px;
  font-size: 1.6rem; font-weight: 800;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }

.streak-bar { display: flex; gap: 8px; flex: 1; justify-content: center; }
.streak-slot {
  width: clamp(28px, 4.5vw, 44px);
  height: clamp(28px, 4.5vw, 44px);
  border-radius: 50%;
  background: rgba(255,255,255,0.10);
  border: 2px dashed rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
}
.streak-slot img { width: 82%; height: 82%; opacity: 0; transform: scale(0.2) rotate(-180deg); transition: all 0.35s cubic-bezier(0.34,1.56,0.64,1); }
.streak-slot.filled { border-style: solid; border-color: var(--gold); background: rgba(255,201,60,0.15); }
.streak-slot.filled img { opacity: 1; transform: scale(1) rotate(0deg); }

.coin-mini { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.3rem; color: var(--gold); }
.coin-mini img { width: 40px; height: 40px; }

.timer-wrap { padding: 4px 0 12px; }
.timer-track {
  height: 16px;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4ade80, #facc15, #e63946);
  border-radius: 10px;
  transform-origin: left;
}

.scroll-card {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-align: center;
  padding: clamp(12px, 2.5vh, 28px);
  margin-bottom: 14px;
}
.scroll-card.correct { animation: pulseGreen 0.5s ease; }
.scroll-card.wrong { animation: shake 0.5s ease; }
@keyframes pulseGreen { 0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.7);} 100% { box-shadow: 0 0 0 24px rgba(74,222,128,0);} }
@keyframes shake { 0%,100% { transform: translateX(0);} 20%,60% { transform: translateX(-10px);} 40%,80% { transform: translateX(10px);} }

.task-text {
  font-size: clamp(3rem, 9vw, 5rem);
  font-weight: 900;
  letter-spacing: 2px;
}
.answer-display {
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  font-weight: 800;
  color: var(--gold);
  min-height: 1.2em;
  border-bottom: 4px solid rgba(255,255,255,0.25);
  display: inline-block;
  min-width: 140px;
  padding: 0 16px;
}
.feedback { min-height: 1.6em; font-size: 1.2rem; font-weight: 700; margin-top: 6px; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  flex: 1;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 6px;
}
.key {
  font-size: clamp(1.8rem, 4.5vh, 2.6rem);
  font-weight: 800;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--panel-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.08s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 60px;
}
.key:active { transform: scale(0.93); background: rgba(255,255,255,0.18); }
.key-del { color: var(--red); }
.key-ok { background: linear-gradient(135deg, #15803d, #4ade80); border-color: rgba(255,255,255,0.3); color: #06230f; }

/* ===== Overlays ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(8, 11, 24, 0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.reward-box {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 28px;
  padding: 36px 44px;
  text-align: center;
  max-width: 480px;
  width: 90%;
  animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes popIn { from { transform: scale(0.6); opacity: 0;} to { transform: scale(1); opacity: 1;} }
.reward-coin { width: 130px; height: 130px; object-fit: contain; margin-bottom: 12px; animation: coinPop 0.8s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes coinPop { 0% { transform: scale(0) rotate(-360deg);} 100% { transform: scale(1) rotate(0);} }
.reward-coin.spin { animation: spinIn 0.8s ease; }
@keyframes spinIn { from { transform: rotate(-540deg) scale(0);} to { transform: rotate(0) scale(1);} }
.reward-box h2 { font-size: 1.8rem; margin-bottom: 8px; }
.reward-box p { color: var(--text-dim); font-size: 1.15rem; margin-bottom: 22px; }
.reward-box p strong { color: var(--gold); }

.big-btn {
  padding: 18px 34px;
  font-size: 1.25rem; font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #b5212e, #e63946);
  border: none; border-radius: 18px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.big-btn:active { transform: scale(0.94); }
.big-btn.secondary { background: var(--panel); border: 2px solid var(--panel-light); color: var(--text-dim); }
.unlock-btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ===== Minispiel ===== */
.mg-info { font-size: 1.4rem; font-weight: 800; color: var(--gold); }
.mg-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow: hidden;
}
.mg-target {
  position: absolute;
  width: 110px; height: 110px;
  cursor: pointer;
  animation: targetPop 0.3s cubic-bezier(0.34,1.56,0.64,1);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.mg-target img { width: 100%; height: 100%; pointer-events: none; }
@keyframes targetPop { from { transform: scale(0);} to { transform: scale(1);} }
.mg-target.hit { transform: scale(0); opacity: 0; }
.mg-shuriken-fly {
  position: absolute;
  width: 60px; height: 60px;
  pointer-events: none;
  z-index: 5;
  animation: flySpin 0.25s linear;
}
@keyframes flySpin { from { transform: scale(1.6) rotate(0);} to { transform: scale(1) rotate(360deg);} }

/* Confetti coins */
.coin-fly {
  position: fixed;
  width: 44px; height: 44px;
  pointer-events: none;
  z-index: 100;
}

/* ===== Gürtel-System ===== */
.belt-card { padding: 14px 18px; }
.belt-row { display: flex; align-items: center; gap: 14px; }
.belt-badge {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: #f4f6fb;
  border: 4px solid rgba(255,255,255,0.25);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
}
.belt-badge::after {
  content: "";
  position: absolute; left: -6px; right: -6px; top: 50%;
  height: 12px; transform: translateY(-50%);
  background: inherit;
  filter: brightness(0.85);
  border-radius: 6px;
}
.belt-badge.huge { width: 110px; height: 110px; margin: 0 auto 14px; }
.belt-badge.huge::after { height: 24px; left: -12px; right: -12px; border-radius: 12px; }
.belt-info { flex: 1; }
.belt-name { font-weight: 800; font-size: 1.15rem; }
.belt-track { height: 10px; background: rgba(255,255,255,0.12); border-radius: 6px; overflow: hidden; margin: 6px 0 4px; }
.belt-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ffc93c, #ffd76a); border-radius: 6px; transition: width 0.6s ease; }
.belt-hint { color: var(--text-dim); font-size: 0.85rem; }

/* ===== Minispiel-Auswahl ===== */
.game-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  justify-items: center;
  margin-bottom: 18px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
}
.choice-btn {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 22px;
  background: rgba(255,255,255,0.07);
  border: 2px solid var(--panel-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem; font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  min-width: 170px;
}
.choice-btn:active { transform: scale(0.94); border-color: var(--gold); }
.choice-btn img { width: 76px; height: 76px; object-fit: contain; }

/* ===== Ninja-Sprung ===== */
.run-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow: hidden;
}
.run-ground {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 46px;
  background: linear-gradient(180deg, #3d2f22, #2a2018);
  border-top: 3px solid #5d4a37;
}
#run-ninja {
  position: absolute;
  left: 10%;
  bottom: 46px;
  width: 110px; height: 110px;
  z-index: 3;
  will-change: transform;
}
.run-obstacle {
  position: absolute;
  bottom: 46px;
  width: 74px; height: 74px;
  z-index: 2;
  will-change: transform;
}
.run-obstacle img { width: 100%; height: 100%; }
.run-tap-hint {
  position: absolute;
  top: 30%; left: 50%; transform: translateX(-50%);
  font-size: 1.4rem; font-weight: 800;
  color: var(--text-dim);
  animation: bob 1.5s ease-in-out infinite;
  pointer-events: none;
}

/* Hochformat-Anpassung */
@media (orientation: portrait) {
  .home-layout { flex-direction: column; gap: 12px; }
  .home-left { flex: 0 0 auto; }
  .hero-img { max-width: 180px; }
  .home-right { max-width: 560px; width: 100%; }
}

/* ===== Minispiel 3: Frucht-Schnitt ===== */
.fruit-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow: hidden;
}
#fruit-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ===== Minispiel 4: Shuriken-Weitwurf ===== */
.throw-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow: hidden;
}
#throw-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ===== Minispiel 5: Rauchbomben-Ausweichen ===== */
.dodge-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow: hidden;
}
#dodge-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ===== Minispiel 6: Schriftrollen-Memory ===== */
.memory-arena {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  padding: 12px;
  align-content: center;
  perspective: 800px;
  overflow-y: auto;
}
.card {
  position: relative;
  aspect-ratio: 3 / 4;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  touch-action: manipulation;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.card.flipped .card-inner {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-back {
  background: linear-gradient(135deg, #5d4a37, #3d2f22);
  border: 2px solid #8a6a3a;
}
.card-front {
  background: var(--panel);
  border: 2px solid var(--panel-light);
  transform: rotateY(180deg);
}
.card-front svg, .card-back svg { width: 70%; height: 70%; }
.card-math { font-size: clamp(1.4rem, 4vw, 2.4rem); font-weight: 800; color: var(--gold); }
.card.matched .card-front { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.card:active .card-inner { transform: scale(0.97); }
.card.flipped:active .card-inner { transform: rotateY(180deg) scale(0.97); }
.card.matched { pointer-events: none; }
.card.flipped { pointer-events: none; }

/* ===== Minispiel 7: Zahlen-Dojo ===== */
.dojo-arena {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-light);
  overflow-y: auto;
}
.dojo-tile {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid var(--gold);
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.dojo-tile:active { transform: scale(0.94); border-color: var(--red); }
.dojo-tile.done { opacity: 0.25; pointer-events: none; }
.dojo-tile.shake { animation: shake 0.4s ease; }

/* ===== Ausrüstung ===== */
.equip-card { padding: 14px 18px; cursor: pointer; transition: transform 0.12s ease; }
.equip-card:active { transform: scale(0.97); }
.equip-card .equip-row { display: flex; align-items: center; gap: 14px; }
.equip-icon { font-size: 1.8rem; }
.equip-title { font-weight: 800; font-size: 1.1rem; }
.equip-summary { color: var(--text-dim); font-size: 0.9rem; }
.equip-box { max-width: 420px; max-height: 80vh; overflow-y: auto; }
.equip-section { margin-bottom: 18px; }
.equip-section h3 { font-size: 1.1rem; margin-bottom: 10px; color: var(--gold); }
.equip-options { display: flex; gap: 12px; flex-wrap: wrap; }
.equip-opt {
  width: 64px; height: 64px; border-radius: 12px;
  border: 2px solid var(--panel-light); background: rgba(255,255,255,0.07);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s ease, border-color 0.1s ease;
  touch-action: manipulation;
}
.equip-opt:active { transform: scale(0.92); }
.equip-opt.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.equip-opt.locked { opacity: 0.35; cursor: default; }
.equip-opt.locked:active { transform: none; }
.unlock-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--gold);
  color: var(--text); padding: 14px 24px; border-radius: 18px;
  font-weight: 800; font-size: 1.1rem; z-index: 100;
  animation: toastIn 0.3s ease;
}
.unlock-toast.hidden { display: none; }
@keyframes toastIn { from { transform: translate(-50%, -40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#hero-canvas { width: 100%; max-width: 300px; height: auto; }
