/*
  Feint: class register and markbook app (Screenery template)
  1. Tokens first: exercise-book paper, feint blue rules every 32px, a pink-red margin and one red pen.
  2. App shell: the book-cover sidebar (bottom bar on phones), the top line with the date, ruled sheets.
  3. Views: register grid, attendance chart and table, markbook grid, homework, notes; then drawer, dialogs, states.
*/

:root {
  /* Paper and print */
  --paper: #fcfbf7;
  --paper-2: #f5f3ec;
  --cover: #e7e3d6;
  --cover-2: #ddd8c8;
  --feint: #cbd9e8;         /* the ruled lines */
  --margin: #e5a1a7;        /* the double margin line */
  --hair: #d9d4c6;

  /* Ink */
  --ink: #1d2333;
  --ink-2: #4f5667;
  --ink-3: #636a7a;

  /* The teacher's red pen, and the codes that carry meaning */
  --red: #b3202e;
  --red-wash: #f7e4e3;
  --late: #8a5100;
  --late-wash: #f6ecd9;
  --auth: #3b5a7e;
  --auth-wash: #e4ebf3;
  --ok: #2f6a44;

  /* Type */
  --sans: "Gothic A1", "Helvetica Neue", Arial, sans-serif;
  --hand: "Rosario", "Gill Sans", sans-serif;
  --fs-s: 12px;
  --fs: 14px;
  --fs-l: 17px;
  --fs-h: 26px;

  /* Rhythm: everything sits on the 32px ruling */
  --rule: 32px;
  --gut: 24px;
  --margin-x: 64px;
  --radius: 4px;
  --cover-w: 236px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--fs)/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--red);
  accent-color: var(--red);
}
::selection { background: var(--red-wash); color: var(--ink); }
* { scrollbar-color: var(--cover-2) transparent; scrollbar-width: thin; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 2px; }
a { color: var(--ink); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-family: var(--hand); font-weight: 600; text-wrap: balance; letter-spacing: -.005em; }
p { margin: 0; }
.defs { position: absolute; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); }
.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 50; }
.skip:focus { top: 8px; }
kbd { font: 500 11px/1 var(--sans); color: var(--ink-3); border: 1px solid var(--hair); border-bottom-width: 2px; border-radius: 3px; padding: 3px 5px; background: var(--paper); }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: var(--cover-w) 1fr; height: 100vh; height: 100dvh; }

/* The cover: manilla card, a printed white label, the views */
.cover {
  background: var(--cover); padding-bottom: 60px !important;
  border-right: 1px solid var(--cover-2);
  display: flex; flex-direction: column; gap: 20px;
  padding: 20px 16px 16px;
  overflow-y: auto;
}
.crest { display: flex; gap: 10px; align-items: center; color: var(--ink); }
.crest-name { font: 600 14px/1.2 var(--hand); }
.crest-sub { font-size: var(--fs-s); color: var(--ink-2); }
.label {
  margin: 0; background: var(--paper); border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 6px 12px 8px;
}
.label div { display: flex; gap: 8px; align-items: baseline; box-shadow: inset 0 -1px 0 var(--feint); padding: 6px 0 3px; }
.label div:last-child { border-bottom: 0; }
.label dt { font-size: 11px; color: var(--ink-2); width: 50px; flex: none; }
.label dd { margin: 0; font: italic 500 15px/1.2 var(--hand); color: var(--ink); }
.label dd .muted { font: 400 11px var(--sans); margin-left: 6px; }

.views { display: grid; gap: 2px; }
.view-btn {
  display: flex; align-items: center; gap: 10px; text-align: left;
  height: 38px; padding: 0 10px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--ink-2); font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.view-btn:hover { background: var(--cover-2); color: var(--ink); }
.view-btn[aria-current="page"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgb(29 35 51 / .08); }
.view-btn .count { margin-left: auto; white-space: nowrap; font-size: 11px; color: var(--red); font-weight: 700; }
.view-btn .count:empty { display: none; }

