/* ---------- tokens ---------- */
:root {
  --bg: #f3f4f6;
  --bg-soft: #f9fafb;
  --paper: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #93c5fd;
  --code-bg: #eef2ff;
  --pill-bg: #dbeafe;  --pill-ink: #1e40af;
  --ok-bg: #dcfce7;    --ok-ink: #15803d;   --ok-line: #bbf7d0;
  --warn-bg: #fef3c7;  --warn-ink: #b45309; --warn-line: #fde68a;
  --err-bg: #fee2e2;   --err-ink: #b91c1c;  --err-line: #fecaca;
  --mark-x-bg: #e5e7eb; --mark-x-ink: #111827;
  --mark-5-bg: #dcfce7; --mark-5-ink: #166534;
  --mark-4-bg: #dbeafe; --mark-4-ink: #1e40af;
  --mark-3-bg: #fef3c7; --mark-3-ink: #92400e;
  --mark-2-bg: #fee2e2; --mark-2-ink: #991b1b;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }

/* dark palette: applied by explicit choice or by system preference (unless forced light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --bg-soft: #1b1f27; --paper: #171a21; --ink: #e5e7eb; --muted: #9aa3b2; --faint: #6b7280;
    --line: #2a2f3a; --line-strong: #3b4252; --accent: #60a5fa; --accent-ink: #0b1020; --accent-soft: #1d4ed8;
    --code-bg: #232a3b; --pill-bg: #1e3a8a; --pill-ink: #bfdbfe;
    --ok-bg: #14532d; --ok-ink: #bbf7d0; --ok-line: #166534;
    --warn-bg: #4a2f05; --warn-ink: #fde68a; --warn-line: #78350f;
    --err-bg: #4c1d1d; --err-ink: #fecaca; --err-line: #7f1d1d;
    --mark-x-bg: #2a2f3a; --mark-x-ink: #e5e7eb;
    --mark-5-bg: #14532d; --mark-5-ink: #bbf7d0;
    --mark-4-bg: #1e3a8a; --mark-4-ink: #bfdbfe;
    --mark-3-bg: #4a2f05; --mark-3-ink: #fde68a;
    --mark-2-bg: #4c1d1d; --mark-2-ink: #fecaca;
    --shadow: 0 1px 3px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-soft: #1b1f27; --paper: #171a21; --ink: #e5e7eb; --muted: #9aa3b2; --faint: #6b7280;
  --line: #2a2f3a; --line-strong: #3b4252; --accent: #60a5fa; --accent-ink: #0b1020; --accent-soft: #1d4ed8;
  --code-bg: #232a3b; --pill-bg: #1e3a8a; --pill-ink: #bfdbfe;
  --ok-bg: #14532d; --ok-ink: #bbf7d0; --ok-line: #166534;
  --warn-bg: #4a2f05; --warn-ink: #fde68a; --warn-line: #78350f;
  --err-bg: #4c1d1d; --err-ink: #fecaca; --err-line: #7f1d1d;
  --mark-x-bg: #2a2f3a; --mark-x-ink: #e5e7eb;
  --mark-5-bg: #14532d; --mark-5-ink: #bbf7d0;
  --mark-4-bg: #1e3a8a; --mark-4-ink: #bfdbfe;
  --mark-3-bg: #4a2f05; --mark-3-ink: #fde68a;
  --mark-2-bg: #4c1d1d; --mark-2-ink: #fecaca;
  --shadow: 0 1px 3px rgba(0,0,0,.5);
}

/* ---------- scale ---------- */
:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r1: 6px; --r2: 10px; --r3: 14px;
  --t-xs: .78rem; --t-sm: .875rem; --t-md: 1rem; --t-lg: 1.15rem; --t-xl: 1.4rem;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--t-md);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: var(--t-xl); margin: 0; line-height: 1.2; }
