/* =============================================================================
   Chapter shells — Notes, Flashcards, Summary (structure only)
   ============================================================================= */

.chapter-page {
  align-items: stretch;
  justify-content: flex-start;
  padding-top: var(--nav-offset);
  overflow: hidden;
}

/* Notes overlay: default .blank-page centers children — stretch so PDF row can use full viewport width */
#notes-page.blank-page.active {
  justify-content: flex-start;
  align-items: stretch;
}

.chapter-scroll {
  width: 100%;
  max-width: min(840px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 20px 48px;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 100%;
}

.chapter-hero {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.chapter-eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary, #64748b);
}

.chapter-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--text-primary, #0f172a);
  letter-spacing: -0.02em;
}

.chapter-lead {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-secondary, #64748b);
}

.chapter-section-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chapter-section {
  margin: 0;
}

.chapter-section-title {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary, #0f172a);
}

.chapter-slot {
  min-height: 5.5rem;
  border-radius: 12px;
  border: 1px dashed var(--border-color, #cbd5e1);
  background: rgba(148, 163, 184, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-secondary, #64748b);
  text-align: center;
}

/* Summary: infographic + language-specific subtopic strips */
.summary-infographic-card {
  margin: 0;
  border-radius: 16px;
  border: 1px solid var(--border-color, #e2e8f0);
  background: var(--bg-color, #fff);
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.summary-infographic-media {
  width: 100%;
  background: #f8fafc;
}

.summary-infographic-img {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-height: 820px) {
  .summary-infographic-media {
    max-height: min(52dvh, 560px);
    overflow: auto;
  }

  .summary-infographic-img {
    max-height: min(52dvh, 560px);
    width: auto;
    max-width: 100%;
    margin: 0 auto;
    object-fit: contain;
  }
}

.summary-infographic-actions {
  padding: 0.6rem 0.85rem;
  border-top: 1px solid var(--border-color, #e2e8f0);
  background: var(--element-bg, #f8fafc);
}

.summary-infographic-link {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-highlight, #6366f1);
  text-decoration: none;
}

.summary-infographic-link:hover {
  text-decoration: underline;
}

.summary-subtopic-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Summary Topic 2: two infographic cards per row on desktop */
#summary-panel-topic-2 .chapter-section-stack,
#summary-panel-topic-3 .chapter-section-stack,
#summary-panel-topic-4 .chapter-section-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem 1rem;
  align-items: start;
}

#summary-panel-topic-2 .chapter-section:has(.summary-infographic-card + .summary-infographic-card),
#summary-panel-topic-3 .chapter-section:has(.summary-infographic-card + .summary-infographic-card),
#summary-panel-topic-4 .chapter-section:has(.summary-infographic-card + .summary-infographic-card) {
  grid-column: 1 / -1;
}

#summary-panel-topic-2 .summary-subtopic-stack,
#summary-panel-topic-3 .summary-subtopic-stack,
#summary-panel-topic-4 .summary-subtopic-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

#summary-panel-topic-2 .summary-subtopic-stack:has(> :only-child),
#summary-panel-topic-3 .summary-subtopic-stack:has(> :only-child),
#summary-panel-topic-4 .summary-subtopic-stack:has(> :only-child) {
  grid-template-columns: 1fr;
}

@media (max-width: 900px) {
  #summary-panel-topic-2 .chapter-section-stack,
  #summary-panel-topic-3 .chapter-section-stack,
  #summary-panel-topic-4 .chapter-section-stack {
    grid-template-columns: 1fr;
  }

  #summary-panel-topic-2 .chapter-section:has(.summary-infographic-card + .summary-infographic-card),
  #summary-panel-topic-3 .chapter-section:has(.summary-infographic-card + .summary-infographic-card),
  #summary-panel-topic-4 .chapter-section:has(.summary-infographic-card + .summary-infographic-card) {
    grid-column: auto;
  }
}

@media (max-height: 820px) {
  #summary-panel-topic-2 .summary-infographic-media,
  #summary-panel-topic-3 .summary-infographic-media,
  #summary-panel-topic-4 .summary-infographic-media {
    max-height: min(42dvh, 480px);
  }

  #summary-panel-topic-2 .summary-infographic-img,
  #summary-panel-topic-3 .summary-infographic-img,
  #summary-panel-topic-4 .summary-infographic-img {
    max-height: min(42dvh, 480px);
  }
}

