/* ECS: identidad "piezas que encajan". No usa /css/base.css (noBaseStyles): todo lo que necesita está acá.
   El color informa: violeta = entidad, amarillo = componente, turquesa = sistema, coral = problema.
   Estructura propia: regla de años fija arriba, relato a la izquierda y taller fijo a la derecha
   (arriba en el celular). */
:root {
  --paper: #FCFCFB; --surface: #FFFFFF; --ink: #1C2433; --ink-soft: #4A5468;
  --border: #1C2433; --piece-border: #1C2433; --shadow: #1C2433; --dots: rgba(28, 36, 51, .13);
  --entity: #A08CF2; --component: #F2B632; --system: #3CC3BB; --problem: #F2856F; --on-piece: #1C2433;
  --entity-text: #5B3FC4; --component-text: #7A5000; --system-text: #0A6F6A; --problem-text: #B03A26;
  --f-title: "Bricolage Grotesque", system-ui, sans-serif;
  --f-text: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  --f-mono: "Space Mono", ui-monospace, monospace;
  --workshop-height: 42vh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151515; --surface: #1A1A19; --ink: #E8ECF3; --ink-soft: #A9B3C5;
    --border: #7C8AA3; --piece-border: #05080E; --shadow: #05080E; --dots: rgba(232, 236, 243, .09);
    --entity: #A996FF; --component: #F5C04A; --system: #43CFC6; --problem: #FF8C75; --on-piece: #141A26;
    --entity-text: #BBA9FF; --component-text: #F5C04A; --system-text: #5FD9D1; --problem-text: #FF9C88;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151515; --surface: #1A1A19; --ink: #E8ECF3; --ink-soft: #A9B3C5;
  --border: #7C8AA3; --piece-border: #05080E; --shadow: #05080E; --dots: rgba(232, 236, 243, .09);
  --entity: #A996FF; --component: #F5C04A; --system: #43CFC6; --problem: #FF8C75; --on-piece: #141A26;
  --entity-text: #BBA9FF; --component-text: #F5C04A; --system-text: #5FD9D1; --problem-text: #FF9C88;
  color-scheme: dark;
}

/* Base */
* { box-sizing: border-box; }
/* Esta guía no carga /css/base.css: su reinicio es propio */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden]:not([hidden=until-found i]) { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--bar-height) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-text); font-size: 1.0625rem; line-height: 1.6; -webkit-font-smoothing: antialiased; }
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration-color: var(--entity); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--entity-text); }
:focus-visible { outline: 3px solid var(--entity-text); outline-offset: 3px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--f-title); margin: 0; text-wrap: balance; }
.mono { font-family: var(--f-mono); font-size: .88em; }
.t-entity { color: var(--entity-text); }
.t-component { color: var(--component-text); }
.t-system { color: var(--system-text); }
.t-problem { color: var(--problem-text); }

/* Barra con la regla de años */
/* «Volver» y el foco son fijos (/css/common.css): la línea de tiempo les deja lugar con el relleno de los costados */
.bar { --bar-pad: clamp(16px, 3vw, 32px); position: sticky; top: 0; z-index: 30; height: var(--bar-height); display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; padding: 0 calc(var(--bar-pad) + clamp(12px, 3vw, 40px)); background: var(--paper); }
.bar-title { display: none; margin: 0; font: 800 1rem var(--f-title); }
.timeline { min-width: 0; }
.timeline ol { list-style: none; margin: 0 auto; padding: 0; max-width: 760px; display: flex; justify-content: space-between; align-items: center; position: relative; }
.timeline ol::before { content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 3px; margin-top: -1.5px; border-radius: 2px; background: var(--border); }
.timeline li { position: relative; }
.timeline a { display: grid; place-items: center; min-width: 44px; min-height: 44px; text-decoration: none; }
.timeline .year { display: block; padding: 3px 9px; border: 2.5px solid var(--border); border-radius: 8px; background: var(--paper); color: var(--ink); font: 700 .85rem var(--f-title); font-variant-numeric: tabular-nums; transition: transform .15s ease; border-color: var(--border); }
.timeline a:hover .year { background: var(--surface); }
.timeline a[aria-current="step"] .year { background: var(--ink); color: var(--paper); box-shadow: 3px 3px 0 var(--entity); transform: translateY(-2px); }