h2 { font-size: var(--t-lg); margin: 0; line-height: 1.25; }
h3 { font-size: var(--t-md); margin: var(--s4) 0 var(--s2); }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--code-bg); padding: .05em .3em; border-radius: var(--r1); }
.muted { color: var(--muted); }
.small { font-size: var(--t-sm); }
.container { max-width: 880px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }
.container.wide { max-width: 1400px; }
.container.plan { max-width: 1180px; }
.print-only { display: none !important; }
.short { display: none; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s4); background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; }
.topbar nav { display: flex; gap: var(--s4); align-items: center; }
.topbar nav a { color: var(--muted); padding: var(--s1) 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--ink); border-color: var(--accent); font-weight: 500; }
.inline { display: inline; }
.linklike { border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; padding: var(--s1) 0; }
.linklike:hover { color: var(--ink); }
.theme-btn { border: 1px solid var(--line); background: var(--paper); border-radius: var(--r1); padding: 3px 8px; cursor: pointer; font: inherit; color: var(--muted); line-height: 1; }
.theme-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 0 var(--s3); border-radius: var(--r1); border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font: inherit; font-size: var(--t-sm); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--bg-soft); border-color: var(--line); color: var(--ink); }
.btn-icon { width: 36px; padding: 0; font-size: var(--t-md); }
.btn-danger { color: var(--err-ink); }
.pill { display: inline-block; font-size: var(--t-xs); padding: 1px var(--s2); border-radius: 999px; background: var(--pill-bg); color: var(--pill-ink); vertical-align: middle; font-weight: 500; }
.pill-ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill-error { background: var(--err-bg); color: var(--err-ink); }
.pill-new { background: var(--warn-ink); color: var(--paper); }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------- page toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.nav-group { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.page-title { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-xl); }
.cap::first-letter { text-transform: uppercase; }
.actions { display: flex; align-items: center; gap: var(--s2); }

.alert { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r2); margin: 0 0 var(--s4); border: 1px solid; font-size: var(--t-sm); }
.alert-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.alert-error { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); }

/* ---------- cards / forms ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r3); padding: var(--s5); margin: 0 0 var(--s4); }
.card h2 { margin-bottom: var(--s3); }
.stack { display: flex; flex-direction: column; gap: var(--s2); }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
label { font-size: var(--t-sm); color: var(--muted); }
textarea, input[type=text], input[type=password], input:not([type]) {
  width: 100%; font: inherit; font-size: var(--t-sm); padding: var(--s2) var(--s3);
  border: 1px solid var(--line); border-radius: var(--r1); background: var(--paper); color: var(--ink);
}
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .tab:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--t-xs); resize: vertical; }
.help { margin-top: var(--s3); }
.help summary { cursor: pointer; color: var(--accent); font-size: var(--t-sm); }
.help ol { padding-left: var(--s5); font-size: var(--t-sm); }
.status { display: grid; grid-template-columns: max-content 1fr; gap: var(--s1) var(--s4); margin: 0 0 var(--s3); font-size: var(--t-sm); }
.status dt { color: var(--muted); }
.status dd { margin: 0; }
.kids { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s2); }
.kids label { display: flex; align-items: center; gap: var(--s2); cursor: pointer; color: var(--ink); font-size: var(--t-md); }
.order { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; font-size: var(--t-sm); }
.chip { display: inline-flex; align-items: center; gap: var(--s1); padding: var(--s1) var(--s1) var(--s1) var(--s3); border: 1px solid var(--line); border-radius: 999px; background: var(--bg-soft); }
.chip-btn { border: 0; background: transparent; cursor: pointer; font-size: var(--t-md); padding: 0 var(--s1); color: var(--muted); }
.chip-btn:hover { color: var(--ink); }
fieldset { border: 1px solid var(--line); border-radius: var(--r1); padding: var(--s3) var(--s4); }
legend { font-size: var(--t-sm); color: var(--muted); padding: 0 var(--s1); }
fieldset label, .check { display: flex; align-items: center; gap: var(--s2); color: var(--ink); font-size: var(--t-md); }
.captcha { max-width: 320px; border: 1px solid var(--line); border-radius: var(--r1); background: #fff; }
.login-box { max-width: 380px; margin: 48px auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r3); padding: var(--s5); }
.login-box h1 { margin-bottom: var(--s4); }

/* ---------- tabs / segmented / tables ---------- */
.tabs { display: flex; gap: var(--s2); margin-bottom: var(--s4); flex-wrap: wrap; }
.child-switch { display: none; }
.child.is-hidden { display: none; }
button.tab { font: inherit; font-size: var(--t-sm); cursor: pointer; }
.tab { padding: var(--s2) var(--s4); border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: var(--t-sm); }
.tab:hover { border-color: var(--line-strong); }
.tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 500; }
.tab.active .muted { color: var(--paper); opacity: .65; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r1); overflow: hidden; }
.seg { padding: var(--s2) var(--s3); color: var(--muted); background: var(--paper); border-right: 1px solid var(--line); font-size: var(--t-sm); }
.seg:last-child { border-right: 0; }
.seg.active { background: var(--code-bg); color: var(--accent); font-weight: 600; }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th, .table td { text-align: left; padding: var(--s3) var(--s2); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th { font-weight: 500; color: var(--muted); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .03em; padding-bottom: var(--s2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table tr.dim td { color: var(--faint); }

/* ---------- day plan ---------- */
.sheet { display: grid; grid-template-columns: 1fr; gap: var(--s4); }
/* columns appear only when there is room for them, regardless of window width */
.sheet.children-2, .sheet.children-3, .sheet.children-4 {
  /* min(...) keeps the track from forcing horizontal overflow on narrow screens */
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
}
.sheet-wide { display: block; }
.child {
  min-width: 0; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r3); padding: var(--s4) var(--s5) var(--s5);
}
.child-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); padding-bottom: var(--s3); margin-bottom: var(--s2); border-bottom: 1px solid var(--line); }
.child-id h2 { font-size: var(--t-lg); }
.child-meta, .child-date { font-size: var(--t-sm); color: var(--muted); white-space: nowrap; }
.empty { color: var(--muted); padding: var(--s4) 0; font-size: var(--t-sm); }