.summary-lang {
  display: none;
}

html[lang="en"] .summary-lang--en {
  display: block;
}

html[lang="zh-Hant"] .summary-lang--zh-hant {
  display: block;
}

/* Treat Simplified Chinese as showing the Traditional set for now */
html[lang="zh"] .summary-lang--zh-hant {
  display: block;
}

/* Notes: full-width row so PDF previews span the viewport (not a narrow reading column) */
.chapter-scroll.chapter-scroll--notes {
  max-width: none;
  width: 100%;
  padding-left: clamp(10px, 2.5vw, 28px);
  padding-right: clamp(10px, 2.5vw, 28px);
  box-sizing: border-box;
}

.notes-section-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(1rem, 2vw, 1.75rem);
  align-items: start;
}

@media (max-width: 900px) {
  .notes-section-stack {
    grid-template-columns: 1fr;
  }
}

.notes-section-stack .notes-pdf-hint {
  margin-bottom: 0.5rem;
}

.notes-section-stack .notes-pdf-frame-wrap {
  min-height: min(48dvh, 480px);
  height: min(54dvh, 560px);
}

@media (max-width: 900px) {
  .notes-section-stack .notes-pdf-frame-wrap {
    min-height: min(60dvh, 640px);
    height: min(68dvh, 760px);
  }
}

.notes-topic .chapter-section-title {
  font-size: 1.15rem;
}

.notes-pdf-hint {
  margin: 0 0 0.85rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-secondary, #64748b);
}

.notes-pdf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(0.5rem, 1.5vw, 1.25rem);
  align-items: stretch;
  width: 100%;
}

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

@media (max-width: 900px) {
  .notes-pdf-grid {
    grid-template-columns: 1fr;
  }
}

