/* ══ Material editor and teacher blocks ═════════════════════════════════════
   Two halves: what students read (rich text, headings, boxes, quotes, tables,
   images a teacher added) and what the teacher edits with (the editor chrome).
   Colours come from the theme tokens so both themes and the ambient scene
   work; palette classes (hl-*, tc-*) are the only colours rich text carries.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Rich text as students read it ─────────────────────────────────────── */
.aula-rich { font-size: inherit; line-height: 1.7; color: var(--text-primary); overflow-wrap: anywhere; }
/* Teacher text reads at the lesson's own body size, not the card's smaller default. */
.study-topic-wrapper .aula-rich { font-size: 17px; line-height: 1.7; }
@media (min-width: 1500px) { .study-topic-wrapper .aula-rich { font-size: 18px; } }
.aula-rich > :first-child { margin-top: 0; }
.aula-rich > :last-child { margin-bottom: 0; }
.aula-rich p { margin: 0 0 .75em; }
.aula-rich h2 { font-size: 1.35em; font-weight: 700; line-height: 1.3; margin: 1.1em 0 .45em; letter-spacing: -.01em; }
.aula-rich h3 { font-size: 1.12em; font-weight: 650; line-height: 1.35; margin: 1em 0 .4em; }
.aula-rich h4 { font-size: 1em; font-weight: 650; margin: .9em 0 .35em; }
.aula-rich ul, .aula-rich ol { margin: 0 0 .75em; padding-inline-start: 1.4em; }
.aula-rich li { margin: .2em 0; }
.aula-rich a { color: var(--accent-light, var(--accent)); text-decoration: underline; text-underline-offset: 2px; }
.aula-rich code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; padding: .08em .35em; border-radius: 5px; background: color-mix(in srgb, var(--text-primary) 8%, transparent); }
.aula-rich blockquote { margin: 0 0 .75em; }
.pedagogy-guide-block + .aula-rich, .aula-rich + .pedagogy-rules-container { margin-top: 18px; }

