:root{
  /* ===== Base + aliases para el look OptimeFlow(s) ===== */
  --bg:#0b0f14;
  --fg:#e6e8ea;
  --muted:#9aa1a8;
  --accent:#29d;
  --panel:#0f141b;
  --border:#10161d;
  --chip:#121925;

  /* aliases estilo Normaliza */
  --text: var(--fg);
  --card: var(--panel);
  --surface: var(--panel);
  --surface2: color-mix(in srgb, var(--panel) 70%, var(--bg));
  --input-bg: color-mix(in srgb, var(--panel) 35%, var(--bg));
  --input-border: color-mix(in srgb, var(--border) 90%, #000);
  --shadow:0 8px 28px rgba(0,0,0,.28);

  --radius:12px;
  --radius-sm:8px;

  /* Header/Footer OptimeFlow(s) */
  --border-subtle: color-mix(in srgb, var(--border) 65%, transparent);
  --ink: var(--text);
  --ghost: #111827;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Vidrio */
  --glass: blur(18px) saturate(1.1);

  /* Footer height (se ajusta por JS también) */
  --footer-h: 64px;
  --footer-author: #c69a2d;
}

/* ===== TEMAS (8) ===== */
html[data-theme="dark"]{
  --bg:#0b0f14; --fg:#e6e8ea; --muted:#9aa1a8; --accent:#29d;
  --panel:#0f141b; --border:#10161d; --chip:#121925;
}
html[data-theme="midnight"]{
  --bg:#0a0c12; --fg:#e3e6ee; --muted:#96a0b0; --accent:#4aa3ff;
  --panel:#0d1119; --border:#111827; --chip:#0f1724;
}
html[data-theme="violet"]{
  --bg:#0e0915; --fg:#efeaff; --muted:#b6aeda; --accent:#8b5cf6;
  --panel:#130e1d; --border:#1b1330; --chip:#1a1233;
}
html[data-theme="emerald"]{
  --bg:#06100c; --fg:#e7fff5; --muted:#96c7b4; --accent:#10b981;
  --panel:#0a1612; --border:#0c1e18; --chip:#0d1f18;
}
html[data-theme="amber"]{
  --bg:#130f06; --fg:#fff7e6; --muted:#d6c7a3; --accent:#f59e0b;
  --panel:#181307; --border:#241a0b; --chip:#1e170a;
}
html[data-theme="rose"]{
  --bg:#12080d; --fg:#ffe9f0; --muted:#e0b7c7; --accent:#f472b6;
  --panel:#190b13; --border:#26111c; --chip:#1d0f16;
}
html[data-theme="ocean"]{
  --bg:#061117; --fg:#e6fbff; --muted:#9fd0db; --accent:#22d3ee;
  --panel:#0a1820; --border:#0f2330; --chip:#0c1e29;
}
html[data-theme="mono"]{
  --bg:#0d0d0d; --fg:#eaeaea; --muted:#a8a8a8; --accent:#b5b5b5;
  --panel:#121212; --border:#1a1a1a; --chip:#151515;
}

*{ box-sizing:border-box; }

html, body{
  margin:0;
  height:100%;
  background: var(--bg);
  color: var(--fg);
}

body{
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  overflow:hidden;

  /* layout: header + main + spacer (footer fijo) */
  display:flex;
  flex-direction:column;
  height:100dvh;
}

.muted{ color: var(--muted); }

/* Accesibilidad: salto al contenido */
.skip-link{
  position:absolute;
  left:12px;
  top:12px;
  z-index:1000;
  padding:10px 12px;
  border-radius:999px;
  background:var(--surface2);
  border:1px solid var(--input-border);
  color:var(--text);
  text-decoration:none;
  transform:translateY(-140%);
  transition:transform .18s ease;
}
.skip-link:focus{
  transform:translateY(0);
  outline:none;
}

.sr-only{
  position:absolute;
  width:1px;
  height:1px;
  padding:0;
  margin:-1px;
  overflow:hidden;
  clip:rect(0,0,0,0);
  white-space:nowrap;
  border:0;
}

/* ===== HEADER estilo OptimeFlow(s) (Normaliza-like) ===== */
.brand-header{
  position:sticky;
  top:0;
  z-index:40;

  padding:
    calc(6px + var(--safe-top))
    calc(14px + var(--safe-right))
    6px
    calc(14px + var(--safe-left));

  background:
    radial-gradient(circle at 0% 0%, color-mix(in srgb, var(--muted) 18%, transparent), transparent 55%),
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--bg) 92%, transparent),
      color-mix(in srgb, var(--bg) 70%, transparent)
    );

  backdrop-filter:var(--glass);
  border-bottom:1px solid var(--border);
  box-shadow:0 18px 40px rgba(0,0,0,0.85);
}

