/* calculadora.css — calculadora de la plataforma: armazón, campos, científica, gráficos, 3D,
   derivadas, integrales y límites. Requiere base.css y herramientas.css.
   Funciona igual en la página /calculadora/ y embebida en el aula (panel de 380 a 460 px). */

/* ——— página ——— */
.pagina-calc__cuerpo { max-width: 1500px; margin: 0 auto; padding: 18px clamp(12px, 2.2vw, 30px) 56px; }
.pagina-calc .h-barra__fin .h-boton svg { width: 19px; height: 19px; }
@media (max-width: 520px) {
  .pagina-calc .h-barra__fin .h-boton { width: 44px; padding: 0; }
  .pagina-calc .h-barra__fin .h-boton span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ——— armazón ——— */
.calc { container: calc / inline-size; position: relative; min-width: 0; }
.calc .katex-display { margin: 0; text-align: left; }
.calc .katex-display > .katex { text-align: left; }
.calc__solapas { position: relative; margin-bottom: 16px; }
.calc__solapas::before, .calc__solapas::after { content: ''; position: absolute; top: 4px; bottom: 4px; width: 28px; pointer-events: none; opacity: 0; transition: opacity .2s; z-index: 1; }
.calc__solapas::before { left: 0; border-radius: 13px 0 0 13px; background: linear-gradient(90deg, var(--papel-hondo), rgba(239, 233, 218, 0)); }
.calc__solapas::after { right: 0; border-radius: 0 13px 13px 0; background: linear-gradient(270deg, var(--papel-hondo), rgba(239, 233, 218, 0)); }
.calc__solapas.hay-izq::before, .calc__solapas.hay-der::after { opacity: 1; }
.calc__fichas { scroll-behavior: smooth; }
.calc__ficha { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.calc__ficha svg { width: 19px; height: 19px; flex: none; opacity: .75; transition: opacity .15s, color .15s; }
.calc__ficha[aria-selected="true"] svg { color: var(--tinta); opacity: 1; }
.calc__ficha:focus-visible { outline-offset: -3px; }
.calc__panel:focus { outline: none; }
.calc__cargando { padding: 48px 16px; text-align: center; color: var(--grafito-70); font-size: 15.5px; }
.calc__aviso { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); z-index: 80; display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; background: var(--grafito); color: var(--papel); font-size: 15px; font-weight: 600; box-shadow: 0 14px 30px -14px rgba(29, 33, 37, .55); opacity: 0; transform: translate(-50%, 14px); pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2, .8, .2, 1); }
.calc__aviso.es-visible { opacity: 1; transform: translate(-50%, 0); }
.calc__aviso--error { background: var(--rojo); }

