:root {
  --fondo: #f6f7f8;
  --superficie: #ffffff;
  --superficie-2: #eef1f3;
  --borde: #d5dade;
  --texto: #1f2328;
  --texto-2: #545b63;
  --acento: #0f5a5c;
  --acento-texto: #ffffff;
  --acento-suave: #e3eeee;
  --barra: #0f5a5c;
  --barra-texto: #ffffff;
  --consola: #111619;
  --consola-borde: transparent;
  --bien: #1f7a55;
  --bien-suave: #e2f2ea;
  --mal: #b3261e;
  --mal-suave: #fbe9e7;
  --resalte: #fff3c4;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radio: 8px;
  --alto-barra: 52px;
  --alto-pestanas: 46px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #14181b; --superficie: #1c2125; --superficie-2: #252b30; --borde: #3a424a;
    --texto: #e6e9ec; --texto-2: #a9b1b9; --acento: #4fb3b5; --acento-texto: #0b1f20; --acento-suave: #1f3536;
    --bien: #5cc795; --bien-suave: #183428; --mal: #f2867d; --mal-suave: #3a1f1d; --resalte: #4a4220;
    --barra: #0c3f41; --consola: #0b0e10; --consola-borde: #3a424a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #14181b; --superficie: #1c2125; --superficie-2: #252b30; --borde: #3a424a;
  --texto: #e6e9ec; --texto-2: #a9b1b9; --acento: #4fb3b5; --acento-texto: #0b1f20; --acento-suave: #1f3536;
  --bien: #5cc795; --bien-suave: #183428; --mal: #f2867d; --mal-suave: #3a1f1d; --resalte: #4a4220;
  --barra: #0c3f41; --consola: #0b0e10; --consola-borde: #3a424a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fondo); color: var(--texto);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--acento); }
code, pre { font-family: var(--mono); }

button, .boton {
  font: inherit; font-weight: 600; border: 1px solid var(--acento); background: var(--acento); color: var(--acento-texto);
  padding: .55rem 1rem; border-radius: var(--radio); cursor: pointer; min-height: 44px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
button.secundario, .boton.secundario { background: transparent; color: var(--acento); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--acento); outline-offset: 2px;
}
input, select, textarea {
  font: inherit; color: var(--texto); background: var(--superficie); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: .5rem .6rem; min-height: 44px; width: 100%;
}
textarea { font-family: var(--mono); resize: vertical; }
label { display: block; font-weight: 600; margin: .75rem 0 .3rem; }

/* Barra superior */
.barra {
  position: sticky; top: 0; z-index: 20; height: var(--alto-barra);
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: 0 16px; background: var(--barra); color: var(--barra-texto);
}
.marca { color: inherit; text-decoration: none; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca span { font-weight: 400; opacity: .85; }
@media (max-width: 560px) { .marca span { display: none; } }
.sesion { display: flex; align-items: center; gap: .5rem; font-size: .9rem; min-width: 0; }
.sesion .nombre { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.sesion button, .tema { min-height: 36px; padding: .3rem .7rem; background: transparent; color: inherit; border-color: currentColor; }

.vista { max-width: 1100px; margin: 0 auto; padding: 16px; outline: none; }
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; margin-bottom: 16px; }
.nota { color: var(--texto-2); font-size: .92rem; }
.aviso { color: var(--mal); font-size: .92rem; min-height: 1.2em; margin: .4rem 0 0; }
.fila { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Lista de ejercicios */
.bloque-ej { margin-bottom: 1.25rem; }
.bloque-ej h3 { color: var(--texto-2); font-size: .95rem; text-transform: none; }
.lista-ej { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lista-ej a {
  display: grid; grid-template-columns: auto 1fr auto; gap: .75rem; align-items: center;
  padding: .7rem .9rem; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  color: var(--texto); text-decoration: none; min-height: 52px;
}
.lista-ej .num { font-family: var(--mono); color: var(--texto-2); font-size: .9rem; }
.estado { font-size: .8rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: var(--superficie-2); color: var(--texto-2); white-space: nowrap; }
.estado.completado { background: var(--bien-suave); color: var(--bien); }
.estado.progreso { background: var(--resalte); color: var(--texto); }
.modo { font-size: .78rem; font-weight: 600; color: var(--acento); background: var(--acento-suave); padding: .1rem .5rem; border-radius: 999px; }

/* Vista de ejercicio */
.vista.ancha { max-width: none; padding: 0; }
.pestanas {
  position: sticky; top: var(--alto-barra); z-index: 10; height: var(--alto-pestanas);
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--superficie); border-bottom: 1px solid var(--borde);
}
.pestanas button {
  border: 0; border-radius: 0; background: transparent; color: var(--texto-2); font-weight: 600; min-height: var(--alto-pestanas);
  border-bottom: 3px solid transparent;
}
.pestanas button[aria-selected="true"] { color: var(--acento); border-bottom-color: var(--acento); }
.panel { display: none; padding: 16px; }
.panel.activo { display: block; }
#p-bloques { padding: 0; }
.area-bloques { height: calc(100dvh - var(--alto-barra) - var(--alto-pestanas)); min-height: 360px; position: relative; }

@media (min-width: 1000px) {
  .pestanas { display: none; }
  .ejercicio {
    display: grid; grid-template-columns: minmax(300px, 1fr) minmax(420px, 1.6fr) minmax(320px, 1fr);
    height: calc(100dvh - var(--alto-barra));
  }
  .panel { display: block; overflow: auto; border-right: 1px solid var(--borde); }
  .col-izq { overflow: auto; border-right: 1px solid var(--borde); }
  .col-izq .panel { border-right: 0; overflow: visible; }
  .area-bloques { height: 100%; }
}

.casos { width: 100%; border-collapse: collapse; font-size: .92rem; margin: .5rem 0 1rem; }
.casos th, .casos td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--borde); vertical-align: top; }
.casos th { color: var(--texto-2); font-weight: 600; }
.casos td { font-family: var(--mono); }
details { margin: .5rem 0 1rem; }
summary { cursor: pointer; font-weight: 600; color: var(--acento); min-height: 32px; }
.navegacion { display: flex; justify-content: space-between; gap: .5rem; margin-top: 1rem; }

pre.codigo {
  margin: 0; padding: .6rem 0; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  font-size: .9rem; line-height: 1.55; overflow-x: hidden; counter-reset: linea;
}
pre.codigo .ln { display: block; padding: 0 .75rem 0 3.2rem; position: relative; white-space: pre-wrap; overflow-wrap: anywhere; text-indent: 0; }
pre.codigo .ln::before {
  counter-increment: linea; content: counter(linea); position: absolute; left: 0; width: 2.4rem; text-align: right;
  color: var(--texto-2); opacity: .7;
}
pre.codigo .ln.actual { background: var(--resalte); }
pre.codigo .ln.error { background: var(--mal-suave); }
.mensajes { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; gap: 6px; }
.mensajes li { padding: .5rem .7rem; border-radius: var(--radio); font-size: .92rem; background: var(--superficie-2); }
.mensajes li.error { background: var(--mal-suave); color: var(--mal); }
.mensajes li.bien { background: var(--bien-suave); color: var(--bien); }

.controles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: .75rem 0; }
.controles .ancho { grid-column: 1 / -1; }
.consola {
  font-family: var(--mono); font-size: .9rem; background: var(--consola); color: #e6e9ec; border: 1px solid var(--consola-borde); border-radius: var(--radio);
  padding: .6rem .75rem; min-height: 3.5rem; white-space: pre-wrap; word-break: break-word; margin: .5rem 0 1rem;
}
.consola .entrada { color: #7fd1d3; }
.consola .entrada::before { content: "> "; }
.tabla-prueba-envoltura { overflow-x: auto; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); }
.tabla-prueba { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
.tabla-prueba th, .tabla-prueba td { padding: .35rem .5rem; border-bottom: 1px solid var(--borde); text-align: left; white-space: nowrap; }
.tabla-prueba th { background: var(--superficie-2); position: sticky; top: 0; font-weight: 600; }
.tabla-prueba td.mono, .tabla-prueba td.valor { font-family: var(--mono); }
.tabla-prueba td.cambio { background: var(--resalte); font-weight: 700; }
.tabla-prueba tr.actual td { outline: 2px solid var(--acento); outline-offset: -2px; }

.resultado { padding: .75rem; border-radius: var(--radio); margin: .75rem 0; }
.resultado.bien { background: var(--bien-suave); color: var(--bien); }
.resultado.mal { background: var(--mal-suave); color: var(--mal); }
.resultado ul { margin: .4rem 0 0; padding-left: 1.2rem; }

.dialogo { border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); color: var(--texto); width: min(92vw, 420px); padding: 16px; }
.dialogo::backdrop { background: rgba(0, 0, 0, .45); }
.dialogo menu { display: flex; justify-content: flex-end; gap: .5rem; padding: 0; margin: 1rem 0 0; }

/* Blockly: tamaño de letra legible y objetivos táctiles amplios. */
.blocklyText, .blocklyHtmlInput { font-size: 15px !important; }
.blocklyFlyoutButton .blocklyText { fill: var(--acento) !important; }
@media (max-width: 600px) {
  .blocklyToolboxCategoryLabel, .blocklyTreeLabel { font-size: 13px !important; }
  .blocklyToolboxCategory, .blocklyTreeRow { padding-right: 6px !important; }
}

.tema { font-size: .85rem; }
@media (max-width: 560px) { .tema { padding: .3rem .5rem !important; } .tema .pref { display: none; } }

.barra a.boton { color: var(--barra-texto); border-color: currentColor; min-height: 36px; padding: .3rem .7rem; }
@media (max-width: 560px) { .sesion .nombre { display: none; } }
