/* Motor común. Cada juego redefine las variables en su theme.css. */
:root {
  --bg: #12161f; --panel: #1f2633; --panel2: #2a3344; --text: #f1ead8; --muted: #a9b0bd;
  --ink: #0b0e14; --accent: #e0a43a; --accent-text: #1b1406; --good: #5cc28a; --bad: #e0574a;
  --paper: #f3e6c8; --paper-ink: #1b2233;
  --font-ui: 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --font-doc: 'American Typewriter', 'Courier New', monospace;
  --font-comic: 'Chalkboard SE', 'Comic Sans MS', 'Marker Felt', sans-serif;
  --font-title: 'Avenir Next Condensed', 'Arial Narrow', 'Avenir Next', sans-serif;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; position: fixed; inset: 0;
  background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 18px; line-height: 1.4;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
img { -webkit-user-drag: none; }
h1, h2, h3 { font-family: var(--font-title); margin: 0; letter-spacing: 0.01em; }
p { margin: 0 0 0.6em; }
p.gap { height: 0.4em; margin: 0; }
.meta { color: var(--muted); font-size: 16px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; justify-content: center; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
[hidden] { display: none !important; }

/* ---------- botones ---------- */
.btn {
  min-height: 48px; min-width: 48px; padding: 0 18px; border-radius: 12px; font: 600 18px var(--font-ui);
  border: 3px solid var(--ink); background: var(--panel2); color: var(--text); box-shadow: 0 4px 0 var(--ink);
  cursor: pointer; transition: transform 0.06s, box-shadow 0.06s; touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.big { min-height: 60px; font-size: 21px; padding: 0 26px; }
.btn.small { min-height: 44px; font-size: 16px; }
.btn.ghost { background: transparent; }
.btn.armed { background: var(--bad); color: #fff; }

/* ---------- menú ---------- */
.menu { position: absolute; inset: 0; padding: 28px 36px; display: flex; flex-direction: column; gap: 24px; }
.menu > * { flex-shrink: 0; } /* en pantallas bajas (iPad) la columna no debe aplastar las tarjetas: se desplaza */
.menu-head h1 { font-size: 46px; color: var(--accent); }
.menu-head p { color: var(--muted); }
/* Cuadrícula (no carrusel): en iPad el desplazamiento lateral está bloqueado y las tarjetas de la derecha no se verían. */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(480px, 1fr)); gap: 20px; }
.card { display: flex; gap: 18px; background: var(--panel); border: 4px solid var(--ink); border-radius: 20px; padding: 16px; box-shadow: 0 8px 0 var(--ink); min-width: 0; }
.card img { width: 160px; height: 220px; flex-shrink: 0; object-fit: cover; border-radius: 12px; border: 3px solid var(--ink); }
.card-body h2 { font-size: 28px; }
.card-body { display: flex; flex-direction: column; gap: 6px; }
.card-body h2 { font-size: 34px; }
.card-body .tag { font-style: italic; }
.card-body .btn { margin-top: auto; align-self: flex-start; }
.menu-actions { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.saved:empty { display: none; }
.saved { display: flex; flex-direction: column; gap: 8px; max-width: 900px; }
.saved h2 { font-size: 24px; color: var(--accent); }
.saved-row { display: flex; align-items: center; gap: 16px; padding: 10px 12px 10px 18px; background: var(--panel); border: 3px solid var(--ink); border-radius: 14px; }
.saved-row.done { opacity: 0.6; }
.saved-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.saved-info b { font-size: 19px; }
.saved-info span { color: var(--muted); font-size: 15px; }
.meta.warn { color: var(--accent); }
.join { display: flex; gap: 12px; }
.code-input {
  width: 200px; height: 60px; font: 700 32px var(--font-title); letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
  border-radius: 12px; border: 3px solid var(--ink); background: var(--paper); color: var(--paper-ink); -webkit-user-select: text; user-select: text;
}
.code-input::placeholder { font-size: 22px; letter-spacing: 0.05em; color: #9a917c; }

/* ---------- sala de espera ---------- */
.lobby { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; }
.lobby h1 { font-size: 40px; color: var(--accent); }
.code-box { display: flex; flex-direction: column; align-items: center; background: var(--paper); color: var(--paper-ink); padding: 12px 40px; border-radius: 18px; border: 4px solid var(--ink); }
.code { font: 800 80px/1 var(--font-title); letter-spacing: 0.25em; padding-left: 0.25em; }
.roles { display: flex; gap: 22px; }
.role-card { display: flex; gap: 14px; width: 420px; background: var(--panel); border: 4px solid var(--ink); border-radius: 18px; padding: 14px; opacity: 0.85; }
.role-card.mine { outline: 4px solid var(--accent); opacity: 1; }
.role-card img { width: 110px; height: 138px; object-fit: contain; background: var(--panel2); border-radius: 12px; }
.role-card h3 { font-size: 26px; }
.role-card .who { font-weight: 700; color: var(--muted); }
.role-card .who.on, .role-card.mine .who { color: var(--good); }

/* ---------- juego ---------- */
.game { position: absolute; inset: 0; display: grid; grid-template-rows: 62px 1fr; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 14px; background: var(--panel); border-bottom: 4px solid var(--ink); }
.hud-left { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.hud-left .chapter { font-size: 14px; color: var(--muted); }
.hud-left .scene-title { font: 700 21px var(--font-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { display: flex; align-items: center; gap: 10px; }
.hud-btn { min-height: 46px; padding: 0 14px; font-size: 17px; }
.partner { font-size: 15px; padding: 6px 12px; border-radius: 99px; background: var(--panel2); max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.partner::before { content: '●'; margin-right: 6px; color: var(--good); }
.partner.off::before { color: var(--bad); }
.timer { font: 700 19px var(--font-title); min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.main { display: grid; grid-template-columns: 1fr 136px; min-height: 0; }
.stage-wrap { position: relative; min-height: 0; overflow: hidden; background: #000; }
.stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.scene-box { position: relative; }
.scene-svg { display: block; width: 100%; height: 100%; }
.hs { fill: transparent; stroke: transparent; stroke-width: 6; cursor: pointer; outline: none; }
.reveal .hs { stroke: var(--accent); stroke-dasharray: 18 12; fill: rgba(224, 164, 58, 0.12); }
.use-mode .hs { stroke: rgba(255, 255, 255, 0.55); stroke-dasharray: 10 10; }
.hs.flash { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { fill: rgba(255, 215, 130, 0.45); } 100% { fill: transparent; } }
.back { position: absolute; top: 12px; left: 12px; }
.reveal-btn { position: absolute; bottom: 12px; left: 12px; font-size: 16px; opacity: 0.9; }
.usebar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 76%; display: flex; gap: 12px; align-items: center; background: var(--accent); color: var(--accent-text); font-weight: 700; padding: 6px 8px 6px 16px; border-radius: 14px; border: 3px solid var(--ink); }
.inv { background: var(--panel); border-left: 4px solid var(--ink); padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.inv h3 { font-size: 16px; color: var(--muted); text-align: center; }
.item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; min-height: 104px; border-radius: 12px; border: 3px solid var(--ink); background: var(--panel2); color: var(--text); font: 600 14px/1.15 var(--font-ui); hyphens: auto; overflow-wrap: anywhere; text-align: center; }
.item img { width: 64px; height: 64px; }
.item.selected { outline: 4px solid var(--accent); }
.item em { position: absolute; top: 4px; right: 4px; font-size: 10px; font-style: normal; background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 1px 4px; }
.inv .empty, .partner-items { font-size: 14px; color: var(--muted); text-align: center; }

/* ---------- modales ---------- */
.modal-host { position: absolute; inset: 62px 0 0 0; pointer-events: none; display: flex; align-items: center; justify-content: center; }
.modal-host:not(:empty) { background: rgba(5, 8, 14, 0.55); pointer-events: auto; }
.modal { position: relative; background: var(--panel); border: 4px solid var(--ink); border-radius: 20px; box-shadow: 0 10px 0 var(--ink); width: min(880px, 92%); max-height: 94%; display: flex; flex-direction: column; overflow: hidden; animation: pop 0.22s ease-out; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.modal > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 20px; border-bottom: 3px solid var(--ink); background: var(--panel2); }
.modal > header h2 { font-size: 24px; }
.btn.close { min-width: 52px; padding: 0; font-size: 22px; }
.prompt { padding: 12px 22px 0; font-size: 18px; color: var(--muted); }
.pz-body { padding: 16px 22px 22px; display: flex; justify-content: center; }
.pz-img { display: block; max-width: calc(100% - 44px); max-height: 30vh; margin: 12px auto 0; border-radius: 10px; border: 3px solid var(--ink); }

/* puzles */
.slots { display: flex; gap: 10px; justify-content: center; margin-bottom: 18px; }
.slot { width: 62px; height: 74px; border-radius: 10px; border: 3px solid var(--ink); background: #0f1712; color: #7dffb0; font: 700 40px/68px 'Courier New', monospace; text-align: center; }
.slots.letters .slot { width: 54px; height: 66px; font-size: 34px; line-height: 60px; background: var(--paper); color: var(--paper-ink); }
.slot.on { border-color: var(--accent); }
.good .slot, .good.wheels .wheel { border-color: var(--good); box-shadow: 0 0 18px var(--good); }
.shake { animation: shake 0.45s; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-14px); } 40% { transform: translateX(12px); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } }
.keys { display: grid; grid-template-columns: repeat(3, 92px); gap: 12px; justify-content: center; }
.key { height: 72px; min-width: 56px; border-radius: 14px; border: 3px solid var(--ink); background: var(--paper); color: var(--paper-ink); font: 700 30px var(--font-title); box-shadow: 0 4px 0 var(--ink); }
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.key.ok { background: var(--good); color: var(--ink); }
.key.ok:disabled { opacity: 0.45; }
.key.del { background: var(--panel2); color: var(--text); }
.kb { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.kbrow { display: flex; gap: 8px; }
.kb .key { width: 62px; height: 64px; font-size: 26px; }
.kb .key.wide { width: 140px; font-size: 22px; }
.pz-wheels { display: flex; flex-direction: column; gap: 22px; align-items: center; }
.wheels { display: flex; gap: 18px; padding: 18px; background: var(--accent); border: 4px solid var(--ink); border-radius: 22px; }
.wheel { display: flex; flex-direction: column; align-items: center; gap: 8px; border: 3px solid transparent; border-radius: 14px; padding: 4px; }
.warrow { width: 104px; height: 52px; border-radius: 12px; border: 3px solid var(--ink); background: var(--panel2); color: var(--text); font-size: 22px; }
.wbody { width: 104px; height: 120px; border-radius: 12px; border: 3px solid var(--ink); background: var(--ink); padding: 0; }
.wface { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text); font: 700 48px var(--font-title); }
.wface img { width: 96px; height: 96px; }

/* interruptores */
.pz-switches, .pz-sequence, .pz-dials, .pz-symbols, .pz-order { display: flex; flex-direction: column; gap: 18px; align-items: center; width: 100%; }
.switches { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.switch { width: 96px; min-height: 150px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border-radius: 14px; border: 3px solid var(--ink); background: var(--panel2); color: var(--text); font: 600 15px var(--font-ui); }
.switch img { width: 48px; height: 48px; }
.switch small { color: var(--muted); }
.lever { width: 30px; height: 56px; border-radius: 15px; background: #11151d; border: 3px solid var(--ink); position: relative; }
.lever::after { content: ''; position: absolute; left: 2px; right: 2px; height: 24px; bottom: 2px; border-radius: 10px; background: var(--muted); transition: bottom 0.15s, background 0.15s; }
.switch.on .lever::after { bottom: 26px; background: var(--good); }
.switch.on { border-color: var(--good); }
.gauge { width: min(520px, 90%); height: 34px; border-radius: 10px; border: 3px solid var(--ink); background: #11151d; position: relative; overflow: hidden; }
.gauge i { position: absolute; inset: 0 auto 0 0; background: var(--good); opacity: 0.6; transition: width 0.2s; }
.gauge i.over { background: var(--bad); opacity: 0.85; }
.gauge span { position: relative; z-index: 1; display: block; text-align: center; font: 700 17px/28px var(--font-ui); }
/* secuencia */
.slots.seq .slot { display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--text); }
.slots.seq .slot img, .seq-key img { width: 44px; height: 44px; }
.seq-pad { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.seq-key { width: 92px; height: 82px; display: flex; align-items: center; justify-content: center; }
/* discos */
.dials { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px; border-radius: 16px; background: var(--panel2); border: 3px solid var(--ink); min-width: 170px; }
.knob-btn { width: 120px; height: 120px; border-radius: 50%; border: 0; padding: 0; background: none; }
.knob { width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #cfd6e0, #7a8597 70%); border: 4px solid var(--ink); position: relative; transition: transform 0.2s; }
.knob i { position: absolute; left: 50%; top: 8px; width: 10px; height: 40px; margin-left: -5px; border-radius: 5px; background: var(--bad); }
.dial-val { display: flex; align-items: center; gap: 6px; font: 700 20px var(--font-title); min-height: 40px; }
.dial-val img { width: 36px; height: 36px; }
.warrow.small { width: 64px; height: 50px; }
/* símbolos */
.symgrid { display: grid; gap: 10px; width: min(600px, 100%); }
.sym { min-width: 0; }
.sym { aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--ink); background: var(--paper); color: var(--paper-ink); font: 700 22px var(--font-title); padding: 6px; }
.sym img { width: 100%; height: 100%; object-fit: contain; }
.sym.on { outline: 5px solid var(--accent); background: #fff3cf; }
.pick-count { color: var(--muted); margin: 0; }
/* ordenar */
.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; width: min(680px, 100%); }
.order-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; background: var(--paper); color: var(--paper-ink); border: 3px solid var(--ink); }
.order-item .pos { font: 800 24px var(--font-title); width: 32px; text-align: center; }
.order-item img { width: 56px; height: 56px; }
.order-item .txt { flex: 1; display: flex; flex-direction: column; }
.order-item small { font-size: 15px; opacity: 0.8; }
.good.switches .switch, .good.dials .dial, .good.symgrid .sym, .good.order-list .order-item { border-color: var(--good); box-shadow: 0 0 14px var(--good); }
/* rutas de energía */
.pz-route { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.route { display: grid; gap: 4px; padding: 10px; background: #0b0f17; border: 3px solid var(--ink); border-radius: 14px; }
.rt-cell { position: relative; padding: 0; border-radius: 8px; border: 2px solid #26324a; background: #141c2b; display: flex; align-items: center; justify-content: center; }
.rt-cell.fixed { background: #1b2436; }
.rt-cell small { position: absolute; bottom: 1px; left: 0; right: 0; font-size: 10px; color: var(--muted); text-align: center; }
.rt-pipe { stroke: #4a5a78; stroke-width: 16; stroke-linecap: round; }
.rt-pipe.on { stroke: var(--accent); }
.rt-joint { fill: #4a5a78; }
.rt-joint.on, .rt-node.on { fill: var(--accent); }
.rt-node { fill: #4a5a78; stroke: var(--ink); stroke-width: 4; }
.rt-node.S { fill: var(--good); }
.rt-block { fill: #070a10; stroke: #26324a; stroke-width: 4; }
.good.route { box-shadow: 0 0 18px var(--good); }
/* relacionar */
.pz-match { display: flex; flex-direction: column; gap: 14px; align-items: center; width: 100%; }
.match { display: flex; flex-direction: column; gap: 8px; width: min(760px, 100%); }
.match-row { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 12px; background: var(--paper); color: var(--paper-ink); border: 3px solid var(--ink); }
.match-left { flex: 1; display: flex; gap: 10px; align-items: center; min-width: 0; }
.match-left img { width: 52px; height: 52px; }
.match-left small { display: block; font-size: 14px; opacity: 0.8; }
.match-opts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.match-opt { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 2px solid var(--ink); background: var(--panel2); color: var(--text); font: 600 15px var(--font-ui); }
.match-opt.on { background: var(--accent); color: var(--accent-text); }
.good.match .match-row { border-color: var(--good); box-shadow: 0 0 12px var(--good); }
/* puzles a dos partes */
.dual-banner { margin: 10px 22px 0; padding: 10px 14px; border-radius: 12px; border: 3px solid var(--ink); background: var(--panel2); font-weight: 700; text-align: center; }
.dual-banner.ready { background: var(--good); color: var(--ink); }
.dual-banner.urgent { background: var(--bad); color: #fff; animation: pulse 0.6s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.03); } }
.timer.urgent { color: var(--bad); }
.modal.puzzle { overflow: hidden; }
.modal.puzzle .pz-body { flex: 1; min-height: 0; overflow-y: auto; align-items: flex-start; }
.modal.puzzle .pz-img { max-height: 24vh; }

/* documentos */
.doc-page { padding: 18px 26px; flex: 1; min-height: 0; }
.doc-page h3 { font-size: 22px; margin-bottom: 10px; }
.doc-page img { display: block; max-width: 100%; max-height: 52vh; margin: 0 auto 12px; border-radius: 6px; }
.modal.doc > footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 3px solid var(--ink); background: var(--panel2); }
.count { color: var(--muted); font-weight: 700; }
.style-paper .doc-page { background: var(--paper); color: var(--paper-ink); font: 19px/1.5 var(--font-doc); }
.style-paper .doc-page h3 { font-family: var(--font-doc); border-bottom: 2px solid var(--paper-ink); padding-bottom: 6px; }
.style-photo .doc-page { background: #101318; text-align: center; font-size: 19px; }
.style-photo .doc-page img { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6); }

/* paneles */
#panel { position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; }
#panel.open { display: flex; }
#panel .scrim { position: absolute; inset: 0; background: rgba(5, 8, 14, 0.6); }
#panel .modal { max-height: 86%; }
.panel-body { padding: 16px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.hint { background: var(--panel2); border-radius: 14px; padding: 12px 16px; border: 3px solid var(--ink); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hint.solved { opacity: 0.6; }
.hint h3 { font-size: 21px; }
.entry { background: var(--paper); color: var(--paper-ink); font: 18px/1.5 var(--font-doc); padding: 12px 16px; border-radius: 10px; }
.slider { display: flex; align-items: center; gap: 16px; font-size: 19px; }
.slider span { width: 200px; }
.slider input { flex: 1; height: 44px; accent-color: var(--accent); }
.slider input[type=checkbox] { flex: 0 0 44px; width: 44px; }
.item-card .item-main { display: flex; gap: 20px; padding: 18px 22px; }
.item-card .item-main img { width: 150px; height: 150px; background: var(--panel2); border-radius: 14px; border: 3px solid var(--ink); }
.item-card .row { padding: 0 22px 22px; justify-content: flex-start; }

/* ---------- cómic ---------- */
.comic { position: absolute; inset: 0; display: grid; grid-template-rows: 1fr 84px; background: #0a0c10; }
.comic-host { padding: 16px 18px 6px; min-height: 0; }
.comic-page { height: 100%; display: grid; gap: 14px; }
.comic-page.p1 { grid-template: 1fr / 1fr; }
.comic-page.p2 { grid-template: 1fr / 1fr 1fr; }
.comic-page.p3 { grid-template: 1fr 1fr / 1fr 1fr; }
.comic-page.p3 .panel:first-child { grid-column: 1 / 3; }
.comic-page.p4 { grid-template: 1fr 1fr / 1fr 1fr; }
.panel { position: relative; overflow: hidden; border: 5px solid var(--ink); background: var(--panel2); box-shadow: 0 0 0 3px #fff; opacity: 0; animation: panelIn 0.5s ease-out forwards; }
@keyframes panelIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.panel-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.char { position: absolute; bottom: 0; transform: translateX(-50%); }
.char.flip { transform: translateX(-50%) scaleX(-1); }
.bubble { position: absolute; padding: 10px 14px; background: #fff; color: #111; border: 3px solid #111; border-radius: 22px; font: 19px/1.3 var(--font-comic); opacity: 0; animation: panelIn 0.4s ease-out forwards; }
.bubble .who { display: block; font: 800 13px var(--font-ui); text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-text); opacity: 0.6; }
.bubble.speech.tail-left::after, .bubble.speech.tail-right::after { content: ''; position: absolute; bottom: -22px; width: 0; height: 0; border: 12px solid transparent; border-top: 18px solid #111; }
.bubble.speech.tail-left::after { left: 26px; }
.bubble.speech.tail-right::after { right: 26px; }
.bubble.caption { border-radius: 4px; background: #f4d35e; font: 700 17px/1.3 var(--font-ui); }
.bubble.note { border-radius: 2px; background: var(--paper); font: 24px/1.3 'Noteworthy', 'Bradley Hand', 'Segoe Print', cursive; transform: rotate(-2deg); }
.bubble.thought { border-style: dashed; }
.bubble.speaking { box-shadow: 0 0 0 4px var(--accent); }
.comic-bar .voice-btn { margin-right: auto; }
.comic-bar { display: flex; align-items: center; justify-content: flex-end; gap: 20px; padding: 0 24px; }

/* ---------- fin de capítulo ---------- */
.end { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; padding: 24px; }
.end .kicker { color: var(--accent); font: 700 22px var(--font-title); text-transform: uppercase; letter-spacing: 0.15em; margin: 0; }
.end h1 { font-size: 48px; }
.stats { display: flex; gap: 20px; }
.stats div { display: flex; flex-direction: column; min-width: 190px; padding: 16px 22px; background: var(--panel); border: 4px solid var(--ink); border-radius: 18px; }
.stats span { color: var(--muted); }
.stats strong { font: 800 38px var(--font-title); }
.tease { font-style: italic; color: var(--muted); }

/* ---------- avisos ---------- */
/* Abajo y al centro: no tapa títulos de escena, modales ni globos de cómic. */
#toasts { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; width: min(560px, 80vw); }
.toast { background: var(--panel2); color: var(--text); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 18px; font-size: 18px; text-align: center; box-shadow: 0 6px 0 var(--ink); animation: pop 0.2s ease-out; transition: opacity 0.4s, transform 0.4s; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(-8px); }
#netstatus { position: fixed; bottom: 0; left: 0; right: 0; z-index: 70; background: var(--bad); color: #fff; text-align: center; font-weight: 700; padding: 6px calc(6px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform 0.3s; }
#netstatus.show { transform: none; }
#rotate { display: none; }
@media (orientation: portrait) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 100; background: var(--bg); align-items: center; justify-content: center; font: 700 28px var(--font-title); padding: 40px; text-align: center; }
}
@media (max-height: 700px) {
  .card img { height: 220px; width: 160px; }
  .key { height: 60px; }
  .keys { grid-template-columns: repeat(3, 80px); }
}
