/* =====================================================================
   Laboratorio de Física Cuántica — hoja de estilos común
   Misma base que la de los laboratorios virtuales de Física (LabFis) y de
   Biología (BioLab), más los elementos propios de esta web (osciloscopio,
   tablas de resultados, notas al pie y vídeo).
   ===================================================================== */

:root {
  --brand: #0f6b3e;
  --brand-strong: #0a4f2d;
  --brand-soft: #e7f3ec;
  --brand-line: #b9dcc7;

  --ink: #1b2430;
  --ink-soft: #4a5565;
  --ink-faint: #6b7686;
  --line: #dde3ea;
  --surface: #ffffff;
  --page: #f5f7f9;

  --warn-bg: #fff7e6;
  --warn-line: #f0c36d;
  --warn-ink: #7a4b00;
  --ok: #157f3c;
  --err: #b42318;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 10px 24px rgba(16, 24, 40, .12);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-doc: "Source Serif 4", Georgia, "Times New Roman", serif;
  --maxw: 1200px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-strong); }

h1, h2, h3 { line-height: 1.25; color: var(--ink); }

/* ---------- Cabecera y navegación ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--brand-strong);
  background: linear-gradient(90deg, var(--brand-strong), var(--brand));
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}

.site-header .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand:hover { color: #fff; }
.brand .logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .15);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}
.brand small { display: block; font-weight: 400; font-size: .75rem; opacity: .8; line-height: 1.1; }

.site-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }

.site-nav a {
  color: rgba(255, 255, 255, .88);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s;
}
.site-nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.site-nav a[aria-current="page"] { background: rgba(255, 255, 255, .2); color: #fff; }

@media (max-width: 760px) {
  .site-header .inner { flex-wrap: wrap; gap: 0; padding-top: 8px; }
  .site-nav { width: 100%; margin: 4px -8px 6px; }
}

/* ---------- Estructura de página ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.page-title { margin: 0 0 4px; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.page-subtitle { margin: 0 0 24px; color: var(--ink-soft); font-size: 1.1rem; }

.eyebrow {
  display: inline-block;
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 6px;
}

section.block { margin-top: 40px; }
section.block > h2 {
  font-size: 1.4rem;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--brand-line);
}

/* ---------- Tarjetas y rejillas ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card > h3:first-child, .card-title {
  margin: 0 0 12px;
  font-size: 1.08rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-sub { margin: -8px 0 12px; color: var(--ink-faint); font-size: .9rem; }

.grid { display: grid; gap: 20px; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-side { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); }
@media (max-width: 860px) { .grid-side { grid-template-columns: minmax(0, 1fr); } }

.stack > * + * { margin-top: 20px; }

/* ---------- Hero (portada) ---------- */

.hero {
  background: linear-gradient(135deg, var(--brand-strong), var(--brand) 60%, #2e8b57);
  color: #fff;
  border-radius: 16px;
  padding: clamp(24px, 5vw, 48px);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -80px; top: -80px;
  width: 320px; height: 320px;
  border-radius: 50%;
  border: 40px solid rgba(255, 255, 255, .06);
}
.hero h1 { color: #fff; margin: 0 0 12px; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.hero p { margin: 0; max-width: 62ch; font-size: 1.08rem; opacity: .95; }
.hero .eyebrow { color: rgba(255, 255, 255, .8); }

.link-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.link-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--brand-line); color: inherit; }
.link-card .icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  margin-bottom: 6px;
}
.link-card h3 { margin: 0; font-size: 1.1rem; }
.link-card p { margin: 0; color: var(--ink-soft); font-size: .95rem; }
.link-card .more { margin-top: auto; padding-top: 8px; color: var(--brand); font-weight: 600; font-size: .9rem; }

/* ---------- Avisos ---------- */