/* Relato y taller */
.story-layout { max-width: 1280px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 32px); display: grid; grid-template-columns: minmax(0, 36rem) minmax(0, 1fr); gap: clamp(28px, 5vw, 72px); align-items: start; }
.chapters { padding-bottom: 20vh; }
.chapter { min-height: 85vh; padding-block: clamp(48px, 10vh, 120px) 24px; display: grid; gap: 18px; align-content: start; }
.chapter > * { margin: 0; }
.chapter--cover { min-height: calc(100vh - var(--bar-height)); padding-top: clamp(32px, 7vh, 80px); }
.chapter h1 { font-size: clamp(2.8rem, 1.6rem + 5vw, 5.4rem); font-weight: 800; font-variation-settings: "wdth" 100, "opsz" 96; line-height: .92; letter-spacing: -.02em; }
.chapter h2 { font-size: clamp(2rem, 1.4rem + 2.2vw, 3rem); font-weight: 800; font-variation-settings: "wdth" 88, "opsz" 72; line-height: 1; letter-spacing: -.015em; }
.lead { font-size: 1.25rem; line-height: 1.5; }
.hint { font-weight: 700; }
.chapter-year { margin-bottom: -4px; }
.brick { display: inline-block; padding: 4px 12px 3px; border: 2.5px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 3px 3px 0 var(--shadow); font: 800 1rem var(--f-title); font-variant-numeric: tabular-nums; }
.myth { padding: 14px 16px; border: 2.5px dashed var(--border); border-radius: 12px; background: var(--surface); }
.myth p { margin: 0; }
.source { font-size: .92rem; color: var(--ink-soft); }
.source a { color: var(--ink); }
.ecs-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.ecs-list li { padding: 10px 14px; border: 2.5px solid var(--border); border-left-width: 10px; border-radius: 10px; background: var(--surface); }
.ecs-list .li-entity { border-left-color: var(--entity); }
.ecs-list .li-component { border-left-color: var(--component); }
.ecs-list .li-system { border-left-color: var(--system); }

