:root {
  --ink: #1f2a4d;
  --paper: rgba(245, 250, 255, .94);
  --accent: #3f7be6;
  --accent2: #8a63e0;
  --gold: #ffd166;
  --ok: #34b38a;
  --ice: #bff0ff;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: var(--font); color: var(--ink); background: #0b1640; -webkit-tap-highlight-color: transparent; }

/* ---------- 3D-Szene ---------- */
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#door-buttons { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.door-btn {
  position: absolute; left: 0; top: 0; padding: 0; border: 0; background: transparent;
  border-radius: 45% 45% 10px 10px; cursor: pointer; pointer-events: auto;
}
.door-btn:hover { box-shadow: 0 0 24px 4px rgba(170, 235, 255, .45); }
.door-btn:focus-visible { outline: 3px solid var(--ice); outline-offset: 3px; }
.edit-mode .door-btn { pointer-events: none; }

#loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 40%, #2a4a9a, #0b1640 70%);
  color: #e6f6ff; font-size: clamp(18px, 3vmin, 26px); letter-spacing: .02em;
  transition: opacity .8s; text-shadow: 0 0 18px rgba(150, 220, 255, .8);
}
#loader.done { opacity: 0; pointer-events: none; }

.hud {
  position: fixed; z-index: 10; top: max(12px, env(safe-area-inset-top)); left: 16px;
  color: #fff; pointer-events: none;
  text-shadow: 0 0 18px rgba(120, 200, 255, .7), 0 2px 6px rgba(10, 20, 60, .6);
}
.hud h1 { margin: 0; font-size: clamp(24px, 4.4vmin, 44px); font-weight: 700; letter-spacing: .01em; }
.hud p { margin: 2px 0 0; font-size: clamp(13px, 2vmin, 17px); opacity: .92; }
.hud .hint { font-size: 12px; opacity: .7; }

.walk-nav {
  position: fixed; z-index: 10; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; gap: 14px;
}
.nav-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 2px solid rgba(190, 235, 255, .9);
  background: rgba(245, 250, 255, .85); color: var(--accent); font-size: 20px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(40, 90, 200, .35); backdrop-filter: blur(6px);
}
.nav-btn:active { transform: scale(.94); }
.nav-btn:focus-visible { outline: 3px solid var(--ice); outline-offset: 3px; }
.edit-mode .walk-nav { display: none; }

#toast {
  position: fixed; z-index: 20; left: 50%; bottom: max(86px, calc(env(safe-area-inset-bottom) + 70px));
  max-width: calc(100vw - 32px); padding: 12px 20px; border-radius: 999px;
  background: var(--paper); box-shadow: 0 8px 30px rgba(60, 140, 255, .35);
  text-align: center; opacity: 0; transform: translate(-50%, 20px);
  transition: opacity .3s, transform .3s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 999px; padding: 10px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(80, 120, 230, .4);
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-small { padding: 6px 12px; font-size: 13px; }

.devbar {
  position: fixed; z-index: 30; right: 12px; top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  max-width: calc(100vw - 24px); padding: 8px 12px; border-radius: 14px;
  background: rgba(20, 25, 60, .8); color: #fff; font-size: 13px;
}
.devbar input { font: inherit; border-radius: 8px; border: 0; padding: 4px 6px; }

/* ---------- Modal ---------- */
dialog {
  border: 0; padding: 0; background: transparent; color: inherit;
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgba(8, 20, 60, .5); backdrop-filter: blur(4px); }
dialog[open] .modal-card { animation: pop .35s cubic-bezier(.3, 1.4, .5, 1); }
.modal-card {
  position: relative; background: var(--paper); border-radius: 26px; padding: 28px 24px 24px;
  max-height: calc(100dvh - 32px); overflow: auto;
  border: 2px solid rgba(190, 235, 255, .9);
  box-shadow: 0 0 0 6px rgba(150, 215, 255, .18), 0 20px 60px rgba(10, 30, 90, .5), inset 0 0 40px rgba(170, 225, 255, .35);
  backdrop-filter: blur(10px);
}
.modal-close {
  position: absolute; right: 12px; top: 12px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: #e3f1ff; font-size: 18px; cursor: pointer; color: var(--ink);
}
.modal-kicker { margin: 0; color: var(--accent); font-weight: 600; font-size: 14px; }
#modal-title { margin: 4px 48px 16px 0; font-size: clamp(22px, 5vw, 30px); line-height: 1.15; }
#modal-body p { line-height: 1.55; }
.muted { color: #7a7f99; }

.quiz-q { border: 0; padding: 0; margin: 0 0 20px; }
.quiz-q legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.quiz-option {
  display: block; width: 100%; margin: 6px 0; padding: 12px 14px; text-align: left;
  font: inherit; color: inherit; background: #fff; border: 2px solid #e3e7f5; border-radius: 14px; cursor: pointer;
}
.quiz-option:hover:not(:disabled) { border-color: #8ea2e8; }
.quiz-option:disabled { cursor: default; }
.quiz-option.is-right { background: #e1f5e5; border-color: var(--ok); }
.quiz-option.is-wrong { background: #fde3df; border-color: var(--accent); }
.quiz-feedback { margin: 6px 0 0; min-height: 1em; }
.quiz-score { font-weight: 700; font-size: 18px; }

.video-frame { aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000; }
.video-frame iframe { width: 100%; height: 100%; border: 0; }
.video-file { width: 100%; border-radius: 14px; background: #000; }
.lesson-text { white-space: pre-line; }
figure { margin: 16px 0; }
figure img { max-width: 100%; border-radius: 14px; display: block; }
figcaption { font-size: 14px; color: #7a7f99; margin-top: 6px; }
.mixed-part + .mixed-part { border-top: 2px dashed #cfe3f7; margin-top: 16px; padding-top: 8px; }

.chat-log { max-height: 320px; overflow: auto; display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.chat-msg { margin: 0; padding: 10px 14px; border-radius: 16px; max-width: 85%; background: #e9f2fb; }
.chat-user { align-self: flex-end; background: #dbe5ff; }
.chat-system { align-self: center; background: none; color: #7a7f99; font-size: 14px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; font: inherit; padding: 10px 14px; border-radius: 999px; border: 2px solid #e3e7f5; }

/* ---------- Editor ---------- */
.editor {
  position: fixed; z-index: 30; right: 12px; bottom: 12px;
  width: min(380px, calc(100vw - 24px)); padding: 14px; border-radius: 18px;
  background: rgba(255, 253, 248, .96); box-shadow: 0 10px 30px rgba(20, 25, 60, .35);
}
.editor summary { font-weight: 700; font-size: 18px; cursor: pointer; }
.editor:not([open]) { width: auto; }
.editor p { margin: 6px 0; font-size: 13px; }
.editor textarea { display: block; width: 100%; height: 28dvh; margin-bottom: 8px; font: 12px/1.4 ui-monospace, Menlo, monospace; border-radius: 10px; border: 1px solid #ddd; padding: 8px; resize: none; }

/* ---------- Animationen ---------- */
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 600px) {
  .devbar { top: auto; bottom: 82px; right: 12px; left: 12px; }
}

/* Mission prüfen */
.mission-check { margin-top: 8px; padding: 16px; border-radius: 12px; background: rgba(120, 160, 255, .08); }
.mission-msg { margin: 10px 0 0; font-weight: 600; }
.mission-msg.is-done { color: #1f8a4c; }
.mission-msg.is-todo { color: #b45309; }
