:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #1b2333;
    --muted: #5f6b7d;
    --border: #dde3ec;
    --primary: #1f6feb;
    --primary-text: #ffffff;
    --accent: #ffb020;
    --danger: #d64545;
    --radius: 16px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #10151f;
        --surface: #1a2130;
        --text: #e8edf5;
        --muted: #9aa6b8;
        --border: #2c3647;
        --primary: #4c8dff;
    }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    padding-bottom: var(--safe-bottom);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    margin-right: auto;
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--primary);
    text-decoration: none;
}

main {
    max-width: 560px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 8px 0 0; }

.muted { color: var(--muted); }
.center { text-align: center; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px 0;
}

.stack > * + * { margin-top: 12px; }

label { display: block; font-weight: 600; margin-bottom: 4px; }

input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
    outline-offset: 2px;
}

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 700;
    color: var(--primary-text);
    background: var(--primary);
    border: 0;
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
}

button.secondary, .button.secondary {
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
}

button.danger { background: var(--danger); }

button.link {
    min-height: auto;
    padding: 4px;
    color: var(--primary);
    background: none;
    font-weight: 600;
}

button[disabled] { opacity: 0.5; cursor: not-allowed; }

.full { width: 100%; }

.row { display: flex; gap: 12px; align-items: center; }
.row > .grow { flex: 1; }

.error {
    color: var(--danger);
    font-size: 0.95rem;
    margin-top: 4px;
}

.grades {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.choice {
    min-height: 56px;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--border);
}

.choice[aria-pressed="true"] {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

.tutors { display: grid; gap: 8px; }

.tutor {
    justify-content: flex-start;
    text-align: left;
    font-weight: 400;
    padding: 12px;
}

.tutor strong { display: block; }

.child {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    font-weight: 400;
    padding: 14px 16px;
}

.child .dot, .tutor .dot { width: 40px; height: 40px; flex: none; }
.child .grow { flex: 1; }

.banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--safe-bottom));
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--text);
    color: var(--bg);
    text-align: center;
}

.notice {
    margin: 0;
    padding: 10px 12px;
    font-size: 0.95rem;
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
}

.small { font-size: 0.92rem; margin: 0; }

.hint {
    font-size: 0.95rem;
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
    border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

/* ------------------------------------------------------------------ Tutoren
 * Jeder Tutor ist ein Block mit Farb- und Form-Variablen. Neuer Tutor:
 * Block kopieren, Schlüssel aus config/tutors.php eintragen, Werte anpassen.
 * Der Reaktor (Canvas) liest diese Variablen beim Tutorwechsel ein.
 */

/* Jarvis ist auch der Standard für unbekannte Tutoren */
[data-tutor],
[data-tutor="jarvis"] {
    --t-bg: #020a10;
    --t-bg2: #06202c;
    --t-text: #d8fbff;
    --t-muted: #6fa3b0;
    --t-accent: #ffb46b;
    --t-core: #5ff2ff;
    --t-core-hot: #ffffff;
    --t-ring: #2fc9e0;
    --t-glow: rgba(95, 242, 255, 0.45);
    --t-dashes: 48 6 3;
    --t-gap: 0.45;
    --t-cap: butt;
    --t-blur: 0;
    --t-glow-size: 1.9;
    --t-pulse: 1;
}

/* Friday: gleiche Grundform, aber weichere, rundere Ringe und wärmeres Leuchten */
[data-tutor="friday"] {
    --t-bg: #0d0702;
    --t-bg2: #2a1705;
    --t-text: #fff1d6;
    --t-muted: #c29a62;
    --t-accent: #ffd27a;
    --t-core: #ffbf3f;
    --t-core-hot: #fff6dc;
    --t-ring: #f0a020;
    --t-glow: rgba(255, 176, 48, 0.5);
    --t-dashes: 24 4 2;
    --t-gap: 0.3;
    --t-cap: round;
    --t-blur: 14;
    --t-glow-size: 2.3;
    --t-pulse: 1.4;
}

/* Kleine Reaktor-Vorschau in Listen und Auswahl */
.dot {
    display: inline-block;
    border-radius: 50%;
    background: radial-gradient(circle, var(--t-core-hot) 0 18%, var(--t-core) 40%, var(--t-bg2) 72%);
    box-shadow: 0 0 0 2px var(--t-ring), 0 0 14px var(--t-glow);
}

/* ------------------------------------------------------------------ Sprachbildschirm */

body.voice-mode {
    overflow: hidden;
    padding-bottom: 0;
    background: #000;
}

body.voice-mode .topbar,
body.voice-mode #offline-banner { display: none; }

body.voice-mode main {
    max-width: none;
    margin: 0;
    padding: 0;
}

.voice {
    position: fixed;
    inset: 0;
    overflow: hidden;
    color: var(--t-text);
    background: radial-gradient(circle at 50% 42%, var(--t-bg2), var(--t-bg) 70%);
    background-color: var(--t-bg);
    font-family: "Chakra Petch", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    transition: background-color 0.6s, color 0.6s;
}

/* Der ganze Bildschirm ist der Sprechknopf */
.voice .reactor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    outline: none;
}