.notes-pdf-card {
  border-radius: 16px;
  border: 1px solid var(--border-color, #e2e8f0);
  overflow: hidden;
  background: var(--bg-color, #fff);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.notes-pdf-frame-wrap {
  position: relative;
  width: 100%;
  min-height: min(78dvh, 900px);
  height: min(88dvh, 1100px);
  background: #f1f5f9;
}

@media (max-width: 900px) {
  .notes-pdf-frame-wrap {
    min-height: min(70dvh, 720px);
    height: min(82dvh, 900px);
  }
}

@media (max-height: 900px) {
  .notes-pdf-frame-wrap {
    min-height: min(50dvh, 480px);
    height: min(55dvh, 600px);
  }
}

.notes-pdf-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.notes-pdf-actions {
  padding: 0.5rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  border-top: 1px solid var(--border-color, #e2e8f0);
  background: var(--element-bg, #f8fafc);
}

.notes-pdf-link {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-highlight, #6366f1);
  text-decoration: none;
}

.notes-pdf-link:hover {
  text-decoration: underline;
}

/* Flashcards */
.flash-deck-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.flash-deck-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary, #64748b);
  background: var(--element-bg, #f1f5f9);
  border: 1px solid var(--border-color, #e2e8f0);
  opacity: 0.85;
}

.flash-stage {
  border-radius: 16px;
  border: 1px solid var(--border-color, #e2e8f0);
  background: var(--bg-color, #fff);
  padding: 1.25rem;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
}

.flash-stage-inner {
  display: grid;
  gap: 0.75rem;
}

.flash-stage-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary, #94a3b8);
}

.flash-stage-face {
  min-height: 6rem;
  border-radius: 12px;
  border: 1px dashed var(--border-color, #cbd5e1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary, #64748b);
  text-align: center;
}

.flash-stage-face--back {
  background: rgba(148, 163, 184, 0.05);
}

/* Summary (reuses #settings-page): hub/detail modes override layout below. */
#settings-page.blank-page.chapter-page {
  box-sizing: border-box;
  min-height: 0;
  min-width: 0;
}

/* Summary page: override legacy settings grid */
.settings-viewport.chapter-summary-shell {
  display: flex;
  flex-direction: column;
  /* Flex/grid: allow shrinking so width:100% children don’t spill past the scrollport. */
  min-width: 0;
  /* Use 100% of the scroll parent instead of 100vw — avoids scrollbar-width overflow. */
  max-width: min(960px, 100%);
  width: 100%;
  box-sizing: border-box;
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  grid-template-columns: none;
  grid-template-rows: none;
  grid-template-areas: none;
  gap: 0;
  padding: 0;
  margin: 0 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  flex: 0 0 auto;
  overflow: visible;
  align-self: flex-start;
}

.chapter-summary-shell .chapter-scroll:not(.summary-panel-scroll) {
  max-width: none;
  flex: 0 0 auto;
  min-height: 0;
  min-width: 0;
  max-height: none;
  overflow: visible;
  /* Extra horizontal room so hero shadow + border aren’t clipped by the scrollport edge. */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

.summary-progress {
  margin-bottom: 2rem;
}

.summary-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border-color, #e2e8f0);
  overflow: hidden;
}

.summary-progress-fill {
  width: 18%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #94a3b8, #cbd5e1);
  opacity: 0.6;
}

.summary-progress-caption {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8);
}

.summary-block {
  margin-bottom: 2rem;
}

.summary-lines {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-line {
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px dashed var(--border-color, #cbd5e1);
  font-size: 0.9rem;
  color: var(--text-secondary, #64748b);
  background: rgba(148, 163, 184, 0.04);
}

.summary-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-checklist li label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-color, #e2e8f0);
  font-size: 0.9rem;
  color: var(--text-secondary, #64748b);
  cursor: default;
}

.summary-checklist input {
  opacity: 0.5;
}

/* Summary — hero infographic (full-width under scroll) */
.summary-hero-figure {
  margin: 0 0 1.75rem;
  padding: 0;
}

.summary-hero-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: none;
  /* Intrinsic aspect ratio from the file; avoid forcing a box that + overflow:hidden parents can clip */
  object-fit: contain;
  object-position: top center;
  vertical-align: middle;
  border-radius: 14px;
  border: 1px solid var(--border-color, #e2e8f0);
  box-sizing: border-box;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  background: rgba(148, 163, 184, 0.12);
}

.summary-hero-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 0.85rem;
}

.summary-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary, #0f172a);
  text-decoration: none;
  border-radius: 10px;
  border: 1px solid var(--border-color, #cbd5e1);
  background: rgba(148, 163, 184, 0.12);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.summary-download-btn:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.35);
}

.summary-download-btn:focus-visible {
  outline: 2px solid var(--text-highlight, #6366f1);
  outline-offset: 2px;
}

/* Summary — atomic structure & isotopes study guide */
.summary-study-section {
  margin-bottom: 2rem;
}

.summary-study-p {
  margin: 0 0 0.75rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-primary, #1e293b);
}

.summary-study-p:last-child {
  margin-bottom: 0;
}

.summary-study-table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0 0;
  border-radius: 12px;
  border: 1px solid var(--border-color, #e2e8f0);
  background: rgba(148, 163, 184, 0.04);
}

.summary-study-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  line-height: 1.45;
}

.summary-study-table th,
.summary-study-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  vertical-align: top;
}

.summary-study-table th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #64748b);
  background: rgba(148, 163, 184, 0.08);
}

.summary-study-table tr:last-child td {
  border-bottom: none;
}

.summary-study-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-primary, #1e293b);
}

.summary-study-list li {
  margin-bottom: 0.35rem;
}

.summary-study-callout {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border-left: 4px solid var(--text-highlight, #6366f1);
  background: rgba(99, 102, 241, 0.06);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-secondary, #475569);
}

/* Summary hub — topic picker vs detail panels */
#settings-page.blank-page.active:not(:has(.summary-shell--detail)) {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  padding-top: var(--nav-offset) !important;
  padding-bottom: clamp(12px, 3dvh, 60px) !important;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Match Worksheets: plain hub background without legacy settings ambient blobs */
#settings-page.blank-page.active:not(:has(.summary-shell--detail))::before,
#settings-page.blank-page.active:not(:has(.summary-shell--detail))::after {
  content: none;
}

#settings-page.blank-page.active:not(:has(.summary-shell--detail)) .settings-viewport.chapter-summary-shell {
  max-width: none;
  flex: 1 1 0%;
  align-self: stretch;
  height: auto;
  min-height: 0;
  overflow: hidden;
}

#settings-page.blank-page.active:has(.summary-shell--detail) {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  box-sizing: border-box !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  padding-top: var(--nav-offset) !important;
  padding-bottom: clamp(12px, 3dvh, 60px) !important;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

#settings-page.blank-page.active:has(.summary-shell--detail) .settings-viewport.chapter-summary-shell {
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
  max-width: none;
  overflow: hidden;
}

.summary-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  position: relative;
  width: 100%;
}

