/* Laboratorio visual · estilos compartidos */
@font-face { font-family: 'Atkinson'; src: url('/vendor/fonts/atkinson/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson'; src: url('/vendor/fonts/atkinson/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/vendor/fonts/jetbrains/jetbrains-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/vendor/fonts/jetbrains/jetbrains-mono-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #F7F8FC;
  --surface: #FFFFFF;
  --surface-2: #EEF0F7;
  --line: #DCE0EC;
  --text: #172033;
  --text-2: #4A5570;
  --muted: #6B7590;
  --primary: #4F46E5;
  --primary-soft: #EEF0FF;
  --concept: #2563EB;
  --concept-soft: #EAF1FE;
  --ok: #15803D;
  --ok-soft: #E8F5EC;
  --warn: #B45309;
  --warn-soft: #FDF3E4;
  --err: #B91C1C;
  --err-soft: #FCEBEB;
  --ai: #7E22CE;
  --ai-soft: #F5ECFC;
  --r1: #D97706;   /* 1ª votación */
  --r2: #4F46E5;   /* 2ª votación */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 32, 51, .06), 0 4px 16px rgba(23, 32, 51, .06);
  --font: 'Atkinson', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --code-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* Botones */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .55rem 1rem; border-radius: 10px; font-weight: 700; display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; transition: background .15s, border-color .15s; }
button:hover:not(:disabled) { border-color: #B9C0D6; background: #FAFBFE; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: #4338CA; border-color: #4338CA; }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-ok:hover:not(:disabled) { background: #166534; }
.btn-danger { color: var(--err); border-color: #F1C4C4; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .65rem; font-size: .875rem; border-radius: 8px; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

input[type=text], input[type=password], input:not([type]), textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .75rem; width: 100%;
}
textarea { resize: vertical; min-height: 4rem; }
label { font-weight: 700; display: block; margin-bottom: .3rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.card + .card { margin-top: 1rem; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-title h3 { margin: 0; }

.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.ai { background: var(--ai-soft); color: var(--ai); }
.pill.primary { background: var(--primary-soft); color: var(--primary); }
.pill.concept { background: var(--concept-soft); color: var(--concept); }
.dot { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); } .dot.off { background: var(--err); } .dot.wait { background: var(--warn); }

/* Código de solo lectura */
.code { font-family: var(--mono); font-size: var(--code-size); line-height: 1.6; background: #FBFBFE; border: 1px solid var(--line); border-radius: 10px; padding: .6rem 0; overflow-x: auto; margin: 0; }
.code .ln { display: flex; padding: 0 .9rem 0 0; min-height: 1.6em; border-left: 4px solid transparent; }
.code .ln .n { width: 2.4rem; text-align: right; padding-right: .9rem; color: #A3AAC0; user-select: none; flex: none; }
.code .ln .c { white-space: pre; }
.code .ln.active { background: var(--primary-soft); border-left-color: var(--primary); }
.code .ln.done .n { color: var(--text-2); }
.code .ln.err { background: var(--err-soft); border-left-color: var(--err); }
.tok-kw { color: #7C3AED; font-weight: 700; } .tok-str { color: #0F766E; } .tok-num { color: #B45309; }
.tok-com { color: #8A93AB; font-style: italic; } .tok-fn { color: #2563EB; } .tok-bool { color: #BE185D; font-weight: 700; }
.tok-blank { background: #FDE68A; border-radius: 4px; padding: 0 .2em; font-weight: 700; }

/* Salida */
.output { font-family: var(--mono); font-size: 15px; background: #111827; color: #E5E7EB; border-radius: 10px; padding: .75rem 1rem; min-height: 3.2rem; white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 18rem; overflow: auto; }
.output:empty::before { content: 'La salida aparecerá aquí'; color: #6B7280; font-style: italic; }
.output .new { background: rgba(79, 70, 229, .45); border-radius: 3px; }

/* Feedback */
.feedback { border-radius: 10px; padding: .75rem 1rem; border: 1px solid; margin-top: .75rem; }
.feedback.ok { background: var(--ok-soft); border-color: #B7DEC3; color: #14532D; }
.feedback.err { background: var(--err-soft); border-color: #F1C4C4; color: #7F1D1D; }
.feedback.warn { background: var(--warn-soft); border-color: #F3D9B1; color: #78350F; }
.feedback.info { background: var(--concept-soft); border-color: #C7D8FB; color: #1E3A8A; }
.feedback.ai { background: var(--ai-soft); border-color: #E2C8F5; color: #581C87; }
.feedback strong { display: block; margin-bottom: .15rem; }

/* Tests */
.tests { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .35rem; }
.tests li { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem .7rem; border-radius: 8px; background: var(--surface-2); border: 1px solid transparent; }
.tests li .ic { font-weight: 700; width: 1.2rem; flex: none; text-align: center; }
.tests li.pass { background: var(--ok-soft); border-color: #B7DEC3; } .tests li.pass .ic { color: var(--ok); }
.tests li.fail { background: var(--err-soft); border-color: #F1C4C4; } .tests li.fail .ic { color: var(--err); }
.tests li .msg { font-size: .85rem; color: var(--text-2); }

/* Variables (tarjetas) */
.vars { display: flex; flex-wrap: wrap; gap: .6rem; }
.var { border: 2px solid var(--concept); border-radius: 10px; background: var(--surface); min-width: 6.5rem; overflow: hidden; }
.var .vn { background: var(--concept); color: #fff; font-family: var(--mono); font-size: .85rem; padding: .15rem .6rem; display: flex; justify-content: space-between; gap: .5rem; }
.var .vn .vt { opacity: .8; font-size: .75rem; }
.var .vv { font-family: var(--mono); font-size: 1.1rem; padding: .35rem .6rem; font-weight: 700; }
.var.changed { box-shadow: 0 0 0 4px rgba(37, 99, 235, .2); }
.var.changed .vv { animation: enter .45s ease-out; }
.var .prev { font-size: .75rem; color: var(--muted); text-decoration: line-through; margin-right: .35rem; font-weight: 400; }
@keyframes enter { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.listviz { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .3rem; }
.listviz .cell { border: 2px solid var(--line); border-radius: 8px; min-width: 2.8rem; text-align: center; background: var(--surface); position: relative; }
.listviz .cell .i { font-size: .7rem; color: var(--muted); border-bottom: 1px solid var(--line); padding: 0 .3rem; }
.listviz .cell .v { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; padding: .2rem .4rem; }
.listviz .cell.cur { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-3px); transition: transform .2s; }
.listviz .cell.cur::after { content: '▲'; position: absolute; left: 50%; bottom: -1.2rem; transform: translateX(-50%); color: var(--primary); font-size: .8rem; }

/* Condición / bifurcación */
.cond { display: inline-flex; gap: .5rem; align-items: center; padding: .4rem .8rem; border-radius: 10px; font-family: var(--mono); font-weight: 700; border: 2px solid; }
.cond.t { border-color: var(--ok); background: var(--ok-soft); color: #14532D; }
.cond.f { border-color: #7E22CE; background: #F5ECFC; color: #581C87; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 1000; max-width: min(90vw, 36rem); }

/* Tooltip de gráficos */
.tip { position: fixed; pointer-events: none; background: var(--text); color: #fff; font-size: .8rem; padding: .35rem .6rem; border-radius: 6px; z-index: 2000; max-width: 18rem; }

/* Gráficos */
.chart { width: 100%; }
.chart text { font-family: var(--font); fill: var(--text-2); font-size: 12px; }
.chart .val { fill: var(--text); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; color: var(--text-2); margin-top: .4rem; }
.legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
body.reduced *, body.reduced *::before, body.reduced *::after { animation: none !important; transition: none !important; }
.err-line-deco { background: #FCEBEB; }

/* Gráficos HTML */
.hbars { display: grid; gap: .55rem; }
.hb-row { display: grid; gap: 3px; }
.hb-label { font-size: .9rem; color: var(--text); }
.hb-label.ok { color: var(--ok); font-weight: 700; }
.hb-line { display: grid; grid-template-columns: 1fr 3.4rem; align-items: center; gap: .5rem; }
.hb-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hb-fill { height: 100%; border-radius: 4px; transition: width .35s; }
.hb-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .9rem; }
.hbars.big { gap: .9rem; }
.hbars.big .hb-label { font-size: 1.15em; }
.hbars.big .hb-track { height: 26px; }
.hbars.big .hb-val { font-size: 1.1em; }
.hbars.big .hb-line { grid-template-columns: 1fr 5rem; }
.stack-bar { display: flex; gap: 2px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.stack-bar .seg { display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .8rem; min-width: 3px; }
.cols { display: flex; gap: .5rem; align-items: stretch; height: 170px; }
.col-item { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; max-width: 5rem; }
.col-val { font-weight: 700; font-size: .85rem; height: 1.3em; }
.col-track { flex: 1; width: 100%; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.col-fill { width: 100%; border-radius: 4px 4px 0 0; transition: height .35s; }
.col-lbl { font-size: .8rem; color: var(--text-2); margin-top: .25rem; }
.opt:disabled { opacity: 1; }
.opt:disabled:not(.correct):not(.wrong-mine) { opacity: .75; }
.trace-grid .card { margin-top: 0; }
.cards-row > .card, .charts > .card, .locks > .card, .gallery > .card, .kpis > .card { margin-top: 0; }
/* Sin ligaduras: >= debe verse como >= */
.code, .output, .pb, .var, .listviz, .cond, .monaco-editor, textarea.fallback, .digit, .final-key { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
