/* Laboratorio de Python. Diseño como el de mycompiler.io (lo pidió el dueño): archivos a la izquierda, el editor al
   centro y, a la derecha, «Ejecutar» con las pestañas Salida y Variables. Tema claro por omisión (o el del sistema) y
   oscuro con la paleta de Arduino 3D; html[data-tema] lo pone tema.js antes de pintar. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --panel-3: #e9edf2;
  --line: #e3e7ec;
  --line-2: #d0d6de;
  --text: #1d2939;
  --muted: #5d6b7e;
  --faint: #8a96a8;
  --accent: #0e8f9c;
  --accent-soft: rgba(14, 143, 156, 0.1);
  --sel: #e7f4f5;
  --run: #16a34a;
  --run-2: #15803d;
  --stop: #dc2626;
  --warn: #b45309;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.07);
  --ok: #067647;
  --var: #b54708;
  --radius: 7px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-tema="oscuro"] {
  --bg: #0e1217;
  --panel: #151a21;
  --panel-2: #1b222b;
  --panel-3: #222b36;
  --line: #29333f;
  --line-2: #344050;
  --text: #e6ebf1;
  --muted: #95a2b3;
  --faint: #6b7889;
  --accent: #22b8c8;
  --accent-soft: rgba(34, 184, 200, 0.14);
  --sel: #1d3340;
  --run: #2ea043;
  --run-2: #238636;
  --stop: #da3633;
  --warn: #e3b341;
  --warn-soft: rgba(227, 179, 65, 0.16);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.08);
  --ok: #56d364;
  --var: #e5c07b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--panel);
  color: var(--text);
  font: 14px/1.45 var(--font);
  display: grid;
  /* La columna no crece con el contenido: una línea larga del editor no debe ensanchar la página. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 52px minmax(0, 1fr);
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
svg { fill: currentColor; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--panel-3); padding: 1px 5px; border-radius: 4px; }
kbd { font: 10.5px var(--mono); padding: 0 4px; border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barra de arriba */
.barra {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.marca { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px; white-space: nowrap; }
.titulo {
  flex: 0 1 520px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  margin-left: auto;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--faint);
  min-width: 0;
}
.titulo:focus-within { border-color: var(--accent); }
.titulo input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 13.5px; }
.titulo input::placeholder { color: var(--faint); }
.barra-derecha { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
.ejemplos {
  height: 32px;
  max-width: 230px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
}
.estado { color: var(--faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
body[data-estado="espera"] .estado, body[data-estado="entrada"] .estado { color: var(--warn); }

.btn-icono {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.btn-icono:hover { background: var(--panel-2); color: var(--text); }
.btn-icono.chico { width: 26px; height: 26px; }
:root[data-tema="oscuro"] .icono-luna, :root:not([data-tema="oscuro"]) .icono-sol { display: none; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13.5px;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ejecutar { background: var(--run); border-color: var(--run); color: #fff; font-weight: 500; }
.btn.ejecutar:hover:not(:disabled) { background: var(--run-2); }
.btn.detener { background: var(--stop); border-color: var(--stop); color: #fff; font-weight: 500; }
.btn-texto { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0 4px; font-size: 12px; }
.btn-texto:hover { color: var(--text); }

/* Área: archivos | editor | ejecución */
.area {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) minmax(320px, 31%);
  min-height: 0;
}

.lateral { display: flex; flex-direction: column; min-height: 0; background: var(--bg); border-right: 1px solid var(--line); }
.lateral-cabeza {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.archivos { list-style: none; margin: 6px 0; padding: 0; overflow: auto; flex: 1; }
.archivo {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px 7px 14px;
  border-left: 3px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.archivo:hover { background: var(--panel-2); }
.archivo.activo { background: var(--sel); border-left-color: var(--accent); }
.archivo svg { flex: none; color: var(--accent); }
.archivo .nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archivo .borrar { visibility: hidden; border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0 4px; font-size: 15px; line-height: 1; }
.archivo:hover .borrar, .archivo .borrar:focus-visible { visibility: visible; }
.archivo .borrar:hover { color: var(--danger); }
.lateral-nota { margin: 0; padding: 12px 14px; color: var(--faint); font-size: 12px; border-top: 1px solid var(--line); }

.centro { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.centro-barra { display: none; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
.centro-barra select { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); font: 13px var(--mono); }
.editor { flex: 1; min-height: 0; overflow: hidden; }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); }
.panel-barra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 48px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.controles { display: flex; gap: 6px; min-width: 0; }
.pestanas { display: flex; gap: 2px; }
.pestana {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.pestana:hover { color: var(--text); }
.pestana.activa { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.cuenta { font-size: 11px; opacity: 0.8; }
/* En el paso a paso se ven las dos vistas (variables arriba, salida abajo) y las pestañas sobran. */
body.paso-a-paso .pestanas { visibility: hidden; }

.panel-cuerpo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.vista { display: none; flex-direction: column; min-height: 0; }
.vista.activa { display: flex; flex: 1; }
.vista-titulo { display: none; }
body.paso-a-paso .vista { display: flex; }
body.paso-a-paso .vista-variables { flex: 0 0 46%; border-bottom: 1px solid var(--line); }
body.paso-a-paso .vista-salida { flex: 1; }
body.paso-a-paso .vista-titulo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 14px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Salida */
.consola {
  flex: 1;
  overflow: auto;
  padding: 12px 14px 18px;
  font: 13.5px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.c-vacio { color: var(--faint); }
.c-err { color: var(--danger); }
.c-in { color: var(--ok); font-weight: 500; }
.c-entrada {
  width: min(40ch, 80%);
  padding: 0 2px;
  border: 0;
  border-bottom: 1.5px solid var(--accent);
  outline: none;
  background: var(--accent-soft);
  color: var(--ok);
  font: inherit;
  font-weight: 500;
  caret-color: var(--accent);
}
.c-aviso { color: var(--faint); font-family: var(--font); font-size: 12.5px; white-space: normal; margin: 0 0 8px; }
.c-aviso.c-fin { margin: 10px 0 0; }
.c-aviso-error { color: var(--warn); }
.c-error {
  margin: 12px 0 4px;
  padding: 11px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
  font-family: var(--font);
  white-space: normal;
}
.c-error-titulo { color: var(--danger); font-size: 13.5px; }
.c-error p { margin: 6px 0 0; font-size: 14px; }
.c-pista { color: var(--muted); }
.c-pista::before { content: "Pista: "; color: var(--warn); font-weight: 600; }
.c-error details { margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.c-error summary { cursor: pointer; }
.c-error pre { margin: 6px 0 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font: 12px/1.5 var(--mono); overflow-x: auto; white-space: pre; color: var(--text); }

/* Variables */
.variables { flex: 1; overflow: auto; padding: 6px 12px 14px; }
.variables h3 { margin: 10px 2px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; }
.variables h3 code { text-transform: none; letter-spacing: 0; }
.variables table { width: 100%; border-collapse: collapse; font: 13px/1.4 var(--mono); table-layout: fixed; }
.variables td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.v-nombre { width: 32%; color: var(--var); overflow-wrap: anywhere; }
.v-valor { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-tipo { width: 20%; color: var(--faint); text-align: right; font-size: 12px; }
tr.v-cambio td { background: var(--warn-soft); }
.v-vacio { color: var(--faint); margin: 10px 2px; font-size: 13px; }

/* Ventanas medianas: sin la columna de archivos (van en la barra del editor). Celular: todo en una columna. */
@media (max-width: 1100px) {
  .area { grid-template-columns: minmax(0, 1fr) minmax(300px, 38%); }
  .lateral { display: none; }
  .centro-barra { display: flex; }
  .marca-nombre { display: none; }
}
@media (max-width: 760px) {
  body { grid-template-rows: auto minmax(0, 1fr); overflow: auto; height: auto; min-height: 100%; }
  .barra { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .titulo { order: 3; flex: 1 1 100%; margin: 0; }
  .estado { display: none; }
  .area { display: flex; flex-direction: column; }
  .centro { height: 52vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); min-height: 48vh; }
  .panel-barra { height: auto; flex-wrap: wrap; padding: 8px 10px; }
  .btn kbd { display: none; }
}
