.td-notebook-reader {
  position: relative;
  display: grid;
  gap: 14px;
  min-width: 0;
  outline: none;
}

.td-notebook-reader:focus-visible {
  border-radius: 18px;
  box-shadow: 0 0 0 3px rgba(126, 102, 213, 0.25);
}

.td-notebook-spread {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.td-notebook-spread.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.td-notebook-spread.is-single .td-notebook-page {
  width: min(920px, 100%);
  justify-self: center;
}

.td-notebook-page {
  position: relative;
  min-width: 0;
  min-height: 690px;
  overflow: visible;
  padding: clamp(28px, 4.2vw, 54px) clamp(24px, 4vw, 50px) 48px;
  border: 1px solid rgba(35, 27, 31, 0.13);
  border-radius: 5px 17px 13px 5px;
  color: #292126;
  background:
    linear-gradient(90deg, transparent 0 38px, rgba(181, 45, 79, 0.16) 39px 40px, transparent 41px),
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0) 0 30px,
      rgba(84, 111, 137, 0.085) 31px,
      rgba(255, 255, 255, 0) 32px
    ),
    #fffdf8;
  box-shadow:
    0 20px 55px rgba(0, 0, 0, 0.23),
    inset -16px 0 28px rgba(68, 48, 52, 0.025);
}

.td-notebook-reader.is-density-compact .td-notebook-page {
  min-height: 650px;
  padding-top: clamp(22px, 3.2vw, 38px);
}

.td-notebook-reader.is-density-airy .td-notebook-page {
  min-height: 740px;
}

.td-notebook-reader.is-paper-grid .td-notebook-page {
  background:
    linear-gradient(90deg, transparent 0 38px, rgba(181, 45, 79, 0.14) 39px 40px, transparent 41px),
    linear-gradient(rgba(77, 122, 154, 0.075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77, 122, 154, 0.075) 1px, transparent 1px),
    #fffefa;
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.td-notebook-reader.is-paper-dots .td-notebook-page {
  background:
    linear-gradient(90deg, transparent 0 38px, rgba(181, 45, 79, 0.14) 39px 40px, transparent 41px),
    radial-gradient(circle, rgba(77, 103, 126, 0.18) 1px, transparent 1.2px),
    #fffefa;
  background-size: auto, 22px 22px, auto;
}

.td-notebook-reader.is-paper-plain .td-notebook-page {
  background: #fffefb;
}

.td-notebook-reader.is-theme-editorial .td-notebook-page {
  min-height: 0;
  border: 1px solid #e4dfe7;
  border-radius: 8px;
  background-color: #fffefb;
  box-shadow: 0 14px 46px rgba(30, 22, 38, 0.12);
}

.td-notebook-reader.is-theme-technical .td-notebook-page {
  border-color: rgba(35, 73, 91, 0.18);
  color: #172b34;
  background-color: #fbfeff;
}

.td-notebook-reader.is-theme-minimal .td-notebook-page {
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.16);
}

.td-notebook-page:nth-child(even) {
  border-radius: 17px 5px 5px 13px;
}

.td-notebook-page.is-role-cover {
  background:
    radial-gradient(circle at 82% 11%, rgba(120, 186, 213, 0.16), transparent 31%),
    radial-gradient(circle at 8% 88%, rgba(181, 45, 79, 0.12), transparent 36%),
    #fffdf8;
}

.td-notebook-paper-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 34px;
  padding-bottom: 24px;
  border-bottom: 1px solid #ddd5e3;
}

.td-notebook-reader.is-title-compact .td-notebook-paper-heading {
  gap: 4px;
  margin-bottom: 15px;
  padding-bottom: 10px;
}

.td-notebook-reader.is-title-compact .td-notebook-paper-heading h2 {
  font-size: clamp(1rem, 1.7vw, 1.3rem);
}

.td-notebook-paper-heading span {
  color: #756284;
  font-size: 0.7rem;
  font-weight: 950;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.td-notebook-paper-heading h2 {
  margin: 0;
  color: #261d22;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.td-notebook-page-body {
  min-width: 0;
}

.td-notebook-page-number {
  position: absolute;
  right: 24px;
  bottom: 18px;
  color: rgba(63, 49, 55, 0.48);
  font-size: 0.68rem;
  font-weight: 850;
}

.td-notebook-page-navigation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 4px 0;
}

