:root {
  --font-body: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-math: "MathJax_Main", "Cambria Math", "Times New Roman", serif;
  --font-mono: "D2Coding", "Consolas", monospace;
  --paper-width: 210mm;
  --paper-height: 297mm;
  --page-margin-x: 22mm;
  --page-margin-y: 14mm;
  --line: #d9dee8;
  --text: #1e2430;
  --muted: #667085;
  --blue: #2563eb;
  --green: #15803d;
  --amber: #b45309;
  --red: #b42318;
  --flow-accent: #8f8cf7;
  --flow-accent-soft: #fbfaff;
  --flow-accent-line: #e7e3ff;
  --rose-accent: #e9a5c2;
  --rose-soft: #fff8fb;
  --rose-line: #f3d9e7;
  --card-line: #dfe7f2;
  --card-soft: #fffdfd;
  --formula-line: #eadfbf;
  --formula-soft: #fffdf6;
  --card-radius: 8px;
  --paper: #ffffff;
  --surface: #f5f6f8;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--text);
  background: #e9edf3;
  font-family: var(--font-body);
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: #aeb8c8;
}

button.primary {
  border-color: #1d4ed8;
  background: #2563eb;
  color: #ffffff;
}

button.danger-light,
.danger-light {
  border-color: #fecaca;
  color: #b91c1c;
  background: #fff7f7;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 340px;
  min-height: 100vh;
}

.app-shell.stage-cards {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.stage-layout {
  grid-template-columns: 264px minmax(0, 1fr);
}

.app-shell.stage-cards .sidebar,
.app-shell.stage-cards .inspector {
  display: none;
}

.app-shell.stage-layout .inspector {
  position: fixed;
  top: 70px;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: none;
  width: min(380px, calc(100vw - 32px));
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(28, 39, 54, 0.22);
}

.app-shell.stage-layout.tools-open .inspector {
  display: block;
}

.app-shell.stage-cards .layout-only-control {
  display: none !important;
}

.sidebar,
.inspector {
  height: 100vh;
  overflow: auto;
  background: #fbfcfe;
  border-color: var(--line);
}

.sidebar {
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
  padding: 12px;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

.brand strong {
  font-size: 15px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.view-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.view-switch button,
.segmented button {
  min-height: 32px;
}

.view-switch button.active,
.segmented button.active,
.stage-switch button.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}

.page-list button.dragging,
.page-list button.drop-target {
  border-color: var(--flow-accent);
  background: var(--flow-accent-soft);
}

.page-list {
  display: grid;
  gap: 4px;
  padding: 8px;
}

.page-list button {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: start;
  min-height: 44px;
  padding: 7px;
  text-align: left;
}

.page-list button.active {
  border-color: #2563eb;
  background: #f0f6ff;
}

.page-list span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.page-list strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
}

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

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.workspace-heading {
  display: grid;
  gap: 6px;
}

.workspace-toolbar strong {
  font-size: 15px;
}

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

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stage-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-switch button {
  min-height: 30px;
  padding: 4px 10px;
}

#layout-template-select {
  min-height: 32px;
  max-width: 148px;
}

.toolbar-actions button {
  min-height: 32px;
  min-width: 34px;
  padding: 4px 10px;
}

#zoom-label {
  min-width: 48px;
  text-align: center;
}

.save-status {
  min-width: 86px;
  text-align: right;
}

.save-status.dirty {
  color: var(--amber);
}

.save-status.saved {
  color: var(--green);
}

.save-status.error {
  color: var(--red);
}

.preview-stage {
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.preview-stage.print-mode {
  display: grid;
  justify-items: center;
  align-items: start;
}

.preview-stage.mobile-mode {
  display: grid;
  justify-items: center;
  align-items: start;
}

.preview-stage.landscape-mode {
  display: grid;
  justify-items: center;
  align-items: start;
}

.card-board-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #eef2f7;
}

.card-board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.card-board-toolbar div:first-child {
  display: grid;
  gap: 2px;
}

.card-board-toolbar strong {
  font-size: 16px;
}

.card-board-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.card-board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-board-actions button {
  min-height: 32px;
  padding: 4px 10px;
}

