:root {
  --study-bg: #f6f5f1;
  --study-paper: #fffefb;
  --study-paper-2: #fbfaf6;
  --study-ink: #20252b;
  --study-muted: #747b83;
  --study-line: #dadde0;
  --study-line-soft: #e9e8e3;
  --study-blue: #536b82;
  --study-red: #b96d72;
  --study-green: #718778;
  --study-yellow: #d9bc67;
  --study-purple: #7b718c;
  --paper-rule: rgba(86, 107, 130, .115);
  --paper-margin: rgba(185, 109, 114, .24);
  --paper-shadow: 0 16px 42px rgba(30, 39, 47, .08);
}

html[data-bs-theme="dark"], html[data-theme="dark"] {
  --study-bg: #11161c;
  --study-paper: #1a2027;
  --study-paper-2: #171d23;
  --study-ink: #eef1f3;
  --study-muted: #9aa2ab;
  --study-line: #303945;
  --study-line-soft: #252e38;
  --paper-rule: rgba(147, 166, 185, .09);
  --paper-margin: rgba(197, 122, 126, .20);
  --paper-shadow: none;
  --bg: var(--study-bg);
  --surface: var(--study-paper);
  --surface-soft: var(--study-paper-2);
  --surface-muted: #222a34;
  --ink: var(--study-ink);
  --muted: var(--study-muted);
  --line: var(--study-line);
}

html { background: var(--study-bg); }
body { background: var(--study-bg); color: var(--study-ink); overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
svg { pointer-events: none; }
.hidden { display: none !important; }
.desktop-only { display: inline-flex; }

.study-shell { background: var(--study-bg); }
.study-sidebar { width: 248px; background: var(--study-paper); border-right-color: var(--study-line-soft); }
.study-main { margin-left: 248px; }
.study-brand { min-height: 68px; border-bottom-color: var(--study-line-soft); padding: 13px 15px; }
.brand-button { width: 100%; border: 0; background: transparent; padding: 0; text-align: left; }
.study-brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--study-ink); color: var(--study-paper); border-color: var(--study-ink); }
.study-brand-mark svg { width: 16px; }
.study-profile { background: transparent; border-color: var(--study-line-soft); display: flex; align-items: center; gap: 10px; }
.study-profile-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--study-paper-2); color: var(--study-muted); }
.study-profile strong, .study-profile small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-profile strong { font-size: .86rem; font-weight: 600; }
.study-profile small { margin-top: 2px; font-size: .72rem; }
.study-sidebar .sidebar-nav .nav-link { width: calc(100% - 24px); border: 0; text-align: left; background: transparent; }
.study-sidebar .sidebar-nav .nav-link.active { background: var(--study-paper-2); }
.study-sidebar .sidebar-nav .nav-link.active .nav-icon { color: var(--study-ink); }
.study-sidebar-footer { display: grid; gap: 10px; }
.storage-compact { padding: 10px 11px; border: 1px solid var(--study-line-soft); border-radius: 9px; background: var(--study-paper-2); }
.storage-copy { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .7rem; color: var(--study-muted); }
.storage-copy b { color: var(--study-ink); font-size: .72rem; font-weight: 600; }
.storage-track { height: 4px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: var(--study-line-soft); }
.storage-track i { display: block; width: 0; height: 100%; background: var(--study-blue); transition: width .25s ease; }
.study-settings-link { width: 100%; display: flex; align-items: center; justify-content: flex-start; gap: 11px; padding: 0 12px; }

.study-topbar { min-height: 68px; border-bottom-color: var(--study-line-soft); background: color-mix(in srgb, var(--study-paper) 94%, transparent); backdrop-filter: blur(14px); }
.sidebar-mobile-toggle { display: none; }
.page-heading { min-width: 140px; }
.page-heading .page-kicker { display: block; margin-bottom: 1px; font-size: .66rem; letter-spacing: .055em; }
.page-heading .page-title { font-size: 1.08rem; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.study-search { max-width: 520px; margin-left: 12px; background: var(--study-paper-2); border-color: var(--study-line-soft); }
.study-search input { font-size: .86rem; }
.study-top-actions { flex: 0 0 auto; }
.connection-chip { height: 38px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--study-line-soft); border-radius: 8px; color: var(--study-muted); background: var(--study-paper); font-size: .72rem; }
.connection-chip .status-dot { background: var(--study-green); }
.connection-chip.offline .status-dot { background: var(--study-yellow); }
.connection-chip b { font-weight: 500; }
.top-add-file { gap: 7px; }

.study-content { padding: 20px 0 36px; }
.study-container { max-width: 1500px; margin: 0 auto; }