.td-notebook-page-navigation button {
  position: static;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(46, 34, 39, 0.16);
  border-radius: 13px;
  color: #3b2c33;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 10px 28px rgba(25, 18, 21, 0.18);
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
  transform: none;
}

.td-notebook-page-navigation .is-previous {
  left: 10px;
}

.td-notebook-page-navigation .is-next {
  right: 10px;
}

.td-notebook-page-navigation button:disabled {
  opacity: 0.28;
  cursor: default;
}

.td-notebook-page-navigation span {
  padding: 8px 12px;
  border-radius: 20px;
  color: #695c70;
  background: #fffefb;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.student-notebook-blocks.is-paper {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 32px 20px;
  padding: 0;
}

.student-notebook-blocks.is-paper .student-notebook-block {
  grid-column: 1 / -1;
  overflow: visible;
  border: 0;
  border-radius: 0;
  color: #292126;
  background: transparent;
  box-shadow: none;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-width-half {
  grid-column: span 6;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-width-third {
  grid-column: span 4;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-width-wide {
  grid-column: 2 / span 10;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-align-start {
  align-self: start;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-align-center {
  align-self: center;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-density-compact {
  padding-top: 9px;
  padding-bottom: 9px;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-density-spacious {
  padding-top: 17px;
  padding-bottom: 17px;
}

.student-notebook-blocks.is-paper .student-notebook-block::before {
  display: none;
}

.student-notebook-blocks.is-paper .student-notebook-block-heading {
  min-height: 0;
  padding: 0 0 13px;
  border-bottom: 1px solid #e4dfe7;
  cursor: default;
}

.student-notebook-blocks.is-paper .student-notebook-block-heading-copy > span {
  color: #756284;
  font-size: 0.65rem;
}

.student-notebook-blocks.is-paper .student-notebook-block-heading-copy strong {
  color: #281f24;
  font-size: 1.12rem;
  line-height: 1.4;
}

.student-notebook-blocks.is-paper .student-notebook-block-heading-copy small {
  color: #74666d;
}

.student-notebook-blocks.is-paper .student-notebook-block-content {
  gap: 16px;
  padding: 15px 0 0;
  border: 0;
}

.student-notebook-blocks.is-paper .student-notebook-block-content p,
.student-notebook-blocks.is-paper .student-notebook-block-content ol {
  color: #30272c;
  font-size: 1rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-definition,
.student-notebook-blocks.is-paper .student-notebook-block.is-algorithm,
.student-notebook-blocks.is-paper .student-notebook-block.is-warning {
  padding: 20px 22px;
  border: 1px solid #d6d0c9;
  border-radius: 6px;
  background: #f8f6f1;
}

.student-notebook-blocks.is-paper .student-notebook-definition-part {
  color: #30272c;
  background: rgba(255, 255, 255, 0.55);
}

.student-notebook-blocks.is-paper .student-notebook-definition-part p {
  color: #30272c;
}

.student-notebook-blocks.is-paper .notebook-math-card {
  overflow-x: auto;
  color: #201a1d;
  background: rgba(255, 255, 255, 0.72);
}

.student-notebook-blocks.is-paper .student-notebook-curated-asset {
  color: #284f62;
  background: rgba(81, 156, 193, 0.06);
}

.student-notebook-blocks.is-paper .student-notebook-curated-asset :is(
  span,
  figcaption,
  .student-notebook-curated-asset-source
) {
  color: #526b76;
}

.student-notebook-blocks.is-paper .student-notebook-block:is(
  .is-diff-added,
  .is-diff-changed,
  .is-diff-moved,
  .is-diff-removed
) {
  position: relative;
  margin: -8px;
  padding: 8px;
  border-radius: 12px;
}

.student-notebook-blocks.is-paper .student-notebook-block.is-diff-added {
  background: rgba(57, 139, 85, 0.1);
  box-shadow: inset 0 0 0 1px rgba(57, 139, 85, 0.3);
}

.student-notebook-blocks.is-paper .student-notebook-block.is-diff-changed,
.student-notebook-blocks.is-paper .student-notebook-block.is-diff-moved {
  background: rgba(36, 103, 168, 0.08);
  box-shadow: inset 0 0 0 1px rgba(36, 103, 168, 0.28);
}

.student-notebook-blocks.is-paper .student-notebook-block.is-diff-removed {
  background: rgba(181, 45, 79, 0.08);
  box-shadow: inset 0 0 0 1px rgba(181, 45, 79, 0.28);
}

.student-notebook-diff-badge {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 999px;
  color: #1f4e36;
  background: rgba(57, 139, 85, 0.13);
  font-size: 0.56rem;
  font-weight: 950;
}

.is-diff-changed .student-notebook-diff-badge,
.is-diff-moved .student-notebook-diff-badge {
  color: #174b77;
  background: rgba(36, 103, 168, 0.13);
}

.is-diff-removed .student-notebook-diff-badge {
  color: #81223b;
  background: rgba(181, 45, 79, 0.13);
}

.student-notebook-empty {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px dashed rgba(65, 48, 55, 0.18);
  border-radius: 14px;
  color: #4c3f45;
  background: rgba(255, 255, 255, 0.45);
}

.student-notebook-empty span {
  color: #766970;
  font-size: 0.78rem;
  line-height: 1.5;
}

.student-notebook-unfiled {
  overflow: hidden;
  border: 1px solid rgba(120, 186, 213, 0.2);
  border-radius: 16px;
  background: rgba(26, 22, 25, 0.84);
}

.student-notebook-unfiled-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  color: #f4e9ec;
  cursor: pointer;
  list-style: none;
}

.student-notebook-unfiled-heading::-webkit-details-marker {
  display: none;
}

.student-notebook-unfiled-heading span {
  font-size: 0.8rem;
  font-weight: 900;
}

.student-notebook-unfiled-heading small {
  color: #8fbfd2;
  font-size: 0.66rem;
}

.student-notebook-unfiled-list {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.student-notebook-unfiled-entry {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.025);
}

.student-notebook-unfiled-entry-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
}

.student-notebook-unfiled-entry-head strong {
  color: #f8eff1;
  font-size: 0.76rem;
}

.student-notebook-unfiled-entry-head small {
  grid-column: 1;
  color: #93868b;
  font-size: 0.64rem;
}

.student-notebook-unfiled-entry-head button {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(120, 186, 213, 0.2);
  border-radius: 10px;
  color: #dff4fc;
  background: rgba(48, 111, 137, 0.12);
  font: inherit;
  font-size: 0.65rem;
  font-weight: 850;
  cursor: pointer;
}

.notebook-reading-flow {
  display: grid;
  gap: 18px;
  min-width: 0;
  --flow-muted: #c0accf;
  --flow-soft: rgba(163, 131, 195, 0.12);
  --flow-line: rgba(172, 145, 198, 0.3);
}

.is-paper .notebook-reading-flow {
  --flow-muted: #756284;
  --flow-soft: #f2edf6;
  --flow-line: #ddd2e6;
}

.notebook-reading-flow > * {
  min-width: 0;
}

.student-notebook-block-content .notebook-reading-flow p {
  margin: 0;
  padding: 0;
  font-size: 1rem;
  line-height: 1.8;
  white-space: pre-wrap;
}

.notebook-flow-step {
  padding-top: 8px;
}

.notebook-flow-step h4 {
  margin: 5px 0 0;
  color: inherit;
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.notebook-flow-label,
.notebook-flow-origin {
  display: block;
  margin-bottom: 5px;
  color: var(--flow-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.notebook-flow-note {
  padding: 17px 20px;
  border-left: 3px solid #b4a17c;
  border-radius: 0 8px 8px 0;
  background: rgba(177, 153, 105, 0.1);
}

.notebook-flow-answer {
  padding: 17px 20px;
  border: 1px solid var(--flow-line);
  border-radius: 8px;
  background: var(--flow-soft);
}

.notebook-reading-flow .notebook-math-card {
  max-width: 100%;
  margin: 10px 0 0;
  padding: 10px 14px;
  border: 0;
  border-left: 2px solid var(--flow-line);
  border-radius: 0;
  background: transparent;
}

.notebook-reading-flow .notebook-math-card-label {
  display: none;
}

.notebook-flow-code-content,
.notebook-flow-math-fallback {
  max-width: 100%;
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  border: 1px solid rgba(147, 166, 196, 0.2);
  border-radius: 8px;
  color: #e8edf7;
  background: #232733;
  font: 0.9rem/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre;
  tab-size: 4;
}

.notebook-flow-code-content code {
  color: inherit;
  font: inherit;
  white-space: inherit;
}

.notebook-flow-editor,
.notebook-flow-edit-rows {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.notebook-board-figures {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.notebook-board-figure {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  margin: 18px 0;
  padding: 12px;
  border: 1px solid rgba(140, 128, 113, 0.26);
  border-radius: 10px;
  background: rgba(190, 174, 150, 0.07);
  break-inside: avoid;
}

.notebook-board-figure-open {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 5px;
  background: #fff;
  cursor: zoom-in;
}

.notebook-board-figure-open img {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 420px;
  height: auto;
  object-fit: contain;
}

.notebook-board-figure figcaption {
  margin-top: 9px;
  color: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.5;
  opacity: 0.74;
}

.notebook-board-figure-status {
  margin: 0;
  padding: 20px 8px;
  color: inherit;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.notebook-board-figure [hidden] { display: none !important; }

.notebook-board-figure-dialog {
  box-sizing: border-box;
  width: min(1100px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
  border: 1px solid #d6cec1;
  border-radius: 12px;
  color: #292432;
  background: #fcfaf5;
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.3);
}

.notebook-board-figure-dialog::backdrop { background: rgba(22, 20, 29, 0.7); }

.notebook-board-figure-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid #ddd5ca;
}

.notebook-board-figure-toolbar h2 {
  flex: 1 1 170px;
  min-width: 0;
  margin: 0;
  color: inherit;
  font-size: 1rem;
}

.notebook-board-figure-toolbar button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #cfc4b3;
  border-radius: 6px;
  color: inherit;
  background: #fff;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
}

.notebook-board-figure-viewport {
  box-sizing: border-box;
  max-width: 100%;
  max-height: calc(100dvh - 170px);
  padding: 12px;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
  background: #fff;
}

.notebook-board-figure-viewport img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 195px);
  margin: auto;
  object-fit: contain;
}

.notebook-board-figure-viewport.is-natural-size img {
  max-width: none;
  max-height: none;
}

.notebook-board-figure-open:focus-visible,
.notebook-board-figure-dialog :focus-visible {
  outline: 3px solid #7161a9;
  outline-offset: 3px;
}

.lesson-notebook-block-editor,
.student-notebook-block-editor,
.lesson-notebook-block-editor-content,
.student-notebook-block-editor-content {
  min-width: 0;
}

.lesson-notebook-block-editor-content,
.student-notebook-block-editor-content {
  grid-template-columns: minmax(0, 1fr);
}

.lesson-notebook-block-editor-toolbar,
.student-notebook-block-editor-toolbar {
  flex-wrap: wrap;
}

.notebook-flow-edit-row textarea,
.notebook-flow-edit-toolbar select {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.notebook-flow-edit-row {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(172, 145, 198, 0.25);
  border-radius: 10px;
  background: rgba(163, 131, 195, 0.04);
}

.notebook-flow-edit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.notebook-flow-edit-toolbar button,
.notebook-flow-add {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid rgba(172, 145, 198, 0.3);
  border-radius: 8px;
  color: inherit;
  background: rgba(163, 131, 195, 0.08);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.notebook-flow-edit-row textarea.is-code {
  min-height: 160px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre;
  tab-size: 4;
}

@media print {
  .td-notebook-page-navigation { display: none; }
  .td-notebook-page { box-shadow: none; }
  .notebook-flow-answer, .notebook-flow-note, .notebook-flow-code { break-inside: avoid; }
  .notebook-flow-step { break-after: avoid; }
}

@media (max-width: 720px) {
  .td-notebook-page {
    min-height: 610px;
    padding: 28px 22px 44px;
    border-radius: 10px;
  }

  .td-notebook-page-navigation button {
    width: 44px;
    height: 44px;
  }

  .td-notebook-page-navigation .is-previous {
    left: 4px;
  }

  .td-notebook-page-navigation .is-next {
    right: 4px;
  }

  .student-notebook-blocks.is-paper {
    grid-template-columns: minmax(0, 1fr);
  }

  .student-notebook-blocks.is-paper .student-notebook-block-content p,
  .student-notebook-blocks.is-paper .student-notebook-block-content ol {
    font-size: 0.96rem;
  }

  .notebook-flow-note, .notebook-flow-answer {
    padding: 15px;
  }

  .notebook-flow-code-content { padding: 14px; font-size: 0.82rem; }

  .student-notebook-blocks.is-paper .student-notebook-block:is(
    .is-width-wide,
    .is-width-half,
    .is-width-third
  ) {
    grid-column: 1;
  }
}