.lessons { list-style: none; margin: 0; padding: 0; }
.lesson { display: grid; grid-template-columns: 48px 1fr; gap: var(--s3); padding: var(--s3) 0; break-inside: avoid; }
.lesson + .lesson { border-top: 1px solid var(--line); }
.rail { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; padding-top: 1px; }
.rail .num { font-size: var(--t-xs); color: var(--faint); font-weight: 600; }
.rail .time { font-size: var(--t-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson .body { min-width: 0; }
.child, .sheet > * { min-width: 0; }
.lesson-line { min-width: 0; }
.subject { font-weight: 600; overflow-wrap: break-word; }
.room { white-space: nowrap; }
.lesson-line { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.room { color: var(--muted); font-size: var(--t-sm); }
.lesson.cancelled .subject { text-decoration: line-through; color: var(--muted); }
.lesson.extra .subject { font-weight: 500; font-style: italic; }
.hw { display: flex; gap: var(--s2); align-items: flex-start; margin-top: var(--s2); font-size: var(--t-sm); }
.hw.none { color: var(--faint); margin-top: var(--s1); }
.hw-text { white-space: pre-line; overflow-wrap: break-word; min-width: 0; }
.hw-text a { text-decoration: underline; word-break: break-all; }
.box { flex: 0 0 auto; width: 14px; height: 14px; border: 1.5px solid var(--line-strong); border-radius: 3px; margin-top: 3px; }

.materials { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); min-width: 0; }
.material {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 28px; max-width: 100%;
  font-size: var(--t-sm); padding: 2px var(--s3); border-radius: var(--r1);
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--ink);
}
.m-icon { flex: 0 0 auto; }
.m-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-meta { flex: 0 0 auto; display: inline-flex; align-items: center; gap: var(--s1); white-space: nowrap; }
.m-att { color: var(--muted); font-size: var(--t-xs); }
.material:hover { border-color: var(--accent); color: var(--accent); background: var(--paper); }
.material.cdz { border-style: dashed; }
.done-tick { color: var(--ok-ink); font-weight: 700; }
.score { display: inline-block; padding: 0 var(--s1); border-radius: var(--r1); font-weight: 700; font-size: var(--t-xs); white-space: nowrap; background: var(--mark-x-bg); color: var(--mark-x-ink); }
.score.good { background: var(--mark-5-bg); color: var(--mark-5-ink); }
.score.bad { background: var(--mark-3-bg); color: var(--mark-3-ink); }

.section-title { font-weight: 600; font-size: var(--t-sm); margin-bottom: var(--s2); color: var(--muted); }
.extra-hw, .marks { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--line); }
.extra-hw .hw { margin-top: var(--s2); }
.marks-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.mark-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: var(--t-sm); }
.mark {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.7em; height: 1.7em;
  padding: 0 .3em; border-radius: var(--r1); font-weight: 700; font-size: var(--t-sm);
  background: var(--mark-x-bg); color: var(--mark-x-ink);
}
.mark-5 { background: var(--mark-5-bg); color: var(--mark-5-ink); }
.mark-4 { background: var(--mark-4-bg); color: var(--mark-4-ink); }
.mark-3 { background: var(--mark-3-bg); color: var(--mark-3-ink); }
.mark-2 { background: var(--mark-2-bg); color: var(--mark-2-ink); }
.mark-point { background: var(--bg-soft); color: var(--muted); border: 1px dashed var(--faint); }
.mark.inline { min-width: 1.4em; height: 1.4em; font-size: var(--t-xs); }
.mark.big { min-width: 2.2em; height: 2.2em; font-size: var(--t-lg); }
.mark sup { font-size: .6em; font-weight: 600; margin-left: 1px; }
.mark-subject { font-weight: 500; }
.mark-kind { font-size: var(--t-xs); }
.mark-comment { flex-basis: 100%; margin-left: 2.1em; font-size: var(--t-xs); color: var(--muted); white-space: pre-line; }