/* Shared paper language */
.paper-surface { position: relative; background: var(--study-paper); border: 1px solid var(--study-line-soft); box-shadow: var(--paper-shadow); }
.paper-rule-bg {
  background-color: var(--study-paper);
  background-image: linear-gradient(to bottom, transparent 31px, var(--paper-rule) 32px);
  background-size: 100% 32px;
}
.paper-margin-line::before { content: ""; position: absolute; top: 0; bottom: 0; left: 54px; width: 1px; background: var(--paper-margin); pointer-events: none; }
.paper-kicker { color: var(--study-muted); font-size: .67rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.ink-title { margin: 0; color: var(--study-ink); font-size: clamp(1.45rem, 2vw, 2.05rem); font-weight: 650; letter-spacing: -.035em; }
.ink-subtitle { margin: 7px 0 0; color: var(--study-muted); line-height: 1.6; max-width: 720px; font-size: .9rem; }
.hand-mark { display: inline-block; position: relative; }
.hand-mark::after { content: ""; position: absolute; height: 7px; left: -2px; right: -4px; bottom: 0; z-index: -1; border-radius: 50%; background: rgba(217, 188, 103, .38); transform: rotate(-1.6deg); }

/* Home */
.home-layout { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, .72fr); gap: 18px; }
.welcome-paper { min-height: 280px; padding: clamp(26px, 5vw, 58px) clamp(24px, 6vw, 70px) 34px 78px; border-radius: 4px 12px 12px 4px; overflow: hidden; }
.welcome-paper::after { content: ""; position: absolute; right: 22px; top: 18px; width: 74px; height: 24px; border-radius: 2px; background: rgba(229, 218, 188, .28); transform: rotate(4deg); }
.welcome-paper h2 { margin: 9px 0 0; max-width: 780px; font-size: clamp(1.8rem, 3.4vw, 3rem); line-height: 1.08; letter-spacing: -.045em; font-weight: 650; }
.welcome-paper p { max-width: 660px; margin: 14px 0 0; color: var(--study-muted); line-height: 1.7; }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 26px; }
.study-button, .study-button-primary, .study-icon-button { border: 1px solid var(--study-line); color: var(--study-ink); background: var(--study-paper); border-radius: 8px; min-height: 40px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 550; font-size: .83rem; transition: .16s ease; }
.study-button:hover, .study-icon-button:hover { background: var(--study-paper-2); border-color: #c8cdd1; }
.study-button-primary { background: var(--study-ink); border-color: var(--study-ink); color: var(--study-paper); }
.study-button-primary:hover { opacity: .9; }
.study-icon-button { width: 40px; padding: 0; }
.study-button.danger { color: #9a454b; }
.study-button.tiny { min-height: 32px; padding: 0 9px; font-size: .75rem; }
.quick-paper { padding: 18px; border-radius: 12px; }
.quick-paper-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 12px; }
.quick-paper-head h3 { margin: 0; font-size: .95rem; }
.quick-list { display: grid; gap: 7px; }
.quick-row { width: 100%; min-height: 62px; padding: 10px 8px; border: 0; border-bottom: 1px solid var(--study-line-soft); background: transparent; display: grid; grid-template-columns: 34px 1fr 20px; align-items: center; gap: 9px; text-align: left; color: var(--study-ink); }
.quick-row:last-child { border-bottom: 0; }
.quick-row:hover { background: var(--study-paper-2); }
.quick-row .quick-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--study-paper-2); color: var(--study-muted); }
.quick-row strong, .quick-row small { display: block; }
.quick-row strong { font-size: .8rem; }
.quick-row small { margin-top: 3px; color: var(--study-muted); font-size: .68rem; }
.quick-row > svg { color: var(--study-muted); }
.section-stack { margin-top: 20px; display: grid; gap: 18px; }
.study-section { min-width: 0; }
.section-headline { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-headline h3 { margin: 0; font-size: .96rem; font-weight: 600; }
.section-headline p { margin: 3px 0 0; color: var(--study-muted); font-size: .72rem; }
.text-button { border: 0; background: transparent; color: var(--study-muted); padding: 3px 0; font-size: .75rem; }
.text-button:hover { color: var(--study-ink); }
.recent-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

/* File cards */
.file-tile { position: relative; min-width: 0; background: var(--study-paper); border: 1px solid var(--study-line-soft); border-radius: 10px; overflow: hidden; transition: transform .16s ease, border-color .16s ease; }
.file-tile:hover { transform: translateY(-2px); border-color: #c9cdd1; }
.file-tile-preview { height: 138px; display: grid; place-items: center; overflow: hidden; background: var(--study-paper-2); border-bottom: 1px solid var(--study-line-soft); }
.file-tile-preview img { width: 100%; height: 100%; object-fit: cover; }
.file-glyph { width: 48px; height: 58px; position: relative; display: grid; place-items: center; border: 1px solid var(--study-line); border-radius: 4px; background: var(--study-paper); color: var(--study-muted); font-size: .62rem; font-weight: 650; letter-spacing: .04em; }
.file-glyph::after { content: ""; position: absolute; right: -1px; top: -1px; width: 12px; height: 12px; border-left: 1px solid var(--study-line); border-bottom: 1px solid var(--study-line); background: var(--study-paper-2); }
.file-glyph.pdf { color: #a9565c; }
.file-glyph.doc { color: #536f8f; }
.file-glyph.img { color: #607d68; }
.file-tile-body { padding: 11px 38px 11px 12px; }
.file-tile-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--study-ink); font-size: .8rem; font-weight: 600; }
.file-tile-meta { display: block; margin-top: 4px; color: var(--study-muted); font-size: .67rem; }
.file-menu { position: absolute; right: 7px; bottom: 9px; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--study-muted); }
.file-menu:hover { background: var(--study-paper-2); color: var(--study-ink); }
.file-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; }
.folder-row-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 9px; }
.folder-tile { min-width: 0; min-height: 74px; padding: 12px 36px 12px 13px; position: relative; display: flex; align-items: center; gap: 10px; border: 1px solid var(--study-line-soft); border-radius: 9px; background: var(--study-paper); color: var(--study-ink); text-align: left; }
.folder-tile:hover { background: var(--study-paper-2); }
.folder-tile .folder-icon { color: var(--study-blue); font-size: 1.25rem; }
.folder-copy { min-width: 0; }
.folder-copy strong, .folder-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-copy strong { font-size: .8rem; }
.folder-copy small { margin-top: 3px; color: var(--study-muted); font-size: .66rem; }
.folder-tile .file-menu { bottom: 21px; }

.file-list { border: 1px solid var(--study-line-soft); border-radius: 10px; overflow: hidden; background: var(--study-paper); }
.file-row { min-height: 62px; display: grid; grid-template-columns: minmax(240px, 1.7fr) 100px 90px 116px 38px; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; border-bottom: 1px solid var(--study-line-soft); color: var(--study-muted); font-size: .72rem; }
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: var(--study-paper-2); }
.file-row-main { min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--study-ink); }
.file-row-main .row-type { width: 34px; height: 40px; flex: 0 0 auto; }
.file-row-main strong, .file-row-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-main strong { font-size: .78rem; }
.file-row-main small { margin-top: 2px; color: var(--study-muted); font-size: .65rem; font-weight: 400; }

/* File page toolbar */
.library-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 15px; }
.library-toolbar-left, .library-toolbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.study-input, .study-select, .study-textarea { border: 1px solid var(--study-line); background: var(--study-paper); color: var(--study-ink); border-radius: 8px; min-height: 39px; padding: 8px 10px; outline: none; font-size: .8rem; }
.study-input:focus, .study-select:focus, .study-textarea:focus { border-color: #aeb6bd; box-shadow: 0 0 0 3px rgba(83, 107, 130, .10); }
.study-textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.toolbar-search { position: relative; min-width: min(360px, 38vw); }
.toolbar-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--study-muted); }
.toolbar-search input { width: 100%; padding-left: 34px; }
.crumb { display: flex; align-items: center; gap: 7px; font-size: .75rem; color: var(--study-muted); }
.crumb button { border: 0; padding: 0; background: transparent; color: var(--study-ink); }

/* Empty */
.empty-paper { min-height: 310px; display: grid; place-items: center; padding: 36px; border: 1px dashed var(--study-line); border-radius: 10px; background: var(--study-paper); text-align: center; }
.empty-paper .empty-sketch { width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 12px; color: var(--study-muted); font-size: 1.7rem; border: 1px solid var(--study-line-soft); border-radius: 50%; }
.empty-paper h3 { margin: 0; font-size: 1rem; }
.empty-paper p { max-width: 480px; margin: 7px auto 15px; color: var(--study-muted); line-height: 1.55; font-size: .78rem; }

