/* Calamus: armazón, árbol de cuadernos, editor de bloques y sus menús. */

.cal-ico { display: inline-flex; flex: none; }
.cal-ico svg, .cal-rowbtn svg, .blk-btn svg, .cal-bubble-btn svg, .btn svg, .cal-menu-icon svg, .cal-palette-icon svg, .cal-composer-title svg, .cal-card-new svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; display: block;
}
.blk-grip svg circle { fill: currentColor; stroke: none; }
.cal-rowbtn svg circle, .icon-btn svg circle { fill: currentColor; stroke: none; }

/* ---------- barra lateral: el cuaderno abierto y su árbol de páginas ---------- */
.cal-back { display: inline-flex; align-items: center; gap: 4px; padding: 5px 8px 5px 4px; border-radius: 7px; color: var(--text-muted); text-decoration: none; font-weight: 550; }
.cal-back:hover { background: var(--surface-2); color: var(--text); }
.cal-nbhead { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 10px; }
.cal-nbname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; font-weight: 650; font-size: 1rem; }
.cal-nbname:hover { text-decoration: underline; }
.cal-tree { gap: 1px; overflow-y: auto; padding-bottom: 14px; }
.cal-newpage { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; font: inherit; color: var(--text-muted); cursor: pointer; text-align: left; margin-bottom: 2px; }
.cal-newpage:hover { color: var(--text); }
.cal-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--nb); flex: none; }
.cal-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; text-decoration: none; }
.cal-row { display: flex; align-items: center; border-radius: 7px; padding-left: calc(var(--depth, 0) * 16px); }
.cal-row:hover { background: var(--surface-2); }
.cal-row .sb-link { flex: 1; min-width: 0; align-items: center; gap: 7px; padding-left: 2px; padding-right: 2px; }
.cal-row .sb-link:hover { background: none; }
.cal-page { -webkit-touch-callout: none; }
.cal-page .cal-ico { color: var(--text-muted); }
.cal-page.current .cal-ico { color: var(--accent); }
.cal-rowbtn {
  flex: none; width: 24px; height: 24px; display: inline-grid; place-items: center;
  border: 0; border-radius: 6px; background: none; color: var(--text-muted); cursor: pointer; opacity: 0;
}
.cal-rowbtn:hover { background: var(--surface); color: var(--text); }
.cal-rowbtn.visible, .cal-row:hover .cal-rowbtn, .cal-rowbtn:focus-visible, .cal-row:has(.current) .cal-rowbtn { opacity: 1; }
.cal-twisty svg { width: 13px; height: 13px; transition: rotate 0.15s; }
.cal-twisty.open svg { rotate: 90deg; }
.cal-twisty-space { flex: none; width: 24px; }
@media (pointer: coarse) { .cal-rowbtn { opacity: 0.7; } .cal-row .cal-rowbtn:not(.cal-twisty) { width: 34px; height: 34px; } }
.cal-empty-row { margin: 4px 8px; font-size: 0.8rem; color: var(--text-muted); }

/* página de cuadernos: sin barra lateral */
body.cal-home.shell { grid-template-columns: minmax(0, 1fr); }
body.cal-home .page { grid-column: 1; }
body.cal-home .sidebar, body.cal-home .scrim, body.cal-home .cal-menu-btn { display: none; }

