:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --panel: #ffffff;
  --panel-2: #eef4f6;
  --ink: #17211c;
  --muted: #637069;
  --line: #d9e1dc;
  --brand: #0e7c66;
  --brand-dark: #075342;
  --accent: #d9853b;
  --blue: #2f66a5;
  --shadow: 0 18px 50px rgba(30, 46, 39, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.library-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
  background: #0f211c;
  color: #eef8f3;
  transition: width 180ms ease, padding 180ms ease, transform 180ms ease;
}

.app-shell.library-collapsed {
  grid-template-columns: 76px 1fr;
}

.app-shell.library-collapsed .library-rail {
  padding: 18px 12px;
}

.app-shell.library-collapsed .brand-row div:last-child,
.app-shell.library-collapsed .nav-item span:last-child,
.app-shell.library-collapsed .library-section {
  display: none;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-row strong,
.brand-row span {
  display: block;
}

.brand-row strong {
  white-space: nowrap;
}

.brand-row span {
  color: #9fb8ad;
  font-size: 12px;
  line-height: 1.25;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 800;
}

.main-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c7d8d1;
  cursor: pointer;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-item span:first-child {
  display: grid;
  place-items: center;
  width: 24px;
  min-width: 24px;
}

.library-section {
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

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

.load-book-row button {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #e6f4ef;
  color: var(--brand-dark);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.load-book-row button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.section-title {
  color: #9fb8ad;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.book-card {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 76px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #edf8f4;
  cursor: pointer;
  text-align: left;
}

.book-card span {
  color: #a8bbb3;
  font-size: 12px;
}

.book-card.active {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(14, 124, 102, 0.44);
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
}

.page-title {
  min-width: 0;
  margin-right: auto;
}

.page-title strong,
.page-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title span {
  color: var(--muted);
  font-size: 13px;
}

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

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(280px, 24vw);
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.icon-button,
.page-controls button,
.reading-tools button,
.page-fit-tools button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.pill {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.pill.active {
  border-color: rgba(14, 124, 102, 0.24);
  background: #e6f4ef;
  color: var(--brand-dark);
  font-weight: 700;
}

.study-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(380px, 515px);
  align-items: start;
  gap: 16px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.app-shell.study-collapsed .study-grid {
  grid-template-columns: 1fr 52px;
}

.source-panel,
.study-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.source-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  align-self: stretch;
  overflow: hidden;
}

.source-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: #fbfcf9;
  overflow-x: auto;
}

.source-toolbar > div:first-child {
  min-width: 104px;
}

.source-toolbar span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.page-controls {
  display: flex;
  gap: 6px;
}

.reading-tools,
.page-controls,
.page-fit-tools {
  display: flex;
  gap: 6px;
}

.reading-tools {
  margin-left: auto;
}

.reading-tools button,
.page-fit-tools button {
  width: auto;
  min-width: 46px;
  height: 32px;
  padding: 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.page-controls button,
.page-fit-tools button {
  min-width: 34px;
  height: 32px;
  font-size: 11px;
}

.reading-tools button.active,
.page-fit-tools button.active {
  border-color: rgba(14, 124, 102, 0.24);
  background: #e6f4ef;
  color: var(--brand-dark);
}

.page-fit-tools button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.highlight-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcf9;
}

.highlight-swatches {
  display: flex;
  gap: 5px;
}

.highlight-swatches button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}

.highlight-swatches button.active {
  border-color: #24352d;
}

.highlight-swatches .yellow {
  background: #ffe48a;
}

.highlight-swatches .green {
  background: #bcefd0;
}

.highlight-swatches .blue {
  background: #bfe3ff;
}

.highlight-swatches .pink {
  background: #ffcfe0;
}

.highlight-tools input {
  flex: 1;
  min-width: 120px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  outline: 0;
}

.highlight-tools > button {
  min-width: 58px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.document-page {
  align-self: stretch;
  width: min(1040px, 100%);
  height: auto;
  min-height: 0;
  margin: 0 auto 12px;
  padding: clamp(24px, 4vw, 52px);
  overflow: auto;
  border: 1px solid #e6e8e3;
  border-radius: 4px;
  background: #fffefa;
  box-shadow: 0 8px 30px rgba(34, 39, 35, 0.08);
}

.document-page[data-fit="wide"] {
  width: min(1120px, 100%);
  padding: clamp(20px, 3.5vw, 44px);
}

.page-kicker {
  color: var(--accent);
  font-size: calc(13px * var(--reading-text-scale, 1));
  font-weight: 800;
  text-transform: uppercase;
}

.document-page h1 {
  margin: 8px 0 20px;
  font-size: calc(clamp(28px, 4vw, 48px) * var(--reading-text-scale, 1));
  line-height: 1.06;
}

.document-page p {
  max-width: 64ch;
  color: #29342e;
  font-size: calc(17px * var(--reading-text-scale, 1));
  line-height: 1.72;
}

.document-page mark {
  position: relative;
  padding: 0 2px;
  border-radius: 3px;
  color: inherit;
}

.document-page mark.highlight-yellow {
  background: #ffe48a;
}

.document-page mark.highlight-green {
  background: #bcefd0;
}

.document-page mark.highlight-blue {
  background: #bfe3ff;
}

.document-page mark.highlight-pink {
  background: #ffcfe0;
}

.highlight-sticker {
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  z-index: 3;
  display: block;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(31, 50, 41, 0.22);
  border-radius: 4px 4px 7px 4px;
  box-shadow: 0 1px 2px rgba(24, 42, 34, 0.16);
  cursor: pointer;
  transform: translateY(-50%);
}

.highlight-sticker::after {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 6px;
  height: 6px;
  border-radius: 1px 1px 5px;
  background: rgba(255, 255, 255, 0.58);
  content: "";
}

.highlight-sticker:hover,
.highlight-sticker:focus-visible {
  outline: 2px solid rgba(14, 124, 102, 0.34);
  outline-offset: 2px;
}

.highlight-sticker.sticker-yellow,
.highlight-popover.sticker-yellow {
  background: #ffe48a;
}

.highlight-sticker.sticker-green,
.highlight-popover.sticker-green {
  background: #bcefd0;
}

.highlight-sticker.sticker-blue,
.highlight-popover.sticker-blue {
  background: #bfe3ff;
}

.highlight-sticker.sticker-pink,
.highlight-popover.sticker-pink {
  background: #ffcfe0;
}

.highlight-popover {
  position: fixed;
  z-index: 20;
  width: min(260px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid rgba(31, 50, 41, 0.18);
  border-radius: 8px;
  box-shadow: 0 14px 35px rgba(16, 31, 24, 0.2);
  color: #17241d;
}

.highlight-popover strong {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
}

.highlight-popover p {
  margin: 0;
  color: #22342a;
  font-size: 13px;
  line-height: 1.45;
}

.document-page mark.search-hit {
  background: #bfe3ff;
}

.source-reader {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 0 14px;
}

.pdf-chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 280px);
  align-items: stretch;
  align-self: stretch;
  gap: 10px;
  width: auto;
  min-width: 0;
  max-width: none;
  min-height: 0;
  margin: 10px 0 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 251, 249, 0.95);
}