/* ——— dos columnas: a = entrada, v = gráfico, b = lo demás ——— */
.cx { display: grid; grid-template-columns: minmax(330px, 440px) minmax(0, 1fr); grid-template-areas: "a v" "b v"; grid-template-rows: auto 1fr; gap: 16px 22px; align-items: start; }
.cx__a { grid-area: a; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cx__b { grid-area: b; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cx__v { grid-area: v; position: sticky; top: 82px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.cx__grafico { height: clamp(420px, calc(100svh - 200px), 780px); }
@container calc (max-width: 900px) {
  .cx { grid-template-columns: minmax(0, 1fr); grid-template-areas: "a" "v" "b"; grid-template-rows: auto; }
  .cx__v { position: static; }
  .cx__grafico { height: clamp(270px, 74cqi, 460px); }
}
.calc--compacta .cx { grid-template-columns: minmax(0, 1fr); grid-template-areas: "a" "v" "b"; grid-template-rows: auto; gap: 12px; }
.calc--compacta .cx__v { position: static; }
.calc--compacta .cx__grafico { height: clamp(240px, 72cqi, 320px); }

/* ——— hoja (tarjeta) ——— */
.cc-hoja { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cc-hoja__cabeza { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 32px; }
.cc-hoja__titulo { font-family: var(--serif); font-weight: 700; font-size: 20px; line-height: 1.15; }
.cc-hoja__acciones { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.calc--compacta .h-tarjeta { padding: 14px; }
.calc--compacta .cc-hoja__titulo { font-size: 18.5px; }

/* ——— campo con vista compuesta ——— */
.cc-campo { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cc-campo__caja { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cc-campo__pre { flex: none; font-size: 18px; color: var(--grafito); white-space: nowrap; }
.cc-campo__entrada { flex: 1 1 auto; min-width: 0; }
.cc-campo--grande .cc-campo__entrada { min-height: 52px; font-size: 18.5px; }
.cc-campo__vista { min-height: 40px; display: flex; align-items: center; padding: 2px 4px; overflow-x: auto; overflow-y: hidden; font-size: 17px; color: var(--grafito); scrollbar-width: thin; }
.cc-campo__vista .katex { font-size: 1.12em; }
.cc-campo__error { font-size: 15px; line-height: 1.35; color: var(--rojo); }
.cc-campo__error:empty { display: none; }
.cc-campo__error.es-aviso { color: var(--grafito-70); }
.cc-campo__ayuda { margin-top: -2px; }
.cc-fila { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.cc-fila > .cc-campo { flex: 1 1 140px; }

/* ——— resultado resaltado ——— */
.cc-res { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cc-res__rotulo { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.cc-res__tex { overflow-x: auto; overflow-y: hidden; padding: 2px 0; scrollbar-width: thin; line-height: 2; }
.cc-res__aprox { font-family: var(--mono); font-size: 15px; color: var(--grafito-70); font-variant-numeric: tabular-nums; }
.cc-res__aprox .katex { font-size: 1em; }
.cc-secundario { padding: 12px 14px; border-radius: 12px; background: var(--papel); box-shadow: 0 0 0 1px var(--grafito-12) inset; overflow-x: auto; }
.cc-secundario .katex { font-size: 1.12em; }
.cc-secundario { line-height: 1.9; }
.cc-dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@container calc (max-width: 520px) { .cc-dos { grid-template-columns: 1fr; } }
.calc--compacta .cc-dos { grid-template-columns: 1fr; }

/* ——— botones chicos, chips y selectores ——— */
.cc-guardar { gap: 7px; }
.cc-guardar.es-hecho { background: rgba(31, 122, 85, .1); color: var(--verde); box-shadow: 0 0 0 1px rgba(31, 122, 85, .35) inset; }
.cc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cc-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 13px; border-radius: 999px; background: var(--blanco); box-shadow: 0 0 0 1px var(--grafito-12) inset; font-size: 15px; font-weight: 500; color: var(--grafito); white-space: nowrap; transition: box-shadow .15s, background-color .15s; }
.cc-chip:hover { box-shadow: 0 0 0 1px var(--grafito-45) inset; }
.cc-chip .katex { font-size: 1.05em; }
.cc-chip[aria-pressed="false"] { color: var(--grafito-45); }
.cc-chip[aria-pressed="false"] .cc-punto { background: transparent !important; box-shadow: 0 0 0 1.5px currentColor inset; }
.cc-punto { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.cc-raya { width: 18px; height: 3px; border-radius: 2px; flex: none; }
.cc-raya--punteada { background-image: linear-gradient(90deg, currentColor 55%, transparent 55%) !important; background-size: 7px 3px; }
.cc-selector { display: inline-flex; padding: 3px; gap: 2px; background: var(--papel-hondo); border-radius: 12px; max-width: 100%; }
.cc-hoja > .cc-selector { display: flex; }
.cc-hoja > .cc-selector .cc-selector__op { padding: 0 8px; min-width: 0; }
.cc-selector__op { flex: 1 1 auto; min-height: 38px; padding: 0 14px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--grafito-70); white-space: nowrap; transition: background-color .15s, color .15s; }
.cc-selector__op:hover { color: var(--grafito); }
.cc-selector__op[aria-checked="true"] { background: var(--blanco); color: var(--grafito); box-shadow: 0 1px 2px rgba(29, 33, 37, .16); }
.cc-selector--chico .cc-selector__op { min-height: 34px; padding: 0 11px; font-size: 14.5px; }
@media (pointer: coarse) {
  .cc-chip, .cc-selector__op, .cc-selector--chico .cc-selector__op { min-height: 44px; }
}

/* ——— pasos ——— */
.cc-pasos > li { grid-template-columns: 28px minmax(0, 1fr); }
.cc-pasos .h-nota { color: var(--grafito); font-weight: 500; font-size: 15px; }
.cc-pasos__tex { overflow-x: auto; overflow-y: hidden; padding: 2px 0 4px; scrollbar-width: thin; line-height: 2; }
.cc-pasos__tex .katex { font-size: 1.05em; }
.cc-nota { display: flex; gap: 8px; align-items: flex-start; }
.cc-nota svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }

/* ——— tablas ——— */
.cc-tabla-caja { overflow-x: auto; border-radius: 10px; }
.cc-tabla { min-width: 100%; }
.cc-tabla th, .cc-tabla td { white-space: nowrap; }
.cc-tabla td { font-family: var(--mono); font-size: 15px; text-align: right; }
.cc-tabla th { text-align: right; }
.cc-tabla th .katex { font-size: 1.05em; color: var(--grafito); }
.cc-tabla tr.es-cerca td { background: #fffbe6; }

/* ——— gráfico 2D ——— */
.graf { position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; outline-offset: 2px; }
.graf__lienzo { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.graf__lienzo:active { cursor: grabbing; }
.graf:focus-visible { outline: 3px solid var(--amarillo); }
.graf__controles { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 2; }
.graf__boton { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; height: 44px; padding: 0 10px; border-radius: 12px; background: rgba(255, 253, 248, .94); color: var(--grafito); font-size: 14.5px; font-weight: 600; box-shadow: 0 0 0 1px var(--grafito-12) inset, 0 8px 18px -12px rgba(29, 33, 37, .4); transition: background-color .15s, box-shadow .15s; }
.graf__boton:hover { box-shadow: 0 0 0 1px var(--grafito-45) inset, 0 8px 18px -12px rgba(29, 33, 37, .4); }
.graf__boton svg { width: 19px; height: 19px; flex: none; }
.graf__boton--texto { padding: 0 12px 0 10px; }
.graf__boton[aria-pressed="true"] { background: var(--grafito); color: var(--papel); }
@container calc (max-width: 340px) { .graf__boton--texto span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } .graf__boton--texto { padding: 0; } }
.cc-leyenda { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cc-vista-nota { font-size: 14px; color: var(--grafito-70); }

/* ——— científica ——— */
.cien { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); grid-template-areas: "pantalla cinta" "teclado cinta"; gap: 16px 22px; align-items: start; }
.cien__pantalla { grid-area: pantalla; position: relative; overflow: hidden; padding: 0; }
.cien__teclado { grid-area: teclado; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.cien__cinta { grid-area: cinta; position: sticky; top: 82px; max-height: calc(100svh - 104px); display: flex; flex-direction: column; }
@container calc (max-width: 1000px) {
  .cien { grid-template-columns: minmax(0, 1fr); grid-template-areas: "pantalla" "teclado" "cinta"; }
  .cien__cinta { position: static; max-height: none; }
}
@container calc (max-width: 660px) { .cien__teclado { grid-template-columns: minmax(0, 1fr); gap: 8px; } }
.calc--compacta .cien { grid-template-columns: minmax(0, 1fr); grid-template-areas: "pantalla" "teclado" "cinta"; gap: 12px; }
.calc--compacta .cien__cinta { position: static; max-height: none; }
.calc--compacta .cien__teclado { grid-template-columns: minmax(0, 1fr); gap: 8px; }

.cien__barra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px 0; position: relative; }
.cien__barra .cc-guardar { margin-left: auto; }
.cien__papel { position: relative; margin: 12px 0 0; padding: 14px 18px 12px; min-height: 168px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px;
  background-color: var(--blanco);
  background-image: linear-gradient(rgba(207, 219, 232, .55) 1px, transparent 1px), linear-gradient(90deg, rgba(207, 219, 232, .55) 1px, transparent 1px);
  background-size: 22px 22px; background-position: -1px -1px;
  border-top: 1px solid var(--grafito-12); border-bottom: 1px solid var(--grafito-12); }
.cien__expr { min-height: 44px; display: flex; align-items: center; overflow-x: auto; overflow-y: hidden; font-size: 20px; color: var(--grafito); scrollbar-width: thin; }
.cien__expr .katex { font-size: 1.2em; }
.cien__expr.es-vacia { color: var(--grafito-45); font-family: var(--sans); font-size: 16px; }
.cien__resultado { align-self: flex-end; max-width: 100%; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-height: 64px; justify-content: center; }
.cien__resultado .h-resultado { padding: 8px 16px 8px 20px; max-width: 100%; overflow-x: auto; transition: opacity .15s; }
.cien__resultado .h-resultado .katex { font-size: 1.62em; }
.cien__resultado.es-previa .h-resultado { background: transparent; box-shadow: none; opacity: .55; }
.cien__resultado.es-previa .h-resultado::before { opacity: 0; }
.cien__aprox { font-family: var(--mono); font-size: 15px; color: var(--grafito-70); font-variant-numeric: tabular-nums; padding-right: 4px; }
.cien__aprox:empty { display: none; }
.cien__linea { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.cien__entrada { font-size: 19px; min-height: 50px; }
.cien__mensaje { font-size: 15px; min-height: 21px; color: var(--grafito-70); }
.cien__mensaje.es-error { color: var(--rojo); }

.cien__bloque { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.cien__tecla { min-height: 52px; min-width: 0; padding: 0 2px; font-family: var(--sans); font-size: 18px; line-height: 1; touch-action: manipulation; }
.cien__tecla--fun { font-family: var(--serif); font-size: 19px; }
.cien__tecla--fun i { font-style: italic; }
.cien__tecla sup { font-size: .62em; vertical-align: .55em; line-height: 0; margin-left: 1px; }
.cien__tecla--num { font-size: 21px; font-weight: 500; }
.cien__tecla--igual { font-size: 24px; }
.cien__tecla--chica { font-size: 15.5px; font-weight: 600; }
.cien__tecla svg { width: 22px; height: 22px; }
.cien__tecla:focus-visible { outline-offset: 1px; }
@media (hover: hover) {
  .cien__tecla:hover { filter: brightness(.97); }
  .cien__tecla.h-tecla--num:hover { filter: brightness(1.25); }
}
.calc--compacta .cien__tecla { min-height: 46px; font-size: 17px; }
.calc--compacta .cien__tecla--num { font-size: 19.5px; }
.calc--compacta .cien__bloque { gap: 6px; }
@container calc (max-width: 420px) { .cien__tecla { min-height: 46px; } .cien__bloque { gap: 6px; } .cien__papel { padding: 12px 14px 10px; min-height: 148px; } }

.cien__lista { display: flex; flex-direction: column; overflow-y: auto; min-height: 0; margin: 0 -8px; padding: 0 8px; scrollbar-width: thin; }
.cien__item { display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; padding: 10px 10px; border-radius: 10px; text-align: left; border-bottom: 1px dashed var(--grafito-12); transition: background-color .15s; }
.cien__item:hover, .cien__item:focus-visible { background: var(--papel); }
.cien__item-expr { color: var(--grafito-70); overflow-x: auto; overflow-y: hidden; font-size: 15px; }
.cien__item-res { align-self: flex-end; font-weight: 600; overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.cien__item-res .katex { font-size: 1.12em; }

/* ——— 3D ——— */
.tres__escena { position: relative; border-radius: 12px; overflow: hidden; touch-action: none; background: radial-gradient(120% 90% at 50% 38%, #fffdf8 0%, #f7f3e9 55%, #ece5d4 100%); box-shadow: 0 0 0 1px var(--grafito-12) inset; }
.tres__escena canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; cursor: grab; }
.tres__escena canvas:active { cursor: grabbing; }
.tres__pista { position: absolute; left: 12px; bottom: 12px; display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; background: rgba(255, 253, 248, .9); box-shadow: 0 0 0 1px var(--grafito-12) inset; font-size: 14px; color: var(--grafito-70); pointer-events: none; transition: opacity .4s; }
.tres__pista svg { width: 17px; height: 17px; }
.tres__pista.es-oculta { opacity: 0; }
.tres__formula { position: absolute; left: 14px; top: 12px; padding: 6px 12px; border-radius: 10px; background: rgba(255, 253, 248, .86); font-size: 17px; pointer-events: none; max-width: calc(100% - 200px); overflow: hidden; }
@container calc (max-width: 460px) { .tres__formula { display: none; } }
.tres__sin-webgl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--grafito-70); }
.tres__datos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tres__dato { padding: 10px 12px; border-radius: 11px; background: var(--papel); box-shadow: 0 0 0 1px var(--grafito-12) inset; }
.tres__dato .h-rotulo { display: block; margin-bottom: 2px; }
.tres__dato .katex { font-size: 1.1em; }
.tres__rango { display: flex; align-items: center; gap: 12px; }
.tres__rango output { font-family: var(--mono); font-size: 15px; min-width: 64px; text-align: right; }

/* ——— parámetros (deslizadores) ——— */
.cc-param { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; }
.cc-param__nombre { font-family: var(--serif); font-style: italic; font-size: 20px; min-width: 18px; }
.cc-param__valor { width: 76px; min-height: 40px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-size: 15.5px; }
.cc-param .h-boton--icono { width: 40px; min-height: 40px; }
@media (pointer: coarse) { .cc-param .h-boton--icono, .cc-param__valor { min-height: 44px; } .cc-param .h-boton--icono { width: 44px; } }

/* ——— lista de funciones (gráficos) ——— */
.gr-func { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 6px 8px; align-items: start; }
.gr-func + .gr-func { padding-top: 12px; border-top: 1px dashed var(--grafito-12); }
.gr-func__color { width: 44px; height: 46px; border-radius: 11px; display: grid; place-items: center; }
.gr-func__color span { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--grafito-12); }
.gr-func__color[aria-pressed="false"] span { background: transparent !important; box-shadow: 0 0 0 2px currentColor inset, 0 0 0 3px #fff; }
.gr-func__quitar { width: 44px; height: 46px; border-radius: 11px; display: grid; place-items: center; color: var(--grafito-70); }
.gr-func__quitar:hover { background: var(--papel); color: var(--grafito); }
.gr-func__quitar svg, .gr-func__color svg { width: 19px; height: 19px; }
.gr-func .cc-campo__vista { min-height: 30px; }
.gr-notables { display: flex; flex-direction: column; gap: 4px; }
.gr-grupo { display: flex; flex-direction: column; gap: 4px; }
.gr-grupo + .gr-grupo { margin-top: 8px; }
.gr-grupo__nombre { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--grafito-70); }
.gr-punto { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 44px; padding: 6px 10px; border-radius: 10px; text-align: left; font-size: 15px; transition: background-color .15s; }
.gr-punto:hover, .gr-punto:focus-visible, .gr-punto.es-elegido { background: #fffbe6; }
.gr-punto__tipo { color: var(--grafito-70); flex: none; }
.gr-punto__coord { overflow-x: auto; overflow-y: hidden; }
.gr-punto__coord .katex { font-size: 1.05em; }

/* ——— límites ——— */
.li-tablas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@container calc (max-width: 560px) { .li-tablas { grid-template-columns: 1fr; } }
.calc--compacta .li-tablas { grid-template-columns: 1fr; }
.li-tablas .h-rotulo { display: block; margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) {
  .calc__fichas { scroll-behavior: auto; }
}
@media print {
  .graf__controles, .calc__solapas, .cc-guardar { display: none !important; }
}
