:root {
  --bg: #f4efe7;
  --bg-2: #eef4f6;
  --paper: #fffdf9;
  --paper-soft: rgba(255, 252, 247, 0.88);
  --ink: #24323a;
  --muted: #5b6b72;
  --line: rgba(36, 50, 58, 0.12);
  --line-strong: rgba(36, 50, 58, 0.18);
  --accent: #5f81c3;
  --accent-deep: #3b5a99;
  --accent-soft: rgba(95, 129, 195, 0.16);
  --shadow: 0 20px 70px rgba(36, 50, 58, 0.08);
  --radius-lg: 30px;
  --radius-md: 22px;
  --radius-sm: 14px;
  --max: 1460px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(95, 129, 195, 0.16), transparent 26%),
    radial-gradient(circle at right top, rgba(222, 231, 235, 0.8), transparent 24%),
    linear-gradient(180deg, var(--bg) 0%, #f8f5ef 38%, var(--bg-2) 100%);
}

body.is-dragging-chat {
  user-select: none;
  cursor: move;
}

a,
button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(95, 129, 195, 0.28);
  outline-offset: 2px;
}

.page-shell {
  width: min(calc(100% - 28px), var(--max));
  margin: 0 auto;
  padding: 24px 0 72px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 26px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 253, 250, 0.92), rgba(246, 250, 252, 0.88)),
    rgba(255, 255, 255, 0.74);
  box-shadow: var(--shadow);
}

.topbar-copy {
  display: grid;
  gap: 8px;
}

.topbar h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(2.2rem, 4.2vw, 3.6rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.guide-tabs {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
}

.guide-tab {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.guide-tab:hover {
  transform: translateY(-1px);
}

.guide-tab.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: 0 12px 24px rgba(59, 90, 153, 0.16);
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.82fr);
  gap: 24px;
  padding: 38px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: calc(var(--radius-lg) + 4px);
  background:
    linear-gradient(135deg, rgba(255, 251, 245, 0.94), rgba(246, 250, 252, 0.84)),
    rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.hero::before {
  width: 320px;
  height: 320px;
  top: -140px;
  right: -60px;
  background: radial-gradient(circle, rgba(95, 129, 195, 0.18), transparent 68%);
}

.hero::after {
  width: 240px;
  height: 240px;
  bottom: -120px;
  left: -60px;
  background: radial-gradient(circle, rgba(225, 234, 239, 0.9), transparent 70%);
}

.hero-copy,
.hero-panel {
  position: relative;
  z-index: 1;
}

.eyebrow,
.section-label,
.panel-label,
.chat-kicker,
.sidebar-label,
.chapter-eyebrow {
  margin: 0 0 10px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.hero h1,
.doc-paper-head h2,
.chat-header h2,
.doc-chapter-head h3 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.hero h1 {
  max-width: 12ch;
  line-height: 0.98;
  font-size: clamp(3rem, 7vw, 5.4rem);
}

.hero-lede {
  max-width: 62ch;
  margin: 18px 0 0;
  line-height: 1.78;
  font-size: 1.03rem;
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.primary-link,
.secondary-link,
.chat-send {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 14px 18px;
  text-decoration: none;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease;
}

.primary-link,
.chat-send {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: 0 14px 24px rgba(59, 90, 153, 0.16);
}

.secondary-link {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.6);
  border-color: var(--line);
}

.primary-link:hover,
.secondary-link:hover,
.chat-send:hover,
.chat-bubble:hover,
.doc-tab:hover,
.outline-link:hover {
  transform: translateY(-2px);
}

.hero-panel {
  padding: 22px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(36, 50, 58, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 248, 251, 0.82)),
    rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(16px);
}

.hero-points {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.8;
}

.formula-strip {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.formula-strip-inline {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 20px;
}

.formula-chip {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(95, 129, 195, 0.08);
}

.formula-chip strong {
  font-size: 0.78rem;
  color: var(--accent-deep);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.formula-chip span {
  font-size: 0.95rem;
  color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width, 320px) minmax(0, 1fr);
  gap: 22px;
  margin-top: 24px;
  align-items: start;
}

.workspace.sidebar-collapsed {
  --sidebar-width: 88px;
}

.doc-sidebar {
  position: sticky;
  top: 16px;
  padding: 22px 18px 22px 22px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 251, 245, 0.84), rgba(245, 249, 251, 0.92)),
    rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 32px);
  overflow: auto;
  transition:
    width 180ms ease,
    padding 180ms ease;
}

