:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #f1f4f1;
  --ink: #1d2423;
  --muted: #68706e;
  --line: #dfe5df;
  --line-strong: #c7d1ca;
  --blue: #2864d8;
  --blue-soft: #e8f0ff;
  --green: #16845f;
  --green-soft: #e5f5ee;
  --coral: #d4553f;
  --coral-soft: #faebe8;
  --yellow: #a87509;
  --shadow: 0 18px 50px rgba(29, 36, 35, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f8f5 0%, #edf2f4 100%);
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-brand,
.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.auth-brand > div,
.brand-line > div {
  min-width: 0;
}

.brand-logo {
  width: 112px;
  height: 42px;
  display: block;
  object-fit: contain;
  object-position: left center;
  flex: 0 0 auto;
}

.brand-logo.small {
  width: 92px;
  height: 35px;
}

.auth-brand h1,
.graph-toolbar h2,
.insights-head h2,
.empty-state h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.auth-brand p,
.graph-toolbar p,
.insights-head p,
.brand-line span {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.brand-line strong,
.brand-line span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 24px 0 18px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.auth-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 9px 12px;
}

.auth-tabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(29, 36, 35, 0.08);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.password-auth-panel {
  margin-top: 8px;
}

.google-auth-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 48px;
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(29, 36, 35, 0.06);
}

.google-auth-button:hover {
  border-color: rgba(40, 100, 216, 0.35);
  box-shadow: 0 8px 24px rgba(29, 36, 35, 0.08);
}

.google-auth-button span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  color: #2864d8;
  font-weight: 900;
  font-family: Arial, sans-serif;
}

.auth-global-error {
  margin-top: 10px;
  text-align: center;
}

.auth-password-toggle {
  width: fit-content;
  justify-self: center;
  margin: 10px auto 0;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form input,
.search-box input,
.note-title,
.graph-controls select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.auth-form input {
  height: 42px;
  padding: 0 12px;
}

.verification-form {
  margin-top: 18px;
}

.verification-copy {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.verification-copy strong {
  color: var(--ink);
  font-size: 16px;
}

.verification-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.auth-form .code-input {
  height: 50px;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 7px;
}

.auth-secondary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-weight: 700;
  padding: 4px 0;
  cursor: pointer;
}

.text-button:hover {
  color: var(--blue-dark);
}

.auth-form input:focus,
.search-box input:focus,
.note-title:focus,
.graph-controls select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 100, 216, 0.12);
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--coral);
  font-size: 13px;
}

.admin-back-link {
  display: inline-flex;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.admin-back-link:hover {
  color: var(--ink);
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.primary-button {
  background: var(--ink);
  color: #fff;
  padding: 0 14px;
  font-weight: 650;
}

.primary-button:hover {
  background: #303a38;
}

.ghost-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 14px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  padding: 0;
}

.icon-button.light {
  background: rgba(255, 255, 255, 0.92);
}

.app-shell {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  height: 100vh;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #f4f5f2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  flex: 0 0 auto;
  min-height: 62px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-head .brand-line {
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-head-actions,
.insights-head-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
}

.library-tabs {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  align-items: center;
  gap: 3px;
  margin: 2px 12px 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ebeee9;
}

.library-tabs button {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 720;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: inset 0 0 0 1px transparent;
}

.library-tabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(214, 221, 216, 0.9), 0 1px 3px rgba(29, 36, 35, 0.08);
}

.library-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.mobile-nav-button,
.mobile-insights-button,
.mobile-drawer-close,
.mobile-scrim {
  display: none;
}

.app-shell.book-reading-mode .book-topbar .mobile-nav-button {
  width: 34px;
  height: 34px;
  min-height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 23px;
  line-height: 1;
}

.sidebar-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 6px 12px 8px;
}

.sidebar-actions.single {
  grid-template-columns: minmax(0, 1fr);
}

.search-box {
  flex: 0 0 auto;
  padding: 4px 12px 10px;
}

.search-box input {
  height: 36px;
  padding: 0 11px;
  font-size: 14px;
  background: #ffffff;
}

.notes-list,
.books-list,
.review-topics-list,
.admin-users-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 8px 14px;
  scrollbar-width: thin;
}

.note-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.note-row:hover {
  background: #e9ece7;
}

.note-row.active {
  background: #ffffff;
  border-color: var(--line);
  box-shadow: 0 1px 3px rgba(29, 36, 35, 0.06);
}

.note-item {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  display: block;
  color: var(--ink);
  min-width: 0;
  min-height: 36px;
}

.note-item:focus-visible,
.note-delete:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.note-delete {
  width: 26px;
  height: 26px;
  margin-right: 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  opacity: 0;
}

.note-row:hover .note-delete,
.note-row.active .note-delete,
.note-delete:focus-visible {
  opacity: 1;
}

.note-delete:hover {
  background: var(--coral-soft);
  color: var(--coral);
}

.note-delete:disabled {
  cursor: wait;
  opacity: 0.45;
}

.note-item-title {
  display: -webkit-box;
  font-size: 14px;
  line-height: 1.28;
  font-weight: 520;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

.book-library-view {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: clamp(24px, 4vw, 54px);
  background: #ffffff;
}

.book-library-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: clamp(26px, 4vw, 56px);
}

.book-library-actions {
  display: grid;
  grid-template-columns: minmax(220px, 340px) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.book-library-actions input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.book-library-head h2 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(42px, 5vw, 72px);
  line-height: 0.95;
  letter-spacing: 0;
}

.book-library-head p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
}

.book-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: clamp(36px, 5vw, 70px) clamp(24px, 4vw, 54px);
  align-items: start;
}

.book-library-empty {
  grid-column: 1 / -1;
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 18px;
  font-weight: 720;
}

.book-card {
  min-width: 0;
}

.book-card-cover-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  color: inherit;
}