/* ---------- vistas ---------- */
main.cal-main { max-width: 900px; padding-top: 14px; padding-bottom: 30vh; }
.cal-h2 { font-size: 1rem !important; margin: 30px 0 10px !important; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.cal-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin: 22px 0 6px; }
.cal-card {
  position: relative; display: grid; gap: 4px; align-content: start; min-height: 96px; padding: 18px 16px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  text-decoration: none; overflow: hidden; font: inherit; text-align: left; cursor: pointer;
}
.cal-card:hover { border-color: var(--accent); }
.cal-card-band { position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--nb); }
.cal-card-new { place-items: center; align-content: center; color: var(--text-muted); border-style: dashed; background: none; }
.cal-card-new svg { width: 22px; height: 22px; }
.cal-recent { display: grid; gap: 2px; }
.cal-recent-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 4px 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; border: 0; background: none; font: inherit; text-align: left; cursor: pointer;
}
.cal-recent-item:hover { background: var(--surface); }
.cal-recent-item > span:nth-child(3) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34ch; }
.cal-recent-item.cal-add { color: var(--text-muted); grid-template-columns: auto 1fr; }
.cal-when { white-space: nowrap; }
@media (max-width: 640px) { .cal-recent-item { grid-template-columns: auto minmax(0, 1fr); } .cal-recent-item > span:nth-child(n + 3) { display: none; } }
.cal-nb-actions { margin: 6px 0 18px; }
.cal-homehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.cal-homehead h1 { margin-bottom: 0 !important; }
.cal-homesearch-wrap { margin: 18px 0 0; max-width: 520px; }
.cal-homeresults { display: grid; gap: 2px; margin-top: 10px; }
.cal-homeresults[hidden] { display: none; }
.cal-viewswitch { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--surface-2); }
.cal-viewswitch button { width: 34px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 7px; background: none; color: var(--text-muted); cursor: pointer; }
.cal-viewswitch button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.cal-viewswitch button svg circle { fill: currentColor; stroke: none; }
.cal-viewswitch button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); }
.cal-card, .cal-nbrow { -webkit-touch-callout: none; }
.cal-card-more { position: absolute; top: 10px; right: 8px; }
.cal-card:hover .cal-card-more, .cal-nbrow:hover .cal-card-more { opacity: 1; }
.cal-nblist { display: grid; gap: 2px; margin: 22px 0 6px; }
.cal-nbrow {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto 30px; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 9px; color: var(--text); text-decoration: none; border: 0; background: none; font: inherit; text-align: left; cursor: pointer;
}
.cal-nbrow:hover { background: var(--surface); }
.cal-nbrow .cal-dot { width: 12px; height: 12px; }
.cal-nbrow .cal-card-more { position: static; }
.cal-nbrow-new { grid-template-columns: auto 1fr; color: var(--text-muted); }
@media (max-width: 640px) { .cal-nbrow { grid-template-columns: auto minmax(0, 1fr) 30px; } .cal-nbrow .cal-when, .cal-nbrow > .muted:not(.cal-when) { display: none; } }
@media (pointer: coarse) { .cal-card-more { opacity: 0.7; width: 34px; height: 34px; } }

/* cuadro de ajustes del cuaderno */
.cal-dialog-wrap { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgb(0 0 0 / 0.35); }
.cal-dialog {
  width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; display: grid; gap: 16px; padding: 20px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg); color: var(--text); box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}
.cal-dialog h2 { margin: 0; font-size: 1.15rem; }
.cal-swatches { display: flex; gap: 8px; }
.cal-swatch { width: 30px; height: 30px; padding: 0; border: 2px solid var(--bg); border-radius: 50%; background: var(--nb); cursor: pointer; box-shadow: 0 0 0 1px var(--border-strong); }
.cal-swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--accent); }
.cal-toggles { display: grid; gap: 4px; }
.cal-toggles-title { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.cal-toggle { position: relative; display: flex; align-items: center; gap: 14px; padding: 10px 2px; cursor: pointer; }
.cal-toggle + .cal-toggle { border-top: 1px solid var(--border); }
.cal-toggle-text { flex: 1; display: grid; gap: 2px; }
.cal-toggle-text span { font-size: 0.8rem; color: var(--text-muted); }
.cal-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cal-switch { flex: none; position: relative; width: 40px; height: 24px; border-radius: 12px; background: var(--border-strong); transition: background 0.15s; }
.cal-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: translate 0.15s; }
.cal-toggle input:checked + .cal-switch { background: var(--accent); }
.cal-toggle input:checked + .cal-switch::after { translate: 16px 0; }
.cal-toggle input:focus-visible + .cal-switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* instalar la app y aviso de versión nueva (install.js) */
.cal-install-btn[hidden] { display: none; }
.cal-install-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.cal-update {
  position: fixed; z-index: 90; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); translate: -50% 0;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 8px 8px 8px 14px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 4px 20px rgb(0 0 0 / 0.15);
}