.voice .reactor:focus-visible {
    box-shadow: inset 0 0 0 3px var(--t-ring);
}

.voice-top {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 640px;
    margin: 0 auto;
    padding: calc(14px + var(--safe-top)) 18px 0;
    pointer-events: none;
}

.tutor-switch {
    pointer-events: auto;
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    min-height: 0;
    padding: 0;
    margin-left: -6px;
    background: transparent;
    border: 0;
    border-radius: 50%;
}

.tutor-switch .dot {
    width: 34px;
    height: 34px;
    transition: transform 0.2s;
}

.tutor-switch:hover .dot,
.tutor-switch:focus-visible .dot { transform: scale(1.12); }

.gear {
    pointer-events: auto;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin-right: -8px;
    color: var(--t-muted);
    font-size: 1.3rem;
    text-decoration: none;
    border-radius: 50%;
    opacity: 0.8;
}

.gear:hover, .gear:focus-visible { opacity: 1; }
.gear svg { width: 22px; height: 22px; }

.voice-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--safe-bottom) + 22px);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 22px;
    pointer-events: none;
    text-align: center;
}

.voice .sub {
    max-width: 30ch;
    margin: 0;
    min-height: 2.6em;
    font-size: clamp(1.45rem, 6.2vw, 2.1rem);
    line-height: 1.25;
    font-weight: 600;
    text-shadow: 0 0 18px var(--t-glow);
    transition: opacity 0.25s;
}

.voice .de {
    max-width: 36ch;
    margin: 0;
    min-height: 1.3em;
    font-size: clamp(1rem, 4vw, 1.15rem);
    color: var(--t-accent);
}

.voice .state-hint {
    margin: 0;
    font-size: 0.95rem;
    color: var(--t-muted);
}

@media (prefers-reduced-motion: reduce) {
    .voice, .voice .sub { transition: none; }
}

/* ------------------------------------------------------------------ Lehrbuch-Import */

.grades .choice { font-size: 0.95rem; padding: 8px 4px; }

textarea { resize: vertical; }

input[aria-invalid="true"] { border-color: var(--danger); }

.thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.thumb { position: relative; }

.thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.thumb .remove {
    position: absolute;
    top: 4px;
    right: 4px;
    min-height: 28px;
    width: 28px;
    padding: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
}

.units { list-style: none; margin: 8px 0 0; padding: 0; }

