/* Lernen – Schulheft: Papierweiß, Königsblau, Karoraster nur dort, wo geschrieben wird. */

:root {
    --paper: #F7F9FB;
    --surface: #FFFFFF;
    --ink: #1F3FA6;
    --ink-strong: #17307F;
    --ink-wash: #E8EDFA;
    --grid: #D5DEEA;
    --graphite: #23272F;
    --graphite-soft: #5B6372;
    --line: #DDE3EB;
    --red: #C8322B;
    --red-wash: #FBEAE9;
    --green: #2E7D4F;
    --green-wash: #E6F3EB;
    --amber: #8A5A00;
    --amber-wash: #FBF1DC;
    --margin-red: #E4A3A0;

    --font: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    --radius: 10px;
    --tap: 48px;
    --gap: 16px;
    --measure: 760px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #161B22;
        --surface: #1E242D;
        --ink: #8EA6FF;
        --ink-strong: #B3C3FF;
        --ink-wash: #232D45;
        --grid: #2A3340;
        --graphite: #E6EAF0;
        --graphite-soft: #A2ABB8;
        --line: #2E3642;
        --red: #FF8A80;
        --red-wash: #3A2223;
        --green: #7BD3A0;
        --green-wash: #1D3227;
        --amber: #F2C76B;
        --amber-wash: #3A3020;
        --margin-red: #7A3B39;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--graphite);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Karopapier, 5-mm-Raster */
.on-grid {
    background-color: var(--paper);
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
}

a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--ink-strong); }

:focus-visible {
    outline: 3px solid var(--ink);
    outline-offset: 2px;
    border-radius: 4px;
}

h1, h2 { line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 30px; margin: 4px 0 8px; }
h2 { font-size: 20px; margin: 0 0 12px; }

.skip {
    position: absolute; left: -999px; top: 8px;
    background: var(--surface); padding: 8px 12px; z-index: 10;
}
.skip:focus { left: 8px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

/* Kopfzeile */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
    position: sticky; top: 0; z-index: 5;
}
.topbar-inner {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    display: flex; align-items: center; gap: 16px;
    min-height: 56px;
}
.wordmark {
    font-weight: 700; font-size: 21px; color: var(--ink);
    text-decoration: none; letter-spacing: -0.02em;
}
.mainnav {
    margin-left: auto;
    display: flex; gap: 4px;
    overflow-x: auto; scrollbar-width: none;
}
.mainnav a {
    display: inline-flex; align-items: center;
    min-height: 40px; padding: 0 12px;
    border-radius: 999px;
    color: var(--graphite-soft); text-decoration: none; white-space: nowrap;
    font-size: 16px;
}
.mainnav a[aria-current="page"] { background: var(--ink-wash); color: var(--ink); font-weight: 600; }

.page {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 20px max(16px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.crumbs { display: flex; flex-wrap: wrap; gap: 4px; font-size: 15px; margin-bottom: 4px; }
.crumbs a { color: var(--graphite-soft); text-decoration: none; }
.crumbs a:not(:last-child)::after { content: "/"; margin-left: 6px; color: var(--line); }
.crumbs a:hover { color: var(--ink); }

.lead { font-size: 19px; color: var(--graphite-soft); }
.muted { color: var(--graphite-soft); }
.block { margin-top: 32px; }
.narrow { max-width: 520px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
}

/* Meldungen */
.notice {
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 0 0 16px;
    border-left: 4px solid;
}
.notice-success { background: var(--green-wash); border-color: var(--green); }
.notice-error { background: var(--red-wash); border-color: var(--red); }
.notice-warning { background: var(--amber-wash); border-color: var(--amber); }

/* Formulare */
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form .grow { flex: 1 1 240px; }
.narrow-field { max-width: 140px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 15px; }
.field small { color: var(--graphite-soft); font-size: 14px; }
.optional { font-style: normal; font-weight: 400; color: var(--graphite-soft); }

input[type="text"], input[type="password"], input[type="number"], input[type="email"], select, textarea {
    font: inherit;
    color: var(--graphite);
    background: var(--surface);
    border: 1.5px solid var(--line);
    border-radius: 8px;
    min-height: var(--tap);
    padding: 10px 12px;
    width: 100%;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--ink-wash); }

.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }

/* Knöpfe */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap); padding: 0 20px;
    border-radius: 999px;
    border: 1.5px solid var(--ink);
    background: transparent; color: var(--ink);
    font: inherit; font-weight: 600; text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { .btn:hover { background: var(--ink-wash); color: var(--ink); } }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-strong); color: #fff; }
@media (prefers-color-scheme: dark) {
    .btn-primary, .btn-primary:hover { color: #10172B; }
}
.btn-quiet { border-color: transparent; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-wash); color: var(--red); }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }

/* Listen */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rows li { border-bottom: 1px solid var(--line); }
.row-link:active { background: var(--ink-wash); }
.row-link {
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 4px; min-height: 60px; justify-content: center;
    text-decoration: none; color: var(--graphite);
}
@media (hover: hover) { .row-link:hover { background: var(--ink-wash); } }
.row-main { font-weight: 600; }
.row-meta { font-size: 15px; color: var(--graphite-soft); }

.tag {
    display: inline-block; font-size: 13px; font-weight: 600;
    padding: 1px 8px; border-radius: 999px; margin-left: 6px;
    background: var(--ink-wash); color: var(--ink); vertical-align: 2px;
}
.tag-red { background: var(--red-wash); color: var(--red); }

/* Fächer: farbig nach Art, wie Heftumschläge */
.subject-grid {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px;
}
.subject {
    display: flex; flex-direction: column; justify-content: space-between;
    min-height: 96px; padding: 14px 16px 14px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    text-decoration: none; color: var(--graphite);
    position: relative; overflow: hidden;
}
.subject::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
    background: var(--ink);
}
.subject-language::before { background: var(--ink); }
.subject-math::before { background: var(--green); }
.subject-fact::before { background: var(--amber); }
@media (hover: hover) { .subject:hover { border-color: var(--ink); } }
.subject-name { font-weight: 600; font-size: 18px; }
.subject-meta { font-size: 14px; color: var(--graphite-soft); }
.subject-quiet { min-height: 56px; justify-content: center; }
.subject-quiet::before { background: var(--line); }
.subject-grid-quiet { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.more-subjects { margin-top: 16px; }
.more-subjects summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--ink); font-weight: 600; }

/* Vokabeltabelle */
.vocab-table { width: 100%; border-collapse: collapse; }
.vocab-table th {
    text-align: left; font-size: 14px; font-weight: 600; color: var(--graphite-soft);
    padding: 8px 8px; border-bottom: 2px solid var(--line);
}
.vocab-table td { padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.vocab-table .word { font-weight: 600; color: var(--ink); font-size: 18px; }
.vocab-table .grammar, .vocab-table .note { display: block; font-size: 14px; color: var(--graphite-soft); }
.cell-action { text-align: right; white-space: nowrap; width: 1%; }
.cell-action a { display: inline-flex; min-height: 40px; align-items: center; padding: 0 4px; }

.qa-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.qa-list li { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.qa-q { font-weight: 600; }
.qa-a { color: var(--ink); }
.qa-wrong { font-size: 14px; color: var(--graphite-soft); }
.qa-edit { justify-self: start; font-size: 15px; }

.empty-note {
    border: 1.5px dashed var(--line); border-radius: var(--radius);
    padding: 20px; color: var(--graphite-soft);
}

.danger-zone summary { cursor: pointer; color: var(--graphite-soft); min-height: var(--tap); display: flex; align-items: center; }
.danger-zone form { margin-top: 16px; }
.delete-form { padding-top: 16px; border-top: 1px solid var(--line); }

kbd {
    font: inherit; font-weight: 600; padding: 0 6px;
    border: 1px solid var(--line); border-radius: 4px; background: var(--surface);
}

/* Fakten, Admin */
.facts { display: grid; gap: 0; margin: 16px 0; border-top: 1px solid var(--line); }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--graphite-soft); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a {
    padding: 10px 14px; min-height: 44px; display: inline-flex; align-items: center;
    text-decoration: none; color: var(--graphite-soft); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--ink); font-weight: 600; }

.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.admin-table thead th { font-size: 14px; color: var(--graphite-soft); }
.admin-table tbody th { font-weight: 600; }
.admin-table select, .admin-table input[type="text"] { min-height: 40px; padding: 6px 8px; }
.admin-table input[type="text"] { width: 4.5em; }
.admin-table input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--ink); }

.checklist { list-style: none; padding: 0; margin: 0 0 16px; }
.checklist li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.check-mark { font-weight: 700; width: 20px; }
.checklist .ok .check-mark { color: var(--green); }
.checklist .bad .check-mark { color: var(--red); }

.empty { text-align: left; padding: 48px 0; }

