:root { --sa-accent: var(--accent); }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--ground); color: var(--ink); font: 14px/20px var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); }
kbd { font: 500 11px var(--font); color: var(--ink-3); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 1px 5px; }

/* MARK: shell */

#app { display: flex; height: 100vh; }
.rail { width: 68px; flex: none; background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail-mark { width: 36px; height: 36px; border-radius: 9px; background: #EA580C; color: #14171C; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.rail-mark:hover { color: #14171C; }
.rail-item { width: 52px; height: 52px; border-radius: var(--r-xl); color: var(--rail-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 500 10px/12px var(--font); text-decoration: none; }
.rail-item:hover { color: #FFFFFF; background: color-mix(in srgb, var(--rail-active) 60%, transparent); }
.rail-item[aria-current="page"] { background: var(--rail-active); color: #FFFFFF; font-weight: 600; }
.rail-item[aria-current="page"] svg { stroke: var(--accent-soft); }
.rail-space { flex: 1; }
.rail-account { width: 36px; height: 36px; border-radius: 18px; border: 0; background: var(--rail-avatar); color: #FFFFFF; font: 600 12px var(--font); }
.rail :focus-visible { outline-color: var(--accent-soft); }

.view { flex: 1; min-width: 0; height: 100vh; overflow: hidden; }
.view-root { height: 100%; }
.view-root:focus { outline: none; }
.view-error { padding: 40px 32px; }

/* MARK: controls */

.btn { height: 36px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--r-lg); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 14px var(--font); text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }
.btn.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); font-weight: 500; }
.btn.secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--danger); color: #FFFFFF; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }
.new-button { padding: 0 14px 0 10px; }

.field { height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 0 10px; font-size: 14px; color: var(--ink); min-width: 0; }
.field::placeholder { color: var(--ink-4); }
.field:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 0; border-color: transparent; }
select.field { padding-right: 6px; }

.seg { display: flex; background: var(--fill); border-radius: var(--r-lg); padding: 3px; gap: 2px; flex: none; }
.seg-button { height: 30px; padding: 0 12px; border: 0; border-radius: var(--r-md); background: transparent; font: 500 13px var(--font); color: var(--ink-2); white-space: nowrap; }
.seg-button:hover { color: var(--ink); }
.seg-button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow-1); font-weight: 600; color: var(--ink); }

.icon-button { width: 32px; height: 32px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; }
.icon-button:hover { background: var(--fill); color: var(--ink); }
.link-button { border: 0; background: transparent; padding: 0; color: var(--accent); font: 500 13px var(--font); }
.link-button:hover { color: var(--accent-hover); }

.type-tag { font: 600 11px/16px var(--font); letter-spacing: 0.04em; border-radius: var(--r-sm); padding: 1px 6px; white-space: nowrap; color: var(--tone-other-ink); background: var(--tone-other-wash); }
.type-tag[data-tone="workbook"] { color: var(--tone-workbook-ink); background: var(--tone-workbook-wash); }
.type-tag[data-tone="filled"] { color: var(--tone-filled-ink); background: var(--tone-filled-wash); }
.type-tag[data-tone="homework"] { color: var(--tone-homework-ink); background: var(--tone-homework-wash); }
.type-tag[data-tone="tute"] { color: var(--tone-tute-ink); background: var(--tone-tute-wash); }
.type-tag[data-tone="practice"] { color: var(--tone-practice-ink); background: var(--tone-practice-wash); }
.type-tag[data-tone="ppqs"] { color: var(--tone-ppqs-ink); background: var(--tone-ppqs-wash); }
.type-tag[data-tone="exam"] { color: var(--tone-exam-ink); background: var(--tone-exam-wash); }
.type-tag[data-tone="notes"] { color: var(--tone-notes-ink); background: var(--tone-notes-wash); }
.type-tag[data-tone="solutions"] { color: var(--tone-solutions-ink); background: var(--tone-solutions-wash); }

