/* Studyroom — light grayscale surfaces, blue actions; user media/colors stay intact. */
/* V13 document dialog only: scriptless, bounded actual EPUB fragment. */
.document-import-dialog .epub-layout-preview{display:flex;flex-direction:column;flex:1;min-height:0;min-width:0;padding:12px;gap:8px;overflow:hidden}
.document-import-dialog .epub-layout-selectors{display:grid;grid-template-columns:minmax(0,2fr) minmax(0,1fr);gap:12px;flex:none}
.document-import-dialog .epub-layout-selectors .field{margin:0;min-width:0}
.document-import-dialog .epub-layout-selectors select{width:100%;min-width:0;max-width:100%;font-size:13px;height:34px}
.document-import-dialog .document-layout-notice{font-size:12px;line-height:1.5;margin:0;color:#4b5563;flex:none}
.document-import-dialog .epub-layout-preview>p[role=status]{font-size:12px;margin:0;flex:none}
.document-import-dialog .epub-layout-frame{display:block;flex:1;width:100%;min-height:150px;border:1px solid #ccd2dc;background:white}
.document-import-dialog .document-failure-panel{padding:24px;overflow:auto;color:#503315;background:#fff6e7;min-height:180px}
.document-import-dialog .document-failure-panel h3{margin:0 0 12px;font-size:18px}
.document-import-dialog .document-failure-panel .btn{margin:8px 8px 0 0}
@media(max-width:760px){.document-import-dialog .epub-layout-preview{padding:8px;gap:5px}.document-import-dialog .epub-layout-selectors{gap:6px}.document-import-dialog .document-layout-notice{font-size:11px}}

:root {
  color-scheme: light;
  --bg: #f6f9fd;
  --surface: #ffffff;
  --surface-soft: #f5f9ff;
  --surface-inset: #edf4fc;
  --sidebar-bg: #fbfdff;
  --ink: #243247;
  --text: var(--ink);
  --muted: #59677a;
  --placeholder: #6b7078;
  --primary: #376895;
  --primary-hover: #28547f;
  --accent-soft: #edf6ff;
  --accent-border: #bed9f2;
  --focus: #5a8fc8;
  --focus-ring: #5a8fc826;
  /* Compatibility aliases for existing components, never green. */
  --sage: var(--primary);
  --sage-light: var(--accent-soft);
  --border: #dce5ef;
  --border-strong: #8193a8;
  --danger: #a53732;
  --danger-bg: #fbefeb;
  --warning: #815921;
  --warning-bg: #fbf3df;
  --success: #347565;
  --success-bg: #edf9f4;
  --overlay: #20212480;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 3px 16px #2021240a;
  --shadow-lg: 0 22px 70px #20212426;
  --sidebar-width: 242px;
  --font: "RIDIBatang", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { min-width: 280px; scroll-behavior: smooth; scroll-padding-top: 90px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.65 var(--font); letter-spacing: -.025em; -webkit-font-smoothing: antialiased; }
body, #app { min-height: 100vh; min-height: 100dvh; }
:where(div, section, article, aside, main, header, footer, nav, form, fieldset, label) { min-width: 0; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); color: var(--primary-hover); }
a { color: var(--primary); text-decoration: none; text-underline-offset: 4px; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; letter-spacing: inherit; }
button, select, summary, input[type="checkbox"], input[type="radio"], input[type="color"] { cursor: pointer; }
button { color: inherit; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .55; }
button, a, input, select, textarea, [contenteditable], summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.main:focus { outline: none; }
img, video, canvas, svg { max-width: 100%; }
img { display: block; height: auto; }
svg { flex-shrink: 0; vertical-align: middle; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { color: var(--ink); line-height: 1.4; font-weight: 700; word-break: keep-all; overflow-wrap: anywhere; }
h1 { font-size: clamp(25px, 2.4vw, 34px); letter-spacing: -.055em; }
h2 { font-size: 22px; letter-spacing: -.04em; }
h3 { font-size: 18px; }
h4 { font-size: 15px; }
small { font-size: 12px; }
hr { margin: 24px 0; border: 0; border-top: 1px solid var(--border); }
pre, code { font-family: "SFMono-Regular", Consolas, monospace; font-size: .9em; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 18px; }
legend { padding: 0 7px; font-weight: 600; }
.muted, .subtitle, .field-help, .help-text, .description { color: var(--muted); }
.subtitle { margin-top: 10px; font-size: 14px; line-height: 1.85; }
.eyebrow { color: var(--muted); font-size: 10px; line-height: 1.6; font-weight: 750; letter-spacing: .18em; margin-bottom: 9px; }
.sr-only, .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 1000; background: var(--primary); color: white; padding: 12px 20px; border-radius: 8px; }
.skip-link:focus { top: 12px; }

/* Application frame */
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 32px 18px 16px; background: var(--sidebar-bg); border-right: 1px solid var(--border); overflow-y: auto; overscroll-behavior: contain; }
.sidebar > a:hover, .nav-link:hover, .subject-link:hover { text-decoration: none; }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 38px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 45px; border-radius: 13px 13px 13px 4px; background: var(--primary); color: var(--surface); }
.brand strong { display: block; font-size: 18px; letter-spacing: -.055em; }
.brand small { display: block; color: var(--muted); font-size: 8px; letter-spacing: .16em; margin-top: 3px; }
.sidebar-section-label { display: flex; align-items: center; justify-content: space-between; padding: 0 13px; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 600; }
.subject-label { margin-top: 32px; }
.subject-label > span { color: var(--muted); background: var(--surface-inset); min-width: 22px; padding: 1px 6px; border-radius: 6px; text-align: center; font-size: 10px; }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { display: flex; align-items: center; gap: 11px; min-height: 46px; border-radius: 9px; padding: 10px 12px; color: var(--muted); font-size: 13px; transition: background .16s, color .16s; }
.nav-link > span:not(.nav-soon) { flex: 1; min-width: 0; }
.nav-link:hover, .subject-link:hover { background: var(--accent-soft); color: var(--primary); }
.nav-link.active { background: var(--primary); color: var(--surface); font-weight: 650; box-shadow: 0 4px 9px #2021240a; }
.nav-soon { font-size: 9px; border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; white-space: nowrap; color: var(--muted); }
.subject-nav { max-height: 30vh; overflow-y: auto; margin-bottom: 20px; }
.subject-link { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 8px 13px; color: var(--muted); font-size: 13px; border-radius: 8px; }
.subject-link > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-link.selected { background: var(--accent-soft); color: var(--primary); font-weight: 650; }
.subject-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; }
.sidebar-empty { white-space: pre-line; color: var(--muted); font-size: 12px; line-height: 1.9; padding: 6px 13px 16px; }
.sidebar-bottom { margin-top: auto; padding-top: 22px; }
.quiet-note { display: flex; gap: 12px; color: var(--muted); margin: 0 10px 24px; font-size: 12px; }
.quiet-note small { display: block; font-size: 10px; margin-top: 5px; color: var(--muted); line-height: 1.7; }
.account { display: flex; align-items: center; gap: 9px; border-top: 1px solid var(--border); padding: 17px 2px 0; margin-top: 13px; }
.account > div { flex: 1; overflow: hidden; }
.account strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 12px; white-space: nowrap; }
.account small { display: block; color: var(--muted); font-size: 9px; margin-top: 2px; }
.account .btn-icon { margin-right: -5px; }
.avatar { flex-shrink: 0; display: inline-grid; place-items: center; width: 36px; height: 36px; background: var(--surface-inset); border: 1px solid var(--border); color: var(--muted); border-radius: 50%; font-size: 13px; font-weight: 700; }
.avatar.small { width: 32px; height: 32px; font-size: 12px; }
.app-body { margin-left: var(--sidebar-width); min-width: 0; }
.main { min-height: 100vh; min-height: 100dvh; }
.page { width: 100%; max-width: 1380px; margin-inline: auto; padding: 49px clamp(24px, 4vw, 64px) 64px; }
/* Title and action groups must wrap as units before the title is squeezed.
   Overflow-only tests miss a 30px-wide, thousand-pixel-tall title on Fold. */
.page-heading, .page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 32px; }
.page-heading > div:first-child, .page-header > div:first-child { flex: 1 1 280px; min-width: min(100%, 280px); }
.page-heading > .actions, .page-header > .actions { max-width: 100%; }
.actions, .toolbar, .button-group, .row-actions, .card-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.actions { justify-content: flex-end; }
.mobile-header, .sidebar-overlay { display: none; }