.cover-foot { margin-top: auto; display: grid; gap: 12px; }
.board-toggle {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px;
  border: 1px solid var(--cover-2); border-radius: var(--radius); background: transparent; color: var(--ink-2);
}
.board-toggle b { display: block; color: var(--ink); font-weight: 600; }
.board-toggle small { display: block; font-size: 11px; line-height: 1.35; margin-top: 2px; }
.board-toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.board-toggle[aria-pressed="true"] b { color: var(--paper); }
.sync { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--ink-2); }
.sync .i { width: 16px; height: 16px; }
.sync.off { color: var(--red); }

/* The page: ruled paper with the margin. The ruling is a background on the scroller so it moves with the content. */
.page {
  position: relative; overflow-y: auto; overflow-x: hidden; outline: none;
  padding: 0 var(--gut) calc(var(--rule) * 3) calc(var(--margin-x) + 20px);
  background:
    linear-gradient(90deg, transparent calc(var(--margin-x) - 1px), var(--margin) calc(var(--margin-x) - 1px), var(--margin) var(--margin-x), transparent var(--margin-x), transparent calc(var(--margin-x) + 3px), var(--margin) calc(var(--margin-x) + 3px), var(--margin) calc(var(--margin-x) + 4px), transparent calc(var(--margin-x) + 4px)) 0 0 / 100% 100% no-repeat local,
    repeating-linear-gradient(180deg, transparent 0 calc(var(--rule) - 1px), var(--feint) calc(var(--rule) - 1px) var(--rule)) 0 0 / 100% var(--rule) repeat local,
    var(--paper);
}
/* The margin carries the session mark like a pupil writes the date: here, the row numbers live there */

.topline {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: var(--rule) calc(var(--rule) * 2);
  align-items: end; column-gap: 16px;
  margin-left: calc(-1 * (var(--margin-x) + 20px)); margin-right: calc(-1 * var(--gut));
  padding: 0 var(--gut) 0 calc(var(--margin-x) + 20px);
  background: var(--paper);
  box-shadow: inset 0 -1px 0 var(--feint);
}
.topline::before { /* keep the margin line running through the sticky header */
  content: ""; position: absolute; top: 0; bottom: 0; left: calc(var(--margin-x) - 1px); width: 5px;
  border-left: 1px solid var(--margin); border-right: 1px solid var(--margin); pointer-events: none;
}
.date-line { grid-column: 1 / -1; grid-row: 1; justify-self: end; align-self: end; font: italic 400 14px/1 var(--hand); color: var(--ink-2); padding-bottom: 6px; text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 4px; }
.topline-title { grid-row: 2; display: flex; align-items: baseline; gap: 14px; padding-bottom: 8px; min-width: 0; flex-wrap: wrap; }
.topline-title h1 { font-size: var(--fs-h); line-height: 1; text-decoration: underline; text-decoration-color: var(--red); text-decoration-thickness: 1.5px; text-underline-offset: 6px; }
.topline-sub { color: var(--ink-2); font-size: 13px; }
.topline-tools { grid-row: 2; display: flex; gap: 10px; align-items: center; padding-bottom: 8px; }