.ask-chat {
  grid-template-columns: 1fr;
  margin: 10px 0 0;
  padding: 12px;
}

.pdf-chat-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 7px;
}

.chat-side-tools {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
  padding-left: 10px;
  border-left: 1px solid rgba(31, 50, 41, 0.1);
}

.ask-chat .chat-side-tools {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  align-items: start;
  gap: 10px;
  padding-top: 10px;
  padding-left: 0;
  border-top: 1px solid rgba(31, 50, 41, 0.1);
  border-left: 0;
}

.ask-chat .pdf-chat-messages {
  min-height: 190px;
  max-height: 310px;
}

.ask-chat .voice-status {
  grid-column: 1 / -1;
}

.voice-chip {
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fbf9;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.voice-chip:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.voice-chip.active {
  border-color: rgba(14, 124, 102, 0.24);
  background: #e6f4ef;
  color: var(--brand-dark);
}

.voice-chip.speaking {
  border-color: rgba(224, 122, 95, 0.34);
  background: #ffe7de;
  color: #9f3f28;
  box-shadow: 0 0 0 3px rgba(224, 122, 95, 0.12);
}

.pdf-chat-messages {
  display: grid;
  gap: 6px;
  align-content: start;
  flex: 1;
  max-height: none;
  min-height: 76px;
  overflow: auto;
  padding: 6px;
  border: 1px solid rgba(31, 50, 41, 0.08);
  border-radius: 8px;
  background: #ffffff;
}

.chat-message {
  width: fit-content;
  max-width: 100%;
  padding: 7px 8px;
  border-radius: 8px;
  color: #27332d;
  font-size: 12px;
  line-height: 1.35;
}

.chat-message.assistant {
  justify-self: start;
  background: #edf4f1;
}

.chat-message.user {
  justify-self: end;
  background: #eaf1fb;
}

.pdf-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.pdf-chat-form textarea {
  flex: 1;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font: inherit;
  line-height: 1.1;
  outline: 0;
  resize: none;
  overflow: hidden;
  white-space: nowrap;
}

.pdf-chat-form button {
  min-height: 30px;
  min-width: 50px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.pdf-chat-form button.listening,
.ask-row button.listening {
  background: #e07a5f;
  box-shadow: 0 0 0 3px rgba(224, 122, 95, 0.16);
}

.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  min-width: 0;
}

.chat-label {
  grid-column: 1 / -1;
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.chat-suggestions button {
  min-height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fbf9;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.chat-suggestions button:hover {
  border-color: rgba(14, 124, 102, 0.24);
  color: var(--brand-dark);
}

.chat-voice-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.voice-tools-label {
  margin-bottom: 1px;
}

.voice-status {
  display: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
}

.voice-status.active {
  color: #9f3f28;
}

.document-page p.focus-active {
  position: relative;
  padding: 10px 12px;
  border-left: 4px solid var(--brand);
  border-radius: 6px;
  background: #edf7f3;
}

.source-panel.focus-reading .document-page p[data-paragraph] {
  cursor: pointer;
}

.source-panel.focus-reading .document-page p:not(.focus-active) {
  opacity: 0.32;
}

.focus-controls {
  display: none;
  position: absolute;
  top: 104px;
  left: 50%;
  z-index: 12;
  transform: translateX(-50%);
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  max-width: calc(100% - 28px);
  min-height: 30px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(249, 251, 248, 0.94);
  box-shadow: 0 8px 18px rgba(34, 39, 35, 0.11);
  backdrop-filter: blur(8px);
}

.source-panel.focus-reading .focus-controls {
  display: flex;
}

.focus-controls button {
  display: grid;
  place-items: center;
  min-width: 48px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.focus-controls span {
  min-width: 86px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.focus-controls .focus-hint {
  min-width: 92px;
  color: var(--brand);
  font-size: 10px;
}

.study-panel {
  display: grid;
  grid-template-rows: 54px 1fr;
  overflow: hidden;
}

.app-shell.study-collapsed .study-panel {
  grid-template-rows: 1fr;
}

.app-shell.study-collapsed .tool-tabs,
.app-shell.study-collapsed .tool-content {
  display: none;
}

.app-shell.study-collapsed .study-panel::before {
  content: "Study";
  display: grid;
  place-items: center;
  writing-mode: vertical-rl;
  color: var(--muted);
  font-weight: 800;
}

.tool-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  overflow: hidden;
}

.tool-tab {
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  padding: 0 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-tab:last-child {
  border-right: 0;
}

.tool-tab.active {
  background: var(--panel);
  color: var(--brand-dark);
}

.tool-content {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  font-size: 12px;
}

.answer-block {
  display: grid;
  gap: 8px;
}

.notes-workspace {
  height: auto;
  min-height: auto;
}

.study-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.study-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  line-height: 1.3;
}

.study-card p,
.study-card li {
  color: #394640;
  font-size: 12px;
  line-height: 1.4;
}

.study-card ul,
.study-card ol {
  margin: 6px 0 0;
  padding-left: 18px;
}

.note-card {
  display: block;
  min-height: auto;
  height: auto;
}

.note-fixed-tools {
  padding-bottom: 0;
  border-bottom: 0;
  background: white;
}

.note-scroll-area {
  display: grid;
  gap: 8px;
  overflow: visible;
  padding-top: 0;
  padding-right: 0;
}

.nested-note-card {
  padding: 9px;
  background: #fbfdfb;
}

.quiz-answer-panel {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.quiz-answer-panel summary {
  width: fit-content;
  cursor: pointer;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  list-style-position: inside;
}

.quiz-answer-panel p {
  margin: 7px 0 0;
}

.tool-action {
  width: 100%;
  min-height: 38px;
  margin-bottom: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf4f1;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 700;
}

.ask-box {
  width: 100%;
  min-height: 320px;
  padding: 8px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}

.note-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-title-row strong {
  margin-bottom: 0;
}

.note-settings-toggle {
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbf9;
  color: var(--brand-dark);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.note-settings-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  place-items: center;
  padding: 18px;
  background: rgba(15, 33, 28, 0.32);
}

.note-settings-backdrop.open {
  display: grid;
}

.note-settings-modal {
  width: min(360px, 92vw);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 70px rgba(15, 33, 28, 0.22);
}

.note-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.note-settings-header strong {
  margin-bottom: 0;
  font-size: 13px;
}

.note-settings-header button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbf9;
  color: var(--ink);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.note-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.note-settings-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.note-settings-grid select,
.note-settings-grid input[type="range"],
.note-settings-grid input[type="color"] {
  width: 100%;
  min-width: 0;
}

.note-settings-grid select {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 11px;
}

.note-settings-grid input[type="color"] {
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.note-a4-preview {
  --note-font-size: 14px;
  --note-line-height: 1.5;
  --note-row: 21px;
  --note-ink: #17211c;
  --note-paper: #fffefa;
  width: min(100%, calc(62vh * 210 / 297));
  aspect-ratio: 210 / 297;
  max-height: min(620px, 62vh);
  margin: 0 auto;
  padding: 18px 16px;
  overflow: hidden;
  border: 1px solid #cfd9d3;
  border-radius: 6px;
  background: var(--note-paper);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
}

.note-box {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  resize: none;
  color: var(--note-ink);
  background-color: var(--note-paper);
  font-size: var(--note-font-size);
  line-height: var(--note-line-height);
  outline: 0;
}

.note-box.lined {
  background-image: linear-gradient(to bottom, transparent calc(var(--note-row) - 1px), #dfe8e3 var(--note-row));
  background-position-y: -1px;
  background-size: 100% var(--note-row);
}

.note-box.grid {
  background-image:
    linear-gradient(to right, #dfe8e3 1px, transparent 1px),
    linear-gradient(to bottom, #dfe8e3 1px, transparent 1px);
  background-position-y: -1px;
  background-size: var(--note-row) var(--note-row);
}

.note-box.math {
  background-image:
    linear-gradient(to right, rgba(47, 102, 165, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(47, 102, 165, 0.16) 1px, transparent 1px);
  background-position-y: -1px;
  background-size: var(--note-row) var(--note-row);
}

.note-font-system {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.note-font-serif {
  font-family: Georgia, "Times New Roman", serif;
}

.note-font-mono {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.note-mode-row,
.math-symbol-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.note-mode-row button,
.math-symbol-row button {
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.note-mode-row button.active {
  border-color: rgba(14, 124, 102, 0.24);
  background: #e6f4ef;
  color: var(--brand-dark);
}

.math-symbol-row button {
  min-width: 28px;
  color: var(--ink);
  font-size: 12px;
}

.save-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.save-row button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.export-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.export-row button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbf9;
  color: var(--brand-dark);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.saved-note-list {
  display: grid;
  gap: 8px;
}

.saved-note {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
  color: #394640;
  line-height: 1.45;
}

.ask-row {
  display: flex;
  gap: 8px;
}

.ask-row input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.ask-row button {
  min-width: 82px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.ask-guide p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.ask-guide ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.ask-help {
  padding: 0;
  overflow: hidden;
}

.ask-help summary {
  min-height: 38px;
  padding: 10px 12px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  list-style-position: inside;
}

.ask-help summary:hover {
  background: #f5f9f7;
  color: var(--brand-dark);
}

.ask-help ul {
  margin: 0;
  padding: 0 14px 12px 30px;
}

.ask-prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ask-prompt-grid button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.ask-prompt-grid button:hover {
  border-color: rgba(14, 124, 102, 0.28);
  background: #edf8f4;
  color: var(--brand-dark);
}

.companion-card {
  border-color: rgba(47, 102, 165, 0.22);
  background: #f4f8fc;
}

.learning-control-group {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.control-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.segmented-control button {
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  background: #e6f4ef;
  color: var(--brand-dark);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.level-card {
  display: grid;
  gap: 4px;
  min-height: 86px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.level-card strong {
  margin: 0;
  color: inherit;
  font-size: 13px;
}

.level-card span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.level-card.active {
  border-color: rgba(14, 124, 102, 0.34);
  background: #e6f4ef;
}

.companion-status {
  border-color: rgba(14, 124, 102, 0.2);
  background: #fbfdfb;
}

.library-manager p,
.danger-zone p {
  margin: 0 0 10px;
}

.library-manager,
.library-panel-card,
.source-container-card,
.danger-zone {
  font-size: 12px;
}

.library-manager.study-card,
.library-panel-card.study-card,
.source-container-card.study-card,
.danger-zone.study-card {
  padding: 10px;
}

.library-manager > strong,
.library-panel-card > strong,
.source-container-card > strong,
.danger-zone > strong {
  font-size: 13px;
}

.library-manager p,
.source-container-card p,
.danger-zone p {
  font-size: 11px;
  line-height: 1.35;
}

.library-book-list,
.chapter-list {
  display: grid;
  gap: 6px;
}

.chapter-list {
  max-height: min(44vh, 430px);
  overflow: auto;
  padding-right: 2px;
  overscroll-behavior: contain;
}

.library-book-row,
.chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.library-book-row span,
.chapter-row {
  min-width: 0;
}

.library-book-row strong,
.library-book-row small,
.chapter-row span,
.chapter-row strong {
  display: block;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-book-row strong,
.chapter-row strong {
  font-size: 12px;
  line-height: 1.2;
}

.library-book-row small,
.library-book-row em,
.chapter-row span {
  color: var(--muted);
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
}

.chapter-row {
  display: grid;
  justify-content: stretch;
  min-height: 46px;
}

.library-book-row.active,
.chapter-row.active {
  border-color: rgba(14, 124, 102, 0.28);
  background: #e6f4ef;
}

.danger-zone {
  border-color: rgba(159, 52, 52, 0.2);
  background: #fff8f6;
}

.ghost-action {
  margin-top: 8px;
  background: #f8fbf9;
  color: var(--muted);
  border: 1px solid var(--line);
}

.source-container-card {
  border-color: rgba(47, 102, 165, 0.18);
  background: #f7fbff;
}

.source-container-card dl {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
}

.source-container-card dl div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.source-container-card dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.source-container-card dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #27342d;
  font-size: 13px;
}

.danger-zone button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(159, 52, 52, 0.24);
  border-radius: 8px;
  background: white;
  color: #8b2f2f;
  cursor: pointer;
  font-weight: 800;
}

.progress-view,
.settings-view {
  gap: 10px;
}

.progress-hero {
  border-color: rgba(14, 124, 102, 0.2);
  background: #f2faf7;
}

.progress-meter {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe9e4;
}

.progress-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.progress-hero em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric-card {
  display: grid;
  gap: 2px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.metric-card strong {
  color: var(--brand-dark);
  font-size: 24px;
  line-height: 1;
}

.metric-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.settings-card {
  gap: 8px;
}

.ai-protocol-card {
  border-color: rgba(47, 102, 165, 0.2);
  background: #f5f9fd;
}

.trial-card {
  border-color: rgba(224, 122, 95, 0.24);
  background: #fff8f4;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.settings-row em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.settings-row button,
.settings-button-row button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.settings-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-button-row button.active {
  border-color: rgba(14, 124, 102, 0.28);
  background: #e6f4ef;
  color: var(--brand-dark);
}

.context-menu {
  position: fixed;
  z-index: 50;
  display: none;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 16px 42px rgba(30, 46, 39, 0.18);
}

.context-menu.open {
  display: grid;
}

.context-menu button {
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.context-menu button:hover {
  background: #edf4f1;
  color: var(--brand-dark);
}

@media (max-width: 980px) {
  .app-shell,
  .app-shell.library-collapsed {
    grid-template-columns: 1fr;
  }

  .library-rail {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    transform: translateX(-100%);
  }

  .app-shell:not(.library-collapsed) .library-rail {
    transform: translateX(0);
  }

  .workspace {
    min-height: 100vh;
  }

  .source-panel {
    overflow: auto;
  }

  .study-grid,
  .app-shell.study-collapsed .study-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 1fr) minmax(360px, 46vh);
  }

  .document-page {
    min-height: 560px;
    margin-right: auto;
  }

  .highlight-tools {
    flex-wrap: wrap;
  }

  .highlight-tools input {
    flex-basis: min(100%, 280px);
  }

  .search-box {
    width: min(300px, 34vw);
  }
}

@media (max-width: 1280px) {
  .source-reader {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 10px;
    overflow: auto;
  }

  .document-page {
    min-height: 520px;
    margin: 12px auto;
  }

  .pdf-chat {
    min-height: 190px;
    margin: 0 0 12px;
  }

  .pdf-chat-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .pdf-chat-messages {
    max-height: 112px;
    min-height: 54px;
  }

  .chat-side-tools {
    padding-top: 7px;
  }

  .ask-chat .chat-side-tools {
    grid-template-columns: 1fr;
  }

  .chat-suggestions,
  .chat-voice-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar {
    gap: 10px;
    padding: 10px;
  }

  .pill {
    display: none;
  }

  .search-box {
    order: 4;
    width: 100%;
  }

  .topbar {
    flex-wrap: wrap;
    min-height: 112px;
  }

  .study-grid {
    padding: 10px;
  }

  .chat-side-tools {
    padding-top: 8px;
    padding-left: 0;
    border-top: 1px solid rgba(31, 50, 41, 0.1);
    border-left: 0;
  }

  .ask-chat .chat-side-tools {
    grid-template-columns: 1fr;
  }

  .pdf-chat {
    grid-template-columns: 1fr;
  }

  .pdf-chat-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .chat-suggestions,
  .chat-voice-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tool-tabs {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
    min-height: 96px;
    overflow-x: auto;
  }

  .tool-tab {
    min-height: 48px;
  }

  .segmented-control,
  .level-grid {
    grid-template-columns: 1fr;
  }

  .source-toolbar {
    flex-wrap: wrap;
    min-height: 112px;
  }

  .reading-tools {
    order: 3;
    width: 100%;
  }

  .page-fit-tools {
    order: 4;
    width: 100%;
  }

  .reading-tools button,
  .page-fit-tools button {
    flex: 1;
  }

  .highlight-tools {
    padding: 8px 10px;
  }

  .highlight-swatches {
    width: 100%;
  }

  .highlight-tools input {
    flex-basis: 100%;
  }
}