.card-board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(288px, 1fr));
  gap: 14px;
  align-content: start;
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.board-card {
  display: grid;
  grid-template-rows: auto auto minmax(132px, 1fr) auto;
  gap: 9px;
  min-height: 292px;
  padding: 15px;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: linear-gradient(180deg, #ffffff 0%, var(--card-soft) 100%);
  box-shadow: 0 8px 20px rgba(28, 39, 54, 0.08);
  cursor: grab;
}

.board-card.active {
  border-color: var(--flow-accent);
  box-shadow:
    0 0 0 2px rgba(143, 140, 247, 0.18),
    0 10px 24px rgba(28, 39, 54, 0.1);
}

.board-card.chapter-start {
  border-color: #d8d3f4;
  background:
    linear-gradient(135deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.1) 50%, rgba(255, 255, 255, 0.94)),
    #fffafd;
}

.board-card.dragging {
  opacity: 0.48;
}

.board-card.drop-target {
  border-color: #2563eb;
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.14),
    0 10px 24px rgba(28, 39, 54, 0.1);
}

.board-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.board-card-index,
.board-card-role,
.board-warning-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.board-card-index {
  font-family: var(--font-mono);
}

.board-warning-chip {
  margin-left: auto;
  border-color: #f6c565;
  background: #fffbeb;
  color: #92400e;
}

.board-card h2 {
  margin: 0;
  color: #111827;
  font-size: 17px;
  line-height: 1.35;
}

.board-card-preview {
  min-height: 0;
  overflow: hidden;
  color: #263244;
  font-size: 13px;
  line-height: 1.58;
}

.board-card-preview p {
  margin: 0 0 7px;
}

.board-card-preview ul {
  margin: 0 0 8px;
  padding-left: 18px;
}

.board-card-preview li {
  margin-bottom: 4px;
}

.board-card-preview mjx-container[jax="CHTML"][display="true"] {
  margin: 6px 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.board-card-foot {
  border-top: 1px solid #edf0f5;
  padding-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.paper-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 6mm;
  width: var(--paper-width);
  height: var(--paper-height);
  padding: var(--page-margin-y) var(--page-margin-x);
  transform: scale(var(--preview-scale, 1));
  transform-origin: top center;
  background: var(--paper);
  box-shadow: 0 12px 34px rgba(28, 39, 54, 0.18);
  overflow: hidden;
}

.paper-page.overflowing {
  outline: 3px solid rgba(180, 35, 24, 0.5);
}

.paper-header,
.paper-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 9.2pt;
}

.paper-header strong {
  color: var(--text);
  font-size: 10pt;
  text-align: center;
}

.paper-header span:last-child {
  text-align: right;
}

.paper-footer {
  border-top: 1px solid #e5e7eb;
  padding-top: 3mm;
}

.paper-body {
  display: grid;
  min-height: 0;
  overflow: hidden;
}

.paper-flow {
  display: grid;
  align-content: start;
  gap: 3mm;
  width: min(100%, 154mm);
  margin: 0 auto;
  min-height: 0;
  overflow: visible;
}

.textbook-block {
  position: relative;
  margin: 0;
  font-size: 10.2pt;
  line-height: 1.62;
}

.textbook-block.span-2 {
  width: 100%;
}

.textbook-block h1,
.textbook-block h2,
.textbook-block h3 {
  break-after: avoid;
  margin: 0 0 1.5mm;
  color: #111827;
  line-height: 1.28;
}

.textbook-block h1 {
  max-width: 88%;
  font-size: 20pt;
  letter-spacing: 0;
}

.textbook-block h2 {
  font-size: 13.6pt;
}

.textbook-block h3 {
  font-size: 12pt;
}

.block-content p {
  margin: 0 0 1.7mm;
}

.block-content ul {
  margin: 0 0 2mm;
  padding-left: 5mm;
}

.block-content li {
  margin-bottom: 0.9mm;
}