.doc-sidebar.is-collapsed {
  width: 88px;
  padding: 18px 10px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.sidebar-collapse {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(95, 129, 195, 0.14);
  color: var(--accent-deep);
  font-size: 1.3rem;
}

.doc-sidebar.is-collapsed .sidebar-label,
.doc-sidebar.is-collapsed .outline-nav {
  display: none;
}

.doc-sidebar.is-collapsed .sidebar-head {
  justify-content: center;
}

.doc-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  font-size: 0.85rem;
}

.outline-nav {
  display: grid;
  gap: 16px;
}

.outline-legend {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.58);
}

.outline-legend-kicker {
  margin: 0;
  color: var(--accent-deep);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.outline-legend-note,
.outline-legend-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.58;
}

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

.outline-legend-item {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid rgba(36, 50, 58, 0.08);
  border-radius: 16px;
  background: rgba(255, 252, 247, 0.82);
}

.outline-legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.outline-scroll-shell {
  position: relative;
  padding-left: 18px;
}

.outline-scroll-shell::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  bottom: 2px;
  width: 2px;
  background: rgba(36, 50, 58, 0.08);
}

.outline-active-pill {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border: 1px solid rgba(95, 129, 195, 0.16);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(205, 224, 255, 0.64), rgba(233, 243, 255, 0.9)),
    rgba(95, 129, 195, 0.12);
  box-shadow: 0 14px 28px rgba(95, 129, 195, 0.12);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition:
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1),
    width 220ms ease,
    height 220ms ease,
    opacity 180ms ease;
}

.outline-list,
.outline-sublist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline-list {
  position: relative;
  z-index: 1;
}

.outline-item + .outline-item {
  margin-top: 10px;
}

.outline-sublist {
  margin-top: 8px;
  padding-left: 16px;
  display: grid;
  gap: 8px;
}

.outline-link {
  display: block;
  position: relative;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 14px;
  transition:
    color 180ms ease,
    background-color 180ms ease;
}

.outline-link:hover {
  transform: none;
  color: var(--ink);
}

.outline-link-shell {
  display: grid;
  gap: 6px;
}

.outline-link-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.outline-link-title {
  flex: 1 1 auto;
  min-width: 0;
}

.outline-link-meta {
  display: block;
  color: rgba(91, 107, 114, 0.94);
  font-size: 0.78rem;
  line-height: 1.46;
}

.outline-link-chapter {
  font-weight: 600;
  color: var(--ink);
}

.outline-link-section {
  font-size: 0.95rem;
}

.outline-badge,
.section-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.outline-badge {
  background: rgba(95, 129, 195, 0.12);
  color: var(--accent-deep);
}

.outline-link.is-active .outline-link-title,
.outline-link.is-parent-active .outline-link-title {
  color: var(--accent-deep);
}

.outline-link.is-active .outline-link-title {
  font-weight: 700;
}

.outline-link.is-active .outline-link-meta {
  color: var(--accent-deep);
}

.doc-main {
  min-width: 0;
}

.doc-paper {
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 253, 250, 0.98), rgba(250, 253, 255, 0.92)),
    var(--paper);
  box-shadow: var(--shadow);
}