.workshop { position: sticky; top: calc(var(--bar-height) + 20px); height: calc(100vh - var(--bar-height) - 40px); }
html:not(.js) .workshop { display: none; }
.workshop-frame { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; border: 2.5px solid var(--border); border-radius: 16px; background-color: var(--surface); background-image: radial-gradient(var(--dots) 1.3px, transparent 1.6px); background-size: 20px 20px; box-shadow: 6px 6px 0 var(--shadow); }
.workshop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 2.5px solid var(--border); background: var(--surface); }
.workshop-title { margin: 0; font: 800 1rem var(--f-title); }
.button.expand { display: none; }
.back-to-story:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; padding: 0; border: 0; }
.to-workshop { justify-self: start; }
.workshop-scenes { overflow: auto; padding: clamp(14px, 2.5vw, 28px); display: grid; align-content: safe center; }
.scene { margin: 0; display: grid; gap: 16px; min-width: 0; }
.scene figcaption { font-size: .92rem; color: var(--ink-soft); }
.workshop .scene.enter { animation: enter .32s cubic-bezier(.2, .8, .3, 1.2); }
@keyframes enter { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.chapter .scene { padding: 16px; border: 2.5px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 4px 4px 0 var(--shadow); }
.workshop.expanded { position: fixed; inset: 0; z-index: 60; height: 100vh; height: 100dvh; margin: 0; padding: 12px; background: var(--paper); }

/* Botones y piezas */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: .55rem 1rem; border: 2.5px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); box-shadow: 3px 3px 0 var(--shadow); font: 700 .95rem var(--f-title); cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.button:hover { background: var(--paper); }
.button:active, .button[aria-pressed="true"] { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.button:disabled { opacity: .55; cursor: default; transform: none; box-shadow: 3px 3px 0 var(--shadow); }
.button--small { min-height: 36px; padding: .3rem .75rem; font-size: .85rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.piece { --c: var(--component); position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; padding: .5rem .9rem .45rem; min-height: 40px; border: 2.5px solid var(--piece-border); border-radius: 9px; background: var(--c); color: var(--on-piece); box-shadow: 3px 3px 0 var(--shadow); font: 700 .92rem/1.1 var(--f-title); white-space: nowrap; }
.piece::before, .piece::after { content: ""; position: absolute; top: -9px; width: 14px; height: 7px; border: 2.5px solid var(--piece-border); border-bottom: 0; border-radius: 7px 7px 0 0; background: var(--c); }
.piece::before { left: 10px; }
.piece::after { right: 10px; }
.piece--system { --c: var(--system); }
.piece--problem { --c: var(--problem); }
.piece--neutral { --c: var(--surface); color: var(--ink); border-color: var(--border); }
.piece--neutral::before, .piece--neutral::after { border-color: var(--border); }
button.piece { min-height: 44px; cursor: pointer; }
button.piece[aria-pressed="false"] { --c: var(--surface); color: var(--ink); border-style: dashed; border-color: var(--border); box-shadow: none; }
button.piece[aria-pressed="false"]::before, button.piece[aria-pressed="false"]::after { border-color: var(--border); }
button.piece[aria-pressed="true"] { animation: snap .28s cubic-bezier(.3, 1.6, .5, 1); }
button.system-button[aria-pressed="false"] { --c: var(--system); color: var(--on-piece); border-style: solid; box-shadow: 3px 3px 0 var(--shadow); }
.system-button[aria-pressed="true"] { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); outline: 3px solid var(--ink); outline-offset: 2px; }
@keyframes snap { 0% { transform: translateY(-8px); } 60% { transform: translateY(2px); } 100% { transform: none; } }
.piece-row { display: flex; flex-wrap: wrap; gap: 14px 10px; }
.entity-id { margin: 0; font: 800 1.1rem var(--f-title); }
.entity-id .mono { color: var(--entity-text); }
.big-stat { margin: 0; }
.big-stat strong { display: block; font: 800 2.2rem/1 var(--f-title); }

/* Escena: armar */
.entity-card { display: grid; gap: 8px; padding: 14px; border: 2.5px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 4px 4px 0 var(--entity); }
.character { display: block; width: 100%; max-height: 210px; }
.entity-status { margin: 0; min-height: 3.2em; }
.tray { display: flex; flex-wrap: wrap; gap: 16px 10px; }
.character .is-hidden { opacity: 0; }
html:not(.js) .character .is-hidden { opacity: 1; }
html:not(.js) .character [data-layer="ghost"], html:not(.js) .character [data-layer="outline"] { display: none; }
html:not(.js) .character .body-group { transform: translateY(-22px); }
.character [data-layer] { transition: opacity .2s ease; }
.character .body-group { transition: transform .3s cubic-bezier(.3, 1.5, .5, 1); }
.character.flying .body-group { transform: translateY(-22px); }
.p-ground { stroke: var(--ink-soft); stroke-width: 2.5; stroke-dasharray: 2 6; stroke-linecap: round; }
.p-ghost { fill: none; stroke: var(--ink-soft); stroke-width: 2.5; stroke-dasharray: 6 5; }
.p-outline { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.p-body { fill: var(--entity); stroke: var(--piece-border); stroke-width: 2.5; }
.p-eye { fill: var(--on-piece); }
.p-wing { fill: var(--component); stroke: var(--piece-border); stroke-width: 2.5; }
.p-piece { fill: var(--component); stroke: var(--piece-border); stroke-width: 2.5; }
.p-bar { fill: var(--surface); stroke: var(--border); stroke-width: 2.5; }
.p-coord { font: 700 11px var(--f-mono); fill: var(--ink-soft); }

/* Escena: herencia contra piezas */
.request { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.request p { margin: 0; }
.two-paths { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.path { display: grid; gap: 10px; align-content: start; padding: 12px; border: 2.5px solid var(--border); border-radius: 12px; background: var(--paper); }
.path-title { margin: 0; font: 800 1rem var(--f-title); }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 10px; padding-left: 18px; border-left: 2.5px solid var(--border); }
.tree li { position: relative; padding-top: 8px; }
.tree ul > li::before { content: ""; position: absolute; left: -18px; top: 22px; width: 14px; border-top: 2.5px solid var(--border); }
.node { display: inline-block; padding: 3px 10px; border: 2.5px solid var(--border); border-radius: 8px; background: var(--surface); font: 700 .88rem var(--f-title); }
.node--problem { background: var(--problem); color: var(--on-piece); }
.verdict { margin: 0; min-height: 1.5em; font-size: .92rem; }
html.js [data-scene="inheritance"]:not(.tried) .result { visibility: hidden; }

/* Escena: Dungeon Siege */
.cards { display: grid; gap: 12px; }
.card { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px 12px; border: 2.5px solid var(--border); border-radius: 12px; background: var(--paper); }
.card-title { margin: 0; font: 800 1rem var(--f-title); }

/* Escena: el desarme de Tony Hawk */
.breakdown { min-height: 220px; display: grid; place-items: center; padding: 18px; border: 2.5px solid var(--border); border-radius: 12px; background: var(--paper); }
.breakdown-box { max-width: 420px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 16px 10px; padding: 18px; border: 2.5px solid var(--border); border-radius: 14px; background: var(--problem); box-shadow: 4px 4px 0 var(--shadow); transition: background-color .3s, border-color .3s, box-shadow .3s; }
.breakdown-name { flex-basis: 100%; margin: 0; text-align: center; font: 800 1.1rem var(--f-title); color: var(--on-piece); }
.breakdown .piece { transition: background-color .3s, box-shadow .3s, border-color .3s; }
.breakdown[data-stage="0"] .piece { --c: var(--problem); margin: 0; padding: 0 2px; min-height: 0; border-color: transparent; box-shadow: none; }
.breakdown[data-stage="0"] .piece::before, .breakdown[data-stage="0"] .piece::after { display: none; }
.breakdown[data-stage="1"] .piece { --c: var(--surface); color: var(--ink); box-shadow: none; }
.breakdown[data-stage="2"] .breakdown-box { background: var(--surface); border-style: dashed; }
.breakdown[data-stage="3"] .breakdown-box { background: transparent; border-color: transparent; box-shadow: none; }
.breakdown[data-stage="2"] .breakdown-name, .breakdown[data-stage="3"] .breakdown-name { color: var(--ink); }
.stage-text { margin: 0; min-height: 3em; }

/* Escena: la caja de documentos */
.race { display: grid; gap: 12px; }
.lane { display: grid; gap: 8px; padding: 12px; border: 2.5px solid var(--border); border-radius: 12px; background: var(--paper); }
.lane-title { margin: 0; font: 800 1rem var(--f-title); }
.shelf { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
.shelf span { aspect-ratio: 1; border: 2px solid var(--border); border-radius: 4px; background: var(--surface); transition: background-color .2s, transform .2s; }
.shelf span.target { box-shadow: inset 0 0 0 3px var(--component); }
.shelf span.fetched { background: var(--component); transform: translateY(-3px); }
.lane-stat { margin: 0; font-size: .92rem; font-variant-numeric: tabular-nums; }
.race-result { margin: 0; min-height: 1.5em; font-weight: 700; }

/* Escena: la memoria por dentro */
.memory { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.cell { aspect-ratio: 1; display: grid; place-items: center; border: 2px solid var(--piece-border); border-radius: 5px; background: var(--component); color: var(--on-piece); font: 700 .72rem var(--f-mono); }
.cell--empty { background: transparent; border-style: dashed; border-color: var(--ink-soft); }
.memory.reorder .cell { animation: enter .3s ease; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: .9rem; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.cell--sample { width: 22px; }
.memory-text { margin: 0; min-height: 3em; }

/* Escena: los sistemas en acción */
.view { display: grid; gap: 14px; }
.view[hidden] { display: none; }
.ecs-table-wrap { overflow-x: auto; border: 2.5px solid var(--border); border-radius: 12px; background: var(--paper); }
.ecs-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ecs-table th, .ecs-table td { padding: 6px 10px; text-align: center; border-bottom: 2px solid var(--border); transition: opacity .2s, background-color .2s; }
.ecs-table thead th { background: var(--surface); font: 800 .8rem var(--f-title); }
.ecs-table tbody th { text-align: left; font-weight: 700; white-space: nowrap; }
.ecs-table tbody th .mono { margin-right: 6px; color: var(--entity-text); }
.ecs-table tbody tr:last-child th, .ecs-table tbody tr:last-child td { border-bottom: 0; }
.piece-cell { display: inline-block; width: 22px; height: 16px; vertical-align: middle; border: 2px solid var(--piece-border); border-radius: 4px; background: var(--component); }
.ecs-table tr.selected th, .ecs-table tr.selected td { background: color-mix(in srgb, var(--system) 30%, var(--paper)); }
.ecs-table tr.dimmed { opacity: .45; }
.system-text { margin: 0; min-height: 3em; }
.sim { display: block; width: 100%; aspect-ratio: 16 / 10; border: 2.5px solid var(--border); border-radius: 12px; background: var(--surface); }
.sim-label { font-weight: 700; }
.range { width: 100%; accent-color: var(--entity-text); }
.sim-status { margin: 0; min-height: 1.5em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* Escena: ECS en los motores */
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: 16px 12px; }
.engine { display: grid; gap: 4px; justify-items: start; }
.engine p { margin: 0; font-size: .88rem; color: var(--ink-soft); }
.fit { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.fit-title { margin: 0 0 6px; font: 800 1rem var(--f-title); }
.piece-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.piece-list .piece { justify-content: flex-start; text-align: left; white-space: normal; }

/* Para consultar */
/* El mismo ancho que en las otras guías: 52 rem de contenido, más el relleno de los costados */
.reference { box-sizing: content-box; max-width: 52rem; margin: 0 auto; padding: 64px clamp(16px, 3vw, 32px) 96px; }
.reference > h2 { font-weight: 800; font-variation-settings: "wdth" 88, "opsz" 72; line-height: 1; }
/* El cuestionario de ECS: sus colores y el botón con borde y sombra */
.reference { --q-number: var(--entity-text); --q-number-font: var(--f-title); --q-bg: var(--surface); --q-bg-hover: var(--paper); --q-ink: var(--ink); --q-border: 2.5px solid var(--border); --q-radius: 10px; --q-shadow: 3px 3px 0 var(--shadow); --q-family: var(--f-title); --q-weight: 700; --q-right: var(--system); --q-wrong: var(--problem); --q-on-answer: var(--on-piece); }
.reference .q-opt:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.drawer > summary { font-family: var(--f-title); font-weight: 800; }
.drawer > summary::after { font-family: var(--f-text); }
.clarifications, .sources { display: grid; gap: 10px; padding-left: 1.2rem; }

/* Celular y tablet: el taller pasa arriba, como una franja fija */
@media (max-width: 899px) {
  :root { --bar-height: 108px; }
  html { scroll-padding-top: calc(var(--bar-height) + var(--workshop-height) + 16px); }
  /* Dos filas: el título entre «Volver» y el foco, y abajo la línea de tiempo de punta a punta */
  .bar { padding: 4px var(--bar-pad); }
  .bar-title { display: block; text-align: center; }
  .story-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .workshop { order: -1; z-index: 20; top: var(--bar-height); height: calc(var(--workshop-height) + 22px); margin-inline: calc(-1 * clamp(16px, 3vw, 32px)); padding: 10px clamp(16px, 3vw, 32px) 12px; background: var(--paper); border-bottom: 2.5px solid var(--border); }
  .workshop-frame { box-shadow: 4px 4px 0 var(--shadow); }
  .button.expand { display: inline-flex; }
  .workshop-scenes { align-content: start; }
  .chapter { min-height: 70vh; padding-top: 40px; }
  .chapter--cover { min-height: auto; }
}
@media (max-width: 899px) and (max-height: 500px) {
  :root { --workshop-height: 30vh; }
}
@media (max-width: 520px) {
  .timeline .year { width: 14px; height: 14px; padding: 0; border-radius: 4px; font-size: 0; }
  .timeline a[aria-current="step"] .year { width: auto; height: auto; padding: 2px 7px; font-size: .8rem; }
  .two-paths, .fit { grid-template-columns: minmax(0, 1fr); }
  .card { grid-template-columns: minmax(0, 1fr); }
}
@media (pointer: coarse) {
  .button--small { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