.tag { font: 500 11px/16px var(--font); border-radius: var(--r-sm); padding: 1px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tag.warn { color: var(--warn-ink); background: var(--warn-wash); }
.tag.info { color: var(--info-ink); background: var(--info-wash); }

.course-dot { width: 8px; height: 8px; border-radius: 3px; background: var(--dot, var(--ink-4)); flex: none; }
.course-dot.big { width: 12px; height: 12px; border-radius: 4px; }

.status-dot { width: 8px; height: 8px; border-radius: 4px; flex: none; background: var(--dot-none); }
.status-dot[data-kind="draft"] { background: var(--dot-draft); }
.status-dot[data-kind="books"] { background: var(--dot-books); }
.status-dot[data-kind="ok"] { background: var(--dot-ok); }

.skeleton { background: var(--skeleton); border-radius: var(--r-md); animation: pulse 1.4s ease-in-out infinite; }
.sk-row { height: 26px; margin: 2px 0; }
.sk-card { height: 62px; border-radius: var(--r-xl); }
.sk-head { height: 18px; width: 180px; }
.sk-tile { height: 92px; border-radius: var(--r-lg); }
@keyframes pulse { 50% { opacity: 0.55; } }

/* MARK: library */

.library { display: flex; height: 100%; }
.lib-side { width: 252px; flex: none; background: var(--surface-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 14px; overflow-y: auto; }
.find-field { height: 38px; flex: none; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); display: flex; align-items: center; gap: 8px; padding: 0 10px; color: var(--ink-3); font: 400 14px var(--font); text-align: left; }
.find-field:hover { border-color: var(--line-strong); }
.find-label { flex: 1; }

.side-list { display: flex; flex-direction: column; gap: 1px; }
.side-group { height: 30px; border: 0; background: transparent; display: flex; align-items: center; gap: 6px; padding: 0 8px; margin-top: 6px; font: 600 11px var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); text-align: left; border-radius: var(--r-md); }
.side-group:first-child { margin-top: 0; }
.side-group:hover { color: var(--ink); }
.side-group svg { transition: transform 120ms ease; }
.side-group[aria-expanded="true"] svg { transform: rotate(90deg); }
.side-course { height: 30px; border-radius: var(--r-md); display: flex; align-items: center; gap: 8px; padding: 0 8px; font: 500 14px var(--font); color: var(--ink); text-decoration: none; }
.side-course:hover { background: var(--fill-hover); color: var(--ink); }
.side-course.on { background: var(--fill); font-weight: 600; }
.side-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-count { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.side-topics { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 15px; padding-left: 9px; border-left: 1px solid var(--line); }
.side-topic { height: 28px; border-radius: 7px; display: flex; align-items: center; gap: 6px; padding: 0 8px; font: 500 13px var(--font); color: var(--ink-2); text-decoration: none; }
.side-topic:hover { background: var(--fill-hover); color: var(--ink); }
.side-topic.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.side-topic.on .side-count { color: inherit; }

.lib-main { flex: 1; min-width: 0; overflow-y: auto; }
.lib-inner { padding: 22px 32px 48px; display: flex; flex-direction: column; gap: 18px; max-width: 1400px; }

.section-head { display: flex; align-items: baseline; gap: 10px; }
.section-title { margin: 0; font: 600 13px var(--font); color: var(--ink-2); }
.section-link { font-size: 13px; text-decoration: none; }
.section-link:hover { text-decoration: underline; }

.jump { display: flex; flex-direction: column; gap: 8px; }
.jump-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.jump-card { height: 62px; border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); display: flex; align-items: center; gap: 12px; padding: 0 12px; color: var(--ink); text-decoration: none; min-width: 0; }
.jump-card:hover { border-color: var(--line-strong); color: var(--ink); }
.paper { width: 30px; height: 40px; border-radius: 3px; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 2px 2px 0 var(--paper-shadow); flex: none; display: flex; flex-direction: column; gap: 3px; padding: 6px 5px; }
.paper-head { height: 3px; background: var(--dot, var(--ink-4)); border-radius: 1px; width: 70%; }
.paper-line { height: 2px; background: var(--line-strong); border-radius: 1px; }
.paper-line.short { width: 60%; }
.jump-text { min-width: 0; display: flex; flex-direction: column; }
.jump-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jump-where { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.course-group { display: flex; flex-direction: column; gap: 8px; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.course-card { min-height: 62px; border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: var(--ink); text-decoration: none; }
.course-card:hover { border-color: var(--line-strong); color: var(--ink); }
.course-card-text { display: flex; flex-direction: column; min-width: 0; }
.course-card-name { font-weight: 600; }
.course-card-count { font-size: 12px; color: var(--ink-3); }

.course-head { display: flex; align-items: flex-end; gap: 12px 16px; margin-top: 6px; flex-wrap: wrap; }
.course-title { flex: 1 1 240px; min-width: 0; }
.eyebrow { font-size: 13px; color: var(--ink-3); }
.page-title { margin: 2px 0 0; font: 700 30px/36px var(--font-display); letter-spacing: -0.01em; color: var(--ink); }
.filter { width: 200px; height: 36px; }

.shelf { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2xl); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.shelf-head { display: flex; align-items: baseline; gap: 10px; }
.shelf-title { margin: 0; font: 700 16px/22px var(--font-display); }
.shelf-note { font-size: 12px; color: var(--ink-3); }
.shelf-count { margin-left: auto; font-size: 12px; color: var(--ink-4); }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 10px; }
.tile-wrap { position: relative; min-width: 0; }
.tile { min-height: 92px; height: 100%; width: 100%; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-2); padding: 10px 12px; display: flex; flex-direction: column; text-align: left; color: var(--ink); text-decoration: none; }
a.tile:hover { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.tile-top { display: flex; padding-right: 26px; }
.tile-title { margin-top: 6px; font: 600 14px/18px var(--font); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; min-width: 0; }
.tile-fill { flex: 1; min-height: 8px; }
.tile-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; min-width: 0; }
.status-text { overflow: hidden; text-overflow: ellipsis; }
.tile-more { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-3); display: flex; align-items: center; justify-content: center; opacity: 0; }
.tile-wrap:hover .tile-more, .tile-more:focus-visible, .tile-more[aria-expanded="true"] { opacity: 1; }
.tile-more:hover, .tile-more[aria-expanded="true"] { background: var(--fill); color: var(--ink); }
.tile.new-here { border: 1px dashed var(--line-dashed); background: transparent; color: var(--ink-3); flex-direction: row; align-items: center; justify-content: center; gap: 6px; font: 500 13px var(--font); }
.tile.new-here:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .tile-more { opacity: 1; } }