/* Anmeldung: ein Blatt aus dem Heft, mit rotem Rand */
.sheet-wrap {
    min-height: 100vh; min-height: 100dvh;
    display: grid; place-items: center;
    padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.sheet {
    width: 100%; max-width: 420px;
    background: var(--surface);
    border-radius: 4px;
    padding: 36px 28px 28px 52px;
    position: relative;
    box-shadow: 0 1px 0 var(--line), 0 12px 32px -18px rgba(31, 63, 166, 0.35);
}
.sheet::before {
    content: ""; position: absolute; top: 0; bottom: 0; left: 32px;
    border-left: 2px solid var(--margin-red);
}
.sheet-title {
    font-size: 44px; font-weight: 700; color: var(--ink);
    letter-spacing: -0.03em; margin: 0;
}
.sheet-sub { margin: 4px 0 24px; color: var(--graphite-soft); }
.hint { font-size: 14px; color: var(--graphite-soft); margin: 20px 0 0; }

@media (max-width: 520px) {
    body { font-size: 16px; }
    h1 { font-size: 26px; }
    .vocab-table .word { font-size: 17px; }
    .sheet { padding-left: 44px; }
    .sheet::before { left: 26px; }
}

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

/* Foto-Upload */
.upload-thumb { display: block; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; }
.proposal legend { padding: 0; }
input[type="file"] { min-height: 48px; max-width: 100%; }

/* Vokabelabfrage */
.quiz-card { max-width: 560px; }
.quiz-dir { margin: 0 0 4px; color: var(--graphite-soft); font-size: 15px; }
.quiz-word { margin: 0 0 12px; font-size: 32px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.quiz-input { font-size: 22px; min-height: 56px; }
.wrong-given { color: var(--red); text-decoration: line-through; }
.quiz-progress { margin-bottom: 8px; }
.boxes { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.box-chip { padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }

/* Eingang für Fotos */
.notice-link { display: block; color: inherit; text-decoration: none; }
.notice-link:hover { filter: brightness(0.97); }
.photo-pick { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; min-height: 48px; }
.photo-card img, .photo-img { width: 100%; height: 120px; object-fit: cover; border-radius: 4px; }
.photo-card input { width: 22px; height: 22px; accent-color: var(--ink); }
.photo-meta { font-size: 14px; overflow-wrap: anywhere; }
.photo-meta small { display: block; color: var(--graphite-soft); }

/* Schreibfeld mit Karoraster (nur hier und auf der Anmeldung) */
.writepad {
    position: relative;
    border: 2px solid var(--line);
    border-radius: 10px;
    background-color: var(--paper);
    background-image:
        linear-gradient(to right, var(--line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--line) 1px, transparent 1px);
    background-size: 28px 28px;
}
.writepad-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 2 / 1;
    touch-action: none;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: crosshair;
}
@media (min-width: 700px) { .writepad-canvas { aspect-ratio: 3 / 1; } }
.writepad-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; pointer-events: none; }
.quiz-word.is-hidden { visibility: hidden; }
.read-text { font-size: 30px; font-weight: 600; margin: 4px 0 12px; overflow-wrap: anywhere; }
.diff { margin: 8px 0 0; display: flex; flex-direction: column; gap: 2px; }
.diff-label { font-size: 14px; color: var(--graphite-soft); }
.diff-text { font-size: 26px; font-weight: 600; letter-spacing: 0.03em; overflow-wrap: anywhere; }
.d-bad { color: var(--red); text-decoration: underline; text-decoration-thickness: 2px; background: var(--red-wash); border-radius: 2px; }
.clean-form { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.file-chip { margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; font-size: 14px; }
.photo-card .file-chip { border: 0; padding: 0; }

/* Karteikarten */
.flashcard { max-width: 720px; margin: 8px 0 16px; border: 2px solid var(--line); border-radius: 16px; background: var(--paper); overflow: hidden; }
.flashcard-front, .flashcard-back { padding: 28px 24px; min-height: 140px; }
.flashcard-back { border-top: 2px dashed var(--line); background: var(--green-wash); }
.flashcard-label { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--graphite-soft); }
.flashcard-text { margin: 0; font-size: 26px; line-height: 1.35; overflow-wrap: anywhere; }
.flashcard-word { font-size: 38px; font-weight: 600; }
.btn-xl { min-height: 64px; font-size: 20px; padding: 0 28px; }
.rate-row { display: flex; gap: 12px; flex-wrap: wrap; }
.rate-row .btn { flex: 1 1 160px; }
.btn-known { background: var(--green); border-color: var(--green); color: var(--paper); }
.btn-unknown { border-color: var(--red); color: var(--red); }

/* Quiz mit Stufen */
.quiz-question { margin: 0 0 16px; font-size: 24px; line-height: 1.4; overflow-wrap: anywhere; }
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice { display: block; width: 100%; min-height: 64px; padding: 14px 18px; text-align: left; font: inherit; font-size: 19px; line-height: 1.35; color: inherit; background: var(--paper); border: 2px solid var(--line); border-radius: 12px; cursor: pointer; }
.choice:hover, .choice:focus-visible { border-color: var(--ink); }
.feedback-text { margin: 6px 0; }
.given-text { margin: 0 0 8px; padding: 8px 10px; border-left: 3px solid var(--line); white-space: normal; }