.child-foot { margin-top: var(--s4); }
.notes-label { font-size: var(--t-xs); color: var(--muted); }
.notes-lines { height: 40px; background: repeating-linear-gradient(to bottom, transparent 0, transparent 19px, var(--line) 19px, var(--line) 20px); }

/* ---------- mark detail ---------- */
button.mark { border: 0; font-family: inherit; cursor: pointer; }
button.mark:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.detail-card { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r3); padding: var(--s4) var(--s5); margin-bottom: var(--s4); }
.detail-close { position: absolute; top: var(--s3); right: var(--s3); border: 0; background: none; color: var(--muted); font-size: var(--t-md); cursor: pointer; }
.detail-close:hover { color: var(--ink); }
.detail-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.detail-section { margin-top: var(--s4); }
.detail-title { font-weight: 600; font-size: var(--t-sm); margin-bottom: var(--s2); color: var(--muted); }
.dist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.dist li { display: flex; align-items: center; gap: var(--s3); }
.dist .mark.mine { outline: 2px solid var(--accent); outline-offset: 1px; }
.bar { flex: 1 1 auto; max-width: 260px; height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ---------- marks page ---------- */
.marks-table .subj { font-weight: 600; }
.target-inline { display: none; font-size: var(--t-xs); font-weight: 400; margin-top: 2px; }
.marks-table .chips .mark { margin: 2px var(--s1) 2px 0; vertical-align: middle; }
.marks-table .avg { font-weight: 700; font-size: var(--t-md); }
.big-avg { font-size: 2rem; font-weight: 700; color: var(--ink); line-height: 1; }

/* ---------- week matrix ---------- */
.matrix { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: var(--t-sm); }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: var(--s2) var(--s3); vertical-align: top; text-align: left; }
.matrix tr > *:first-child { border-left: 1px solid var(--line); }
.matrix thead th { background: var(--bg-soft); border-top: 1px solid var(--line); font-weight: 600; }
.matrix th.subj-col { width: 140px; font-weight: 600; }
.matrix tbody th.subj-col { background: var(--paper); }
.matrix .day-name::first-letter { text-transform: uppercase; }
.matrix .day-meta { font-size: var(--t-xs); font-weight: 400; }
.matrix th.holiday, .matrix th.vacation { background: var(--warn-bg); }
.matrix td.nolesson { background: var(--bg-soft); }
.matrix .is-today { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.cell-lesson + .cell-lesson { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px dashed var(--line); }
.cell-meta { font-size: var(--t-xs); color: var(--muted); }
.cell-lesson.cancelled .cell-meta { color: var(--err-ink); }
.matrix .hw { margin-top: var(--s1); font-size: var(--t-xs); }
.matrix .hw-text { overflow-wrap: break-word; hyphens: auto; }
.matrix .box { width: 11px; height: 11px; margin-top: 3px; }
.matrix .materials { margin-top: var(--s1); }
.matrix .material { font-size: var(--t-xs); min-height: 22px; padding: 1px var(--s2); }
.week-days { display: none; }

/* ---------- points ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: var(--s3); margin-bottom: var(--s4); }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r3); padding: var(--s4); }
.tile-main { border-color: var(--accent); }
.tile-label { font-size: var(--t-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tile-value { font-size: 2rem; font-weight: 700; line-height: 1.15; margin-top: var(--s1); font-variant-numeric: tabular-nums; }
.tile-sub { font-size: var(--t-xs); color: var(--muted); margin-top: var(--s1); }
.pos { color: var(--ok-ink); }
.neg { color: var(--err-ink); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.card-head h2 { margin: 0; }
.weeks { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s2); align-items: end; height: 120px; margin-bottom: var(--s2); }
.week-col { display: flex; flex-direction: column; align-items: center; gap: var(--s1); height: 100%; }
.bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.bar-plus, .bar-minus { width: 40%; max-width: 18px; min-height: 2px; border-radius: 3px 3px 0 0; }
.bar-plus { background: var(--mark-5-ink); opacity: .75; }
.bar-minus { background: var(--err-ink); opacity: .6; }
.week-label { font-size: var(--t-xs); color: var(--muted); }
.screen-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--s2); margin-bottom: var(--s3); }
.screen-day { display: flex; flex-direction: column; align-items: center; gap: var(--s1); }
.screen-bar-wrap { position: relative; width: 100%; max-width: 44px; height: 90px; background: var(--bg-soft); border-radius: var(--r1); overflow: hidden; }
.screen-bar { position: absolute; left: 0; right: 0; bottom: 0; border-radius: var(--r1) var(--r1) 0 0; background: var(--mark-5-ink); opacity: .7; }
.screen-day.over .screen-bar { background: var(--err-ink); opacity: .65; }
.screen-limit { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed var(--muted); z-index: 1; }
.screen-val { font-size: var(--t-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
.screen-day.over .screen-val { color: var(--err-ink); }
.screen-day.empty .screen-val { color: var(--faint); font-weight: 400; }
.screen-form { display: grid; grid-template-columns: 160px 110px auto; gap: var(--s2); justify-content: start; }
@media (max-width: 760px) { .screen-form { grid-template-columns: 1fr 1fr; } .screen-form button { grid-column: 1 / -1; } }
.presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: var(--s4); margin-bottom: var(--s4); }
.preset-group { display: flex; flex-wrap: wrap; gap: var(--s2); align-content: flex-start; }
.preset-group .section-title { width: 100%; margin-bottom: 0; }
.btn.preset { justify-content: flex-start; white-space: normal; text-align: left; min-height: 34px; }
.btn.preset.pos { border-color: var(--ok-line); }
.btn.preset.neg { border-color: var(--err-line); }
.custom-points { display: grid; grid-template-columns: 190px 100px 1fr auto; gap: var(--s2); }
select { font: inherit; font-size: var(--t-sm); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--r1); background: var(--paper); color: var(--ink); }
input[type=number], input[type=date] { font: inherit; font-size: var(--t-sm); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--r1); background: var(--paper); color: var(--ink); width: 100%; }
.ledger-day + .ledger-day { margin-top: var(--s4); }
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger-row { display: grid; grid-template-columns: 64px 1fr auto auto; align-items: center; gap: var(--s2); padding: var(--s2) 0; border-bottom: 1px solid var(--line); font-size: var(--t-sm); }
.ledger-row:last-child { border-bottom: 0; }
.ledger-row.voided { opacity: .45; }
.ledger-row.voided .ledger-reason, .ledger-row.voided .amt { text-decoration: line-through; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.amt.award { color: var(--ok-ink); }
.amt.penalty { color: var(--err-ink); }
.amt.spend { color: var(--muted); }
.ledger-reason { min-width: 0; overflow-wrap: break-word; }
.ledger-void { border: 0; background: none; color: var(--faint); cursor: pointer; font-size: var(--t-md); padding: 0 var(--s1); }
.ledger-void:hover { color: var(--ink); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.inline-h2 { display: inline; }
.rules { margin-top: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: var(--s3); }
.rules-grid label { display: flex; flex-direction: column; gap: var(--s1); }
.w-num { width: 64px !important; display: inline-block; margin-left: var(--s1); }
@media (max-width: 760px) {
  .custom-points { grid-template-columns: 1fr 90px; }
  .custom-points input[name=reason], .custom-points button { grid-column: 1 / -1; }
  .tiles { grid-template-columns: 1fr 1fr; gap: var(--s2); }
  .tile { padding: var(--s3); }
  .tile-value { font-size: 1.5rem; }
}

/* ---------- highlight after refresh ---------- */
.changed > .body, .hw.changed { background: var(--warn-bg); border-radius: var(--r1); }
.lesson.changed { background: var(--warn-bg); border-radius: var(--r1); }
.cell-lesson.changed { background: var(--warn-bg); border-radius: var(--r1); padding: var(--s1) var(--s2); }
.mark.new { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .topbar { padding: var(--s2) var(--s3); gap: var(--s2); }
  .full { display: none; }
  .short { display: inline; }
  .topbar nav { gap: var(--s3); white-space: nowrap; }
  .topbar nav a, .linklike { font-size: var(--t-sm); }
  .topbar .pill { display: none; }
  .theme-btn { padding: 3px 6px; }
  .container { padding: var(--s4) var(--s3) var(--s6); }
  .container.wide { max-width: none; }
  .grid2 { grid-template-columns: 1fr; }
  .page-title { font-size: var(--t-lg); }
  .toolbar { gap: var(--s2); }
  .actions { width: 100%; justify-content: flex-end; }
  .card { padding: var(--s4); }
  .child { padding: var(--s3) var(--s4) var(--s4); }
  .lesson { grid-template-columns: 42px 1fr; gap: var(--s2); }
  .child-switch { display: flex; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }

  .matrix { display: none; }
  .week-days { display: block; }
  .week-day + .week-day { margin-top: var(--s5); }
  .week-day-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); border-bottom: 2px solid var(--ink); padding-bottom: var(--s1); margin-bottom: var(--s2); }
  .week-day-head b::first-letter { text-transform: uppercase; }
  .week-day.is-today .week-day-head { border-color: var(--accent); }

  .marks-table th:nth-child(3), .marks-table td:nth-child(3),
  .marks-table th:nth-child(5), .marks-table td:nth-child(5),
  .marks-table th:nth-child(6), .marks-table td:nth-child(6) { display: none; }
  .target-inline { display: block; }
  .child-head { flex-direction: column; align-items: flex-start; gap: var(--s1); }
  .child-date { text-align: left; }
  .marks-table th, .marks-table td { padding: var(--s2) var(--s1); }
  .big-avg { font-size: var(--t-xl); }
}

