:root {
  --paper: #f6f2ea; --card: #fffdf8; --ink: #22201c; --muted: #6b655b; --line: #e3dccd;
  --accent: #7a2e1f; --accent-soft: #f3e3dc; --warn: #a15c00; --warn-soft: #fbefd9; --mark: #d0261a;
  --radius: 10px; --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .06);
  --serif: "Frank Ruhl Libre", Georgia, "Times New Roman", serif;
  --sans: "Heebo", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); overflow-x: hidden; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 40px; min-height: 70vh; outline: none; }
bdi, .ltr { unicode-bidi: isolate; }

/* header */
.top { background: var(--ink); color: #f7f1e6; position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 10px; font: 600 18px/1.2 var(--serif); min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 6px; background: #f7f1e6; color: var(--ink); display: grid; place-items: center; font: 700 17px var(--serif); flex: none; }
.langs { display: flex; gap: 2px; background: rgba(255,255,255,.1); border-radius: 8px; padding: 2px; flex: none; }
.langs button { border: 0; background: none; color: #e9e1d2; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.langs button[aria-pressed="true"] { background: #f7f1e6; color: var(--ink); font-weight: 600; }

/* typography */
h1 { font: 700 clamp(26px, 4vw, 36px)/1.15 var(--serif); margin: 6px 0 6px; }
h2 { font: 600 22px/1.25 var(--serif); margin: 28px 0 12px; }
.lead { color: var(--muted); margin: 0 0 18px; max-width: 70ch; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }

/* search */
.search { position: relative; margin: 8px 0 4px; }
.search input { width: 100%; font: inherit; font-size: 17px; padding: 13px 44px 13px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
[dir="rtl"] .search input { padding: 13px 14px 13px 44px; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search .clear { position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; font-size: 22px; width: 36px; height: 36px; cursor: pointer; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 4px 2px 0; }

/* school cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: inherit; display: flex; flex-direction: column; overflow: hidden; transition: transform .12s ease, box-shadow .12s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(40,30,10,.08), 0 10px 26px rgba(40,30,10,.1); }
.card-img { height: 150px; background: #ddd5c4 center 18% / cover no-repeat; border-bottom: 1px solid var(--line); }
.card-body { padding: 14px 16px 16px; }
.card .year { font: 700 15px var(--sans); color: var(--accent); letter-spacing: .02em; }
.card h3 { font: 600 19px/1.3 var(--serif); margin: 4px 0 4px; }
.card .pl { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 13px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }

.about { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 26px; color: #3b372f; font-size: 15px; }
.about h2 { margin: 0 0 6px; font-size: 18px; }
.about p { margin: 0; }

/* class chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 16px; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 999px; font-size: 15px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.chip small { color: var(--muted); margin-inline-start: 4px; }
.chip[aria-current="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip[aria-current="true"] small { color: #d8d0c0; }

/* pupil list */
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-decoration: none; color: inherit; }
.row:hover { border-color: #c9bda5; box-shadow: var(--shadow); }
.row .who { min-width: 0; }
.row .name { font-weight: 600; font-size: 17px; line-height: 1.3; }
.row .nr { color: var(--muted); font-weight: 400; font-size: 14px; margin-inline-end: 6px; }
.row .meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.row .meta span + span::before { content: " · "; }
.warn { color: var(--warn); font-size: 14px; margin-inline-start: 4px; cursor: help; }
.class-head { font: 600 18px var(--serif); margin: 18px 0 8px; }

/* handwritten strip (CSS crop of the page photo) */
.strip { position: relative; overflow: hidden; border-radius: 6px; background: #e9e3d6; border: 1px solid var(--line); width: 100%; direction: ltr; aspect-ratio: var(--arw); }
.strip img { position: absolute; max-width: none; display: block; user-select: none; -webkit-user-drag: none;
  width: var(--ww); left: var(--lw); height: var(--h); top: var(--t); }
.strip.approx { border-style: dashed; border-color: #c9a46a; }

/* pupil page */
.pupil { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 20px; align-items: start; }
.pupil h1 { margin-top: 2px; }
.pupil .sub { color: var(--muted); margin: 0 0 14px; }
.facts { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px; margin: 0; }
.facts div { display: grid; grid-template-columns: 42% 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid #efe9dc; }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .term { border-bottom: 1px dotted var(--muted); cursor: help; }
.facts .tr { color: var(--muted); font-size: 14px; }
.note { background: var(--warn-soft); border: 1px solid #efd3a3; color: #5c3b00; border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-top: 10px; }
.also { background: var(--accent-soft); border: 1px solid #e3c2b6; border-radius: 8px; padding: 10px 12px; margin-top: 12px; font-size: 15px; }
.also a { display: block; margin-top: 4px; font-weight: 500; }
.acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; cursor: pointer; text-decoration: none; color: var(--ink); font-size: 15px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #c9bda5; }
.btn[disabled], .btn.off { opacity: .4; pointer-events: none; }
.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }

/* image viewer */
.viewer-wrap { position: sticky; top: 64px; }
.viewer { position: relative; overflow: hidden; background: #2c2924; border-radius: var(--radius); touch-action: none; cursor: grab; user-select: none; direction: ltr; height: min(68vh, 640px); }
.viewer.drag { cursor: grabbing; }
.viewer .stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.viewer .stage img { position: absolute; left: 0; top: 0; max-width: none; display: block; -webkit-user-drag: none; }
.viewer .mark { position: absolute; border-radius: 4px; box-shadow: 0 0 0 9999px rgba(20, 16, 10, .28); pointer-events: none; }
.viewer .mark.approx { box-shadow: 0 0 0 9999px rgba(20, 16, 10, .18); }
.tools { position: absolute; inset-inline-end: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.tools button { width: 42px; height: 42px; border-radius: 10px; border: 0; background: rgba(255, 253, 248, .94); color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.25); display: grid; place-items: center; }
.tools button:hover { background: #fff; }
.tools svg { width: 20px; height: 20px; }
.viewer-hint { font-size: 13px; color: var(--muted); margin: 6px 2px 0; }
.viewer-cap { font-size: 14px; color: var(--muted); margin: 0 0 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
body.fs { overflow: hidden; }
.viewer.full { position: fixed; inset: 0; height: auto; border-radius: 0; z-index: 100; }

/* page gallery */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.thumb { text-decoration: none; color: inherit; font-size: 13px; }
.thumb img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); background: #ddd5c4; display: block; }
.thumb span { display: block; margin-top: 3px; color: var(--muted); }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 18px 0 28px; }
.empty { color: var(--muted); padding: 20px 0; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* correction form */
.btn .ico { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #6a2618; }
.btn.primary[disabled] { opacity: .45; pointer-events: none; }
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 200; background: rgba(30, 24, 16, .5); display: grid; place-items: center; padding: 20px; }
.sheet { background: var(--card); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.3); width: min(620px, 100%); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 21px; }
.sheet-head .x { border: 0; background: none; font-size: 28px; line-height: 1; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.sheet-head .x:hover { background: var(--paper); }
.sheet-body { padding: 12px 18px 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.sg-who { margin: 0; font-weight: 600; }
.sg-intro { margin: 0; }
.sg-fields { border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 12px; }
.sg-row { display: grid; grid-template-columns: 36% 1fr 40px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid #efe9dc; min-height: 50px; }
.sg-row:last-child { border-bottom: 0; }
.sg-label { color: var(--muted); font-size: 14px; }
.sg-val { min-width: 0; overflow-wrap: anywhere; }
.sg-empty { color: #b3aa98; }
.sg-val input { width: 100%; font: inherit; padding: 7px 9px; border: 1px solid #c9bda5; border-radius: 7px; background: #fff; }
.sg-val input:focus, .sg-field input:focus, .sg-field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sg-was { font-size: 13px; color: var(--muted); margin-top: 2px; }
.sg-row.changed .sg-was bdi { text-decoration: line-through; }
.sg-row.changed { background: var(--warn-soft); margin: 0 -12px; padding-inline: 12px; }
.sg-row.changed .sg-val input { border-color: var(--warn); }
.pen { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.pen:hover { border-color: #c9bda5; background: var(--paper); }
.pen .ico { width: 19px; height: 19px; }
.pen.undo { color: var(--muted); }
.sg-field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.sg-field small { font-size: 12px; }
.sg-field input, .sg-field textarea { font: inherit; font-size: 16px; color: var(--ink); padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
.sg-field textarea { resize: vertical; min-height: 76px; }
.sg-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sg-two + .hint { margin-top: -4px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.sg-msg:empty { display: none; }
.sg-msg { border-radius: 8px; padding: 10px 12px; font-size: 15px; }
.sg-msg.ok { background: #e4f1e1; border: 1px solid #b9d8b2; color: #234d1c; font-size: 16px; }
.sg-msg.err { background: #fbe4e1; border: 1px solid #ebb8b1; color: #7a1d12; }
.sg-msg.warn { background: var(--warn-soft); border: 1px solid #efd3a3; color: #5c3b00; }
.sg-msg p { margin: 0 0 8px; }
.sg-msg pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #fff; border: 1px solid #efd3a3; border-radius: 6px; padding: 8px; font-size: 13px; margin: 0 0 8px; text-align: left; }
.sheet-foot { position: sticky; bottom: 0; background: var(--card); display: flex; justify-content: flex-end; gap: 8px; padding: 12px 0 16px; margin-top: 2px; border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  .modal { padding: 0; place-items: stretch; }
  .sheet { width: 100%; max-height: none; height: 100%; border-radius: 0; }
  .sheet-head { padding: 10px 14px 8px; }
  .sheet-body { padding: 10px 14px 0; }
  .sg-row { grid-template-columns: 1fr 40px; grid-template-areas: "l b" "v b"; gap: 2px 10px; }
  .sg-label { grid-area: l; font-size: 13px; }
  .sg-val { grid-area: v; }
  .sg-row .pen { grid-area: b; }
  .sg-two { grid-template-columns: 1fr; }
  .sheet-foot .btn { flex: 1; justify-content: center; padding: 11px 12px; }
}

@media (max-width: 899px) {
  .pupil { grid-template-columns: 1fr; }
  .pupil .viewer-wrap { position: static; order: -1; }
  .pupil .info { order: 0; }
  .viewer { height: min(56vh, 460px); }
}
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; gap: 8px; padding: 10px; }
  .strip { aspect-ratio: var(--arn); }
  .strip img { width: var(--wn); left: var(--ln); }
  .brand { font-size: 16px; }
  .langs button { padding: 5px 8px; font-size: 13px; }
  .facts div { grid-template-columns: 40% 1fr; }
  h2 { margin-top: 22px; }
}
