:root {
  --bg: #f4f3ff;
  --card: #ffffff;
  --text: #1e1b4b;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --c-neu: #9ca3af;
  --c-ueben: #ec4647;
  --c-gut: #f2a600;
  --c-sehr_gut: #00b894;
  --c-ausgezeichnet: #6a4ce2;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(30, 27, 75, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.8rem; margin: .2em 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; color: var(--primary-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }
.row { display: flex; align-items: center; gap: .6rem; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-top { margin-top: .8rem; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .8rem; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1rem;
  background: var(--primary); color: #fff;
  box-shadow: var(--shadow);
}
.brand { background: none; border: 0; color: #fff; font-weight: 700; font-size: 1.15rem; cursor: pointer; padding: .2rem; }
.topbar-actions { display: flex; gap: .4rem; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }
main { max-width: 760px; margin: 0 auto; padding: 1rem 16px 3rem; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}

/* ---------- Buttons & Inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 2px solid var(--line); background: #fff; border-radius: 12px;
  padding: .6rem 1rem; cursor: pointer; font-weight: 600; text-decoration: none;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .7rem; font-size: .875rem; }
.btn.big { padding: .9rem 1.4rem; font-size: 1.15rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=password], input[type=text], input[type=search], input[type=number], select, textarea {
  border: 2px solid var(--line); border-radius: 12px; padding: .6rem .8rem; background: #fff; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { width: 100%; resize: vertical; margin: .6rem 0; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
input.num { width: 5.5rem; }
label { display: inline-flex; align-items: center; gap: .4rem; }

/* Segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: .4rem; }
.seg button {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: .5rem 1rem; cursor: pointer; font-weight: 600;
}
.seg.small button { padding: .3rem .75rem; font-size: .875rem; }
.seg button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 12px;
  padding: .5rem .8rem; cursor: pointer; text-align: left;
}
.chip b { display: block; }
.chip small { color: var(--muted); }
.chip.active { border-color: var(--primary); background: var(--primary-soft); }
.chip:disabled { opacity: .45; cursor: not-allowed; }

/* Rätselart */
.puzzles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.puzzles button {
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: .8rem .4rem; cursor: pointer;
}
.puzzles button span { font-size: 1.8rem; }
.puzzles button small { color: var(--muted); font-size: .75rem; text-align: center; }
.puzzles button.active { border-color: var(--primary); background: var(--primary-soft); }

/* Karteikasten */
.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.box {
  border: 0; border-radius: 14px; padding: .7rem .3rem; cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.12);
}
.box .n { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.box .l { font-size: .78rem; font-weight: 600; text-align: center; }
.box.active { outline: 3px solid var(--text); outline-offset: 2px; }
.bg-neu { background: var(--c-neu); }
.bg-ueben { background: var(--c-ueben); }
.bg-gut { background: var(--c-gut); }
.bg-sehr_gut { background: var(--c-sehr_gut); }
.bg-ausgezeichnet { background: var(--c-ausgezeichnet); }
.stackbar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin-top: .8rem; background: var(--line); }
.stackbar div { height: 100%; transition: width .3s; }
.badge { display: inline-block; color: #fff; border-radius: 99px; padding: .1rem .55rem; font-size: .75rem; font-weight: 600; white-space: nowrap; }

/* ---------- Login ---------- */
.login-card { max-width: 380px; margin: 12vh auto 0; text-align: center; padding: 2rem 1.5rem; }
.login-emoji { font-size: 3.5rem; }
.login-card form { display: flex; flex-direction: column; gap: .7rem; margin-top: 1.2rem; }
.login-card input { text-align: center; font-size: 1.1rem; }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; align-items: center; gap: .7rem; margin-bottom: 1rem; }
.progress { flex: 1; height: 12px; background: #fff; border-radius: 99px; overflow: hidden; box-shadow: var(--shadow); }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #a855f7); transition: width .3s; }
.quiz-count { font-weight: 700; min-width: 3.5rem; text-align: right; }
.quiz-card { text-align: center; padding: 1.6rem 1.2rem; min-height: 380px; display: flex; flex-direction: column; gap: 1rem; }
.q-label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.q-word { font-size: 2.1rem; font-weight: 800; word-break: break-word; display: flex; justify-content: center; align-items: center; gap: .5rem; flex-wrap: wrap; }
.q-meta { display: flex; justify-content: center; gap: .4rem; }
.speak-btn {
  border: 0; background: var(--primary-soft); color: var(--primary); border-radius: 50%;
  width: 2.8rem; height: 2.8rem; font-size: 1.3rem; cursor: pointer; flex-shrink: 0;
}
.speak-btn.huge { width: 7rem; height: 7rem; font-size: 3rem; box-shadow: var(--shadow); }
.speak-btn.mid { width: 3.6rem; height: 3.6rem; font-size: 1.6rem; }
.speak-row { display: flex; justify-content: center; align-items: center; gap: 1rem; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.option {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 1rem .6rem;
  font-size: 1.1rem; font-weight: 600; cursor: pointer; min-height: 4rem; word-break: break-word;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.correct { background: var(--ok-soft); border-color: var(--ok); color: #14532d; }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); color: #7f1d1d; }
.option:disabled { cursor: default; }
.answer-input { font-size: 1.4rem; text-align: center; width: 100%; padding: .8rem; }
.answer-input.correct { border-color: var(--ok); background: var(--ok-soft); }
.answer-input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { border-radius: 14px; padding: .9rem; font-size: 1.05rem; }
.feedback.ok { background: var(--ok-soft); color: #14532d; }
.feedback.bad { background: var(--bad-soft); color: #7f1d1d; }
.feedback .solution { font-size: 1.4rem; font-weight: 800; display: block; margin-top: .2rem; }
.heard { color: var(--muted); font-style: italic; min-height: 1.4em; }
.mic-btn {
  border: 0; border-radius: 999px; padding: 1rem 2rem; font-size: 1.2rem; font-weight: 700; cursor: pointer;
  background: var(--ok); color: #fff; box-shadow: var(--shadow);
}
.mic-btn.listening { background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.quiz-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: auto; }
.pop { animation: pop .3s; }
@keyframes pop { 0% { transform: scale(.9); opacity: .4; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Ergebnis ---------- */
.result-emoji { font-size: 4rem; }
.result-score { font-size: 1.3rem; font-weight: 700; }
.wordlist { list-style: none; padding: 0; margin: 0; }
.wordlist li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.wordlist li:last-child { border-bottom: 0; }
.move { font-size: .9rem; margin: .2rem 0; }

/* ---------- Verwaltung ---------- */
.table-wrap { overflow-x: auto; margin-top: .6rem; }
.vtable { width: 100%; border-collapse: collapse; font-size: .92rem; }
.vtable th, .vtable td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.vtable th { font-size: .78rem; color: var(--muted); text-transform: uppercase; }
.vtable td.actions { white-space: nowrap; text-align: right; }
.vtable input { padding: .3rem .5rem; width: 100%; min-width: 6rem; border-radius: 8px; }
.vtable input.num { width: 4rem; min-width: 0; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 1rem; padding: .25rem; border-radius: 6px; }
.icon-btn:hover { background: var(--primary-soft); }

/* ---------- Schulbuch-Import ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center;
  border: 2px dashed var(--line); border-radius: 14px; padding: 1.2rem; margin: .8rem 0; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 2rem; }
.filelist { list-style: none; padding: 0; margin: 0 0 .6rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.filelist li {
  display: flex; align-items: center; gap: .4rem; background: var(--primary-soft); border-radius: 10px;
  padding: .25rem .3rem .25rem .6rem; font-size: .85rem; max-width: 100%;
}
.filelist li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.full-input { width: 100%; margin-bottom: .6rem; }
.note { background: #fef9c3; color: #713f12; border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; }
.spacer { flex: 1; }
.vtable tr.off td:not(:first-child) { opacity: .4; }
.spinner {
  display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.15em;
}
@keyframes spin { to { transform: rotate(360deg); } }
code { background: var(--primary-soft); padding: 0 .3em; border-radius: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: .7rem 1.2rem; border-radius: 12px; z-index: 50;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

@media (max-width: 600px) {
  h1 { font-size: 1.5rem; }
  .brand span { display: none; }
  .puzzles { grid-template-columns: 1fr 1fr; }
  .boxes { grid-template-columns: repeat(5, 1fr); gap: .3rem; }
  .box .n { font-size: 1.25rem; }
  .box .l { font-size: .65rem; }
  .q-word { font-size: 1.7rem; }
  .options { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 1rem; }
}

/* Gelb braucht dunkle Schrift (Kontrast) */
.box.bg-gut, .badge.bg-gut { color: #0b0b0b; }

/* ---------- Verwaltung: Reiter ---------- */
.tabs {
  display: flex; gap: .3rem; margin-bottom: 1rem; overflow-x: auto;
  background: var(--card); border-radius: var(--radius); padding: .35rem; box-shadow: var(--shadow);
}
.tabs button {
  flex: 1; border: 0; background: none; border-radius: 12px; padding: .6rem .7rem;
  font-weight: 600; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.tabs button.active { background: var(--primary); color: #fff; }
.filter-row { margin-bottom: .4rem; }

/* ---------- Auswertung ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; }
.kpi .k-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kpi .k-value { font-size: 1.7rem; font-weight: 800; line-height: 1.2; margin-top: .15rem; }
.kpi .k-sub { font-size: .8rem; color: var(--muted); }
.kpi .k-sub.up { color: #006c10; }
.kpi .k-sub.down { color: #b42318; }
.chart-sub { margin: -.5rem 0 .6rem; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: #e7e7e7; stroke-width: 1; }
.chart .base { stroke: #c2c2c2; stroke-width: 1; }
.chart .tick { fill: #666; font-size: 11px; }
.chart .bar { fill: var(--primary); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { fill: var(--primary-dark); }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
details { margin-top: .6rem; font-size: .9rem; }
summary { cursor: pointer; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .8rem; font-size: .85rem; color: var(--text); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.hbar-row { display: grid; grid-template-columns: minmax(7rem, 9rem) 1fr; gap: .7rem; align-items: center; margin: .45rem 0; }
.hbar-label { font-size: .88rem; }
.hbar-label small { display: block; color: var(--muted); font-size: .75rem; }
.segbar { display: flex; gap: 2px; height: 22px; background: #fff; }
.segbar > div { height: 100%; min-width: 3px; }
.segbar > div:first-child { border-radius: 4px 0 0 4px; }
.segbar > div:last-child { border-radius: 0 4px 4px 0; }
.segbar > div:only-child { border-radius: 4px; }
.meter { position: relative; display: flex; align-items: center; gap: .5rem; height: 22px; }
.meter-track { flex: 1; height: 14px; background: #f1f1f4; border-radius: 0 4px 4px 0; overflow: hidden; }
.meter-fill { height: 100%; background: var(--primary); border-radius: 0 4px 4px 0; }
.meter-val { font-weight: 700; font-size: .9rem; min-width: 3rem; text-align: right; }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none; background: #191919; color: #efefef;
  border-radius: 8px; padding: .45rem .65rem; font-size: .82rem; line-height: 1.35; box-shadow: var(--shadow);
  max-width: 240px;
}
.tooltip b { color: #fff; }

@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .k-value { font-size: 1.4rem; }
  .tabs button { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .45rem .2rem; font-size: .72rem; }
  .tabs button span { font-size: 1.1rem; }
  .hbar-row { grid-template-columns: 6.5rem 1fr; }
}