.doc-paper-head {
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.doc-paper-head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.doc-head-controls {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.doc-paper-head h2 {
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.02;
}

.study-concepts-count {
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(95, 129, 195, 0.14);
  font-size: 0.84rem;
}

.compact-toggle {
  position: fixed;
  top: max(18px, calc(env(safe-area-inset-top, 0px) + 12px));
  right: max(18px, calc(env(safe-area-inset-right, 0px) + 12px));
  z-index: 66;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid rgba(95, 129, 195, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.92);
  box-shadow: 0 14px 34px rgba(36, 50, 58, 0.12);
  backdrop-filter: blur(10px);
  color: var(--accent-deep);
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
}

.compact-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-deep);
}

.doc-paper-head p:last-child {
  margin: 12px 0 0;
  max-width: 64ch;
  color: var(--muted);
  line-height: 1.78;
}

.doc-chapter {
  padding-top: 34px;
}

.doc-chapter + .doc-chapter {
  border-top: 1px solid var(--line);
  margin-top: 34px;
}

.doc-chapter-head h3 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.03;
}

.doc-chapter-intro {
  margin-top: 18px;
}

.chapter-intro-grid,
.study-map-grid,
.worked-example-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.chapter-intro-card,
.study-map-card,
.worked-step {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.76);
}

.chapter-intro-label {
  margin: 0 0 8px;
  color: var(--accent-deep);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-intro-value,
.study-map-card p,
.worked-step p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.study-map-card h4,
.worked-example-head h4 {
  margin: 0 0 8px;
  font-family: "Fraunces", serif;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
}

.study-map-card .quiz-kicker,
.worked-example-head .quiz-kicker {
  margin: 0 0 6px;
}

.doc-section-stack {
  display: grid;
  gap: 22px;
  margin-top: 18px;
}

.doc-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper-soft);
}

.doc-section-heading {
  padding: 22px 24px 0;
}

.doc-section-kicker {
  margin: 0 0 10px;
  color: var(--accent-deep);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.doc-section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.doc-section-locator {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.58;
}

.doc-section-locator strong {
  color: var(--accent-deep);
}

.doc-section-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 24px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.doc-section-title {
  font-family: "Fraunces", serif;
  font-size: 1.45rem;
  font-weight: 500;
}

.doc-section-chevron {
  color: var(--accent-deep);
  font-size: 1.5rem;
  transition: transform 180ms ease;
}

.doc-section.is-open .doc-section-chevron {
  transform: rotate(45deg);
}

.doc-section-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 220ms ease;
}

.doc-section-body {
  padding: 0 24px 24px;
}

.figure-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.doc-section-body p,
.doc-section-body li,
.doc-section-body td,
.doc-section-body th {
  color: var(--muted);
  line-height: 1.84;
}

.doc-section-body p:last-child {
  margin-bottom: 0;
}

.doc-snippet-highlight {
  background: rgba(95, 129, 195, 0.12);
  border-radius: 12px;
  box-shadow: 0 0 0 0 rgba(95, 129, 195, 0);
  animation: snippet-flash 2s ease-out;
}

@keyframes snippet-flash {
  0% {
    background: rgba(95, 129, 195, 0.22);
    box-shadow: 0 0 0 0 rgba(95, 129, 195, 0.24);
  }

  20% {
    background: rgba(95, 129, 195, 0.18);
    box-shadow: 0 0 0 8px rgba(95, 129, 195, 0.12);
  }

  100% {
    background: rgba(95, 129, 195, 0.06);
    box-shadow: 0 0 0 0 rgba(95, 129, 195, 0);
  }
}

.doc-section-body ul,
.doc-section-body ol {
  margin: 12px 0 0;
  padding-left: 20px;
}

.doc-section-body h4 {
  margin: 0 0 12px;
  font-family: "Fraunces", serif;
  font-size: 1.14rem;
  font-weight: 500;
}

.doc-section-body h4 + h4,
.doc-section-body p + h4,
.doc-section-body ul + h4,
.doc-section-body table + h4,
.doc-section-body .formula-inline + h4,
.doc-section-body .formula-box + h4 {
  margin-top: 18px;
}

.quiz-shell {
  display: grid;
  gap: 16px;
}

