/* ============================================================
   ECHO — estilos. Estética de videocámara: el juego es una cinta
   y cada intento una toma. Colores cálidos y apagados, un rojo de
   grabación y los tonos de fósforo de los fantasmas como acento.
   ============================================================ */
:root {
  --bg: #0d0b10;
  --ink: #e9e0cc;
  --muted: #8d8496;
  --line: #2c2633;
  --panel: #16131b;
  --panel-2: #1d1923;
  --rec: #ff4b3a;
  --amber: #e8a33d;
  --jade: #6cc4a8;
  --font: 'VT323', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --top: 48px;
  --touch-pad: 0px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; background: var(--bg); }
body {
  color: var(--ink);
  font: 20px/1.15 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
body.has-touch { --touch-pad: 92px; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
kbd { font: inherit; font-size: 0.8em; color: var(--muted); margin-left: 4px; }

/* ---------- Barra superior ---------- */
.topbar {
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
.menu-button {
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  font-size: 20px;
  letter-spacing: 1px;
}
.menu-button:hover, .menu-button:focus-visible { color: var(--ink); outline: none; }
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 400 30px/1 var(--font);
  letter-spacing: 6px;
  color: var(--ink);
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--rec);
  box-shadow: 0 0 8px rgba(255, 75, 58, 0.55);
  animation: rec 1.6s steps(1) infinite;
}
@keyframes rec { 50% { opacity: 0.15; } }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.top-actions button {
  white-space: nowrap;
  padding: 4px 10px;
  color: var(--muted);
  border: 1px solid transparent;
  letter-spacing: 1px;
}
.top-actions button:hover, .top-actions button:focus-visible { color: var(--ink); border-color: var(--line); outline: none; }
.top-actions .help-button { width: 32px; padding: 4px 0; border-color: var(--line); }

/* ---------- Escenario ---------- */
.stage {
  height: calc(100% - var(--top));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--touch-pad) + env(safe-area-inset-bottom));
  --board-w: min(100%, 1180px, calc((100dvh - var(--top) - 120px - var(--touch-pad)) * 16 / 9));
}
.board, .tip, .deck { width: var(--board-w); }

.board {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  /* Carcasa: un marco grueso y oscuro, como el visor de la cámara. */
  outline: 1px solid var(--line);
  outline-offset: 5px;
  border-radius: 3px;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; image-rendering: pixelated; }

.tip { min-height: 1.2em; text-align: center; color: var(--muted); font-size: 19px; }
.tip b { color: var(--amber); font-weight: 400; }

/* ---------- Teclas de pletina ---------- */
.deck { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 6px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #3a3342;
  border-bottom-width: 3px;
  border-bottom-color: #0a080c;
  border-radius: 3px;
  letter-spacing: 1px;
  font-size: 20px;
  transition: transform 0.05s;
}
.key i { font-style: normal; color: var(--muted); }
.key:hover, .key:focus-visible { border-color: #5a5066; border-bottom-color: #0a080c; outline: none; }
.key:active { transform: translateY(2px); border-bottom-width: 1px; margin-bottom: 2px; }
.key:disabled { opacity: 0.35; cursor: default; transform: none; }
.key-rec i { color: var(--rec); }
.key-play { background: var(--ink); color: var(--bg); border-color: var(--ink); border-bottom-color: #8d8496; }
.key-play:hover, .key-play:focus-visible { border-color: #fff; border-bottom-color: #8d8496; }

/* ---------- Pantallas encima del visor ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 8, 12, 0.88);
  overflow: auto;
}
.overlay-light { background: rgba(10, 8, 12, 0.55); }
.sheet {
  width: min(760px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.sheet-small { width: min(440px, 100%); text-align: center; }
.sheet h2 { font: 400 34px/1 var(--font); letter-spacing: 2px; color: var(--ink); }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.kicker { color: var(--rec); letter-spacing: 3px; margin-bottom: 4px; }

/* Estantería: un capítulo por balda, una cinta por nivel. */
.shelf { flex: 1 1 auto; min-height: 0; overflow: auto; display: grid; align-content: start; gap: 10px; padding-right: 4px; }
.chapter h3 { font: 400 18px/1 var(--font); color: var(--muted); letter-spacing: 3px; text-transform: uppercase; margin-bottom: 6px; }
.chapter h3 b { color: var(--ink); font-weight: 400; margin-right: 6px; }
.tapes { list-style: none; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.tape {
  position: relative;
  width: 100%;
  aspect-ratio: 2.2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px 6px 4px;
  text-align: left;
  background: #221d28;
  border: 1px solid #3a3342;
  border-radius: 2px;
}
/* La etiqueta de papel y las dos bobinas */
.tape::before {
  content: '';
  position: absolute;
  right: 6px; top: 6px;
  width: 34%; height: 9px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 18% 50%, #0d0b10 0 28%, transparent 30%),
    radial-gradient(circle at 82% 50%, #0d0b10 0 28%, transparent 30%),
    #2f2936;
}
.tape b { font-size: 22px; line-height: 1; color: var(--ink); }
.tape span { position: relative; font-size: 15px; line-height: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tape.done { background: #2a2418; border-color: #6b5a33; }
.tape.done b { color: var(--amber); }
.tape.current { outline: 2px solid var(--ink); outline-offset: 1px; }
.tape.boss { background: #2a1517; border-color: #7a2a24; }
.tape.boss b { color: var(--rec); }
.chapter:last-child .tapes { grid-template-columns: repeat(2, 1fr); }
.tape:disabled { opacity: 0.3; cursor: default; }
.tape:not(:disabled):hover, .tape:focus-visible { border-color: var(--ink); outline: none; }

.stats { display: flex; justify-content: center; gap: 8px; margin: 14px 0 8px; }
.stats div { min-width: 92px; padding: 6px 8px; border: 1px solid var(--line); background: var(--panel-2); }
.stats dt { color: var(--muted); font-size: 16px; letter-spacing: 1px; }
.stats dd { font-size: 34px; line-height: 1; }
.keys { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.warn { color: var(--rec); text-align: center; }

/* ---------- Móvil ---------- */
@media (max-width: 700px) {
  :root { --top: 42px; }
  body { font-size: 18px; }
  .topbar { gap: 8px; padding: 0 8px; }
  .brand { font-size: 24px; letter-spacing: 3px; }
  .menu-button, .top-actions button { font-size: 17px; }
  .top-actions button { padding: 3px 6px; }
  .stage { padding-left: 6px; padding-right: 6px; gap: 8px; }
  .key { font-size: 17px; padding: 6px 10px 5px; }
  .key kbd { display: none; }
  .tip { font-size: 16px; }
  .tapes { grid-template-columns: repeat(3, 1fr); }
  .sheet { padding: 12px; }
}
@media (max-height: 480px) {
  :root { --top: 36px; }
  .stage { gap: 4px; padding-top: 4px; --board-w: min(100%, calc((100dvh - var(--top) - 64px - var(--touch-pad)) * 16 / 9)); }
  body.has-touch { --touch-pad: 0px; }
  .tip { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rec-dot { animation: none; }
}
