/* FunciLab · estilos. Arriba, el diseño de ordenador; al final, los ajustes para tableta y móvil. */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; cursor: pointer; }
.mono { font-family: "Cascadia Code", Consolas, "Courier New", monospace; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- cabecera ---------- */
.top { display: flex; align-items: center; gap: 24px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -0.3px; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: -2px; }
.tabs { display: flex; gap: 6px; margin-left: 12px; }
.tab { border: 1px solid transparent; background: transparent; padding: 8px 14px; border-radius: 9px; font-weight: 600; color: #334155; }
.tab:hover { background: #f1f5f9; }
.tab.active { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }
.level { margin-left: auto; display: flex; background: #f1f5f9; border-radius: 10px; padding: 3px; }
.level button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.level button.active { background: white; color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

/* ---------- distribución ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 310px 1fr 380px; min-height: 0; }
.left, .right { overflow-y: auto; background: var(--panel); }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); background: #f8fafc; }
.center { position: relative; min-width: 0; padding: 12px; }

/* ---------- gráfica ---------- */
.graph { position: relative; width: 100%; height: 100%; background: white; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; touch-action: none; cursor: crosshair; user-select: none; }
.graph-svg { display: block; }
.halo { paint-order: stroke; stroke: white; stroke-width: 4px; stroke-linejoin: round; }
.zoom-ctrl { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px; }
.zoom-ctrl button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: white; font-size: 18px; font-weight: 700; color: #334155; box-shadow: 0 1px 3px rgb(0 0 0 / 0.08); }
.zoom-ctrl button:hover { background: #f1f5f9; }
.caption { position: absolute; left: 14px; top: 14px; max-width: 70%; background: rgb(255 255 255 / 0.96); border: 2px solid; border-radius: 12px; padding: 10px 14px; font-size: 15px; box-shadow: 0 4px 14px rgb(0 0 0 / 0.08); pointer-events: none; }
.caption-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ---------- barra lateral ---------- */
.side { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.lbl-small { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; }
.select, .input { width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 9px; font-size: 15px; background: white; color: var(--ink); }
.input:focus, .select:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.input.small { width: 64px; padding: 6px 7px; font-size: 13px; }
.generic { background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 2px 8px; }
.sliders { display: flex; flex-direction: column; gap: 10px; }
.slider-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 2px; }
.slider-top b { font-family: Consolas, monospace; background: #eff6ff; color: var(--primary); padding: 0 8px; border-radius: 6px; }
.slider input { width: 100%; accent-color: var(--primary); }
.current { background: #eff6ff; border-radius: 10px; padding: 8px 10px; }
.current .tex-block .katex-display { margin: 6px 0; }
.theory h4 { margin: 4px 0 6px; font-size: 14px; }
.theory ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.5; color: #334155; }
.theory li { margin-bottom: 5px; }
.fx-input { display: flex; align-items: center; gap: 8px; }
.fx { font-style: italic; font-weight: 600; white-space: nowrap; }
.pieces { display: flex; flex-direction: column; gap: 10px; }
.piece { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: #f8fafc; }
.piece-cond { display: flex; align-items: center; gap: 5px; font-size: 14px; }
.ineq { border: 1px solid #cbd5e1; background: white; border-radius: 6px; width: 28px; height: 28px; font-weight: 700; }
.del { margin-left: auto; border: 0; background: #fee2e2; color: #b91c1c; border-radius: 6px; width: 26px; height: 26px; font-weight: 700; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { border: 1px solid #cbd5e1; background: white; padding: 8px 13px; border-radius: 9px; font-weight: 600; color: #1e293b; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { background: #f8fafc; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 9px 11px; border-radius: 9px; font-size: 14px; }
.ex-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ex { border: 1px solid var(--line); background: white; padding: 5px 9px; border-radius: 99px; font-size: 13px; color: #334155; }
.ex:hover { border-color: var(--primary); color: var(--primary); }
.help summary { cursor: pointer; font-weight: 600; font-size: 14px; color: #334155; }
.help table { margin-top: 8px; font-size: 13px; border-collapse: collapse; width: 100%; }
.help td { padding: 4px 4px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.help td:first-child { white-space: nowrap; color: var(--primary); }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.45; margin: 6px 0 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.score { text-align: center; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.score-num { font-size: 34px; font-weight: 800; color: var(--primary); }
.score-num span { font-size: 20px; color: var(--muted); }

/* ---------- panel de propiedades ---------- */
.panel { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card { background: white; border: 1px solid var(--line); border-left: 5px solid; border-radius: var(--radius); padding: 10px 12px; font-size: 14.5px; transition: box-shadow 0.15s; }
.card.on { box-shadow: 0 2px 10px rgb(37 99 235 / 0.10); }
.card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h3 { margin: 0; font-size: 15.5px; }
.card-actions { display: flex; gap: 6px; }
.card-body p { margin: 7px 0; line-height: 1.5; }
.eye { border: 1.5px solid; background: white; border-radius: 99px; padding: 3px 11px; font-size: 12.5px; font-weight: 700; }
.eye.on { color: white; }
.play { border: 0; color: white; border-radius: 99px; padding: 4px 11px; font-size: 12.5px; font-weight: 700; }
.play:hover { filter: brightness(1.08); }
.big { font-size: 16.5px; margin: 8px 0 4px; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }
.alt { font-size: 14px; color: #334155; }
.hints { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: #475569; line-height: 1.45; }
.chip { display: inline-block; color: white; border-radius: 6px; padding: 1px 7px; font-size: 12.5px; font-weight: 700; margin-right: 4px; }
.plain { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-direction: column; gap: 6px; }
.tex { white-space: nowrap; }
.card-body .tex { white-space: normal; }

/* ---------- ejercicios ---------- */
.exercise h3 { margin: 4px 0 6px; font-size: 17px; }
.big-fx { font-size: 18px; background: #f8fafc; border-radius: 10px; padding: 0 8px; margin-bottom: 8px; overflow-x: auto; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; }
.field label { font-weight: 600; font-size: 14px; }
.field.ok .input { border-color: #16a34a; background: #f0fdf4; }
.field.ko .input { border-color: #dc2626; background: #fef2f2; }
.fb { font-size: 13.5px; font-weight: 600; }
.field.ok .fb { color: #15803d; }
.field.ko .fb { color: #b91c1c; }
.sol { font-size: 14px; background: #fefce8; border: 1px solid #fde68a; border-radius: 8px; padding: 5px 8px; }
.choices { display: flex; gap: 8px; }
.choice { flex: 1; border: 1.5px solid #cbd5e1; background: white; border-radius: 9px; padding: 8px; font-weight: 600; text-transform: capitalize; }
.choice.sel { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.field.ok .choice.sel { border-color: #16a34a; background: #f0fdf4; color: #15803d; }
.field.ko .choice.sel { border-color: #dc2626; background: #fef2f2; color: #b91c1c; }
.bravo { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; padding: 9px; border-radius: 9px; font-weight: 700; text-align: center; margin-bottom: 10px; }
.hint { margin-top: 10px; background: #fffbeb; border: 1px solid #fde68a; padding: 9px 11px; border-radius: 9px; font-size: 14px; line-height: 1.45; }
.caption-slot:empty { display: none; }

/* ---------- tableta y móvil (menos de 1100 px de ancho) ----------
   Una sola columna: la gráfica arriba, fija mientras se baja por la página,
   para ver cómo cambia al mover los deslizadores. Debajo, los controles y las propiedades. */
@media (max-width: 1099px) {
  .app { height: auto; min-height: 100vh; }
  .top { flex-wrap: wrap; gap: 10px 16px; padding: 10px 14px; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  .tab { white-space: nowrap; flex: 1; }
  .layout { display: flex; flex-direction: column; }
  .center {
    order: 1; position: sticky; top: 0; z-index: 5;
    height: 48vh; height: 48svh; min-height: 260px; padding: 8px 10px;
    background: var(--bg);
  }
  .left { order: 2; border-right: 0; border-bottom: 1px solid var(--line); }
  .right { order: 3; border-left: 0; }
  .left, .right { overflow: visible; }
  /* en ejercicios, primero la pregunta y después los ajustes */
  .layout.ex-mode .right { order: 2; }
  .layout.ex-mode .left { order: 3; border-top: 1px solid var(--line); }
  .layout.ex-mode .center { height: 40vh; height: 40svh; min-height: 220px; }
  .panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
  .layout.ex-mode .panel { display: flex; }
  .caption { max-width: calc(100% - 70px); font-size: 14px; padding: 8px 11px; left: 10px; top: 10px; }
}

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .level button { padding: 7px 10px; font-size: 14px; }
  .tab { padding: 8px 8px; font-size: 14px; }
  .side { padding: 14px; }
  .panel { grid-template-columns: 1fr; padding: 10px; }
  .zoom-ctrl { right: 8px; top: 8px; }
  .zoom-ctrl button { width: 38px; height: 38px; }
  .caption-sub { display: none; }
  /* deslizadores más fáciles de mover con el dedo */
  .slider input { height: 28px; }
  .input, .select { font-size: 16px; } /* 16 px evita que el móvil haga zoom al escribir */
  .input.small { width: 58px; font-size: 15px; }
  .piece-cond { flex-wrap: wrap; }
}