.units li {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.units .unit-missing { color: var(--muted); }

.unit-no { display: flex; align-items: center; gap: 6px; margin: 0; }
.unit-no input { width: 4.5em; }

.word-rows { display: grid; gap: 6px; }

.word-row {
    display: grid;
    grid-template-columns: 1fr 1fr 32px;
    gap: 6px;
    align-items: center;
}

.word-row input { padding: 8px 10px; }

.grammar-edit {
    padding: 10px;
    border: 1px dashed var(--border);
    border-radius: 12px;
}

/* ------------------------------------------------------------------ Lernfortschritt */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.tile-value { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.tile-value small { font-size: 1rem; font-weight: 600; }
.tile-label { font-size: 0.9rem; color: var(--muted); }

/* Säulen: dünn, oben 4px abgerundet, 2px Abstand, Achse zurückhaltend */
.bars {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 2px;
    height: 160px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.bar-col {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    outline: none;
}

.bar {
    width: 70%;
    max-width: 18px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
}

.bar-value { font-size: 0.8rem; color: var(--muted); min-height: 1.1em; }

.bar-label {
    position: absolute;
    bottom: -20px;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Hover-/Tipp-Info pro Säule bzw. Zeile */
[data-tip] { position: relative; }

.bar-col[data-tip]:hover::after,
.bar-col[data-tip]:focus::after,
.hbar-row[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% - 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    padding: 4px 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    color: var(--bg);
    background: var(--text);
    border-radius: 6px;
    pointer-events: none;
}

.bar-col:hover .bar,
.bar-col:focus .bar { filter: brightness(1.15); }

.hbar-row {
    display: grid;
    grid-template-columns: 4.5em 1fr 3em;
    gap: 8px;
    align-items: center;
}

.hbar-label { font-size: 0.9rem; }
.hbar-value { font-size: 0.9rem; text-align: right; }

.hbar-track {
    display: block;
    height: 12px;
    background: color-mix(in srgb, var(--border) 60%, transparent);
    border-radius: 6px;
    overflow: hidden;
}

.hbar-track.wide { margin: 6px 0 2px; }

.hbar {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
}

table.words { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.words th { text-align: left; font-size: 0.85rem; color: var(--muted); font-weight: 600; padding: 4px 6px; }
table.words td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
table.words .num { text-align: right; white-space: nowrap; }

/* ------------------------------------------------------------------ Rollen: Start, Profile, Tutoren, Geräte */

.avatar {
    display: inline-grid;
    place-items: center;
    flex: none;
    line-height: 1;
    border-radius: 50%;
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

.avatar.initial { color: var(--primary); font-weight: 800; }

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.avatar-grid .choice { min-height: 44px; padding: 0; font-size: 1.5rem; }

@media (max-width: 420px) {
    .avatar-grid { grid-template-columns: repeat(6, 1fr); }
}

.start { text-align: center; }
.start .card { text-align: left; }

.hero-dot { width: 96px; height: 96px; margin: 8px auto 12px; display: block; }

.code-input {
    font-size: 2.4rem;
    text-align: center;
    letter-spacing: 0.6em;
    padding-left: 0.6em;
    font-variant-numeric: tabular-nums;
}

.profiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.profile {
    flex-direction: column;
    gap: 10px;
    min-height: 170px;
    font-size: 1.4rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border);
}

.tutor-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

/* Jede Karte trägt die Farben ihres Tutors */
.tutor-card {
    flex-direction: column;
    gap: 8px;
    min-height: 220px;
    padding: 18px 12px;
    font-weight: 400;
    color: var(--t-text);
    background: radial-gradient(circle at 50% 35%, var(--t-bg2), var(--t-bg) 75%);
    border: 2px solid color-mix(in srgb, var(--t-ring) 40%, transparent);
}

.tutor-card .dot { width: 92px; height: 92px; }
.tutor-card strong { font-size: 1.4rem; letter-spacing: 0.06em; text-transform: uppercase; }
.tutor-card span:last-child { font-size: 0.95rem; color: var(--t-muted); }
.tutor-card[aria-pressed="true"] { border-color: var(--t-ring); box-shadow: 0 0 18px var(--t-glow); }

.tutor-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
    text-align: center;
    background: color-mix(in srgb, var(--t-bg) 92%, transparent);
    backdrop-filter: blur(6px);
}

.tutor-overlay h2 { margin: 0; }
.tutor-overlay .tutor-cards { max-width: 520px; width: 100%; margin: 16px auto; }
.tutor-overlay [data-close-tutors] { align-self: center; color: var(--t-text); border-color: color-mix(in srgb, var(--t-ring) 40%, transparent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .button, .actions button { flex: 1 1 auto; min-height: 44px; padding: 8px 12px; font-size: 0.95rem; }

.device-list { list-style: none; margin: 0; padding: 0; }

.device-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}

.device-list li:first-child { border-top: 0; padding-top: 0; }
.device-list button { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; }

details.card summary { cursor: pointer; min-height: 32px; }