/* bloque de marca */
.brand{
  display:flex;
  align-items:center;
  gap:8px;
  position:relative;
  min-height:40px;
  font-weight:700;
  letter-spacing:.2px;
  min-width:0;
}

.brand-logo{
  height:clamp(32px, 5vw, 48px);
  width:clamp(32px, 5vw, 48px);
  object-fit:contain;
  border-radius:10px;
  flex-shrink:0;
}

.brand-logo-link{
  display:inline-grid;
  place-items:center;
  line-height:0;
  border-radius:10px;
  flex-shrink:0;
  outline:none;
  transition:transform .12s ease, filter .15s ease, box-shadow .15s ease;
}

.brand-logo-link:hover,
.brand-logo-link:focus-visible{
  transform:translateY(-1px);
  filter:brightness(1.04);
  box-shadow:0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent);
}

.brand-logo-link:active{
  transform:translateY(0);
}

.brand-logo.heat{
  filter:
    url(#heat-waves)
    drop-shadow(0 0 6px rgba(255,255,255,.35))
    drop-shadow(0 0 16px color-mix(in srgb, var(--accent) 55%, transparent));
}

.brand-word{
  font-weight:800;
  font-size:clamp(1.6rem, 2.8vw, 2.0rem);
  letter-spacing:.2px;
  white-space:nowrap;
  line-height:1;
}

/* Marca principal con glow */
.brand-neon{
  filter:hue-rotate(0deg);
  animation:hue 12s linear infinite, glow 3.2s ease-in-out infinite;
  color:#000;
}

@keyframes hue{
  from{filter:hue-rotate(0)}
  to{filter:hue-rotate(360deg)}
}
@keyframes glow{
  0%,100%{
    text-shadow:0 0 6px rgba(255,255,255,.25), 0 0 14px rgba(34,211,238,.55);
  }
  50%{
    text-shadow:0 0 10px rgba(255,255,255,.5), 0 0 24px rgba(167,139,250,.7);
  }
}

/* Tagline centrado */
.tagline{
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%, -50%);
  display:flex;
  align-items:center;
  gap:10px;
  line-height:1;
  white-space:nowrap;
  pointer-events:none;
  text-align:center;
  max-width: min(70vw, 860px);
}

/* Estética “rEsOnAnCiA / LaB” aplicada al nuevo título */
.tagline .res{
  font-weight:800;
  font-size:clamp(1.05rem, 2.1vw, 1.55rem);
  letter-spacing:.4px;
  animation:greenShift 6s ease-in-out infinite alternate;
  text-shadow: 0 0 8px rgba(34,197,94,.35), 0 0 22px rgba(34,197,94,.25);
}
.tagline .lab{
  font-weight:900;
  font-size:clamp(1.05rem, 2.1vw, 1.55rem);
  color:#fff;
  text-shadow: 0 0 8px rgba(255,255,255,.35), 0 0 24px rgba(255,255,255,.20);
}

@keyframes greenShift{
  0% {
    color:#16a34a;
    text-shadow:0 0 8px rgba(22,163,74,.45), 0 0 24px rgba(22,163,74,.30), 0 0 40px rgba(22,163,74,.20);
  }
  33% {
    color:#22c55e;
    text-shadow:0 0 8px rgba(34,197,94,.55), 0 0 24px rgba(34,197,94,.35), 0 0 40px rgba(34,197,94,.25);
  }
  66% {
    color:#84cc16;
    text-shadow:0 0 8px rgba(132,204,22,.45), 0 0 24px rgba(132,204,22,.30), 0 0 40px rgba(132,204,22,.20);
  }
  100% {
    color:#16a34a;
    text-shadow:0 0 8px rgba(22,163,74,.45), 0 0 24px rgba(22,163,74,.30), 0 0 40px rgba(22,163,74,.20);
  }
}