/* Highlights: pale fills in the light theme, translucent ones in the dark. */
.aula-rich mark, .ae-swatch--hl { color: inherit; border-radius: 3px; padding: 0 .12em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl-yellow { background: #fde68a; }
.hl-green  { background: #bbf7d0; }
.hl-blue   { background: #bfdbfe; }
.hl-pink   { background: #fbcfe8; }
.hl-orange { background: #fed7aa; }
.tc-red    { color: #dc2626; }
.tc-orange { color: #ea580c; }
.tc-green  { color: #15803d; }
.tc-blue   { color: #2563eb; }
.tc-purple { color: #9333ea; }
.tc-gray   { color: #6b7280; }
html[data-theme="dark"] .hl-yellow, html:not([data-theme="light"]) .hl-yellow { background: rgba(250, 204, 21, .32); }
html[data-theme="dark"] .hl-green,  html:not([data-theme="light"]) .hl-green  { background: rgba(74, 222, 128, .28); }
html[data-theme="dark"] .hl-blue,   html:not([data-theme="light"]) .hl-blue   { background: rgba(96, 165, 250, .30); }
html[data-theme="dark"] .hl-pink,   html:not([data-theme="light"]) .hl-pink   { background: rgba(244, 114, 182, .30); }
html[data-theme="dark"] .hl-orange, html:not([data-theme="light"]) .hl-orange { background: rgba(251, 146, 60, .32); }
html[data-theme="dark"] .tc-red,    html:not([data-theme="light"]) .tc-red    { color: #f87171; }
html[data-theme="dark"] .tc-orange, html:not([data-theme="light"]) .tc-orange { color: #fb923c; }
html[data-theme="dark"] .tc-green,  html:not([data-theme="light"]) .tc-green  { color: #4ade80; }
html[data-theme="dark"] .tc-blue,   html:not([data-theme="light"]) .tc-blue   { color: #60a5fa; }
html[data-theme="dark"] .tc-purple, html:not([data-theme="light"]) .tc-purple { color: #c084fc; }
html[data-theme="dark"] .tc-gray,   html:not([data-theme="light"]) .tc-gray   { color: #9ca3af; }

/* ── Teacher blocks as students read them ──────────────────────────────── */
.ae-h { color: var(--text-primary); letter-spacing: -.01em; line-height: 1.3; }
.ae-h--2 { font-size: 1.45em; font-weight: 700; margin: 1.2em 0 .5em; }
.ae-h--3 { font-size: 1.15em; font-weight: 650; margin: 1em 0 .4em; }
.study-card > .ae-h:first-child { margin-top: 0; }
.study-card > .aula-rich, .study-card > .ae-callout, .study-card > .ae-quote,
.study-card > .ae-figure, .study-card > .ae-table-wrap { margin-bottom: 18px; }

.ae-callout {
  --tone: #3b82f6;
  position: relative;
  border-radius: 14px;
  padding: 14px 18px 16px;
  background: color-mix(in srgb, var(--tone) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
}
.ae-callout--info    { --tone: #3b82f6; }
.ae-callout--tip     { --tone: #eab308; }
.ae-callout--warning { --tone: #f97316; }
.ae-callout--success { --tone: #22c55e; }
.ae-callout--note    { --tone: #a855f7; }
.ae-callout__head { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: .92em; color: color-mix(in srgb, var(--tone) 70%, var(--text-primary)); margin-bottom: 6px; }
.ae-callout__icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--tone); }

.ae-quote {
  margin: 0;
  padding: 6px 0 6px 18px;
  border-inline-start: 3px solid var(--accent);
  font-style: italic;
  color: var(--text-secondary);
}
.ae-divider { border: 0; height: 1px; margin: 24px 0; background: var(--line); }
.ae-figure { margin: 0; text-align: center; }
.ae-figure img { max-width: 100%; height: auto; border-radius: 12px; display: inline-block; }
.ae-figure figcaption { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.ae-table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }
.ae-table { width: 100%; border-collapse: collapse; font-size: .95em; }
.ae-table th, .ae-table td { padding: 10px 14px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--line); }
.ae-table tr:last-child > * { border-bottom: 0; }
.ae-table th { font-weight: 650; background: color-mix(in srgb, var(--text-primary) 5%, transparent); }
.ae-table td + td, .ae-table th + th { border-inline-start: 1px solid var(--line); }
.ae-empty-page { text-align: center; padding: 40px; color: var(--text-muted); }

/* ── The toolbar's edit button ─────────────────────────────────────────── */
.mtoolbar__edit { flex-shrink: 0; color: var(--text-secondary); }
.mtoolbar__edit svg { width: var(--icon, 18px); height: var(--icon, 18px); }
.mtoolbar__edit.is-on { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.mtoolbar__regen { flex-shrink: 0; color: var(--text-secondary); }
.mtoolbar__regen svg { width: var(--icon, 18px); height: var(--icon, 18px); }

/* ── Editor ────────────────────────────────────────────────────────────── */
/* Every edit re-renders the page; the reader's fade-in would flash it each time. */
.study-topic-wrapper.is-editing, .study-topic-wrapper.is-editing .study-card { animation: none !important; }
.study-topic-wrapper.is-editing .study-card { padding: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; }
.study-topic-wrapper.is-editing .study-page-heading { display: none; }
.study-topic-wrapper.is-editing .study-footer-nav { margin-top: 28px; }

.ae { --ae-surface: var(--s1, var(--surface-1)); --ae-well: color-mix(in srgb, var(--text-primary) 4%, var(--ae-surface)); display: flex; flex-direction: column; gap: 14px; font-size: 16px; }
.ae svg { width: 16px; height: 16px; flex-shrink: 0; }

.ae-bar {
  position: sticky; top: 64px; z-index: 30;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px 8px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--ae-surface) 88%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px -18px rgba(0, 0, 0, .55);
}
.ae-bar__badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--accent); }
.ae-bar__status { font-size: 12.5px; color: var(--text-muted); padding-inline-start: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ae-bar__status[data-status="dirty"], .ae-bar__status[data-status="saving"] { color: var(--text-secondary); }
.ae-bar__status[data-status="error"] { color: var(--danger); }
.ae-bar__spacer { flex: 1; }
.ae-ibtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px; border: 0; background: transparent;
  color: var(--text-secondary); cursor: pointer; transition: background .15s, color .15s;
}
.ae-ibtn:hover:not(:disabled) { background: var(--fill-hover, color-mix(in srgb, var(--text-primary) 8%, transparent)); color: var(--text-primary); }
.ae-ibtn:disabled { opacity: .35; cursor: default; }
.ae-done {
  height: 32px; padding: 0 16px; border-radius: 9px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-contrast, #fff); font-weight: 650; font-size: 13.5px;
}
.ae-done:hover { filter: brightness(1.06); }

.ae-title-row { display: flex; flex-direction: column; gap: 6px; }
.ae-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ae-field--wide { grid-column: 1 / -1; }
.ae-field__label { font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: .01em; }
.ae-input, .ae-rich, .ae-cell {
  outline: none; min-width: 0; cursor: text;
  border-radius: 10px; transition: box-shadow .15s, background .15s, border-color .15s;
}
.ae-input {
  padding: 8px 11px; min-height: 38px; line-height: 1.5; font-size: 15px;
  background: var(--ae-well); border: 1px solid var(--line); color: var(--text-primary);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.ae-input--target { font-weight: 550; }
.ae-input--title { font-size: 26px; font-weight: 700; letter-spacing: -.015em; padding: 10px 14px; border-radius: 12px; line-height: 1.25; }
.ae-input--heading { flex: 1; font-weight: 700; }
.ae-input--h2 { font-size: 22px; }
.ae-input--h3 { font-size: 18px; }
.ae-input--inline { flex: 1; padding: 2px 6px; min-height: 0; background: transparent; border-color: transparent; font-weight: 650; color: inherit; }
.ae-rich {
  padding: 12px 14px; min-height: 90px;
  background: var(--ae-well); border: 1px solid var(--line);
}
.ae-input:focus, .ae-rich:focus, .ae-cell:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
[contenteditable][data-placeholder]:empty::before { content: attr(data-placeholder); color: var(--text-muted); opacity: .75; pointer-events: none; }

.ae-blocks { display: flex; flex-direction: column; }
.ae-block {
  position: relative;
  border-radius: 16px; padding: 12px 14px 14px;
  background: var(--ae-surface); border: 1px solid var(--line);
  transition: box-shadow .15s, border-color .15s, opacity .15s;
}
.ae-block:focus-within { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); box-shadow: 0 8px 26px -18px rgba(0, 0, 0, .5); }
.ae-block.is-dragging { opacity: .45; }
.ae-block.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.ae-block.drop-after { box-shadow: 0 3px 0 var(--accent); }
.ae-block__tools { display: flex; align-items: center; justify-content: flex-end; gap: 2px; margin: -4px -6px 6px 0; opacity: .55; transition: opacity .15s; }
.ae-block:hover .ae-block__tools, .ae-block:focus-within .ae-block__tools { opacity: 1; }
.ae-block__tools .ae-ibtn { width: 28px; height: 28px; }
.ae-grip { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin-inline-end: auto; border-radius: 8px; color: var(--text-muted); cursor: grab; }
.ae-grip:hover { background: color-mix(in srgb, var(--text-primary) 7%, transparent); }
.ae-grip:active { cursor: grabbing; }

.ae-insert { display: flex; justify-content: center; padding: 6px 0; }
.ae-insert__btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px;
  border-radius: 999px; border: 1px dashed color-mix(in srgb, var(--text-primary) 22%, transparent);
  background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
  opacity: .55; transition: opacity .15s, color .15s, border-color .15s, background .15s;
}
.ae-insert__btn svg { width: 14px; height: 14px; }
.ae-insert:hover .ae-insert__btn, .ae-insert__btn:focus-visible { opacity: 1; color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

.ae-ai__label { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.ae-sec { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.ae-sec:first-of-type { border-top: 0; padding-top: 0; }
.ae-sec__title { margin: 0; font-size: 14px; font-weight: 650; color: var(--text-secondary); }
.ae-card { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--text-primary) 3%, transparent); border: 1px solid var(--line); }
.ae-card__tools { display: flex; justify-content: flex-end; gap: 2px; margin: -6px -6px -4px 0; }
.ae-card__tools .ae-ibtn { width: 26px; height: 26px; }
.ae-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ae-line { display: grid; grid-template-columns: minmax(90px, 160px) minmax(0, 1fr); gap: 8px; }
.ae-add {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 9px; border: 1px dashed var(--line); background: transparent; color: var(--text-secondary);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.ae-add:hover { color: var(--accent); border-color: var(--accent); }
.ae-muted { color: var(--text-muted); font-size: 13px; margin: 0; }

.ae-options { display: flex; flex-direction: column; gap: 8px; }
.ae-option { display: flex; align-items: flex-start; gap: 8px; }
.ae-option__body { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ae-option__mark {
  flex-shrink: 0; width: 34px; height: 38px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--ae-well); color: transparent;
  display: inline-flex; align-items: center; justify-content: center;
}
.ae-option__mark:hover { color: var(--text-muted); }
.ae-option.is-correct .ae-option__mark { background: #22c55e; border-color: #22c55e; color: #fff; }
.ae-option.is-correct .ae-input { border-color: color-mix(in srgb, #22c55e 55%, transparent); }

.ae-heading { display: flex; align-items: center; gap: 10px; }
.ae-seg { display: inline-flex; padding: 3px; border-radius: 10px; background: color-mix(in srgb, var(--text-primary) 6%, transparent); flex-shrink: 0; }
.ae-seg button { border: 0; background: transparent; color: var(--text-muted); font-weight: 700; font-size: 12px; height: 28px; min-width: 34px; border-radius: 8px; cursor: pointer; }
.ae-seg button.is-on { background: var(--ae-surface); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }

.ae-callout--edit { display: flex; flex-direction: column; gap: 8px; }
.ae-callout--edit .ae-rich { background: color-mix(in srgb, var(--ae-surface) 60%, transparent); min-height: 60px; }
.ae-tones { display: flex; gap: 6px; }
.ae-tone { --tone: #3b82f6; width: 30px; height: 30px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid color-mix(in srgb, var(--tone) 35%, transparent); background: color-mix(in srgb, var(--tone) 12%, transparent); color: var(--tone); }
.ae-tone.is-on { box-shadow: 0 0 0 2px var(--tone); }
.ae-tone--info { --tone: #3b82f6; } .ae-tone--tip { --tone: #eab308; } .ae-tone--warning { --tone: #f97316; }
.ae-tone--success { --tone: #22c55e; } .ae-tone--note { --tone: #a855f7; }

.ae-quote-edit .ae-rich { border-inline-start: 3px solid var(--accent); font-style: italic; }
.ae-image { display: flex; flex-direction: column; gap: 8px; }
.ae-image img { max-width: 100%; max-height: 360px; object-fit: contain; border-radius: 12px; align-self: center; }
.ae-image__empty { display: flex; align-items: center; justify-content: center; height: 120px; border-radius: 12px; border: 1px dashed var(--line); color: var(--text-muted); font-size: 13px; }
.ae-table--edit td, .ae-table--edit th { padding: 0; }
.ae-cell { padding: 9px 12px; min-height: 40px; border-radius: 0; border: 1px solid transparent; }
.ae-table-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ae-chip {
  height: 28px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--line); background: transparent;
  color: var(--text-secondary); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.ae-chip:hover { color: var(--text-primary); border-color: color-mix(in srgb, var(--text-primary) 30%, transparent); }
.ae-chip.is-on { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ── Floating layers: menus, the format bar, dialogs ───────────────────── */
.ae-menu, .ae-fmt, .ae-dialog__panel {
  --ae-surface: var(--s1, var(--surface-1));
  background: color-mix(in srgb, var(--ae-surface) 96%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px -12px rgba(0, 0, 0, .55);
}
.ae-menu { position: fixed; z-index: 3000; min-width: 220px; padding: 6px; border-radius: 14px; display: flex; flex-direction: column; }
.ae-menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px;
  border: 0; border-radius: 9px; background: transparent; color: var(--text-primary); font-size: 14px; text-align: start; cursor: pointer;
}
.ae-menu__item svg { width: 16px; height: 16px; color: var(--text-secondary); fill: none; stroke: currentColor; stroke-width: 2; }
.ae-menu__item:hover:not(:disabled), .ae-menu__item:focus-visible { background: color-mix(in srgb, var(--text-primary) 8%, transparent); outline: none; }
.ae-menu__item:disabled { opacity: .4; cursor: default; }
.ae-menu__item.is-danger, .ae-menu__item.is-danger svg { color: var(--danger); }
.ae-menu__sep { height: 1px; margin: 5px 4px; background: var(--line); }

.ae-fmt {
  position: fixed; z-index: 3000; display: none; align-items: center; gap: 2px; flex-wrap: wrap; max-width: calc(100vw - 16px);
  padding: 5px; border-radius: 12px;
}
.ae-fmt.is-on { display: flex; }
.ae-fmt button {
  min-width: 30px; height: 30px; padding: 0 6px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-primary); font-size: 13.5px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.ae-fmt button svg { width: 16px; height: 16px; }
.ae-fmt button:hover { background: color-mix(in srgb, var(--text-primary) 9%, transparent); }
.ae-fmt__sep { width: 1px; height: 20px; margin: 0 3px; background: var(--line); }
.ae-fmt__group { display: inline-flex; gap: 3px; align-items: center; }
.ae-fmt .ae-swatch { min-width: 22px; width: 22px; height: 22px; padding: 0; border-radius: 6px; border: 1px solid color-mix(in srgb, var(--text-primary) 18%, transparent); }
.ae-fmt .ae-swatch--tc { background: transparent; font-weight: 800; font-size: 14px; }

.ae-dialog { position: fixed; inset: 0; z-index: 3100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .45); }
.ae-dialog__panel { width: min(520px, 100%); max-height: min(640px, 90vh); display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: 18px; }
.ae-dialog__head { display: flex; align-items: center; justify-content: space-between; }
.ae-dialog__head h3 { margin: 0; font-size: 18px; }
.ae-revs { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.ae-rev { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); }
.ae-rev__when { font-weight: 600; font-size: 14px; }
.ae-rev.is-current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.ae-rev__now { font-size: 12px; font-weight: 600; color: var(--accent); white-space: nowrap; padding: 4px 10px; }

@media (max-width: 640px) {
  .ae-bar { top: calc(var(--topnav-h, 56px) + 52px); }
  .ae-bar__status { display: none; }
  .ae-grid2, .ae-line { grid-template-columns: minmax(0, 1fr); }
  .ae-input--title { font-size: 21px; }
  .ae-block { padding: 10px; }
}

/* A page being rewritten by AI: readable, not editable, clearly busy. */
.ae.is-regenerating .ae-blocks,
.ae.is-regenerating .ae-title-row { opacity: .45; pointer-events: none; transition: opacity .2s; }
.ae.is-regenerating .ae-bar__status::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: ae-spin .8s linear infinite;
}
@keyframes ae-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ae.is-regenerating .ae-bar__status::before { animation: none; } }