/* Shared surfaces and layouts */
.panel, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 25px; margin-bottom: 24px; }
.card { padding: 22px; }
.panel-heading, .panel-header, .section-heading, .section-header, .card-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel-heading p, .panel-header p, .section-heading p, .section-header p { color: var(--muted); font-size: 13px; margin-top: 5px; }
.panel > :last-child, .card > :last-child { margin-bottom: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 20px; }
.two-col, .two-column, .form-grid, .compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.stack { display: grid; gap: 18px; }
.full-width, .span-full { grid-column: 1 / -1; }
.section { margin-top: 30px; }
.toolbar { margin-bottom: 22px; }
.toolbar input[type="search"] { flex: 1 1 180px; width: auto; }
.toolbar .field { margin-bottom: 0; }
.toolbar select { width: auto; max-width: 100%; }
.spacer { flex: 1; }
.tabs { display: flex; align-items: center; gap: 6px; margin: 0 0 26px; padding-bottom: 1px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tabs > a, .tabs > button, .tab { display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex-shrink: 0; min-height: 48px; padding: 10px 17px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; border-radius: 6px 6px 0 0; text-decoration: none; }
.tabs .active, .tabs [aria-selected="true"], .tab.active { border-bottom-color: var(--primary); color: var(--primary); background: var(--accent-soft); }
.tabs a:hover, .tabs button:hover { color: var(--primary); background: var(--sage-light); }
.segmented, .segmented-control { display: inline-flex; gap: 4px; flex-wrap: wrap; padding: 4px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); }
.segmented .active, .segmented-control .active, .segmented [aria-pressed="true"] { background: var(--surface); box-shadow: 0 2px 5px #2021240a; color: var(--primary); }
.breadcrumb, .breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 22px; }
.breadcrumb a, .breadcrumbs a { min-height: 28px; display: inline-flex; align-items: center; }

/* Interactive controls: minimum 44px targets, explicit keyboard focus. */
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 9px; font-size: 13px; font-weight: 600; line-height: 1.45; text-align: center; text-decoration: none; transition: background .16s, border-color .16s, box-shadow .16s; overflow-wrap: anywhere; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--surface); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: 0 3px 9px #1d4ed820; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--sage-light); border-color: var(--sage); }
.btn-ghost { color: var(--ink); background: transparent; }
.btn-ghost:hover:not(:disabled), .btn-icon:hover:not(:disabled) { background: var(--accent-soft); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #862e2a; }
.btn-danger-outline { color: var(--danger); background: var(--danger-bg); border-color: #e6c8c0; }
.btn-icon, .icon-button { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 10px; background: transparent; border: 1px solid transparent; border-radius: 9px; color: var(--muted); }
.btn-small, .btn-sm { padding: 8px 12px; font-size: 12px; }
.btn[aria-pressed="true"] { background: var(--primary); color: white; }
.btn[data-busy] { cursor: progress; }
.field { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 20px; }
.field-label { display: block; color: var(--ink); font-size: 13px; font-weight: 650; }
.field-help { font-size: 12px; line-height: 1.7; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea { display: block; width: 100%; min-width: 0; min-height: 46px; padding: 11px 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; line-height: 1.5; transition: border-color .16s, box-shadow .16s; }
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--sage); box-shadow: 0 0 0 3px var(--focus-ring); }
input[readonly], textarea[readonly] { background: var(--surface-soft); }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
textarea { min-height: 118px; resize: vertical; }
select { padding-right: 30px; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; flex-shrink: 0; margin: 0; accent-color: var(--primary); }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--primary); }
input[type="color"] { width: 46px; height: 44px; padding: 5px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
input[type="file"] { font-size: 12px; }
input::file-selector-button { min-height: 36px; margin: -4px 12px -4px -5px; border: 0; border-radius: 5px; background: var(--sage-light); color: var(--primary); padding: 6px 12px; font: inherit; cursor: pointer; }
.check, .checkbox-row, .radio-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 13px; cursor: pointer; }
.check span { min-width: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 12px; }
.search-field, .search-box { position: relative; display: flex; align-items: center; gap: 10px; }
.search-field > svg, .search-box > svg { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.search-field input, .search-box input { padding-left: 42px !important; }

/* Feedback, progress and badges */
.notice, .form-error { display: flex; align-items: flex-start; gap: 10px; background: var(--success-bg); color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 13px 16px; font-size: 13px; line-height: 1.75; margin-bottom: 18px; overflow-wrap: anywhere; }
.notice > svg { margin-top: 3px; }
.notice p { margin-top: 4px; }
.notice.warning, .notice.warn { background: var(--warning-bg); border-color: #e9d9b2; color: var(--warning); }
.notice.error, .notice.danger, .form-error { background: var(--danger-bg); border-color: #e9c9c0; color: var(--danger); }
.notice.success { background: var(--success-bg); border-color: var(--accent-border); color: var(--success); }
.badge, .chip, .status-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 6px; background: var(--surface-soft); color: var(--muted); font-size: 11px; line-height: 1.7; font-weight: 550; white-space: nowrap; vertical-align: middle; }
.badge.success, .badge.done, .badge.correct, .badge.completed { color: var(--success); background: var(--success-bg); }
.badge.warning, .badge.pending, .badge.running, .badge.in_progress { color: #846020; background: #f7edd1; }
.badge.error, .badge.failed, .badge.incorrect, .badge.danger { color: #a14037; background: #f9e8e3; }
.badge.info, .badge.theory, .badge.primary { color: var(--success); background: var(--accent-soft); }
.badge.problem { color: var(--ink); background: var(--surface-inset); }
.badge.mixed { color: var(--primary-hover); background: var(--accent-soft); }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 290px; padding: 40px 24px; }
.empty-icon { display: grid; place-items: center; width: 74px; height: 74px; margin-bottom: 22px; border-radius: 24px; background: var(--sage-light); color: var(--muted); }
.empty-state h3 { margin-bottom: 10px; }
.empty-state p { max-width: 420px; color: var(--muted); font-size: 13px; line-height: 1.9; margin-bottom: 22px; white-space: pre-line; }
#toasts { position: fixed; z-index: 110; right: 24px; bottom: max(24px, env(safe-area-inset-bottom)); display: grid; gap: 10px; width: min(430px, calc(100% - 32px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 8px 10px 16px; background: var(--surface); color: var(--primary); box-shadow: var(--shadow-lg); font-size: 13px; pointer-events: auto; animation: appear .2s ease-out; }
.toast > span { flex: 1; overflow-wrap: anywhere; }
.toast.error { color: var(--danger); border-color: #e5bfb5; background: #fff7f2; }
.boot, .route-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; gap: 18px; padding: 32px; color: var(--muted); font-size: 13px; text-align: center; }
.loading-ring { display: inline-block; width: 28px; height: 28px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .85s linear infinite; }
progress { width: 100%; height: 7px; border: 0; border-radius: 10px; overflow: hidden; background: var(--surface-inset); accent-color: var(--sage); }
progress::-webkit-progress-bar { background: var(--surface-inset); border-radius: 10px; }
progress::-webkit-progress-value { background: var(--sage); border-radius: 10px; }
progress::-moz-progress-bar { background: var(--sage); border-radius: 10px; }
.progress-track, .progress-bar { height: 6px; border-radius: 5px; background: var(--surface-inset); overflow: hidden; }
.progress-track > *, .progress-bar > span, .progress-fill { display: block; height: 100%; border-radius: inherit; background: var(--primary); }

/* Native dialogs retain focus trapping and Escape behavior. */
dialog, .modal { width: min(540px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); margin: auto; padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: auto; overscroll-behavior: contain; }
dialog:not([open]) { display: none; }
dialog.wide, .modal.wide { width: min(900px, calc(100vw - 32px)); }
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(4px); }
dialog[open] { animation: appear .18s ease-out; }
.dialog-form { display: flex; flex-direction: column; }
.dialog-heading, .modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 25px 26px 19px; border-bottom: 1px solid var(--border); }
.dialog-heading h2 { font-size: 21px; }
.dialog-heading p { margin-top: 8px; color: var(--muted); font-size: 13px; }
.dialog-heading .btn-icon { margin: -8px -9px 0 0; }
.dialog-body, .modal-body { padding: 24px 26px; }
.dialog-body > :last-child { margin-bottom: 0; }
.dialog-footer, .modal-footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; padding: 17px 26px; border-top: 1px solid var(--border); background: var(--surface-soft); position: sticky; bottom: 0; z-index: 1; }
.dialog-form > .form-error { margin: 0 26px 20px; }