/* Controles rápidos (nav header) */
.quick-controls{
  margin-left:auto;
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:nowrap;
  justify-content:flex-end;
}
.topnav{
  display:flex;
  gap:8px;
  flex-wrap:nowrap;
}

/* Botón engranaje */
.icon-button{
  border-radius:999px;
  border:1px solid var(--border-subtle);
  background:
    radial-gradient(circle at 30% 0%, rgba(255,255,255,0.16), transparent 55%),
    linear-gradient(145deg, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 80%, transparent));
  padding:6px 10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  box-shadow:
    0 8px 22px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transition:
    background .15s ease,
    border-color .15s ease,
    transform .08s ease,
    box-shadow .15s ease,
    filter .16s ease;
}
.icon-button:hover{
  background:
    radial-gradient(circle at 30% 0%, rgba(255,255,255,0.22), transparent 55%),
    linear-gradient(145deg, color-mix(in srgb, var(--bg) 88%, transparent), color-mix(in srgb, var(--bg) 70%, transparent));
  border-color:var(--accent);
  box-shadow:
    0 10px 26px rgba(0,0,0,0.65),
    0 0 20px color-mix(in srgb, var(--accent) 28%, transparent);
  transform:translateY(-1px);
  filter:brightness(1.03);
}
.icon-button:active{
  transform:translateY(0);
  box-shadow:
    0 6px 16px rgba(0,0,0,0.7),
    inset 0 0 0 1px rgba(0,0,0,0.18);
  filter:brightness(0.98);
}

.icon-gear{
  width:18px;
  height:18px;
  border-radius:999px;
  border:2px solid var(--accent);
  box-shadow:0 0 0 1px rgba(0,0,0,0.25);
  position:relative;
}
.icon-gear::before,
.icon-gear::after{
  content:"";
  position:absolute;
  inset:4px;
  border-radius:999px;
  border:2px solid color-mix(in srgb, var(--muted) 75%, transparent);
}
.icon-gear::after{
  inset:7px;
  border-width:3px;
  border-color:var(--accent);
}

/* Menú engranaje */
.gear-menu-wrapper{ position:relative; }
.gear-menu{
  position:absolute;
  right:0;
  top:120%;
  min-width:200px;
  max-width:min(92vw, 320px);
  max-height: min(60vh, 420px);
  overflow:auto;
  background:var(--surface2);
  border:1px solid var(--input-border);
  border-radius:10px;
  box-shadow:var(--shadow);
  padding:6px;
  display:none;
}
.gear-menu.open{ display:block; }
.gear-item{
  width:100%;
  text-align:left;
  border:none;
  background:transparent;
  color:var(--text);
  padding:10px 10px;
  border-radius:8px;
  cursor:pointer;
  font-size:0.95rem;
}
.gear-item:hover{
  background:color-mix(in oklab,var(--chip) 80%, var(--accent));
}

/* Móvil/tablet en vertical: misma idea que Normaliza */
@media (max-width:1024px) and (orientation: portrait){
  .brand{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:8px;
    min-height:40px;
    flex-wrap:nowrap;
  }

  /* Ocultar “OptimeFlow(s)” */
  .brand-word{ display:none; }

  /* Rótulo dentro del flujo */
  .tagline{
    position:static;
    transform:none;
    flex:1;
    display:flex;
    justify-content:flex-start;
    align-items:center;
    pointer-events:none;

    white-space:nowrap;
    min-width:0;
    max-width:100%;
    overflow:hidden;

    font-size:clamp(0.78rem, 3.8vw, 0.98rem);
  }

  .quick-controls{
    margin-left:8px;
    flex-shrink:0;
  }
}

/* ===== MAIN layout ===== */
.mainContent{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-direction:column;
}