/* herramientas quitadas en los ajustes del cuaderno */
body.cal-no-ia .ai-fab, body.cal-no-ia .ai-mbar-btn, body.cal-no-ia .ai-panel, body.cal-no-ia .ai-pop,
body.cal-no-ia .cal-bubble-btn.ai, body.cal-no-ia .cal-bubble-btn.ask,
body.cal-no-calc .calc-fab, body.cal-no-calc .calc-mbar-btn, body.cal-no-calc .calc-panel { display: none !important; }

/* ---------- barra superior ---------- */
.cal-topbar {
  position: sticky; top: var(--mbar-h); z-index: 30; display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 8px 18px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
}
.cal-crumbs { margin: 0; min-width: 0; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.cal-crumbs > * { overflow: hidden; text-overflow: ellipsis; }
.cal-actions { display: flex; align-items: center; gap: 6px; }
.cal-topbar .top-tools { position: static; }
@media (max-width: 960px) { .cal-topbar { padding: 6px 12px; min-height: 46px; } }

/* ---------- página ---------- */
.cal-saved { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }
.page-title { outline: none; margin-bottom: 18px !important; overflow-wrap: anywhere; }
.page-title.is-empty::before, .rich.is-empty::before { content: attr(data-placeholder); color: var(--text-muted); opacity: 0.7; pointer-events: none; }
.page-title.is-empty::before { position: absolute; }
.rich.is-empty::before { position: absolute; }
.rich { position: relative; outline: none; min-height: 1.7em; overflow-wrap: anywhere; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 0.65em; }
.rich h2 { margin: 0.9em 0 0.4em; }
.rich h3 { margin: 0.8em 0 0.3em; }
.rich ul, .rich ol { margin: 0 0 0.65em; }
.rich blockquote { margin: 0 0 0.65em; padding-left: 14px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.rich code { font-family: var(--font-mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.rich a { color: var(--accent); }
.rich table { border-collapse: collapse; font-size: 0.92rem; margin: 0 0 0.65em; }
.rich th, .rich td { border: 1px solid var(--border); padding: 4px 8px; }
.rich img { max-width: 100%; height: auto; border-radius: 8px; }

/* fórmulas en línea */
.m { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.m:hover { background: var(--accent-soft); }
.m.display { display: block; text-align: center; margin: 6px 0; overflow-x: auto; }
.m .katex { font-size: 1.04em; }

/* bloques y su marco */
.blocks { display: grid; gap: 2px; }
.blk { position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); margin-left: -52px; border-radius: 8px; }
.blk-gutter { display: flex; justify-content: flex-end; align-items: flex-start; gap: 1px; padding: 4px 4px 0 0; opacity: 0; transition: opacity 0.12s; }
.blk:hover > .blk-gutter, .blk:focus-within > .blk-gutter { opacity: 1; }
.blk-btn {
  width: 22px; height: 24px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 5px; background: none; color: var(--text-muted); cursor: pointer;
}
.blk-btn:hover { background: var(--surface-2); color: var(--text); }
.blk-grip { cursor: grab; }
.blk.dragging { opacity: 0.4; }
.blk-body { grid-column: 2; min-width: 0; padding: 3px 0; }
.blk-drop-line { height: 3px; margin: -2px 0 -1px 0; border-radius: 2px; background: var(--accent); }
.blocks-tail { height: 120px; cursor: text; }
@media (max-width: 720px) {
  .blk { grid-template-columns: 24px minmax(0, 1fr); margin-left: -10px; }
  .blk-gutter { flex-direction: column; align-items: center; padding-right: 2px; opacity: 0.55; }
}

.blk-spacer { flex: 1; }
.blk-placeholder { color: var(--text-muted); font-size: 0.92rem; }
.blk-msg { margin: 4px 0 0; font-size: 0.82rem; color: var(--bad); }
.blk-msg:empty { display: none; }
.blk-help { margin: 0 0 8px; font: 0.76rem/1.5 var(--font-mono); color: var(--text-muted); }
.blk-link { border: 0; padding: 0; background: none; color: var(--accent); font: inherit; font-size: 0.84rem; cursor: pointer; text-decoration: underline; }
.blk-link.danger { color: var(--bad); }
.blk-input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); font: 0.92rem var(--font-sans); resize: vertical;
}
.blk-input.mono { font-family: var(--font-mono); font-size: 0.84rem; }
.blk-input:focus { outline: 0; border-color: var(--accent); }
.blk-field { display: grid; gap: 3px; margin-bottom: 8px; font-size: 0.78rem; color: var(--text-muted); }

/* fórmula */
.blk-formula-view { padding: 6px 0; border-radius: 8px; cursor: pointer; overflow-x: auto; min-height: 2.2em; }
.blk-formula-view:hover, .blk-formula.editing .blk-formula-view { background: var(--surface); }
.blk-formula .blk-input { margin-top: 4px; }

/* visualizaciones */
.blk-widget { position: relative; }
.blk-widget .widget { margin: 6px 0; }
.blk-widget-view:empty { min-height: 40px; }
.blk-edit {
  position: absolute; top: 12px; right: 10px; z-index: 2; padding: 3px 10px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text);
  font: 600 0.78rem var(--font-sans); cursor: pointer; opacity: 0; transition: opacity 0.12s;
}
.blk:hover .blk-edit, .blk-edit:focus-visible, .blk-widget:has(.blk-panel) .blk-edit { opacity: 1; }
@media (pointer: coarse) { .blk-edit { opacity: 0.85; } }
.blk-edit:hover { border-color: var(--accent); color: var(--accent); }
.blk-panel { margin: 0 0 10px; padding: 12px; border: 1px solid var(--accent); border-radius: 10px; background: var(--bg); }
.blk-panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }

/* imagen */
.blk-image { position: relative; margin: 6px 0; }
.blk-image img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; }
.blk-image .blk-edit { top: 8px; }
.blk-caption { margin-top: 6px; text-align: center; font-size: 0.88rem; color: var(--text-muted); min-height: 1.4em; }
.blk-caption.is-empty::before { position: static; }
.blk-drop {
  display: grid; gap: 4px; place-items: center; padding: 26px; border: 2px dashed var(--border-strong); border-radius: 10px;
  color: var(--text-muted); text-align: center; cursor: pointer; font-size: 0.9rem;
}
.blk-drop:hover, .blk-image.dragging .blk-drop { border-color: var(--accent); color: var(--accent); }

/* código */
.blk-code { position: relative; margin: 6px 0; }
.blk-code pre { margin: 0; cursor: text; min-height: 2.6em; }
.blk-lang { position: absolute; top: 6px; right: 8px; z-index: 1; width: auto; padding: 1px 4px; font: 0.72rem var(--font-mono); opacity: 0; border-color: var(--border); background: var(--surface); }
.blk:hover .blk-lang, .blk-lang:focus { opacity: 1; }
.blk-code-input {
  display: block; width: 100%; padding: 12px 14px; border: 1px solid var(--accent); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: 0.85rem/1.5 var(--font-mono); resize: none; overflow: hidden; tab-size: 4;
}
.blk-code-input:focus { outline: 0; }
.blk-code-input[hidden], .blk-code pre[hidden] { display: none; }