/* Catalogue: adaptable to dense collections and spacious empty states. */
.subject-grid, .book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 245px), 1fr)); gap: 20px; }
.subject-card, .book-card { position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); transition: border-color .18s, box-shadow .18s, transform .18s; }
.subject-card:hover, .book-card:hover { border-color: var(--border-strong); box-shadow: 0 7px 22px #2021240a; }
.subject-card { padding: 24px; gap: 16px; }
.subject-card h3, .book-card h3 { font-size: 18px; }
.subject-card p, .book-card p { font-size: 12px; color: var(--muted); }
.subject-card > a, .book-card > a { display: block; color: inherit; text-decoration: none; }
.subject-icon, .book-icon { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; color: var(--primary); background: var(--sage-light); }
.subject-card-top, .book-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.subject-card .card-actions, .book-card .card-actions { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.book-cover { display: flex; align-items: center; justify-content: center; min-height: 160px; padding: 24px; background: var(--surface-inset); color: var(--primary); position: relative; }
.book-cover img { height: 160px; width: 100%; object-fit: contain; }
.book-cover::after { content: ""; position: absolute; inset: 0 auto 0 16px; width: 1px; background: #fff6; }
.book-card-body, .book-info { padding: 20px; }
.book-meta, .subject-meta, .meta, .metadata { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 9px; }
.book-hero { display: flex; gap: 25px; align-items: flex-start; }
.book-hero > :last-child { flex: 1; }
.stats-grid, .stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr)); gap: 15px; margin-bottom: 25px; }
.stat-card, .stat { padding: 20px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.stat-label, .stat-card small { color: var(--muted); font-size: 12px; }
.stat-value, .stat-card strong { display: block; color: var(--ink); font-size: 29px; line-height: 1.5; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: 11px; }
.table-wrap, .table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 11px; scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
th { padding: 13px 16px; background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-soft); }
td .actions { justify-content: flex-start; }
.page-list, .round-list, .schedule-list { display: grid; gap: 10px; }
.page-row, .round-row, .schedule-row, .list-row { display: flex; align-items: center; gap: 14px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; }
.page-row > .row-content, .round-row > .row-content, .schedule-row > .row-content, .list-row > .row-content { flex: 1; }
.page-number { display: inline-grid; place-items: center; min-width: 38px; height: 40px; border-radius: 8px; background: var(--sage-light); font-weight: 650; color: var(--primary); font-variant-numeric: tabular-nums; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 24px; flex-wrap: wrap; }

