:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1d2330;
    --muted: #667085;
    --border: #e3e6eb;
    --primary: #2f6fed;
    --primary-text: #ffffff;
    --danger: #c9372c;
    --success-bg: #e8f6ee;
    --success-text: #1d6b40;
    --error-bg: #fdecea;
    --error-text: #9b2c22;
    --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }

.container { max-width: 1040px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.container.narrow { max-width: 440px; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .75rem 16px; background: var(--card); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.muted { color: var(--muted); font-size: .9rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; background: #eef2fb; color: #2b4a8b; font-size: .8rem; }
.badge.off { background: #f1f1f1; color: var(--muted); }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

form.stack { display: flex; flex-direction: column; gap: .75rem; }
form.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
form.inline { display: inline; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: .4rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    font: inherit; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; min-width: 0;
}
textarea { min-height: 8rem; }

button, .button { font: inherit; padding: .5rem 1rem; border: 0; border-radius: 8px; background: var(--primary); color: var(--primary-text); cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .button.secondary { background: #e9edf5; color: var(--text); }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--primary); padding: 0; }
button.small, .button.small { padding: .25rem .6rem; font-size: .85rem; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }
.callout { background: #fff8e1; border: 1px solid #f3dc8c; padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; word-break: break-all; }

details summary { cursor: pointer; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* Kinder-Bereich */
.kid { text-align: center; }
.kid h1 { font-size: 2rem; }
.kid input { font-size: 1.2rem; padding: .75rem; }
.kid button { font-size: 1.2rem; padding: .8rem 1.5rem; border-radius: 14px; }
.stars { font-size: 2.5rem; margin: 1rem 0; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14171c; --card: #1d2128; --text: #e7e9ee; --muted: #9aa3b2; --border: #2e343e;
        --primary: #6c9cff; --primary-text: #0d1220;
        --success-bg: #173526; --success-text: #8fe0b2; --error-bg: #3a1b18; --error-text: #ffb4aa;
    }
    :root:not([data-theme="light"]) th { background: #222730; }
    :root:not([data-theme="light"]) .badge { background: #26324a; color: #b9cdf5; }
    :root:not([data-theme="light"]) .callout { background: #3a3218; border-color: #5c4e1f; }
    :root:not([data-theme="light"]) button.secondary, :root:not([data-theme="light"]) .button.secondary { background: #2b313b; }
    :root:not([data-theme="light"]) input, :root:not([data-theme="light"]) select, :root:not([data-theme="light"]) textarea { background: #14171c; color: var(--text); }
}

/* Abgaben */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1.5rem; align-items: start; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.scan { width: 100%; border: 1px solid var(--border); border-radius: 8px; margin-bottom: .75rem; background: #fff; }
.segment { margin: .25rem 0 .75rem; }
.corrected { color: var(--success-text); }
.transcript { white-space: pre-wrap; font-family: inherit; margin: 0; }
.wrong { background: var(--error-bg); color: var(--error-text); padding: 0 .2rem; border-radius: 4px; }
li.right { color: var(--success-text); font-weight: 600; }
.status-review, .status-failed { background: var(--error-bg); color: var(--error-text); }
.status-done { background: var(--success-bg); color: var(--success-text); }

/* Etappe 4: Inbox, Prüfen, Statistik */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.count { display: inline-block; min-width: 1.4rem; padding: 0 .4rem; border-radius: 99px; background: var(--primary); color: #fff; font-size: .75rem; text-align: center; }
.filters { margin-bottom: 1rem; }
.reviewbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; padding: .9rem 1rem; margin-bottom: 1rem;
    background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); }
.reviewbar > div { flex: 1 1 260px; }
table.errors select { padding: .3rem .4rem; font-size: .9rem; max-width: 12rem; }
table.errors tr.rejected td { color: var(--muted); background: #fafbfc; }
table.errors tr.rejected s { text-decoration: none; }
td.actions { white-space: nowrap; text-align: right; }
button.icon { padding: .25rem .55rem; min-width: 2rem; background: var(--card); color: var(--text); border: 1px solid var(--border); }
button.icon:hover { border-color: var(--primary); }
.ok { color: var(--success-text); font-weight: 700; padding: 0 .55rem; }

.heatmap { border-collapse: separate; border-spacing: 2px; background: transparent; border: 0; }
.heatmap th, .heatmap td { border: 0; padding: .4rem .5rem; }
.heatmap thead th { background: transparent; vertical-align: bottom; font-size: .78rem; line-height: 1.2; min-width: 4.2rem; }
.heatmap tbody th { background: var(--card); font-weight: 500; white-space: nowrap; color: var(--text); font-size: .9rem; }
.heatmap td { text-align: center; font-size: .85rem; border-radius: 4px; background: #f1f3f6; color: var(--muted); }
.heatmap td.l1, .legend .l1 { background: #fde9d8; color: #7a3d0c; }
.heatmap td.l2, .legend .l2 { background: #fbcca6; color: #6b330a; }
.heatmap td.l3, .legend .l3 { background: #f59b5e; color: #fff; }
.heatmap td.l4, .legend .l4 { background: #d9622b; color: #fff; }
.legend { display: flex; gap: .4rem; align-items: center; font-size: .8rem; color: var(--muted); margin: .5rem 0 1rem; flex-wrap: wrap; }
.legend span.sw { width: 1.4rem; height: .9rem; border-radius: 3px; display: inline-block; }

.hint { padding: .6rem .8rem; border-radius: 8px; margin-bottom: .5rem; border-left: 4px solid; }
.hint-watch { background: #fff4e5; border-color: #e8890c; }
.hint-good { background: var(--success-bg); border-color: #2e9e5b; }
.hint-info { background: #eef2fb; border-color: #7b93c4; }
.bar { height: .55rem; border-radius: 99px; background: #f59b5e; display: inline-block; vertical-align: middle; }
.stat { font-size: 1.6rem; font-weight: 700; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .heatmap td { background: #232831; }
    :root:not([data-theme="light"]) .heatmap td.l1, .legend .l1 { background: #4a2f1d; color: #f5c9a6; }
    :root:not([data-theme="light"]) .heatmap td.l2, .legend .l2 { background: #7a4120; color: #ffe0c7; }
    :root:not([data-theme="light"]) .heatmap td.l3, .legend .l3 { background: #b4571f; color: #fff; }
    :root:not([data-theme="light"]) .heatmap td.l4, .legend .l4 { background: #e2742f; color: #1a0e05; }
    :root:not([data-theme="light"]) .hint-watch { background: #3a2a14; }
    :root:not([data-theme="light"]) .hint-info { background: #1e2738; }
    :root:not([data-theme="light"]) table.errors tr.rejected td { background: #191c22; }
}

/* Etappe 5: Übungen der Kinder */
.flash-retry { background: #fff4e5; color: #8a4b08; font-weight: 600; font-size: 1.1rem; }
.flash-info { background: #eef2fb; color: #2b4a8b; }
.kid .big { font-size: 1.3rem; font-weight: 700; margin: .25rem 0; }
.kid .streak { color: #c2410c; font-weight: 700; margin-top: -.5rem; }
.kid .bigemoji { font-size: 4rem; margin: 1rem 0 0; }
.big-button, a.button.big-button { display: block; width: 100%; font-size: 1.25rem; padding: .9rem 1.5rem; border-radius: 14px; margin-top: 1rem; text-align: center; }
.topics { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.topic { background: #eef2fb; color: #2b4a8b; padding: .3rem .8rem; border-radius: 99px; font-weight: 600; }

.practice { text-align: left; }
.practice-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; font-weight: 600; }
.progress { height: .6rem; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 1rem; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.task .task-head { display: flex; gap: .75rem; align-items: flex-start; }
.task .instruction { font-size: 1.35rem; font-weight: 700; margin: 0 0 1rem; flex: 1; }
.task .text { font-size: 1.4rem; line-height: 1.7; }
.task .math { font-size: 2rem; font-weight: 700; text-align: center; }
.task .gap { color: var(--primary); font-weight: 800; }
.task input[type=text] { width: 100%; font-size: 1.4rem; padding: .8rem; border-radius: 12px; }
button.speak { background: none; border: 1px solid var(--border); color: inherit; font-size: 1.4rem; padding: .3rem .6rem; border-radius: 10px; }

.tokens { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.token { display: inline-block; font-size: 1.35rem; padding: .5rem .8rem; border-radius: 10px; border: 2px solid var(--border); background: var(--card); }
.token.wrong { border-color: var(--danger); background: var(--error-bg); color: var(--error-text); }
label.token.pick { cursor: pointer; user-select: none; padding: 0; border: 0; background: none; }
label.token.pick input { position: absolute; opacity: 0; pointer-events: none; }
label.token.pick span { display: inline-block; padding: .5rem .8rem; border-radius: 10px; border: 2px solid var(--border); background: var(--card); }
label.token.pick input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
label.token.pick input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }

.options { display: grid; gap: .6rem; }
.option { font-size: 1.3rem; padding: .9rem 1rem; border-radius: 12px; border: 2px solid var(--border); background: var(--card); color: var(--text); text-align: center; }
button.option:hover { border-color: var(--primary); }
.option.right { border-color: #2e9e5b; background: var(--success-bg); color: var(--success-text); font-weight: 700; }
.result { padding: .8rem 1rem; border-radius: 12px; font-size: 1.2rem; font-weight: 700; margin: 1rem 0 .5rem; }
.result.right { background: var(--success-bg); color: var(--success-text); }
.result.wrong { background: #fff4e5; color: #8a4b08; }
.solution { color: var(--success-text); font-weight: 700; font-size: 1.15rem; }
.dots { letter-spacing: .1rem; color: var(--primary); white-space: nowrap; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .flash-retry, :root:not([data-theme="light"]) .result.wrong { background: #3a2a14; color: #ffcf99; }
    :root:not([data-theme="light"]) .flash-info, :root:not([data-theme="light"]) .topic { background: #1e2738; color: #b9cdf5; }
}