/* recuadro */
.blk-box { position: relative; margin: 8px 0; }
.blk-box .box-title { outline: none; min-width: 3em; }
.blk-box-style { position: absolute; top: 8px; right: 8px; width: auto; padding: 1px 4px; font-size: 0.74rem; opacity: 0; background: var(--surface); }
.blk:hover .blk-box-style, .blk-box-style:focus { opacity: 1; }

/* ejercicio */
.blk-ex { margin: 8px 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.blk-ex-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.blk-sol-btn { margin-top: 8px; border: 0; padding: 0; background: none; color: var(--accent); font: 600 0.86rem var(--font-sans); cursor: pointer; }
.blk-ex-solbox { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border-strong); }
.blk-ex-solbox[hidden] { display: none; }
.blk-ex-solbox .blk-ex-label { color: var(--good); }

.blk-hr { border: 0; border-top: 1px solid var(--border-strong); margin: 18px 0; }

/* ---------- menús ---------- */
.cal-menu, .cal-palette {
  position: absolute; z-index: 70; min-width: 210px; max-width: calc(100vw - 16px); padding: 5px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
.cal-menu { display: grid; }
.cal-menu-head { padding: 6px 9px 4px; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 700; }
.cal-menu-sep { height: 1px; margin: 4px 2px; background: var(--border); }
.cal-menu-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 9px; border: 0; border-radius: 7px; background: none;
  color: var(--text); font: 0.88rem var(--font-sans); text-align: left; cursor: pointer;
}
.cal-menu-item:hover, .cal-menu-item:focus { background: var(--surface-2); outline: none; }
.cal-menu-item.danger { color: var(--bad); }
.cal-menu-icon { width: 18px; display: inline-grid; place-items: center; color: var(--text-muted); font-size: 0.85rem; }
.cal-menu-label { flex: 1; }
.cal-menu-hint { font-size: 0.72rem; color: var(--text-muted); }

.cal-palette { width: 290px; padding: 6px; }
.cal-palette-search { width: 100%; margin-bottom: 6px; }
.cal-palette-list { max-height: min(380px, 60vh); overflow-y: auto; display: grid; }
.cal-palette-group { padding: 8px 8px 3px; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 700; }
.cal-palette-item {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 0; border-radius: 7px; background: none;
  color: var(--text); font: 0.9rem var(--font-sans); text-align: left; cursor: pointer;
}
.cal-palette-item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.cal-palette-icon {
  width: 28px; height: 28px; display: inline-grid; place-items: center; flex: none;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); font: 600 0.78rem var(--font-mono); color: var(--text-muted);
}
.cal-palette-empty { padding: 8px; margin: 0; color: var(--text-muted); font-size: 0.86rem; }

/* burbuja de selección */
.cal-bubble {
  position: absolute; z-index: 65; display: flex; align-items: center; gap: 1px; padding: 3px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: 0 8px 24px rgb(0 0 0 / 0.16);
}
.cal-bubble[hidden] { display: none; }
.cal-bubble-btn {
  min-width: 30px; height: 30px; padding: 0 7px; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 0; border-radius: 7px; background: none; color: var(--text); font: 0.88rem var(--font-sans); cursor: pointer;
}
.cal-bubble-btn:hover { background: var(--surface-2); }
.cal-bubble-btn.wide { font-weight: 600; font-size: 0.82rem; }
.cal-bubble-btn.ai { color: var(--accent); }
.cal-bubble-sep { width: 1px; height: 20px; margin: 0 3px; background: var(--border); }

