/* Studyroom — quiet, warm surfaces; no remote fonts or runtime dependencies. */
:root {
  color-scheme: light;
  --bg: #f5f4ee;
  --surface: #fffefa;
  --surface-soft: #f0f2e9;
  --ink: #253b35;
  --muted: #68766c;
  --primary: #244e45;
  --primary-hover: #173e35;
  --sage: #789381;
  --sage-light: #e8eee4;
  --border: #dedfd4;
  --border-strong: #bdc7bb;
  --danger: #a53732;
  --danger-bg: #fbefeb;
  --warning: #815921;
  --warning-bg: #fbf3df;
  --success: #346546;
  --success-bg: #edf4e9;
  --radius: 16px;
  --radius-sm: 9px;
  --shadow: 0 3px 16px #243c3310;
  --shadow-lg: 0 22px 70px #162d3326;
  --sidebar-width: 242px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-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: #d2e3cc; color: #163b30; }
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 #57865c; 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(--primary); 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: #657e69; 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: #edeee5; border-right: 1px solid #dddfd3; 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: #f4f0dc; }
.brand strong { display: block; font-size: 18px; letter-spacing: -.055em; }
.brand small { display: block; color: #788170; 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: #6b786a; font-size: 11px; font-weight: 600; }
.subject-label { margin-top: 32px; }
.subject-label > span { color: #697665; background: #e0e4d8; 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: #5d6c60; 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: #e2e8db; color: var(--primary); }
.nav-link.active { background: var(--primary); color: #fffdf1; font-weight: 650; box-shadow: 0 4px 9px #244e4513; }
.nav-soon { font-size: 9px; border: 1px solid #d1d8c9; border-radius: 5px; padding: 1px 5px; white-space: nowrap; color: #6b7868; }
.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: #5d6c60; font-size: 13px; border-radius: 8px; }
.subject-link > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-link.selected { background: #dfe7d8; 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: #7a8475; 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: #71846b; margin: 0 10px 24px; font-size: 12px; }
.quiet-note small { display: block; font-size: 10px; margin-top: 5px; color: #6c7867; line-height: 1.7; }
.account { display: flex; align-items: center; gap: 9px; border-top: 1px solid #d7ddcd; 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: #6b7866; 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: #dde5d4; border: 1px solid #cbd7c2; color: #34573e; 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; }
.page-heading, .page-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 32px; }
.page-heading > div:first-child, .page-header > div:first-child { flex: 1; }
.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: #e8ede258; }
.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: #eeefe7; }
.segmented .active, .segmented-control .active, .segmented [aria-pressed="true"] { background: var(--surface); box-shadow: 0 2px 5px #203c3512; 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: #fffdf4; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: 0 3px 9px #244e4520; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: var(--sage-light); border-color: var(--sage); }
.btn-ghost { color: var(--primary); background: transparent; }
.btn-ghost:hover:not(:disabled), .btn-icon:hover:not(:disabled) { background: #e8eee3; }
.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: #596f60; }
.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: #3e5347; 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: #fffefa; border: 1px solid #cdd4c7; border-radius: 8px; line-height: 1.5; transition: border-color .16s, box-shadow .16s; }
input::placeholder, textarea::placeholder { color: #7b8579; opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--sage); box-shadow: 0 0 0 3px #78938121; }
input[readonly], textarea[readonly] { background: #f0f1e9; }
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: #edf1e9; color: #455f4a; border: 1px solid #d8e2d0; 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: #d2e3c9; color: var(--success); }
.badge, .chip, .status-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 6px; background: #eef0e9; color: #65725f; 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: #356146; background: #e6f0e0; }
.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: #3b665b; background: #e2eee8; }
.badge.problem { color: #8a6732; background: #f3ebd9; }
.badge.mixed { color: #726381; background: #eee8f1; }
.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: #7c9778; }
.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 #c7d6c1; border-radius: 12px; padding: 10px 8px 10px 16px; background: #f9fff4; 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 #dce3d6; 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: #e5e9df; accent-color: var(--sage); }
progress::-webkit-progress-bar { background: #e5e9df; 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: #e6e9df; overflow: hidden; }
.progress-track > *, .progress-bar > span, .progress-fill { display: block; height: 100%; border-radius: inherit; background: #779874; }

/* 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: #173b345c; 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: #f8f8f1; 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: #adbfa8; box-shadow: 0 7px 22px #244e4510; }
.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: #e5e9db; 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(--primary); 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: #f0f2e9; color: #62735e; font-size: 11px; font-weight: 600; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid #e6e8de; vertical-align: middle; }
tbody tr:hover { background: #f6f8f0; }
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 #aebb9f; background: #f3f6ec; border-radius: 14px; padding: 28px; text-align: center; color: #5b7255; }
.drop-zone.dragover, .dropzone.dragover, .upload-zone.dragover, .drop-zone.is-dragover { background: #e1eed7; 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: #e9eae2; }
.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: #e9ebe3; 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: #fafbf4; 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(#b9c4b4 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 #cfd7c8; border-radius: 10px; overflow: hidden; background: var(--surface); }
.editor-wrap:focus-within { border-color: #7d9a74; box-shadow: 0 0 0 3px #7d9a741b; }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 5px 8px; background: #f1f4eb; border-bottom: 1px solid #dbe1d3; }
.editor-tool { min-width: 44px; min-height: 44px; padding: 7px; background: transparent; border: 1px solid transparent; border-radius: 6px; color: #4a6350; font-size: 14px; }
.editor-tool:hover, .editor-tool[aria-pressed="true"] { background: #dfe9d8; 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: #d2dbca; }
.rich-editor { min-height: 220px; padding: 21px 22px; outline-offset: -4px; color: #324b3a; 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: #788573; 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: #f1f5e9; border-left: 3px solid #91a47c; color: #597049; }
.rich-editor pre, .rich-content pre { padding: 15px; background: #f1f3eb; 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: #536f48; background: #edf3e6; 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(--primary); }
.draft-row { margin: 18px 0; }
.draft-row h4 { margin-bottom: 10px; }
.draft-preview { min-height: 90px; max-height: 280px; overflow: auto; padding: 16px; background: #f3f5ec; 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: #f0f3e9; }
.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: #edf0e6; 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: #5a7058; font-size: 12px; text-decoration: none; }
.study-sidebar .active, .study-nav .active { background: #dce7d3; 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: #f8faf1; }
.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: #c7d0bd; }
.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 #d2dfc7; border-radius: 10px; background: #f0f6e9; }
.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: #eef5e7; }
.calendar-day.other-month { color: #879080; background: #f0f1e9; }
.calendar-weekday { padding: 9px; background: #edf0e5; color: var(--muted); font-size: 11px; text-align: center; }
.calendar-event { display: block; padding: 5px 7px; margin-top: 5px; border-radius: 5px; background: #e1ead7; color: var(--primary); font-size: 11px; overflow-wrap: anywhere; }
.schedule-date { flex-shrink: 0; width: 54px; padding: 8px; background: #edf1e5; border-radius: 9px; text-align: center; color: var(--primary); }
.schedule-date strong { display: block; font-size: 22px; }
.schedule-row.done { background: #f2f7ed; }
.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(--primary); 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: #e6eadc; overflow: hidden; }
.login-wordmark { display: flex; align-items: center; gap: 12px; color: var(--primary); font-size: 20px; font-weight: 700; letter-spacing: -.05em; }
.login-message { width: min(100%, 460px); margin: auto; padding-top: 55px; }
.login-message .eyebrow { color: #6b8260; 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: #64755e; line-height: 2; font-size: 14px; }
.login-footer { position: relative; color: #75846c; 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: #d7dfc7; }
.illustration-circle::after { content: ""; position: absolute; width: 46px; height: 46px; top: 12px; right: -25px; border-radius: 50%; border: 1px solid #aebb966e; }
.illustration-book { position: absolute; top: 83px; width: 140px; height: 161px; padding: 36px 20px 16px; background: #fffdf0; box-shadow: 0 8px 0 #dedcc5, 0 10px 0 #faf7e7, 0 22px 30px #53653d17; }
.illustration-book.left { left: 35px; transform: skewY(-9deg) rotate(-7deg); border-radius: 9px 1px 2px 10px; background: linear-gradient(90deg, #fffdf0 70%, #e7e8d9); }
.illustration-book.right { left: 175px; transform: skewY(9deg) rotate(-7deg); border-radius: 1px 9px 10px 2px; background: linear-gradient(90deg, #efefdf, #fffdf0 20%); }
.illustration-book.right::after { content: ""; position: absolute; right: 22px; top: -4px; width: 15px; height: 54px; background: #b4bd89; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); }
.illustration-book i { display: block; height: 2px; background: #d5dbbf; margin-top: 13px; width: 88%; }
.illustration-book i:last-child { width: 62%; }
.illustration-book span { color: #7a8c60; font-size: 13px; font-weight: 550; }
.illustration-stem { position: absolute; left: 20px; top: 41px; transform: rotate(-26deg); color: #7b976e; }
.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: #7a9069; 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: #74806d; 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: #f5f4eef5; 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: #17342f70; }
  .page-heading, .page-header { align-items: flex-start; }
  .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(--primary); 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); }
.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; }
.upload-controls .form-grid, .upload-fields .form-grid { gap: 12px 16px; }
.upload-controls .field, .upload-fields .field { margin-bottom: 0; }
.upload-controls > .actions, .upload-summary { margin-top: 16px; }
.upload-item { align-items: start; }
.upload-item > .upload-preview { flex: 0 0 100px; width: 100px; }
.upload-preview img { width: 100%; max-height: 150px; object-fit: contain; }
.upload-item > .upload-fields { flex: 1 1 0; }
.upload-fields > strong, .upload-fields > small { display: block; margin-bottom: 8px; }
.upload-item > .upload-item-actions { display: flex; flex: 0 0 44px; flex-direction: column; gap: 4px; }
.upload-error { margin-top: 12px; color: var(--danger); font-size: 12px; }
.upload-item.success .upload-error { color: var(--success); }
.upload-error:empty { display: none; }
.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); }
.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; }
  .upload-item { flex-wrap: wrap; gap: 12px; }
  .upload-item > .upload-preview { flex-basis: 64px; width: 64px; }
  .upload-item > .upload-fields { flex: 1 1 160px; }
  .upload-item > .upload-item-actions { flex: 1 1 100%; flex-direction: row; flex-wrap: wrap; justify-content: flex-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; }
}
@media print {
  .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; }
}
