/* EBM-9000 · Estilos
   Paleta: Botones #1F3B5C · Menú #3F6FA6 · Agua #A9C9E8 · Oil #7A4E2D · Fondo #E7D8C9 */
:root {
  --btn: #1F3B5C;
  --menu: #3F6FA6;
  --agua: #A9C9E8;
  --oil: #7A4E2D;
  --fondo: #E7D8C9;
  --gas: #E8C86A;
  --gas-dark: #C99A3B;
  --roca: #A08A72;
  --card: #F6EEE4;
  --card2: #FCF8F2;
  --line: #CDB9A5;
  --text: #2B1F16;
  --muted: #6B5A4B;
  --ok: #2E7D4F;
  --warn: #B4641E;
  --header-h: 64px;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(43, 31, 22, .10);
  --font-body: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-head: 'Exo 2', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--fondo);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
a { color: var(--btn); }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--btn); line-height: 1.2; margin: 0 0 .5em; }
sub, sup { font-size: .72em; line-height: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Encabezado y navegación ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  min-height: var(--header-h);
  background: var(--menu);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 6px 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; min-width: 0; }
.brand img { width: 44px; height: 52px; object-fit: contain; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .35)); }
.brand .name { font-family: var(--font-head); font-weight: 800; font-size: 22px; letter-spacing: .06em; line-height: 1; }
.brand .sub { font-size: 12px; opacity: .9; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tab-btn {
  background: rgba(255, 255, 255, .10); color: #fff; border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 10px; padding: 8px 14px; font-weight: 600; cursor: pointer; transition: background .15s;
}
.tab-btn:hover { background: rgba(255, 255, 255, .22); }
.tab-btn.active { background: var(--btn); border-color: var(--btn); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn {
  background: var(--btn); color: #fff; border: 1.5px solid var(--btn); border-radius: 10px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: filter .15s, transform .05s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--btn); }
.btn.icon { width: 40px; height: 40px; padding: 0; justify-content: center; font-size: 18px; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1.5px solid var(--btn); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { background: transparent; color: var(--btn); border: 0; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1.5px solid var(--btn); }
.seg button.active { background: var(--btn); color: #fff; }
.seg.sm button { padding: 5px 10px; font-size: 13px; }
select.ctl { border: 1.5px solid var(--btn); color: var(--btn); background: #fff; border-radius: 10px; padding: 7px 10px; font-weight: 600; cursor: pointer; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--card2); border: 1px solid var(--line); }
.badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.badge.end .dot { background: var(--warn); }
.badge.inj .dot { background: var(--menu); }

/* Tooltip (pregunta didáctica) */
#tooltip {
  position: fixed; z-index: 1000; max-width: 320px; pointer-events: none;
  background: #2B1F16; color: #fff; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
#tooltip.show { opacity: 1; transform: none; }
#tooltip .tt-sym { font-family: var(--font-head); font-weight: 700; color: var(--gas); font-size: 15px; }
#tooltip .tt-name { color: #d9c9b8; font-size: 12px; }
#tooltip .tt-q { font-weight: 600; margin: 5px 0 3px; font-size: 13.5px; }
#tooltip .tt-v { color: var(--agua); font-weight: 600; }
[data-tip] { cursor: help; }

/* ---------- Simulación ---------- */
.sim {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 8px;
  padding: 10px 14px 12px; height: calc(100dvh - var(--header-h)); min-height: 620px;
}
.sim-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sim-controls .spacer { flex: 1; }
.dash { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.chip {
  flex: 0 0 auto; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; min-width: 96px;
}
.chip .k { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chip .v { font-family: var(--font-head); font-weight: 700; font-size: 15px; white-space: nowrap; color: var(--btn); }
.chip.hl { border-color: var(--btn); background: #fff; }
.sim-main { display: grid; grid-template-columns: minmax(0, 1fr) 410px; gap: 10px; min-height: 0; }
.tank-wrap { position: relative; min-height: 0; overflow: hidden; display: flex; }
.tank-wrap svg { width: 100%; height: 100%; display: block; }
.tank-note { position: absolute; left: 12px; bottom: 8px; font-size: 11.5px; color: var(--muted); background: rgba(252, 248, 242, .85); padding: 3px 8px; border-radius: 6px; }
.panel { padding: 12px 14px; overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.panel h3 { margin: 0; font-size: 16px; }
.eq-live { font-family: var(--font-head); font-size: 13.5px; color: var(--text); background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; line-height: 1.6; }
.eq-live .L { color: var(--btn); font-weight: 700; }
.eq-live .R { color: var(--oil); font-weight: 700; }
.bar-block { display: flex; flex-direction: column; gap: 4px; }
.bar-title { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.bar-title .tot { font-family: var(--font-head); color: var(--btn); }
.bar { position: relative; display: flex; height: 34px; border-radius: 8px; overflow: hidden; background: #E9E0D5; border: 1px solid var(--line); }
.bar .sg { height: 100%; transition: width .2s linear; position: relative; }
.bar .sg:hover { filter: brightness(1.1); outline: 2px solid #fff; outline-offset: -2px; }
.bar .neg {
  position: absolute; top: 0; height: 100%; transition: left .2s linear, width .2s linear;
  background: repeating-linear-gradient(135deg, rgba(74, 46, 26, .70) 0 6px, rgba(255, 255, 255, .55) 6px 12px);
  border-left: 2px dashed #2B1F16; box-sizing: border-box;
}
.bar .mark { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dashed var(--btn); transition: left .2s linear; }
.balance-line { font-size: 13px; display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); }
.balance-line b { font-family: var(--font-head); }
.balance-line.ok { border-color: var(--ok); }
.legend { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; gap: 3px 8px; align-items: center; font-size: 13px; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .15); }
.legend .sw.neg { background: repeating-linear-gradient(135deg, rgba(74, 46, 26, .70) 0 3px, rgba(255, 255, 255, .55) 3px 6px); }
.legend .lg-sym { font-family: var(--font-head); font-weight: 600; white-space: nowrap; }
.legend .lg-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend .lg-pct { color: var(--muted); font-size: 12px; min-width: 44px; text-align: right; }
.legend .lg-head { grid-column: 1 / -1; font-weight: 700; color: var(--btn); margin-top: 4px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.legend .row { display: contents; }
.legend .row:hover > * { background: rgba(31, 59, 92, .07); }
.mech { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.mech b { color: var(--btn); }
.warnbox { font-size: 12.5px; color: #6b3d0f; background: #fbe9d3; border: 1px solid #e7bf92; border-radius: 8px; padding: 6px 10px; }
.timeline { padding: 8px 16px 6px; }
.timeline-top { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.timeline-top .tlabel { font-family: var(--font-head); font-weight: 700; color: var(--btn); min-width: 150px; }
.timeline input[type=range] { width: 100%; accent-color: var(--btn); cursor: pointer; margin: 6px 0 0; }
.events { position: relative; height: 34px; margin: 2px 6px 0; }
.ev { position: absolute; top: 0; transform: translateX(-50%); font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }
.ev::before { content: ''; display: block; width: 2px; height: 8px; background: var(--btn); margin: 0 auto 2px; border-radius: 2px; }
.ev.end { color: var(--warn); }
.ev.end::before { background: var(--warn); }
.ev.past { color: var(--btn); font-weight: 600; }
.end-banner {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  background: #2B1F16; color: #fff; padding: 10px 18px; border-radius: 12px; font-family: var(--font-head); font-weight: 700; font-size: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); display: none; text-align: center; max-width: 90%;
}
.end-banner.show { display: block; animation: pop .3s ease-out; }
.end-banner small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 12.5px; opacity: .85; margin-top: 3px; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* SVG del tanque */
.lbl { font-family: var(--font-body); font-size: 12px; fill: var(--text); }
.lbl.b { font-weight: 700; font-family: var(--font-head); }
.lbl.w { fill: #fff; }
.lbl.muted { fill: var(--muted); font-size: 11px; }
.gauge-needle { transition: transform .2s linear; transform-origin: 0 0; }
.flow { stroke-dasharray: 6 6; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -12; } }
.bubble { animation: rise 3s ease-in infinite; }
@keyframes rise { 0% { transform: translateY(0); opacity: .9; } 100% { transform: translateY(-22px); opacity: 0; } }
.hot:hover { filter: brightness(1.08); }
@media (prefers-reduced-motion: reduce) { .flow, .bubble { animation: none; } .bar .sg, .bar .neg, .bar .mark { transition: none; } }

/* ---------- Modal de datos ---------- */
.modal { position: fixed; inset: 0; background: rgba(43, 31, 22, .55); display: none; align-items: center; justify-content: center; z-index: 900; padding: 14px; }
.modal.open { display: flex; }
.modal-box { background: var(--card2); border-radius: 16px; max-width: 1040px; width: 100%; max-height: 94dvh; overflow: auto; padding: 18px 22px 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 22px; }
.modal-head .x { margin-left: auto; }
.fgroup { margin-top: 12px; }
.fgroup h4 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--menu); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); line-height: 1.25; margin-bottom: 3px; min-height: 30px; }
.field .sym { font-family: var(--font-head); font-weight: 700; color: var(--btn); font-size: 13px; }
.field .in { display: flex; align-items: center; gap: 6px; }
.field input { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
.field input:focus { outline: 2px solid var(--menu); border-color: var(--menu); }
.field input.bad { border-color: #c0392b; outline-color: #c0392b; }
.field .u { font-size: 11.5px; color: var(--muted); white-space: nowrap; min-width: 54px; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.errbox { color: #7b1e12; background: #f9dcd7; border: 1px solid #e6a49a; border-radius: 8px; padding: 8px 12px; font-size: 13px; display: none; }
.errbox.show { display: block; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2B1F16; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 1200; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* ---------- Teoría ---------- */
.theory { max-width: 1100px; margin: 0 auto; padding: 20px 18px 24px; }
.theory-top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.theory-top h1 { margin: 0; font-size: 26px; }
.theory-top .spacer { flex: 1; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 18px; }
.toc a { font-size: 12.5px; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; text-decoration: none; color: var(--btn); font-weight: 600; }
.theory section { margin-bottom: 26px; scroll-margin-top: 80px; }
.theory h2 { font-size: 21px; border-left: 5px solid var(--menu); padding-left: 10px; }
.theory h3 { font-size: 16.5px; margin-top: 16px; }
.theory p, .theory li { max-width: 78ch; }
.eq { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; overflow-x: auto; margin: 10px 0; position: relative; font-size: 15px; }
.eq .eqn { position: absolute; right: 12px; top: 8px; font-size: 12px; color: var(--muted); font-family: var(--font-head); }
.eq .katex-display { margin: .4em 0; }
.eq .katex-display > .katex { text-align: left; }
.eq.sub { border-left: 5px solid var(--oil); }
.eq code { font-size: 13px; white-space: pre-wrap; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; background: var(--card2); border-radius: 12px; overflow: hidden; font-size: 14px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.tbl th { background: var(--menu); color: #fff; font-family: var(--font-head); font-weight: 600; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .k { font-family: var(--font-head); font-weight: 700; white-space: nowrap; }
.tbl tr:hover td { background: rgba(31, 59, 92, .05); }
.callout { border-left: 5px solid var(--gas-dark); background: #FBF3DC; border-radius: 10px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }
.callout.blue { border-left-color: var(--menu); background: #E9F0F8; }
.termgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.termcard { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; border-top: 5px solid var(--menu); }
.termcard .q { font-weight: 600; color: var(--btn); font-size: 14px; }
.termcard .katex-display { margin: .3em 0; overflow-x: auto; overflow-y: hidden; }
.termgrid.wide { grid-template-columns: 1fr; }
.termcard .res { font-family: var(--font-head); font-weight: 700; font-size: 15px; color: var(--oil); }
.authors { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.author { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.author b { font-family: var(--font-head); color: var(--btn); font-size: 15px; display: block; }
.author .yrs { color: var(--muted); font-size: 12px; }
.sub-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.sub-controls input[type=range] { flex: 1; min-width: 160px; accent-color: var(--btn); }
.sub-controls .st { font-family: var(--font-head); font-weight: 700; color: var(--btn); white-space: nowrap; }
.biblio { position: sticky; bottom: 0; z-index: 20; margin-top: 24px; }
.biblio-body { display: none; background: var(--card2); border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; max-height: 55dvh; overflow: auto; padding: 14px 18px; box-shadow: 0 -8px 24px rgba(0, 0, 0, .12); }
.biblio.open .biblio-body { display: block; }
.biblio-bar {
  width: 100%; background: var(--btn); color: #fff; border: 0; padding: 14px 18px; font-size: 16px; font-weight: 700; font-family: var(--font-head);
  border-radius: 12px 12px 0 0; cursor: pointer; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 -4px 16px rgba(0, 0, 0, .2);
}
.biblio.open .biblio-bar { border-radius: 0; }
.biblio-bar .arrow { transition: transform .2s; font-size: 18px; }
.biblio.open .biblio-bar .arrow { transform: rotate(180deg); }
.biblio-body ol { padding-left: 22px; }
.biblio-body li { margin-bottom: 8px; font-size: 14px; }
.biblio-body a { word-break: break-all; }

/* ---------- Créditos ---------- */
.credits { max-width: 1100px; margin: 0 auto; padding: 24px 18px 60px; display: grid; gap: 18px; }
.hero { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 22px; align-items: center; padding: 22px 26px; }
.hero img { width: 100%; max-width: 200px; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .25)); }
.hero h1 { font-size: 38px; letter-spacing: .06em; margin-bottom: 4px; }
.hero .tag { font-size: 15px; color: var(--muted); margin-bottom: 10px; }
.hero p { margin: 6px 0; max-width: 78ch; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.author-card { padding: 22px 26px; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 20px; align-items: center; }
.author-card img { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; border: 5px solid #fff; box-shadow: var(--shadow); }
.author-card h2 { font-size: 24px; margin-bottom: 2px; }
.author-card .role { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.visit { padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.visit img { border-radius: 12px; box-shadow: var(--shadow); }
.visit img.qr { width: 220px; max-width: 100%; }
.visit img.insta { width: 100%; max-width: 380px; }
.visit .cap { font-family: var(--font-head); font-weight: 700; color: var(--btn); font-size: 16px; }
.visit .url { font-size: 12.5px; color: var(--muted); word-break: break-all; }
.sources { padding: 18px 24px; font-size: 14px; }
.sources ul { margin: 6px 0 0; padding-left: 20px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 10px 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1050px) {
  .sim { height: auto; min-height: 0; }
  .sim-main { grid-template-columns: 1fr; }
  .tank-wrap { min-height: 480px; }
  .panel { max-height: none; }
}
@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; }
  .tabs { margin-left: 0; width: 100%; justify-content: stretch; }
  .tab-btn { flex: 1; padding: 8px 6px; font-size: 13px; }
  .brand .sub { display: none; }
  .hero, .author-card { grid-template-columns: 1fr; text-align: center; justify-items: center; }
  .hero h1 { font-size: 30px; }
  .tank-wrap { min-height: 380px; }
  .tank-note { display: none; }
  .timeline-top .tlabel { min-width: 0; }
}