/* editar una fórmula en línea */
.cal-mathpop {
  position: absolute; z-index: 66; width: min(380px, calc(100vw - 16px)); padding: 10px; display: grid; gap: 8px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
.cal-mathpop[hidden] { display: none; }
.cal-mathpop-row { display: flex; align-items: center; gap: 6px; }
.cal-mathpop-preview { min-height: 2.4em; padding: 4px; overflow-x: auto; text-align: center; border-radius: 6px; background: var(--bg); }

/* compositor de IA */
.cal-composer {
  margin: 10px 0; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border)); border-radius: 12px;
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}
.cal-composer-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cal-composer-title { color: var(--accent); display: inline-flex; }
.cal-composer-quote { margin: 0 0 8px; padding-left: 10px; border-left: 3px solid var(--accent); color: var(--text-muted); font-size: 0.86rem; max-height: 6em; overflow: auto; }
.cal-composer-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.cal-composer-chips button {
  padding: 3px 10px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface);
  color: var(--text); font: 0.8rem var(--font-sans); cursor: pointer;
}
.cal-composer-chips button:hover { border-color: var(--accent); color: var(--accent); }
.cal-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.cal-composer-out { margin-top: 10px; padding: 12px 14px; max-height: 60vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.cal-composer-out[hidden] { display: none; }
.cal-composer-out > :first-child, .cal-preview-blk > :first-child { margin-top: 0; }
.cal-preview-blk + .cal-preview-blk { margin-top: 8px; }
.cal-composer-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.cal-composer-actions[hidden] { display: none; }
.cal-wait { color: var(--text-muted); animation: cal-pulse 1.2s ease-in-out infinite; }
@keyframes cal-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .cal-wait { animation: none; } }

/* aviso */
.cal-toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
  padding: 9px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.88rem; box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}
.cal-toast button { border: 0; background: none; color: inherit; font: 700 0.86rem var(--font-sans); text-decoration: underline; cursor: pointer; }

/* ---------- pantallas táctiles (tablet, móvil) ---------- */
/* sin «pasar el ratón»: el bloque tocado (o con el foco) muestra sus controles */
@media (hover: none) {
  .blk.is-active > .blk-gutter, .blk:focus-within > .blk-gutter { opacity: 1; }
  .blk.is-active .blk-edit, .blk.is-active .blk-lang, .blk.is-active .blk-box-style { opacity: 1; }
  .cal-rowbtn { opacity: 0.75; }
}
/* dedos: objetivos de al menos ~40 px */
@media (pointer: coarse) {
  .blk { grid-template-columns: 44px minmax(0, 1fr); margin-left: -44px; }
  .blk-gutter { position: absolute; left: 0; top: 0; width: 44px; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0 0; }
  .blk-btn { width: 40px; height: 40px; border-radius: 9px; }
  .blk-grip { touch-action: none; }
  .cal-rowbtn { width: 38px; height: 38px; }
  .sb-link, .sb-group > summary { padding-top: 9px; padding-bottom: 9px; }
  .cal-bubble-btn { min-width: 42px; height: 42px; }
  .cal-palette-item { padding: 10px 8px; }
  .cal-menu-item { padding: 11px 10px; }
  .blk-edit { padding: 7px 14px; top: 8px; }
  .icon-btn { width: 40px; height: 40px; }
}
@media (pointer: coarse) and (max-width: 720px) {
  .blk { grid-template-columns: 30px minmax(0, 1fr); margin-left: -14px; }
  .blk-gutter { width: 30px; }
  .blk-btn { width: 30px; height: 36px; }
}
body.cal-dragging, body.cal-dragging * { cursor: grabbing !important; user-select: none; }

/* ---------- modo lectura: la página no se edita al tocarla ---------- */
.is-reading .blk-gutter, .is-reading .blk-edit, .is-reading .blk-lang, .is-reading .blk-box-style,
.is-reading .blk-drop, .is-reading .blk-drop-line { display: none !important; }
.is-reading .rich.is-empty::before, .is-reading .page-title.is-empty::before { content: none; }
.is-reading .blocks-tail { cursor: default; }
.is-reading .blk-formula-view, .is-reading .blk-code pre, .is-reading .m { cursor: auto; }
.is-reading .blk-formula-view:hover, .is-reading .m:hover { background: none; }
.cal-bubble.reading .fmt { display: none; }
.cal-edit-btn svg { width: 16px; height: 16px; }
/* en edición, un aviso discreto en el margen superior de la página */
.is-editing .page-title { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--accent) 35%, transparent); }