/* ===== Panel de Control (flotante/arrastrable) ===== */
.control-panel{
  position:fixed;
  z-index:55;
  left:16px;
  top:calc(76px + var(--safe-top));
  width:min(720px, calc(100vw - 32px));
  max-width:760px;

  background:linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 75%, var(--bg)));
  border:1px solid var(--input-border);
  border-radius:12px;
  box-shadow:var(--shadow);
  backdrop-filter:var(--glass);
}

.control-panel[hidden]{ display:none !important; }

.control-panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  border-bottom:1px solid rgba(255,255,255,.06);
  user-select:none;
  cursor:grab;
}
.control-panel-head:active{ cursor:grabbing; }

.control-panel-title{
  font-weight:900;
  letter-spacing:.2px;
  color:var(--fg);
}

.control-panel-actions{
  display:flex;
  gap:8px;
  align-items:center;
}

.panel-action-btn{
  background:transparent;
  border:1px solid var(--border);
  color:var(--fg);
  height:30px;
  min-width:34px;
  border-radius:8px;
  font-weight:900;
  cursor:pointer;
}
.panel-action-btn:hover{
  border-color:var(--accent);
  box-shadow:0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.control-panel-body{
  padding:12px;
}

.control-panel.minimized .control-panel-body{ display:none; }

/* Grid de controles dentro del panel */
.controlsGrid{
  display:grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  grid-auto-rows: 42px;
  gap: 12px 12px;
  align-items: stretch;
}
.controlsGrid .gridItem{
  display:flex;
  align-items:stretch;
  min-width:0;
}
.controlsGrid .gridItem > *{ width:100%; }

@media (max-width:1200px){
  .controlsGrid{
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}
@media (max-width:520px){
  .controlsGrid{
    grid-template-columns: 1fr;
  }
}

/* ===== Botones + cápsulas (estilo app original) ===== */
button, .inline{
  background: var(--chip);
  color: var(--fg);
  border: 1px solid #1c2735;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
button:hover{
  border-color: var(--accent);
  cursor: pointer;
}

label.inline{
  display:flex;
  align-items:center;
  gap:8px;
  height:42px;
  white-space:nowrap;
  overflow:hidden;
  cursor:default;
}
label.inline:hover{ border-color: var(--accent); }

/* Texto de la izquierda dentro de la cápsula */
label.inline > span{
  flex:1 1 auto;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* Select / input dentro de cápsula */
label.inline > select,
label.inline > input:not([type="checkbox"]){
  margin-left:auto;
  font-size:12px;
  line-height:1;
  width:auto;
  min-width:0;
  max-width:65%;
}
label.inline > select{
  -webkit-appearance:none;
  appearance:none;
  background-color:#fff;
  color:#000;
  border:1px solid color-mix(in srgb, var(--border) 75%, #fff);
  border-radius:6px;
  outline:none;
  padding:5px 30px 5px 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
  background-image:
    linear-gradient(45deg, transparent 50%, #000 50%),
    linear-gradient(135deg, #000 50%, transparent 50%),
    linear-gradient(to right, rgba(0,0,0,.12), rgba(0,0,0,.12));
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px),
    calc(100% - 26px) 50%;
  background-size:5px 5px, 5px 5px, 1px 60%;
  background-repeat:no-repeat;
}
label.inline > select:focus{
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.85),
    0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
label.inline > select option{
  background:#fff;
  color:#000;
}
label.inline > input:not([type="checkbox"]){
  background:transparent;
  border:0;
  outline:none;
  color:var(--fg);
  padding:0;
}
label.inline > input[type="checkbox"]{
  margin-left:auto;
  width:18px;
  height:18px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
input[type="number"]{ text-align:right; width: 6ch; }
select{ width:max-content; }

label.inline.small{ font-size:12px; padding:4px 8px; }

button.secondary{ opacity:.9; }
.hidden{ display:none !important; }

/* ===== Numbers Bar ===== */
.numbersBar{
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 75%, var(--bg));
  padding: 10px 12px 12px;
  flex:0 0 auto;
}
.numbers-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  margin-bottom:8px;
  flex-wrap:wrap;
}
.numbers-tools{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.tableWrap.full{
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  max-height: 40vh;
  background: color-mix(in srgb, var(--bg) 92%, #000);
}

table.numbers{
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  width: max-content;
  min-width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  line-height: 1.25;
}
table.numbers th,
table.numbers td{
  border-right: 1px solid #0e1621;
  border-bottom: 1px solid #0e1621;
  padding: 2px 4px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
table.numbers thead th{
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0e1621;
  color: #d8dde2;
}
table.numbers tbody th{
  position: sticky;
  left: 0;
  z-index: 1;
  background: #0e1621;
  color: #c8d0d7;
  text-align: left;
}
table.numbers tbody tr:nth-child(odd) td{ background: #0b1118; }
table.numbers td.pos{ color: #8be08b; }
table.numbers td.neg{ color: #ff8f8f; }
table.numbers td .val{ display:block; }
table.numbers td .sub{ display:block; font-size: 9px; color: var(--muted); }

@keyframes flashChange{
  0% { background-color: rgba(41,153,221,0.2);}
  100%{ background-color: transparent; }
}
table.numbers td.changed{ animation: flashChange 0.4s ease-out; }

/* ===== Workspace ===== */
.workspace{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns: 1fr 1.6fr 1fr;
  gap: 12px;
  padding: 12px;
}
.card{
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  min-height: 240px;
  overflow: auto;
}
@media (max-width:1200px){
  .workspace{
    grid-template-columns: 1fr;
    height:auto;
  }
  #simCanvas{ height: 50vh; }
}

/* Explicación */
.explain{
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}
.explain code{
  background: #0c121a;
  padding: 2px 4px;
  border-radius: 4px;
}
.flowNote{
  margin-top:10px;
  padding:10px 12px;
  border-radius:8px;
  border:1px solid color-mix(in srgb, var(--accent) 32%, var(--border));
  background: color-mix(in srgb, var(--panel) 80%, var(--accent) 8%);
}

/* Semillas manuales */
.manualSeeds.hidden{ display:none; }
.manualSeeds h4{ margin: 10px 0; }

.seedGrid{
  display:grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.seedGrid .seedCell{
  display:flex;
  flex-direction:column;
  gap: 4px;
}
.seedGrid label{ font-size: 12px; color: var(--muted); }
.seedGrid input{
  width: 100%;
  background: #0c121a;
  color: var(--fg);
  border: 1px solid #1c2735;
  border-radius: 6px;
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.seedActions{
  display:flex;
  align-items:center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap:wrap;
}
.seedActions span#seedStatus{
  color: var(--muted);
  font-size: 12px;
}
.manualRunRow{ margin-top: 6px; }

/* Viewer */
.viewer{
  position: relative;
  display: grid;
  place-items: center;
}
.hud{
  position: absolute;
  inset: 8px 12px auto 12px;
  display:flex;
  gap: 16px;
  align-items:flex-start;
  justify-content:space-between;
  pointer-events:none;
}
.hud .keys{
  color: var(--muted);
  font-size: 12px;
}
.hud pre#info{
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-align: right;
}
#simCanvas{
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: linear-gradient(180deg, #0b0f14 0%, #0c1118 100%);
  display:block;
  border-radius: 6px;
}

/* Panel datos grupo */
.singleData{
  position:absolute;
  right: 10px;
  bottom: 10px;
  max-height: 70%;
  width: 280px;
  overflow: auto;
  background: rgba(12,18,26,0.92);
  border: 1px solid #1c2735;
  border-radius: 8px;
  padding: 10px;
  z-index: 2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.singleData h4{
  margin:0 0 8px 0;
  font-size: 12px;
  color: var(--muted);
}
.singleData table{
  width:100%;
  border-collapse:collapse;
  table-layout:fixed;
}
.singleData th,
.singleData td{
  border-bottom: 1px solid #0e1621;
  padding: 4px 6px;
  text-align:right;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.singleData th:first-child,
.singleData td:first-child{ text-align:left; }

/* Notas */
#notesText{
  width: 100%;
  min-height: 240px;
  background: #0c121a;
  color: var(--fg);
  border: 1px solid #1c2735;
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}
.notes-actions{
  display:flex;
  align-items:center;
  gap: 8px;
  margin-top:8px;
  flex-wrap:wrap;
}
#notesStatus{
  color: var(--muted);
  font-size: 12px;
}

/* Controles bajo Notas */
.viewerControls{
  margin-top:10px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
  border-top:1px solid var(--border);
  padding-top:10px;
}

/* ===== Modales (estilo Normaliza) ===== */
.modal{
  border:none;
  border-radius:12px;
  max-width:920px;
  width:92vw;
  background:linear-gradient(180deg,var(--panel),var(--surface2));
  color:var(--text);
  box-shadow:var(--shadow);
}
.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 14px;
  border-bottom:1px solid rgba(255,255,255,.05);
}
.modal-body{ padding:14px; }
.modal-foot{
  padding:10px 14px;
  border-top:1px solid rgba(255,255,255,.05);
  display:flex;
  justify-content:flex-end;
}

.btn{
  background:var(--chip);
  border:1px solid #334155;
  color:var(--text);
  padding:10px 14px;
  border-radius:var(--radius-sm);
  cursor:pointer;
  min-height:44px;
}
.btn:hover{ background:color-mix(in oklab,var(--chip) 85%,var(--accent)); }
.btn.small{ font-size:12px; padding:8px 12px; min-height:36px; }

.chip{
  background:var(--chip);
  border:1px solid #111827;
  color:var(--text);
  border-radius:999px;
  padding:8px 12px;
  cursor:pointer;
  min-height:36px;
}
.chip.ghost{ background:transparent; }

/* Grid de idioma */
.lang-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(120px,1fr));
  gap:8px;
}

.lang-grid .btn.active,
.lang-grid .btn[aria-pressed="true"]{
  border-color:color-mix(in oklab, var(--accent) 75%, white);
  box-shadow:0 0 0 2px color-mix(in oklab, var(--accent) 30%, transparent);
  background:color-mix(in oklab, var(--chip) 82%, var(--accent));
  font-weight:600;
}

/* Grid de temas */
.themes-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
  gap:8px;
}
.theme-chip{
  border-radius:999px;
  border:1px solid var(--input-border);
  background:var(--chip);
  color:var(--text);
  padding:8px 12px;
  text-align:center;
  cursor:pointer;
  font-size:0.9rem;
}
.theme-chip:hover{
  background:color-mix(in oklab,var(--chip) 80%, var(--accent));
}
.theme-chip.active,
.theme-chip[aria-pressed="true"]{
  border-color:color-mix(in oklab, var(--accent) 75%, white);
  box-shadow:0 0 0 2px color-mix(in oklab, var(--accent) 30%, transparent);
}

/* Texto largo MIT */
.license-pre{
  margin:0;
  padding:12px;
  border-radius:var(--radius-sm);
  border:1px solid var(--input-border);
  background:var(--surface2);
  white-space:pre-wrap;
  word-break:break-word;
  line-height:1.45;
  max-height:60vh;
  overflow:auto;
}

.side-card{
  background:linear-gradient(180deg,var(--panel),var(--surface2));
  border:1px solid var(--input-border);
  border-radius:var(--radius);
  padding:12px;
  box-shadow:var(--shadow);
}

.warning-card{
  padding:14px;
  border-radius:12px;
  border:1px solid color-mix(in srgb, var(--footer-author) 38%, var(--input-border));
  border-left:4px solid var(--footer-author);
  background:linear-gradient(180deg, color-mix(in srgb, var(--panel) 86%, var(--footer-author) 6%), color-mix(in srgb, var(--surface2) 92%, black));
  box-shadow:var(--shadow);
}

.warning-card p + p{
  margin-top:10px;
}

.warning-card strong{
  color:var(--fg);
}

dialog::backdrop{
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

select{
  color:#000;
}
select option{
  background:#fff;
  color:#000;
}

.modal-wide{
  max-width:min(1080px, 96vw);
  width:min(1080px, 96vw);
}

.modal-wide .modal-body{
  max-height:min(74vh, 900px);
  overflow:auto;
}

.dialog-rich-content{
  display:grid;
  gap:14px;
  font-size:14px;
  line-height:1.62;
}

.dialog-rich-content h4{
  margin:0 0 6px;
  color:var(--fg);
  font-size:1rem;
}

.dialog-rich-content p,
.dialog-rich-content ul,
.dialog-rich-content ol{
  margin:0;
}

.dialog-rich-content ul{
  padding-left:18px;
}

.dialog-rich-content li + li{
  margin-top:6px;
}

.dialog-rich-content code{
  background:color-mix(in srgb, var(--chip) 86%, black);
  border:1px solid color-mix(in srgb, var(--border) 88%, #000);
  border-radius:6px;
  padding:2px 5px;
}

.dialog-rich-content a{
  color:var(--accent);
  text-decoration:underline;
  text-underline-offset:2px;
  word-break:break-word;
}

.dialog-rich-content a:hover{
  filter:brightness(1.08);
}

.info-status-card{
  margin-bottom:16px;
  padding:12px;
  border-radius:12px;
  border:1px solid color-mix(in srgb, var(--accent) 26%, var(--border));
  background:linear-gradient(180deg, color-mix(in srgb, var(--panel) 82%, var(--accent) 8%), color-mix(in srgb, var(--panel) 92%, black));
  box-shadow:var(--shadow);
}

.info-status-card h4{
  margin:0 0 10px;
  font-size:0.98rem;
  color:var(--fg);
}

.dialog-status-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(160px, 1fr));
  gap:10px;
}

.status-item{
  display:flex;
  flex-direction:column;
  gap:4px;
  min-height:70px;
  padding:10px 11px;
  border-radius:10px;
  border:1px solid color-mix(in srgb, var(--border) 85%, #000);
  background:color-mix(in srgb, var(--surface2) 88%, black);
}

.status-label{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.06em;
  color:var(--muted);
}

.status-value{
  font-size:14px;
  line-height:1.35;
  color:var(--fg);
}

.essay-links{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));
  gap:12px;
}

.essay-link-card{
  display:flex;
  flex-direction:column;
  gap:8px;
  padding:12px;
  border-radius:12px;
  border:1px solid color-mix(in srgb, var(--accent) 20%, var(--border));
  background:linear-gradient(180deg, color-mix(in srgb, var(--surface2) 88%, black), color-mix(in srgb, var(--panel) 92%, black));
}

.essay-link-card strong{
  color:var(--fg);
}

.essay-link-card .doi{
  font-size:12px;
  color:var(--muted);
  word-break:break-word;
}

.footer-author-link{
  color:var(--footer-author) !important;
  text-decoration:underline;
  text-decoration-color:color-mix(in srgb, var(--footer-author) 72%, transparent);
  text-underline-offset:2px;
  text-decoration-thickness:2px;
}

.footer-author-link:hover,
.footer-author-link:focus-visible{
  color:color-mix(in srgb, var(--footer-author) 84%, white) !important;
}

/* ===== Footer spacer ===== */
#footerSpacer{
  flex:0 0 auto;
  height: var(--footer-h);
}

/* ===== FOOTER estilo OptimeFlow(s) ===== */
.brand-footer{
  background:
    radial-gradient(circle at 0% 100%, color-mix(in srgb, var(--muted) 18%, transparent), transparent 55%),
    radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
    linear-gradient(
      0deg,
      color-mix(in srgb, var(--bg) 92%, transparent),
      color-mix(in srgb, var(--bg) 70%, transparent)
    );
  border-top: 1px solid var(--border);

  padding:
    4px
    calc(12px + var(--safe-right))
    calc(4px + var(--safe-bottom))
    calc(12px + var(--safe-left));

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  color:var(--muted);
  box-shadow:0 -14px 32px rgba(0,0,0,.55);

  position:fixed;
  left:0;
  right:0;
  bottom:0;
  z-index:40;

  backdrop-filter:var(--glass);
}

.brand-footer strong{ color:var(--ink); }
.brand-footer .sep{ opacity:.6; }

.footer-left{
  display:flex;
  flex-direction:column;
  gap:2px;
  font-size:0.78rem;
  min-width:0;
}

.footer-center{
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
}

.footer-right{
  display:flex;
  align-items:center;
  gap: clamp(8px, 2vw, 18px);
  min-width:0;
}

.footer-mit-btn{
  background:var(--ghost);
  border:1px solid var(--border);
  color:var(--ink);
  height:26px;
  border-radius:7px;
  padding:0 10px;
  font-weight:800;
  letter-spacing:.35px;
  cursor:pointer;
  transition:
    background .15s ease,
    border-color .15s ease,
    box-shadow .15s ease,
    transform .08s ease,
    filter .15s ease;
}
.footer-mit-btn:hover{
  transform:translateY(-1px);
  background:color-mix(in srgb, var(--ghost) 70%, var(--accent) 30%);
  border-color:var(--accent);
  box-shadow:
    0 8px 24px rgba(0,0,0,.35),
    0 0 16px color-mix(in srgb, var(--accent) 30%, transparent);
  filter:brightness(1.03);
}
.footer-mit-btn:active{
  transform:translateY(0);
  filter:brightness(0.98);
  box-shadow:0 6px 16px rgba(0,0,0,.4);
}

.footer-logo-btn{
  display:inline-grid;
  place-items:center;
  padding:0;
  border-radius:50%;
  border:1px solid transparent;
  background:transparent;
  cursor:pointer;
  -webkit-appearance:none;
  appearance:none;
  transition:
    box-shadow .14s ease,
    transform .08s ease,
    filter .14s ease,
    border-color .12s ease,
    background-color .12s ease;
  box-shadow:none;
}
.footer-logo-btn:hover,
.footer-logo-btn:focus-visible{
  background:
    radial-gradient(circle at 20% 0%, rgba(255,255,255,0.16), transparent 55%),
    linear-gradient(145deg, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 80%, transparent));
  border-color:var(--accent);
  box-shadow:
    0 8px 24px rgba(0,0,0,0.45),
    inset 0 1px 0 rgba(255,255,255,0.08);
}
.footer-logo-btn:active{ transform:scale(0.97); }

.footer-logo{
  height: clamp(22px, 5vw, 28px);
  width: clamp(22px, 5vw, 28px);
  object-fit:contain;
  border-radius:10px;
}

.tag-logo{
  object-fit:contain;
  transform-origin:center center;
  animation:sway 5.5s ease-in-out infinite;
  filter:
    drop-shadow(0 0 6px rgba(255,255,255,.35))
    drop-shadow(0 0 16px color-mix(in srgb, var(--accent) 55%, transparent));
}
@keyframes sway{
  0%{transform:rotate(-3deg);}
  50%{transform:rotate(3deg);}
  100%{transform:rotate(-3deg);}
}

/* Footer responsive (patrón 3 columnas) */
@media (max-width:600px) and (orientation: portrait){
  .brand-footer{
    display:grid;
    grid-template-columns: 1fr auto 1fr;
    align-items:center;

    padding-left: calc(10px + var(--safe-left));
    padding-right: calc(10px + var(--safe-right));

    column-gap:8px;
  }
  .footer-center{
    position:static;
    transform:none;
    justify-self:center;
  }
  .footer-left{
    justify-self:flex-start;
    text-align:left;
  }
  .footer-right{
    justify-self:flex-end;
    display:flex;
    flex-direction:column;
    align-items:flex-end;
    gap:4px;
  }
  .footer-logo{
    height: clamp(32px, 10vw, 40px);
    width: clamp(32px, 10vw, 40px);
  }
}

/* ===== TOAST ===== */
.toast{
  position:fixed;
  left:50%;
  transform:translateX(-50%) translateY(6px);
  bottom:calc(var(--footer-h) + 12px + env(safe-area-inset-bottom));
  z-index:60;
  min-width:min(92vw, 720px);
  max-width:min(92vw, 720px);
  padding:10px 12px;
  border-radius:12px;
  background:color-mix(in oklab, var(--surface2) 90%, black);
  border:1px solid var(--input-border);
  box-shadow:var(--shadow);
  color:var(--text);
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease, transform .18s ease;
}
.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}
.toast[data-type="ok"]{
  border-color: color-mix(in oklab, #22c55e 55%, var(--input-border));
}
.toast[data-type="warn"]{
  border-color: color-mix(in oklab, var(--accent) 55%, var(--input-border));
}
.toast[data-type="bad"]{
  border-color: color-mix(in oklab, #ef4444 55%, var(--input-border));
}