.quiz-toolbar,
.quiz-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quiz-kicker {
  margin: 0 0 4px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.quiz-title,
.quiz-prompt {
  margin: 0;
}

.quiz-title {
  font-family: "Fraunces", serif;
  font-size: 1.3rem;
  font-weight: 500;
}

.quiz-progress {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.92rem;
}

.quiz-card,
.quiz-summary {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(95, 129, 195, 0.14);
  border-radius: 20px;
  background: rgba(95, 129, 195, 0.07);
}

.quiz-prompt {
  color: var(--ink);
  line-height: 1.7;
  font-weight: 600;
}

.quiz-choices {
  display: grid;
  gap: 10px;
}

.quiz-choice,
.quiz-submit,
.quiz-restart,
.quiz-next {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

.quiz-choice,
.quiz-submit,
.quiz-next {
  padding: 12px 14px;
}

.quiz-restart {
  padding: 10px 14px;
}

.quiz-choice:hover,
.quiz-submit:hover,
.quiz-restart:hover,
.quiz-next:hover {
  transform: translateY(-1px);
}

.quiz-choice.is-correct {
  border-color: rgba(53, 117, 69, 0.32);
  background: rgba(53, 117, 69, 0.14);
  color: #1f5b2c;
}

.quiz-choice.is-incorrect {
  border-color: rgba(154, 59, 59, 0.32);
  background: rgba(154, 59, 59, 0.14);
  color: #7b2323;
}

.quiz-choice.is-muted {
  opacity: 0.76;
}

.quiz-short-form {
  display: grid;
  gap: 12px;
}

.quiz-short-input {
  width: 100%;
  min-height: 90px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  resize: vertical;
}

.quiz-feedback {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 18px;
}

.quiz-feedback strong,
.quiz-feedback p {
  margin: 0;
}

.quiz-feedback.is-correct {
  background: rgba(53, 117, 69, 0.12);
  color: #1f5b2c;
}

.quiz-feedback.is-incorrect {
  background: rgba(154, 59, 59, 0.12);
  color: #7b2323;
}

.formula-box,
.formula-inline,
.callout {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  background: rgba(95, 129, 195, 0.08);
}

.formula-box,
.formula-inline {
  font-family: "Fraunces", serif;
  color: var(--accent-deep);
}

.inline-term {
  display: inline;
  padding: 0 0.18em;
  border: 0;
  border-radius: 0.42em;
  background: rgba(95, 129, 195, 0.08);
  color: var(--accent-deep);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.inline-term:hover,
.inline-term:focus-visible {
  background: rgba(95, 129, 195, 0.16);
  color: var(--ink);
  box-shadow: 0 0 0 2px rgba(95, 129, 195, 0.1);
  outline: none;
}

.formula-box.is-explainable,
.formula-inline.is-explainable,
.formula-chip.is-explainable,
.data-table td.is-explainable,
code.is-explainable {
  cursor: help;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

code.is-explainable {
  display: inline-block;
  padding: 0.08em 0.26em;
  border-radius: 0.42em;
  background: rgba(95, 129, 195, 0.08);
}

.formula-box.is-explainable:hover,
.formula-box.is-explainable:focus-visible,
.formula-inline.is-explainable:hover,
.formula-inline.is-explainable:focus-visible,
.formula-chip.is-explainable:hover,
.formula-chip.is-explainable:focus-visible,
.data-table td.is-explainable:hover,
.data-table td.is-explainable:focus-visible,
code.is-explainable:hover,
code.is-explainable:focus-visible {
  background: rgba(95, 129, 195, 0.14);
  box-shadow: 0 10px 24px rgba(36, 53, 88, 0.08);
  transform: translateY(-1px);
  outline: none;
}

.callout {
  color: var(--ink);
}

.outline-badge.tone-priority,
.section-badge.tone-priority {
  background: rgba(237, 149, 52, 0.16);
  color: #955018;
}

.outline-badge.tone-trap,
.section-badge.tone-trap {
  background: rgba(177, 72, 72, 0.14);
  color: #8d2b2b;
}

.outline-badge.tone-method,
.section-badge.tone-method {
  background: rgba(69, 122, 101, 0.14);
  color: #24604a;
}

.outline-badge.tone-review,
.section-badge.tone-review {
  background: rgba(95, 129, 195, 0.12);
  color: var(--accent-deep);
}

.callout.callout-priority {
  border-color: rgba(237, 149, 52, 0.16);
  background: rgba(250, 186, 120, 0.14);
}

.callout.callout-trap {
  border-color: rgba(177, 72, 72, 0.18);
  background: rgba(192, 96, 96, 0.1);
}

.callout.callout-method {
  border-color: rgba(69, 122, 101, 0.16);
  background: rgba(104, 166, 142, 0.1);
}

.callout.callout-review {
  border-color: rgba(95, 129, 195, 0.14);
  background: rgba(95, 129, 195, 0.08);
}

.worked-example {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 18px;
  border: 1px solid rgba(95, 129, 195, 0.14);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
}

.worked-example-head {
  display: grid;
  gap: 8px;
}

.concept-inspector-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 37, 70, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 72;
}

.concept-inspector-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.concept-inspector {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(440px, calc(100vw - 28px));
  max-height: min(72vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(95, 129, 195, 0.16);
  border-radius: 28px;
  background: rgba(255, 251, 246, 0.97);
  box-shadow: 0 28px 70px rgba(28, 38, 64, 0.2);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  z-index: 74;
}

.concept-inspector.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.concept-inspector-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(95, 129, 195, 0.12);
  background: rgba(255, 255, 255, 0.7);
}

.concept-inspector-header h2 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.32rem;
  font-weight: 500;
  color: var(--ink);
}

.concept-inspector-body {
  overflow: auto;
  padding: 18px 20px 22px;
}

.concept-inspector-body p,
.concept-inspector-body li {
  margin-top: 0;
  color: var(--muted);
  line-height: 1.78;
}

.concept-inspector-body p:last-child {
  margin-bottom: 0;
}

.concept-inspector-body h3 {
  margin: 18px 0 10px;
  font-family: "Fraunces", serif;
  font-size: 1.03rem;
  font-weight: 500;
  color: var(--ink);
}

.concept-inspector-body ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

.concept-inspector-note {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(95, 129, 195, 0.08);
  color: var(--ink);
}

.concept-hovercard {
  position: fixed;
  z-index: 55;
  width: min(320px, calc(100vw - 24px));
  padding: 12px 14px;
  border: 1px solid rgba(95, 129, 195, 0.18);
  border-radius: 18px;
  background: rgba(255, 251, 246, 0.98);
  box-shadow: 0 18px 42px rgba(28, 38, 64, 0.14);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.concept-hovercard.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.concept-hovercard p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.58;
}

.concept-hovercard strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.concept-hovercard ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.concept-hovercard li {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.52;
}

.concept-hovercard-meta {
  margin-top: 10px !important;
  color: var(--accent-deep) !important;
  font-size: 0.82rem !important;
  font-weight: 600;
}

.worked-step strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
}

.takeaway-line {
  margin-top: 16px;
  padding: 16px 18px;
  border-left: 3px solid rgba(95, 129, 195, 0.4);
  background: rgba(95, 129, 195, 0.06);
  border-radius: 0 18px 18px 0;
  color: var(--ink);
}

.takeaway-line strong {
  color: var(--accent-deep);
}

.concept-figure {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
}

.concept-figure img {
  width: 100%;
  display: block;
  border-radius: 14px;
  background: #fff;
}

.concept-figure-small img {
  max-width: 460px;
  margin: 0 auto;
}

.concept-figure figcaption {
  color: var(--muted);
  line-height: 1.7;
  font-size: 0.94rem;
}

.concept-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.data-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.data-table th {
  color: var(--accent-deep);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

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

.floating-actions-rail {
  position: fixed;
  right: max(22px, calc((100vw - var(--max)) / 2 + 22px));
  bottom: 22px;
  z-index: 60;
  display: grid;
  gap: 14px;
  justify-items: end;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

body.concept-inspector-open .floating-actions-rail {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

.resource-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.resource-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid rgba(190, 58, 46, 0.16);
  border-radius: 999px;
  color: #8f241f;
  background: rgba(255, 248, 246, 0.92);
  text-decoration: none;
  font-weight: 700;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

.resource-button:hover,
.resource-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(143, 36, 31, 0.12);
  background: rgba(255, 243, 239, 0.98);
  border-color: rgba(190, 58, 46, 0.26);
  outline: none;
}

.resource-button::before {
  content: "▶";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #d93025;
  color: #fff;
  font-size: 0.72rem;
  line-height: 1;
}

.chat-bubble,
.study-concepts-fab,
.notes-fab {
  position: relative;
  right: auto;
  bottom: auto;
  display: inline-flex;
  align-items: center;
}

.chat-bubble {
  gap: 12px;
  padding: 15px 18px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: 0 18px 50px rgba(59, 90, 153, 0.24);
}

.study-concepts-fab {
  width: 62px;
  height: 62px;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #f3b15c, #d97b31);
  box-shadow: 0 18px 50px rgba(191, 118, 45, 0.24);
}

.notes-fab {
  width: 62px;
  height: 62px;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #7e8f9a, #4e6471);
  box-shadow: 0 18px 50px rgba(56, 75, 86, 0.24);
}

.notes-fab svg {
  width: 26px;
  height: 26px;
}

.study-concepts-fab svg {
  width: 26px;
  height: 26px;
}

.study-concepts-fab .study-concepts-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 26px;
  height: 26px;
  background: #fff7ef;
  color: #9b4d14;
  box-shadow: 0 8px 18px rgba(103, 54, 18, 0.14);
}

.selection-actions {
  position: fixed;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px) scale(0.98);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.selection-actions.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.selection-action {
  position: relative;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  box-shadow: 0 10px 24px rgba(59, 90, 153, 0.2);
}

.selection-action-secondary {
  background: linear-gradient(135deg, #f59d4e, #d9732c);
}

.selection-action-highlight {
  background: linear-gradient(135deg, #f2d56b, #d7a43b);
  color: #5d4306;
}

.selection-action-highlight svg {
  width: 16px;
  height: 16px;
}

.selection-action[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(28, 36, 43, 0.9);
  color: #fff;
  font-size: 0.74rem;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.selection-action[data-tooltip]:hover::after,
.selection-action[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.chat-bubble-ping {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.12);
}

.study-empty,
.study-note,
.study-concept-source {
  color: var(--muted);
}

.study-concepts-shell {
  position: fixed;
  right: 22px;
  bottom: 96px;
  z-index: 68;
  width: min(430px, calc(100vw - 32px));
  max-height: min(72vh, 760px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(36, 50, 58, 0.14);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(246, 250, 252, 0.96)),
    rgba(255, 255, 255, 0.95);
  box-shadow: 0 28px 110px rgba(21, 31, 37, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.98);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.study-concepts-shell.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.notes-shell {
  position: fixed;
  right: 22px;
  top: 92px;
  bottom: 96px;
  z-index: 69;
  width: min(410px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(36, 50, 58, 0.14);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(246, 250, 252, 0.96)),
    rgba(255, 255, 255, 0.95);
  box-shadow: 0 28px 110px rgba(21, 31, 37, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateX(12px) scale(0.98);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.notes-shell.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.notes-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.notes-header h2 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 1.04;
}

.notes-body {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}

.notes-label {
  color: var(--accent-deep);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.notes-input {
  width: 100%;
  min-height: 220px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  line-height: 1.75;
  resize: vertical;
}

.notes-saved {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.notes-saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notes-highlights-root {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  padding-right: 4px;
}

.notes-highlight-list {
  display: grid;
  gap: 12px;
}

.notes-highlight-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.notes-highlight-jump {
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}

.notes-highlight-text,
.notes-empty p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.notes-empty {
  padding: 14px 16px;
  border: 1px dashed rgba(95, 129, 195, 0.26);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.doc-persistent-highlight {
  padding: 0.06em 0.18em;
  border-radius: 0.35em;
  background: rgba(242, 213, 107, 0.58);
  box-shadow: 0 0 0 1px rgba(215, 164, 59, 0.18) inset;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    box-shadow 140ms ease;
}

.doc-persistent-highlight:hover {
  background: rgba(242, 213, 107, 0.8);
  box-shadow: 0 0 0 1px rgba(215, 164, 59, 0.28) inset;
}

.doc-persistent-highlight.is-focused {
  animation: persistent-highlight-flash 1.8s ease-out;
}

.example-study-mode {
  display: grid;
  gap: 14px;
}

.example-study-head {
  display: flex;
  justify-content: flex-end;
}

.example-steps-toggle {
  border: 1px solid rgba(95, 129, 195, 0.16);
  border-radius: 999px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--accent-deep);
  font-weight: 700;
}

.example-problem {
  padding: 14px 16px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  border-radius: 18px;
  background: rgba(95, 129, 195, 0.06);
}

.example-solution {
  display: grid;
  gap: 14px;
}

.example-study-mode.is-solution-hidden .example-solution {
  display: none;
}

@keyframes persistent-highlight-flash {
  0% {
    background: rgba(242, 213, 107, 0.88);
    box-shadow: 0 0 0 0 rgba(215, 164, 59, 0.2);
  }

  35% {
    background: rgba(242, 213, 107, 0.76);
    box-shadow: 0 0 0 10px rgba(242, 213, 107, 0.12);
  }

  100% {
    background: rgba(242, 213, 107, 0.58);
    box-shadow: 0 0 0 0 rgba(215, 164, 59, 0);
  }
}

.study-concepts-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.study-concepts-header h2 {
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 1.04;
}

.study-concepts-root {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.study-concepts-body {
  display: grid;
  gap: 14px;
}

.study-toolbar,
.study-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.study-toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.study-concepts-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.study-concept-item,
.study-card {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.study-concept-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.study-concept-source,
.study-card-source {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.study-concept-text,
.study-card-footer {
  margin: 0;
  line-height: 1.72;
}

.study-remove {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--muted);
}

.chat-shell {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 320px;
  min-height: 380px;
  padding: 18px;
  border: 1px solid rgba(36, 50, 58, 0.14);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(246, 250, 252, 0.96)),
    rgba(255, 255, 255, 0.95);
  box-shadow: 0 28px 110px rgba(21, 31, 37, 0.22);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.chat-shell.is-open {
  opacity: 1;
  pointer-events: auto;
}

.chat-shell.is-condensed {
  gap: 12px;
  padding: 16px;
}

.chat-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  cursor: move;
}

.chat-header h2 {
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  line-height: 1;
}

.chat-shell.is-condensed .chat-header h2 {
  font-size: clamp(1.35rem, 3vw, 1.7rem);
}

.chat-actions {
  display: flex;
  gap: 8px;
}

.chat-gear,
.chat-close {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.chat-settings {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.74);
}

.chat-settings.is-hidden {
  display: none;
}

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

.chat-settings label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.settings-toggles {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.settings-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink) !important;
}

.settings-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-deep);
}

.chat-settings input,
.chat-settings select,
.chat-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}

.settings-note {
  margin: 12px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.65;
}

.chat-messages {
  display: grid;
  flex: 1 1 auto;
  gap: 12px;
  overflow: auto;
  align-content: start;
  min-height: 0;
  min-width: 0;
}

.message {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: 20px;
  line-height: 1.72;
}

.message p {
  margin: 0;
}

.message-text {
  display: grid;
  gap: 8px;
}

.message-text .katex-display {
  margin: 0.9rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.message-text .katex {
  font-size: 1.02em;
}

.message-sources {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(36, 50, 58, 0.08);
}

.message-meta-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.message-source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-source-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid rgba(95, 129, 195, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--accent-deep);
  text-decoration: none;
  font-size: 0.84rem;
  line-height: 1.2;
}

.message-image-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.message-image-card {
  display: grid;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.message-image-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  border-radius: 14px;
  border: 1px solid rgba(95, 129, 195, 0.12);
  background: rgba(255, 255, 255, 0.9);
}

.message-image-card span {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.35;
}

.message-assistant {
  border-top-left-radius: 8px;
  background: rgba(95, 129, 195, 0.1);
  color: var(--ink);
}

.message-user {
  justify-self: end;
  border-top-right-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
}

.message-error {
  background: rgba(164, 52, 52, 0.1);
  color: #7d1d1d;
}

.chat-form {
  display: block;
  flex: 0 0 auto;
  margin-top: auto;
  min-width: 0;
}

.chat-composer {
  display: grid;
  gap: 10px;
  position: relative;
  padding: 12px 64px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.76);
  min-width: 0;
}

.chat-mode-switch {
  display: inline-flex;
  width: fit-content;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.mode-option {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
}

.mode-option.is-active {
  background: rgba(95, 129, 195, 0.18);
  color: var(--accent-deep);
  font-weight: 700;
}

.chat-form textarea {
  min-width: 0;
  min-height: 90px;
  height: 90px;
  max-height: 160px;
  resize: none;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
}

.chat-send {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  box-shadow: 0 12px 22px rgba(59, 90, 153, 0.18);
}

.chat-send svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.resize-handle {
  position: absolute;
  z-index: 3;
}

.resize-n,
.resize-s {
  left: 12px;
  right: 12px;
  height: 10px;
}

.resize-n {
  top: -4px;
  cursor: ns-resize;
}

.resize-s {
  bottom: -4px;
  cursor: ns-resize;
}

.resize-e,
.resize-w {
  top: 12px;
  bottom: 12px;
  width: 10px;
}

.resize-e {
  right: -4px;
  cursor: ew-resize;
}

.resize-w {
  left: -4px;
  cursor: ew-resize;
}

.resize-ne,
.resize-nw,
.resize-se,
.resize-sw {
  width: 16px;
  height: 16px;
}

.resize-ne {
  top: -5px;
  right: -5px;
  cursor: nesw-resize;
}

.resize-nw {
  top: -5px;
  left: -5px;
  cursor: nwse-resize;
}

.resize-se {
  right: -5px;
  bottom: -5px;
  cursor: nwse-resize;
}

.resize-sw {
  left: -5px;
  bottom: -5px;
  cursor: nesw-resize;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .doc-sidebar {
    position: relative;
    top: 0;
    max-height: none;
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px 18px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .page-shell {
    width: min(calc(100% - 18px), var(--max));
    padding-top: 18px;
  }

  .doc-paper-head-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .guide-tabs {
    width: 100%;
    justify-content: space-between;
  }

  .guide-tab {
    flex: 1 1 0;
    text-align: center;
  }

  .doc-head-controls {
    justify-content: flex-start;
  }

  .compact-toggle {
    top: max(12px, calc(env(safe-area-inset-top, 0px) + 8px));
    right: max(12px, calc(env(safe-area-inset-right, 0px) + 8px));
    padding: 9px 12px;
  }

  .doc-paper {
    padding: 22px 18px;
  }

  .concept-gallery {
    grid-template-columns: 1fr;
  }

  .doc-section-title-row,
  .outline-link-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .doc-section-heading {
    padding: 18px 18px 0;
  }

  .doc-section-body {
    padding: 0 18px 18px;
  }

  .settings-grid,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-bubble-label {
    display: none;
  }

  .floating-actions-rail {
    right: 16px;
    bottom: 16px;
  }

  .study-concept-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1560px) {
  .floating-actions-rail {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