.others { display: flex; flex-direction: column; gap: 14px; }
.others > summary { cursor: pointer; padding: 4px 0; list-style-position: inside; }
.others[open] > summary { margin-bottom: 14px; }
.others > .shelf + .shelf { margin-top: 14px; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty p { margin: 0; }

/* MARK: popovers, menus */

.popover { position: fixed; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); max-height: calc(100vh - 16px); overflow: auto; animation: pop-in 120ms ease-out; }
.popover:focus { outline: none; }
.popover-scrim { position: fixed; inset: 0; z-index: 49; background: var(--scrim); animation: fade-in 120ms ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes fade-in { from { opacity: 0; } }

.menu { padding: 6px; min-width: 200px; display: flex; flex-direction: column; }
.menu-item { height: 32px; width: 100%; border: 0; border-radius: 7px; background: transparent; display: flex; align-items: center; gap: 8px; padding: 0 10px; font: 400 14px var(--font); color: var(--ink); text-align: left; text-decoration: none; white-space: nowrap; }
.menu-item:hover, .menu-item:focus { background: var(--fill); color: var(--ink); outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-bright); }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { color: var(--ink-4); cursor: default; }
.menu-label { flex: 1; }
.menu-hint { font-size: 12px; color: var(--ink-4); }
.menu-check { width: 14px; display: flex; color: var(--accent); }
.menu-heading { font: 600 11px var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); padding: 8px 10px 2px; }
.menu-heading:first-child { padding-top: 4px; }
.menu-note { font-size: 13px; color: var(--ink-3); padding: 6px 10px; }
.menu-divider { height: 1px; background: var(--line); margin: 4px 0; }

/* MARK: Find anything */

