:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #667085;
    --primary: #4057d6;
    --primary-dark: #3043ad;
    --border: #dce2ee;
    --danger: #b42318;
    --warning: #b54708;
    --success: #067647;
    --radius: 18px;
    --shadow: 0 12px 30px rgba(28, 39, 73, 0.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; }
button, a, label, input { -webkit-tap-highlight-color: transparent; }
button, .button, .option-card { touch-action: manipulation; }
body {
    margin: 0;
    min-height: 100dvh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.55;
}
a { color: var(--primary); }
.shell { width: min(1080px, calc(100% - 32px)); margin-inline: auto; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.site-header { background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.header-inner { min-height: 66px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 900; text-decoration: none; color: var(--text); font-size: 1.15rem; display: grid; line-height: 1.05; }
.brand small { color: var(--muted); font-size: .68rem; font-weight: 700; margin-top: 4px; letter-spacing: .02em; }
.version { color: var(--muted); font-size: .86rem; }
main.shell { padding-block: 34px 60px; }
.site-footer { color: var(--muted); padding: 22px 0 calc(34px + env(safe-area-inset-bottom)); font-size: .88rem; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(22px, 4vw, 38px);
    margin-bottom: 24px;
}
.narrow { max-width: 650px; }
.hero, .result-hero { display: grid; grid-template-columns: 1fr auto; gap: 30px; align-items: center; }
.hero h1, .result-hero h1 { margin: 4px 0 12px; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; }
.lead { font-size: 1.12rem; color: #3b455b; max-width: 720px; }
.diagnostic-title { margin: 0 0 12px; font-size: clamp(1.2rem, 2.5vw, 1.65rem); color: var(--primary-dark); }
.eyebrow { color: var(--primary); font-weight: 800; letter-spacing: .07em; text-transform: uppercase; font-size: .78rem; }
.hero-facts { display: grid; gap: 10px; min-width: 170px; }
.hero-facts div { background: #eef1ff; border-radius: 14px; padding: 12px 16px; }
.hero-facts strong, .hero-facts span { display: block; }
.hero-facts strong { font-size: 1.25rem; }
.hero-facts span { color: var(--muted); font-size: .82rem; }
.grid-2, .grid-3 { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.small-card { padding: 24px; }
.small-card h3 { margin-top: 0; }
.stack { display: grid; gap: 12px; }
label { font-weight: 700; }
input[type="text"], input:not([type]), .large-input {
    width: 100%; min-height: 54px; padding: 14px 16px; border: 1px solid #bfc8da; border-radius: 12px; font: inherit; font-size: 16px; background: #fff;
}
input:focus { outline: 3px solid rgba(64, 87, 214, .18); border-color: var(--primary); }
.field-hint, .muted { color: var(--muted); font-size: .9rem; }
.button {
    appearance: none; border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 800;
    min-height: 52px; background: var(--primary); color: #fff; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.button:hover { background: var(--primary-dark); }
.button:disabled { opacity: .65; cursor: wait; }
.button-secondary { background: #eef1f7; color: var(--text); border: 1px solid var(--border); }
.button-secondary:hover { background: #e1e6ef; }
.actions { display: flex; gap: 12px; align-items: center; }
.actions form { margin: 0; }
.wrap { flex-wrap: wrap; }
.alert { padding: 15px 18px; border-radius: 12px; margin-bottom: 22px; border: 1px solid; }
.alert-error { background: #fff1f0; color: var(--danger); border-color: #f6c6c2; }
.alert-warning { background: #fff7ed; color: var(--warning); border-color: #fed7aa; }
.alert-success { background: #ecfdf3; color: var(--success); border-color: #abefc6; }
.progress-panel { margin-bottom: 22px; position: sticky; top: 0; z-index: 20; padding: 12px 0 10px; background: rgba(244,246,251,.94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.progress-meta { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.progress-track, .bar { height: 12px; background: #e5e9f2; border-radius: 999px; overflow: hidden; }
.progress-fill, .bar span { height: 100%; display: block; background: var(--primary); border-radius: inherit; }
.question-card { max-width: 900px; margin-inline: auto; }
.question-topline, .competency-heading, .competency-details { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.pill { padding: 6px 10px; border-radius: 999px; background: #eef1ff; color: var(--primary-dark); font-size: .82rem; font-weight: 800; }
.question-prompt { font-size: clamp(1.65rem, 4vw, 2.5rem); margin: 26px 0 10px; }
.instruction { color: var(--muted); margin-bottom: 22px; }
.option-list { display: grid; gap: 12px; }
.option-card { display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 15px 17px; border: 2px solid var(--border); border-radius: 14px; cursor: pointer; font-size: 1.03rem; user-select: none; -webkit-user-select: none; transition: border-color .15s ease, background .15s ease, transform .08s ease; }
.option-card:hover { border-color: var(--primary); background: #f8f9ff; }
.option-card:active { transform: scale(.995); }
.option-card.is-selected, .option-card:has(input:checked) { border-color: var(--primary); background: #eef1ff; box-shadow: 0 0 0 2px rgba(64,87,214,.10); }
.option-card input { width: 20px; height: 20px; accent-color: var(--primary); }
.question-actions { justify-content: space-between; margin-top: 28px; position: sticky; bottom: 0; z-index: 10; padding: 14px 0 max(4px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 24%); }
.score-ring {
    --score: 0;
    width: 145px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
    background: conic-gradient(var(--primary) calc(var(--score) * 1%), #e5e9f2 0);
    position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 13px; background: white; border-radius: 50%; }
.score-ring span { position: relative; font-size: 1.8rem; font-weight: 900; }
.competency-list { display: grid; gap: 14px; }
.competency-row { padding: 18px; border: 1px solid var(--border); border-left-width: 7px; border-radius: 14px; }
.competency-row h3 { margin: 0; }
.competency-row p { margin: 3px 0 0; color: var(--muted); }
.competency-heading > strong { font-size: 1.35rem; }
.competency-details { margin-top: 8px; color: var(--muted); font-size: .84rem; flex-wrap: wrap; }
.status-critical { border-left-color: #d92d20; }
.status-uncertain { border-left-color: #f79009; }
.status-mostly_secure { border-left-color: #2e90fa; }
.status-secure { border-left-color: #12b76a; }
.gap-note, .mixed-note, .strength-note { margin: 10px 0 0; color: #3b455b; font-size: .9rem; }
.mixed-note { border-left: 3px solid #f79009; padding-left: 10px; }
.strength-note { border-left: 3px solid #12b76a; padding-left: 10px; }
.recommendation-main { font-size: 1.35rem; font-weight: 900; color: var(--primary-dark); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
    .hero, .result-hero, .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .hero-facts { grid-template-columns: repeat(3, 1fr); min-width: 0; }
    .hero-facts div { padding: 10px; }
    .score-ring { width: 120px; }
    .question-topline, .progress-meta { align-items: flex-start; }
}

@media (max-width: 520px) {
    .shell { width: min(100% - 20px, 1040px); }
    main.shell { padding-top: 20px; }
    .card { padding: 20px; border-radius: 15px; }
    .hero-facts { grid-template-columns: 1fr; }
    .actions { align-items: stretch; flex-direction: column; }
    .actions > *, .actions form, .actions form button { width: 100%; }
    .question-actions { flex-direction: row; }
    .question-actions > * { width: auto; flex: 1; }
    .competency-heading { align-items: flex-start; }
}

@media print {
    @page { margin: 12mm; }
    body { background: white; font-size: 10.5pt; }
    .site-header, .site-footer, .no-print { display: none !important; }
    main.shell { padding: 0; width: 100%; }
    .card { box-shadow: none; padding: 14px 16px; margin-bottom: 10px; break-inside: auto; }
    .result-hero, .grid-2 { display: block; }
    .result-hero h1 { font-size: 24pt; }
    .result-hero .lead { font-size: 11pt; }
    .score-ring { width: 90px; float: right; margin: -78px 0 8px 18px; }
    .competency-list { gap: 8px; }
    .competency-row { padding: 10px 12px; break-inside: avoid; }
    .competency-row h3 { font-size: 13pt; }
    .bar { height: 7px; }
    .grid-2 .card { break-inside: avoid; }
    .alert { padding: 10px 12px; margin-bottom: 10px; }
}

input[type="password"], input[type="file"] {
    width: 100%; min-height: 54px; padding: 14px 16px; border: 1px solid #bfc8da; border-radius: 12px; font: inherit; font-size: 16px; background: #fff;
}
.check-row { display: flex; gap: 12px; align-items: flex-start; font-weight: 600; }
.check-row input { width: 20px; height: 20px; margin-top: 3px; flex: 0 0 auto; accent-color: var(--primary); }
.top-gap { margin-top: 18px; }
.summary-list { display: grid; gap: 8px; }
.summary-list > div { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.summary-list dt { font-weight: 800; }
.summary-list dd { margin: 0; }
code { background: #f1f3f8; padding: .12em .35em; border-radius: 5px; }


/* Tablet-Optimierung, insbesondere iPad Air im Hoch- und Querformat */
@media (min-width: 700px) and (max-width: 1200px) {
    .shell { width: min(94%, 1040px); }
    main.shell { padding-top: 28px; }
    .card { padding: clamp(28px, 4vw, 42px); }
    .question-card { max-width: 920px; }
    .question-prompt { font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1.18; }
    .option-list { gap: 14px; }
    .option-card { min-height: 64px; padding: 17px 19px; font-size: 1.08rem; }
    .option-card input { width: 24px; height: 24px; }
    .button { min-height: 56px; padding-inline: 22px; }
    .large-input { min-height: 60px; font-size: 18px; }
}

@media (orientation: landscape) and (min-width: 900px) and (max-width: 1400px) {
    .question-card { max-width: 980px; }
    .hero { grid-template-columns: minmax(0, 1fr) 240px; }
}

.character-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.character-key {
    appearance: none;
    min-width: 46px;
    min-height: 46px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #f7f8fc;
    color: var(--text);
    font: inherit;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
}
.character-key:active { transform: scale(.97); }
.orthography-note { border-left: 3px solid #2e90fa; padding-left: 10px; margin-top: 10px; color: #3b455b; font-size: .9rem; }

@media (min-width: 700px) and (max-width: 1200px) {
    .character-key { min-width: 52px; min-height: 52px; font-size: 1.2rem; }
}

/* v0.2.2: Durchlaufart und PIN-geschützte Ergebnisverwaltung */
.run-type-fieldset { border: 0; padding: 0; margin: 0 0 8px; }
.run-type-fieldset legend { font-weight: 900; margin-bottom: 10px; }
.run-type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.run-type-card {
    display: flex; gap: 12px; align-items: flex-start; min-height: 118px; padding: 16px;
    border: 2px solid var(--border); border-radius: 14px; cursor: pointer; background: #fff;
}
.run-type-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(64,87,214,.10); }
.run-type-card input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--primary); flex: 0 0 auto; }
.run-type-card span { display: grid; gap: 4px; }
.run-type-card strong { font-size: 1.05rem; }
.run-type-card small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.run-type-test:has(input:checked) { background: #fff7ed; border-color: #f79009; }
.run-type-real:has(input:checked) { background: #ecfdf3; border-color: #12b76a; }
.test-run-banner { border-width: 2px; }
.footer-inner { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.footer-inner a { color: var(--muted); text-decoration: none; }
.footer-inner a:hover { color: var(--primary); }
.admin-heading h1 { margin: 4px 0 10px; font-size: clamp(2rem, 5vw, 3.2rem); }
.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.filter-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-tabs a { text-decoration: none; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 9px 13px; font-weight: 800; }
.filter-tabs a span { color: var(--muted); margin-left: 5px; }
.filter-tabs a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.filter-tabs a.active span { color: #fff; }
.admin-results-card { padding-inline: clamp(16px, 3vw, 30px); }
.result-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.result-table { width: 100%; border-collapse: collapse; min-width: 920px; }
.result-table th, .result-table td { text-align: left; padding: 13px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.result-table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.result-table td small { display: block; color: var(--muted); margin-top: 3px; }
.admin-actions { display: flex; gap: 7px; align-items: center; }
.admin-actions form { margin: 0; }
.button-small { min-height: 40px; padding: 8px 11px; font-size: .86rem; }
.button-danger { background: #b42318; }
.button-danger:hover { background: #8f1c13; }
.run-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 54px; border-radius: 999px; padding: 5px 8px; font-size: .75rem; font-weight: 900; }
.run-real_diagnostic { color: #067647; background: #dcfae6; }
.run-technical_test { color: #b54708; background: #ffead5; }
.run-legacy { color: #475467; background: #eaecf0; }
.admin-back-actions { margin-bottom: 18px; }
.code-block { overflow-x: auto; padding: 16px; border-radius: 12px; background: #111827; color: #f9fafb; font-size: .9rem; }
.code-block code { background: transparent; padding: 0; color: inherit; }

@media (max-width: 760px) {
    .run-type-grid { grid-template-columns: 1fr; }
    .admin-toolbar { align-items: stretch; flex-direction: column; }
    .admin-toolbar > form .button { width: 100%; }
    .footer-inner { align-items: flex-start; flex-direction: column; }
}

/* v0.2.2: neutrale Schüler-Abschlussseite */
.completion-card {
    max-width: 760px;
    margin-inline: auto;
    text-align: center;
    padding-block: clamp(34px, 7vw, 68px);
}
.completion-icon {
    width: 92px;
    height: 92px;
    margin: 0 auto 22px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #dcfae6;
    color: #067647;
    font-size: 3.2rem;
    font-weight: 900;
    box-shadow: inset 0 0 0 1px #abefc6;
}
.completion-card h1 { font-size: clamp(2.4rem, 7vw, 4rem); margin: 6px 0 12px; }
.completion-lead { font-size: clamp(1.25rem, 3vw, 1.65rem); font-weight: 800; margin-bottom: 10px; }
.completion-note {
    display: grid;
    gap: 5px;
    margin: 28px auto;
    padding: 18px;
    max-width: 600px;
    border-radius: 14px;
    background: #eef1ff;
    color: var(--primary-dark);
}
.completion-note span { color: var(--muted); }
.completion-actions { justify-content: center; }
.completion-info { max-width: 900px; margin-inline: auto; }

/* v0.3.1: Verwaltungsnavigation, Import und Archiv */
.admin-actions { flex-wrap: wrap; }
.filter-tabs + .card,
.filter-tabs + .admin-toolbar,
.filter-tabs + .alert { margin-top: 18px; }

/* v0.3.2: Mehrfachauswahl und Bildaufgaben */
.bulk-action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 12px 0 16px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8f9fc;
}
.bulk-action-bar strong { margin-right: auto; }
.selection-column { width: 48px; text-align: center !important; }
.selection-column input { width: 20px; height: 20px; accent-color: var(--primary); }
.question-media {
    margin: 20px 0 24px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #f8f9fc;
    text-align: center;
}
.question-media a { display: block; }
.question-media img {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: min(58vh, 620px);
    margin: 0 auto;
    object-fit: contain;
    border-radius: 10px;
    background: #fff;
}
.question-media figcaption { margin-top: 10px; color: var(--muted); font-size: .92rem; }
.media-upload-form { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.file-button { position: relative; overflow: hidden; cursor: pointer; }
.file-button input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    min-height: 0;
    padding: 0;
}
@media (max-width: 760px) {
    .bulk-action-bar { align-items: stretch; }
    .bulk-action-bar strong { width: 100%; }
    .bulk-action-bar .button { flex: 1 1 100%; }
    .question-media { padding: 8px; }
}