.block-content mjx-container[jax="CHTML"][display="true"] {
  margin: 1.5mm 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.soft-rule {
  border: 0;
  border-top: 1px solid #e5e7eb;
  margin: 3mm 0;
}

blockquote,
.view-block {
  break-inside: avoid;
  margin: 3mm 0;
  padding: 2.5mm 3mm;
  border-left: 3px solid var(--flow-accent);
  background: var(--flow-accent-soft);
}

.block-eyebrow {
  width: fit-content;
  margin: 0 0 1.8mm;
  padding: 0.6mm 1.8mm;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  color: #596579;
  background: #ffffff;
  font-size: 7.4pt;
  font-weight: 800;
  line-height: 1.2;
}

.block-chapter_title {
  margin-bottom: 5mm;
  padding-bottom: 4mm;
  border-bottom: 1px solid #e4e8ef;
  border-left-color: var(--flow-accent);
  background: #fbfbff;
}

.role-question,
.role-answer,
.role-principle,
.role-formula,
.role-example,
.role-warning,
.role-recap,
.role-bridge {
  break-inside: avoid;
}

.role-question {
  padding: 2.2mm 2.5mm;
  border: 1px solid var(--rose-line);
  border-left: 4px solid var(--flow-accent);
  border-radius: var(--card-radius);
  background: var(--rose-soft);
}

.role-answer,
.role-bridge {
  padding: 2.2mm 2.5mm;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: #fcfdff;
}

.role-principle,
.role-recap {
  padding: 2.2mm 2.5mm;
  border: 1px solid var(--flow-accent-line);
  border-left: 4px solid var(--flow-accent);
  border-radius: var(--card-radius);
  background: var(--flow-accent-soft);
}

.role-formula {
  padding: 2.2mm 2.5mm;
  border: 1px solid var(--formula-line);
  border-radius: var(--card-radius);
  background: var(--formula-soft);
}

.role-formula .block-content p {
  margin-bottom: 1mm;
}

.role-formula mjx-container[jax="CHTML"][display="true"] {
  margin: 1.2mm 0 !important;
}

.role-example {
  padding: 2.2mm 2.5mm;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #f5f7fa;
}

.role-warning {
  padding: 2.2mm 2.5mm;
  border: 1px solid #f0cfc6;
  border-left: 4px solid #d98272;
  border-radius: var(--card-radius);
  background: #fff9f7;
}

.density-light {
  margin-bottom: 3mm;
}

.density-light .block-content p {
  margin-bottom: 1.6mm;
}

.density-dense {
  font-size: 9pt;
  line-height: 1.5;
}

.table-wrap {
  break-inside: avoid;
  overflow-x: auto;
  margin: 3mm 0;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.8pt;
}

.table-wrap th,
.table-wrap td {
  border: 1px solid #cfd7e4;
  padding: 1.8mm 2mm;
  vertical-align: top;
}

.table-wrap th {
  background: #f2f6fb;
  font-weight: 700;
}

.block-tools {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
}

.block-warning {
  min-width: 22px;
  min-height: 22px;
  padding: 0 5px;
  border-color: #f6c565;
  background: #fffbeb;
  color: #92400e;
  font-size: 11px;
  font-weight: 700;
}

.warning-chip {
  display: inline-flex;
  padding: 1px 5px;
  border-radius: 4px;
  background: #fff7ed;
  color: #9a3412;
}

.graph-placeholder {
  break-inside: avoid;
  display: grid;
  gap: 3px;
  margin: 3mm 0;
  padding: 3mm;
  border: 1px dashed #9cb5d6;
  background: #f7fbff;
  color: #344054;
}

.graph-placeholder strong {
  color: #1d4ed8;
}

.graph-placeholder span,
.graph-placeholder p {
  margin: 0;
  font-size: 8.6pt;
}

.mobile-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  width: min(420px, calc((100vh - 150px) * 9 / 16), calc(100vw - 48px));
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(28, 39, 54, 0.14);
  overflow: hidden;
}

.landscape-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 6mm;
  width: 297mm;
  height: 210mm;
  padding: 22mm 14mm 9mm 16mm;
  transform: scale(var(--preview-scale, 1));
  transform-origin: top center;
  background: var(--paper);
  box-shadow: 0 12px 34px rgba(28, 39, 54, 0.18);
  overflow: hidden;
}

.landscape-page.overflowing {
  outline: 3px solid rgba(180, 35, 24, 0.5);
}

