/* ============ DERIVADAS ============ */
.page-head { padding-top: clamp(1.1rem, 3.5vw, 2.2rem); text-align: center; }

.drv-wrap {
    width: 100%; min-width: 0; max-width: 1160px;
    margin: 0 auto clamp(3rem, 8vw, 5rem);
    display: flex; flex-direction: column; gap: 20px;
}

/* Tarjetas glass */
.drv-card {
    background: var(--glass-bg);
    backdrop-filter: blur(14px) saturate(1.3);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: clamp(18px, 3vw, 28px);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.drv-card:hover { border-color: var(--accent-soft); }

.drv-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 22px;
}
.drv-card-title {
    display: flex; align-items: center; gap: 8px;
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1.2px; color: var(--muted); margin: 0;
}
.drv-card-title i { font-size: 17px; }

/* Preview */
.drv-preview {
    text-align: center; padding: 28px 18px; margin-bottom: 18px;
    min-height: 104px; color: #1a1a1a; font-size: 1.35rem;
    background: #ffffff; border: 1px solid var(--border);
    border-radius: 18px; display: flex; align-items: center; justify-content: flex-start;
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}
[data-theme="dark"] .drv-preview { background: #18181C; color: var(--text); }
/* ============ ACCIONES DEL VISOR + MODAL TRANSFORMAR ============ */
.eq-preview-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: 4px;
    margin: 0 0 22px;
}
.eq-prev-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    padding: 9px 15px; border-radius: 999px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text); cursor: pointer; font-family: inherit; font-size: .82rem; font-weight: 700;
    transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
}
.eq-prev-btn i { flex-shrink: 0; font-size: 1.05rem; }
.eq-prev-btn:hover { background: var(--surface-2); border-color: var(--accent-soft); transform: translateY(-2px); }
.eq-prev-btn:active { transform: translateY(0); }
.eq-prev-btn .eq-prev-label { display: none; }
@media (min-width: 768px) {
    .eq-prev-btn .eq-prev-label { display: inline; }
}
.eq-transform-modal {
    position: fixed; inset: 0; z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    padding: 20px;
}
.eq-transform-modal[hidden] { display: none; }
.eq-transform-modal:not([hidden]) { animation: rcModalFade var(--transition) both; }
.eq-transform-card {
    position: relative;
    width: 100%; max-width: 900px;
    max-height: min(86vh, 720px);
    overflow-y: auto;
    padding: clamp(1.6rem, 4vw, 2.4rem);
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
}
.eq-transform-modal:not([hidden]) .eq-transform-card { animation: rcModalPop var(--transition) both; }
.eq-transform-head { display: block; padding: 0; border: none; margin-bottom: 8px; }
.eq-transform-title { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 8px; padding-right: 40px; font-size: clamp(2.1rem, 5vw, 2.7rem); text-align: center; }
.eq-transform-title i { font-size: 26px; color: var(--accent); }
.eq-transform-close {
    position: absolute; top: 16px; right: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border: none; border-radius: 12px;
    background: var(--surface-2); color: var(--text); font-size: 18px; cursor: pointer;
}
.eq-transform-close:hover { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); color: var(--accent); }
.eq-transform-list { display: flex; flex-direction: column; gap: 8px; padding: 0; margin: 0; overflow: visible; }
.eq-transform-item {
    display: flex; align-items: center; gap: 13px;
    padding: 12px 16px; border-radius: 14px; text-align: left;
    border: 1px solid transparent; background: transparent; color: var(--text);
    font-weight: 600; font-size: .93rem; font-family: inherit; cursor: pointer;
    transition: all var(--transition);
}
.eq-transform-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.eq-transform-nombre { display: inline-flex; align-items: center; gap: 13px; flex: 1 1 auto; min-width: 0; font-size: .93rem; font-weight: 600; color: var(--text); }
.eq-transform-nombre i { font-size: 20px; color: var(--accent); flex-shrink: 0; }
.eq-transform-math {
    flex-shrink: 0; max-width: 58%;
    overflow-x: auto; white-space: nowrap;
    font-size: 1.4rem; font-weight: 700; color: var(--text);
    background: var(--surface-2); padding: 6px 14px; border-radius: var(--r-sm);
}
.eq-transform-math::-webkit-scrollbar { display: none; }
.eq-transform-vacio { margin: 0; color: var(--muted); font-size: .95rem; text-align: center; }
@media (max-width: 560px) {
    .eq-transform-item { flex-wrap: wrap; gap: 8px 10px; }
    .eq-transform-nombre { flex: 1 1 100%; }
    .eq-transform-math { flex: 1 1 100%; max-width: none; }
}

