:root {
  --accent: #ff5a1f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 90, 31, 0.12);
  --surface: #ffffff;
  --surface-2: #f4f3ef;
  --surface-3: #ebe9e3;
  --line: rgba(24, 26, 32, 0.1);
  --text: #1b1d22;
  --muted: #6b7080;
  --danger: #e03131;
  --shadow: 0 8px 28px rgba(20, 22, 30, 0.1), 0 1px 3px rgba(20, 22, 30, 0.08);
  --radius: 14px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
body[data-theme='chalk'] {
  --accent: #ff7a45;
  --accent-soft: rgba(255, 122, 69, 0.16);
  --surface: #1b2024;
  --surface-2: #242a2f;
  --surface-3: #2d343a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9edf1;
  --muted: #8d969f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.38; cursor: default; }
input { font: inherit; color: inherit; }
code, kbd { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 6px; text-align: center;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
svg.lucide { width: 18px; height: 18px; stroke-width: 1.9; flex: none; }

#app { display: grid; grid-template-rows: 52px 1fr; height: 100vh; height: 100dvh; }

/* ---------- верхняя панель */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 10px 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0; position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand-mark { width: 28px; height: 28px; }
.brand-name { font-weight: 800; letter-spacing: -0.02em; font-size: 15px; }
.pages {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 4px 0;
}
.pages::-webkit-scrollbar { display: none; }
.page-tab {
  flex: none; border: 0; background: transparent; height: 32px; padding: 0 14px; border-radius: 9px;
  color: var(--muted); font-weight: 600; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
.page-tab:hover { background: var(--surface-2); color: var(--text); }
.page-tab.on { background: var(--accent-soft); color: var(--accent); }
.page-rename {
  flex: none; width: 140px; height: 32px; border: 1.5px solid var(--accent); border-radius: 9px; padding: 0 10px;
  background: var(--surface); font-weight: 600; outline: none;
}
.page-add {
  flex: none; width: 32px; height: 32px; border: 1px dashed var(--line); border-radius: 9px; background: transparent;
  display: grid; place-items: center; color: var(--muted);
}
.page-add:hover { color: var(--accent); border-color: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.tb {
  height: 34px; min-width: 34px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; position: relative;
}
.tb.icon { padding: 0; }
.tb:hover:not(:disabled) { background: var(--surface-2); }
.tb .chev { width: 14px; height: 14px; opacity: 0.6; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.zoom { display: flex; align-items: center; }
.zoom-val { min-width: 54px; padding: 0 4px; font-variant-numeric: tabular-nums; font-size: 13px; }

/* подсказки при наведении */
[data-tip]::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(-2px);
  white-space: pre; padding: 6px 9px; border-radius: 8px; background: #16181d; color: #fff; font-size: 12px; font-weight: 600;
  pointer-events: none; opacity: 0; transition: opacity 0.12s, transform 0.12s; z-index: 30;
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%); transition-delay: 0.35s; }

/* ---------- холст */
.stage { position: relative; overflow: hidden; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: crosshair; }
#board[data-tool='select'] { cursor: default; }
#board[data-tool='hand'], #board.grab { cursor: grab; }
#board.grabbing { cursor: grabbing !important; }
#board[data-tool='text'] { cursor: text; }
#board[data-tool='eraser'], #board[data-tool='laser'] { cursor: none; }
#board[data-tool='formula'], #board[data-tool='graph'] { cursor: copy; }
.stage.drop::after {
  content: 'Отпусти — вставлю картинку'; position: absolute; inset: 14px; border: 2px dashed var(--accent); border-radius: 18px;
  display: grid; place-items: center; font-weight: 700; color: var(--accent); background: var(--accent-soft); pointer-events: none;
}
.text-editor {
  position: absolute; z-index: 4; margin: 0; padding: 2px 4px; border: 0; border-radius: 6px; resize: none; overflow: hidden;
  background: transparent; outline: 1.5px dashed var(--accent); white-space: pre; min-width: 60px;
}

/* ---------- инструменты слева */
.rail {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); z-index: 3;
  display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
  max-height: calc(100% - 24px); overflow-y: auto; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-sep { height: 1px; margin: 4px 6px; background: var(--line); flex: none; }
.tool {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 11px; background: transparent;
  display: grid; place-items: center; position: relative; color: var(--text);
}
.tool:hover { background: var(--surface-2); }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.tool svg.lucide { width: 20px; height: 20px; }
.rail [data-tip]::after { top: 50%; left: calc(100% + 10px); transform: translateY(-50%) translateX(-2px); }
.rail [data-tip]:hover::after { transform: translateY(-50%); }

/* ---------- настройки инструмента снизу */
.optbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
  max-width: calc(100% - 24px); overflow-x: auto; scrollbar-width: none;
}
.optbar::-webkit-scrollbar { display: none; }
.optbar[hidden] { display: none; }
.opt-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.sw {
  width: 30px; height: 30px; flex: none; border: 0; border-radius: 50%; background: transparent; position: relative; padding: 0;
  display: grid; place-items: center;
}
.sw::before { content: ''; width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.sw.on::after { content: ''; position: absolute; inset: 1px; border-radius: 50%; border: 2px solid var(--accent); }
.sw-custom::before { background: var(--c, conic-gradient(#e03131, #fab005, #2b8a3e, #1c64f2, #7048e8, #e03131)); }
.sw-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.size {
  width: 32px; height: 32px; flex: none; border: 0; border-radius: 9px; background: transparent; display: grid; place-items: center;
}
.size .dot { border-radius: 50%; background: var(--text); display: block; }
.size .size-t { font-weight: 700; line-height: 1; }
.size:hover, .opt-btn:hover { background: var(--surface-2); }
.size.on, .opt-btn.on { background: var(--accent-soft); color: var(--accent); }
.size.on .dot { background: var(--accent); }
.opt-btn {
  height: 32px; min-width: 32px; flex: none; border: 0; border-radius: 9px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; font-weight: 600; white-space: nowrap;
}
.opt-btn.wide { padding: 0 10px; }
.opt-btn.danger:hover { color: var(--danger); background: rgba(224, 49, 49, 0.1); }
.hand-font { font-family: 'Caveat', cursive; font-size: 19px; font-weight: 700; }

.hint {
  position: absolute; left: 72px; bottom: 20px; z-index: 2; max-width: 300px; font-size: 12px; line-height: 1.45;
  color: var(--muted); pointer-events: none;
}
.save-state {
  position: absolute; right: 14px; bottom: 18px; z-index: 2; font-size: 12px; color: var(--muted); pointer-events: none;
}
.save-state[data-s='error'] { color: var(--danger); font-weight: 600; }

/* ---------- панели формулы и графика */
.panel {
  position: absolute; right: 12px; top: 12px; z-index: 6; width: 380px; max-height: calc(100% - 24px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
  animation: panel-in 0.16s ease-out;
}
.panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(-6px); } }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; }
.panel-title svg.lucide { color: var(--accent); }
.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 9px; background: transparent; display: grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.f-note {
  margin: 0; padding: 9px 11px; border-radius: 10px; background: var(--accent-soft); color: var(--text);
  font-size: 12.5px; line-height: 1.45; font-weight: 600;
}
.f-note[hidden] { display: none; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.f-input, .g-in, .g-range input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 11px; border: 1.5px solid var(--line); background: var(--surface-2);
  font-family: var(--mono); font-size: 15px; outline: none; transition: border-color 0.12s;
}
.f-input:focus, .g-in:focus, .g-range input:focus { border-color: var(--accent); background: var(--surface); }
.f-preview {
  min-height: 86px; max-height: 200px; overflow: auto; display: grid; place-items: center; padding: 12px;
  border-radius: 12px; background: var(--surface-2); font-size: 24px;
}
.f-preview .muted { font-size: 13px; }
.f-preview mjx-container { margin: 0 !important; }
mjx-assistive-mml { display: none !important; } /* копия для экранных читалок — MathJax её не спрятал */
.f-meta { display: flex; align-items: center; gap: 8px; min-height: 0; flex-wrap: wrap; }
.f-meta:has(.calc[hidden]):has(.f-err:empty) { display: none; }
.f-err { color: var(--danger); font-size: 12px; font-weight: 600; }
.chip {
  height: 30px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  font-family: var(--mono); font-size: 13px; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.calc { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs { display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface-2); overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1; border: 0; background: transparent; height: 30px; border-radius: 8px; font-weight: 600; font-size: 12.5px; color: var(--muted); white-space: nowrap; padding: 0 8px; }
.tab.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 5px; }
.key {
  min-height: 38px; padding: 4px 6px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif; font-size: 16px; line-height: 1.1;
  display: grid; place-items: center; text-align: center;
}
.key:hover { border-color: var(--accent); background: var(--accent-soft); }
.key:active { transform: translateY(1px); }
.fr { display: inline-flex; flex-direction: column; align-items: center; font-size: 12px; line-height: 1; }
.fr span:first-child { border-bottom: 1.3px solid currentColor; padding: 0 3px 1px; }
.fr span:last-child { padding-top: 1px; }
.f-help { font-size: 12.5px; color: var(--muted); }
.f-help summary { cursor: pointer; font-weight: 700; }
.f-help ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.7; }
.panel-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; flex-wrap: wrap; }
.btn {
  height: 38px; padding: 0 13px; border-radius: 10px; border: 1px solid transparent; display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700; white-space: nowrap;
}
.btn.small { height: 34px; padding: 0 11px; font-size: 13px; }
.btn.icon-only { padding: 0; width: 34px; justify-content: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: var(--surface-2); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn svg.lucide { width: 16px; height: 16px; }
.g-row { display: grid; grid-template-columns: 28px auto 1fr 32px; align-items: center; gap: 8px; }
.g-color { width: 22px; height: 22px; border-radius: 50%; border: 0; margin-left: 3px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--line); }
.g-y { font-family: var(--mono); font-weight: 500; color: var(--muted); }
.g-in { height: 40px; }
.g-err { grid-column: 3 / 5; color: var(--danger); font-size: 12px; font-weight: 600; margin-top: -4px; }
.g-err:empty { display: none; }
#gFns { display: flex; flex-direction: column; gap: 8px; }
.g-range { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 8px; align-items: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.g-range input { height: 36px; font-size: 14px; padding: 0 9px; }
.g-tools { display: flex; gap: 6px; }

/* ---------- меню */
.menu {
  position: fixed; z-index: 40; min-width: 230px; padding: 6px; border-radius: 13px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.menu[hidden] { display: none; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border: 0; border-radius: 9px;
  background: transparent; text-align: left; font-weight: 600;
}
.menu-item span { flex: 1; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.on { color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ---------- справка */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 12, 16, 0.45); backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(860px, 100%); max-height: 100%; overflow-y: auto; padding: 18px 22px 22px; border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow);
}
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 32px; margin-top: 8px; }
.help-grid .wide { grid-column: 1 / -1; }
.help-grid h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 8px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; align-items: center; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
.tips { margin: 0; padding-left: 18px; line-height: 1.6; display: grid; gap: 6px; }
.tips b { color: var(--text); }

/* ---------- уведомление */
.toast {
  position: fixed; left: 50%; bottom: 76px; z-index: 60; transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  max-width: min(560px, calc(100% - 32px)); padding: 10px 16px; border-radius: 12px; background: #16181d; color: #fff;
  font-weight: 600; font-size: 13px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  transition: opacity 0.16s, transform 0.16s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- телефон и узкие окна */
@media (max-width: 900px) {
  .hint { display: none; }
}
@media (max-width: 720px) {
  .brand-name, .hide-sm { display: none !important; }
  .topbar { gap: 6px; padding: 0 6px 0 10px; }
  .tb-sep { margin: 0 2px; }
  .rail {
    top: auto; bottom: 8px; left: 8px; right: 8px; transform: none; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    max-height: none; padding: 5px;
  }
  .rail-sep { width: 1px; height: auto; margin: 6px 3px; }
  .rail [data-tip]::after { display: none; }
  .optbar { bottom: 70px; }
  .save-state { bottom: auto; top: 10px; right: 12px; }
  .panel { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 72%; }
  .help-grid { grid-template-columns: 1fr; }
  .toast { bottom: 130px; }
  [data-tip]::after { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
  .toast { transition: none; }
}

/* ---------- конспект */
:root {
  --paper: #fffefb;
  --rule: rgba(64, 118, 186, 0.17);
  --margin-line: rgba(224, 49, 49, 0.28);
  --mark: rgba(255, 212, 59, 0.5);
}
body[data-theme='chalk'] {
  --paper: #171b1f;
  --rule: rgba(255, 255, 255, 0.07);
  --margin-line: rgba(255, 135, 135, 0.22);
  --mark: rgba(255, 212, 59, 0.32);
}
.notes-view { position: absolute; inset: 0; z-index: 2; overflow-y: auto; display: none; background: var(--surface-2); }
body.mode-notes .notes-view { display: block; }
body.mode-notes #board, body.mode-notes .rail, body.mode-notes .optbar, body.mode-notes .hint,
body.mode-notes .zoom, body.mode-notes .zoom + .tb-sep { display: none !important; }
.notes-toolbar {
  position: sticky; top: 12px; z-index: 3; margin: 12px auto 0; width: max-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 2px; padding: 6px; border-radius: 14px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.notes-toolbar::-webkit-scrollbar { display: none; }
.nb {
  height: 34px; min-width: 34px; flex: none; border: 0; border-radius: 9px; background: transparent; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 700; font-size: 13px; white-space: nowrap; position: relative;
}
.nb:hover { background: var(--surface-2); }
.nb.on { background: var(--accent-soft); color: var(--accent); }
.nb.accent { color: var(--accent); }
.nb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.notes-toolbar [data-tip]::after { top: calc(100% + 8px); }

.notes-paper {
  max-width: 860px; margin: 16px auto 140px; padding: 48px 64px 96px 84px; position: relative;
  min-height: calc(100% - 110px); border-radius: 8px; background-color: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 10px 30px rgba(20, 22, 30, 0.07); border: 1px solid var(--line);
}
.notes-paper[data-bg='lines'] {
  background-image: linear-gradient(90deg, transparent 63px, var(--margin-line) 63px 64px, transparent 64px),
    repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px);
  background-position: 0 0, 0 16px;
}
.notes-paper[data-bg='grid'], .notes-paper[data-bg='coord'] {
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px),
    repeating-linear-gradient(to right, transparent 0 31px, var(--rule) 31px 32px);
  background-position: 0 16px, 20px 0;
}
.notes-paper[data-bg='dots'] {
  background-image: radial-gradient(circle, var(--rule) 1.4px, transparent 1.6px);
  background-size: 32px 32px; background-position: 4px 0;
}
.notes-editor { outline: none; font-size: 17px; line-height: 32px; color: var(--text); min-height: 60vh; word-wrap: break-word; caret-color: var(--accent); }
.notes-editor.is-empty::before { content: attr(data-placeholder); position: absolute; color: var(--muted); pointer-events: none; }
.notes-editor > *:first-child { margin-top: 0; }
.notes-editor p, .notes-editor div:not([class]) { margin: 0; }
.notes-editor h1 { font-size: 30px; line-height: 64px; margin: 0; font-weight: 800; letter-spacing: -0.02em; }
.notes-editor h2, .notes-editor h3 { font-size: 21px; line-height: 32px; margin: 32px 0 0; font-weight: 800; color: var(--accent); }
.notes-editor ul, .notes-editor ol { margin: 0; padding-left: 28px; }
.notes-editor blockquote { margin: 0; padding-left: 16px; border-left: 3px solid var(--line); color: var(--muted); }
.notes-editor b, .notes-editor strong { font-weight: 800; }
.notes-editor mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

/* формулы */
.qn-math { display: inline-block; vertical-align: middle; line-height: 1; padding: 2px 3px; border-radius: 6px; cursor: pointer; font-style: normal; }
.qn-math mjx-container { display: inline-block !important; margin: 0 !important; }
.qn-mathblock { display: flex; justify-content: center; padding: 8px 0; margin: 4px 0; border-radius: 10px; cursor: pointer; font-size: 19px; background: var(--paper); }
.qn-math:hover, .qn-mathblock:hover { background: var(--accent-soft); }
.qn-math.pending, .qn-mathblock.pending { font-family: var(--mono); font-size: 14px; color: var(--muted); }

/* блоки «Определение», «Теорема»… */
.qn-box { margin: 16px 0; padding: 0 16px; border-radius: 10px; border-left: 4px solid var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 9%, var(--paper)); }
.qn-def { --c: #1c64f2; }
.qn-thm { --c: #7048e8; }
.qn-ex { --c: #2b8a3e; }
.qn-warn { --c: #e03131; }
body[data-theme='chalk'] .qn-def { --c: #74c0fc; }
body[data-theme='chalk'] .qn-thm { --c: #b197fc; }
body[data-theme='chalk'] .qn-ex { --c: #8ce99a; }
body[data-theme='chalk'] .qn-warn { --c: #ff8787; }

/* зарисовки и картинки */
.qn-sketch { margin: 16px 0; position: relative; display: flex; justify-content: center; cursor: pointer; border-radius: 12px; }
.qn-sketch img { display: block; max-width: 100%; height: auto; border-radius: 10px; box-shadow: 0 0 0 1px var(--line); }
.qn-sk-empty {
  width: 100%; min-height: 128px; display: grid; place-items: center; border-radius: 12px; border: 2px dashed var(--line);
  color: var(--muted); font-weight: 600; font-size: 14px; background: var(--paper);
}
.qn-sk-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s; }
.qn-sketch:hover .qn-sk-tools, .qn-sketch:focus-within .qn-sk-tools { opacity: 1; }
.qn-sk-tools button {
  height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 5px; box-shadow: var(--shadow);
}
.qn-sk-tools button:hover { color: var(--accent); border-color: var(--accent); }
.qn-sk-tools button.del:hover { color: var(--danger); border-color: var(--danger); }
.qn-sk-tools svg.lucide { width: 14px; height: 14px; }
.qn-img { display: block; max-width: 100%; height: auto; margin: 16px auto; border-radius: 10px; }

/* плашка режима зарисовки */
.sketch-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: none; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); border: 1.5px solid var(--accent);
  font-weight: 700; white-space: nowrap;
}
.sketch-bar svg.lucide { color: var(--accent); }
body.mode-sketch .sketch-bar { display: flex; }

/* переключатель «в строку / отдельной строкой» */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface-2); }
.seg[hidden] { display: none; }
.seg button { flex: 1; height: 32px; border: 0; border-radius: 8px; background: transparent; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }

.page-tab svg.lucide { width: 14px; height: 14px; margin-right: 5px; vertical-align: -2px; }

@media (max-width: 720px) {
  .notes-paper { margin: 12px 8px 120px; padding: 32px 16px 80px 20px; }
  .notes-paper[data-bg='lines'] { background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px); background-position: 0 0; }
  .sketch-bar { top: auto; bottom: 132px; }
}
.study-dialog {
  width: min(540px, calc(100vw - 24px));
  max-height: min(80vh, 720px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
.study-dialog::backdrop { background: rgba(15, 18, 25, .45); }
.study-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.study-dialog h2 { font-size: 18px; margin: 0; }
.study-dialog p { font-size: 13px; }
.study-dialog button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: inherit;
  cursor: pointer;
}
.study-dialog button:hover { background: var(--surface-3); }
.study-dialog button:disabled { opacity: .45; cursor: default; }
.shortcut-row, .quick-math-row {
  display: grid;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}
.shortcut-row { grid-template-columns: minmax(0, 1fr) auto auto; }
.quick-math-row { grid-template-columns: minmax(0, 1fr) auto; }
.quick-math-row > button:first-child { display: grid; text-align: left; gap: 3px; }
.quick-math-row span, .quick-math-row small { overflow-wrap: anywhere; }
.quick-math-row [aria-pressed="true"] { color: var(--accent); }
#shortcutStatus { min-height: 2em; }

/* Размер панелей и кнопок независимо от масштаба листа. */
body[data-interface-size='large'] { --ui-scale: 1.15; }
body[data-interface-size='extra'] { --ui-scale: 1.3; }

.interface-size {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 8px; margin-top: 16px; padding: 10px; border-radius: 9px; background: var(--surface-2);
}
.interface-size select {
  max-width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: inherit; font: inherit;
}

body:is([data-interface-size='large'], [data-interface-size='extra']) {
  font-size: calc(14px * var(--ui-scale));
}
body:is([data-interface-size='large'], [data-interface-size='extra']) #app {
  grid-template-rows: calc(52px * var(--ui-scale)) minmax(0, 1fr);
}
.tb { min-width: calc(34px * var(--ui-scale, 1)); height: calc(34px * var(--ui-scale, 1)); }
.page-tab, .page-add, .page-rename { height: calc(32px * var(--ui-scale, 1)); }
.page-add { width: calc(32px * var(--ui-scale, 1)); }
.tool { width: calc(40px * var(--ui-scale, 1)); height: calc(40px * var(--ui-scale, 1)); }
.tool svg.lucide { width: calc(20px * var(--ui-scale, 1)); height: calc(20px * var(--ui-scale, 1)); }
.sw { width: calc(30px * var(--ui-scale, 1)); height: calc(30px * var(--ui-scale, 1)); }
.sw::before { width: calc(20px * var(--ui-scale, 1)); height: calc(20px * var(--ui-scale, 1)); }
.nb { min-width: calc(34px * var(--ui-scale, 1)); height: calc(34px * var(--ui-scale, 1)); font-size: calc(13px * var(--ui-scale, 1)); }
.study-dialog p { font-size: calc(13px * var(--ui-scale, 1)); }

@media (hover: hover) and (pointer: fine) {
  .tool:hover:not(:disabled), .sw:hover:not(:disabled) {
    z-index: 2; scale: 1.12; box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
  }
  .sw:hover:not(:disabled) { background: var(--surface); }
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .tool, .sw { transition: scale 120ms ease, box-shadow 120ms ease; }
}
@media (max-width: 600px) {
  body:is([data-interface-size='large'], [data-interface-size='extra']) #app { grid-template-rows: auto minmax(0, 1fr); }
  body:is([data-interface-size='large'], [data-interface-size='extra']) .topbar { flex-wrap: wrap; padding-block: 4px; }
  body:is([data-interface-size='large'], [data-interface-size='extra']) .pages { order: 1; flex-basis: 100%; }
  body:is([data-interface-size='large'], [data-interface-size='extra']) .top-actions { flex: 1 1 auto; min-width: 0; flex-wrap: wrap; }
  body:is([data-interface-size='large'], [data-interface-size='extra']) .optbar { bottom: calc(24px + 46px * var(--ui-scale)); }
}

/* Главная и библиотека тетрадей */
#app[hidden], .library [hidden], #home[hidden] { display: none; }
.library {
  --library-ink: #29231e;
  --library-muted: #6b6056;
  --library-stroke: #e7ded2;
  --library-white: #fffdf8;
  display: grid; grid-template-columns: 225px minmax(0, 1fr);
  height: 100dvh; overflow: auto; color: var(--library-ink);
  background: #f8f4ee; color-scheme: light;
}
.library button, .book-form button { font-weight: 700; }
.library-nav {
  padding: 30px 18px; border-right: 1px solid var(--library-stroke); background: var(--library-white);
}
.library-brand {
  display: flex; align-items: center; gap: 12px; padding: 0 8px;
  font-size: 21px; line-height: 1.15; font-weight: 800; letter-spacing: -.03em;
}
.library-brand small { display: block; margin-top: 5px; color: var(--library-muted); font-size: 11px; letter-spacing: 0; font-weight: 600; }
.library-nav nav { display: grid; gap: 6px; margin-top: 38px; }
.library-nav nav button {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border: 0; border-radius: 11px; background: transparent; text-align: left;
}
.library-nav nav button:hover { background: #f7f2eb; }
.library-nav nav button[aria-current] { background: #f9e8dc; color: #a83b14; }
.library-main { padding: clamp(24px, 5vw, 70px); max-width: 1450px; width: 100%; margin-inline: auto; }
.library-heading {
  display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap;
  gap: 16px; border-bottom: 1px solid var(--library-stroke); padding-bottom: 24px; margin-bottom: 24px;
}
.library-heading h1 { font-size: clamp(32px, 5vw, 54px); letter-spacing: -.06em; margin: 0; line-height: 1.05; }
.library-heading p, .library-box p { color: var(--library-muted); margin: 8px 0 0; }
.library-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.library-actions button, .library-box button, .book-form button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 13px;
  border: 1px solid var(--library-stroke, var(--line)); border-radius: 9px; background: var(--library-white, var(--surface-2));
}
button.library-primary { background: #a53c19; border-color: #a53c19; color: white; }
button.library-primary:hover { background: #853013; }
#libraryStatus:empty, #bookFormStatus:empty, #profileStatus:empty { display: none; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 205px), 1fr)); gap: 16px; }
.book-card { min-width: 0; border: 1px solid var(--library-stroke); border-radius: 15px; background: var(--library-white); padding: 7px; }
.book-cover {
  position: relative; display: block; width: 100%; height: 130px;
  border: 1px solid #e8dfd1; border-radius: 10px; background-color: #f7efdf; overflow: hidden;
  --paper-rule: #a6bcc399;
}
.book-cover:hover { border-color: #a53c19; }
.book-cover[data-paper='grid'], .book-cover[data-paper='coord'] {
  background-image: linear-gradient(var(--paper-rule) 1px, transparent 1px), linear-gradient(90deg, var(--paper-rule) 1px, transparent 1px);
  background-size: 17px 17px;
}
.book-cover[data-paper='lines'] { background-image: linear-gradient(var(--paper-rule) 1px, transparent 1px); background-size: 100% 17px; }
.book-cover[data-paper='dots'] { background-image: radial-gradient(#7996a5 1px, transparent 1.5px); background-size: 14px 14px; }
.book-cover[data-paper='coord']::before {
  content: ''; position: absolute; inset: 0; background:
    linear-gradient(90deg, transparent calc(50% - 1px), #7696a8 50%, transparent calc(50% + 1px)),
    linear-gradient(transparent calc(50% - 1px), #7696a8 50%, transparent calc(50% + 1px));
}
.book-cover span {
  position: absolute; top: 9px; left: 9px; padding: 5px 9px; border-radius: 7px;
  background: #fffdf3ee; border: 1px solid #e8dfd1; font-size: 12px;
}
.book-caption { display: flex; align-items: center; gap: 6px; padding: 7px 3px 1px 7px; }
.book-caption h2 { margin: 0; min-width: 0; flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-caption button { display: grid; place-items: center; border: 0; width: 36px; height: 36px; border-radius: 9px; background: transparent; }
.book-caption button:hover { background: #f8ede2; }
.book-popup {
  position: fixed; margin: 0; inset: auto; min-width: 170px; padding: 5px; border-radius: 15px;
  border: 1px solid #fff; background: #fffaf0eb; color: #29231e;
  backdrop-filter: blur(18px) saturate(150%); box-shadow: 0 12px 36px #34200e33;
}
.book-popup button {
  display: flex; width: 100%; align-items: center; gap: 9px; padding: 9px 10px;
  border: 0; border-radius: 9px; background: transparent; text-align: left;
}
.book-popup button:is(:hover, :focus-visible) { background: #efe3d6; }
.book-popup button:last-child { color: #a73124; }
.library-box {
  max-width: 500px; display: grid; justify-items: start; gap: 10px;
  padding: 20px; background: var(--library-white); border: 1px solid var(--library-stroke); border-radius: 14px;
}
.library-box h2 { margin: 0; font-size: 17px; }
.library-box p { margin: 0; }
.library-box input, .book-form input, .book-form select {
  width: 100%; min-width: 0; padding: 9px; border: 1px solid var(--library-stroke, var(--line)); border-radius: 8px;
  background: var(--library-white, var(--surface-2)); color: inherit; font: inherit;
}
.book-form { display: grid; gap: 8px; padding-top: 16px; }
.book-form button { justify-self: start; }

@media (max-width: 720px) {
  .library { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .library-nav { padding: 12px; border-right: 0; border-bottom: 1px solid var(--library-stroke); }
  .library-nav nav { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
  .library-nav nav button { padding: 7px 8px; }
  .library-main { padding: 20px 12px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 145px), 1fr)); gap: 8px; }
}
@media (max-width: 600px) {
  #backToLibrary { min-width: 32px; }
  .topbar:has(#backToLibrary) .top-actions { flex: 1 1 auto; flex-wrap: wrap; min-width: 0; }
  .topbar:has(#backToLibrary) .pages { min-width: min(80px, 25vw); }
}

.notes-editor .qn-solution {
  margin: 12px 0; padding: 4px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface);
}
.notes-editor .qn-solution > summary { cursor: pointer; font-weight: 800; color: var(--accent); }

/* Главное меню: профиль сверху, разделы в нижней панели. */
.library {
  display: block;
  background: var(--library-bg, #f8f4ee);
}
.library-top {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center;
  justify-content: space-between; min-height: 62px; gap: 12px;
  padding: 8px clamp(12px, 4vw, 48px); border-bottom: 1px solid var(--library-stroke);
  background: var(--library-white);
}
.library-top .library-brand { padding: 0; }
.library-dock {
  position: fixed; z-index: 2; left: 50%; bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; gap: 4px; padding: 5px; border-radius: 17px;
  border: 1px solid var(--library-stroke); background: var(--library-white);
  box-shadow: 0 8px 30px #18120d28;
}
.library-dock button, .profile-tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px;
  white-space: nowrap; border: 0; border-radius: 11px; background: transparent;
}
.library-dock button:hover, .profile-tab:hover { background: var(--library-hover, #f7f2eb); }
.library-dock button[aria-current], .profile-tab[aria-current] {
  background: var(--library-selected, #f9e8dc); color: var(--library-accent, #a83b14);
}
.library-main { min-height: calc(100% - 62px); padding-bottom: 100px; }
.library-box + .library-box { margin-top: 12px; }
.library-box select {
  min-width: 0; padding: 8px; border: 1px solid var(--library-stroke); border-radius: 8px;
  background: var(--library-white); color: inherit; font: inherit;
}
.library-box .profile-check { display: flex; align-items: center; gap: 7px; }
.library-box .profile-check input { width: auto; accent-color: var(--accent); }
.library-box a { color: var(--library-accent, #a83b14); text-underline-offset: 2px; }
.library-box progress { width: 100%; accent-color: var(--accent); }
#homeContext:has(.context-emoji) { min-width: 0; }
#homeContext .context-emoji { padding: 7px 11px; font-size: 30px; }
#homeContext button:last-child { color: inherit; }
body[data-theme='chalk'] .library {
  color-scheme: dark;
  --library-ink: #ede8e2;
  --library-muted: #aea7a0;
  --library-stroke: #414140;
  --library-white: #242424;
  --library-bg: #191919;
  --library-hover: #35312f;
  --library-selected: #543625;
  --library-accent: #ffad91;
}
body[data-theme='chalk'] .book-cover { border-color: #55514b; background-color: #33302c; --paper-rule: #71909769; }
body[data-theme='chalk'] .book-cover span { border-color: #62594d; background: #302b26; }
body[data-theme='chalk'] .book-caption button:hover { background: #35312f; }
body[data-theme='chalk'] .book-popup { border-color: #645851; background: #282421e8; color: #f2e9df; }
body[data-theme='chalk'] .book-popup button:is(:hover,:focus-visible) { background: #44372f; }
body[data-theme='chalk'] .book-popup button:last-child { color: #ff9d8b; }
@media (max-width: 720px) {
  .library-main { padding-bottom: 90px; }
}

/* Настройки главного меню */
.settings-page {
  --settings-line: #decfc1;
  --settings-action: #913713;
  --settings-tint: #f7e5d7;
  --settings-key-bg: #f5ebdf;
  --settings-key: #fffaf2;
  --settings-focus: #a83b14;
}
body[data-theme='chalk'] .settings-page {
  --settings-line: #51443b;
  --settings-action: #ffbb9c;
  --settings-tint: #483025;
  --settings-key-bg: #2a2420;
  --settings-key: #302923;
  --settings-focus: #ffb494;
}
.settings-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 22px; border-bottom: 1px solid var(--library-stroke); padding-bottom: 18px;
}
.settings-heading h1 {
  margin: 0; font-size: clamp(32px, 5vw, 54px); letter-spacing: -.06em; line-height: 1.05;
}
.settings-heading p { margin: 8px 0 0; color: var(--library-muted); }
.settings-buddy {
  flex: none; object-fit: contain; transform: rotate(5deg);
  filter: drop-shadow(0 5px 8px #1d140c30);
}
.settings-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 1.5vw, 20px);
}
.settings-card {
  display: flex; flex-direction: column; align-items: start; gap: 10px; min-width: 0;
  border: 1px solid var(--library-stroke); border-radius: 18px; padding: clamp(14px, 2vw, 24px);
  background: var(--library-white);
}
.settings-card:is(:focus-within, :hover) { border-color: var(--settings-line); }
.settings-card h2 {
  display: flex; align-items: center; gap: 10px; font-size: clamp(16px, 2vw, 20px); margin: 0;
  letter-spacing: -.025em; line-height: 1.2;
}
.settings-card p { color: var(--library-muted); margin: 0; max-width: 55ch; }
.settings-mark {
  display: grid; place-items: center; flex: none; border-radius: 12px; width: 38px; height: 38px;
  color: var(--settings-action); background: var(--settings-tint);
}
.settings-mark svg { width: 20px; height: 20px; }
.settings-app-mark { background: transparent; }
.settings-team-mark {
  display: flex; justify-content: center; gap: 1px; background: #173333; color: #e4fff8;
  font-size: 24px; font-weight: 800; letter-spacing: -.085em;
}
.settings-team-mark span { color: #6ce6bd; }
.settings-keyboard {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0;
  padding: 8px; background: var(--settings-key-bg); border-radius: 10px;
}
.settings-keyboard kbd {
  display: grid; place-items: center; min-width: 33px; height: 28px; background: var(--settings-key);
  border-color: var(--settings-line); color: var(--library-ink);
}
.settings-card .settings-action {
  display: inline-flex; align-items: center; gap: 8px; margin-top: auto;
  background: var(--settings-tint); padding: 8px 11px; border-radius: 9px; border: 1px solid transparent;
  color: var(--settings-action); text-decoration: none; font-weight: 800; min-height: 36px;
}
.settings-action svg { width: 15px; height: 15px; }
.settings-card .settings-action:hover { border-color: var(--settings-line); }
.theme-options { display: grid; width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: auto; }
.theme-option {
  display: grid; gap: 4px; min-width: 0; padding: 5px; background: var(--library-bg, #f8f4ee);
  color: var(--library-ink); border: 1px solid var(--library-stroke); border-radius: 10px;
  font-size: clamp(11px, 1.2vw, 13px); text-align: center;
}
.theme-option[aria-pressed='true'] { border-color: var(--settings-focus); color: var(--settings-action); background: var(--settings-tint); }
.theme-sample {
  --mock-bg: #f6ead9; --mock-grid: #b6a59255; --mock-line: #9a7e6270;
  display: block; height: clamp(37px, 5vw, 64px); border-radius: 6px; position: relative;
  background:
    linear-gradient(var(--mock-grid) 1px,transparent 1px), linear-gradient(90deg,var(--mock-grid) 1px,transparent 1px), var(--mock-bg);
  background-size: 9px 9px,9px 9px,auto;
}
.theme-sample--dark { --mock-bg: #262623; --mock-grid: #d2d0b922; --mock-line: #decdbb80; }
.theme-sample--auto { --mock-bg: linear-gradient(120deg,#f6ead9 50%,#262623 50%); --mock-line: #ef9464; }
.theme-sample::after {
  content: ''; position: absolute; top: 30%; left: 21%; right: 21%; height: 3px; border-radius: 3px;
  background: var(--mock-line); box-shadow: 0 8px var(--mock-line);
}
#homeContext .context-emoji { display: block; object-fit: contain; padding: 4px; }
.settings-page :is(button,a):focus-visible { outline: 2px solid var(--settings-focus); outline-offset: 2px; }
@media (min-width: 681px) {
  .library-main:has(.settings-page:not([hidden])) { padding-top: clamp(16px, 3vw, 38px); }
}
@media (max-width: 680px) {
  .settings-grid { grid-template-columns: 1fr; }
  .settings-heading { margin-bottom: 12px; }
  .settings-buddy { width: 65px; height: 65px; }
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .settings-card { transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease; }
  .settings-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px #25160d18; }
  .settings-buddy { transition: transform 180ms ease; }
  .settings-buddy:hover { transform: rotate(-7deg) scale(1.07); }
}

/* Профиль и состояния аккаунта */
.profile-heading {
  display: flex; align-items: center; gap: clamp(12px, 2vw, 24px); margin-bottom: 20px; padding-bottom: 18px;
  border-bottom: 1px solid var(--library-stroke);
}
.profile-heading h1 { font-size: clamp(32px, 5vw, 52px); margin: 0; letter-spacing: -.06em; line-height: 1; }
.profile-heading p { margin: 6px 0 0; color: var(--library-muted); }
.profile-heading #profileIdentity { color: var(--settings-action); font-weight: 800; }
.profile-mascot, .home-mascot { object-fit: contain; flex: none; }
.profile-grid { align-items: stretch; }
.profile-grid .settings-card { align-self: stretch; width: 100%; overflow-wrap: anywhere; }
.profile-fields {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); width: 100%; gap: 8px;
}
.profile-details input:not([type='checkbox']) {
  min-width: 0; width: 100%; border: 1px solid var(--library-stroke); border-radius: 8px;
  padding: 9px; background: var(--library-bg, #f8f4ee); color: inherit;
}
.profile-fields label, .profile-details > label:not(.profile-check) {
  display: block; margin-bottom: 3px; font-weight: 700; font-size: .9em;
}
.profile-check { display: inline-flex; align-items: center; gap: 7px; }
.profile-check input, #profileQuota { accent-color: var(--accent); }
.stamp-preview {
  display: block; width: 100%; padding: 7px; text-align: right; border-top: 1px dashed var(--library-stroke);
  color: var(--library-muted); font-size: .9em;
}
#profileQuota { width: 100%; min-height: 11px; }
.profile-account-link { color: var(--settings-action); text-underline-offset: 3px; }
.profile-list { display: grid; gap: 6px; width: 100%; margin: 0; padding: 0; list-style: none; }
.profile-list li {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 5px;
  border-bottom: 1px solid var(--library-stroke); padding: 5px 0;
}
.profile-list button { background: var(--settings-tint); border: 0; border-radius: 8px; padding: 5px 8px; color: var(--settings-action); }
#accountDialogBody input { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px; }
@media (max-width: 420px) {
  .profile-mascot { width: 58px; height: 58px; }
  .profile-fields { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .home-panel-enter { animation: reveal-home-panel 220ms ease-out both; }
  .home-mascot, .profile-mascot { transition: transform 180ms ease; }
  .home-mascot:hover, .profile-mascot:hover { transform: rotate(-7deg) scale(1.08); }
  @keyframes reveal-home-panel {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* Состояние аккаунта задаётся сервером, скрытые действия остаются скрытыми. */
.library :is(#accountLogin, #accountLogout)[hidden] { display: none; }
.library-brand, .editor-brand {
  border: 0; background: transparent; color: inherit; cursor: pointer; border-radius: 8px;
}
.editor-brand { padding: 2px 4px; }
.library-brand:hover, .editor-brand:hover { color: var(--accent); }
.quorvox-mark { object-fit: contain; }

/* Совместный холст */
.room-view {
  height: 100dvh; overflow: auto; background: var(--surface-2); color: var(--text);
}
.room-view[hidden], .room-view [hidden] { display: none; }
.room-header, .room-tools {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 10px clamp(10px, 4vw, 34px); background: var(--surface); border-bottom: 1px solid var(--line);
}
.room-header > div { flex: 1 1 170px; }
.room-header h1 { font-size: clamp(18px, 3vw, 26px); margin: 0; overflow-wrap: anywhere; }
.room-header p { margin: 4px 0 0; color: var(--muted); }
.room-header button:not(.library-brand), .room-tools :is(button,select), #roomDialogBody :is(input,button) {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
#roomDialogBody input { width: 100%; }
.room-paper { margin: 10px auto; width: min(calc(100% - 20px), 1360px); }
#roomCanvas {
  display: block; width: 100%; height: auto; aspect-ratio: 1360 / 768;
  border: 1px solid var(--line); border-radius: 10px; touch-action: none;
  background: #fbfaf6;
}
#roomCanvas[data-editable='true'] { cursor: crosshair; }
@media (max-width: 640px) {
  .room-header { gap: 7px; }
  .room-tools { gap: 6px; }
}

.f-study-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.f-study-actions button[hidden], #fAddSolution[hidden], .f-solution[hidden] { display: none; }
.f-solution { padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.f-solution h3 { font-size: 14px; margin: 0 0 6px; }
.f-solution ol { margin: 4px 0 8px; padding-left: 20px; }
.f-solution li { margin: 3px 0; overflow-wrap: anywhere; }
.f-solution p:empty { display: none; }
.f-solution p { color: var(--danger); }
