:root {
  color-scheme: dark;
  --bg: #0b0e1a;
  --panel: #141829;
  --panel2: #1b2036;
  --line: #262c48;
  --text: #e8eaf3;
  --muted: #8b90a8;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #f87171;
  --gold: #fbbf24;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: radial-gradient(1200px 600px at 20% -10%, #1d1a4a 0%, var(--bg) 60%) fixed;
  color: var(--text); font: 15px/1.5 var(--font); overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; }
code { font-family: var(--mono); font-size: 0.92em; background: #0b0e1a; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: #c4b5fd; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 10px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; transition: transform .08s, filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b3df5); border-color: transparent; color: #fff; box-shadow: 0 6px 18px -8px var(--accent); }
.btn.ghost { background: transparent; }
.btn.gold { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1a1200; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 17px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Header ---- */
#top {
  height: 64px; display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 24px;
  padding: 0 20px; background: rgba(20,24,41,.85); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
}
.logo { font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.logo span { background: linear-gradient(90deg, #c4b5fd, var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.xpwrap { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; max-width: 640px; }
.rank { font-weight: 700; white-space: nowrap; }
.xpbar { height: 12px; background: #0b0e1a; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.xpbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .6s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 12px var(--accent2); }
.xpnum { white-space: nowrap; font-size: 14px; }
.player { display: flex; align-items: center; gap: 10px; }
.badge { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 8px; font-weight: 600; }

/* ---- Layout ---- */
#app {
  display: grid; grid-template-columns: 250px minmax(480px, 1fr) minmax(380px, 0.85fr);
  height: calc(100% - 64px); gap: 14px; padding: 14px;
}
#missions, #work, #preview { min-height: 0; }
#missions { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow: auto; }
#missions h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#mission-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#mission-list li {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center;
  padding: 9px 10px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; transition: background .15s;
}
#mission-list li:hover { background: var(--panel2); }
#mission-list li.active { background: var(--panel2); border-color: var(--accent); }
#mission-list li.locked { opacity: .5; cursor: not-allowed; }
#mission-list li .t { font-weight: 600; font-size: 14px; line-height: 1.25; }
#mission-list li .t small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
#mission-list li .st { font-size: 15px; }
#mission-list li.bonus { margin-top: 8px; border-top: 1px dashed var(--line); border-radius: 0 0 10px 10px; padding-top: 14px; }

#work { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.mission-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.mission-head h1 { margin: 0; font-size: 21px; }
.xp-pill { background: #2a1f5c; color: #c4b5fd; border: 1px solid #4c3a9c; border-radius: 999px; padding: 3px 10px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.intro { margin: 10px 0 12px; }
.hintbox { background: #2a2211; border: 1px solid #6b4e0c; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; animation: pop .25s ease; }
.hintbox .n { color: var(--warn); font-weight: 700; margin-right: 6px; }
.confirm { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; cursor: pointer; }
.confirm input { margin-top: 3px; }
.mission-actions { display: flex; gap: 8px; align-items: center; }
.mission-actions .primary { margin-left: auto; }
.result { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; animation: pop .25s ease; }
.result.bad { background: #3b1111; border: 1px solid #7f1d1d; }
.result.good { background: #0f2e1d; border: 1px solid #166534; }

.editorwrap { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: relative; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; border: 1px solid transparent; border-bottom: 0; color: var(--muted); padding: 7px 14px; border-radius: 8px 8px 0 0; cursor: pointer; font-weight: 600; font-family: var(--mono); font-size: 13px; }
.tabs button.active { background: #282a36; color: #fff; border-color: var(--line); }
#editor { flex: 1; min-height: 0; }
.CodeMirror { height: 100%; font-family: var(--mono); font-size: 14px; line-height: 1.55; }
.savestate { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--muted); background: rgba(11,14,26,.8); padding: 2px 8px; border-radius: 6px; pointer-events: none; }
.savestate.dirty { color: var(--warn); }

#preview { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
#frame { flex: 1; width: 100%; border: 0; background: #fff; }
.console { height: 96px; overflow: auto; border-top: 1px solid var(--line); background: #0b0e1a; padding: 6px 10px; font: 12px/1.5 var(--mono); }
.console .err { color: var(--err); }
.console .log { color: #a5f3fc; }
.console .err b { color: #fecaca; }

/* ---- Coach ---- */
.coach-toggle {
  position: fixed; right: 22px; bottom: 22px; z-index: 50; border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent2), #0ea5e9); color: #04121a; cursor: pointer; box-shadow: 0 10px 30px -8px var(--accent2);
  animation: float 3s ease-in-out infinite;
}
.coach { position: fixed; right: 22px; bottom: 22px; width: 380px; max-height: 70vh; z-index: 60; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 60px -20px #000; overflow: hidden; animation: pop .2s ease; }
.coach-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 700; }
.coach-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 160px; }
.msg { padding: 8px 12px; border-radius: 12px; max-width: 88%; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: #1e2a4a; }
.msg.assistant { align-self: flex-start; background: #1f1a3d; }
.msg.info { align-self: center; color: var(--muted); font-size: 13px; text-align: center; }
.msg.typing::after { content: "…"; animation: blink 1s steps(3) infinite; }
.coach-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.coach-form textarea { flex: 1; resize: none; border-radius: 10px; border: 1px solid var(--line); background: #0b0e1a; color: var(--text); padding: 8px 10px; font: 14px var(--font); }
.coach-offline { padding: 12px 14px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); background: #1a1d2e; }

/* ---- Modals ---- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(5,7,15,.78); display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(4px); }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 30px; width: 100%; max-width: 520px; box-shadow: 0 30px 80px -30px #000; animation: pop .25s ease; }
.modal-box.wide { max-width: 900px; }
.modal-box.center { text-align: center; }
.modal-box h1 { margin: 0 0 10px; font-size: 26px; }
.modal-box label { display: block; font-weight: 600; margin: 14px 0 6px; }
.modal-box input[type=text] { display: block; width: 100%; margin-top: 6px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: #0b0e1a; color: #fff; font-size: 16px; }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 8px 0 12px; }
.avatars button { font-size: 24px; background: var(--panel2); border: 2px solid transparent; border-radius: 10px; padding: 6px 0; cursor: pointer; }
.avatars button.active { border-color: var(--accent2); background: #0f2a3a; }
.error { color: var(--err); font-weight: 600; }
.bigemoji { font-size: 64px; animation: bounce .8s ease; }
.xp-gain { font-size: 34px; font-weight: 800; color: var(--gold); margin: 6px 0; }

/* ---- Urkunde ---- */
.urkunde-controls { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.urkunde-controls label { flex: 1; margin: 0; }
.urkunde { background: #fff; color: #1a1a2e; padding: 24px; border-radius: 10px; }
.u-frame { border: 6px double #5b3df5; padding: 36px 40px; text-align: center; font-family: Georgia, "Times New Roman", serif; }
.u-top { font: 800 18px/1 var(--font); letter-spacing: .3em; color: #5b3df5; }
.u-sub { font-size: 44px; font-weight: 700; margin: 10px 0 18px; }
.u-text { font-size: 17px; margin: 6px 0; }
.u-name { font-size: 34px; font-weight: 700; margin: 14px 0; border-bottom: 2px solid #1a1a2e; display: inline-block; padding: 0 24px 4px; min-width: 50%; }
.u-rank { font-size: 28px; font-weight: 700; color: #5b3df5; margin: 10px 0; }
.u-date { margin-top: 22px; color: #555; }
.u-tips { margin-top: 26px; font: 13px/1.6 var(--font); color: #444; border-top: 1px solid #ddd; padding-top: 12px; }
.u-tips b { display: block; }

@media print {
  body * { visibility: hidden; }
  #urkunde, #urkunde * { visibility: visible; }
  #urkunde { position: fixed; inset: 0; background: #fff; padding: 0; display: block; }
  .modal-box { border: 0; box-shadow: none; max-width: none; padding: 0; background: #fff; }
  .urkunde-controls { display: none !important; }
  .urkunde { border-radius: 0; padding: 40px; }
}

@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bounce { 0% { transform: scale(.4); } 60% { transform: scale(1.2); } 100% { transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes blink { to { visibility: hidden; } }

/* ---- Icons (Lucide) ---- */
.lucide { width: 1.15em; height: 1.15em; vertical-align: -0.22em; flex: none; }
.btn .lucide { margin-right: 2px; }
.logo .lucide { width: 1.2em; height: 1.2em; color: var(--accent2); }
.rank .lucide { color: var(--accent2); }
#mission-list li .em { display: flex; align-items: center; justify-content: center; color: #c4b5fd; }
#mission-list li .st .lucide { color: var(--muted); }
#mission-list li .st .lucide.ok { color: var(--ok); }
#mission-list li.active .st .lucide { color: var(--accent2); }
.mission-head h1 .lucide { color: var(--accent2); }
.bigicon { display: flex; justify-content: center; margin-bottom: 8px; }
.bigicon .lucide { width: 72px; height: 72px; color: var(--gold); animation: bounce .8s ease; }
.result { display: flex; gap: 10px; align-items: flex-start; }
.result > .lucide { margin-top: 2px; }
.result.good > .lucide { color: var(--ok); }
.result.bad > .lucide { color: var(--warn); }
.console .err .lucide { color: var(--err); }
.pill { background: #2a1f5c; color: #c4b5fd; border: 1px solid #4c3a9c; border-radius: 999px; padding: 1px 8px; font-size: 11px; margin-left: 6px; vertical-align: 1px; }
.u-top .lucide, .u-rank .lucide { color: #5b3df5; }
.u-rank .lucide { width: 1em; height: 1em; }
.xpwrap .rank { display: flex; align-items: center; gap: 6px; }

/* ---- Lektion ---- */
.section-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; }
.section-head .lucide { color: var(--accent2); }
.section-head.small { margin: 12px 0 6px; }
.section-head.task { margin-top: 16px; }
.section-head button { text-transform: none; letter-spacing: 0; }
.lesson { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 12px; margin-top: 12px; }
.lesson.collapsed { padding-bottom: 4px; }
.lesson .section-head { margin-top: 8px; }
.lesson-text p { margin: 0 0 10px; font-size: 14.5px; }
.lesson-text p:last-child { margin-bottom: 0; }
.example { margin-top: 10px; }
.ex-file + .ex-file { margin-top: 8px; }
.ex-label { font: 11px var(--mono); color: var(--muted); margin-bottom: 3px; }
.example pre { margin: 0; background: #282a36; color: #f8f8f2; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 13px/1.5 var(--mono); white-space: pre-wrap; max-height: 220px; overflow: auto; }
#lesson-done { margin-top: 12px; }
#work { overflow: auto; }
.editorwrap { min-height: 320px; }