.search { position: relative; display: flex; align-items: center; }
.search .i { position: absolute; left: 9px; width: 17px; height: 17px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 220px; height: 34px; padding: 0 34px 0 32px; border: 1px solid var(--hair); border-radius: var(--radius);
  background: var(--paper);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.search kbd { position: absolute; right: 8px; }

/* Segmented control for ranges and filters */
.seg { display: inline-flex; border: 1px solid var(--hair); border-radius: var(--radius); background: var(--paper); overflow: hidden; flex-wrap: wrap; }
.seg button, .seg label span { display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px; border: 0; background: transparent; color: var(--ink-2); font-size: 13px; cursor: pointer; white-space: nowrap; }
.seg button + button, .seg label + label span { border-left: 1px solid var(--hair); }
.seg button[aria-pressed="true"], .seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg label { display: contents; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span { outline: 2px solid var(--red); outline-offset: -3px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border: 1px solid var(--ink); border-radius: var(--radius); background: var(--ink); color: var(--paper); font-weight: 500;
  transition: transform .15s var(--ease), background .15s var(--ease);
}
.btn:hover { background: #2c3449; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--hair); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.red { background: var(--red); border-color: var(--red); }
.btn.red:hover { background: #9c1826; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .65; cursor: progress; }
.btn .i { width: 18px; height: 18px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: var(--radius); background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; min-height: 24px; }
.link-btn:hover { color: var(--red); }

/* ---------- Sheets: content written on the ruling ---------- */
.view { padding-top: var(--rule); }
.line { min-height: var(--rule); line-height: var(--rule); }
.row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; min-height: calc(var(--rule) * 2); padding: calc(var(--rule) / 2) 0; }
.row-head > * { min-height: var(--rule); }
.row-head .btn { height: var(--rule); }
.row-head .grow { flex: 1; }
.sentence { font: 400 var(--fs-l)/var(--rule) var(--hand); max-width: 70ch; color: var(--ink); }
.sentence b { font-weight: 600; }
.sentence .red { color: var(--red); }
h2.sheet-h { font-size: 19px; line-height: var(--rule); height: var(--rule); margin-top: var(--rule); }
.sheet-note { color: var(--ink-2); font-size: 13px; line-height: var(--rule); }
.nojs-sheet { padding-top: var(--rule); font-family: var(--hand); font-size: var(--fs-l); }

.banner[hidden] { display: none; }
.banner {
  display: flex; box-sizing: border-box; min-height: calc(var(--rule) * 2); gap: 12px; align-items: center; flex-wrap: wrap; margin-top: var(--rule);
  padding: 10px 14px; border: 1px solid currentColor; border-radius: var(--radius); color: var(--red); background: var(--red-wash);
}
.banner p { color: var(--ink); flex: 1; min-width: 220px; }
.banner .i { color: var(--red); }

/* ---------- Register ---------- */
.reg-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 28px; align-items: start; }
.reg-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.reg-table th, .reg-table td { height: var(--rule); padding: 0 4px; text-align: center; vertical-align: middle; box-shadow: inset 0 -1px 0 var(--feint); }
.reg-table thead th { font-size: 11px; font-weight: 500; color: var(--ink-2); vertical-align: middle; height: var(--rule); }
.reg-table thead .dayhead { font-size: 12px; font-weight: 700; color: var(--ink); border-left: 1px solid var(--hair); }
.reg-table thead .dayhead.today { color: var(--red); }
.reg-table thead th[rowspan] { vertical-align: bottom; padding-bottom: 8px; }
.reg-table col.c-no { width: 36px; }
.reg-table col.c-ses { width: 30px; }
.reg-table col.c-now { width: 150px; }
.reg-table col.c-pct { width: 64px; }
.reg-table .no { text-align: right; color: var(--ink-3); font-size: 11px; position: relative; }
.reg-table .no span { position: absolute; right: calc(100% + 22px); top: 50%; transform: translateY(-50%); } /* sits in the margin */
.reg-table .name { text-align: left; padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg-table .name button { border: 0; background: none; padding: 0; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; min-height: 28px; }
.reg-table .name button:hover { text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.reg-table .name .sur { font-weight: 700; }
.reg-table .ses { font: 500 15px/1 var(--hand); color: var(--ink-2); }
.reg-table .ses.am { border-left: 1px solid var(--hair); }
.reg-table .now { background: rgb(179 32 46 / .035); border-left: 1px solid var(--margin); border-right: 1px solid var(--margin); }
.reg-table thead .now { color: var(--red); font-weight: 700; }
.reg-table .now-day { display: none; }
.reg-table .pct { text-align: right; font-size: 13px; color: var(--ink-2); }
.reg-table tr.focus td { background: var(--paper-2); }
.reg-table tr.focus .now { background: rgb(179 32 46 / .07); }
.code { font: 500 15px/1 var(--hand); }
.code.c-L, .code.c-U { color: var(--late); }
.code.c-N, .code.c-O { color: var(--red); font-weight: 600; }
.code.c-I, .code.c-M, .code.c-C { color: var(--auth); }
.code.c-x { color: var(--ink-3); }

.mark3 { display: inline-flex; gap: 4px; }
.mark3 button {
  width: 36px; height: 26px; border: 1px solid var(--hair); border-radius: 3px; background: var(--paper);
  font: 600 15px/1 var(--hand); color: var(--ink-2); display: grid; place-items: center; position: relative;
}
.mark3 button:hover { border-color: var(--ink-3); color: var(--ink); }
.mark3 button[aria-pressed="true"][data-code="/"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.mark3 button[aria-pressed="true"][data-code="L"] { background: var(--late-wash); color: var(--late); border-color: var(--late); }
.mark3 button[aria-pressed="true"][data-code="N"] { background: var(--red-wash); color: var(--red); border-color: var(--red); }
.mark3[aria-disabled="true"] button { pointer-events: none; opacity: .8; }

.reg-side { position: sticky; top: calc(var(--rule) * 4); display: grid; gap: 16px; }
.tally { border: 1px solid var(--hair); border-radius: var(--radius); background: var(--paper); padding: 14px 16px; }
.tally h2 { font-size: 17px; margin-bottom: 4px; }
.tally dl { margin: 8px 0 12px; display: grid; grid-template-columns: 1fr auto; row-gap: 0; }
.tally dt, .tally dd { margin: 0; line-height: 30px; box-shadow: inset 0 -1px 0 var(--feint); font-size: 13px; }
.tally dd { text-align: right; font-weight: 700; }
.tally .bar { display: flex; height: 8px; border-radius: 2px; overflow: hidden; background: var(--paper-2); margin: 6px 0 4px; }
.tally .bar span { display: block; height: 100%; transition: width .35s var(--ease); }
.tally .actions { display: grid; gap: 8px; }
.tally .btn { justify-content: center; }
.tally .err { color: var(--red); font-size: 13px; min-height: 0; }
.tally .err:empty { display: none; }
.key { font-size: 12px; color: var(--ink-2); line-height: 1.5; margin: 12px 0 0; display: grid; grid-template-columns: 22px 1fr; gap: 3px 6px; }
.key dt { font: 600 15px/1.2 var(--hand); text-align: center; }
.key dd { margin: 0; }
.key .keys { grid-column: 1 / -1; margin-top: 6px; color: var(--ink-2); }
.key b { font: 600 14px var(--hand); display: inline-block; width: 16px; }
.key .c-L { color: var(--late); } .key .c-N { color: var(--red); } .key .c-I { color: var(--auth); }
.office { border: 1px solid var(--margin); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; color: var(--ink); background: var(--paper); }
.office b { color: var(--red); }

/* Seen stamp: the red pen tick and initials that appear when the register is submitted (the authored moment) */
.seen { display: flex; align-items: center; gap: 10px; color: var(--red); font: italic 500 16px/1.2 var(--hand); }
.seen svg { width: 44px; height: 34px; flex: none; }
.seen path { fill: none; stroke: var(--red); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-reduced-motion: no-preference) {
  .seen.draw path { stroke-dasharray: 80; stroke-dashoffset: 80; animation: pen .7s var(--ease) forwards; }
  .seen.draw path + path { animation-delay: .35s; }
  .mark3 button[aria-pressed="true"] { animation: press .25s var(--ease); }
}
@keyframes pen { to { stroke-dashoffset: 0; } }
@keyframes press { from { transform: scale(.88); } }

/* ---------- Attendance ---------- */
.chart-frame { margin-top: var(--rule); position: relative; height: calc(var(--rule) * 8); background: var(--paper); }
.chart { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .gap text { font-size: 12px; }
.chart .axis text { font: 400 11px var(--sans); fill: var(--ink-2); }
.chart .grid line { stroke: var(--feint); }
.chart .goal line { stroke: var(--red); stroke-dasharray: 4 4; }
.chart .goal text { font: italic 500 12px var(--hand); fill: var(--red); }
.chart .bar rect { fill: var(--ink); transition: fill .15s; }
.chart .bar.low rect { fill: var(--red); }
.chart .bar rect.hit { fill: transparent; }
.chart .bar:hover rect.v, .chart .bar:focus rect.v, .chart .bar.on rect.v { fill: var(--auth); }
.chart .bar:focus { outline: none; }
.chart .bar:focus-visible rect.hit { stroke: var(--red); stroke-width: 2; }
.chart .gap text { font: italic 400 12px var(--hand); fill: var(--ink-3); }
.readout { min-height: var(--rule); line-height: var(--rule); font: italic 400 15px var(--hand); color: var(--ink-2); }
.readout b { font-style: normal; color: var(--ink); }

.att-tools { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: center; min-height: calc(var(--rule) * 2); padding: calc(var(--rule) / 2) 0; }
.dtable { width: 100%; border-collapse: collapse; }
.dtable th, .dtable td { height: var(--rule); padding: 0 10px; box-shadow: inset 0 -1px 0 var(--feint); text-align: right; white-space: nowrap; }
.dtable th:first-child, .dtable td:first-child { text-align: left; padding-left: 0; }
.dtable thead th { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.dtable thead button { border: 0; background: none; padding: 0 2px; color: inherit; font: inherit; display: inline-flex; gap: 4px; align-items: center; min-height: 28px; }
.dtable thead button .i { width: 14px; height: 14px; opacity: .5; }
.dtable thead th[aria-sort] button { color: var(--ink); font-weight: 700; }
.dtable thead th[aria-sort] .i { opacity: 1; color: var(--red); }
.dtable tbody tr { cursor: pointer; }
.dtable tbody tr:hover td { background: var(--paper-2); }
.dtable .pname { border: 0; background: none; padding: 0; font: inherit; text-align: left; min-height: 28px; }
.dtable .pname b { font-weight: 700; }
.dtable .low { color: var(--red); font-weight: 700; }
.strip { display: inline-flex; gap: 1px; vertical-align: middle; }
.strip i { display: block; width: 4px; height: 14px; background: var(--ink); border-radius: 1px; }
.strip i.L, .strip i.U { background: var(--late); }
.strip i.N, .strip i.O { background: var(--red); }
.strip i.I, .strip i.M, .strip i.C { background: var(--auth); opacity: .7; }
.strip i.x { background: var(--hair); }

/* ---------- Markbook ---------- */
.mb-frame { position: relative; overflow-x: auto; margin-top: var(--rule); border-left: 0; }
.mb { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.mb th, .mb td { height: var(--rule); padding: 0 8px; box-shadow: inset 0 -1px 0 var(--feint); text-align: center; white-space: nowrap; }
.mb thead th { vertical-align: bottom; font-size: 11px; font-weight: 500; color: var(--ink-2); height: calc(var(--rule) * 2); padding-top: 4px; padding-bottom: 6px; line-height: 1.3; }
.mb thead th .t { display: block; font: 600 13px/1.25 var(--hand); color: var(--ink); white-space: normal; width: 124px; margin: 0 auto 2px; }
.mb .first { position: sticky; left: 0; z-index: 2; background: var(--paper); text-align: left; padding-left: 0; min-width: 190px; border-right: 1px solid var(--hair); }
.mb thead .first { vertical-align: bottom; }
.mb td.cell { padding: 0 4px; min-width: 104px; }
.mb .cell button {
  width: 100%; min-height: 28px; border: 0; background: transparent; border-radius: 3px;
  font: italic 500 16px/1 var(--hand); color: var(--red);
}
.mb .cell button:hover { background: var(--red-wash); }
.mb .cell button .of { font: 400 11px var(--sans); color: var(--ink-3); font-style: normal; margin-left: 2px; }
.mb .cell button.none { color: var(--ink-3); font-style: normal; font-size: 13px; }
.mb .cell button.abs { color: var(--auth); font-size: 14px; }
.mb .cell input {
  width: 64px; height: 28px; text-align: center; border: 1px solid var(--red); border-radius: 3px; background: var(--paper);
  font: italic 500 16px var(--hand); color: var(--red);
}
.mb .cell input[aria-invalid="true"] { background: var(--red-wash); }
.mb .avg { font-weight: 700; min-width: 72px; border-left: 1px solid var(--hair); }
.mb .avg.low { color: var(--red); }
.mb tfoot td, .mb tfoot th { font-weight: 700; height: calc(var(--rule) * 2); line-height: 1.35; box-shadow: inset 0 1px 0 var(--ink), inset 0 -1px 0 var(--feint); }
.mb tfoot .first { font: 600 14px var(--hand); }
.mb tr.hl td, .mb tr.hl th { background: var(--paper-2); }
.cell-err { color: var(--red); font-size: 13px; min-height: var(--rule); line-height: var(--rule); }

/* ---------- Homework ---------- */
.hw-list { list-style: none; margin: var(--rule) 0 0; padding: 0; }
.hw-item { box-shadow: inset 0 -1px 0 var(--feint); }
.hw-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 170px 28px; align-items: center; gap: 16px; width: 100%; min-height: calc(var(--rule) * 2); padding: 6px 0; border: 0; background: none; text-align: left; }
.hw-row:hover .hw-task { text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.hw-task { font: 400 16px/1.35 var(--hand); }
.hw-meta { font-size: 12px; color: var(--ink-2); }
.hw-in { font-size: 13px; }
.hw-in .meter { display: block; height: 4px; background: var(--paper-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.hw-in .meter span { display: block; height: 100%; background: var(--ink); }
.hw-row .i { transition: transform .2s var(--ease); color: var(--ink-3); }
.hw-row[aria-expanded="true"] .i { transform: rotate(90deg); }
.hw-detail { padding: 4px 0 var(--rule); }
.hw-detail[hidden] { display: none; }
.ticks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 16px; }
.tick { display: flex; align-items: center; gap: 8px; height: var(--rule); box-shadow: inset 0 -1px 0 var(--feint); font-size: 13px; cursor: pointer; }
.tick input { width: 18px; height: 18px; margin: 0; }
.tick .late { color: var(--late); font-size: 11px; margin-left: auto; }
.tick.missing span:first-of-type { color: var(--ink); }

/* ---------- Notes ---------- */
.notes { width: 100%; border-collapse: collapse; margin-top: var(--rule); }
.notes td, .notes th { box-shadow: inset 0 -1px 0 var(--feint); padding: 0 12px 0 0; text-align: left; vertical-align: top; line-height: var(--rule); }
.notes thead th { font-size: 12px; font-weight: 500; color: var(--ink-2); height: var(--rule); vertical-align: bottom; }
.notes .when { white-space: nowrap; color: var(--ink-2); font-size: 13px; width: 110px; }
.notes .who { white-space: nowrap; font-weight: 700; width: 150px; }
.notes .what { font: 400 15px/var(--rule) var(--hand); color: var(--ink); max-width: 60ch; }
.tag { display: inline-block; line-height: 1.3; vertical-align: middle; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 3px; border: 1px solid currentColor; white-space: nowrap; }
.tag.praise { color: var(--ok); }
.tag.homework { color: var(--auth); }
.tag.attendance { color: var(--late); }
.tag.concern { color: var(--red); }
.status-s { font-size: 12px; color: var(--ink-2); white-space: nowrap; }

/* ---------- Empty, loading, error ---------- */
.empty { padding: var(--rule) 0; max-width: 56ch; }
.empty h2 { font-size: 20px; line-height: var(--rule); }
.empty p { line-height: var(--rule); color: var(--ink-2); }
.empty .btn { margin-top: 8px; }
.skel { display: block; height: 12px; border-radius: 2px; background: var(--paper-2); margin: 10px 0; }
@media (prefers-reduced-motion: no-preference) {
  .skel { background: linear-gradient(90deg, var(--paper-2) 30%, #ebe8de 50%, var(--paper-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
}
@keyframes shimmer { to { background-position: -150% 0; } }
.skel-row { display: grid; grid-template-columns: 36px 30% 1fr 64px; gap: 14px; height: var(--rule); box-shadow: inset 0 -1px 0 var(--feint); align-items: center; }

/* ---------- Board view (projector safe) ---------- */
body.board .sur-only, body.board .pct, body.board .pv { visibility: hidden; }
body.board .mb .cell button, body.board .mb .cell .of, body.board .mb .avg, body.board .mb tfoot td, body.board .dtable td:not(:first-child) { color: transparent !important; text-shadow: none; }
body.board .mb .cell button::after, body.board .mb .avg::after { content: ""; }
body.board .board-flag { display: flex; }
.board-flag { display: none; align-items: center; gap: 8px; color: var(--paper); background: var(--ink); padding: 0 12px; border-radius: var(--radius); font-size: 12px; height: var(--rule); }

/* ---------- Drawer ---------- */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: rgb(29 35 51 / .28); }
.drawer {
  margin: 0 0 0 auto; height: 100vh; height: 100dvh; max-height: none; width: min(460px, 100vw);
  box-shadow: -12px 0 40px rgb(29 35 51 / .16); border-left: 1px solid var(--hair);
  background:
    linear-gradient(90deg, transparent 39px, var(--margin) 39px, var(--margin) 40px, transparent 40px, transparent 43px, var(--margin) 43px, var(--margin) 44px, transparent 44px) 0 0 / 100% 100% no-repeat local,
    var(--paper);
}
@media (prefers-reduced-motion: no-preference) {
  .drawer[open] { animation: slide .35s var(--ease); }
  .sheet-dialog[open] { animation: rise .3s var(--ease); }
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.drawer-in { padding: 18px 22px 32px 62px; display: grid; gap: 0; overflow-y: auto; height: 100%; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer-head h2 { font-size: 26px; line-height: 1.15; }
.drawer-head p { color: var(--ink-2); font-size: 13px; margin-top: 4px; }
.drawer h3 { font-size: 16px; line-height: var(--rule); margin-top: 20px; box-shadow: inset 0 -1px 0 var(--feint); }
.drawer .kv { display: grid; grid-template-columns: 1fr auto; }
.drawer .kv > * { line-height: var(--rule); box-shadow: inset 0 -1px 0 var(--feint); font-size: 13px; }
.drawer .kv dd { margin: 0; font-weight: 700; text-align: right; }
.drawer .kv dt { color: var(--ink-2); }
.drawer .kv dd.red { color: var(--red); }
.drawer .term-strip { margin-top: 10px; }
.strip-key { font-size: 11px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin: 4px 0 8px; }
.strip-key i { display: inline-block; width: 10px; height: 8px; border-radius: 1px; margin-right: -6px; }
.term-strip svg { width: 100%; height: auto; display: block; }
.drawer .marks { display: grid; grid-template-columns: 1fr auto; }
.drawer .marks > * { line-height: var(--rule); height: var(--rule); box-shadow: inset 0 -1px 0 var(--feint); font-size: 13px; }
.drawer .marks .m { font: italic 500 16px var(--hand); color: var(--red); text-align: right; }
.drawer .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.drawer .nlist p { font: 400 14px/1.45 var(--hand); padding: 6px 0; box-shadow: inset 0 -1px 0 var(--feint); }
.drawer .nlist small { display: block; font: 400 11px var(--sans); color: var(--ink-2); }

/* ---------- Dialogs ---------- */
.sheet-dialog { width: min(560px, calc(100vw - 24px)); border-radius: 8px; box-shadow: 0 24px 60px rgb(29 35 51 / .22); }
.sheet-dialog form { display: grid; max-height: calc(100dvh - 40px); grid-template-rows: auto 1fr auto; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px 22px; box-shadow: inset 0 -1px 0 var(--feint); }
.dlg-head h2 { font-size: 21px; }
.dlg-body { padding: 16px 22px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-foot { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 22px 16px; border-top: 1px solid var(--feint); flex-wrap: wrap; }
.dlg-status { margin-right: auto; font-size: 13px; color: var(--ink-2); }
.dlg-status.err { color: var(--red); }
.dlg-status.ok { color: var(--ok); }
.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field label, .field legend { font-size: 12px; font-weight: 700; color: var(--ink-2); padding: 0; margin-bottom: 0; }
.field legend { margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--hair); border-radius: var(--radius); background: var(--paper);
}
.field textarea {
  resize: vertical; line-height: 28px; padding: 2px 10px; font: 400 16px/28px var(--hand);
  background: repeating-linear-gradient(180deg, transparent 0 27px, var(--feint) 27px 28px) 0 2px / 100% 28px local, var(--paper);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }
.field [aria-invalid="true"] { border-color: var(--red); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.field-help, .field-note { font-size: 12px; color: var(--ink-2); line-height: 1.5; }
.field-err { font-size: 13px; color: var(--red); }
.field-err:empty { display: none; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; min-height: 28px; }
.check input { width: 18px; height: 18px; margin: 0; }
.privacy { display: flex; gap: 10px; font-size: 12px; color: var(--ink-2); line-height: 1.5; background: var(--paper-2); padding: 10px 12px; border-radius: var(--radius); }
.privacy .i { width: 18px; height: 18px; color: var(--ink-2); }
.warn { font-size: 13px; color: var(--late); background: var(--late-wash); border-radius: var(--radius); padding: 8px 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius); font-size: 13px; z-index: 60;
  transition: opacity .25s var(--ease), transform .25s var(--ease); max-width: calc(100vw - 32px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.bottombar { display: none; }

/* ---------- 1024 and below: narrower cover, register aside drops under ---------- */
@media (max-width: 1180px) {
  :root { --cover-w: 224px; --margin-x: 48px; }
  .reg-wrap { grid-template-columns: 1fr; }
  .reg-side { position: static; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
  .reg-table col.c-ses { width: 26px; }
}
@media (max-width: 900px) {
  :root { --cover-w: 0px; --margin-x: 36px; --gut: 18px; }
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .cover { display: none; }
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--cover-2); background: var(--cover);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottombar button { display: grid; justify-items: center; gap: 2px; padding: 8px 2px 8px; border: 0; background: transparent; font-size: 11px; color: var(--ink-2); min-height: 54px; }
  .bottombar button[aria-current="page"] { color: var(--ink); font-weight: 700; background: var(--paper); }
  .reg-table { table-layout: auto; }
  .reg-table .ses, .reg-table .dayhead, .reg-table col.c-ses { display: none; }
  .reg-table .now-day { display: inline; }
  .page { padding-left: calc(var(--margin-x) + 14px); }
  .topline { padding-left: calc(var(--margin-x) + 14px); margin-left: calc(-1 * (var(--margin-x) + 14px)); }
  .reg-table .no span { right: calc(100% + 14px); }
}
@media (max-width: 640px) {
  :root { --margin-x: 26px; --gut: 14px; --fs-h: 23px; }
  .topline { grid-template-columns: 1fr; grid-template-rows: var(--rule) var(--rule) calc(var(--rule) * 2); }
  .topline-sub { display: none; }
  .topline-title { grid-row: 2; padding-bottom: 4px; }
  .topline-tools { grid-row: 3; padding-bottom: 0; align-self: center; }
  .search, .search input { width: 100%; }
  .row-head .seg[aria-label="Date range"] { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .row-head .seg[aria-label="Date range"] button { border-left: 0; justify-content: center; }
  .row-head .seg[aria-label="Date range"] button:nth-child(even) { border-left: 1px solid var(--hair); }
  .row-head .seg[aria-label="Date range"] button:nth-child(n+3) { border-top: 1px solid var(--hair); }
  .search kbd { display: none; }
  .date-line { justify-self: start; }
  .reg-table .no, .reg-table col.c-no { width: 0; padding: 0; }
  .reg-table .no span { right: calc(100% + 8px); }
  .reg-table .name { padding-left: 0; white-space: normal; line-height: 1.2; }
  .reg-table col.c-now { width: 128px; }
  .reg-table col.c-pct { width: 46px; }
  .reg-table .pct { font-size: 12px; }
  .reg-table td.now { padding: 0 2px; }
  .mark3 button { width: 38px; height: 28px; }
  .mark3 { gap: 3px; }
  .reg-side { grid-template-columns: 1fr; }
  .dtable .hide-s { display: none; }
  .hw-row { grid-template-columns: minmax(0, 1fr) 24px; gap: 4px 10px; }
  .hw-row .hw-meta, .hw-row .hw-in { grid-column: 1; }
  .hw-row .i { grid-row: 1; grid-column: 2; }
  .notes thead { display: none; }
  .notes tr { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; box-shadow: inset 0 -1px 0 var(--feint); }
  .notes td { box-shadow: none; }
  .notes td { border: 0; padding: 0; width: auto; }
  .notes .what { grid-column: 1 / -1; }
  .notes .st { grid-column: 1 / -1; }
  .mb .first { min-width: 132px; max-width: 132px; white-space: normal; line-height: 1.2; }
  .mb td.cell { min-width: 76px; }
  .mb thead th .t { width: 92px; font-size: 12px; }
  .mb thead th { height: calc(var(--rule) * 3); }
  .field-row { grid-template-columns: 1fr; }
  .drawer-in { padding-left: 54px; padding-right: 16px; }
  .chart .axis text { font-size: 11px; }
}