.landscape-header,
.landscape-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 9pt;
}

.landscape-header strong {
  color: var(--text);
  font-size: 10pt;
}

.landscape-header span:last-child {
  text-align: right;
}

.landscape-footer {
  border-top: 1px solid #e5e7eb;
  padding-top: 3mm;
}

.landscape-card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6mm;
  align-items: start;
  min-height: 0;
}

.landscape-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  aspect-ratio: 9 / 16;
  min-height: 0;
  padding: 4mm;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: linear-gradient(180deg, #ffffff 0%, var(--card-soft) 100%);
  box-shadow: inset 0 0 0 1px #f7f4fb;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.landscape-card.is-output-dragging,
.rendered-graph.is-output-dragging {
  z-index: 8;
  cursor: grabbing;
  outline: 2px solid rgba(143, 140, 247, 0.42);
  box-shadow:
    0 10px 24px rgba(28, 39, 54, 0.16),
    inset 0 0 0 1px #f7f4fb;
}

.landscape-card-kicker {
  width: fit-content;
  margin-bottom: 2mm;
  padding: 0.6mm 1.8mm;
  border: 1px solid #e0d8f2;
  border-radius: 999px;
  color: #596579;
  background: #ffffff;
  font-size: 6.8pt;
  font-weight: 800;
  line-height: 1.2;
}

.landscape-card-body {
  display: grid;
  align-content: start;
  gap: 2.4mm;
  min-height: 0;
  overflow: hidden;
}

.landscape-card-body .textbook-block {
  align-self: start;
  margin: 0;
  font-size: 8.1pt;
  line-height: 1.46;
  min-height: 0;
}

.landscape-card-section {
  min-height: 0;
}

.landscape-card-body .textbook-block h1 {
  max-width: 86%;
  font-size: 13pt;
}

.landscape-card-body .textbook-block h2 {
  font-size: 10.6pt;
}

.landscape-card-body .textbook-block h3 {
  font-size: 9.8pt;
}

.landscape-card.is-long .landscape-card-body {
  gap: 1.8mm;
}

.landscape-card.is-long .landscape-card-body .textbook-block {
  font-size: 7.55pt;
  line-height: 1.34;
}

.landscape-card.is-long .landscape-card-body .textbook-block h3 {
  font-size: 9pt;
}

.landscape-card.is-long .landscape-card-body .role-question,
.landscape-card.is-long .landscape-card-body .role-answer,
.landscape-card.is-long .landscape-card-body .role-bridge,
.landscape-card.is-long .landscape-card-body .role-principle,
.landscape-card.is-long .landscape-card-body .role-recap,
.landscape-card.is-long .landscape-card-body .role-formula,
.landscape-card.is-long .landscape-card-body .role-example,
.landscape-card.is-long .landscape-card-body .role-warning {
  padding: 1.25mm 1.45mm;
}

.landscape-card-body .block-content p {
  margin-bottom: 1.2mm;
}

.landscape-card-body .block-content ul {
  margin-bottom: 1.4mm;
  padding-left: 4mm;
}

.landscape-card-body .block-content li {
  margin-bottom: 0.5mm;
}

.landscape-card-body .block-eyebrow {
  margin-bottom: 1.3mm;
  padding: 0.45mm 1.5mm;
  font-size: 6.5pt;
}

.landscape-card-body .role-question,
.landscape-card-body .role-answer,
.landscape-card-body .role-bridge,
.landscape-card-body .role-principle,
.landscape-card-body .role-recap,
.landscape-card-body .role-formula,
.landscape-card-body .role-example,
.landscape-card-body .role-warning {
  padding: 1.55mm 1.8mm;
  border-radius: 7px;
}

.landscape-card-body .role-question {
  border-color: var(--rose-line);
  border-left-color: var(--flow-accent);
  background: #fff9fc;
}

.landscape-card-body .role-principle,
.landscape-card-body .role-recap {
  border-color: var(--flow-accent-line);
  border-left-color: var(--flow-accent);
  background: #fbfaff;
}

.landscape-card-body .role-answer,
.landscape-card-body .role-bridge {
  border-color: var(--card-line);
  background: #ffffff;
}

.landscape-card-body .role-formula {
  border-color: var(--formula-line);
  background: var(--formula-soft);
}

.landscape-card-body .block-chapter_title {
  margin-bottom: 0;
  padding: 4.5mm 4.8mm 5mm;
  border: 1px solid #ded8f6;
  border-left: 5px solid var(--flow-accent);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.08) 52%, rgba(255, 255, 255, 0.9)),
    #fffafd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 5px 14px rgba(64, 54, 115, 0.06);
}