.book-card-cover-button:focus-visible,
.book-card-delete:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 4px;
}

.book-cover {
  position: relative;
  width: min(100%, 230px);
  aspect-ratio: 0.68;
  border-radius: 4px;
  overflow: hidden;
  background: #0a4d99;
  box-shadow:
    0 18px 28px rgba(31, 35, 33, 0.18),
    inset 7px 0 0 rgba(255, 255, 255, 0.18),
    inset 10px 0 18px rgba(0, 0, 0, 0.25);
}

.book-cover img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.book-cover.default {
  padding: 26px 18px 24px 26px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 12%),
    linear-gradient(160deg, #1267bd 0%, #073c80 54%, #04224f 100%);
  color: #ffffff;
}

.book-cover.default::before {
  content: "";
  position: absolute;
  inset: 18px 16px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  pointer-events: none;
}

.book-cover-title {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  font-size: clamp(18px, 1.7vw, 25px);
  line-height: 1.14;
  font-weight: 760;
}

.book-cover-author {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: rgba(255, 255, 255, 0.7);
  font-size: 17px;
  line-height: 1.15;
  font-weight: 720;
}

.book-card-foot {
  width: min(100%, 230px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.book-card-progress-text {
  min-width: 0;
  color: #808783;
  font-size: 14px;
  font-weight: 760;
}

.book-card-progress-text.new {
  justify-self: start;
  padding: 2px 10px;
  border-radius: 999px;
  background: #0d559d;
  color: #ffffff;
  line-height: 1.1;
}

.book-card-delete {
  width: 32px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8c918f;
  display: grid;
  place-items: center;
}

.book-card-delete span {
  position: relative;
  width: 13px;
  height: 14px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 3px 3px;
}

.book-card-delete span::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -5px;
  width: 15px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.book-card-delete span::after {
  content: "";
  position: absolute;
  left: 3px;
  top: -8px;
  width: 5px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.book-card-delete:hover {
  background: var(--coral-soft);
  color: var(--coral);
}

.book-card-progress {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: #e4e9e4;
}

.book-card-progress span {
  display: block;
  height: 100%;
  width: var(--book-progress, 0%);
  border-radius: inherit;
  background: #0d8f61;
}

.notes-group {
  padding: 14px 10px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.notes-empty {
  margin: 8px;
  padding: 12px 10px;
  color: var(--muted);
  font-size: 13px;
}

.review-sidebar-summary {
  margin: 6px 12px 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.review-sidebar-summary strong {
  font-size: 24px;
  line-height: 1;
}

.review-sidebar-summary span {
  color: var(--muted);
  font-size: 13px;
}

.review-topic-item {
  width: 100%;
  min-height: 48px;
  margin: 0 0 5px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 5px;
}

.admin-user-item {
  width: 100%;
  min-height: 48px;
  margin: 0 0 5px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 5px;
}

.admin-user-item:hover,
.admin-user-item.active {
  border-color: var(--line);
  background: var(--surface);
}

.admin-user-item strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.25;
}

.admin-user-item span {
  color: var(--muted);
  font-size: 11px;
}

.review-topic-item:hover,
.review-topic-item.active {
  border-color: var(--line);
  background: var(--surface);
}

.review-topic-item strong {
  font-size: 13px;
  line-height: 1.25;
}

.review-topic-meter {
  height: 6px;
  border-radius: 999px;
  background: #e0e6e1;
  overflow: hidden;
}

.review-topic-meter i {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  background: var(--green);
}

.review-topic-meta {
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 330px;
  overflow: hidden;
}

.editor-pane {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.app-shell.books-view .workspace {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.review-view .workspace {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.admin-view .workspace {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.books-view .editor-pane,
.app-shell.books-view .insights-pane,
.app-shell.review-view .editor-pane,
.app-shell.review-view .book-pane,
.app-shell.review-view .insights-pane,
.app-shell.admin-view .editor-pane,
.app-shell.admin-view .book-pane,
.app-shell.admin-view .review-pane,
.app-shell.admin-view .insights-pane {
  display: none;
}

.app-shell:not(.review-view) .review-pane {
  display: none;
}

.app-shell:not(.admin-view) .admin-pane {
  display: none;
}

.app-shell.books-view.book-reading-mode {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.books-view.book-reading-mode .sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 80;
  display: flex;
  width: min(360px, 88vw);
  height: 100dvh;
  border-right: 1px solid var(--line);
  box-shadow: 18px 0 46px rgba(29, 36, 35, 0.22);
  transform: translateX(-105%);
  transition: transform 0.2s ease;
}

.app-shell.books-view.book-reading-mode.sidebar-open .sidebar {
  transform: translateX(0);
}

.app-shell.books-view.book-reading-mode .mobile-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: rgba(20, 24, 23, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.app-shell.books-view.book-reading-mode.sidebar-open .mobile-scrim {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.book-pane {
  position: relative;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #eef1ec;
  overflow: hidden;
  --book-bg: #ffffff;
  --book-page-bg: #ffffff;
  --book-text: #424846;
  --book-heading: #313735;
  --book-muted: #737b78;
  --book-selection: #cfe0ff;
  --book-font-family: Georgia, "Times New Roman", serif;
  --book-font-size: 21px;
  --book-line-height: 1.48;
  --book-paragraph-gap: 0.64em;
  --book-indent: 1.7em;
  --book-spread-gap: clamp(58px, 7vw, 132px);
}

.review-pane {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8faf7;
}

.review-topbar {
  min-height: 74px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}

.review-topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.review-topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.review-layout {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 360px;
  gap: 0;
}

.review-session {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: clamp(22px, 4vw, 64px);
  overflow: auto;
}

.review-empty {
  width: min(520px, 100%);
  text-align: center;
  color: var(--muted);
}

.review-empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 24px;
}

.review-empty p {
  margin: 0;
  line-height: 1.5;
}

.review-card {
  width: min(720px, 100%);
  min-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: clamp(22px, 3.5vw, 38px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.review-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.review-card h2 {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.18;
}

.review-answer {
  margin-top: auto;
  padding: 18px;
  border-left: 3px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--green-soft);
  color: #26312d;
  font-size: 18px;
  line-height: 1.55;
}

.review-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.review-rating-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.review-rating-buttons button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 640;
}

.review-rating-buttons button:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.review-progress {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: #f1f4f1;
}

.review-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.review-stats-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.review-stats-grid strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.review-stats-grid span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.review-section-head {
  margin: 18px 0 9px;
}

.review-section-head h2 {
  margin: 0;
  color: #5d6663;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.review-completed-topics,
.review-history-list {
  display: grid;
  gap: 8px;
}

.review-completed-topic,
.review-history-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.review-completed-topic strong,
.review-history-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.review-completed-topic small,
.review-history-item small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.admin-pane {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8faf7;
}

.admin-topbar {
  min-height: 74px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  background: var(--surface);
}

.admin-topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.admin-topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  overflow: auto;
  padding: 18px;
}

.admin-card {
  min-width: 0;
  align-self: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-card-head {
  margin-bottom: 16px;
}

.admin-card-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.admin-card-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.admin-create-user {
  display: grid;
  gap: 12px;
}

.admin-create-user label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.admin-create-user input,
.admin-create-user select {
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.admin-users-card {
  min-height: min(620px, calc(100dvh - 112px));
}

.admin-users-table {
  display: grid;
  gap: 10px;
}

.admin-user-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(260px, 1.05fr) minmax(360px, 1.15fr) minmax(260px, 0.8fr);
  grid-template-areas:
    "main stats logins"
    "access access access";
  gap: 14px 18px;
  align-items: start;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.admin-user-main {
  grid-area: main;
  min-width: 0;
}

.admin-user-main strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.25;
}

.admin-user-main span,
.admin-user-main small,
.admin-user-logins span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.admin-user-main small {
  margin-top: 6px;
  color: var(--blue);
  font-weight: 700;
}

.admin-user-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 6px;
}

.admin-user-stats span {
  min-width: 0;
  padding: 8px;
  border-radius: 6px;
  background: #eef2ed;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.admin-user-stats b {
  display: block;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.1;
}

.admin-user-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.admin-user-access {
  grid-area: access;
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) minmax(150px, 220px) minmax(120px, 150px);
  gap: 10px;
  align-items: end;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.admin-user-access label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.admin-user-access input,
.admin-user-access select {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.admin-user-access button {
  align-self: end;
  min-height: 34px;
  white-space: nowrap;
}

.admin-user-logins {
  grid-area: logins;
  align-self: start;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding-top: 2px;
}

.standalone-admin {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8faf7;
}

.admin-page-header {
  flex: 0 0 auto;
  min-height: 66px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.admin-page-header .brand-line {
  min-width: 0;
}

.admin-page-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-app-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.admin-page .admin-page-pane {
  height: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.admin-page .admin-topbar {
  grid-template-columns: minmax(0, 1fr);
}

.admin-users-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.review-reminder-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(29, 36, 35, 0.36);
}

.review-reminder-card {
  position: relative;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.review-reminder-card .icon-button {
  position: absolute;
  top: 10px;
  right: 10px;
}

.review-reminder-card h2 {
  margin: 0 42px 8px 0;
  font-size: 24px;
}

.review-reminder-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.review-reminder-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.editor-topbar {
  height: 74px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.book-topbar {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 30;
  width: min(1120px, calc(100vw - 34px));
  min-height: 58px;
  padding: 9px 12px;
  border: 1px solid rgba(199, 209, 202, 0.86);
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 38px rgba(29, 36, 35, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(12px);
}

.app-shell.book-controls-visible .book-topbar,
.book-topbar:focus-within,
.book-topbar:hover {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.app-shell.book-controls-hidden .book-topbar {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translate(-50%, -10px) !important;
}

.book-title-block {
  min-width: 0;
}

.book-title-block h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 760;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-title-block p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-actions .active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

#bookHideControlsButton {
  color: var(--muted);
}

#bookHideControlsButton:hover {
  color: var(--ink);
}

.book-actions button:disabled,
.book-selection-bar button:disabled {
  cursor: default;
  opacity: 0.45;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dictation-button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 620;
}

.dictation-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.dictation-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.dictation-button.active {
  border-color: #dc7767;
  background: var(--coral-soft);
  color: #a83929;
}

.dictation-mark {
  position: relative;
  width: 9px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 6px;
}

.dictation-mark::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 11px;
  height: 7px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 7px 7px;
  transform: translateX(-50%);
}

.dictation-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 2px;
  height: 4px;
  background: currentColor;
  transform: translateX(-50%);
}

.dictation-button.active .dictation-mark {
  animation: dictation-pulse 1.15s ease-in-out infinite;
}

@keyframes dictation-pulse {
  50% {
    opacity: 0.45;
  }
}

.note-title {
  height: 42px;
  border-color: transparent;
  padding: 0;
  font-size: 24px;
  font-weight: 760;
  background: transparent;
}

.note-title:focus {
  border-color: transparent;
  box-shadow: none;
}

.save-state {
  color: var(--muted);
  font-size: 13px;
  min-width: 86px;
  text-align: right;
}

.save-state.saving {
  color: var(--yellow);
}

.save-state.error {
  color: var(--coral);
}

.blocks-editor {
  flex: 1;
  overflow: auto;
  padding: 34px 9vw 90px;
}

.book-empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.book-empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
}

.book-empty-state p {
  max-width: 340px;
  margin: 0;
  line-height: 1.45;
}

.book-reader-shell {
  position: absolute;
  inset: 0;
  min-height: 0;
  display: block;
  background: var(--book-bg);
  overflow: hidden;
}

.book-toc-panel {
  position: absolute;
  top: 86px;
  bottom: 86px;
  left: 16px;
  z-index: 25;
  width: min(330px, calc(100vw - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(247, 248, 245, 0.97);
  padding: 16px 12px 18px;
  box-shadow: 0 16px 42px rgba(29, 36, 35, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(10px);
}

.app-shell.book-toc-open .book-toc-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.book-settings-panel {
  position: absolute;
  top: 86px;
  right: 16px;
  z-index: 28;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 172px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(247, 248, 245, 0.98);
  box-shadow: 0 18px 48px rgba(29, 36, 35, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(12px);
}

.app-shell.book-settings-open .book-settings-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.book-setting-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.book-setting-section:last-child {
  border-bottom: 0;
}

.book-setting-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.book-font-scale {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.book-font-scale strong {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.book-setting-button,
.book-segmented button,
.book-font-list button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.book-setting-button:hover,
.book-segmented button:hover,
.book-font-list button:hover,
.book-theme-option:hover {
  border-color: var(--line-strong);
}

.book-setting-button .small-a {
  font-size: 22px;
}

.book-setting-button .large-a {
  font-size: 34px;
  line-height: 1;
}

.book-segmented {
  display: grid;
  gap: 8px;
}

.book-segmented.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.book-segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.book-segmented button.active,
.book-font-list button.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.density-lines,
.align-icon {
  width: 42px;
  height: 26px;
  display: block;
  margin: 0 auto;
  background:
    linear-gradient(currentColor, currentColor) 0 4px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 12px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 20px / 100% 3px no-repeat;
  color: currentColor;
  opacity: 0.72;
}

.density-lines.compact {
  height: 20px;
  background:
    linear-gradient(currentColor, currentColor) 0 3px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 9px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 15px / 100% 3px no-repeat;
}

.density-lines.airy {
  height: 30px;
  background:
    linear-gradient(currentColor, currentColor) 0 2px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 14px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 26px / 100% 3px no-repeat;
}

.align-icon.left {
  width: 34px;
  background:
    linear-gradient(currentColor, currentColor) 0 4px / 72% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 12px / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) 0 20px / 58% 3px no-repeat;
}

.align-icon.justify {
  width: 34px;
}

.book-theme-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.book-theme-option {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 680;
}

.book-theme-option.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(40, 100, 216, 0.14);
}

.theme-white {
  background: #fff;
  color: #252b29;
}

.theme-sepia {
  background: #f6eed9;
  color: #71503a;
}

.theme-gray {
  background: #575757;
  color: #f4f4f4;
}

.theme-black {
  background: #050505;
  color: #f4f4f4;
}

.book-switch {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0;
  font-size: 15px;
  text-align: left;
}

.book-switch:last-child {
  border-bottom: 0;
}

.book-switch i {
  position: relative;
  width: 42px;
  height: 24px;
  border: 2px solid #9da5a1;
  border-radius: 999px;
  background: transparent;
  flex: 0 0 auto;
}

.book-switch i::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #9da5a1;
  transition: transform 0.16s ease, background 0.16s ease;
}

.book-switch.active i {
  border-color: var(--ink);
}

.book-switch.active i::before {
  background: var(--ink);
  transform: translateX(18px);
}

.book-font-list {
  display: grid;
  gap: 8px;
}

.book-font-list button {
  font-size: 20px;
}

.book-toc-head {
  padding: 0 6px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.book-toc-head h2 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

.book-toc {
  display: grid;
  gap: 3px;
}

.book-toc-item {
  width: 100%;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 7px 8px;
  text-align: left;
}

.book-toc-item:hover {
  background: #ecefeb;
}

.book-toc-item.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.book-toc-item span {
  display: block;
  font-size: 13px;
  line-height: 1.28;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.book-toc-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.book-toc-item.level-1 {
  padding-left: 18px;
}

.book-toc-item.level-2,
.book-toc-item.level-3,
.book-toc-item.level-4 {
  padding-left: 28px;
}

.book-reading-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(24px, 3.4vw, 54px);
  overflow: hidden;
}

.book-reader {
  width: min(1720px, calc(100vw - clamp(42px, 5vw, 90px)));
  height: min(1040px, calc(100dvh - clamp(42px, 5vw, 90px)));
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--book-page-bg);
  box-shadow: none;
  outline: none;
  color: var(--book-text);
  font-family: var(--book-font-family);
  font-size: var(--book-font-size);
  line-height: var(--book-line-height);
  user-select: text;
  transition: width 0.18s ease, height 0.18s ease;
}

.book-measure-reader {
  position: absolute;
  inset: auto auto 0 50%;
  z-index: -1;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%);
  transition: none;
}

.book-spread {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--book-spread-gap);
}

.book-page {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: clamp(42px, 6vh, 84px) clamp(14px, 2vw, 34px) 40px;
  border: 0;
  background: var(--book-page-bg);
  box-shadow: none;
  scrollbar-width: none;
}

.book-page::-webkit-scrollbar {
  display: none;
}

.book-pane[data-book-scroll="on"] .book-reader {
  overflow: auto;
}

.book-pane[data-book-scroll="on"] .book-spread {
  height: auto;
  min-height: 100%;
}

.book-pane[data-book-scroll="on"] .book-page {
  height: auto;
  min-height: 100%;
  overflow: visible;
}

.book-pane[data-book-format="pdf"] .book-page {
  padding: clamp(3px, 0.7vh, 8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-pane[data-book-format="pdf"] .book-reading-area {
  padding: clamp(4px, 0.8vw, 10px);
}

.book-pane[data-book-format="pdf"] .book-reader {
  width: min(2040px, calc(100vw - clamp(8px, 1.2vw, 18px)));
  height: min(1280px, calc(100dvh - clamp(8px, 1.2vw, 18px)));
}

.book-pane[data-book-format="pdf"] .book-spread {
  gap: clamp(8px, 1.2vw, 18px);
}

.book-pdf-page-frame {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-pdf-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  box-shadow: 0 10px 30px rgba(31, 35, 33, 0.12);
}

.book-page.left {
  border-radius: 0;
}

.book-page.right {
  border-radius: 0;
}

.book-page.empty {
  visibility: hidden;
}

.book-page-heading {
  margin-bottom: 10px;
  padding-bottom: 2px;
  border-bottom: 0;
}

.book-page-heading h2 {
  margin: 0;
  color: var(--book-heading);
  font-size: 24px;
  line-height: 1.22;
  text-align: center;
}

.book-page-subtitle {
  margin: 3px 0 0;
  color: var(--book-muted);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  text-align: center;
}

.book-page.chapter-start .book-page-heading {
  margin-top: 0;
  margin-bottom: clamp(12px, 1.6vh, 20px);
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--book-muted) 16%, transparent);
}

.book-page.chapter-start .book-page-heading h2 {
  font-size: clamp(22px, 1.7vw, 30px);
  line-height: 1.16;
}

.book-page.chapter-start .book-page-subtitle {
  margin-top: 10px;
}

.book-page.chapter-continuation .book-page-heading {
  display: none;
}

.book-page.chapter-continuation .book-page-heading h2 {
  color: var(--book-muted);
  font-size: 16px;
  font-weight: 650;
}

.book-reader p {
  max-width: 100%;
  margin: 0 0 var(--book-paragraph-gap);
  text-align: left;
  text-indent: var(--book-indent);
}

.book-page-heading + p,
.book-image + p {
  text-indent: 0;
}

.book-image {
  margin: 20px auto 22px;
  height: min(42vh, 420px);
  max-width: 100%;
  text-indent: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-image img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  margin: 0 auto;
}

.book-page.image-page {
  display: flex;
  flex-direction: column;
}

.book-page.image-page .book-image {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto 0;
}

.book-page.image-page .book-image img {
  max-width: 100%;
  max-height: 100%;
}

.book-reader::selection,
.book-reader *::selection {
  background: var(--book-selection);
}

.book-pane[data-book-align="justify"] .book-reader p {
  text-align: justify;
  text-justify: inter-word;
}

.book-pane[data-book-hyphenation="on"] .book-reader p {
  hyphens: auto;
  overflow-wrap: break-word;
}

.book-bionic-prefix {
  color: var(--book-heading);
  font-weight: 790;
}

.book-pane[data-book-theme="black"] {
  background: #050505;
}

.book-pane[data-book-theme="gray"] {
  background: #e4e6e4;
}

.book-pane[data-book-theme="sepia"] {
  background: #f5eedf;
}

.book-pane[data-book-theme="black"] .book-topbar,
.book-pane[data-book-theme="black"] .book-pagebar,
.book-pane[data-book-theme="black"] .book-settings-panel {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(24, 24, 23, 0.94);
  color: #f2f2ed;
}

.book-pane[data-book-theme="black"] .book-title-block p,
.book-pane[data-book-theme="black"] .book-setting-label,
.book-pane[data-book-theme="black"] .book-page-status span,
.book-pane[data-book-theme="black"] .book-font-scale strong {
  color: #a8a8a0;
}

.book-pane[data-book-theme="black"] .ghost-button,
.book-pane[data-book-theme="black"] .icon-button,
.book-pane[data-book-theme="black"] .book-setting-button,
.book-pane[data-book-theme="black"] .book-segmented button,
.book-pane[data-book-theme="black"] .book-font-list button {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #f2f2ed;
}

.book-pane[data-book-theme="black"] .book-switch {
  color: #f2f2ed;
  border-color: rgba(255, 255, 255, 0.14);
}

.book-pagebar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 30;
  width: min(760px, calc(100vw - 38px));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(199, 209, 202, 0.82);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 32px rgba(29, 36, 35, 0.14);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(12px);
}

.app-shell.book-controls-visible .book-pagebar,
.book-pagebar:focus-within,
.book-pagebar:hover {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.app-shell.book-controls-hidden .book-pagebar {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translate(-50%, 10px) !important;
}

.book-page-status {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.book-page-status span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.book-page-status input {
  width: 100%;
  accent-color: var(--blue);
}

.book-turn-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 12;
  width: clamp(38px, 5vw, 78px);
  border: 0;
  padding: 0;
  background: transparent;
  opacity: 0;
}

.book-turn-zone.left {
  left: 0;
}

.book-turn-zone.right {
  right: 0;
}

@media (max-width: 859px) {
  .book-library-view {
    padding: 24px 16px 42px;
  }

  .book-library-head {
    align-items: start;
    flex-direction: column;
    margin-bottom: 28px;
  }

  .book-library-actions {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }

  .book-library-head h2 {
    font-size: 44px;
  }

  .book-library-grid {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: 30px 18px;
  }

  .book-cover,
  .book-card-foot {
    width: min(100%, 178px);
  }

  .book-cover.default {
    padding: 22px 14px 20px 22px;
  }

  .book-cover-title {
    font-size: 17px;
  }

  .book-cover-author {
    font-size: 14px;
  }

  .book-spread {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .book-page.right {
    display: none;
  }

  .book-reader {
    width: min(680px, calc(100vw - 28px));
    height: calc(100dvh - 28px);
  }

  .book-pane[data-book-format="pdf"] .book-reader {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
  }

  .book-pane[data-book-format="pdf"] .book-reading-area {
    padding: 6px;
  }

  .book-page.left {
    border-radius: 0;
  }

  .book-turn-zone {
    width: 42px;
  }
}

.document-editor {
  outline: none;
  font-size: 18px;
  line-height: 1.62;
  color: var(--ink);
  caret-color: var(--blue);
}

.document-editor:empty::before {
  content: "Пишите здесь";
  color: #9aa29f;
}

.document-editor h1,
.document-editor h2,
.document-editor h3,
.document-editor p,
.document-editor ol,
.document-editor ul {
  max-width: 760px;
}

.document-editor h1,
.document-editor h2,
.document-editor h3 {
  margin: 18px 0 12px;
  font-size: 32px;
  line-height: 1.18;
  font-weight: 780;
}

.document-editor h1:first-child,
.document-editor h2:first-child,
.document-editor h3:first-child,
.document-editor p:first-child,
.document-editor ol:first-child,
.document-editor ul:first-child {
  margin-top: 0;
}

.document-editor p {
  margin: 8px 0;
  min-height: 30px;
}

.document-editor ol,
.document-editor ul {
  margin: 8px 0 8px 24px;
  padding-left: 22px;
}

.document-editor li {
  margin: 5px 0;
  padding-left: 4px;
}

.document-editor .review-source-highlight {
  border-radius: 7px;
  background: rgba(255, 222, 112, 0.48);
  box-shadow: 0 0 0 7px rgba(255, 222, 112, 0.24);
  transition: background 0.35s ease, box-shadow 0.35s ease;
}

.document-editor p[data-type="task"] {
  position: relative;
  padding-left: 30px;
}

.document-editor p[data-type="task"]::before {
  content: "☐";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--green);
}

.document-editor p[data-type="task"].checked {
  color: var(--muted);
  text-decoration: line-through;
}

.document-editor p[data-type="task"].checked::before {
  content: "☑";
}

.note-image-block {
  position: relative;
  margin: 14px 0;
  width: min(100%, 760px);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

.note-image-block img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
}

.note-image-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: rgba(29, 36, 35, 0.76);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.note-image-block:hover .note-image-delete,
.note-image-delete:focus {
  opacity: 1;
}

@media (hover: none) {
  .note-image-delete {
    opacity: 0.85;
  }
}

.format-bar {
  position: fixed;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  background: #1d2423;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(29, 36, 35, 0.22);
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.book-selection-bar {
  position: fixed;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px;
  background: #1d2423;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(29, 36, 35, 0.22);
}

.book-selection-bar button {
  min-width: 34px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 700;
}

.book-selection-bar button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.book-selection-bar #bookSelectionExplainButton {
  width: 32px;
  padding: 0;
  color: #bfffe1;
  background: rgba(72, 210, 151, 0.18);
  font-size: 16px;
}

.format-bar::-webkit-scrollbar {
  display: none;
}

.format-bar button {
  width: 32px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  font-size: 13px;
}

.format-bar button:hover,
.format-bar button.active {
  background: rgba(255, 255, 255, 0.16);
}

.format-bar button:disabled {
  cursor: default;
  opacity: 0.32;
  background: transparent;
}

.format-bar span {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.18);
  margin: 0 2px;
}

.format-bar #explainTermButton {
  background: rgba(72, 210, 151, 0.18);
  color: #bfffe1;
  font-size: 16px;
  font-weight: 750;
}

.format-bar #explainTermButton:hover {
  background: rgba(72, 210, 151, 0.32);
}

.term-popover {
  position: fixed;
  z-index: 45;
  width: min(390px, calc(100vw - 24px));
  max-height: min(560px, calc(100vh - 24px));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(29, 36, 35, 0.2);
}

.term-popover-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.term-popover-head span {
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.term-popover-head h3 {
  margin: 3px 0 0;
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.term-popover-head button {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 20px;
}

.term-popover-head button:hover {
  color: var(--ink);
}

.term-popover-body {
  padding: 4px 14px 14px;
}

.term-popover-body section {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.term-popover-body section:last-child {
  border-bottom: 0;
}

.term-popover-body h4 {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.term-popover-body p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.term-related {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.term-related span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
}

.term-popover-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

.term-popover-actions button {
  gap: 6px;
}

.term-loading,
.term-error {
  padding: 14px 0;
  color: var(--muted);
}

.term-notice {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid #d3a42d;
  background: #fff8df;
  color: #66531f;
  font-size: 13px;
  line-height: 1.45;
}

.term-error {
  color: var(--coral);
}

.insights-pane {
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #fbfcfa;
  padding: 18px;
}

.insights-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.insight-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.insight-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0;
}

.topic-list,
.suggested-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.topic-chip,
.suggestion-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}

.suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-align: left;
}

.suggestion-chip > span:last-child {
  display: grid;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 15px;
  line-height: 1;
}

.suggestion-chip:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.suggestion-chip.loading {
  cursor: wait;
  opacity: 0.65;
}

.topic-chip {
  display: grid;
  gap: 2px;
  border-radius: var(--radius);
}

.topic-chip small {
  color: var(--muted);
  font-size: 10px;
}

.topic-chip:nth-child(3n + 1) {
  background: var(--green-soft);
  border-color: #c5eadb;
}

.topic-chip:nth-child(3n + 2) {
  background: var(--blue-soft);
  border-color: #c8dafd;
}

.topic-chip:nth-child(3n) {
  background: var(--coral-soft);
  border-color: #f0c9c1;
}

.summary-text,
.empty-line {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.related-list {
  display: grid;
  gap: 9px;
}

.manual-links-list {
  display: grid;
  gap: 7px;
}

.manual-link-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.manual-link-item > button:first-child {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 9px;
  text-align: left;
}

.manual-link-item > button:first-child:hover {
  background: var(--green-soft);
}

.manual-link-direction {
  color: var(--green);
  font-size: 18px;
  font-weight: 700;
}

.manual-link-item strong,
.manual-link-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manual-link-item strong {
  white-space: nowrap;
  font-size: 13px;
}

.manual-link-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.manual-link-delete {
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}

.manual-link-delete:hover {
  background: var(--coral-soft);
  color: var(--coral);
}

.related-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
  text-align: left;
}

.related-item:hover {
  border-color: var(--blue);
}

.related-item strong {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 3px;
}

.related-item strong small {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 10px;
  font-weight: 650;
}

.related-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.related-item .related-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.related-item .related-topics span {
  display: inline-flex;
  max-width: 100%;
  padding: 3px 6px;
  border: 1px solid #d9d4eb;
  border-radius: 5px;
  background: #f5f2fc;
  color: #625878;
  font-size: 10px;
  font-weight: 650;
  line-height: 1.2;
}

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 28px;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--ink);
}

.graph-window {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #1e1e1e;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.graph-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 64px;
  padding: 10px 12px;
  border-bottom: 1px solid #363636;
  background: #242424;
  color: #dcdae3;
}

.graph-toolbar-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.graph-toolbar h2 {
  flex: 0 0 auto;
  font-size: 18px;
}

.graph-mode-switch {
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  background: #1e1e1e;
}

.graph-mode-switch button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #92909a;
  font-size: 12px;
}

.graph-mode-switch button:hover {
  color: #dcdae3;
}

.graph-mode-switch button.active {
  background: #3a354c;
  color: #ded6ff;
}

#graphSearch {
  flex: 0 1 220px;
  min-width: 140px;
  width: min(220px, 24vw);
  height: 34px;
  padding: 0 10px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  outline: 0;
  background: #1e1e1e;
  color: #dcdae3;
  font-size: 12px;
}

#graphSearch::placeholder {
  color: #77747f;
}

#graphSearch:focus {
  border-color: #786bb5;
  box-shadow: 0 0 0 2px rgba(120, 107, 181, 0.2);
}

.graph-controls {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.graph-controls select {
  flex: 0 0 180px;
  width: 180px;
  height: 34px;
  min-width: 0;
  padding: 0 9px;
  background: #1e1e1e;
  border-color: #3a3a3a;
  color: #c9c7d0;
  font-size: 12px;
}

.graph-stats {
  color: #85828d;
  font-size: 12px;
  white-space: nowrap;
}

.graph-reset {
  min-height: 34px;
  background: #2b2b2b;
  border-color: #3a3a3a;
  color: #c9c7d0;
}

.graph-reset:hover {
  background: #353535;
  border-color: #55515e;
}

.graph-delete-link {
  background: #2a2224;
  border-color: rgba(244, 108, 86, 0.3);
  color: #ffc8bf;
}

.graph-delete-link:hover:not(:disabled) {
  background: #472a2b;
  border-color: rgba(244, 108, 86, 0.68);
}

.graph-delete-link:disabled {
  cursor: default;
  opacity: 0.34;
}

.graph-controls .icon-button.light {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  background: #2b2b2b;
  border-color: #3a3a3a;
  color: #c9c7d0;
}

.graph-controls .icon-button.light:hover {
  background: #353535;
  border-color: #55515e;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: move;
}

.graph-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.graph-legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 13px;
  color: #77747f;
  font-size: 11px;
  pointer-events: none;
}

.graph-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.graph-legend i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9a9b3;
}

.graph-legend i.root {
  width: 9px;
  height: 9px;
  background: #b69cff;
}

.graph-legend i.cross {
  width: 18px;
  height: 2px;
  border-radius: 0;
  background: repeating-linear-gradient(90deg, #8f86b5 0 4px, transparent 4px 7px);
}

.graph-hint {
  position: fixed;
  left: 14px;
  bottom: 14px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 6px 8px;
  color: #88858f;
  font-size: 11px;
  pointer-events: none;
}

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .insights-pane {
    display: none;
  }

  .blocks-editor {
    padding-inline: 7vw;
  }

  .graph-toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .graph-controls {
    justify-content: flex-start;
  }
}

@media (max-width: 1200px) {
  .app-shell {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    height: 100dvh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(340px, 88vw);
    height: 100dvh;
    min-height: 0;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 18px 0 46px rgba(29, 36, 35, 0.2);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-scrim {
    position: fixed;
    inset: 0;
    z-index: 70;
    width: 100%;
    height: 100%;
    border: 0;
    padding: 0;
    background: rgba(20, 24, 23, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .app-shell.sidebar-open .mobile-scrim,
  .app-shell.insights-open .mobile-scrim {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-nav-button,
  .mobile-insights-button,
  .mobile-drawer-close {
    width: 34px;
    height: 34px;
    min-height: 34px;
    flex: 0 0 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    display: grid;
    place-items: center;
    padding: 0;
  }

  .mobile-nav-button {
    font-size: 23px;
    line-height: 1;
  }

  .mobile-insights-button {
    width: auto;
    flex-basis: auto;
    padding: 0 9px;
    font-size: 11px;
    font-weight: 760;
  }

  .mobile-drawer-close {
    font-size: 20px;
  }

  .mobile-nav-button:hover,
  .mobile-insights-button:hover,
  .mobile-drawer-close:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
  }

  .notes-list {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 10px;
  }

  .note-row,
  .note-item {
    min-width: 0;
  }

  .note-delete {
    opacity: 1;
  }

  .editor-pane {
    height: 100dvh;
    min-height: 0;
  }

  .editor-topbar {
    height: 68px;
    padding: 12px 16px;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
  }

  .book-topbar {
    min-height: 68px;
    padding: 12px 16px;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
  }

  .review-topbar {
    min-height: 68px;
    padding: 12px 16px;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
  }

  .admin-topbar {
    min-height: 68px;
    padding: 12px 16px;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
  }

  .review-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px;
  }

  .admin-user-row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "main"
      "stats"
      "access"
      "logins";
    align-items: stretch;
  }

  .admin-user-actions {
    justify-content: space-between;
  }

  .admin-user-access {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .review-session {
    min-height: 54dvh;
    padding: clamp(18px, 4vw, 34px);
  }

  .review-progress {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .book-actions {
    gap: 6px;
  }

  .book-actions .icon-button {
    width: 34px;
    height: 34px;
    min-height: 34px;
    font-size: 13px;
  }

  .book-settings-panel {
    top: 78px;
    right: 12px;
    width: min(380px, calc(100vw - 24px));
    max-height: calc(100dvh - 96px);
  }

  .editor-actions {
    gap: 8px;
  }

  .dictation-button {
    width: 34px;
    padding: 0;
    justify-content: center;
  }

  .dictation-label {
    display: none;
  }

  .note-title {
    min-width: 0;
    font-size: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .blocks-editor {
    padding: 28px clamp(20px, 7vw, 58px) 100px;
  }

  .book-reading-area {
    padding: clamp(16px, 2.5vw, 28px);
  }

  .book-reader {
    width: min(1260px, calc(100vw - 38px));
    height: min(820px, calc(100dvh - 38px));
  }

  .book-pane[data-book-format="pdf"] .book-reader {
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
  }

  .book-pane[data-book-format="pdf"] .book-reading-area {
    padding: 8px;
  }

  .block-row.heading .block-content {
    font-size: 24px;
  }

  .workspace {
    width: 100%;
    height: 100dvh;
    min-height: 0;
  }

  .book-pane {
    height: 100dvh;
  }

  .insights-pane {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 80;
    display: block;
    width: min(370px, 92vw);
    height: 100dvh;
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 46px rgba(29, 36, 35, 0.2);
    transform: translateX(105%);
    transition: transform 0.2s ease;
  }

  .app-shell.insights-open .insights-pane {
    transform: translateX(0);
  }

  .graph-toolbar {
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr);
  }

  .graph-toolbar-main {
    flex-wrap: wrap;
  }

  #graphSearch {
    flex: 1 1 180px;
    width: auto;
  }

  .graph-controls {
    flex-wrap: wrap;
  }

  .graph-controls select {
    flex: 1 1 180px;
    width: auto;
  }
}

@media (max-width: 500px) {
  .sidebar {
    width: min(340px, 94vw);
  }

  .editor-topbar {
    height: 64px;
    padding-inline: 12px;
    gap: 8px;
  }

  .book-topbar {
    min-height: 64px;
    padding-inline: 12px;
    gap: 8px;
  }

  #bookToggleTocButton {
    width: 34px;
    min-width: 34px;
    padding: 0;
    font-size: 0;
  }

  #bookToggleTocButton::before {
    content: "☰";
    font-size: 18px;
    line-height: 1;
  }

  .editor-actions {
    gap: 6px;
  }

  .note-title {
    font-size: 18px;
  }

  .book-title-block h1 {
    font-size: 18px;
  }

  .review-topbar h1 {
    font-size: 18px;
  }

  .review-topbar p,
  .admin-topbar p {
    font-size: 11px;
  }

  .review-topbar .primary-button {
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .review-card {
    min-height: 320px;
  }

  .review-card h2 {
    font-size: 25px;
  }

  .review-answer {
    font-size: 16px;
  }

  .review-stats-grid {
    grid-template-columns: 1fr;
  }

  .admin-topbar h1 {
    font-size: 18px;
  }

  .admin-user-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-user-access {
    grid-template-columns: minmax(0, 1fr);
  }

  .book-title-block p {
    font-size: 11px;
  }

  #bookCreateNoteButton {
    display: none;
  }

  .book-settings-panel {
    top: 74px;
    right: 10px;
    width: calc(100vw - 20px);
  }

  .book-theme-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .book-font-list button {
    min-height: 40px;
    font-size: 18px;
  }

  .save-state {
    min-width: 58px;
    max-width: 58px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
  }

  .blocks-editor {
    padding: 22px 16px 96px;
  }

  .book-toc-panel {
    top: 72px;
    bottom: 72px;
    left: 10px;
    width: calc(100vw - 20px);
    padding: 10px;
  }

  .book-toc {
    display: grid;
    gap: 6px;
  }

  .book-toc-item {
    min-height: 32px;
  }

  .book-reading-area {
    padding: 10px;
  }

  .book-reader {
    width: calc(100vw - 20px);
    height: 100%;
    font-size: 17px;
    line-height: 1.54;
  }

  .book-pane[data-book-format="pdf"] .book-reader {
    width: calc(100vw - 8px);
    height: calc(100dvh - 8px);
  }

  .book-pane[data-book-format="pdf"] .book-reading-area {
    padding: 4px;
  }

  .book-pane[data-book-format="pdf"] .book-page {
    padding: 4px;
  }

  .book-spread {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .book-page.right {
    display: none;
  }

  .book-page {
    padding: 34px 24px;
    border-radius: 0;
  }

  .book-image {
    height: min(34vh, 300px);
  }

  .book-page-heading h2 {
    font-size: 20px;
  }

  .book-page.chapter-start .book-page-heading {
    margin-top: 0;
    margin-bottom: 14px;
  }

  .book-page.chapter-start .book-page-heading h2 {
    font-size: 23px;
  }

  .book-page.chapter-continuation .book-page-heading h2 {
    font-size: 15px;
  }

  .book-pagebar {
    grid-template-columns: 72px minmax(0, 1fr) 72px;
    gap: 8px;
  }

  .document-editor {
    font-size: 16px;
  }

  .document-editor h1,
  .document-editor h2,
  .document-editor h3 {
    font-size: 25px;
  }

  .format-bar {
    border-radius: 6px;
  }

  .term-popover {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }
}