.callout {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--brand-line);
  background: var(--brand-soft);
  display: flex;
  gap: 12px;
}
.callout.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.callout .ci { font-size: 1.2rem; line-height: 1.4; }
.callout p { margin: 0; }
.callout ol, .callout ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Instrucciones plegables ---------- */

details.instructions {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
details.instructions > summary {
  cursor: pointer;
  list-style: none;
  padding: 16px 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
details.instructions > summary::-webkit-details-marker { display: none; }
details.instructions > summary::after {
  content: "▾";
  margin-left: auto;
  transition: transform .2s;
  color: var(--ink-faint);
}
details.instructions[open] > summary::after { transform: rotate(180deg); }
details.instructions > .content { padding: 0 20px 20px; }

ol.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
ol.steps > li {
  counter-increment: step;
  position: relative;
  padding: 10px 0 10px 44px;
  border-top: 1px solid var(--line);
}
ol.steps > li:first-child { border-top: 0; }
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 10px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  font-size: .85rem;
  display: grid;
  place-items: center;
}

/* ---------- Formularios y botones ---------- */

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.fields { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.fields .field { flex: 1 1 200px; }
.fields .field.narrow { flex: 0 1 120px; }

input[type="text"], input[type="number"] {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 107, 62, .15);
}
input.invalid { border-color: var(--err); }

.btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { background: #f1f4f7; border-color: #c9d1da; }
.btn:focus-visible { outline: 3px solid rgba(15, 107, 62, .35); outline-offset: 1px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: #fdecea; border-color: #f5c2bd; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
a.btn { text-decoration: none; }
.btn-link { border: 0; background: none; padding: 0; color: var(--brand); font-weight: 500; text-decoration: underline; }
.btn-link:hover { background: none; color: var(--brand-strong); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.toolbar.bottom { margin: 12px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); }
.toolbar .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); align-self: center; margin-right: 4px; }

.result {
  margin-top: 12px;
  font-size: 1.15rem;
}
.result output { font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }

/* ---------- Cronómetro ---------- */

.chrono {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}
.chrono .display {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 2.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: #0f1720;
  color: #7CFFB2;
  padding: 6px 18px;
  border-radius: 10px;
  letter-spacing: .03em;
}
.chrono .display small { font-size: 1.3rem; opacity: .75; }
.chrono.running .display { box-shadow: 0 0 0 3px rgba(124, 255, 178, .35); }

/* ---------- Gráficos ---------- */

.chart { width: 100%; height: 400px; }

/* ---------- Tablas (Tabulator, tema "simple") ---------- */

.tabulator {
  font-family: var(--font-ui);
  font-size: .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.tabulator .tabulator-header {
  background: #f3f6f8;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-weight: 600;
}
.tabulator .tabulator-header .tabulator-col { background: #f3f6f8; border-right: 1px solid var(--line); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 6px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { text-align: center; white-space: normal; }
.tabulator .tabulator-tableholder .tabulator-table { background: #fff; }
.tabulator-row { border-bottom: 1px solid #eef1f4; }
.tabulator-row.tabulator-row-even { background: #fafbfc; }
.tabulator-row .tabulator-cell { padding: 6px; border-right: 1px solid #eef1f4; font-variant-numeric: tabular-nums; }
.tabulator-row .tabulator-cell.tabulator-editable { cursor: text; }
.tabulator-row .tabulator-cell.tabulator-editable:hover { background: var(--brand-soft); }
.tabulator-row .tabulator-cell.tabulator-editing { border: 2px solid var(--brand); }
.tabulator-row .tabulator-cell.tabulator-validation-fail { border: 2px solid var(--err); background: #fdecea; }
.tabulator-row.tabulator-selected { background: #d6ecdf !important; }
.tabulator-row .tabulator-cell.readonly { color: var(--ink-faint); background: #f7f9fa; }
.tabulator .tabulator-footer { background: #f7f9fa; border-top: 1px solid var(--line); }
.tabulator .tabulator-footer .tabulator-page.active { color: var(--brand); font-weight: 700; }

.table-wrap { max-width: 100%; overflow-x: auto; }

/* ---------- Avisos emergentes (sustituyen a alert) ---------- */

#toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: #1b2430;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  border-left: 5px solid #8a94a6;
  font-size: .95rem;
  animation: toast-in .2s ease-out;
}
.toast.ok { border-left-color: #3ccf7a; }
.toast.err { border-left-color: #ff6b5e; }
.toast.warn { border-left-color: var(--warn-line); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Pie de página ---------- */

.site-footer {
  background: #0f1720;
  color: rgba(255, 255, 255, .75);
  font-size: .88rem;
}
.site-footer .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: space-between;
}
.site-footer a { color: #fff; }

/* ---------- Documentos largos (guiones de las prácticas) ---------- */

main.doc {
  max-width: 860px;
  background: var(--surface);
  margin: 32px auto;
  padding: clamp(20px, 5vw, 56px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: var(--font-doc);
  font-size: 1.08rem;
  line-height: 1.7;
}
main.doc h1, main.doc h2, main.doc h3, main.doc h4 { font-family: var(--font-ui); }
main.doc h2 { margin-top: 2.2em; padding-bottom: .3em; border-bottom: 2px solid var(--brand-line); }
main.doc h3 { margin-top: 1.8em; color: var(--brand-strong); }
main.doc img { max-width: 100%; height: auto; }
main.doc table { max-width: 100%; }
main.doc mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
main.doc .cmbx-12 { font-weight: 700; }
main.doc .titlemark { color: var(--brand); margin-right: .4em; }
main.doc figure { margin: 1.6em 0; text-align: center; }
main.doc figcaption { font-family: var(--font-ui); font-size: .92rem; color: var(--ink-soft); margin-top: .6em; }
main.doc ol, main.doc ul { padding-left: 1.6em; }
main.doc li + li { margin-top: .3em; }
main.doc .card { font-family: var(--font-ui); font-size: 1rem; line-height: 1.6; margin: 1.6em 0; }
main.doc .doc-title { margin: 0 0 4px; font-size: clamp(1.6rem, 3vw, 2.1rem); }
main.doc .doc-subtitle { margin: 0 0 1.5em; color: var(--ink-soft); font-family: var(--font-ui); }
main.doc .next-step { margin-top: 2.5em; }
main.doc .btn { font-family: var(--font-ui); }

@media (max-width: 600px) {
  main.doc { margin: 0; border-radius: 0; border-left: 0; border-right: 0; overflow-x: auto; }
}

/* ---------- Simuladores ---------- */

/* Lienzos: se dibujan con coordenadas fijas y se escalan al ancho disponible. */
.sim-canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.canvas-native { display: block; max-width: 100%; height: auto; margin: 0 auto; }

.controls { display: grid; gap: 10px; margin-top: 16px; }
.range-field {
  display: grid;
  grid-template-columns: minmax(90px, max-content) minmax(0, 1fr) 4.5em;
  align-items: center;
  gap: 12px;
}
.range-field label { font-size: .9rem; font-weight: 600; color: var(--ink-soft); }
.range-field output { font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-soft); }
input[type="range"] { width: 100%; accent-color: var(--brand); margin: 0; }
input[type="range"]:disabled { opacity: .45; }

/* Lectura tipo instrumento (voltímetro). */
.readout {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: #0f1720;
  color: #ffd166;
  padding: 6px 16px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Botones de selección excluyente (condensador). */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  font: inherit; font-size: .9rem; font-weight: 600;
  padding: 8px 14px; border: 0; background: #fff; color: var(--ink); cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.seg button:disabled { cursor: not-allowed; opacity: .55; }
.btn:disabled { cursor: not-allowed; opacity: .55; }

.sim-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.sim-row + .sim-row { margin-top: 16px; }
.sim-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 600; }
.status { font-size: .9rem; color: var(--ink-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--ink-soft); margin: 10px 0 0; padding: 0; list-style: none; }
.legend span { display: inline-block; width: 18px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 6px; }
.legend span.dash { border-top-style: dashed; }

/* Objeto e imagen: tarjetas compactas, una junto a otra y centradas. */
.screens { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.screens .card { flex: 0 0 auto; text-align: center; padding: 16px 20px; }
.screens .card h3 { justify-content: center; font-size: 1rem; }
.screens canvas { width: auto; height: 300px; }

/* ---------- Propio del Laboratorio de Física Cuántica ---------- */

/* Pantalla del osciloscopio virtual. */
.scope {
  display: block;
  width: 100%;
  height: auto;
  background: #0f1720;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px #2a3644;
}
.grid-scope { grid-template-columns: minmax(0, 1fr) minmax(0, 340px); }
@media (max-width: 960px) { .grid-scope { grid-template-columns: minmax(0, 1fr); } }
.grid-data { grid-template-columns: minmax(0, 430px) minmax(0, 1fr); }
@media (max-width: 960px) { .grid-data { grid-template-columns: minmax(0, 1fr); } }
.grid-scope .range-field { grid-template-columns: minmax(60px, max-content) minmax(0, 1fr) 5.6em; }

/* Lista compacta de enlaces dentro de una tarjeta. */
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.link-list li:first-child { border-top: 0; }
.link-list .num { color: var(--brand); font-weight: 700; min-width: 1.4em; }
.link-list .na { color: var(--ink-faint); }
.link-list small { color: var(--ink-faint); margin-left: auto; white-space: nowrap; }

/* Tabla de resultados de los ajustes. */
.results-table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.results-table th, .results-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.results-table th:first-child, .results-table td:first-child { text-align: left; }
.results-table thead th { background: #f3f6f8; color: var(--ink-soft); font-weight: 600; }
.results-table tbody tr:last-child td { border-bottom: 0; }
.results-table td.na { color: var(--ink-faint); }

/* Avisos de coherencia de los datos. */
.checks { margin-top: 12px; font-size: .9rem; }
.checks.ok { color: var(--ok); }
.checks.warn { color: var(--warn-ink); }

/* Vídeo incrustado con proporción 16:9. */
.video { position: relative; aspect-ratio: 16 / 9; width: 100%; border-radius: var(--radius-sm); overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Enunciados y soluciones (cuestiones y problemas). */
main.doc ol.problems { padding-left: 0; list-style: none; counter-reset: prob; }
main.doc ol.problems > li { counter-increment: prob; position: relative; padding-left: 2.6em; margin-top: 1.6em; }
main.doc ol.problems > li::before {
  content: counter(prob);
  position: absolute; left: 0; top: .15em;
  width: 1.8em; height: 1.8em; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-family: var(--font-ui); font-weight: 700; font-size: .9rem;
  display: grid; place-items: center;
}
main.doc .statement { font-weight: 600; font-family: var(--font-ui); font-size: 1rem; line-height: 1.6; }
main.doc .solution { margin-top: .6em; padding-left: 1em; border-left: 3px solid var(--brand-line); }

/* Varias imágenes en una misma figura. */
main.doc .fig-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px 24px; }
main.doc .fig-row img { width: calc((100% - 24px) / 2); max-width: 339px; }
main.doc .fig-row.three img { width: calc((100% - 48px) / 3); max-width: none; }

/* Notas al pie de los apuntes. */
main.doc .footnotes { margin-top: 3em; font-size: .92rem; color: var(--ink-soft); }
main.doc .footnotes hr { border: 0; border-top: 1px solid var(--line); }
main.doc sup a { text-decoration: none; }

/* ---------- Impresión ---------- */

@media print {
  .site-header, .site-footer, .toolbar, #toasts, details.instructions > summary::after { display: none !important; }
  body { background: #fff; }
  .card, main.doc { box-shadow: none; border: 0; }
}