.palette-pop { width: min(640px, calc(100vw - 32px)); overflow: hidden; display: flex; flex-direction: column; }
.palette { display: flex; flex-direction: column; min-height: 0; }
.palette-field { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; border-bottom: 1px solid var(--line); color: var(--ink-3); flex: none; }
.palette-input { flex: 1; border: 0; background: transparent; font-size: 16px; color: var(--ink); min-width: 0; }
.palette-input:focus-visible { outline: none; }
.palette-list { max-height: min(60vh, 520px); overflow-y: auto; padding: 6px; }
.palette-group { font: 600 11px var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-md); color: var(--ink); text-decoration: none; cursor: pointer; }
.palette-item > svg { color: var(--ink-3); flex: none; }
.palette-item[aria-selected="true"] { background: var(--fill); color: var(--ink); }
.palette-item:hover { color: var(--ink); }
.palette-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.palette-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-detail { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-empty { padding: 20px 10px; color: var(--ink-3); text-align: center; }

/* MARK: New */

.new-pop { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.pop-title { margin: 0 0 2px; font: 700 16px/22px var(--font-display); }
.pop-row { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 10px; }
.pop-row.top { align-items: start; }
.pop-row.top > .pop-label { padding-top: 7px; }
.pop-label { font-size: 13px; color: var(--ink-3); }
.select-button, .where-button { height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 0 10px; display: flex; align-items: center; gap: 8px; text-align: left; color: var(--ink); width: 100%; min-width: 0; }
.select-button span { flex: 1; }
.select-button svg { color: var(--ink-3); }
.select-button:hover, .where-button:hover { border-color: var(--line-strong); }
.where-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where-change { font-size: 13px; color: var(--accent); flex: none; }
.where-picker { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.mini-field { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; align-items: center; font-size: 12px; color: var(--ink-3); }
.mini-field .field { height: 32px; width: 100%; }
.pop-note { margin: 6px 0 0; font-size: 12px; line-height: 16px; color: var(--ink-3); }
.pop-note.warn { color: var(--warn-ink); }
.start { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.start .seg { align-self: flex-start; }
.copy-area { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.copy-area .field { width: 100%; }
.copy-list { max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); padding: 4px; }
.copy-option { display: flex; flex-direction: column; width: 100%; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; text-align: left; color: var(--ink); }
.copy-option:hover, .copy-option:focus { background: var(--fill); outline: none; }
.copy-option:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-bright); }
.copy-title { font-size: 13px; font-weight: 500; }
.copy-where { font-size: 12px; color: var(--ink-3); }
.copy-none { margin: 6px 8px; font-size: 13px; color: var(--ink-3); }
.copy-chosen { display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
.pop-error { margin: 0; font-size: 13px; color: var(--danger); }
.pop-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* MARK: sheet */

.sheet-scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: flex; align-items: flex-start; justify-content: center; padding-top: 16vh; animation: fade-in 120ms ease-out; }
.sheet { background: var(--surface); border-radius: var(--r-2xl); padding: 20px; box-shadow: var(--shadow-pop); animation: pop-in 140ms ease-out; }
.sheet-title { margin: 0 0 6px; font: 700 18px/24px var(--font-display); overflow-wrap: anywhere; }
.sheet-body { color: var(--ink-2); }
.sheet-body p { margin: 0; }
.sheet-error { margin: 10px 0 0; font-size: 13px; color: var(--danger); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* MARK: toasts */

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--ink); color: var(--surface); border-radius: var(--r-lg); padding: 8px 6px 8px 14px; box-shadow: var(--shadow-pop); max-width: min(520px, calc(100vw - 32px)); animation: pop-in 140ms ease-out; transition: opacity 150ms ease; }
.toast.leaving { opacity: 0; }
.toast-text { flex: 1; }
.toast-error { background: var(--danger); color: #FFFFFF; }
.toast-action { border: 0; background: transparent; color: var(--accent-soft); font-weight: 600; padding: 4px 8px; border-radius: 6px; }
.toast-action:hover { background: rgba(255, 255, 255, 0.12); }
.toast-close { border: 0; background: transparent; color: inherit; opacity: 0.7; width: 26px; height: 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.toast-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.12); }

/* MARK: placeholders and the document bar */

.editor-shell { display: flex; flex-direction: column; height: 100%; }
.doc-bar { height: 54px; flex: none; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.doc-bar-title { display: flex; flex-direction: column; min-width: 0; }
.doc-bar-where { font-size: 11px; line-height: 14px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-bar-name { font: 700 15px/20px var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-bar-status { font-size: 13px; color: var(--ink-3); margin-left: 6px; white-space: nowrap; }
.placeholder { padding: 40px 32px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.placeholder p { margin: 0; }

/* MARK: narrower windows */

@media (max-width: 1180px) {
  .jump-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .lib-side { width: 220px; }
  .lib-inner { padding: 20px 24px 40px; }
}
@media (max-width: 760px) {
  .lib-side { display: none; }
  .filter { width: 100%; order: 3; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