.drv-preview .katex-display { margin: 0 auto; }
.drv-preview .katex { font-size: 1.5em; }
.drv-result .katex { font-size: 2.025rem; }
.drv-result-math .katex { font-size: 2.025rem; }
/* En celulares el latex del visor es menor */

/* ============ COMPROBAR RESULTADO ============ */
.rc-check { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 14px; }
/* Pildora "Comprobar resultado" del visor de resultados (junto a Transformar) */
.rc-check-chevron { margin-left: 2px; font-size: .92rem; transition: transform .18s ease; }
#rc-check-toggle[aria-expanded="true"] .rc-check-chevron { transform: rotate(180deg); }
#rc-check-toggle[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.rc-check-row { display: flex; align-items: stretch; gap: 12px; flex-wrap: wrap; }
.rc-check-box { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); padding: 10px 14px 12px; position: relative; transition: border-color .15s ease, box-shadow .15s ease; }
.rc-check-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rc-check-label { display: flex; align-items: center; gap: 6px; font-size: .68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.rc-check-label i { color: currentColor; font-size: .95rem; }
.rc-check-math { flex: 1 1 auto; overflow-x: auto; padding: 8px 0 4px; font-size: 1.05rem; min-height: 34px; }
.rc-check-math::-webkit-scrollbar { display: none; }
.rc-check-vs { align-self: center; flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 30px; color: var(--muted); font-size: 1.15rem; transition: color .15s ease; }
.rc-check-vs.ok { color: #22c55e; }
.rc-check-vs.bad { color: #ef4444; }
[data-theme="dark"] .rc-check-vs.ok { color: #4ade80; }
[data-theme="dark"] .rc-check-vs.bad { color: #f87171; }
/* Fila de "Tu apunte": math-field (o texto plano) + boton morado de modo */
.rc-check-field { position: relative; display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.rc-check-field > math-field, .rc-check-field > .rc-check-input2 { flex: 1 1 auto; min-width: 0; }
.rc-check-input2 { width: auto; border: none; background: transparent; color: var(--text); font-family: inherit; font-size: .95rem; padding: 6px 0; }
.rc-check-input2:focus { outline: none; }
.rc-check-field .pista-input { left: 0; right: 46px; max-width: none; top: auto; bottom: 2px; transform: none; }
.rc-check-mathfield { display: block; min-height: 32px; font-size: .95rem; padding: 4px 0 2px; }
.rc-check-mathfield::part(content) { min-height: 24px; }
.rc-check-mode-btn { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 32px; padding: 0; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--accent); cursor: pointer; font-size: .95rem; transition: background .15s ease, color .15s ease, transform .15s ease; }
.rc-check-mode-btn:hover { background: var(--accent); color: var(--accent-text-on); transform: translateY(-1px); }
.rc-check-mode-btn:active { transform: translateY(0); }
.rc-check-textinput { display: none; box-sizing: border-box; }
/* Veredicto: banner con barra de color a la izquierda */
.rc-check-verdict { display: none; margin-top: 12px; border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; font-size: .9rem; line-height: 1.55; }
.rc-check-verdict.ok { display: block; background: color-mix(in srgb, #22c55e 10%, transparent); border-color: color-mix(in srgb, #22c55e 45%, transparent); color: #15803d; }
.rc-check-verdict.bad { display: block; background: color-mix(in srgb, #ef4444 10%, transparent); border-color: color-mix(in srgb, #ef4444 45%, transparent); color: #b91c1c; }
.rc-check-verdict.neutral { display: block; background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--muted); }
[data-theme="dark"] .rc-check-verdict.ok { color: #4ade80; }
[data-theme="dark"] .rc-check-verdict.bad { color: #f87171; }
[data-theme="dark"] .rc-check-verdict.neutral { color: #cbd5e1; }
.rc-check-verdict .katex { color: inherit; }
.rc-check-placeholder { color: var(--muted); opacity: .75; }
.rc-check-diff { margin-top: 6px; overflow-x: auto; color: var(--text); }
.rc-check-diff::-webkit-scrollbar { display: none; }
@media (max-width: 560px) { .rc-check-vs { width: 100%; height: auto; justify-content: center; margin: -4px 0; } .rc-check-box { padding: 10px 12px 12px; } }
@media (max-width: 767px) {
    .drv-preview { padding: 22px 16px; min-height: 84px; }
    .drv-preview .katex { font-size: 1.15em; }
    .drv-result .katex { font-size: 1.5525rem; }
    .drv-result-math .katex { font-size: 1.5525rem; }
}
.drv-preview > * { flex-shrink: 0; margin: 0 auto; }
.drv-preview::-webkit-scrollbar { display: none; }

/* Inputs */
.drv-inputs-section { margin-bottom: 8px; }
.drv-field-group { display: flex; flex-direction: column; gap: 5px; }
.drv-field-label { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.drv-field-input {
    width: 100%; height: 46px; padding: 12px 20px; border: 1px solid var(--border);
    border-radius: 16px; background: var(--surface-2); color: var(--text);
    font-size: .92rem; font-family: inherit; outline: none; transition: border-color .2s;
}
.drv-field-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.drv-var-libre {
    width: 88px; height: 46px; padding: 12px 10px;
    border: 1px solid var(--border); border-radius: 16px;
    background: var(--surface-2); color: var(--text);
    font-size: .92rem; font-family: inherit; outline: none;
    text-align: center; transition: border-color .2s;
}
.drv-var-libre:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.drv-var-libre[hidden] { display: none; }

.drv-select-wrap {
    position: relative; display: flex; align-items: center;
    width: max-content; min-width: 76px; max-width: 100%;
}
.drv-field-select {
    width: auto; min-width: 76px; height: 46px; padding: 10px 36px 10px 18px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface-2); color: var(--text);
    font-size: .88rem; font-weight: 600; font-style: italic;
    font-family: "KaTeX_Math", "Cambria Math", "Latin Modern Math", Georgia, serif;
    outline: none; cursor: pointer;
    appearance: none; -webkit-appearance: none; text-align: center;
    transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
}
.drv-select-chevron {
    position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
    pointer-events: none; color: var(--muted); opacity: .7; font-size: 14px;
}
.drv-field-select:hover { border-color: var(--accent-soft); background: var(--surface); transform: translateY(-1px); }
.drv-field-select:focus { border-color: var(--accent); background: var(--surface-2); box-shadow: 0 0 0 3px var(--accent-soft); }

.drv-single-opts {
    display: grid; grid-template-columns: .7fr 1.1fr 1.4fr; gap: 10px; margin-top: 14px;
    align-items: end;
}
/* Orden: pill contenedora con tres pills dentro (f', f'', f''') */
.drv-opt-pill {
    display: flex; align-items: stretch; gap: 4px; padding: 4px; height: 46px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
}
.drv-opt {
    flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    padding: 8px 6px; border: 1px solid transparent; border-radius: 999px;
    background: transparent; color: var(--muted);
    font-family: inherit; font-size: .84rem; font-weight: 700; letter-spacing: .2px;
    cursor: pointer; white-space: nowrap;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.drv-opt:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.drv-opt.is-active { color: #15803d; background: color-mix(in srgb, #22c55e 16%, transparent); border-color: color-mix(in srgb, #22c55e 45%, transparent); }
.drv-opt[data-orden="2"].is-active { color: #0369a1; background: color-mix(in srgb, #0ea5e9 16%, transparent); border-color: color-mix(in srgb, #0ea5e9 45%, transparent); }
.drv-opt[data-orden="3"].is-active { color: #b45309; background: color-mix(in srgb, #f59e0b 18%, transparent); border-color: color-mix(in srgb, #f59e0b 45%, transparent); }
[data-theme="dark"] .drv-opt.is-active { color: #4ade80; }
[data-theme="dark"] .drv-opt[data-orden="2"].is-active { color: #38bdf8; }
[data-theme="dark"] .drv-opt[data-orden="3"].is-active { color: #fbbf24; }
.drv-opt:focus-visible { outline: 2px solid var(--border); outline-offset: 1px; }
.drv-opt .katex { font-size: 1.05em; line-height: 1.15; }
.drv-opt-tex { display: inline-block; }
.drv-orden-group select { display: none; }
.drv-eval-input {
    width: 100%; height: 46px; padding: 10px 18px; border: 1px solid var(--border);
    border-radius: 999px; background: var(--surface-2); color: var(--text);
    font-size: .88rem; font-family: inherit; font-weight: 600;
    outline: none; transition: border-color .2s;
}
.drv-eval-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.drv-eval-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.drv-eval-label .drv-eval-full { display: inline; }
.drv-eval-label .drv-eval-short { display: none; }

.drv-inf-row {
    display: flex; align-items: center; gap: 8px;
}
.drv-inf-row .drv-field-input { flex: 1; min-width: 0; }

/* Calc button */
.drv-calc-btn {
    width: 100%; padding: 14px 24px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent);
    border: 1px solid var(--accent);
    font-size: .92rem; font-weight: 700; font-family: inherit;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 9px;
    transition: all .3s cubic-bezier(0.4, 0, 0.2, 1); margin-top: 16px;
}
.drv-calc-btn:hover {
    background: var(--accent); color: var(--accent-text-on);
    transform: translateY(-3px) scale(1.01);
}
.drv-calc-btn i { font-size: 18px; }

/* Loading */
.drv-loading {
    display: flex; align-items: center; gap: 12px; margin-top: 14px;
    padding: 12px 16px; border-radius: 12px; background: var(--surface-2);
}
.drv-loading-shimmer {
    width: 100%; height: 4px; border-radius: 4px;
    background: linear-gradient(90deg, var(--surface) 25%, var(--accent-soft) 50%, var(--surface) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.drv-loading-text { font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* Result card */
.drv-result-card { text-align: center; }

/* Zoom control in result card head */
.drv-zoom-ctl {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.drv-zoom-ctl i {
    font-size: 13px;
}

.drv-zoom-ctl input[type="range"] {
    width: 90px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.drv-zoom-ctl input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.drv-zoom-ctl input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

/* Result */
.drv-result {
    text-align: center; font-size: 1.05rem; color: var(--text);
    padding: 20px 18px; min-height: 50px; overflow-x: auto;
    background: #ffffff; border: 1px solid var(--border);
    border-radius: 18px; position: relative;
    scrollbar-width: none; -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.drv-result .katex-display,
.drv-result .katex {
    transform-origin: center center;
    transition: transform 0.2s ease;
}
.drv-result-math { overflow-x: auto; padding: 0 4px; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; }
.drv-result-math::-webkit-scrollbar { display: none; }
.drv-result-math .katex-display { margin: .3em 0; }
[data-theme="dark"] .drv-result { background: #18181C; }
.drv-result .katex-display { margin: .3em auto; }
.drv-result::-webkit-scrollbar { display: none; }
.resultado-decimal { font-size: .88rem; color: var(--muted); margin-top: 6px; }
.result-meta { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.result-chip {
    padding: 4px 12px; border-radius: 999px; font-size: .72rem; font-weight: 600;
    background: var(--accent-soft); color: var(--accent);
}

/* Info button + explanation panel in result */
.drv-result-info {
    position: absolute; top: 10px; right: 10px;
    width: 28px; min-width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0; border: 1px solid transparent; border-radius: 50%;
    background: transparent; color: var(--muted);
    font-size: .72rem; font-family: inherit; cursor: pointer;
    transition: all .25s ease;
}
.drv-result-info i { font-size: 15px; }
.drv-result-info:hover { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.drv-result-explanation {
    display: none; text-align: left;
    margin-top: 14px; padding: 18px 22px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 14px; font-size: .82rem; line-height: 1.6; color: var(--muted);
}
.drv-result-explanation.open { display: block; }
.drv-result-expl-header {
    font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
    color: var(--accent); margin-bottom: 10px;
}
.drv-result-expl-header strong { color: var(--accent); font-weight: 700; }
.drv-result-explanation strong { color: var(--text); font-weight: 700; }
.drv-result-explanation ul { margin: 8px 0 0 18px; padding: 0; }
.drv-result-explanation li { margin-bottom: 4px; }

/* Graph */
.drv-graph-card { overflow: hidden; }
.drv-graph-head {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
}
.drv-graph-canvas {
    width: 100%; min-width: 0; min-height: 380px;
    display: flex; align-items: center; justify-content: center;
    background: #ffffff; border: 1px solid var(--border);
    border-radius: 16px; padding: 16px; overflow: hidden;
    position: relative;
}
[data-theme="dark"] .drv-graph-canvas { background: #18181C; }
.drv-graph-canvas > * { max-width: 100%; }
.drv-graph-canvas .js-plotly-plot { width: 100% !important; height: auto !important; min-height: 360px; }
/* Solo el SVG principal: el selector amplio tambien rompia los iconos de la
   modebar (display:block los apilaba uno debajo de otro). */
.drv-graph-canvas svg.main-svg { display: block; margin: 0 auto; }
.drv-download-btn {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--muted); cursor: pointer;
    font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
    transition: all .2s;
}
.drv-download-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Formulas */
.drv-formulas {
    max-height: 400px; overflow-y: auto; padding-right: 4px;
    contain: layout;
}
.drv-formulas::-webkit-scrollbar { width: 5px; }
.drv-formulas::-webkit-scrollbar-track { background: transparent; }
.drv-formulas::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.formula-item {
    padding: 10px; text-align: center; border-radius: 8px;
    cursor: pointer; transition: background .2s; margin-bottom: 4px;
}
.formula-item:hover { background: var(--surface-2); }
.formula-item .katex { font-size: .95rem; }

.formula-row {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    padding: 10px; border-radius: 8px; cursor: pointer; transition: background .2s;
    flex-wrap: wrap; margin-bottom: 4px;
}
.formula-row:hover { background: var(--surface-2); }
.formula-title { font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.formula-math { text-align: center; }
.formula-math .katex { font-size: .92rem; }

.formula-category-title {
    text-align: center; font-size: .92rem; font-weight: 700;
    color: var(--accent); margin-top: 20px; margin-bottom: 10px; width: 100%;
}

/* Toast: estilos unificados en css/styles.css (.toast-copiado) */

/* Responsive */
@media (max-width: 600px) {
    .drv-card { padding: 18px; }
    .drv-single-opts { grid-template-columns: 1fr 1fr; gap: 10px; }
    .drv-single-opts .drv-orden-group { grid-column: 1 / -1; }
    .drv-single-opts .drv-field-select { padding: 10px 32px 10px 14px; font-size: .82rem; }
    .drv-eval-input { padding: 10px 14px; font-size: .82rem; }
    .drv-eval-label .drv-eval-full { display: none; }
    .drv-eval-label .drv-eval-short { display: inline; }
    .drv-calc-btn { font-size: .88rem; padding: 12px; }
    .drv-graph-canvas { min-height: 260px; padding: 10px; }
    .drv-graph-canvas .js-plotly-plot { width: 100% !important; height: auto !important; min-height: 250px; }
    .drv-card-head { flex-wrap: wrap; }

    .drv-zoom-ctl input[type="range"] {
        width: 64px;
        height: 5px;
    }

    .drv-zoom-ctl input[type="range"]::-webkit-slider-thumb {
        width: 16px;
        height: 16px;
    }

    .drv-zoom-ctl input[type="range"]::-moz-range-thumb {
        width: 16px;
        height: 16px;
    }
}

/* Single scroll context: html handles vertical scroll, body stays hidden
   overflow-x.  The previous body { overflow-x: clip } forced overflow-y to
   compute to auto, creating a competing body scrollbar. */

/* ============ HISTORIAL / TABLA TABS ============ */
.drv-historial-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 12px;
    padding: 0 44px;
}
.drv-historial-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 10px;
    border-radius: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-weight: 700;
    font-size: .82rem;
    cursor: pointer;
    text-align: center;
    transition: all .25s ease;
}
.drv-historial-pill i { font-size: 16px; flex-shrink: 0; }
.drv-historial-pill:hover { border-color: var(--accent-soft); transform: translateY(-2px); }
.drv-historial-pill.active {
    background: var(--accent);
    color: var(--accent-text-on);
    border-color: var(--accent);
}
.drv-historial-pill.active i { color: var(--accent-text-on); }

.drv-historial {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}
.drv-historial::-webkit-scrollbar { width: 5px; }
.drv-historial::-webkit-scrollbar-track { background: transparent; }
.drv-historial::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.historial-vacio {
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    padding: 22px 10px;
    border: 1px dashed var(--border);
    border-radius: 12px;
}
.historial-item {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background .2s, border-color .2s;
    border: 1px solid transparent;
}
.historial-item:hover { border-color: var(--border); }
.historial-item { position: relative; }
.historial-item .historial-item-del {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
    opacity: 0;
    transition: opacity .2s ease, color .2s ease, background .2s ease, border-color .2s ease;
}
.historial-item:hover .historial-item-del,
.historial-item .historial-item-del:focus-visible {
    opacity: 1;
}
.historial-item .historial-item-del:hover {
    color: #e11d48;
    border-color: #e11d48;
    background: color-mix(in srgb, #e11d48 12%, transparent);
}
@media (hover: none) {
    .historial-item .historial-item-del { opacity: 1; background: var(--surface); border-color: var(--border); }
}
.historial-item .historial-math { display: block; text-align: center; overflow-x: auto; }
.historial-item .historial-entrada {
    display: flex; align-items: baseline; gap: 7px;
    margin-top: 8px; padding-top: 7px; border-top: 1px dashed var(--border);
    font-size: .85rem;
}
.historial-item .historial-entrada-tag {
    flex: none; font-size: .64rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--muted);
    border: 1px solid var(--border); border-radius: 99px; padding: 2px 7px;
}
.historial-item .historial-entrada-math { flex: 1 1 auto; min-width: 0; }
.historial-item .historial-entrada .katex { font-size: 1em; }
.historial-item .historial-entrada .katex-display { margin: 0; }
.historial-item .historial-decimal { display: block; text-align: center; font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* Mobile: pills same row */
@media (max-width: 600px) {
    .drv-historial-tabs { flex-wrap: nowrap; padding: 0; gap: 6px; }
    .drv-historial-tabs .drv-historial-pill { flex: 1 1 0; min-width: 0; padding: 11px 6px; font-size: .74rem; white-space: nowrap; }
    .drv-historial-pill i { font-size: 1.05rem; }
}

/* ====== Historial persistente + copia de resultado (compartido) ====== */
.historial-item .historial-item-restaurar {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
    opacity: 0;
    transition: opacity .2s ease, color .2s ease, background .2s ease, border-color .2s ease;
}
.historial-item:hover .historial-item-restaurar,
.historial-item .historial-item-restaurar:focus-visible { opacity: 1; }
.historial-item .historial-item-restaurar:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}
@media (hover: none) {
    .historial-item .historial-item-restaurar { opacity: 1; background: var(--surface); border-color: var(--border); }
}

.rc-copy-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 18px;
    position: sticky;
    left: 0;
    background: #ffffff;
    padding: 10px 0;
    z-index: 1;
}
[data-theme="dark"] .rc-copy-row {
    background: #18181C;
}
.rc-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: .74rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.5;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.rc-copy-btn i { font-size: .92rem; }
.rc-copy-btn:hover { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

@media (max-width: 900px) {
    .content { padding-left: 12px; padding-right: 12px; }
}

/* =========================================================================
   DERIVACION PASO A PASO
   =========================================================================
   Cada paso es una linea: el numero, la regla aplicada y la expresion. La
   expresion pendiente de derivar se muestra como d/dx[...] para que se lea
   igual que en un cuaderno. */

.drv-steps-card { margin-top: 18px; }

.drv-steps-head-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.drv-steps-nota {
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 14px;
}

.drv-steps-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Numero del paso. Mismo criterio que los pasos de triangulos.html: circulo
   con border-radius alto (22%) para que se vea como una ficha y no como un
   punto perfecto. Va en absoluto a la izquierda porque, como columna del grid,
   desplazaba el contenido y la expresion dejaba de estar centrada. */
.drv-step-num {
    position: absolute;
    left: 8px;
    top: 16px;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 22%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .72rem;
    font-weight: 700;
}

/* El ultimo paso es el resultado: la ficha vaLlena para marcarlo. */
.drv-step-es-final .drv-step-num {
    background: var(--accent);
    color: var(--accent-text-on);
}

.drv-step-cuerpo { min-width: 0; }

.drv-step-regla {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--accent);
    margin-bottom: 6px;
}

/* La etiqueta de la regla va centrada sobre la expresion. */
.drv-step-regla-fila { text-align: center; margin-bottom: 8px; }

/* Cambio de nivel: "segunda derivada" */
.drv-step-nivel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 18px 0 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.drv-step-nivel::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Un paso: numero | regla+explicacion | expresion
   El numero va en posicion absoluta a la izquierda, y el padding izquierdo
   que le reserva se compensa con el derecho: si no, todo el contenido queda
   desplazado hacia la derecha y la expresion no esta centrada respecto a la
   tarjeta. */
.drv-step {
    position: relative;
    padding: 16px 44px;
    border-radius: 10px;
    transition: background-color .15s ease;
}

.drv-step:hover { background-color: var(--accent-soft); }
.drv-step + .drv-step { border-top: 1px solid var(--border); }

/* La explicacion se centra y se limita para no quedar una linea interminable
   en pantallas anchas. */
.drv-step-detalle {
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 10px;
    text-align: center;
    max-width: 68ch;
    margin-left: auto;
    margin-right: auto;
}

.drv-step-math {
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* La expresion va centrada y a buen tamano, que es lo que se lee. */
    text-align: center;
    font-size: 1.65rem;
    line-height: 1.7;
}

.drv-step-math::-webkit-scrollbar { display: none; }
.drv-step-math .katex { font-size: 1em; }
.drv-step-math .katex-display { margin: .25em 0; }

/* El ultimo paso se resalta: es el resultado. */
.drv-step-es-final .drv-step-math .katex { font-weight: 500; }

/* La explicacion lleva la regla escrita en su notacion, asi que el LaTeX de
   dentro va un poco mas grande que el texto que lo rodea. */
.drv-step-detalle { font-size: 13.5px; }
.drv-step-detalle .katex { font-size: 1.22em; }
.drv-step-detalle .katex-display { margin: .4em 0 .2em; }
.drv-step-detalle strong { color: var(--text); font-weight: 600; }

/* El paso final, el que simplifica, se separa del resto para que se lea como
   el cierre de la derivacion. */
.drv-step-simplifica {
    margin-top: 6px;
    background: var(--accent-soft);
}

.drv-step-simplifica:hover { background: var(--accent-soft); }
.drv-step-simplifica .drv-step-regla { font-size: 12.5px; }
.drv-step-simplifica .drv-step-math { font-size: 1.85rem; }

.drv-steps-corte {
    margin-top: 14px;
    padding: 11px 13px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 9px;
}

.drv-steps-corte i { font-size: 17px; color: var(--accent); margin-top: 1px; flex-shrink: 0; }

.drv-steps-error {
    margin-top: 14px;
    padding: 11px 13px;
    border-radius: 10px;
    font-size: 13.5px;
    line-height: 1.5;
    background: var(--surface-2);
    color: var(--muted);
}

/* En movil la explicacion ocupa menos y la expresion manda. */
@media (max-width: 640px) {
    .drv-step { padding: 13px 34px; }
    .drv-step-num { left: 4px; top: 13px; width: 22px; height: 22px; font-size: 12px; }
    .drv-step-detalle { font-size: 12.5px; }
    .drv-step-math { font-size: 1.3rem; }
    .drv-steps-head-right { gap: 8px; }
}
