:root {
    --ink: #17352d;
    --muted: #64756f;
    --paper: #f3f5f0;
    --card: #fff;
    --line: #dce3dc;
    --green: #167a5b;
    --green-dark: #0e5c43;
    --lime: #b8e15b;
    --mint: #dff3e9;
    --sand: #f5ead3;
    --blue: #dfeaf5;
    --red: #b63d3d;
    --shadow: 0 18px 50px rgba(28, 57, 45, .10);
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    padding-bottom: 92px;
    color: var(--ink);
    background: radial-gradient(circle at 88% -10%, rgba(184,225,91,.35), transparent 34%), linear-gradient(180deg,#fbfcf8 0,var(--paper) 36%);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(22,122,91,.22); outline-offset: 2px; }
.hidden { display: none !important; }

.global-nav { position: absolute; inset: 22px 24px auto; z-index: 10; display: flex; justify-content: space-between; pointer-events: none; }
.global-nav a { display: flex; gap: 8px; align-items: center; color: rgba(255,255,255,.72); text-decoration: none; pointer-events: auto; }
.global-nav a:hover { color: var(--lime); }

.app-header {
    position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 32px; align-items: end;
    min-height: 290px; padding: 72px max(24px,calc((100vw - 1120px)/2)) 44px; color: #fff;
    background: linear-gradient(120deg,rgba(8,62,47,.98),rgba(23,122,91,.93)), repeating-linear-gradient(90deg,transparent 0 11%,rgba(255,255,255,.06) 11% 11.2%);
}
.app-header::after { content:""; position:absolute; width:360px; height:360px; right:-80px; bottom:-250px; border:38px solid rgba(184,225,91,.45); border-radius:50%; }
.header-copy { position:relative; z-index:1; max-width:760px; }
.eyebrow,.section-kicker { text-transform:uppercase; letter-spacing:.14em; font-size:.72rem; font-weight:850; }
.eyebrow { margin:0 0 14px; color:var(--lime); }
.header-copy h1 { margin:0; font-size:clamp(2.1rem,4.8vw,4.25rem); line-height:.98; letter-spacing:-.045em; }
.header-copy>p:last-child { margin:20px 0 0; max-width:650px; color:rgba(255,255,255,.78); font-size:1.05rem; line-height:1.55; }
.mode-switch { position:relative; z-index:1; display:flex; gap:7px; align-items:center; padding:8px; border:3px solid var(--lime); border-radius:18px; background:#fff; box-shadow:0 14px 34px rgba(0,27,19,.3); }
.mode-switch-label { display:flex; align-items:center; gap:7px; padding:0 12px 0 7px; border-right:1px solid var(--line); color:var(--green-dark); font-size:.72rem; font-weight:900; letter-spacing:.06em; text-transform:uppercase; white-space:nowrap; }
.mode-switch-label i { color:var(--green); font-size:.95rem; }
.mode-switch button { min-width:104px; border:2px solid transparent; border-radius:11px; padding:12px 18px; color:var(--green-dark); background:#edf3ef; font-weight:850; }
.mode-switch button:hover { border-color:#a8c9b9; background:#e4eee8; }
.mode-switch button.active { color:#fff; border-color:var(--green-dark); background:var(--green); box-shadow:0 4px 12px rgba(14,92,67,.25); }

.app-shell { position:relative; z-index:2; width:min(1120px,calc(100% - 32px)); margin:-24px auto 48px; }
.status-banner { margin-bottom:16px; padding:12px 16px; border:1px solid #bcd8ca; border-radius:14px; color:var(--green-dark); background:#eff8f2; text-align:center; font-weight:750; }
.status-banner.error { border-color:#e6bbbb; color:#892b2b; background:#fff0f0; }
.page { display:none; }
.page.active { display:block; animation:fade-in .22s ease-out; }
@keyframes fade-in { from { opacity:0; transform:translateY(6px); } }
.page-heading { display:flex; justify-content:space-between; gap:16px; align-items:end; margin:28px 2px 16px; }
.page-heading h2 { margin:5px 0 0; font-size:clamp(1.7rem,3.2vw,2.45rem); letter-spacing:-.035em; }
.section-kicker { color:var(--green); }
.toolbar-actions { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }

.panel { border:1px solid rgba(23,53,45,.09); border-radius:20px; background:rgba(255,255,255,.96); box-shadow:0 8px 28px rgba(28,57,45,.06); }
.two-column-layout { display:grid; grid-template-columns:300px minmax(0,1fr); gap:16px; }
.class-sidebar { padding:18px; }
.panel-title { display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; }
.panel-title span { min-width:28px; padding:5px 8px; border-radius:999px; color:var(--green-dark); background:var(--mint); text-align:center; font-size:.78rem; font-weight:850; }
.class-list { display:grid; gap:8px; }
.class-item { width:100%; display:flex; justify-content:space-between; align-items:center; gap:10px; padding:14px; border:1px solid transparent; border-radius:13px; color:var(--ink); background:#f8faf7; text-align:left; }
.class-item:hover { border-color:#bcd8ca; }
.class-item.active { border-color:var(--green); background:var(--mint); }
.class-item strong { display:block; }
.class-item small { color:var(--muted); white-space:nowrap; }
.list-empty { padding:26px 8px; color:var(--muted); text-align:center; line-height:1.5; }
.class-editor { padding:24px; }
.editor-head { display:flex; justify-content:space-between; align-items:start; gap:12px; margin-bottom:22px; }
.editor-head h3 { margin:5px 0 0; font-size:1.5rem; }
.roster-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.roster-grid label,.modal-card label { display:grid; gap:8px; color:var(--muted); font-size:.8rem; font-weight:800; }
.roster-grid textarea { min-height:270px; width:100%; resize:vertical; padding:14px; border:1px solid var(--line); border-radius:14px; color:var(--ink); background:#fbfcfa; line-height:1.55; }
.roster-grid label:first-child>span i { color:#327fc7; }
.roster-grid label:last-child>span i { color:#c64e83; }
.editor-footer { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-top:18px; color:var(--muted); font-size:.82rem; }
.empty-panel { display:grid; place-items:center; align-content:center; min-height:420px; padding:30px; color:var(--muted); text-align:center; }
.empty-panel>i { font-size:2.3rem; color:#a9bbb4; }
.empty-panel h3 { margin:16px 0 0; color:var(--ink); }
.empty-panel p { margin:7px 0 0; }

.btn,.icon-button { border:0; border-radius:12px; font-weight:780; transition:transform .16s,background .16s; }
.btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:42px; padding:10px 14px; }
.btn:hover:not(:disabled),.icon-button:hover:not(:disabled) { transform:translateY(-1px); }
.btn:disabled { opacity:.4; cursor:not-allowed; }
.btn.primary { color:#fff; background:var(--green); }
.btn.accent { color:var(--ink); background:var(--lime); }
.btn.ghost { color:var(--green-dark); border:1px solid var(--line); background:#fff; }
.btn.ghost.active { color:#fff; border-color:var(--green); background:var(--green); }
.btn.danger-subtle { color:var(--red); background:#fff0f0; }
.icon-button { display:grid; place-items:center; width:42px; height:42px; }
.icon-button.danger { color:var(--red); background:#fff0f0; }

.entry-controls { padding:18px; }
.control-grid { display:grid; grid-template-columns:1fr 1fr 1.4fr; gap:12px; }
.control-grid label,.result-filters label,.table-controls label { display:grid; gap:7px; color:var(--muted); font-size:.75rem; font-weight:850; }
select,input[type="text"],input[type="number"],.modal-card input { width:100%; min-height:46px; border:1px solid var(--line); border-radius:12px; padding:0 12px; color:var(--ink); background:#fbfcfa; }
.discipline-meta { display:flex; flex-wrap:wrap; gap:8px; min-height:24px; margin-top:14px; }
.meta-chip,.status-chip { display:inline-flex; align-items:center; gap:6px; padding:6px 9px; border-radius:999px; color:var(--green-dark); background:var(--mint); font-size:.74rem; font-weight:800; }
.status-chip.warn { color:#8a5b10; background:#fff1cf; }
.status-chip.bad { color:#8d3030; background:#ffe4e4; }
.action-strip { display:flex; flex-wrap:wrap; gap:8px; margin-top:16px; padding-top:16px; border-top:1px solid var(--line); }
.action-strip .danger-subtle { margin-left:auto; }
.rules-card { display:grid; grid-template-columns:repeat(4,1fr); gap:1px; overflow:hidden; margin:14px 0; border:1px solid #c5d7cc; border-radius:18px; background:#c5d7cc; }
.rules-card>div { display:flex; align-items:center; gap:12px; min-height:90px; padding:16px; background:#eff6f1; }
.rules-card i,.rule-number { display:grid; flex:0 0 36px; place-items:center; width:36px; height:36px; border-radius:11px; color:#fff; background:var(--green); font-size:1rem; font-weight:900; }
.rules-card p { margin:0; color:var(--muted); font-size:.78rem; line-height:1.4; }
.rules-card strong { color:var(--ink); }

.student-list { display:grid; gap:9px; }
.student-row { position:relative; display:grid; grid-template-columns:minmax(160px,.8fr) minmax(270px,1.6fr) minmax(130px,.58fr); gap:14px; align-items:center; padding:13px 15px; border:1px solid var(--line); border-left:5px solid #327fc7; border-radius:16px; background:#fff; box-shadow:0 4px 15px rgba(28,57,45,.04); }
.student-row.female { border-left-color:#c64e83; }
.student-row.selected { background:#f7fbec; box-shadow:0 0 0 2px rgba(184,225,91,.55); }
.student-main { display:flex; align-items:center; gap:10px; min-width:0; }
.select-student { width:20px; height:20px; accent-color:var(--green); }
.student-identity { min-width:0; }
.student-identity strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.student-identity small { color:var(--muted); }
.sort-actions { display:flex; gap:4px; margin-left:auto; }
.sort-actions button { width:32px; height:32px; border:1px solid var(--line); border-radius:9px; color:var(--green-dark); background:#fff; }
.measurement-area { display:flex; align-items:center; gap:8px; }
.measurement-input { min-width:0; flex:1; height:44px; border:1px solid var(--line); border-radius:11px; padding:0 11px; color:var(--ink); background:#fbfcfa; text-align:center; font-variant-numeric:tabular-nums; }
.measurement-input.invalid { border-color:#d67474; background:#fff4f4; }
.timed-values { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; flex:1; }
.timed-field { position:relative; min-width:0; }
.timed-field .measurement-input { width:100%; padding-top:12px; }
.timed-field span { position:absolute; z-index:1; top:4px; left:0; right:0; color:#92a19c; font-size:.61rem; font-weight:850; text-align:center; pointer-events:none; }
.attempts { display:grid; grid-template-columns:repeat(3,1fr); gap:6px; flex:1; }
.attempt { position:relative; }
.attempt input { width:100%; height:44px; border:1px solid var(--line); border-radius:11px; padding:13px 8px 0; color:var(--ink); background:#fbfcfa; text-align:center; }
.attempt span { position:absolute; top:4px; left:0; right:0; color:#92a19c; font-size:.61rem; font-weight:850; text-align:center; pointer-events:none; }
.timer-button { min-width:104px; min-height:44px; border:0; border-radius:11px; color:#fff; background:var(--green); font-weight:850; font-variant-numeric:tabular-nums; }
.timer-button.running { color:var(--ink); background:var(--lime); animation:pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow:0 0 0 5px rgba(184,225,91,.2); } }
.invalid-toggle { display:inline-flex; align-items:center; gap:6px; color:var(--muted); font-size:.72rem; white-space:nowrap; }
.invalid-toggle input { accent-color:var(--red); }
.u18-toggle { display:inline-flex; align-items:center; gap:6px; padding:5px 7px; border-radius:8px; color:#6d561c; background:#fff5d8; font-size:.7rem; font-weight:780; white-space:nowrap; }
.score-area { display:flex; justify-content:flex-end; align-items:center; gap:8px; }
.score-badge { min-width:94px; padding:9px 11px; border-radius:12px; color:var(--green-dark); background:var(--mint); text-align:center; }
.score-badge.empty { color:var(--muted); background:#f0f3f1; }
.score-badge.over { color:#654d0d; background:#edf8c8; }
.score-badge strong { display:block; font-size:1.12rem; }
.score-badge small { display:block; margin-top:2px; font-size:.64rem; }
.row-delete { width:34px; height:34px; border:0; border-radius:9px; color:#a25151; background:#fff0f0; }

.entry-empty,.results-empty { padding:52px 24px; border:1px dashed #b9c6c0; border-radius:20px; color:var(--muted); text-align:center; }
.entry-empty i,.results-empty i { display:block; margin-bottom:14px; color:#a9b8b2; font-size:2rem; }
.entry-empty strong,.results-empty strong { color:var(--ink); }

.result-filters,.table-controls { display:flex; align-items:end; gap:12px; padding:16px; margin-bottom:16px; }
.result-filters label,.table-controls label { flex:1; }
.table-actions { display:flex; gap:7px; }
.backup-actions { display:flex; gap:8px; margin-left:auto; }
.calculation-settings { margin-bottom:20px; padding:18px; }
.calculation-heading { display:flex; justify-content:space-between; align-items:center; gap:18px; }
.calculation-heading h3 { margin:4px 0 0; font-size:1.05rem; }
.calculation-mode { display:flex; flex-wrap:wrap; gap:8px; }
.calculation-mode label { display:flex; align-items:center; gap:6px; padding:8px 10px; border:1px solid var(--line); border-radius:11px; color:var(--muted); background:#fbfcfa; font-size:.76rem; font-weight:780; }
.calculation-mode input { accent-color:var(--green); }
.weighting-controls { display:grid; grid-template-columns:minmax(180px,.8fr) minmax(160px,1.2fr) minmax(120px,.5fr) auto; gap:14px; align-items:end; margin-top:16px; padding-top:14px; border-top:1px solid var(--line); }
.weighting-controls>label { display:grid; gap:8px; color:var(--muted); font-size:.78rem; font-weight:780; }
.weighting-controls strong { color:var(--ink); }
.weighting-controls input[type="range"] { width:100%; accent-color:var(--green); }
.technique-weight { align-self:center; }
.weight-balance { display:flex; overflow:hidden; height:12px; border-radius:999px; background:#edf1ee; }
.weight-balance span:first-child { background:var(--green); }
.weight-balance span:last-child { background:var(--lime); }
.weight-presets { display:flex; gap:5px; }
.weight-presets button { min-height:34px; padding:0 9px; border:1px solid var(--line); border-radius:9px; color:var(--green-dark); background:#fff; font-size:.72rem; font-weight:820; }
.normal-summary-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; margin-bottom:12px; }
.normal-summary-card { padding:14px; border:1px solid var(--line); border-radius:15px; background:#fff; }
.normal-summary-card header { display:flex; justify-content:space-between; gap:8px; margin-bottom:11px; }
.normal-summary-card header small { color:var(--muted); }
.normal-summary-values { display:grid; grid-template-columns:repeat(3,1fr); gap:7px; }
.normal-summary-values div { padding:8px; border-radius:10px; background:#f5f8f5; text-align:center; }
.normal-summary-values strong,.normal-summary-values small { display:block; }
.normal-summary-values strong { color:var(--green-dark); }
.normal-summary-values small { margin-top:2px; color:var(--muted); font-size:.62rem; }
.normal-summary-values .total { background:var(--mint); }
.result-section { margin:18px 0 28px; }
.result-section-head { display:flex; justify-content:space-between; align-items:center; margin:0 2px 10px; }
.result-section-head h3 { margin:0; font-size:1.25rem; }
.result-table-wrap { overflow:auto; border:1px solid var(--line); border-radius:17px; background:#fff; }
.result-table,.grading-table { width:100%; border-collapse:collapse; }
.result-table th,.result-table td,.grading-table th,.grading-table td { padding:12px 13px; border-bottom:1px solid #e7ece8; text-align:left; white-space:nowrap; }
.result-table th,.grading-table th { color:var(--muted); background:#f7f9f6; font-size:.72rem; text-transform:uppercase; letter-spacing:.07em; }
.result-table tr:last-child td,.grading-table tr:last-child td { border-bottom:0; }
.result-score { font-weight:900; color:var(--green-dark); }
.delete-result { border:0; border-radius:8px; padding:7px 9px; color:#a03e3e; background:#fff0f0; }
.abitur-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.abitur-card { padding:19px; border:1px solid var(--line); border-radius:19px; background:#fff; }
.abitur-card-head { display:flex; justify-content:space-between; gap:12px; align-items:start; }
.abitur-card h3 { margin:0; }
.abitur-card-head small { color:var(--muted); }
.abitur-score { min-width:88px; padding:10px; border-radius:13px; color:var(--green-dark); background:var(--mint); text-align:center; }
.abitur-score.locked { color:var(--muted); background:#eef1ef; }
.abitur-score strong { display:block; font-size:1.6rem; }
.abitur-score small { font-size:.65rem; }
.requirement-line { display:flex; flex-wrap:wrap; gap:6px; margin:14px 0; }
.discipline-results { display:grid; gap:6px; }
.discipline-result { display:grid; grid-template-columns:minmax(0,1fr) auto auto; gap:10px; align-items:center; padding:9px 10px; border-radius:11px; background:#f7f9f6; font-size:.78rem; }
.discipline-result span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.discipline-result strong { color:var(--green-dark); }
.discipline-result button { border:0; color:#a03e3e; background:transparent; }
.total-line { display:flex; justify-content:space-between; margin-top:13px; padding-top:12px; border-top:1px solid var(--line); font-size:.82rem; }

.source-note,.legal-note { margin-bottom:14px; padding:18px; }
.source-note { color:var(--muted); line-height:1.5; }
.source-note strong { color:var(--ink); }
.grading-table-container { overflow:auto; margin-bottom:14px; border:1px solid var(--line); border-radius:18px; background:#fff; }
.grading-table th:not(:first-child),.grading-table td:not(:first-child) { text-align:right; }
.grading-table tr.highlight td { color:var(--green-dark); background:#f4fae9; font-weight:850; }
.table-value-input { width:132px; min-height:38px; border:1px solid var(--line); border-radius:9px; padding:0 9px; color:var(--ink); background:#fbfcfa; text-align:right; font-variant-numeric:tabular-nums; }
.table-value-input:focus { border-color:var(--green); background:#fff; }
.table-value-input.invalid { border-color:#d67474; background:#fff4f4; }
.legal-note h3 { margin:0 0 8px; }
.legal-note p { margin:0; color:var(--muted); line-height:1.6; }

.bottom-nav { position:fixed; z-index:20; inset:auto 0 0; display:flex; justify-content:center; gap:8px; padding:10px 16px max(10px,env(safe-area-inset-bottom)); border-top:1px solid var(--line); background:rgba(255,255,255,.94); backdrop-filter:blur(12px); }
.bottom-nav button { display:grid; grid-template-columns:20px auto; gap:8px; align-items:center; border:0; border-radius:12px; padding:11px 16px; color:var(--muted); background:transparent; font-weight:780; }
.bottom-nav button.active { color:#fff; background:var(--green); }

.modal { position:fixed; z-index:50; inset:0; display:grid; place-items:center; padding:20px; background:rgba(8,35,27,.58); backdrop-filter:blur(4px); }
.modal-card { width:min(460px,100%); padding:26px; border-radius:21px; background:#fff; box-shadow:var(--shadow); }
.modal-card h3 { margin:6px 0 20px; font-size:1.6rem; }
.modal-card input { margin-top:4px; }
.modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:20px; }
.toast { position:fixed; z-index:60; left:50%; bottom:92px; max-width:min(440px,calc(100% - 30px)); padding:12px 16px; border-radius:13px; color:#fff; background:var(--ink); box-shadow:var(--shadow); opacity:0; pointer-events:none; transform:translate(-50%,12px); transition:.2s; text-align:center; }
.toast.show { opacity:1; transform:translate(-50%,0); }

@media (max-width:900px) {
    .app-header { grid-template-columns:1fr; align-items:start; padding-top:78px; }
    .mode-switch { justify-self:start; }
    .rules-card { grid-template-columns:repeat(2,1fr); }
    .student-row { grid-template-columns:minmax(140px,.8fr) minmax(260px,1.4fr); }
    .score-area { grid-column:1/-1; justify-content:flex-end; border-top:1px solid #edf0ee; padding-top:9px; }
    .abitur-grid { grid-template-columns:1fr; }
}

@media (max-width:720px) {
    .two-column-layout { grid-template-columns:1fr; }
    .class-sidebar { padding:14px; }
    .roster-grid { grid-template-columns:1fr; }
    .roster-grid textarea { min-height:180px; }
    .control-grid { grid-template-columns:1fr; }
    .student-row { grid-template-columns:1fr; gap:10px; }
    .score-area { grid-column:auto; }
    .measurement-area { flex-wrap:wrap; }
    .measurement-area>.measurement-input,.attempts,.timed-values { min-width:220px; }
    .action-strip .danger-subtle { margin-left:0; }
    .result-filters,.table-controls { align-items:stretch; flex-direction:column; }
    .result-filters label,.table-controls label { width:100%; }
    .table-actions { width:100%; }
    .table-actions .btn { flex:1; }
    .backup-actions { width:100%; margin-left:0; }
    .backup-actions .btn { flex:1; }
    .calculation-heading { align-items:flex-start; flex-direction:column; }
    .weighting-controls { grid-template-columns:1fr; }
    .normal-summary-grid { grid-template-columns:1fr; }
}

@media (max-width:580px) {
    .global-nav span { display:none; }
    .app-header { min-height:360px; padding-left:20px; padding-right:20px; }
    .app-shell { width:min(100% - 20px,1120px); }
    .mode-switch { width:100%; flex-wrap:wrap; }
    .mode-switch-label { width:100%; padding:3px 6px 8px; border-right:0; border-bottom:1px solid var(--line); }
    .mode-switch button { flex:1; min-width:0; }
    .page-heading { align-items:flex-start; flex-direction:column; }
    .toolbar-actions { width:100%; justify-content:flex-start; }
    .toolbar-actions .btn { flex:1; }
    .rules-card { grid-template-columns:1fr; }
    .editor-footer { align-items:stretch; flex-direction:column; }
    .attempts { min-width:100%; }
    .timer-button { flex:1; }
    .bottom-nav { justify-content:space-around; gap:0; }
    .bottom-nav button { grid-template-columns:1fr; gap:3px; min-width:58px; padding:8px 7px; font-size:.68rem; }
}

@media print {
    .global-nav,.app-header,.bottom-nav,.toolbar-actions,.result-filters,.calculation-settings { display:none !important; }
    body { padding:0; background:#fff; }
    .app-shell { width:100%; margin:0; }
    .page { display:none !important; }
    #page-results { display:block !important; }
}
