* { box-sizing:border-box; }

:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color:#182033;
  background:#f4f7fb;
  --primary:#5b5bd6;
  --border:#e3e8f0;
  --muted:#6b7587;
}

body {
  margin:0;
  min-height:100vh;
  background:
    radial-gradient(circle at 0 0, rgba(91,91,214,.08), transparent 25%),
    #f4f7fb;
}

button,select,math-field { font:inherit; }

.app-header {
  position:sticky;
  top:0;
  z-index:50;
  background:rgba(15,23,42,.97);
  box-shadow:0 10px 30px rgba(15,23,42,.12);
}

.app-header-inner {
  max-width:1440px;
  height:72px;
  margin:auto;
  padding:0 24px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.brand { display:flex;align-items:center;gap:12px; }
.brand-icon {
  width:42px;height:42px;border-radius:13px;
  display:grid;place-items:center;
  color:#fff;font-weight:900;
  background:linear-gradient(135deg,#7c66ff,#5548d9);
}
.brand-copy strong { display:block;color:#fff; }
.brand-copy span { display:block;color:#aeb9cb;font-size:.76rem;margin-top:2px; }
.header-badge {
  padding:7px 11px;border:1px solid rgba(255,255,255,.12);
  border-radius:999px;color:#cfd6e2;background:rgba(255,255,255,.05);
  font-size:.73rem;font-weight:700;
}

.app-shell {
  max-width:1440px;
  margin:30px auto;
  padding:0 20px 36px;
  display:grid;
  grid-template-columns:minmax(470px,570px) minmax(0,1fr);
  gap:26px;
  align-items:start;
}

.editor-panel,.preview-card {
  background:#fff;
  border:1px solid var(--border);
  border-radius:24px;
  box-shadow:0 18px 55px rgba(24,32,51,.08);
}

.editor-panel { padding:28px; }

.kicker {
  display:block;margin-bottom:6px;
  color:#6868c5;font-size:.67rem;font-weight:900;letter-spacing:.14em;
}

.panel-heading h1,.preview-top h2 {
  margin:0;color:#162033;letter-spacing:-.035em;
}
.panel-heading h1 { font-size:1.72rem; }
.panel-heading p { margin:10px 0 0;color:var(--muted);font-size:.92rem;line-height:1.55; }

.toolbar-section {
  margin-top:24px;padding:16px;
  border:1px solid #e5e8f3;border-radius:17px;
  background:linear-gradient(180deg,#fafaff,#f7f8fc);
}
.toolbar-heading {
  display:flex;justify-content:space-between;align-items:center;
  margin-bottom:12px;color:#3c4659;font-size:.82rem;font-weight:850;
}
.link-button,.clear-button {
  border:0;background:transparent;color:#5d5dc7;cursor:pointer;font-weight:750;
}
.symbol-palette {
  display:grid;
  grid-template-columns:repeat(8,minmax(0,1fr));
  gap:8px;
}
.symbol-palette.hidden { display:none; }
.symbol-palette button {
  min-height:58px;padding:7px 3px;
  border:1px solid #e1e5ee;border-radius:11px;
  background:#fff;color:#202a3b;cursor:pointer;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
}
.symbol-palette button:hover { border-color:#b9b9ec;background:#faf9ff; }
.symbol-palette b { font-family:Georgia,serif;font-size:1.1rem;font-weight:600; }
.symbol-palette small { font-size:.58rem;color:#8a93a3; }
.symbol-fraction {
  width:20px;display:flex;flex-direction:column;align-items:center;
  font-family:Georgia,serif;font-weight:700;line-height:.85;
}
.symbol-fraction i { font-style:normal;font-size:.75rem; }
.symbol-fraction i:first-child { width:100%;padding-bottom:2px;border-bottom:1px solid; }

.solution-editor-card {
  margin-top:22px;
  border:1px solid #dfe4ec;
  border-radius:18px;
  overflow:hidden;
  background:#fbfcfe;
}
.solution-editor-top {
  padding:14px 16px;
  display:flex;align-items:center;justify-content:space-between;
  border-bottom:1px solid #e7ebf1;
  background:#f8f9fc;
}
.solution-editor-top strong { display:block;font-size:.93rem;color:#2c3547; }

.solution-canvas {
  min-height:330px;
  max-height:540px;
  overflow:auto;
  padding:18px 18px 24px;
  background:#fff;
  display:flex;
  flex-direction:column;
  gap:2px;
}

.math-line {
  position:relative;
  border-radius:10px;
  transition:background .15s ease;
}
.math-line.active { background:#f7f6ff; }

math-field.math-line-field {
  display:block;
  width:100%;
  min-height:56px;
  padding:11px 12px;
  border:0;
  background:transparent;
  color:#111827;
  font-size:1.25rem;
  outline:none;
  --caret-color:#5b5bd6;
  --selection-background-color:rgba(91,91,214,.15);
}

.canvas-help {
  padding:10px 15px;
  border-top:1px solid #e9edf2;
  display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;
  color:#8a94a3;font-size:.69rem;
}

.settings-card {
  margin-top:20px;padding:15px;
  border:1px solid #e5e9f0;border-radius:16px;
  background:#fafbfc;
  display:grid;grid-template-columns:repeat(2,1fr);gap:10px;
}
.setting label { display:block;margin-bottom:7px;color:#515d70;font-size:.7rem;font-weight:850; }
.setting select {
  width:100%;padding:10px 11px;border:1px solid #d8dfe9;
  border-radius:10px;background:#fff;color:#263247;
}

.editor-actions { margin-top:18px;display:flex;gap:9px; }
.primary-button,.ghost-button { border-radius:12px;font-weight:800;cursor:pointer; }
.primary-button {
  flex:1;padding:12px 17px;border:0;color:white;
  background:linear-gradient(135deg,#5c5bdd,#6a56d8);
  box-shadow:0 9px 22px rgba(91,91,214,.24);
}
.ghost-button { padding:12px 15px;border:1px solid #d9dfe8;background:#fff;color:#435065; }

.status-box {
  margin-top:13px;min-height:40px;padding:10px 12px;border-radius:11px;
  background:#f7f9fb;display:flex;align-items:center;gap:8px;
  color:#687387;font-size:.78rem;
}
.status-dot { width:7px;height:7px;border-radius:50%;background:#79a989; }

.preview-panel { position:sticky;top:98px; }
.preview-card { overflow:hidden; }

.preview-top {
  padding:19px 21px;display:flex;align-items:center;justify-content:space-between;
  border-bottom:1px solid #edf0f5;
}
.preview-chip {
  padding:6px 9px;border-radius:999px;background:#f0efff;color:#6464be;
  font-size:.69rem;font-weight:850;
}

.board {
  position:relative;
  aspect-ratio:16/9;
  margin:20px;
  border-radius:18px;
  overflow-y:auto;
  overflow-x:hidden;
  padding:34px 42px;
  display:block;
}
.board-chalk {
  color:#f4f5ef;
  background:
    radial-gradient(circle at 20% 15%,rgba(255,255,255,.028),transparent 22%),
    linear-gradient(135deg,#16241f,#0c1713 69%,#18251f);
  box-shadow:inset 0 0 80px rgba(0,0,0,.28);
}
.board-white { color:#1c2535;background:#fff;border:9px solid #d7dce4; }
.board-paper {
  color:#1d2939;
  background:repeating-linear-gradient(to bottom,#fffdf8 0,#fffdf8 34px,#dce7f2 35px,#fffdf8 36px);
}
.board-grid {
  color:#1d2939;background-color:#fffef9;
  background-image:linear-gradient(#e0e7ef 1px,transparent 1px),linear-gradient(90deg,#e0e7ef 1px,transparent 1px);
  background-size:27px 27px;
}

.board-watermark {
  position:absolute;right:17px;bottom:12px;opacity:.16;
  font-size:.64rem;font-weight:900;letter-spacing:.08em;
}

.animation-stage {
  width:100%;
  min-height:100%;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  justify-content:flex-start;
  gap:13px;
}

.preview-line {
  width:100%;
  min-height:44px;
  display:flex;
  align-items:flex-start;
  justify-content:flex-start;
}

.math-output {
  width:100%;
  display:flex;
  justify-content:flex-start;
  align-items:center;
}

.math-output svg {
  display:block;
  width:auto !important;
  height:auto !important;
  max-width:92%;
  max-height:58px;
  overflow:visible;
}

.empty-preview {
  width:100%;
  min-height:260px;
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  text-align:center;opacity:.62;gap:5px;
}
.empty-icon {
  width:52px;height:52px;border:1px solid;border-radius:15px;
  display:grid;place-items:center;font-family:Georgia,serif;font-size:1.5rem;opacity:.55;
}

.preview-bottom {
  padding:0 20px 18px;
  display:flex;justify-content:space-between;
  color:#7b8492;font-size:.71rem;
}
.preview-state { color:#5f62b9;font-weight:800; }

@media(max-width:1120px) {
  .app-shell { grid-template-columns:1fr; }
  .preview-panel { position:static; }
}
@media(max-width:700px) {
  .app-shell { padding:0 10px 25px; }
  .editor-panel { padding:18px; }
  .symbol-palette { grid-template-columns:repeat(4,minmax(0,1fr)); }
  .settings-card { grid-template-columns:1fr; }
  .board { margin:10px;padding:26px 22px; }
}



/* V2.2 — MathJax siempre hereda el color del escenario actual */
.preview-line {
  min-height: 58px;
  flex: 0 0 auto;
}

.math-output {
  min-height: 52px;
  overflow: visible;
  color: inherit;
}

.math-output > svg {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: 94%;
  max-height: 64px;
  overflow: visible !important;
  transform: none !important;
  color: inherit !important;
}

.math-output > svg g,
.math-output > svg path,
.math-output > svg use,
.math-output > svg rect,
.math-output > svg line,
.math-output > svg polygon,
.math-output > svg polyline,
.math-output > svg circle,
.math-output > svg ellipse {
  color: inherit !important;
}

.board-chalk .math-output,
.board-chalk .math-output > svg {
  color: #f4f5ef !important;
}

.board-white .math-output,
.board-white .math-output > svg,
.board-paper .math-output,
.board-paper .math-output > svg,
.board-grid .math-output,
.board-grid .math-output > svg {
  color: #1d2939 !important;
}


/* V2.3 — exportación de video */
.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 9px;
}

.video-button {
  padding: 12px 17px;
  border: 1px solid #cacdf3;
  border-radius: 12px;
  background: #f3f2ff;
  color: #5050b7;
  font-weight: 850;
  cursor: pointer;
}

.video-button:hover {
  background: #ecebff;
  border-color: #aaaee9;
}

.video-button:disabled,
.primary-button:disabled,
.ghost-button:disabled {
  opacity: .55;
  cursor: default;
}

.export-panel {
  margin-top: 13px;
  padding: 13px 14px;
  border: 1px solid #e0e5ed;
  border-radius: 13px;
  background: #fafbfe;
}

.export-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #4a566b;
  font-size: .78rem;
}

.export-panel-top strong {
  color: #5757bf;
}

.export-progress {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eaf2;
}

.export-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg,#5c5bdd,#755be0);
  transition: width .18s ease;
}

.export-panel small {
  display: block;
  margin-top: 8px;
  color: #8992a1;
  font-size: .67rem;
}

@media(max-width:700px) {
  .editor-actions {
    grid-template-columns: 1fr;
  }
}


/* V2.4 — formatos de video */
.board {
  transition:
    aspect-ratio .22s ease,
    max-width .22s ease,
    width .22s ease,
    background .2s ease,
    color .2s ease;
}

.board.format-16-9 {
  aspect-ratio: 16 / 9;
  width: auto;
}

.board.format-9-16 {
  aspect-ratio: 9 / 16;
  width: min(62%, 430px);
  min-height: 610px;
  margin-left: auto;
  margin-right: auto;
}

.board.format-1-1 {
  aspect-ratio: 1 / 1;
  width: min(82%, 620px);
  margin-left: auto;
  margin-right: auto;
}

.board.format-4-5 {
  aspect-ratio: 4 / 5;
  width: min(72%, 540px);
  margin-left: auto;
  margin-right: auto;
}

.board.format-9-16,
.board.format-4-5 {
  padding-left: 34px;
  padding-right: 34px;
}

.preview-format-note {
  font-size: .68rem;
  color: #8a93a2;
}

@media(max-width:1120px) {
  .board.format-9-16 {
    width: min(54%, 430px);
  }

  .board.format-1-1 {
    width: min(72%, 620px);
  }

  .board.format-4-5 {
    width: min(62%, 540px);
  }
}

@media(max-width:700px) {
  .settings-card {
    grid-template-columns:1fr;
  }

  .board.format-9-16,
  .board.format-1-1,
  .board.format-4-5 {
    width: 92%;
    min-height: 0;
  }
}