/* ---------- print (always light) ---------- */
@page { size: A4 portrait; margin: 9mm 9mm 8mm; }
@media print {
  :root, :root[data-theme="dark"] { --bg: #fff; --paper: #fff; --ink: #000; --muted: #444; --faint: #888; --line: #ccc; --line-strong: #000; --bg-soft: #eee; --warn-bg: #eee; color-scheme: light; }
  html, body { background: #fff; }
  .no-print, .tabs, .child-switch, .segmented, .week-days, .child-meta { display: none !important; }
  .child.is-hidden { display: block !important; }
  .print-only { display: block !important; }
  .container, .container.wide { max-width: none; padding: 0; margin: 0; }
  body { font-size: 10pt; line-height: 1.3; color: #000; }
  .sheet.layout-two-columns { display: grid; gap: 7mm; grid-template-columns: 1fr 1fr; align-items: start; }
  .sheet.children-1 { grid-template-columns: 1fr; }
  .sheet.layout-one-per-page { display: block; font-size: 11pt; }
  .sheet.layout-one-per-page .child { break-after: page; }
  .sheet.layout-one-per-page .child:last-child { break-after: auto; }
  .sheet-wide { display: block; }
  .child { border: 0; border-radius: 0; padding: 0; break-inside: avoid-column; }
  .child-head { border-bottom: 2px solid #000; padding-bottom: 3px; }
  .child-head h2 { font-size: 13pt; }
  .child-date { font-size: 9pt; color: #333; }
  .lesson { padding: 3px 0; grid-template-columns: 42px 1fr; }
  .lesson + .lesson { border-top: 1px solid #ddd; }
  .box { border-color: #000; }
  .material { border-color: #999; background: #fff; color: #000; }
  .m-title { overflow: visible; white-space: normal; text-overflow: clip; }
  .score, .mark { background: #fff !important; color: #000 !important; border: 1px solid #000; }
  .mark-point { border-style: dashed; }
  .hw-text a { color: #000; text-decoration: underline; }
  .notes-lines { height: 34px; background: repeating-linear-gradient(to bottom, transparent 0, transparent 16px, #bbb 16px, #bbb 17px); }
  .matrix { display: table !important; font-size: 8.5pt; }
  .matrix th, .matrix td { border-color: #bbb; padding: 3px 4px; }
  .matrix thead th, .matrix th.holiday, .matrix th.vacation { background: #eee !important; }
  .matrix td.nolesson { background: #fff; }
  .matrix .is-today { box-shadow: none; }
  .table th, .table td { border-bottom-color: #bbb; }
  .big-avg { color: #000; }
  .changed, .changed > .body, .lesson.changed, .cell-lesson.changed { background: none !important; }
  .mark.new { outline: none; }
  a { color: inherit; }
}