.landscape-card-body .block-chapter_title::before {
  content: "";
  display: block;
  width: 22mm;
  height: 1.4mm;
  margin-bottom: 4mm;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--flow-accent), var(--rose-accent));
}

.landscape-card-body .block-chapter_title h1 {
  max-width: 100%;
  margin-bottom: 3mm;
  font-size: 14.2pt;
}

.landscape-card:has(.block-chapter_title) {
  border-color: #d8d3f4;
  background:
    linear-gradient(180deg, #ffffff 0%, #fffafd 52%, #fbfaff 100%);
}

.mobile-page:has(.block-chapter_title) {
  border-color: #d8d3f4;
  background:
    linear-gradient(180deg, #ffffff 0%, #fffafd 50%, #fbfaff 100%);
}

.mobile-body .block-chapter_title {
  margin-bottom: 0;
  padding: 24px 24px 26px;
  border: 1px solid #ded8f6;
  border-left: 6px solid var(--flow-accent);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.08) 52%, rgba(255, 255, 255, 0.94)),
    #fffafd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 6px 18px rgba(64, 54, 115, 0.07);
}

.mobile-body .block-chapter_title::before {
  content: "";
  display: block;
  width: 86px;
  height: 5px;
  margin-bottom: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--flow-accent), var(--rose-accent));
}

.mobile-body .block-chapter_title h1 {
  max-width: 100%;
  margin-bottom: 14px;
  font-size: 26px;
}

.landscape-card-body mjx-container[jax="CHTML"][display="true"] {
  margin: 1mm 0 !important;
}

.mobile-page.overflowing {
  outline: 3px solid rgba(180, 35, 24, 0.5);
}

.mobile-header {
  display: grid;
  gap: 6px;
}

.mobile-header span {
  color: var(--muted);
  font-size: 12px;
}

.mobile-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
}

.mobile-body {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.mobile-body .textbook-block {
  margin: 0;
  font-size: 15px;
  line-height: 1.68;
  min-height: 0;
}

.card-body .textbook-block {
  align-self: start;
  padding: 14px 16px;
}

.card-body.is-paired {
  gap: 14px;
}

.card-section {
  min-height: 0;
}

.card-section,
.textbook-block {
  cursor: default;
}

.card-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  border-top: 1px solid #e5e7eb;
  padding-top: 12px;
}

.card-controls span {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--font-mono);
}

.card-controls button {
  min-height: 36px;
}

.card-controls button:first-child {
  justify-self: start;
}

.card-controls button:last-child {
  justify-self: end;
}

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

.panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.inspector-header {
  position: sticky;
  top: -12px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -12px -12px 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.inspector-header strong {
  font-size: 15px;
}

.inspector-header button {
  min-height: 30px;
  padding: 4px 10px;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
}

.warning-list {
  display: grid;
  gap: 6px;
}

.warning-list button,
.overflow-warning {
  display: grid;
  gap: 2px;
  padding: 8px;
  text-align: left;
}

.warning-list button.error,
.overflow-warning.error {
  border: 1px solid #fda29b;
  border-radius: 6px;
  background: #fff4f3;
  color: var(--red);
}

.warning-list button.note {
  border-color: #cfd7e4;
  background: #f8fafc;
}

.warning-list span,
.overflow-warning span,
.empty,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #ffffff;
  color: var(--text);
}

.field textarea {
  resize: vertical;
  font-family: var(--font-body);
  line-height: 1.55;
}

.block-editor-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
}

.block-editor-toolbar button {
  min-height: 30px;
  padding: 4px 10px;
}