#summary-hub.summary-hub {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  justify-content: center;
  align-items: center;
}

.summary-hub-inner {
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.summary-hub-grid {
  max-height: none;
}

/* Single-topic hub: avoid a lone card sitting in the left column of a 2-col grid */
#settings-page.blank-page.active:not(:has(.summary-shell--detail)) .summary-hub-grid.chem-tools-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr));
  grid-template-rows: auto;
  flex: 0 0 auto;
}

#settings-page.blank-page.active:not(:has(.summary-shell--detail))
  .summary-hub-grid.chem-tools-grid:has(.summary-topic-card:only-child) {
  width: min(560px, 100%);
  margin-inline: auto;
}

button.summary-topic-card {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
}

.summary-topic-card {
  cursor: pointer;
  pointer-events: auto;
}

.summary-topic-card:focus-visible {
  outline: 2px solid var(--text-highlight, #6366f1);
  outline-offset: 2px;
}

#summary-panel-topic-2.summary-panel,
#summary-panel-topic-3.summary-panel,
#summary-panel-topic-4.summary-panel {
  display: none !important;
  flex-direction: column;
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  background: var(--bg-color);
  box-sizing: border-box;
}

.summary-shell--detail #summary-panel-topic-2.summary-panel:not([hidden]),
.summary-shell--detail #summary-panel-topic-3.summary-panel:not([hidden]),
.summary-shell--detail #summary-panel-topic-4.summary-panel:not([hidden]) {
  display: flex !important;
}

.summary-shell--detail #summary-hub {
  display: none !important;
}

.summary-panel-bar {
  flex-shrink: 0;
}

.summary-panel-scroll {
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  max-width: none;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.summary-shell--detail .summary-panel-scroll.chapter-scroll {
  flex: 1 1 0%;
  min-height: 0;
  height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: none;
}

.summary-panel-scroll::-webkit-scrollbar {
  width: 10px;
}

.summary-panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.22);
  border-radius: 999px;
}

/* =============================================================================
   Chapter draw overlay (Notes + Summary)
   ============================================================================= */

.chapter-draw-mount {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

#notes-page.blank-page.active.chapter-draw-active .chapter-scroll,
#settings-page.blank-page.active.chapter-draw-active .chapter-scroll {
  overflow: hidden;
}

.blank-page.chapter-draw-active {
  user-select: none;
  -webkit-user-select: none;
}

.chapter-draw-canvas {
  position: fixed;
  top: 60px;
  left: 0;
  width: 100vw;
  height: calc(100vh - 60px);
  z-index: 2050;
  pointer-events: none;
  touch-action: none;
  opacity: 0;
  visibility: hidden;
}

.chapter-draw-canvas.chapter-draw-canvas--on {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}

.chapter-draw-fab {
  display: none;
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  z-index: 2060;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(255, 255, 255, 0.96);
  color: #0f172a;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
  pointer-events: auto;
}