/* Notes */
.notes-layout { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.note-book { position: relative; min-width: 0; height: 230px; padding: 24px 18px 16px 42px; border: 1px solid var(--study-line-soft); border-radius: 3px 10px 10px 3px; background: var(--study-paper); overflow: hidden; box-shadow: 0 8px 22px rgba(30,39,47,.05); text-align: left; color: var(--study-ink); }
.note-book::before { content: ""; position: absolute; left: 25px; top: 0; bottom: 0; width: 1px; background: var(--paper-margin); }
.note-book::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(to bottom, transparent 0 26px, var(--paper-rule) 27px); pointer-events: none; opacity: .7; }
.note-book > * { position: relative; z-index: 1; }
.note-book-preview { height: 130px; overflow: hidden; margin-bottom: 12px; }
.note-book-preview img { width: 100%; height: 100%; object-fit: contain; object-position: left top; mix-blend-mode: multiply; }
html[data-theme="dark"] .note-book-preview img { mix-blend-mode: normal; }
.note-book strong, .note-book small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-book strong { font-size: .82rem; }
.note-book small { margin-top: 4px; color: var(--study-muted); font-size: .66rem; }

/* Reviewer */
.reviewer-shelf { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.reviewer-pdf { position: relative; min-width: 0; height: 260px; padding: 22px 18px; overflow: hidden; border: 1px solid var(--study-line-soft); background: var(--study-paper); box-shadow: 0 9px 24px rgba(30,39,47,.05); text-align: left; color: var(--study-ink); }
.reviewer-pdf::before { content: "PDF"; position: absolute; top: 0; right: 0; padding: 5px 7px; background: rgba(169,86,92,.10); color: #9f5258; font-size: .57rem; font-weight: 700; letter-spacing: .08em; }
.reviewer-pdf .review-mini-lines { height: 125px; margin: 12px 0 13px; opacity: .8; background: repeating-linear-gradient(to bottom, transparent 0 14px, var(--paper-rule) 15px); }
.reviewer-pdf .review-mini-title { font-size: .88rem; font-weight: 650; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.reviewer-pdf small { display: block; margin-top: 4px; color: var(--study-muted); font-size: .64rem; }
.reviewer-meta-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 0 7px; border: 1px solid var(--study-line-soft); border-radius: 6px; background: var(--study-paper-2); color: var(--study-muted); font-size: .61rem; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; padding: 18px; background: rgba(20, 25, 31, .36); backdrop-filter: blur(8px); }
.study-modal { width: min(650px, 100%); max-height: min(88vh, 920px); overflow: auto; border: 1px solid var(--study-line); border-radius: 12px; background: var(--study-paper); color: var(--study-ink); box-shadow: 0 24px 80px rgba(18,24,30,.22); }
.study-modal.wide { width: min(920px, 100%); }
.study-modal.fullscreen { position: fixed; inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); width: auto; max-height: none; border-radius: 10px; overflow: hidden; }
.modal-head { min-height: 62px; padding: 11px 12px 11px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--study-line-soft); }
.modal-head h2 { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .96rem; font-weight: 620; }
.modal-head-actions { display: flex; gap: 7px; align-items: center; }
.modal-body { padding: 18px; }
.modal-actions { min-height: 62px; padding: 10px 14px; display: flex; justify-content: flex-end; gap: 8px; align-items: center; border-top: 1px solid var(--study-line-soft); }
.form-grid { display: grid; gap: 13px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 6px; }
.field label { font-size: .72rem; font-weight: 600; color: var(--study-ink); }
.field small { color: var(--study-muted); font-size: .65rem; line-height: 1.5; }
.field input, .field select, .field textarea { width: 100%; }
.field-check { display: flex; align-items: flex-start; gap: 9px; color: var(--study-muted); font-size: .7rem; line-height: 1.45; }
.field-check input { margin-top: 2px; }
.info-note, .warning-note { padding: 11px 12px; border: 1px solid var(--study-line-soft); border-radius: 8px; color: var(--study-muted); background: var(--study-paper-2); font-size: .7rem; line-height: 1.55; }
.warning-note { border-color: rgba(185,109,114,.28); background: rgba(185,109,114,.06); }
.warning-note strong { color: #995158; }

/* Context menu */
.context-menu { position: fixed; z-index: 5000; width: 210px; padding: 6px; border: 1px solid var(--study-line); border-radius: 10px; background: var(--study-paper); box-shadow: 0 14px 42px rgba(18,24,30,.18); }
.context-menu button { width: 100%; min-height: 36px; display: flex; align-items: center; gap: 9px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; color: var(--study-ink); text-align: left; font-size: .73rem; }
.context-menu button:hover { background: var(--study-paper-2); }
.context-menu button.danger { color: #9d4d53; }
.context-menu .menu-sep { height: 1px; margin: 5px; background: var(--study-line-soft); }

/* Viewer */
.viewer-layout { height: calc(100% - 63px); display: grid; grid-template-columns: minmax(0,1fr) 270px; }
.viewer-canvas-wrap { min-width: 0; min-height: 0; position: relative; overflow: auto; background: #dfe1e2; display: grid; place-items: start center; padding: 24px; }
html[data-theme="dark"] .viewer-canvas-wrap { background: #0d1116; }
.viewer-document { position: relative; width: min(100%, 1050px); min-height: 100%; display: grid; place-items: center; }
.viewer-document iframe { width: min(100%, 950px); height: calc(100vh - 122px); border: 0; background: #fff; }
.viewer-document > img { max-width: min(100%, 950px); max-height: calc(100vh - 125px); object-fit: contain; box-shadow: 0 8px 28px rgba(0,0,0,.14); background: #fff; }
.viewer-document video { max-width: 100%; max-height: 78vh; }
.viewer-document audio { width: min(560px,100%); }
.viewer-text { width: min(900px, 100%); min-height: 100%; margin: 0; padding: 52px 60px; white-space: pre-wrap; word-break: break-word; color: #20252b; background: #fffefb; box-shadow: 0 10px 30px rgba(0,0,0,.10); font: 15px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.viewer-side { min-width: 0; padding: 16px 14px; overflow: auto; border-left: 1px solid var(--study-line-soft); background: var(--study-paper); }
.viewer-side h3 { margin: 0 0 13px; font-size: .85rem; }
.viewer-side-actions { display: grid; gap: 7px; margin-top: 16px; }
.meta-stack { display: grid; gap: 1px; border-top: 1px solid var(--study-line-soft); }
.meta-line { min-height: 42px; padding: 8px 0; display: grid; grid-template-columns: 70px 1fr; gap: 8px; align-items: start; border-bottom: 1px solid var(--study-line-soft); font-size: .67rem; }
.meta-line span { color: var(--study-muted); }
.meta-line b { min-width: 0; text-align: right; overflow-wrap: anywhere; font-weight: 550; }
.annotation-canvas { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; touch-action: none; pointer-events: none; }
.annotation-canvas.active { pointer-events: auto; }
.annotation-toolbar { position: fixed; left: 50%; bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px)); z-index: 3100; transform: translateX(-50%); min-height: 52px; padding: 6px; display: flex; align-items: center; gap: 5px; border: 1px solid var(--study-line); border-radius: 12px; background: color-mix(in srgb, var(--study-paper) 95%, transparent); box-shadow: 0 12px 34px rgba(18,24,30,.16); backdrop-filter: blur(14px); }
.annotation-toolbar .tool-square { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--study-muted); }
.annotation-toolbar .tool-square.active, .annotation-toolbar .tool-square:hover { background: var(--study-paper-2); color: var(--study-ink); }
.annotation-toolbar input[type="color"] { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; overflow: hidden; }
.annotation-toolbar input[type="range"] { width: 88px; }
.tool-divider { width: 1px; height: 28px; background: var(--study-line-soft); }

/* Notebook editor */
.note-editor-shell { height: calc(100% - 63px); display: grid; grid-template-rows: minmax(0,1fr); background: radial-gradient(circle at top, color-mix(in srgb, var(--study-paper) 45%, transparent) 0, transparent 52%), var(--study-bg); }
.note-editor-shell.enhanced { position: relative; }
.note-stage { min-height: 0; overflow: auto; padding: 28px 24px 172px; display: grid; justify-items: center; align-items: start; }
.note-page { position: relative; width: min(100%, 950px); aspect-ratio: 210 / 297; min-height: 700px; background: var(--study-paper); box-shadow: var(--paper-shadow); border: 1px solid var(--study-line-soft); overflow: hidden; touch-action: none; }
.note-page.hand-mode { cursor: grab; }
.note-page.lined { background-image: linear-gradient(to bottom, transparent 35px, var(--paper-rule) 36px); background-size: 100% 36px; }
.note-page.grid { background-image: linear-gradient(var(--paper-rule) 1px, transparent 1px), linear-gradient(90deg, var(--paper-rule) 1px, transparent 1px); background-size: 28px 28px; }
.note-page.dotted { background-image: radial-gradient(circle, rgba(89,102,115,.22) 1px, transparent 1.2px); background-size: 24px 24px; }
.note-page.cornell { background-image: linear-gradient(to bottom, transparent 35px, var(--paper-rule) 36px); background-size: 100% 36px; }
.note-page.cornell::before { content: ""; position: absolute; left: 31%; top: 0; bottom: 18%; width: 1px; background: var(--paper-margin); }
.note-page.cornell::after { content: ""; position: absolute; left: 0; right: 0; bottom: 18%; height: 1px; background: var(--paper-margin); }
.note-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 2; }
.note-text-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.note-text-layer.select-mode { pointer-events: auto; }
.note-text-layer.select-mode .note-text-item { pointer-events: auto; }
.note-text-item { position: absolute; max-width: 56%; padding: 4px 7px; border-radius: 10px; background: rgba(255,255,255,.28); backdrop-filter: blur(1px); line-height: 1.25; font-weight: 600; white-space: pre-wrap; word-break: break-word; cursor: text; user-select: none; }
.note-text-item.editable { outline: 1px dashed color-mix(in srgb, var(--study-accent, #4f46e5) 40%, transparent); cursor: grab; }
.inkbar-shell { position: absolute; left: 50%; bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px)); transform: translateX(-50%); z-index: 25; width: min(760px, calc(100% - 24px)); padding: 6px 8px; border: 1px solid var(--study-line); border-radius: 18px; background: color-mix(in srgb, var(--study-paper) 92%, transparent); box-shadow: 0 18px 48px rgba(18,24,30,.18); backdrop-filter: blur(18px); }
.inkbar-top, .inkbar-bottom { display: flex; align-items: center; gap: 6px; }
.inkbar-bottom { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--study-line-soft); justify-content: space-between; }
.inktool { min-width: 38px; height: 38px; display: grid; place-items: center; padding: 0 11px; border: 0; border-radius: 11px; background: transparent; color: var(--study-muted); font-size: .92rem; }
.inktool.small { min-width: 34px; height: 34px; padding: 0 9px; }
.inktool.active, .inktool:hover { background: var(--study-paper-2); color: var(--study-ink); }
.ink-swatches, .size-swatches, .paper-mini-group { display: flex; align-items: center; gap: 8px; }
.swatch { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; }
.swatch span { width: 24px; height: 24px; border-radius: 50%; background: var(--swatch); border: 1px solid rgba(0,0,0,.08); box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.swatch.light span { border-color: rgba(32,37,43,.22); }
.swatch.active { outline: 2px solid color-mix(in srgb, var(--study-accent, #4f46e5) 65%, transparent); outline-offset: 2px; }
.size-dot { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; }
.size-dot i { display: block; border-radius: 50%; background: var(--study-ink); width: 6px; height: 6px; }
.size-dot[data-size="4"] i { width: 10px; height: 10px; }
.size-dot[data-size="7"] i { width: 15px; height: 15px; }
.size-dot[data-size="11"] i { width: 20px; height: 20px; }
.size-dot.active { background: var(--study-paper-2); }
.ink-paper-select { min-height: 34px; min-width: 118px; font-size: .72rem; }
.note-drawer { position: absolute; right: 20px; bottom: calc(max(18px, env(safe-area-inset-bottom) + 8px) + 104px); z-index: 24; width: min(320px, calc(100% - 40px)); display: grid; gap: 8px; padding: 14px; border: 1px solid var(--study-line); border-radius: 16px; background: color-mix(in srgb, var(--study-paper) 96%, transparent); box-shadow: 0 12px 40px rgba(18,24,30,.16); }
.note-drawer.hidden { display: none; }
.audio-drawer-head strong, .audio-drawer-head small { display: block; }
.audio-drawer-head small { margin-top: 4px; color: var(--study-muted); font-size: .66rem; line-height: 1.45; }
.audio-recorder-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.note-audio-list { display: grid; gap: 8px; max-height: 260px; overflow: auto; }
.audio-clip-row { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--study-line-soft); border-radius: 12px; background: var(--study-paper-2); }
.audio-clip-meta strong, .audio-clip-meta small { display: block; }
.audio-clip-meta small { margin-top: 2px; color: var(--study-muted); font-size: .62rem; }
.audio-clip-row audio { width: 100%; }
.voice-empty { padding: 10px; border-radius: 10px; background: var(--study-paper-2); color: var(--study-muted); font-size: .68rem; line-height: 1.5; }
.save-state { min-width: 76px; color: var(--study-muted); font-size: .65rem; text-align: right; }

/* Settings */
.settings-layout { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 18px; }
.settings-nav { display: grid; align-content: start; gap: 2px; }
.settings-nav button { min-height: 40px; padding: 0 11px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--study-muted); text-align: left; font-size: .76rem; }
.settings-nav button.active, .settings-nav button:hover { color: var(--study-ink); background: var(--study-paper); }
.settings-panel { padding: 20px; border: 1px solid var(--study-line-soft); border-radius: 10px; background: var(--study-paper); }
.settings-panel > h2 { margin: 0; font-size: 1rem; }
.settings-panel > p { margin: 5px 0 18px; color: var(--study-muted); font-size: .72rem; line-height: 1.55; }
.setting-row { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 0; border-top: 1px solid var(--study-line-soft); }
.setting-row:first-of-type { border-top: 0; }
.setting-row strong, .setting-row small { display: block; }
.setting-row strong { font-size: .76rem; }
.setting-row small { max-width: 620px; margin-top: 3px; color: var(--study-muted); font-size: .65rem; line-height: 1.5; }
.api-key-wrap { display: flex; gap: 7px; }
.api-key-wrap .study-input { flex: 1; }
.ai-status { min-height: 28px; display: inline-flex; align-items: center; gap: 7px; padding: 0 8px; border-radius: 6px; background: var(--study-paper-2); color: var(--study-muted); font-size: .63rem; }
.ai-status.ready { color: #58715f; }

/* Reviewer PDF preview */
.pdf-reader-layout { height: calc(100% - 63px); display: grid; grid-template-columns: minmax(0,1fr) 270px; }
.pdf-reader-stage { min-width: 0; min-height: 0; background: #dfe1e2; padding: 18px; }
.pdf-reader-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* Toasts */
.toast-stack { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 6000; width: min(340px, calc(100vw - 28px)); display: grid; gap: 8px; }
.toast { padding: 11px 12px; border: 1px solid var(--study-line); border-radius: 9px; background: var(--study-paper); box-shadow: 0 12px 34px rgba(18,24,30,.16); }
.toast b, .toast span { display: block; }
.toast b { font-size: .75rem; }
.toast span { margin-top: 3px; color: var(--study-muted); font-size: .67rem; line-height: 1.45; }

.mobile-tabbar { display: none; }

@media (max-width: 1199px) {
  .file-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .notes-layout, .reviewer-shelf { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .recent-strip { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (max-width: 991.98px) {
  .study-sidebar { width: 248px; }
  .study-main { margin-left: 0; }
  .sidebar-mobile-toggle { display: inline-flex; }
  .study-topbar { padding-left: 12px; }
  .study-search { margin-left: 0; }
  .connection-chip { display: none; }
  .home-layout { grid-template-columns: 1fr; }
  .quick-paper { order: 2; }
  .file-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .folder-row-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .viewer-layout, .pdf-reader-layout { grid-template-columns: minmax(0,1fr); }
  .viewer-side { display: none; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .settings-nav button { white-space: nowrap; }
}

@media (max-width: 720px) {
  .desktop-only { display: none !important; }
  .study-content { padding: 13px 0 calc(80px + env(safe-area-inset-bottom)); }
  .study-container { padding-inline: 12px; }
  .page-heading { min-width: 0; }
  .page-heading .page-kicker { display: none; }
  .study-search { display: none !important; }
  .top-add-file span { display: none; }
  .top-add-file { min-width: 40px; width: 40px; padding: 0; }
  .mobile-tabbar { position: fixed; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 2100; height: 58px; padding: 5px; display: grid; grid-template-columns: repeat(5,1fr); border: 1px solid var(--study-line); border-radius: 13px; background: color-mix(in srgb, var(--study-paper) 95%, transparent); box-shadow: 0 12px 34px rgba(18,24,30,.16); backdrop-filter: blur(14px); }
  .mobile-tabbar button { min-width: 0; border: 0; border-radius: 8px; background: transparent; color: var(--study-muted); display: grid; place-items: center; align-content: center; gap: 3px; }
  .mobile-tabbar button.active { color: var(--study-ink); background: var(--study-paper-2); }
  .mobile-tabbar button span { font-size: .57rem; }
  .welcome-paper { min-height: 330px; padding: 42px 22px 26px 56px; }
  .welcome-paper h2 { font-size: 2rem; }
  .welcome-actions .study-button, .welcome-actions .study-button-primary { flex: 1 1 140px; }
  .recent-strip, .file-grid, .notes-layout, .reviewer-shelf { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .folder-row-grid { grid-template-columns: 1fr 1fr; }
  .file-tile-preview { height: 112px; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .library-toolbar-left, .library-toolbar-right { width: 100%; }
  .toolbar-search { flex: 1; min-width: 0; }
  .file-row { grid-template-columns: minmax(0,1fr) 38px; }
  .file-row > span { display: none; }
  .study-modal { max-height: 92vh; }
  .form-row-2 { grid-template-columns: 1fr; }
  .annotation-toolbar { max-width: calc(100vw - 20px); overflow-x: auto; }
  .annotation-toolbar input[type="range"] { width: 68px; }
  .note-editor-shell { grid-template-rows: auto minmax(0,1fr); }
  .penbar { justify-content: flex-start; overflow-x: auto; }
  .note-stage { padding: 12px; }
  .note-page { min-height: 560px; }
  .reviewer-pdf { height: 220px; }
}

@media (max-width: 430px) {
  .recent-strip, .file-grid, .notes-layout, .reviewer-shelf, .folder-row-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .file-tile-preview { height: 95px; }
  .file-tile-body { padding: 9px 32px 9px 9px; }
  .welcome-paper { padding-left: 48px; }
  .quick-paper { padding: 13px; }
  .setting-row { align-items: flex-start; flex-direction: column; }
}


/* V3 — Active recall + Quiz mode */
.study-mode-hero {
  min-height: 176px;
  margin-bottom: 16px;
  padding: 28px 30px 26px 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--study-line-soft);
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 38px, var(--paper-margin) 39px, transparent 40px),
    linear-gradient(to bottom, transparent 35px, var(--paper-rule) 36px);
  background-size: 100% 100%, 100% 36px;
  background-color: var(--study-paper);
}
.study-mode-hero::after {
  content: "";
  position: absolute;
  right: 34px;
  top: 24px;
  width: 82px;
  height: 20px;
  transform: rotate(-3deg);
  background: rgba(217,188,103,.24);
  pointer-events: none;
}
.study-mode-hero > * { position: relative; z-index: 1; }
.study-mode-hero h2 { margin: 5px 0 8px; font-size: clamp(1.55rem, 3vw, 2.35rem); letter-spacing: -.04em; }
.study-mode-hero p { max-width: 760px; margin: 0; color: var(--study-muted); font-size: .77rem; line-height: 1.65; }
.quiz-hero::after { width: 108px; background: rgba(129,160,185,.16); }

.mode-metrics {
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  border-top: 1px solid var(--study-line-soft);
  border-bottom: 1px solid var(--study-line-soft);
}
.mode-metrics > div { min-height: 66px; padding: 12px 16px; display: grid; align-content: center; border-left: 1px solid var(--study-line-soft); }
.mode-metrics > div:first-child { border-left: 0; }
.mode-metrics b { font-size: 1.05rem; line-height: 1; }
.mode-metrics span { margin-top: 5px; color: var(--study-muted); font-size: .62rem; }

.deck-grid, .quiz-grid {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 12px;
}
.deck-tile, .quiz-tile {
  position: relative;
  min-width: 0;
}
.deck-open, .quiz-open {
  width: 100%;
  min-height: 270px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  border: 1px solid var(--study-line-soft);
  border-radius: 9px;
  background: var(--study-paper);
  color: var(--study-ink);
  overflow: hidden;
}
.deck-open:hover, .quiz-open:hover { border-color: var(--study-line); background: color-mix(in srgb, var(--study-paper) 96%, var(--study-ink)); }
.deck-open h3, .quiz-open h3 { margin: 7px 30px 5px 0; font-size: .92rem; line-height: 1.35; }
.deck-open p, .quiz-open p { margin: 0; color: var(--study-muted); font-size: .65rem; line-height: 1.45; }
.deck-more {
  position: absolute;
  z-index: 2;
  right: 8px;
  top: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--study-muted);
}
.deck-more:hover { background: var(--study-paper-2); color: var(--study-ink); }
.deck-stack-art {
  height: 105px;
  margin-bottom: 15px;
  position: relative;
}
.deck-stack-art i {
  position: absolute;
  left: 50%;
  top: 14px;
  width: 116px;
  height: 72px;
  margin-left: -58px;
  border: 1px solid var(--study-line);
  border-radius: 6px;
  background: var(--study-paper);
}
.deck-stack-art i:nth-child(1) { transform: translate(-12px,7px) rotate(-5deg); opacity: .55; }
.deck-stack-art i:nth-child(2) { transform: translate(10px,6px) rotate(4deg); opacity: .72; }
.deck-stack-art i:nth-child(3) { transform: translate(0,0); }
.deck-stack-art > span {
  position: absolute;
  left: 50%;
  top: 35px;
  transform: translateX(-50%);
  font-size: 1.3rem;
  color: var(--study-muted);
}
.deck-progress, .flash-master-progress, .quiz-progress {
  height: 4px;
  overflow: hidden;
  background: var(--study-paper-2);
}
.deck-progress { margin-top: auto; }
.deck-progress i, .flash-master-progress i, .quiz-progress i {
  display: block;
  height: 100%;
  background: var(--study-ink);
}
.deck-open > small { margin-top: 7px; color: var(--study-muted); font-size: .58rem; }

.quiz-tile-icon {
  height: 104px;
  display: grid;
  place-items: center;
  margin: -18px -18px 15px;
  border-bottom: 1px solid var(--study-line-soft);
  background:
    linear-gradient(to bottom, transparent 30px, var(--paper-rule) 31px);
  background-size: 100% 31px;
  font-size: 1.65rem;
  color: var(--study-muted);
}
.quiz-tile-bottom { margin-top: auto; padding-top: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.quiz-tile-bottom small { color: var(--study-muted); font-size: .58rem; }
.quiz-score-pill { padding: 4px 7px; border-radius: 5px; background: var(--study-paper-2); font-size: .6rem; font-weight: 650; }

/* Flashcard player */
.study-mode-modal .modal-head { flex-wrap: nowrap; }
.flash-study-shell, .quiz-play-shell {
  height: calc(100% - 63px);
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background: var(--study-bg);
}
.flash-study-shell {
  display: grid;
  grid-template-rows: auto minmax(360px,1fr) auto auto;
  gap: 16px;
  justify-items: center;
}
.flash-study-top { width: min(860px,100%); display: grid; gap: 10px; }
.flash-study-top > div:first-child { display: flex; justify-content: space-between; gap: 18px; align-items: end; }
.flash-study-top span { color: var(--study-muted); font-size: .64rem; }
.flash-master-progress { width: 100%; }
.flash-card {
  width: min(860px,100%);
  min-height: 410px;
  position: relative;
  border: 0;
  background: transparent;
  perspective: 1200px;
  color: var(--study-ink);
}
.flash-face {
  position: absolute;
  inset: 0;
  padding: 60px 70px 54px 92px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  backface-visibility: hidden;
  transition: transform .36s ease, opacity .36s ease;
  border: 1px solid var(--study-line);
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 50px, var(--paper-margin) 51px, transparent 52px),
    linear-gradient(to bottom, transparent 39px, var(--paper-rule) 40px);
  background-size: 100% 100%, 100% 40px;
  background-color: var(--study-paper);
  box-shadow: var(--paper-shadow);
}
.flash-face::before {
  content: "";
  position: absolute;
  top: 33px;
  right: 44px;
  width: 130px;
  height: 19px;
  transform: rotate(-2deg);
  background: rgba(217,188,103,.28);
}
.flash-face > span { margin-bottom: 16px; color: var(--study-muted); font-size: .62rem; text-transform: uppercase; letter-spacing: .13em; font-weight: 750; }
.flash-face > strong { max-width: 690px; font-size: clamp(1.35rem,3vw,2.05rem); line-height: 1.36; letter-spacing: -.025em; white-space: pre-line; }
.flash-face > small { margin-top: 26px; color: var(--study-muted); font-size: .7rem; line-height: 1.5; }
.flash-face > em { margin-top: auto; color: var(--study-muted); font-size: .6rem; font-style: normal; }
.flash-back { transform: rotateY(180deg); }
.flash-card.revealed .flash-front { transform: rotateY(-180deg); }
.flash-card.revealed .flash-back { transform: rotateY(0); }
.flash-nav {
  width: min(1020px,100%);
  display: grid;
  grid-template-columns: 130px minmax(0,1fr) 130px;
  align-items: stretch;
  gap: 10px;
}
.rating-row { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 7px; }
.rating-row.disabled { opacity: .38; pointer-events: none; }
.rating-row button {
  min-height: 54px;
  padding: 7px;
  border: 1px solid var(--study-line-soft);
  border-radius: 7px;
  background: var(--study-paper);
  color: var(--study-ink);
}
.rating-row button:hover { border-color: var(--study-line); background: var(--study-paper-2); }
.rating-row b,.rating-row small { display: block; }
.rating-row b { font-size: .69rem; }
.rating-row small { margin-top: 2px; color: var(--study-muted); font-size: .54rem; }
.flash-status { color: var(--study-muted); font-size: .62rem; }

/* Quiz player */
.quiz-play-shell { display: grid; justify-items: center; align-content: start; }
.quiz-progress { width: min(940px,100%); margin-bottom: 14px; }
.quiz-question-paper {
  width: min(940px,100%);
  min-height: 640px;
  padding: 48px 60px 38px 86px;
  border: 1px solid var(--study-line-soft);
  background:
    linear-gradient(90deg, transparent 46px, var(--paper-margin) 47px, transparent 48px),
    linear-gradient(to bottom, transparent 39px, var(--paper-rule) 40px);
  background-size: 100% 100%, 100% 40px;
  background-color: var(--study-paper);
  box-shadow: var(--paper-shadow);
}
.quiz-question-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--study-muted); font-size: .6rem; text-transform: uppercase; letter-spacing: .08em; }
.quiz-question-paper > h3 { max-width: 780px; margin: 24px 0 28px; font-size: clamp(1.05rem,2vw,1.4rem); line-height: 1.55; }
.quiz-options { display: grid; gap: 9px; }
.quiz-option {
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 32px minmax(0,1fr) 24px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--study-line-soft);
  border-radius: 7px;
  background: color-mix(in srgb, var(--study-paper) 95%, transparent);
  color: var(--study-ink);
  text-align: left;
}
.quiz-option > span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--study-line);
  border-radius: 50%;
  color: var(--study-muted);
  font-size: .63rem;
  font-weight: 700;
}
.quiz-option > b { font-size: .75rem; line-height: 1.48; font-weight: 550; }
.quiz-option.selected { border-color: var(--study-ink); background: var(--study-paper-2); }
.quiz-option.selected > span { background: var(--study-ink); color: var(--study-paper); }
.quiz-option.correct { border-color: rgba(80,125,92,.45); background: rgba(80,125,92,.08); }
.quiz-option.wrong { border-color: rgba(175,89,89,.42); background: rgba(175,89,89,.07); }
.quiz-option > i { display: grid; place-items: center; font-style: normal; }
.rationale-paper {
  margin-top: 24px;
  padding: 18px 20px;
  border-left: 3px solid var(--study-ink);
  background: color-mix(in srgb,var(--study-paper-2) 88%,transparent);
}
.rationale-paper > p { margin: 6px 0 0; font-size: .72rem; line-height: 1.65; }
.rationale-paper details { margin-top: 13px; border-top: 1px solid var(--study-line-soft); padding-top: 11px; }
.rationale-paper summary { cursor: pointer; color: var(--study-muted); font-size: .63rem; font-weight: 650; }
.rationale-paper details p { margin: 8px 0; color: var(--study-muted); font-size: .64rem; line-height: 1.5; }
.quiz-action-row { margin-top: 26px; display: flex; justify-content: space-between; gap: 10px; }

/* Completion */
.completion-sheet {
  min-height: calc(100% - 63px);
  padding: 48px 24px;
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
  background: var(--study-bg);
}
.completion-mark {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 1px solid var(--study-line);
  border-radius: 50%;
  background: var(--study-paper);
  font-size: 1.5rem;
}
.completion-sheet h3 { margin: 18px 0 7px; font-size: 1.25rem; }
.completion-sheet > p { max-width: 620px; margin: 0; color: var(--study-muted); font-size: .73rem; line-height: 1.6; }
.score-grid { width: min(560px,100%); margin: 24px 0; display: grid; grid-template-columns: repeat(3,1fr); border-top: 1px solid var(--study-line-soft); border-bottom: 1px solid var(--study-line-soft); }
.score-grid > div { padding: 14px 10px; border-left: 1px solid var(--study-line-soft); }
.score-grid > div:first-child { border-left: 0; }
.score-grid b,.score-grid span { display: block; }
.score-grid b { font-size: 1.1rem; }
.score-grid span { margin-top: 4px; color: var(--study-muted); font-size: .58rem; }
.completion-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.score-ring {
  width: 174px;
  height: 174px;
  display: grid;
  place-items: center;
  align-content: center;
  border: 1px solid var(--study-line);
  border-radius: 50%;
  background: var(--study-paper);
}
.score-ring strong { font-size: 2.6rem; letter-spacing: -.06em; }
.score-ring span { color: var(--study-muted); font-size: .62rem; }

@media (max-width: 1199px) {
  .deck-grid,.quiz-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 850px) {
  .study-mode-hero { padding: 24px 22px 24px 54px; align-items: flex-start; flex-direction: column; }
  .deck-grid,.quiz-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .flash-study-shell,.quiz-play-shell { padding: 16px; }
  .flash-face { padding: 52px 40px 42px 68px; }
  .flash-nav { grid-template-columns: 1fr 1fr; }
  .rating-row { grid-column: 1 / -1; grid-row: 1; }
  .quiz-question-paper { padding: 38px 26px 30px 58px; }
}
@media (max-width: 560px) {
  .study-mode-hero { min-height: 0; margin-inline: 0; }
  .mode-metrics > div { padding-inline: 9px; }
  .deck-grid,.quiz-grid { grid-template-columns: 1fr; }
  .deck-open,.quiz-open { min-height: 220px; }
  .flash-study-shell { grid-template-rows: auto minmax(360px,1fr) auto auto; padding: 10px; }
  .flash-card { min-height: 390px; }
  .flash-face { padding: 48px 26px 38px 54px; }
  .flash-face > strong { font-size: 1.25rem; }
  .flash-nav { grid-template-columns: 1fr 1fr; }
  .rating-row { gap: 4px; }
  .rating-row button { min-height: 49px; padding-inline: 3px; }
  .rating-row small { display: none; }
  .quiz-play-shell { padding: 9px; }
  .quiz-question-paper { min-height: 0; padding: 34px 13px 24px 45px; }
  .quiz-question-meta { align-items: flex-start; flex-direction: column; }
  .quiz-option { padding-inline: 8px; grid-template-columns: 29px minmax(0,1fr) 18px; }
  .quiz-action-row { align-items: stretch; flex-direction: column-reverse; }
  .quiz-action-row button { width: 100%; }
  .score-grid { grid-template-columns: repeat(3,1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .flash-face { transition: none; }
}

/* V3.1 runtime / local-file safety notice */
.runtime-notice {
  margin: 12px clamp(14px, 2.4vw, 28px) 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--study-line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--study-paper) 94%, #d9bc67 6%);
  color: var(--study-text);
  font-size: .73rem;
  line-height: 1.45;
}
.runtime-notice.hidden { display: none !important; }
.runtime-notice-copy { min-width: 0; display: flex; align-items: flex-start; gap: 9px; }
.runtime-notice-copy > i,
.runtime-notice-copy > svg { margin-top: 2px; flex: 0 0 auto; color: #9a7630; }
.runtime-notice strong { display: block; margin-bottom: 1px; font-size: .74rem; }
.runtime-notice small { display: block; color: var(--study-muted); font-size: .67rem; }
.runtime-notice .study-button { flex: 0 0 auto; text-decoration: none; white-space: nowrap; }
@media (max-width: 720px) {
  .runtime-notice { align-items: stretch; flex-direction: column; }
  .runtime-notice .study-button { width: 100%; justify-content: center; }
}

/* V3.2 — Appearance controls */
.theme-toggle-button {
  position: relative;
  width: 40px;
  min-width: 40px;
  overflow: hidden;
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}
.theme-toggle-button:hover { transform: translateY(-1px); }
.theme-toggle-button svg { width: 15px; height: 15px; }
html[data-theme="dark"] .theme-toggle-button {
  background: var(--study-paper-2);
  border-color: var(--study-line);
  color: #f2cc76;
}
html[data-theme="light"] .theme-toggle-button { color: #4d5d6c; }

.appearance-preview-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 2px 0 18px;
}
.theme-choice {
  position: relative;
  min-width: 0;
  min-height: 126px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 18px;
  align-items: start;
  gap: 11px;
  padding: 14px;
  text-align: left;
  color: var(--study-ink);
  background: var(--study-paper-2);
  border: 1px solid var(--study-line-soft);
  border-radius: 10px;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.theme-choice:hover { border-color: var(--study-line); transform: translateY(-1px); }
.theme-choice.active { border-color: var(--study-ink); background: var(--study-paper); }
.theme-choice > span:nth-child(2) { min-width: 0; }
.theme-choice strong, .theme-choice small { display: block; }
.theme-choice strong { margin-top: 1px; font-size: .8rem; }
.theme-choice small { margin-top: 5px; color: var(--study-muted); font-size: .66rem; line-height: 1.48; }
.theme-check { margin-top: 3px; color: transparent; }
.theme-choice.active .theme-check { color: var(--study-ink); }
.theme-swatch {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid rgba(127, 137, 148, .22);
}
.theme-swatch-light { background: #fffefb; color: #4c5966; }
.theme-swatch-dark { background: #171d23; color: #f1cc75; }
.theme-swatch-system { background: linear-gradient(135deg, #fffefb 0 49.5%, #171d23 50.5% 100%); color: #777f87; }

html[data-theme="dark"] .study-button:hover,
html[data-theme="dark"] .study-icon-button:hover,
html[data-theme="dark"] .file-tile:hover { border-color: #465363; }
html[data-theme="dark"] .theme-choice.active { border-color: #d9e0e6; }
html[data-theme="dark"] .theme-choice.active .theme-check { color: #d9e0e6; }

@media (max-width: 820px) {
  .appearance-preview-row { grid-template-columns: 1fr; }
  .theme-choice { min-height: 82px; }
}

@media (max-width: 640px) {
  .study-top-actions .connection-chip { display: none; }
  .theme-toggle-button { display: inline-flex; }
}

/* V3.3 — Multi-provider Study AI */
.ai-provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}
.ai-provider-choice {
  min-width: 0;
  min-height: 86px;
  display: grid;
  grid-template-columns: 42px minmax(0,1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 13px;
  text-align: left;
  color: var(--study-ink);
  background: var(--study-paper-2);
  border: 1px solid var(--study-line-soft);
  border-radius: 10px;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.ai-provider-choice:hover { border-color: var(--study-line); transform: translateY(-1px); }
.ai-provider-choice.active { border-color: var(--study-ink); background: var(--study-paper); }
.ai-provider-choice > span:nth-child(2) { min-width: 0; }
.ai-provider-choice strong, .ai-provider-choice small { display: block; }
.ai-provider-choice strong { font-size: .82rem; }
.ai-provider-choice small { margin-top: 4px; color: var(--study-muted); font-size: .65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-provider-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--study-line-soft);
  border-radius: 9px;
  background: var(--study-paper);
  color: var(--study-ink);
}
.ai-provider-icon.gemini { color: #556b82; }
.provider-status {
  padding: 4px 7px;
  border: 1px solid var(--study-line-soft);
  border-radius: 999px;
  color: var(--study-muted);
  background: var(--study-paper);
  font-size: .59rem;
  font-weight: 700;
  white-space: nowrap;
}
.provider-status.ready { color: #55735e; border-color: color-mix(in srgb, #55735e 30%, var(--study-line-soft)); }
.provider-ready-note {
  padding: 10px 12px;
  display: flex;
  gap: 7px;
  align-items: center;
  border: 1px solid color-mix(in srgb, #55735e 26%, var(--study-line-soft));
  border-radius: 9px;
  background: color-mix(in srgb, var(--study-paper) 94%, #55735e 6%);
  color: var(--study-muted);
  font-size: .69rem;
  line-height: 1.45;
}
.provider-ready-note b { color: var(--study-ink); }
html[data-theme="dark"] .ai-provider-choice.active { border-color: #d9e0e6; }
html[data-theme="dark"] .ai-provider-icon.gemini { color: #9fb7cf; }
@media (max-width: 720px) {
  .ai-provider-grid { grid-template-columns: 1fr; }
}

/* V3.4 — Automatic AI fallback */
.fallback-settings {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--study-line-soft);
  border-radius: 11px;
  background: var(--study-paper-2);
}
.fallback-settings h3 {
  margin: -3px 0 0;
  color: var(--study-ink);
  font-size: .9rem;
}
.fallback-settings > p {
  margin: -5px 0 1px;
  color: var(--study-muted);
  font-size: .69rem;
  line-height: 1.55;
}
.fallback-model-list {
  min-height: 132px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
  line-height: 1.65;
}
.fallback-chain-preview {
  padding: 10px 12px;
  border: 1px dashed var(--study-line);
  border-radius: 9px;
  background: var(--study-paper);
  color: var(--study-muted);
  font-size: .67rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.fallback-chain-preview b { color: var(--study-ink); }
.provider-ready-note .fa-rotate,
.provider-ready-note .fa-spinner { flex: 0 0 auto; }
@media (max-width: 720px) {
  .fallback-settings { padding: 12px; }
}
