:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --panel-2: #f0eee9;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2dfd8;
  --accent: #d1453b;      /* German red */
  --accent-2: #b6372e;
  --accent-soft: #fbe9e7;
  --gold: #e0a100;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --warn: #b26a00;
  --warn-soft: #fff4dd;
  --info: #2563a8;
  --info-soft: #e6eef8;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416; --panel: #1d1d20; --panel-2: #26262a; --text: #ececee; --muted: #9a9aa2;
    --border: #33333a; --accent: #ef5b50; --accent-2: #ff7368; --accent-soft: #3a1f1d;
    --ok: #4cc27f; --ok-soft: #173325; --bad: #ff6b6b; --bad-soft: #3b1c1c; --warn: #f0b04a; --warn-soft: #3a2d14;
    --info: #6aa8ef; --info-soft: #182a40; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141416; --panel: #1d1d20; --panel-2: #26262a; --text: #ececee; --muted: #9a9aa2;
  --border: #33333a; --accent: #ef5b50; --accent-2: #ff7368; --accent-soft: #3a1f1d;
  --ok: #4cc27f; --ok-soft: #173325; --bad: #ff6b6b; --bad-soft: #3b1c1c; --warn: #f0b04a; --warn-soft: #3a2d14;
  --info: #6aa8ef; --info-soft: #182a40; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; }
.brand b { display: block; }
.brand small { display: block; font-size: .78rem; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidebar a:hover { background: var(--panel-2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .ic { width: 22px; text-align: center; }
.view { padding: 26px 32px 60px; max-width: 1180px; width: 100%; outline: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; overflow-x: auto; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { display: none; }
  .sidebar a { white-space: nowrap; padding: 6px 10px; font-size: .9rem; }
  .view { padding: 16px 16px 60px; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.flat { box-shadow: none; background: var(--panel-2); border-color: transparent; }
.card.click { cursor: pointer; transition: border-color .15s, transform .15s; text-decoration: none; color: inherit; display: block; }
.card.click:hover { border-color: var(--accent); }
.card h3 small { font-weight: 400; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.rec { background: var(--bad); border-color: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--bad-soft); } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
.field { margin-bottom: 12px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--panel-2); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.stat { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.bar { height: 9px; background: var(--panel-2); border-radius: 99px; overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--gold); }
.bar .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .55; }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text); border-left: 4px solid var(--info); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); border-color: var(--gold); }
.notice.bad { background: var(--bad-soft); border-color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }
.notice.info { background: var(--info-soft); border-color: var(--info); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }

.text-block { white-space: pre-wrap; background: var(--panel-2); padding: 14px 16px; border-radius: 10px; line-height: 1.7; }
.de { font-family: Georgia, "Times New Roman", serif; font-size: 1.04rem; }
.gap { display: inline-block; min-width: 46px; padding: 0 6px; border-bottom: 2px solid var(--accent); font-weight: 700; color: var(--accent); text-align: center; cursor: pointer; }
.gap.filled { background: var(--accent-soft); border-radius: 4px 4px 0 0; }
.gap.right { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.gap.wrong { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }

.q { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.q:last-child { border-bottom: 0; }
.q .num { display: inline-grid; place-items: center; min-width: 26px; height: 26px; border-radius: 7px; background: var(--panel-2); font-weight: 700; margin-right: 6px; font-size: .85rem; }
.opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.opts.inline { flex-direction: row; flex-wrap: wrap; }
.opt { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; background: var(--panel); }
.opt:hover { border-color: var(--accent); }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt b { min-width: 16px; }
.letters { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.letters button { width: 34px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; font-weight: 700; }
.letters button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.letters button.right { background: var(--ok); color: #fff; border-color: var(--ok); }
.letters button.wrong { background: var(--bad); color: #fff; border-color: var(--bad); }
.letters button.used { opacity: .45; }
.explain { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--info-soft); font-size: .92rem; }

.flash { min-height: 220px; display: grid; place-items: center; text-align: center; cursor: pointer; padding: 26px; }
.flash .word { font-size: 2rem; font-weight: 700; }
.flash .art-der { color: #2563a8; } .flash .art-die { color: #c2185b; } .flash .art-das { color: #1f8a4c; }
.art-der { color: #2563a8; } .art-die { color: #c2185b; } .art-das { color: #1f8a4c; }

.chat { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; }
.msg.ai { background: var(--panel-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--accent-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .tr { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.msg .fix { margin-top: 6px; font-size: .86rem; border-top: 1px dashed var(--border); padding-top: 6px; }
.interim { color: var(--muted); font-style: italic; min-height: 1.4em; }
.md p { margin: 0 0 8px; } .md ul { margin: 0 0 8px; padding-left: 20px; } .md code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

.corr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.corr .o { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.corr .c { color: var(--ok); font-weight: 600; }
.corr .e { grid-column: 1 / -1; font-size: .88rem; color: var(--muted); }
@media (max-width: 640px) { .corr { grid-template-columns: 1fr; } }

.grade { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; font-weight: 800; color: #fff; background: var(--muted); }
.grade.A { background: var(--ok); } .grade.B { background: #5b9e3a; } .grade.C { background: var(--gold); } .grade.D { background: var(--bad); }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 8px; background: var(--panel-2); }
.timer.low { background: var(--bad-soft); color: var(--bad); }

.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.split .sticky { position: sticky; top: 12px; }
@media (max-width: 960px) { .split { grid-template-columns: 1fr; } .split .sticky { position: static; } }
.pdf { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

.list { display: flex; flex-direction: column; }
.list > div, .list > a { padding: 10px 2px; border-bottom: 1px solid var(--border); }
.list > :last-child { border-bottom: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--border); }
.check:last-child { border-bottom: 0; }
.check .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--border); flex: none; display: grid; place-items: center; font-size: .8rem; }
.check.done .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.done .t { text-decoration: line-through; color: var(--muted); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 18px 0; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--panel-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(120px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; transition: transform .25s, visibility .25s; z-index: 99; max-width: calc(100% - 32px); visibility: hidden; }
.toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
.toast.err { background: var(--bad); color: #fff; }

.kbd { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; }
.hbars .hb { display: grid; grid-template-columns: 140px 1fr 36px; gap: 8px; align-items: center; margin: 5px 0; font-size: .9rem; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }
.hl { background: #fff3a8; color: #000; border-radius: 3px; padding: 0 2px; }

/* vocabulary gender cues & matching game */
.g-der { --g: #2563a8; } .g-die { --g: #c2185b; } .g-das { --g: #1f8a4c; }
.card.gcard { border: 2px solid var(--g, var(--border)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--g, transparent) 12%, transparent); }
.pairs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 700px) { .pairs { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.pcard { border: 2px solid var(--border); border-radius: 12px; background: var(--panel); min-height: 84px; display: grid; place-items: center; text-align: center; padding: 6px; cursor: pointer; overflow: hidden; }
.pcard .pcard.sel { border-color: var(--accent); background: var(--accent-soft); }
.pcard.done { opacity: .55; pointer-events: none; border-color: var(--g, var(--ok)); color: var(--g, inherit); }
.pcard.bad { border-color: var(--bad); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
[hidden] { display: none !important; }
