:root {
  --bg: #dde1e7;
  --surface: #f5f6f8;
  --surface-2: #e7eaef;
  --sidebar: #e6e9ee;
  --border: #ccd2db;
  --border-strong: #b3bbc7;
  --text: #141922;
  --muted: #586273;
  --primary: #3450c4;
  --primary-ink: #ffffff;
  --primary-soft: #dfe5f7;
  --good: #17723f;
  --good-soft: #dcefe3;
  --mid: #93540a;
  --mid-soft: #f4e8d2;
  --bad: #b3322a;
  --bad-soft: #f5dfdd;
  --focus: #e09412;
  --code-bg: #eceff3;
  --ka: #3450c4;
  --ka-soft: #dfe5f7;
  --nw: #0b7485;
  --nw-soft: #d6ecef;
  --wiso: #a86a0b;
  --wiso-soft: #f2e6cf;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 0.6em; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; }
h1, h2, h3 { overflow-wrap: break-word; }
h1 { hyphens: auto; }

h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; margin-top: 1.3em; }
h4 { font-size: 0.95rem; margin-top: 1em; }
p { margin: 0 0 0.8em; }
ul, ol { padding-left: 1.3em; margin: 0 0 0.8em; }
li { margin-bottom: 0.25em; }
code, pre, kbd { font-family: var(--mono); font-size: 0.88em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
td code, th code { overflow-wrap: normal; }
table.grid td code, table.task-table td code { white-space: nowrap; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; padding: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* ------------------------------------------------------------ Layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: rgba(245, 246, 248, 0.94); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); font-size: 13px; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { font-size: 0.75rem; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; margin-left: 4px; }
.topbar-progress { margin-left: auto; width: 220px; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 40px; height: 40px; font-size: 20px; cursor: pointer; }

.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidebar {
  position: sticky; top: 56px; align-self: start;
  height: calc(100vh - 56px); height: calc(100dvh - 56px); overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 12px 24px; border-right: 1px solid var(--border); background: var(--sidebar);
}
.nav-group { display: flex; align-items: center; gap: 8px; margin: 18px 8px 6px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 7px; color: var(--text); text-decoration: none; font-size: 0.94rem; }
.nav-link:hover { background: rgba(255, 255, 255, 0.55); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.sub { padding-left: 28px; font-size: 0.88rem; color: var(--muted); }
.nav-link.sub.active { color: var(--primary); }
.nav-icon { width: 20px; text-align: center; flex: none; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-badge { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-note, .nav-warning { margin: 18px 8px 0; font-size: 0.78rem; color: var(--muted); }
.nav-warning { color: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ka { background: var(--ka); }
.dot.nw { background: var(--nw); }
.dot.wiso { background: var(--wiso); }

main { padding: 28px clamp(16px, 3.2vw, 44px) 64px; max-width: 1240px; width: 100%; outline: none; }
main:focus, main:focus-visible { outline: none; }
main { overflow-wrap: break-word; }

@media (max-width: 920px) {
  .menu-btn { display: block; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; width: 288px; z-index: 30;
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 8px 30px rgba(16, 24, 40, 0.12);
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open::after { content: ''; position: fixed; inset: 56px 0 0; background: rgba(16, 24, 40, 0.28); z-index: 25; }
  .topbar-progress { width: 120px; }
  main { padding: 20px 16px 48px; }
}
@media (max-width: 520px) {
  .topbar-progress .progress-text { display: none; }
  .topbar-progress { width: 64px; }
  .brand-sub { display: none; }
}
@media (max-width: 380px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar-progress { display: none; }
  .topbar-account { margin-left: auto; }
}
@media (max-width: 350px) {
  .brand strong { display: none; }
}

/* ------------------------------------------------------------ Bausteine */
.page-head { margin-bottom: 22px; }
.back-link { display: inline-block; margin-bottom: 10px; text-decoration: none; font-size: 0.9rem; }
.lead { font-size: 1.04rem; color: var(--muted); max-width: 78ch; }
.eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }

.box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.box.flat { box-shadow: none; }
.box.tip { background: var(--primary-soft); border-color: transparent; }
.box.warn { background: var(--mid-soft); border-color: transparent; }
.box.error { border-color: var(--bad); }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.box-head h2, .box-head h3 { margin: 0; }
details.box > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.box > summary::-webkit-details-marker { display: none; }
details.box > summary::before { content: "›"; display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; font-size: 1.2em; line-height: 1; }
details.box[open] > summary::before { transform: rotate(90deg); }
.details-body { margin-top: 12px; }
.hint { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); margin: 12px 0 0; font-size: 0.94rem; }
.hint.warn { background: var(--mid-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 0.94rem; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.4;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 0.84rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.actions .spacer { flex: 1; }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 7px; padding: 7px 10px; min-width: 0;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 3px solid var(--primary-soft); }
select { max-width: 100%; }
.actions > label { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
@media (max-width: 600px) {
  /* iOS zoomt bei Eingabefeldern unter 16px automatisch hinein */
  input[type="text"], input[type="number"], input[type="password"], select, textarea { font-size: 16px; }
  .actions > label { display: flex; flex-direction: column; align-items: stretch; width: 100%; gap: 3px; }
  .actions > .btn { flex: 1 1 auto; }
}
textarea { width: 100%; resize: vertical; min-height: 120px; line-height: 1.5; }
textarea.code-input { font-family: var(--mono); font-size: 0.9rem; line-height: 1.55; tab-size: 4; white-space: pre; overflow-x: auto; background: var(--code-bg); }
pre.code-model { background: var(--code-bg); tab-size: 4; margin: 6px 0 12px; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.mid { background: var(--mid-soft); color: var(--mid); }
.pill.low { background: var(--bad-soft); color: var(--bad); }
.pill.ka { background: var(--ka-soft); color: var(--ka); }
.pill.nw { background: var(--nw-soft); color: var(--nw); }
.pill.wiso { background: var(--wiso-soft); color: var(--wiso); }
.tag { display: inline-block; padding: 0 7px; border-radius: 5px; font-size: 0.74rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.prio { display: inline-flex; gap: 1px; font-size: 0.8rem; letter-spacing: 1px; color: var(--border-strong); white-space: nowrap; }
.prio .on { color: #e0a100; }
.prio-label { font-size: 0.75rem; font-weight: 650; }
.prio-3 { color: var(--bad); }
.prio-2 { color: var(--mid); }
.prio-1 { color: var(--muted); }

.progress { display: block; position: relative; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress:has(.progress-text) { height: 18px; }
.progress-fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s ease; }
.progress-fill.good { background: var(--good); }
.progress-fill.mid { background: #d99a2b; }
.progress-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.72rem; font-weight: 650; color: var(--text); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0;
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px;
  transition: all 0.25s ease; z-index: 50; pointer-events: none; max-width: calc(100vw - 32px);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

.pager { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------ Dashboard */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; align-items: center; margin-bottom: 26px; }
.hero h1 { font-size: 1.9rem; }
.hero-progress { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; text-align: center; }
.big-number { font-size: 2.3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }

.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
@media (max-width: 980px) { .cat-grid { grid-template-columns: minmax(0, 1fr); } }
.cat-card {
  display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  border-top: 3px solid var(--muted); transition: border-color 0.15s, box-shadow 0.15s;
}
.cat-card:hover { box-shadow: 0 4px 16px rgba(16, 24, 40, 0.06); }
.cat-card.ka { border-top-color: var(--ka); }
.cat-card.nw { border-top-color: var(--nw); }
.cat-card.wiso { border-top-color: var(--wiso); }
.cat-card h3 { margin: 0; font-size: 1.05rem; }
.cat-card p { margin: 0; font-size: 0.9rem; }
.cat-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; margin-bottom: 26px; }
.topic-card {
  display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.topic-card:hover { border-color: var(--primary); }
.topic-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.topic-card h3 { margin: 0; font-size: 1rem; }
.topic-card p { font-size: 0.86rem; margin: 0; color: var(--muted); }
.topic-card .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); }

.list-plain { list-style: none; padding: 0; margin: 0; }
.steps-list { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.steps-list > li { counter-increment: s; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: start; }
.steps-list > li::before { content: counter(s); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 0.8rem; }

/* ------------------------------------------------------------ Analyse */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
table.data th, table.data td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
table.data thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; background: var(--surface); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data a { text-decoration: none; font-weight: 550; }
table.data a:hover { text-decoration: underline; }
table.heat td.cell { text-align: center; width: 34px; padding: 6px 2px; }
table.heat th.exam { text-align: center; padding: 6px 2px; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-size: 0.72rem; height: 78px; }
.hit { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--primary); }
.hit.ka { background: var(--ka); }
.hit.nw { background: var(--nw); }
.hit.wiso { background: var(--wiso); }
.miss { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--surface-2); }
.bar-inline { display: inline-block; height: 8px; border-radius: 4px; background: var(--primary); vertical-align: middle; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--surface); color: var(--text); padding: 6px 14px; font: inherit; font-size: 0.88rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

/* ------------------------------------------------------------ Theorie */
.theory { max-width: 900px; }
.theory table, table.grid { border-collapse: collapse; width: 100%; margin: 10px 0 16px; font-size: 0.93rem; }
.theory th, .theory td, table.grid th, table.grid td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.theory thead th, table.grid thead th { background: var(--surface-2); font-weight: 650; }
.theory .tip, .callout { background: var(--primary-soft); padding: 10px 14px; border-radius: 8px; margin: 14px 0; }
.theory .warn, .callout.warn { background: var(--mid-soft); padding: 10px 14px; border-radius: 8px; margin: 14px 0; }
.theory .formula, .formula { font-family: var(--mono); background: var(--surface-2); padding: 8px 12px; border-radius: 8px; display: block; margin: 8px 0 12px; white-space: pre-wrap; font-size: 0.9rem; overflow-x: auto; }
@media (max-width: 640px) {
  .theory table, table.grid, .cheat-card table, .solution table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .theory th, .theory td, table.grid th, table.grid td { padding: 5px 7px; }
  .cheat { columns: 1; }
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { padding: 6px 13px; border-radius: 999px; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); font-size: 0.88rem; cursor: pointer; font: inherit; font-size: 0.88rem; }
.tab.active { background: var(--text); border-color: var(--text); color: #fff; }

/* ------------------------------------------------------------ Aufgaben */
.task-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 22px; }
.task-row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); text-decoration: none;
}
.task-row:hover { border-color: var(--primary); }
.task-row .kind { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); font-size: 1rem; }
.task-row .kind.gen { background: var(--primary-soft); }
.task-row .title { font-weight: 600; }
.task-row .sub { font-size: 0.84rem; color: var(--muted); }
.task-row .right { display: flex; gap: 8px; align-items: center; }
@media (max-width: 600px) {
  .task-row { grid-template-columns: 32px minmax(0, 1fr); gap: 4px 10px; padding: 11px 12px; }
  .task-row .right { grid-column: 2; flex-wrap: wrap; }
}

.task { max-width: 920px; }
.scenario { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-size: 0.95rem; }
.scenario p:last-child { margin-bottom: 0; }
.scenario table { background: var(--surface); }
.scenario table:last-child { margin-bottom: 0; }
.scenario pre { background: var(--surface); margin: 8px 0 0; }
.scenario details summary { cursor: pointer; color: var(--primary); }
.prompt { margin-bottom: 14px; }
.prompt p:last-child { margin-bottom: 0; }
.fields { display: grid; gap: 10px; margin: 14px 0 4px; }
.field { display: grid; grid-template-columns: minmax(150px, 260px) minmax(0, 1fr); gap: 12px; align-items: center; }
.field-label { font-size: 0.93rem; }
.field-input { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field-input input, .field-input select { width: 100%; max-width: 320px; font-family: var(--mono); }
.field-input select { font-family: inherit; }
.field-unit { color: var(--muted); font-size: 0.9rem; }
.field-feedback { flex-basis: 100%; font-size: 0.85rem; }
.field.correct input, .field.correct select, td.correct input, td.correct select { border-color: var(--good); background: var(--good-soft); }
.field.wrong input, .field.wrong select, td.wrong input, td.wrong select { border-color: var(--bad); background: var(--bad-soft); }
.field.wrong .field-feedback, td.wrong .field-feedback { color: var(--bad); }
@media (max-width: 640px) { .field { grid-template-columns: 1fr; gap: 4px; } }

table.task-table { border-collapse: collapse; width: 100%; font-size: 0.92rem; margin: 10px 0; }
table.task-table th, table.task-table td { border: 1px solid var(--border); padding: 5px 7px; text-align: left; vertical-align: middle; }
table.task-table thead th { background: var(--surface-2); font-weight: 650; white-space: nowrap; }
table.task-table input, table.task-table select { width: 100%; min-width: 64px; padding: 5px 7px; font-family: var(--mono); font-size: 0.9rem; }
table.task-table td.given { color: var(--text); background: var(--surface); font-variant-numeric: tabular-nums; }
table.task-table td.fb-cell { font-size: 0.8rem; }
table.task-table .field-feedback { display: block; margin-top: 2px; font-size: 0.78rem; }

.result-bar { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 8px; margin-top: 16px; background: var(--surface-2); }
.result-bar.good { background: var(--good-soft); }
.result-bar.mid { background: var(--mid-soft); }
.result-bar.low { background: var(--bad-soft); }
.result-score { white-space: nowrap; font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.result-bar.good .result-score { color: var(--good); }
.result-bar.mid .result-score { color: var(--mid); }
.result-bar.low .result-score { color: var(--bad); }

.solution { margin-top: 16px; border: 1px solid var(--border); border-left: 3px solid var(--good); border-radius: 8px; padding: 14px 16px; background: var(--surface); }
.solution h3 { margin-top: 0; font-size: 0.98rem; color: var(--good); }
.solution .steps-list > li::before { background: var(--good-soft); color: var(--good); }
.solution .formula { background: var(--surface-2); }
.solution table { border-collapse: collapse; margin: 8px 0; font-size: 0.9rem; }
.solution table th, .solution table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.solution table thead th { background: var(--surface-2); }
.bin { font-family: var(--mono); letter-spacing: 0.04em; }
.bin .net { color: var(--primary); font-weight: 700; }
.bin .host { color: var(--wiso); }

.code-block { font-family: var(--mono); font-size: 0.88rem; background: var(--code-bg); tab-size: 4; border: 1px solid var(--border); border-radius: 8px; padding: 10px 0; overflow-x: auto; counter-reset: ln; margin: 8px 0 14px; }
.code-line { display: block; padding: 0 14px 0 0; white-space: pre; line-height: 1.55; }
.code-line::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 34px; padding-right: 10px; margin-right: 10px; text-align: right; color: var(--muted); border-right: 1px solid var(--border); }
.code-line .kw { color: #6d28d9; font-weight: 600; }
.code-line .ind { display: inline-block; box-shadow: inset 1px 0 0 rgba(52, 80, 196, 0.22); }
.code-line .cm { color: var(--muted); font-style: italic; }

/* Zuordnen */
.assign-list { display: grid; gap: 8px; margin: 12px 0; }
.assign-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 260px); gap: 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.assign-row.correct { border-color: var(--good); background: var(--good-soft); }
.assign-row.wrong { border-color: var(--bad); background: var(--bad-soft); }
.assign-row select { width: 100%; }
.assign-row .why { grid-column: 1 / -1; font-size: 0.84rem; color: var(--muted); }
@media (max-width: 600px) { .assign-row { grid-template-columns: 1fr; } }

/* Freitext */
.keypoints { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.keypoints li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.keypoints li.checked { background: var(--good-soft); border-color: transparent; }
.keypoints input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--good); }
.keypoints .pts { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.op-hint { font-size: 0.84rem; color: var(--muted); }

/* Quiz */
.quiz-card { max-width: 820px; }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; color: var(--muted); font-size: 0.88rem; }
.question { margin: 14px 0 8px; font-size: 1.12rem; font-weight: 600; }
.options { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 12px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 10px 13px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.missed { border-color: var(--good); border-style: dashed; }
.option:disabled { cursor: default; }
.option-key { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--surface-2); font-weight: 700; font-size: 0.82rem; }
.explain { margin-top: 14px; padding: 12px 14px; border-radius: 9px; }
.explain.ok { background: var(--good-soft); }
.explain.err { background: var(--bad-soft); }
.stat-list { display: grid; gap: 10px; margin-bottom: 12px; }
.stat-row { display: grid; grid-template-columns: 240px 1fr; gap: 12px; align-items: center; }
@media (max-width: 600px) { .stat-row { grid-template-columns: 1fr; gap: 4px; } }
.topic-row { display: grid; grid-template-columns: 240px 1fr; align-items: center; gap: 12px; padding: 7px 10px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; width: 100%; }
.topic-row:hover { background: var(--surface-2); }
@media (max-width: 600px) { .topic-row { grid-template-columns: 1fr; gap: 4px; } }

/* ------------------------------------------------------------ Prüfungssimulation */
.exam-bar { position: sticky; top: 56px; z-index: 10; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 14px; margin: 0 0 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.exam-timer { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.exam-timer.low { color: var(--bad); }
.exam-section { margin-bottom: 26px; }
.exam-section > h2 { display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------------------ Cheat-Sheets */
.cheat { columns: 2 380px; column-gap: 18px; }
.cheat-card { break-inside: avoid; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 16px; font-size: 0.9rem; }
.cheat-card h3 { margin: 0 0 8px; font-size: 0.98rem; display: flex; align-items: center; gap: 8px; }
.cheat-card table { border-collapse: collapse; width: 100%; margin: 6px 0 10px; font-size: 0.85rem; }
.cheat-card th, .cheat-card td { border: 1px solid var(--border); padding: 3px 6px; text-align: left; vertical-align: top; }
.cheat-card thead th { background: var(--surface-2); }
.cheat-card ul { padding-left: 1.1em; margin-bottom: 6px; }
.cheat-card li { margin-bottom: 2px; }
.cheat-card .formula { font-size: 0.8rem; padding: 6px 9px; margin: 4px 0 8px; white-space: pre; overflow-x: auto; }
.cheat-card p { margin-bottom: 6px; }
.cheat-card ol { padding-left: 1.3em; margin-bottom: 6px; }
.cheat-card .ex { background: var(--primary-soft); border-radius: 6px; padding: 6px 9px; font-size: 0.84rem; }
.cheat-card .why { color: var(--muted); font-size: 0.84rem; border-left: 3px solid var(--border-strong); padding-left: 8px; }
.cheat-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.cheat-toolbar .btn { white-space: normal; text-align: left; }

/* ------------------------------------------------------------ Konto & Admin */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.topbar-account { flex: none; }
.account-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 180px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--text); text-decoration: none; font-size: 0.86rem; font-weight: 600; background: var(--surface); }
a.btn.account-chip { border-color: var(--border-strong); }
.account-chip:hover { border-color: var(--primary); }
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync-dot.saving { background: var(--primary); animation: pulse 1s ease-in-out infinite; }
.sync-dot.offline { background: #d99a2b; }
.sync-dot.expired { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .sync-dot.saving { animation: none; } }

.auth-box { max-width: 460px; }
.form-row { display: grid; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 0.9rem; font-weight: 600; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; margin-top: 14px; }
.check-row { display: flex; gap: 8px; align-items: flex-start; font-size: 0.92rem; margin: 4px 0 8px; cursor: pointer; }
.check-row input { margin-top: 4px; }
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: 7px; padding: 8px 10px; font-size: 0.92rem; }
.user-table td { vertical-align: middle; }
.user-table .progress-cell { min-width: 150px; }
.role-pill { margin-left: 6px; }
.page-head + .hint { margin: 0 0 16px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions .btn { white-space: nowrap; }

/* ------------------------------------------------------------ Smartphone */
@media (max-width: 600px) {
  h1 { font-size: 1.42rem; }
  .btn { white-space: normal; }
  .pill { white-space: normal; max-width: 100%; }
  .option { min-width: 0; }
  .option > span { min-width: 0; overflow-wrap: break-word; hyphens: auto; }
  .box { padding-left: 14px; padding-right: 14px; }
  .scenario { padding: 10px 11px; }
  .cheat-card { padding: 12px 12px; }
  .solution { padding: 12px; }
  .steps-list > li { grid-template-columns: 24px minmax(0, 1fr); gap: 8px; }
  .exam-section > h2 { flex-wrap: wrap; row-gap: 2px; }
  .account-chip { max-width: 112px; padding: 4px 9px; }
}

@media (max-width: 640px) {
  /* Schatten am Rand zeigen, dass die Tabelle seitlich scrollt */
  table.grid, .theory table, .cheat-card table, .solution table {
    background: linear-gradient(90deg, var(--surface) 30%, transparent) left / 24px 100% no-repeat local,
      linear-gradient(270deg, var(--surface) 30%, transparent) right / 24px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(16, 24, 40, 0.18), transparent) left / 10px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(16, 24, 40, 0.18), transparent) right / 10px 100% no-repeat scroll,
      var(--surface);
  }
}

@media print {
  body:has(.credentials) main > :not(.credentials):not(div:has(.credentials)) { display: none !important; }
  @page { margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .cheat-card .formula, .cheat-card .ex { background: #f1f1f1; }
  .topbar, .sidebar, .cheat-toolbar, .page-head .back-link, .no-print, #toast { display: none !important; }
  .layout { display: block; }
  main { padding: 0; max-width: none; }
  .cheat { columns: 2; column-gap: 10px; }
  .cheat-card { background: #fff; border-color: #bbb; padding: 8px 10px; margin-bottom: 8px; font-size: 10px; box-shadow: none; }
  .cheat-card h3 { font-size: 11.5px; }
  .cheat-card table { font-size: 9.5px; }
  .cheat-card .formula { font-size: 8.5px; overflow: visible; white-space: pre-wrap; }
  .page-head h1 { font-size: 16px; margin-bottom: 4px; }
  .page-head .lead { font-size: 10px; }
  a { color: inherit; text-decoration: none; }
}