/* Upload, source documents, OCR review */
.drop-zone, .dropzone, .upload-zone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 220px; border: 1.5px dashed var(--border-strong); background: var(--surface-soft); border-radius: 14px; padding: 28px; text-align: center; color: var(--muted); }
.drop-zone.dragover, .dropzone.dragover, .upload-zone.dragover, .drop-zone.is-dragover { background: var(--accent-soft); border-color: var(--primary); }
.drop-zone p, .dropzone p, .upload-zone p { color: var(--muted); font-size: 13px; }
.upload-list, .file-list, .ocr-list { display: grid; gap: 12px; margin-top: 20px; }
.upload-item, .file-item { display: flex; align-items: center; gap: 14px; padding: 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.upload-item > div, .file-item > div { flex: 1; overflow-wrap: anywhere; }
.upload-preview, .source-preview { max-height: 360px; width: 100%; object-fit: contain; border-radius: 9px; background: var(--surface-inset); }
.ocr-text { white-space: pre-wrap; line-height: 1.9; overflow-wrap: anywhere; }
.source-viewer, .image-viewer { position: relative; display: flex; flex-direction: column; min-height: 300px; background: var(--surface-inset); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.viewer-toolbar, .source-toolbar { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.viewer-toolbar span, .source-toolbar span { font-size: 12px; color: var(--muted); }
.viewer-viewport, .source-viewport, .image-viewport, .source-canvas { position: relative; flex: 1; min-height: 280px; max-height: 75vh; overflow: auto; overscroll-behavior: contain; background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 18px 18px; cursor: grab; }
.viewer-viewport:active, .source-viewport:active, .image-viewport:active, .source-canvas:active { cursor: grabbing; }
.viewer-viewport img, .source-viewport img, .image-viewport img, .source-canvas img { max-width: none; transform-origin: top left; user-select: none; -webkit-user-drag: none; }
.source-image { transform-origin: top left; user-select: none; }
.source-viewer iframe, .source-viewer object { width: 100%; min-height: 480px; border: 0; }

/* Rich text, recovery comparison, and save status */
.editor-wrap { border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.editor-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 5px 8px; background: var(--surface-soft); border-bottom: 1px solid var(--border); }
.editor-tool { min-width: 44px; min-height: 44px; padding: 7px; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--muted); font-size: 14px; }
.editor-tool:hover, .editor-tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--primary); }
.editor-toolbar select { width: auto; min-width: 76px; min-height: 44px; padding: 6px 8px; border-color: transparent; background: transparent; font-size: 12px; }
.editor-toolbar input[type="color"] { background: transparent; border-color: transparent; }
.tool-divider { width: 1px; height: 21px; margin-inline: 4px; background: var(--border); }
.rich-editor { min-height: 220px; padding: 21px 22px; outline-offset: -4px; color: var(--ink); font-size: 15px; line-height: 1.95; overflow-wrap: anywhere; overflow-x: auto; }
.rich-editor.compact { min-height: 135px; }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.rich-editor:focus { outline: 2px solid transparent; }
.rich-content { line-height: 1.95; overflow-wrap: anywhere; }
.rich-editor p, .rich-content p { margin: 0 0 .8em; }
.rich-editor h1, .rich-content h1 { font-size: 26px; margin: .9em 0 .5em; }
.rich-editor h2, .rich-content h2 { font-size: 22px; margin: .9em 0 .5em; }
.rich-editor h3, .rich-content h3 { font-size: 18px; margin: .9em 0 .5em; }
.rich-editor ul, .rich-editor ol, .rich-content ul, .rich-content ol { padding-left: 25px; }
.rich-editor blockquote, .rich-content blockquote { margin: 16px 0; padding: 9px 17px; background: var(--surface-soft); border-left: 3px solid var(--border-strong); color: var(--muted); }
.rich-editor pre, .rich-content pre { padding: 15px; background: var(--surface-soft); border-radius: 8px; }
.rich-editor table, .rich-content table { display: block; max-width: 100%; overflow-x: auto; }
.rich-editor td, .rich-content td, .rich-editor th, .rich-content th { border: 1px solid var(--border); }
.save-indicator { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 6px 10px; border-radius: 7px; color: var(--success); background: var(--success-bg); font-size: 11px; line-height: 1.6; }
.save-indicator.warn { color: #8d611f; background: #faf0d8; }
.status-dot { width: 6px; height: 6px; flex-shrink: 0; border-radius: 50%; background: currentColor; }
.pulse { animation: pulse 1.3s ease-in-out infinite; }
.save-detail:empty { display: none; }
.save-detail { margin: 12px 0; }
.save-detail .notice { margin-bottom: 8px; }
.draft-notice { align-items: center; flex-wrap: wrap; }
.draft-notice > div { flex: 1 1 230px; }
.compare-header { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 22px 0 14px; font-size: 13px; color: var(--ink); }
.draft-row { margin: 18px 0; }
.draft-row h4 { margin-bottom: 10px; }
.draft-preview { min-height: 90px; max-height: 280px; overflow: auto; padding: 16px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 8px; }

/* Study desk: explicitly bounded flex/grid children prevent page overflow. */
.study-main { min-width: 0; }
.study-page, .study-layout, .study-shell { min-width: 0; }
.study-page { padding: 25px 28px; }
.study-header, .study-topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 18px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.study-header h1, .study-topbar h1 { font-size: 20px; }
.study-header p, .study-topbar p { font-size: 12px; color: var(--muted); }
.study-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface-soft); }
.study-layout, .study-workspace { display: flex; align-items: stretch; min-height: calc(100dvh - 160px); }
.study-sidebar, .study-nav { flex: 0 0 210px; width: 210px; padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface-soft); overflow-y: auto; overscroll-behavior: contain; }
.study-sidebar.collapsed, .study-nav.collapsed, .study-layout.sidebar-collapsed .study-sidebar { display: none; }
.study-sidebar h3, .study-nav h3 { font-size: 13px; padding: 0 8px 12px; }
.study-sidebar a, .study-sidebar .page-link, .study-nav a { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px; margin-bottom: 4px; border-radius: 7px; color: var(--muted); font-size: 12px; text-decoration: none; }
.study-sidebar .active, .study-nav .active { background: var(--accent-soft); color: var(--primary); font-weight: 650; }
.study-content, .study-body { flex: 1; min-width: 0; padding: 22px; }
.study-panels, .study-split, .split-view { display: flex; align-items: stretch; gap: 0; min-width: 0; }
.study-panel, .source-panel, .notes-panel, .answer-panel { min-width: 0; flex: 1 1 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.study-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.study-panel-header h2, .study-panel-header h3 { font-size: 14px; }
.study-panel-body { padding: 20px; }
.study-section { margin-bottom: 24px; }
.study-section > h2, .study-section > h3 { margin-bottom: 12px; font-size: 16px; }
.study-panel .editor-wrap { margin-bottom: 14px; }
.resizer, .resize-handle, .splitter, .panel-resizer { flex: 0 0 14px; width: 14px; cursor: col-resize; position: relative; touch-action: none; }
.resizer::after, .resize-handle::after, .splitter::after, .panel-resizer::after { content: ""; position: absolute; top: calc(50% - 24px); left: calc(50% - 2px); width: 4px; height: 48px; border-radius: 4px; background: var(--border); }
.resizer:hover::after, .resize-handle:hover::after, .splitter:hover::after, .panel-resizer:hover::after { background: var(--sage); }
.study-footer, .study-navigation { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 22px; padding: 16px 0; border-top: 1px solid var(--border); }
.question-card { padding: 21px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.question-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.answer-reveal, .solution-box { margin-top: 16px; padding: 20px; border: 1px solid var(--accent-border); border-radius: 10px; background: var(--success-bg); }
.grade-correct { color: var(--success); }
.grade-incorrect { color: var(--danger); }

/* Schedules and settings */
.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--border); border-top: 1px solid var(--border); }
.calendar-day { min-height: 110px; padding: 9px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); }
.calendar-day.today { background: var(--success-bg); }
.calendar-day.other-month { color: var(--muted); background: var(--surface-soft); }
.calendar-weekday { padding: 9px; background: var(--surface-soft); color: var(--muted); font-size: 11px; text-align: center; }
.calendar-event { display: block; padding: 5px 7px; margin-top: 5px; border-radius: 5px; background: var(--accent-soft); color: var(--primary); font-size: 11px; overflow-wrap: anywhere; }
.schedule-date { flex-shrink: 0; width: 54px; padding: 8px; background: var(--surface-soft); border-radius: 9px; text-align: center; color: var(--primary); }
.schedule-date strong { display: block; font-size: 22px; }
.schedule-row.done { background: var(--surface-soft); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 24px; }
.settings-section { padding: 25px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.settings-section h2 { font-size: 18px; margin-bottom: 8px; }
.settings-section > p { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 17px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: 0; }
.settings-row small { color: var(--muted); display: block; margin-top: 4px; }
.danger-zone { border-color: #e2c7bc; }
.danger-zone h2, .danger-zone h3 { color: var(--danger); }
details { border: 1px solid var(--border); border-radius: 9px; padding: 0 16px; background: var(--surface); }
summary { min-height: 48px; padding: 13px 0; color: var(--ink); font-size: 13px; font-weight: 600; }
details[open] > summary { margin-bottom: 14px; border-bottom: 1px solid var(--border); }
details > :last-child:not(summary) { margin-bottom: 16px; }

/* A quiet, hand-built book illustration for the signed-out experience. */
.login-layout { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr; }
.login-story { position: relative; display: flex; flex-direction: column; padding: 44px clamp(32px, 5vw, 80px) 32px; background: var(--surface-soft); overflow: hidden; }
.login-wordmark { display: flex; align-items: center; gap: 12px; color: var(--ink); font-size: 20px; font-weight: 700; letter-spacing: -.05em; }
.login-message { width: min(100%, 460px); margin: auto; padding-top: 55px; }
.login-message .eyebrow { color: var(--muted); font-size: 10px; margin-bottom: 20px; }
.login-message h1 { font-size: clamp(32px, 3vw, 46px); line-height: 1.55; font-weight: 650; letter-spacing: -.065em; }
.login-message > p { margin-top: 22px; color: var(--muted); line-height: 2; font-size: 14px; }
.login-footer { position: relative; color: var(--muted); font-size: 11px; margin-top: auto; padding-top: 26px; }
.book-illustration { position: relative; width: 350px; max-width: 100%; height: 260px; margin: 16px auto 5px; isolation: isolate; }
.illustration-circle { position: absolute; z-index: -1; width: 222px; height: 222px; top: 12px; left: 55px; border-radius: 50%; background: var(--surface-inset); }
.illustration-circle::after { content: ""; position: absolute; width: 46px; height: 46px; top: 12px; right: -25px; border-radius: 50%; border: 1px solid var(--accent-border); }
.illustration-book { position: absolute; top: 83px; width: 140px; height: 161px; padding: 36px 20px 16px; background: var(--surface); box-shadow: 0 8px 0 var(--surface-inset), 0 10px 0 var(--surface), 0 22px 30px #2021240a; }
.illustration-book.left { left: 35px; transform: skewY(-9deg) rotate(-7deg); border-radius: 9px 1px 2px 10px; background: linear-gradient(90deg, var(--surface) 70%, var(--surface-soft)); }
.illustration-book.right { left: 175px; transform: skewY(9deg) rotate(-7deg); border-radius: 1px 9px 10px 2px; background: linear-gradient(90deg, var(--surface-soft), var(--surface) 20%); }
.illustration-book.right::after { content: ""; position: absolute; right: 22px; top: -4px; width: 15px; height: 54px; background: var(--primary); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); }
.illustration-book i { display: block; height: 2px; background: var(--border); margin-top: 13px; width: 88%; }
.illustration-book i:last-child { width: 62%; }
.illustration-book span { color: var(--muted); font-size: 13px; font-weight: 550; }
.illustration-stem { position: absolute; left: 20px; top: 41px; transform: rotate(-26deg); color: var(--muted); }
.login-side { display: flex; align-items: center; justify-content: center; padding: 56px 44px; background: var(--bg); }
.login-card { width: 100%; max-width: 385px; }
.login-welcome { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 20px; }
.login-card h2 { font-size: 25px; letter-spacing: -.05em; line-height: 1.55; margin-bottom: 12px; }
.login-card > p.muted { font-size: 13px; line-height: 1.85; }
.login-form { margin-top: 34px; }
.login-form .field { margin-bottom: 20px; }
.login-form input { min-height: 51px !important; background: var(--surface) !important; }
.login-submit { width: 100%; min-height: 51px; justify-content: space-between; padding-inline: 20px; margin-top: 7px; }
.login-help { display: flex; align-items: flex-start; justify-content: center; gap: 7px; color: var(--muted); font-size: 11px; line-height: 1.85; white-space: pre-line; border-top: 1px solid var(--border); padding-top: 23px; margin-top: 28px; }
.login-help svg { margin-top: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .4; } }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 1600px) {
  .page { padding-top: 60px; }
  .login-message { padding-top: 35px; }
  .book-illustration { margin-top: 38px; }
}
@media (max-width: 1199px) {
  .page { padding: 34px 28px 48px; }
  .study-sidebar, .study-nav { flex-basis: 172px; width: 172px; }
  .study-content, .study-body { padding: 16px; }
  .study-panels, .study-split, .split-view { flex-wrap: wrap; gap: 16px; }
  .study-panel, .source-panel, .notes-panel, .answer-panel { flex-basis: 100%; width: 100% !important; }
  .resizer, .resize-handle, .splitter, .panel-resizer { display: none; }
  .three-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-toolbar { gap: 1px; padding-inline: 4px; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 264px; max-width: calc(100vw - 56px); z-index: 70; }
  .app-body { margin-left: 0; }
  .mobile-header { display: flex; position: sticky; top: 0; z-index: 35; justify-content: space-between; align-items: center; gap: 12px; min-height: 65px; padding: max(9px, env(safe-area-inset-top)) 18px 9px; background: #f3f4f6f5; border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); }
  .brand-inline { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }
  .mobile-header a { text-decoration: none; }
  .main { min-height: calc(100dvh - 65px); }
  .menu-open { overflow: hidden; }
  .menu-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .menu-open .sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 60; width: 100%; height: 100dvh; padding: 0; border: 0; background: var(--overlay); }
  .page-heading, .page-header { flex-direction: column; align-items: stretch; gap: 16px; }
  .page-heading > div:first-child, .page-header > div:first-child { flex: 0 0 auto; width: 100%; }
  .page-heading > .actions, .page-header > .actions { width: 100%; justify-content: flex-start; }
  .page-heading .actions .actions, .page-header .actions .actions { justify-content: flex-start; max-width: 100%; }
  .login-story { padding: 32px; }
  .login-message h1 { font-size: 32px; }
  .login-side { padding: 36px; }
  .book-illustration { transform: scale(.85); transform-origin: left center; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  h1 { font-size: 27px; }
  h2 { font-size: 20px; }
  .page { padding: 27px 18px 42px; }
  .page-heading, .page-header { flex-direction: column; gap: 18px; margin-bottom: 25px; }
  .page-heading .actions, .page-header .actions { width: 100%; justify-content: flex-start; }
  .page-heading .actions > .btn, .page-header .actions > .btn { flex-grow: 1; }
  .subtitle { font-size: 13px; margin-top: 8px; }
  .panel, .card, .settings-section { padding: 19px 17px; border-radius: 12px; }
  .panel { margin-bottom: 18px; }
  .panel-heading, .panel-header, .section-heading, .section-header { flex-wrap: wrap; gap: 10px; }
  .grid, .subject-grid, .book-grid, .two-col, .two-column, .three-col, .form-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .stats-grid, .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card, .stat { padding: 15px; }
  .stat-value, .stat-card strong { font-size: 25px; }
  .toolbar { gap: 10px; }
  .toolbar input[type="search"] { flex-basis: 100%; }
  .toolbar .field { flex: 1 1 130px; }
  .toolbar select { flex: 1; }
  .tabs { gap: 1px; margin-bottom: 20px; }
  .tabs > a, .tabs > button, .tab { padding-inline: 13px; font-size: 12px; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea, .rich-editor { font-size: 16px; }
  .editor-toolbar select { font-size: 16px; }
  .field { margin-bottom: 18px; }
  .empty-state { min-height: 265px; padding: 28px 12px; }
  .empty-state p { max-width: 290px; }
  .book-hero { gap: 15px; flex-wrap: wrap; }
  .book-hero .book-cover { min-height: 100px; width: 85px; }
  .page-row, .round-row, .schedule-row, .list-row { flex-wrap: wrap; padding: 13px; gap: 10px; }
  .row-actions { width: 100%; justify-content: flex-end; }
  .notice { padding: 12px; font-size: 12px; }
  dialog, .modal { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); border-radius: 14px; }
  dialog.wide, .modal.wide { width: calc(100vw - 24px); }
  .dialog-heading, .modal-header { padding: 21px 19px 16px; }
  .dialog-heading h2 { font-size: 19px; }
  .dialog-body, .modal-body { padding: 20px 19px; }
  .dialog-footer, .modal-footer { padding: 14px 19px max(14px, env(safe-area-inset-bottom)); }
  .dialog-footer .btn { flex: 1 1 auto; }
  .dialog-form > .form-error { margin-inline: 19px; }
  .compare-grid, .compare-header { gap: 8px; }
  .draft-preview { padding: 10px; font-size: 12px; }
  #toasts { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
  .study-page { padding: 16px 12px; }
  .study-header, .study-topbar { padding: 15px; gap: 12px; }
  .study-header .actions, .study-topbar .actions { width: 100%; justify-content: flex-start; }
  .study-toolbar { padding: 10px 12px; }
  .study-layout, .study-workspace { flex-direction: column; min-height: 0; }
  .study-sidebar, .study-nav { flex: 0 0 auto; width: 100%; max-height: 220px; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px; }
  .study-content, .study-body { padding: 14px 12px; }
  .study-panels, .study-split, .split-view { flex-direction: column; }
  .study-panel-body, .question-card { padding: 16px; }
  .rich-editor { padding: 17px 15px; min-height: 190px; }
  .editor-toolbar { padding: 5px; }
  .tool-divider { margin-inline: 1px; }
  .source-viewer, .image-viewer { min-height: 260px; }
  .viewer-viewport, .source-viewport, .image-viewport, .source-canvas { min-height: 230px; max-height: 60dvh; }
  .calendar-day { min-height: 84px; padding: 4px; font-size: 11px; }
  .calendar-event { font-size: 10px; padding: 3px; }
  .calendar-weekday { padding: 6px 2px; }
  .settings-row { flex-wrap: wrap; gap: 12px; }
  .login-layout { display: flex; flex-direction: column; }
  .login-story { padding: 24px 25px 29px; }
  .login-wordmark { font-size: 17px; gap: 9px; }
  .login-wordmark svg { width: 25px; }
  .login-message { padding-top: 31px; margin: 0; width: 100%; }
  .login-message .eyebrow { font-size: 9px; margin-bottom: 12px; }
  .login-message h1 { position: relative; z-index: 1; font-size: 29px; line-height: 1.5; }
  .login-message > p { position: relative; z-index: 1; font-size: 12px; margin-top: 14px; line-height: 1.85; }
  .book-illustration { position: absolute; right: -116px; bottom: -47px; transform: scale(.52) rotate(9deg); transform-origin: center; opacity: .5; pointer-events: none; }
  .login-footer { display: none; }
  .login-side { padding: 33px 25px 36px; align-items: flex-start; }
  .login-card { max-width: 420px; }
  .login-welcome { font-size: 11px; margin-bottom: 12px; }
  .login-card h2 { font-size: 22px; }
  .login-card > p.muted { font-size: 12px; }
  .login-form { margin-top: 25px; }
  .login-help { font-size: 10px; margin-top: 22px; padding-top: 18px; }
}
/* Integration with the classes emitted by catalog/uploads/schedules/settings/study.js. */
.back-link { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; margin-bottom: 12px; font-size: 13px; }
.book-context-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 20px; }
.book-context-bar > .field { flex: 0 1 480px; margin: 0; }
.book-tabs { display: flex; gap: 5px; max-width: 100%; margin-bottom: 24px; padding: 3px 2px 0; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.book-tab { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; min-height: 46px; padding: 10px 18px; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.book-tab:hover, .book-tab.active, .book-tab[aria-current="page"] { background: var(--sage-light); color: var(--primary); text-decoration: none; }
.book-tab.active, .book-tab[aria-current="page"] { border-bottom-color: var(--primary); }
.filter-bar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 20px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.filter-bar > .field { flex: 1 1 160px; min-width: 0; margin: 0; }
.filter-bar select, .study-controls select { max-width: 100%; text-overflow: ellipsis; }
.section-heading > .actions > .field { margin: 0; }
.book-overview-body { display: grid; grid-template-columns: minmax(140px, 200px) minmax(0, 1fr); align-items: start; gap: 26px; }
.book-overview-body > div:first-child { display: grid; gap: 12px; }
.book-overview .book-cover { border-radius: 10px; min-height: 220px; }
.book-cover-placeholder { display: grid; justify-items: center; gap: 14px; text-align: center; overflow-wrap: anywhere; }
.book-overview-details { display: grid; gap: 16px; }
.book-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.book-stats > div { padding: 13px; border-radius: 10px; background: var(--surface-soft); }
.book-stats strong { display: block; color: var(--ink); font-size: 25px; line-height: 1.4; }
.book-stats span { color: var(--muted); font-size: 12px; }
.quick-actions, .badge-row, .book-card-meta, .page-row-actions, .subject-card-actions, .toc-pages { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.book-card-meta, .book-card-note { margin-top: 12px; }
.preserve-lines, .pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.page-thumbnail { flex: 0 0 72px; width: 72px; }
.page-thumbnail img, .answer-cover { width: 72px; height: 92px; object-fit: contain; background: var(--surface-soft); border-radius: 7px; }
.answer-cover { display: grid; align-content: center; justify-items: center; gap: 7px; }
.page-row-body { flex: 1 1 180px; overflow-wrap: anywhere; }
.page-row-body .badge-row { margin: 8px 0; }
.page-row-actions { flex: 0 1 280px; justify-content: flex-end; }
.round-card, .history-item { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow-wrap: anywhere; }
.round-card.current { border-color: var(--sage); background: var(--success-bg); }
/* Completed schedules have their own density, not the shared round-card layout. */
.history-item.schedule-history-card {
  display: grid; grid-template-columns: 108px minmax(0, 1fr) auto; gap: 18px;
  padding: 16px 18px; align-items: center; border-radius: 14px;
  background: linear-gradient(100deg, #f1f8ff 0, #fff 220px);
}
.schedule-history-date { align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding-right: 16px; border-right: 1px solid var(--border); }
.schedule-history-date small { font-size: 11px; color: var(--muted); }
.schedule-history-date time { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.5; word-break: keep-all; overflow-wrap: normal; }
.schedule-history-date time.is-undated { font-size: 12px; font-weight: 400; color: var(--muted); }
.schedule-history-content { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 5px 8px; min-width: 0; }
.schedule-history-round { justify-self: start; padding: 2px 8px; border-radius: 6px; background: #e5f2ff; color: #285678; font-size: 12px; font-weight: 650; }
.schedule-history-range { margin: 0; font-size: 17px; line-height: 1.4; }
.schedule-history-book,.schedule-history-notes { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.schedule-history-notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.schedule-history-open { white-space: nowrap; font-size: 12px; padding: 8px 12px; min-height: 38px; }
.workspace-focus-help { color: var(--muted); font-size: 11px; white-space: nowrap; }
@media (max-width: 600px) {
  .history-item.schedule-history-card { grid-template-columns: 86px minmax(0, 1fr); gap: 10px 12px; padding: 14px 12px; }
  .schedule-history-date { padding-right: 10px; grid-row: 1 / 3; }
  .schedule-history-date time { font-size: 12px; }
  .schedule-history-content { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .schedule-history-range { font-size: 16px; }
  .schedule-history-book,.schedule-history-notes { font-size: 12px; }
  .schedule-history-open { grid-column: 2; justify-self: start; }
}
.history-list, .token-list, .user-list { display: grid; gap: 12px; }
.toc-tree { list-style: none; padding-left: 0; margin: 0; }
.toc-tree .toc-tree { margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--border); }
.toc-tree:empty { display: none; }
.toc-node { padding-block: 10px; overflow-wrap: anywhere; }
.toc-node-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.toc-node-heading small { display: block; }
.toc-pages { margin-top: 8px; }
.page-chip { display: inline-flex; align-items: center; min-height: 44px; padding: 7px 12px; background: var(--sage-light); border-radius: 8px; font-size: 12px; }
/* Bulk upload contract: native radios inside labels; content scrolls, footer stays put. */
dialog.upload-dialog { width: min(1080px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: hidden; }
.upload-dialog .dialog-form { max-height: calc(100dvh - 34px); min-height: 0; }
.upload-dialog .dialog-heading { flex: 0 0 auto; padding: 16px 20px 12px; }
.upload-dialog .dialog-heading h2 { font-size: 19px; }
.upload-dialog .dialog-heading p { margin-top: 4px; }
.upload-dialog .dialog-body { flex: 1 1 auto; min-height: 0; padding: 14px 20px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.upload-dialog .dialog-footer { flex: 0 0 auto; padding: 10px 20px; background: var(--surface); }
.upload-dialog .dialog-form > .form-error { flex: 0 0 auto; max-height: 20dvh; overflow: auto; margin: 0 20px 10px; }
.upload-content { display: grid; gap: 12px; min-width: 0; }
.upload-help { color: var(--muted); font-size: 12px; line-height: 1.6; }
.upload-file-actions, .upload-batch-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.upload-pick { position: relative; cursor: pointer; }
.upload-pick:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
/* Override generic input dimensions without removing keyboard/file-picker access. */
.upload-dialog .upload-file-actions .upload-pick input[type="file"] { position: absolute; width: 1px; height: 1px; min-width: 0; min-height: 0; padding: 0; margin: -1px; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.upload-controls { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-soft); }
.upload-batch-grid { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 14px; }
.upload-dialog .field { gap: 4px; margin: 0; }
.upload-dialog .field-label { font-size: 12px; line-height: 1.4; }
.upload-dialog input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .upload-dialog select { min-height: 36px; padding: 6px 8px; font-size: 14px; line-height: 1.5; border-radius: 7px; }
.upload-start { flex: 0 0 90px; width: 90px; }
.upload-more { margin-top: 8px; padding: 0 10px; background: transparent; }
.upload-more > summary { min-height: 36px; padding: 7px 0; font-size: 12px; }
.upload-more[open] > summary { margin-bottom: 8px; }
.upload-more > :last-child:not(summary) { margin-bottom: 10px; }
.upload-more .field { max-width: 320px; }
.upload-batch-actions { margin-top: 10px; }
.upload-batch-actions .btn { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.upload-choice-group { display: flex; align-items: center; flex-wrap: nowrap; gap: 4px; min-width: 0; margin: 0; padding: 0; border: 0; border-radius: 0; }
.upload-choice-group > legend { float: none; width: 100%; padding: 0; margin-bottom: 4px; font-size: 12px; font-weight: 650; line-height: 1.4; color: var(--ink); }
.upload-choice { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 5px; flex: 1 1 auto; min-width: 0; min-height: 36px; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface); color: var(--ink); font-size: 12px; line-height: 1.4; white-space: nowrap; cursor: pointer; }
.upload-choice > input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); }
.upload-choice:has(input:checked) { color: var(--primary-hover); background: var(--accent-soft); border-color: var(--primary); }
.upload-choice > input:checked + span { font-weight: 700; }
.upload-choice:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.upload-choice:has(input:disabled) { opacity: .6; cursor: not-allowed; }
.upload-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.upload-summary .upload-progress { flex: 1 1 180px; width: auto; height: 6px; min-width: 80px; }
.upload-list { gap: 8px; margin-top: 0; }
.upload-item { display: grid; grid-template-columns: 60px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 108px; padding: 10px; }
.upload-item > .upload-preview { display: grid; place-items: center; width: 60px; height: 80px; border-radius: 6px; overflow: hidden; background: var(--surface-soft); }
.upload-preview img { width: 100%; height: 100%; max-height: 80px; object-fit: contain; }
.upload-item > .upload-fields { display: grid; gap: 7px; min-width: 0; }
.upload-file-heading { display: flex; align-items: baseline; gap: 8px; min-width: 0; line-height: 1.4; }
.upload-file-heading strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; }
.upload-file-heading small { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.upload-row-controls { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 7px 10px; min-width: 0; }
.upload-page-number { flex: 0 0 78px; width: 78px; }
.upload-kind { flex: 1 1 194px; }
.upload-role { flex: 1 1 152px; }
.upload-toc { flex: 1 1 120px; }
.upload-toc select { width: 100%; text-overflow: ellipsis; }
.upload-item > .upload-item-actions { display: flex; flex-direction: row; align-items: center; align-self: center; flex-wrap: nowrap; gap: 2px; }
.upload-item-actions .btn-icon { min-width: 36px; min-height: 36px; width: 36px; height: 36px; padding: 7px; }
.upload-error { margin: 0; color: var(--danger); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.upload-item.ready .upload-error { color: var(--muted); }
.upload-item.uploading { border-color: var(--primary); }
.upload-item.uploading .upload-error, .upload-item.success .upload-error { color: var(--success); }
.upload-item.success { border-color: var(--accent-border); }
.upload-item.error { border-color: var(--danger); }
.upload-item.verify { border-color: var(--warning); }
.upload-item.verify .upload-error { color: var(--warning); }
.upload-error:empty { display: none; }
@media (max-width: 1000px) and (min-width: 641px) {
  .upload-item { grid-template-columns: 52px minmax(0, 1fr); }
  .upload-item > .upload-preview { width: 52px; height: 70px; grid-row: 1 / 3; }
  .upload-item > .upload-item-actions { grid-column: 2; justify-self: end; margin-top: -4px; }
  .upload-row-controls { gap: 6px; }
  .upload-kind { flex-basis: 186px; }
  .upload-role { flex-basis: 140px; }
}
.ocr-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.ocr-compare > img, .cover-preview img { max-height: 460px; object-fit: contain; margin-inline: auto; }
.schedule-card.panel, .token-row.panel { margin-bottom: 0; }
.schedule-card > .actions, .schedule-card > .notice { margin-top: 14px; }
.schedule-panel > details { margin-top: 20px; }
.schedule-card, .settings-section { overflow-wrap: anywhere; }
.settings-section > .btn + .notice { margin-top: 18px; }
.page-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 6px; max-height: 280px; overflow-y: auto; }
/* study.js owns --original-width and data-mobile-tab; do not size unused panel aliases. */
.study-view.study-workspace { display: block; min-height: 0; }
.study-breadcrumb, .study-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; width: 100%; }
.study-breadcrumb h1 { flex: 1 1 180px; }
.study-controls { align-items: flex-end; }
.study-controls > .field { flex: 1 1 150px; margin: 0; }
.study-controls > .actions { flex: 1 1 260px; }
.study-view .study-layout { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 14px; min-height: 0; padding: 18px; align-items: start; }
.study-page-nav { min-width: 0; }
.study-page-nav > details { padding-inline: 10px; }
.page-nav-list { display: grid; gap: 5px; max-height: 65dvh; overflow-y: auto; overscroll-behavior: contain; }
.page-nav-item { display: flex; justify-content: flex-start; text-align: left; width: 100%; min-width: 0; padding: 10px 8px; gap: 8px; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.page-nav-item > span:not(.badge) { flex: 1 1 65px; font-size: 12px; overflow-wrap: anywhere; }
.page-nav-item.active { background: var(--sage-light); color: var(--primary); box-shadow: inset 3px 0 var(--primary); }
.study-view .study-split { display: grid; grid-template-columns: minmax(0, var(--original-width, 48%)) 14px minmax(0, 1fr); gap: 0; align-items: start; width: 100%; }
.original-panel, .work-panel { min-width: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.original-panel { display: flex; flex-direction: column; }
.original-panel > .panel-heading { padding: 14px 16px; margin: 0; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.original-panel h2 { font-size: 16px; }
.original-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--border); }
.zoom-label { font-size: 12px; min-width: 42px; text-align: center; }
.original-viewport { height: clamp(340px, 65dvh, 820px); flex: none; }
.original-viewport .original-image { width: 100%; max-width: 100%; height: auto; }
.study-splitter { position: relative; align-self: stretch; min-height: 160px; cursor: col-resize; touch-action: none; }
.study-splitter::after { content: ""; position: absolute; top: calc(50% - 24px); left: 5px; width: 4px; height: 48px; border-radius: 4px; background: var(--border-strong); }
.study-splitter:hover::after, .study-splitter:focus-visible::after { background: var(--sage); }
.work-panel > .study-content { padding: 16px; }
.study-tabs { margin-bottom: 14px; }
.study-tabs > .tab { padding-inline: 12px; }
.study-phase, .completion-controls, .question-heading, .question-grade, .explanation-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.study-phase small { color: var(--muted); }
.study-score { color:var(--ink); font-size:13px; font-variant-numeric:tabular-nums; white-space:nowrap; }
.completion-controls { padding-block: 12px; }
.completion-controls > .field { flex: 1 1 160px; margin: 0; }
.note-section { margin-bottom: 24px; }
.note-section > .section-heading { margin-bottom: 6px; }
.note-section h2 { font-size: 17px; }
.note-section > p { margin-bottom: 12px; font-size: 12px; }
.question-actions, .question-prompt, .choice-buttons { margin-bottom: 16px; }
.question-options { list-style: none; padding: 0; }
.question-options > li { display: flex; gap: 10px; margin-bottom: 10px; }
.option-number { flex: 0 0 24px; color: var(--primary); font-weight: 600; }
.answer-key-preview, .explanation-card { padding: 16px; margin-block: 16px; border: 1px solid var(--border); border-radius: 10px; overflow-wrap: anywhere; }
.answer-key-preview > * { display: block; margin-bottom: 6px; }
.study-page-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-top: 1px solid var(--border); }
.study-page-footer > span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.study-mobile-tabs { display: none; }
@media (max-width: 1199px) {
  .study-view .study-layout { grid-template-columns: minmax(0, 1fr); }
  .page-nav-list { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); max-height: 140px; }
  .page-row { flex-wrap: wrap; }
}
@media (max-width: 900px) {
  .study-mobile-tabs { display: flex; gap: 6px; padding: 10px 18px; background: var(--surface-soft); border-bottom: 1px solid var(--border); }
  .study-mobile-tabs > .btn { flex: 1; }
  .study-mobile-tabs .active { background: var(--primary); color: var(--surface); }
  .study-view .study-split { grid-template-columns: minmax(0, 1fr); }
  .study-splitter { display: none; }
  .study-view[data-mobile-tab="work"] .original-panel, .study-view[data-mobile-tab="original"] .work-panel { display: none; }
}
@media (max-width: 640px) {
  .book-tabs { gap: 2px; margin-bottom: 18px; }
  .book-tab { padding-inline: 12px; font-size: 12px; }
  .book-context-bar > .field { flex-basis: 100%; }
  .filter-bar { padding: 12px; gap: 12px; }
  .filter-bar > .field { flex-basis: calc(50% - 6px); }
  .book-overview-body, .ocr-compare { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .book-overview-body > div:first-child { width: min(100%, 200px); margin-inline: auto; }
  .book-stats > div { padding: 10px; }
  .page-row-actions { flex: 1 1 100%; justify-content: flex-start; }
  dialog.upload-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 12px; }
  .upload-dialog .dialog-form { max-height: calc(100dvh - 18px); }
  .upload-dialog .dialog-heading { padding: 12px; }
  .upload-dialog .dialog-body { padding: 10px; scrollbar-gutter: auto; }
  .upload-dialog .dialog-footer { padding: 8px 10px max(8px, env(safe-area-inset-bottom)); gap: 6px; }
  .upload-dialog .dialog-form > .form-error { margin-inline: 10px; }
  .upload-content { gap: 10px; }
  .upload-file-actions .btn { flex: 1 1 auto; padding-inline: 10px; }
  .upload-controls { padding: 8px; }
  .upload-batch-grid { gap: 8px; }
  .upload-batch-grid .upload-choice-group { flex: 1 1 auto; }
  .upload-dialog input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .upload-dialog select { min-height: 42px; font-size: 16px; }
  .upload-choice { min-height: 42px; padding: 7px 6px; gap: 4px; }
  .upload-choice > input[type="radio"] { width: 16px; height: 16px; }
  .upload-batch-actions .btn, .upload-more > summary { min-height: 42px; }
  .upload-item { grid-template-columns: 38px minmax(0, 1fr); align-items: start; gap: 6px; padding: 8px; min-height: 0; }
  .upload-item > .upload-preview { width: 38px; height: 48px; grid-column: 1; grid-row: 1; }
  .upload-preview img { max-height: 48px; }
  /* Flatten only layout wrappers, preserving the native label/fieldset semantics. */
  .upload-item > .upload-fields { display: contents; }
  .upload-file-heading { grid-column: 2; grid-row: 1; padding-top: 0; padding-bottom: 42px; position: relative; }
  .upload-file-heading small { position: absolute; left: 0; bottom: 3px; }
  .upload-row-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 6px 8px; }
  .upload-page-number { width: auto; }
  .upload-kind { grid-column: 2; }
  .upload-role { grid-column: 1 / -1; justify-self: start; }
  .upload-toc { grid-column: 1 / -1; }
  .upload-choice-group > legend, .upload-dialog .field-label { font-size: 11px; }
  .upload-error { grid-column: 1 / -1; }
  .upload-item > .upload-item-actions { grid-column: 2; grid-row: 1; align-self: end; justify-self: end; gap: 0; background: var(--surface); }
  .upload-file-heading { padding-right: 0; }
  .upload-file-heading small { max-width: calc(100% - 120px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .upload-kind .upload-choice { padding-inline: 5px; }
  .upload-item-actions .btn-icon { width: 40px; height: 40px; min-width: 40px; min-height: 40px; padding: 9px; }
  .upload-role { grid-row: 2; }
  .upload-item:has(.upload-toc) .upload-role { width: calc(50% - 4px); justify-self: stretch; }
  .upload-item:has(.upload-toc) .upload-role .upload-choice { padding-inline: 4px; gap: 3px; font-size: 11px; }
  .upload-item:has(.upload-toc) .upload-toc { grid-column: 1 / -1; grid-row: 2; margin-left: calc(50% + 4px); align-self: end; }

  .study-view .study-layout { padding: 12px; gap: 12px; }
  .study-controls > .field { flex-basis: calc(50% - 7px); }
  .study-controls > .actions { flex-basis: 100%; justify-content: flex-start; }
  .study-mobile-tabs { padding-inline: 12px; }
  .work-panel > .study-content { padding: 12px; }
  .study-tabs > .tab { padding-inline: 10px; }
  .study-page-footer { padding-inline: 12px; }
  .study-page-footer > .btn { padding-inline: 10px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .btn, .badge, .save-indicator, .nav-link.active { border: 1px solid ButtonText; }
  .status-dot { background: ButtonText; }
  .rich-editor:focus { outline: 2px solid Highlight; }
}
/* v5 reading workspace: bound every ancestor; containImageSize owns pixels. */
body.is-study { overflow: hidden; --study-shell-height: 100dvh; }
body.is-study .main.study-main { height: var(--study-shell-height); min-height: 0; overflow: hidden; }
.study-view.study-workspace { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; min-height: 0; }
.study-view .study-header { position: relative; z-index: 20; flex-wrap: nowrap; min-height: 52px; padding: 4px 12px; gap: 12px; }
.study-identity { display: flex; align-items: center; gap: 6px; flex: 1 1 0; min-width: 0; }
.study-view .study-identity h1 { min-width: 0; font-size: 14px; line-height: 1.35; }
.study-identity h1 > span, .study-identity h1 > small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-identity h1 > small { font-weight: 400; color: var(--muted); font-size: 11px; margin-top: 2px; }
.study-header-actions { display: flex; align-items: center; flex-shrink: 0; gap: 5px; }
.study-view .study-header .btn, .study-view .original-toolbar .btn, .study-view .study-page-footer .btn { min-height: 32px; padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.study-view .study-header .btn-icon, .study-view .original-toolbar .btn-icon { width: 32px; height: 32px; min-width: 32px; padding: 6px; }
.study-header [aria-pressed="true"], .study-header [aria-expanded="true"] { color: var(--primary); background: var(--accent-soft); }
.study-header .save-indicator { flex-shrink: 0; font-size: 11px; }
.study-view .study-options { position: relative; margin: 0; padding: 0; border: 0; background: transparent; }
.study-options > summary { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 32px; margin: 0; padding: 4px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: 12px; list-style: none; white-space: nowrap; }
.study-options > summary::-webkit-details-marker { display: none; }
.study-options > summary::after { content: ""; width: 5px; height: 5px; margin: -2px 2px 0; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.study-options[open] > summary::after { transform: rotate(225deg); margin-top: 2px; }
.study-options[open] > summary { background: var(--accent-soft); color: var(--primary); }
.study-options > .study-controls { position: absolute; z-index: 25; right: 0; top: calc(100% + 9px); display: grid; width: min(330px, calc(100vw - 24px)); max-height: calc(100dvh - 130px); overflow-y: auto; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-lg); }
.study-options .field { display: grid; width: 100%; margin: 0; }
.study-view .study-layout { height: 100%; min-height: 0; grid-template-columns: 156px minmax(0, 1fr); padding: 6px; gap: 8px; align-items: stretch; overflow: hidden; }
.study-view.page-nav-collapsed .study-layout { grid-template-columns: minmax(0, 1fr); }
.study-view.page-nav-collapsed .study-page-nav { display: none; }
.study-view .study-page-nav { height: 100%; min-height: 0; overflow: hidden; }
.study-view .study-page-nav > details { height: 100%; margin: 0; padding: 8px; border-radius: 8px; }
.study-view .page-nav-list { display: flex; flex-direction: column; max-height: calc(100dvh - 142px); gap: 4px; }
.study-view .page-nav-item { flex: 0 0 auto; min-height: 36px; padding: 6px 8px; }
.study-view .study-split { height: 100%; min-height: 0; grid-template-columns: minmax(0, var(--original-width, 48%)) 10px minmax(0, 1fr); align-items: stretch; }
.study-view .original-panel, .study-view .work-panel { height: 100%; min-height: 0; border-radius: 8px; }
.study-view .work-panel { overflow: auto; overscroll-behavior: contain; }
.study-view .study-splitter { min-height: 0; }
.study-view .study-splitter::after { left: 3px; }
.study-view .original-toolbar { flex: 0 0 38px; height: 38px; padding: 2px 6px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
.study-view .original-toolbar h2 { margin-right: auto; padding-inline: 3px; font-size: 12px; white-space: nowrap; }
.study-view .original-viewport { position: relative; flex: 1 1 0; min-height: 0; height: 0; max-height: none; overflow: hidden; background: var(--surface-soft); cursor: default; }
.study-view .original-viewport[data-zoomed="true"] { cursor: grab; }
.study-view .original-viewport[data-zoomed="true"]:active { cursor: grabbing; }
.study-view .original-viewport .original-image { position: absolute; top: 50%; left: 50%; max-width: none; max-height: none; width: auto; height: auto; transform-origin: center center; box-shadow: 0 1px 8px #20212418; }
.study-view .work-panel > .study-content { min-height: 0; padding: 10px 12px; }
.study-view .study-tabs { position: sticky; z-index: 8; top: 0; display: flex; flex-wrap: wrap; max-width: 100%; margin-bottom: 8px; padding-top: 4px; background: var(--surface); }
.study-view .study-tabs > .tab { flex: 0 0 auto; padding-inline: 9px; white-space: nowrap; font-size: 12px; }
.study-view .study-phase { gap: 6px; margin-bottom: 8px; }
.study-view .study-phase small { font-size: 11px; }
.study-view .completion-controls { gap: 6px 10px; margin-bottom: 12px; padding-block: 5px; font-size: 12px; }
.study-view .completion-controls > .field { flex: 0 1 165px; }
.study-view .completion-controls input[type="date"] { min-height: 32px; padding: 4px 7px; }
.study-view .working-note .rich-editor { min-height: min(460px, 50dvh); }
.study-view .study-page-footer { min-height: 38px; padding: 2px 12px; background: var(--surface); }
.study-view.study-locked { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
body.is-study.study-focus .sidebar { display: none; }
body.is-study.study-focus .app-body { margin-left: 0; }
/* Server-rendered Markdown uses existing sanitized .rich-content; long code stays local. */
.explanation-card pre { padding: 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.explanation-card table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.explanation-card th, .explanation-card td { border: 1px solid var(--border); padding: 6px 10px; }
.explanation-card h1, .explanation-card h2, .explanation-card h3, .explanation-card h4 { margin-block: 1em .5em; }
@media (max-width: 900px) {
  /* Reading already has its own book/back header; don't spend a second row
     on app branding. Catalog navigation remains available via the book back. */
  body.is-study { --study-shell-height: 100dvh; }
  body.is-study .mobile-header { display: none; }
  .study-view.study-workspace { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .study-view .study-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 0; padding: 3px 6px; gap: 2px 6px; }
  .study-view .study-identity h1 { font-size: 13px; }
  .study-identity h1 > small { font-size: 10px; }
  .study-header-actions { grid-column: 1 / -1; justify-content: space-between; gap: 3px; }
  .study-view .study-header .btn, .study-view .original-toolbar .btn { min-height: 40px; padding: 5px 6px; gap: 4px; font-size: 11px; }
  .study-view .study-header .btn-icon, .study-view .original-toolbar .btn-icon { width: 40px; height: 40px; min-width: 40px; }
  .study-options > summary { min-height: 40px; padding-inline: 7px; }
  .study-options > .study-controls { right: -52px; max-height: calc(100dvh - 185px); }
  .study-options input, .study-options select { font-size: 16px; }
  .study-header .save-indicator { max-width: 108px; font-size: 10px; }
  .study-view .study-mobile-tabs { display: flex; gap: 4px; height: 44px; padding: 2px 6px; }
  .study-view .study-mobile-tabs > .btn { min-height: 40px; padding-block: 5px; }
  .study-view .study-layout { position: relative; grid-template-columns: minmax(0, 1fr); padding: 4px; gap: 0; }
  .study-view .study-page-nav { position: absolute; z-index: 15; inset: 4px auto 4px 4px; width: 158px; background: var(--surface); box-shadow: var(--shadow-lg); }
  .study-view .page-nav-list { max-height: calc(100dvh - 250px); }
  .study-view .study-split { grid-template-columns: minmax(0, 1fr); }
  .study-view .original-toolbar { flex-basis: 44px; height: 44px; padding-block: 2px; }
  .study-view .study-tabs > .tab { min-height: 40px; }
  .study-view .study-page-footer { min-height: 46px; padding: 2px 6px calc(2px + env(safe-area-inset-bottom)); }
  .study-view .study-page-footer > .btn { min-height: 40px; }
  .study-view .completion-controls input[type="date"] { min-height: 40px; font-size: 16px; }
  body.is-study.study-focus { --study-shell-height: 100dvh; }
  body.is-study.study-focus .mobile-header { display: none; }
}

/* V6 answer-first workspace: expand notes, not the source image. */
.study-view .has-large-note .note-section .rich-editor { min-height: max(400px, calc(100dvh - 340px)); resize: vertical; overflow: auto; }
.study-view .answer-sheet-row { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto); grid-template-areas: "number answer status"; align-items: center; gap: 6px 8px; padding: 8px 10px; margin-bottom: 8px; border-radius: 8px; }
.study-view .answer-sheet-row > * { min-width: 0; }
.study-view .answer-sheet-row > .question-heading { display: contents; }
.study-view .answer-sheet-row .question-heading > label { grid-area: number; min-height: 40px; max-width: 100px; gap: 6px; overflow-wrap: anywhere; }
.study-view .answer-sheet-row .question-grade { grid-area: status; display: flex; flex-wrap: wrap; gap: 4px; max-width: 110px; margin: 0; }
.study-view .answer-sheet-row .question-grade .badge { white-space: normal; overflow-wrap: anywhere; padding-inline: 6px; }
.study-view .answer-sheet-row > input.question-answer[type="text"] { grid-area: answer; min-width: 0; min-height: 40px; padding: 7px 9px; }
/* Notices/recovery/review tools are full-width, never clipped for density. */
.study-view .answer-sheet-row > :not(.question-heading):not(.question-answer):not(.question-memo):not(.question-legacy) { grid-column: 1 / -1; }
.study-view .answer-sheet-row > .save-detail { margin: 0; }
.study-view .answer-sheet-row > .save-detail:empty { display: none; }
.study-view .answer-sheet-row > details { margin: 0; padding: 0 8px; background: var(--surface-soft); align-self: start; }
.study-view .answer-sheet-row > .question-memo { grid-column: 1 / 3; }
.study-view .answer-sheet-row > .question-legacy { grid-column: 3; }
.study-view .answer-sheet-row > details > summary { min-height: 32px; padding: 6px 0; margin: 0; font-size: 12px; line-height: 20px; }
.study-view .answer-sheet-row > details[open] { grid-column: 1 / -1; }
.study-view .answer-sheet-row > details[open] > summary { margin-bottom: 8px; }
.study-view .answer-sheet-row > details > :last-child:not(summary) { margin-bottom: 8px; }
.study-view .answer-sheet-row .question-legacy .actions { flex-wrap: wrap; }
.study-view .answer-sheet-row .answer-key-preview { overflow-wrap: anywhere; }
.study-view .answer-sheet-row .manual-grade { flex-wrap: wrap; }
.key-entry-view { padding: 12px; border: 2px solid var(--primary); border-radius: 10px; background: var(--accent-soft); }
.key-entry-banner { border-bottom: 1px solid var(--border-strong); margin-bottom: 12px; }
.key-entry-banner strong { color: var(--primary); }
.key-entry-row { display: grid; grid-template-columns: minmax(54px, 90px) minmax(0, 1fr); gap: 12px; align-items: start; margin-bottom: 8px; }
.key-entry-row textarea { min-height: 42px; resize: vertical; background: var(--surface); }
.key-entry-actions { position: sticky; bottom: 0; padding: 10px 0; background: var(--accent-soft); }
@media (max-width: 900px) {
  .study-view .has-large-note .note-section .rich-editor { min-height: max(260px, calc(100dvh - 390px)); }
  .study-view .answer-sheet-row { padding: 8px; }
  .study-view .answer-sheet-row .question-heading > label { max-width: 76px; }
  .study-view .answer-sheet-row .question-grade { max-width: 90px; }
  .study-view .answer-sheet-row > input.question-answer[type="text"] { font-size: 16px; min-height: 42px; }
  .study-view .answer-sheet-row > details > summary { min-height: 36px; padding-block: 8px; }
  .key-entry-row { grid-template-columns: 60px minmax(0, 1fr); }
}

@media print {
  body.is-study { overflow: visible; }
  body.is-study .main.study-main, .study-view.study-workspace, .study-view .study-layout, .study-view .study-split, .study-view .original-panel, .study-view .original-viewport, .study-view .work-panel { height: auto; overflow: visible; }
  .study-view.study-workspace, .study-view .study-layout, .study-view .study-split { display: block; }
  .study-view .study-header, .study-view .study-mobile-tabs, .study-view .study-page-nav, .study-view .study-page-footer, .study-view .original-toolbar { display: none; }
  .study-view .original-viewport .original-image { position: static; width: 100% !important; height: auto !important; transform: none !important; box-shadow: none; }
  .sidebar, .mobile-header, .sidebar-overlay, .actions, .editor-toolbar, .study-sidebar, .study-toolbar, .btn, #toasts, .skip-link { display: none !important; }
  .app-body { margin: 0; }
  body, .panel, .card, .rich-editor { background: white; color: black; box-shadow: none; }
  .page, .study-content { padding: 0; max-width: none; }
  .study-panels, .study-layout { display: block; }
  .study-panel { width: 100% !important; break-inside: avoid; margin-bottom: 20px; }
}