#notes-page.blank-page.active .chapter-draw-fab,
#settings-page.blank-page.active .chapter-draw-fab {
  display: flex;
}

.chapter-draw-fab[aria-pressed="true"] {
  background: #0f172a;
  color: #f8fafc;
  border-color: #0f172a;
}

.chapter-draw-toolbar {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(84px, calc(20px + env(safe-area-inset-bottom, 0px) + 52px));
  z-index: 2060;
  min-width: 200px;
  max-width: min(300px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.94);
  color: #f1f5f9;
  font-size: 0.8125rem;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.25);
  pointer-events: auto;
}

.chapter-draw-toolbar[hidden] {
  display: none !important;
}

.chapter-draw-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chapter-draw-toolbar-row:last-child {
  margin-bottom: 0;
}

.chapter-draw-tool {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.chapter-draw-tool.is-active {
  background: #f8fafc;
  color: #0f172a;
  border-color: #f8fafc;
}

.chapter-draw-width-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
}

.chapter-draw-width {
  width: 100%;
  accent-color: #38bdf8;
}

.chapter-draw-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chapter-draw-color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(248, 250, 252, 0.35);
  background: var(--dot, #0f172a);
  cursor: pointer;
  padding: 0;
}

.chapter-draw-color-dot.active {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.chapter-draw-toolbar-actions {
  margin-top: 4px;
  margin-bottom: 0;
}

.chapter-draw-clear,
.chapter-draw-done {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.chapter-draw-clear {
  background: rgba(248, 113, 113, 0.2);
  color: #fecaca;
}

.chapter-draw-done {
  background: #38bdf8;
  color: #0f172a;
}

/* Quiz tab — full-viewport iframe embed (visibility via .blank-page.active only) */
#quiz-page.quiz-embed-page {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding-top: var(--nav-offset);
  overflow: hidden;
  box-sizing: border-box;
  min-height: 0;
}

#quiz-page.quiz-embed-page.active {
  display: flex;
}

#quiz-page .quiz-embed-fs {
  position: relative;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  background: var(--bg-color, #f7f9fb);
}

#quiz-page .quiz-embed-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg-color, #f7f9fb);
  touch-action: manipulation;
  -webkit-transform: translateZ(0);
}

/* Flashcards tab — full-viewport iframe embed (Topic 2 + Topic 3) */
#flashcards-page.flashcards-embed-page {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding-top: var(--nav-offset);
  overflow: hidden;
  box-sizing: border-box;
  min-height: 0;
}

#flashcards-page.flashcards-embed-page.active {
  display: flex;
}

#flashcards-page .flashcards-embed-fs {
  position: relative;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  background: var(--bg-color, #f7f9fb);
  display: flex;
  flex-direction: column;
}

#flashcards-page .flashcards-embed-toolbars {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  z-index: 1;
  padding-top: 0.5rem;
}

#flashcards-page .flashcards-embed-toolbar {
  flex: 0 0 auto;
  display: inline-flex;
  align-self: center;
  margin: 0;
  padding: 3px;
  border-radius: 999px;
  background: #eceef0;
  border: 1px solid rgba(193, 198, 213, 0.6);
  z-index: 1;
}

#flashcards-page .flashcards-embed-toolbar--topic button {
  padding: 0.35rem 0.65rem;
  font-size: 13px;
}

@media (max-width: 640px) {
  #flashcards-page .flashcards-embed-toolbar--topic button {
    padding: 0.3rem 0.5rem;
    font-size: 11px;
  }

  #flashcards-page .flashcards-embed-toolbar button {
    padding: 0.3rem 0.6rem;
    font-size: 12px;
  }
}

#flashcards-page .flashcards-embed-toolbar button {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #414753;
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

#flashcards-page .flashcards-embed-toolbar button.active {
  background: #fff;
  color: #004e9f;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

#flashcards-page .flashcards-embed-frame {
  position: relative;
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
  border: 0;
  display: block;
  background: var(--bg-color, #f7f9fb);
  touch-action: manipulation;
  -webkit-transform: translateZ(0);
}