.block-editor-toolbar small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.content-edit-surface {
  min-height: 220px;
  max-height: 42vh;
  overflow: auto;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #ffffff;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.content-edit-surface:focus {
  outline: 2px solid rgba(37, 99, 235, 0.22);
  outline-offset: -2px;
}

.content-math-token {
  display: inline-flex;
  align-items: center;
  min-height: 1.55em;
  margin: 0 2px;
  padding: 0 4px;
  border-radius: 4px;
  background: #f4f3ff;
  box-shadow: inset 0 0 0 1px rgba(143, 140, 247, 0.22);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.92em;
  vertical-align: baseline;
  cursor: pointer;
}

.content-math-token.display {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 8px auto;
  padding: 5px 10px;
}

.content-math-token.editing {
  background: #fff7ed;
  box-shadow:
    inset 0 0 0 1px rgba(245, 158, 11, 0.42),
    0 0 0 2px rgba(245, 158, 11, 0.12);
}

.equation-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.36);
}

.card-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.34);
}

.card-edit-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: min(820px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  overflow: hidden;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.24);
}

.card-edit-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card-edit-title h2,
.card-edit-title p {
  margin: 0;
}

.card-edit-title h2 {
  font-size: 18px;
}

.card-edit-title p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.card-edit-body {
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.card-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.equation-modal-card {
  display: grid;
  gap: 12px;
  width: min(980px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.26);
}

.equation-modal-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.equation-modal-title h2,
.equation-modal-title p {
  margin: 0;
}

.equation-modal-title h2 {
  font-size: 18px;
}

.equation-modal-title p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.equation-modal-body,
.equation-editor-box,
.equation-latex-field {
  display: grid;
  gap: 10px;
}

.latex-palette {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.latex-palette-group {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  align-items: start;
}

.latex-palette-group strong {
  color: var(--muted);
  font-size: 12px;
  line-height: 28px;
}

.latex-palette-group div {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.latex-palette button,
.content-edit-insert-row button {
  min-height: 28px;
  padding: 3px 8px;
}

.equation-editor-box {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.equation-editor-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.equation-editor-heading strong {
  font-size: 13px;
}

.equation-editor-heading span,
.equation-latex-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.equation-visual-editor {
  min-height: 176px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-family: "Times New Roman", "Cambria Math", serif;
  font-size: 19px;
  line-height: 1.8;
  overflow: auto;
}

.equation-visual-editor:focus,
#content-edit-equation:focus {
  outline: 2px solid rgba(37, 99, 235, 0.22);
  outline-offset: 0;
}

#content-edit-equation {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.55;
}

.eq-cell {
  display: inline-block;
  min-width: 1.4em;
  min-height: 1.35em;
  padding: 0 4px;
  border-radius: 4px;
  background: #f8fbff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.16);
  text-align: center;
  vertical-align: middle;
}

.eq-cell:focus {
  background: #eef4ff;
  outline: 2px solid rgba(37, 99, 235, 0.32);
  outline-offset: 1px;
}

.eq-frac {
  display: inline-grid;
  grid-template-rows: minmax(1.35em, auto) 1px minmax(1.35em, auto);
  gap: 2px;
  align-items: center;
  min-width: 2.2em;
  margin: 0 4px;
  vertical-align: middle;
}

.eq-frac::before {
  content: "";
  grid-row: 2;
  border-top: 1px solid currentColor;
}

.eq-frac .num {
  grid-row: 1;
}

.eq-frac .den {
  grid-row: 3;
}

.eq-sqrt {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  margin: 0 4px;
  vertical-align: middle;
}

.eq-sqrt-mark {
  padding: 0 3px 0 0;
  font-size: 1.18em;
}

.eq-sqrt .radicand {
  border-top: 1px solid currentColor;
  border-radius: 0 4px 4px 0;
}

.eq-script {
  display: inline-flex;
  align-items: center;
  margin: 0 3px;
  vertical-align: middle;
}

.eq-script-stack {
  display: inline-grid;
  gap: 1px;
  margin-left: 1px;
  font-size: 0.72em;
  line-height: 1.1;
}

.eq-delimited {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 3px;
  vertical-align: middle;
}

.eq-delimiter {
  font-size: 1.45em;
  line-height: 1;
}

.eq-matrix {
  display: inline-flex;
  align-items: center;
  margin: 0 5px;
  vertical-align: middle;
}

.eq-matrix::before,
.eq-matrix::after {
  font-size: 2.2em;
  line-height: 1;
}

.eq-matrix::before {
  content: "(";
}

.eq-matrix::after {
  content: ")";
}

.eq-matrix table {
  border-collapse: separate;
  border-spacing: 5px 3px;
}

.eq-matrix td {
  padding: 0;
}

.content-edit-insert-row {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.equation-preview {
  min-height: 76px;
  padding: 12px;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  background: #fbfdff;
  overflow-x: auto;
}

.equation-close-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid #fedf89;
  border-radius: 8px;
  background: #fffcf5;
  color: #92400e;
}

.equation-close-confirm div {
  display: flex;
  gap: 6px;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
}

.panel-actions button {
  min-height: 32px;
  padding: 4px 10px;
}

.card-layout-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-layout-actions button {
  min-height: 30px;
  padding: 4px 9px;
}

.card-layout-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
  padding-right: 2px;
}

.card-layout-row {
  display: grid;
  grid-template-columns: 20px 42px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  min-height: 42px;
  padding: 7px;
  text-align: left;
  background: #ffffff;
}

.card-layout-row.active {
  border-color: var(--flow-accent);
  background: #fbfaff;
}

.card-layout-row.dragging {
  opacity: 0.45;
}

.card-layout-row.drop-target {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.drag-handle {
  color: var(--muted);
  font-size: 14px;
  cursor: grab;
}

.card-layout-number {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.card-layout-row strong {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.35;
}

.card-layout-row em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

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

.graph-title-field {
  grid-column: 1 / -1;
}

.graph-editor-preview {
  min-height: 238px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.graph-editor-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed #cfd7e4;
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
}

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

.rendered-graph {
  touch-action: none;
  cursor: grab;
  transition: box-shadow 0.12s ease;
}

.graph-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.graph-canvas {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 16 / 11;
  border: 1px solid #cfd7e4;
  border-radius: 8px;
  background: #ffffff;
}

.graph-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-canvas .axis {
  stroke: #1f2937;
  stroke-width: 1.2;
  fill: none;
}

.graph-canvas .grid {
  stroke: #e5e7eb;
  stroke-width: 0.8;
  fill: none;
}

.graph-canvas .curve {
  stroke: #2563eb;
  stroke-width: 2.4;
  fill: none;
}

.graph-canvas .point {
  fill: #b42318;
}

.graph-canvas marker path {
  fill: #1f2937;
}

.graph-label {
  position: absolute;
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.84);
  color: #111827;
  font-family: var(--font-math);
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
}

.graph-label[data-editable-label="true"] {
  cursor: move;
}

.graph-label.selected {
  box-shadow:
    0 0 0 2px rgba(143, 140, 247, 0.3),
    0 4px 10px rgba(28, 39, 54, 0.12);
}

.graph-label.locked {
  opacity: 0.82;
}

.axis-label {
  background: transparent;
}

.math-label mjx-container {
  margin: 0 !important;
}

.boot-error {
  margin: 20px;
  padding: 16px;
  border: 1px solid #fda29b;
  border-radius: 8px;
  background: #fff4f3;
  white-space: pre-wrap;
}

.measure-root {
  position: absolute;
  left: -20000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

.measure-root .measure-box {
  overflow: visible;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar,
  .inspector {
    height: auto;
  }

  .workspace-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    align-items: start;
  }

  .preview-stage {
    padding: 14px;
  }

  .paper-page {
    transform: scale(0.46);
    transform-origin: top left;
  }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  body {
    background: #ffffff;
  }

  .sidebar,
  .inspector,
  .workspace-toolbar {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-stage {
    display: block;
    min-height: 0;
    padding: 0;
    overflow: visible;
  }

  .paper-page {
    width: 210mm;
    height: 297mm;
    transform: none !important;
    box-shadow: none;
    overflow: hidden;
  }

  .mobile-page,
  .landscape-page {
    display: none !important;
  }
}
