/* Pantallas del CPC: barra inferior, teclado virtual y casete. El monitor está en index.html. */

:root {
  --plastic: #2b2b28;
  --plastic-hi: #3b3b37;
  --plastic-lo: #1a1a18;
  --key: #c8c5bb;
  --key-hi: #e2dfd5;
  --key-lo: #8f8c83;
  --key-ink: #24231f;
  --label: #a9a69c;
  --phosphor: #9dff8a;
  --red: #d9372b;
  --green: #3aa84a;
  --blue: #2d6fd1;
  --ui-font: "Press Start 2P", ui-monospace, monospace;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] { display: none !important; }

.view-monitor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Barra ---------- */

.bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding-top: 12px;
  font: 9px/1 var(--ui-font);
}
.bar-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 8px 4px;
  color: var(--label);
  font: inherit;
  letter-spacing: .08em;
  text-decoration: none;
  cursor: pointer;
  text-shadow: 0 1px 0 #000;
}
.bar-btn:hover, .bar-btn:focus-visible { color: var(--phosphor); text-shadow: 0 0 6px rgba(157,255,138,.5); }
.bar-btn:focus-visible { outline: 1px dashed var(--phosphor); outline-offset: 2px; }
.bar-btn[aria-pressed="true"]:not(.mute) { color: var(--phosphor); }
body[data-view="monitor"] .to-monitor,
body[data-view="deck"] .to-deck,
body[data-view="deck"] .kb-toggle,
body[data-view="deck"] .mute { display: none; }
.to-deck { color: #e8e3c9; }

/* ---------- Teclado virtual ---------- */

/* Con teclado, el monitor se apoya encima de él en vez de quedar centrado. */
body.kb-on .stage { place-items: end center; }

.keyboard {
  flex: none;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 8px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--plastic-hi), var(--plastic-lo));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 10px 24px rgba(0,0,0,.5);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.kb-bar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.kb-mode {
  appearance: none;
  border: 1px solid #55544e;
  border-radius: 3px;
  background: #222220;
  color: var(--label);
  font: 7px/1 var(--ui-font);
  padding: 6px 8px;
  cursor: pointer;
}
.kb-keys { display: flex; flex-direction: column; gap: 3px; }
.kb-row { display: flex; gap: 3px; }
.kb-row:first-child { margin-bottom: 4px; }
.kb-key {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  height: clamp(28px, 6.4vw, 40px);
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: linear-gradient(180deg, #3d3d39, #2a2a27);
  box-shadow: inset 0 -3px 0 #161614, inset 0 1px 0 rgba(255,255,255,.12);
  color: #e9e6dc;
  font: clamp(6px, 1.5vw, 9px)/1.1 var(--ui-font);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  cursor: pointer;
}
.kb-key small { font-size: .8em; color: var(--label); }
.kb-key[data-code="8"] span, .kb-key[data-code="9"] span,
.pad-left span, .pad-right span { display: inline-block; rotate: -90deg; }
.kb-row:first-child .kb-key { background: linear-gradient(180deg, #5a5a53, #44443f); height: clamp(22px, 5vw, 30px); }
/* Las teclas de color del 464: ENTER y la barra en azul, RETURN y cursores en gris claro. */
.kb-key[data-code="252"] { background: linear-gradient(180deg, #3a6fc4, #2a559c); }
.kb-key[data-code="13"], .kb-key[data-code="8"], .kb-key[data-code="9"], .kb-key[data-code="10"], .kb-key[data-code="11"] {
  background: linear-gradient(180deg, var(--key-hi), var(--key));
  box-shadow: inset 0 -3px 0 var(--key-lo);
  color: var(--key-ink);
}
.kb-key.down { transform: translateY(1px); box-shadow: inset 0 -1px 0 #161614; filter: brightness(1.25); }
.kb-key.latched { color: var(--phosphor); box-shadow: inset 0 -3px 0 #161614, 0 0 0 1px var(--phosphor); }

.kb-pad { display: none; }
.keyboard.joy-mode .kb-keys { display: none; }
.keyboard.joy-mode .kb-pad {
  display: grid;
  grid-template: repeat(3, clamp(44px, 11vw, 64px)) / repeat(3, clamp(44px, 11vw, 64px)) 1fr repeat(2, clamp(56px, 15vw, 80px));
  gap: 6px;
  align-items: center;
}
.pad-btn {
  appearance: none;
  border: 0;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(180deg, #3d3d39, #232321);
  box-shadow: inset 0 -4px 0 #121211, inset 0 1px 0 rgba(255,255,255,.12);
  color: #e9e6dc;
  font: 14px/1 var(--ui-font);
  cursor: pointer;
}
.pad-up { grid-area: 1 / 2; }
.pad-left { grid-area: 2 / 1; }
.pad-right { grid-area: 2 / 3; }
.pad-down { grid-area: 3 / 2; }
.pad-fire1, .pad-fire2 {
  grid-row: 2;
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #f0584c, #a8231a);
  box-shadow: inset 0 -4px 0 #6d140e;
}
.pad-fire1 { grid-column: 5; }
.pad-fire2 { grid-column: 6; }
.pad-btn.down { transform: translateY(2px); filter: brightness(1.3); }

/* ---------- Pantalla del casete ---------- */

.view-deck {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 8px 0 24px;
  color: var(--label);
  font: 9px/1.7 var(--ui-font);
}
.view-deck.dragging .own-slot { border-color: var(--phosphor); color: var(--phosphor); }

.deck {
  width: min(100%, 560px);
  padding: 14px 16px 16px;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,0) 30%),
    var(--plastic);
  box-shadow:
    inset 0 0 0 1px #45453f,
    inset 0 2px 1px rgba(255,255,255,.08),
    0 24px 50px rgba(0,0,0,.6);
  animation: deck-in .35s ease-out;
}
@keyframes deck-in { from { transform: translateY(12px); opacity: 0; } }

.deck-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: #d8d4c6;
  font-size: 11px;
  letter-spacing: .25em;
}
.deck-brand small { margin-left: auto; color: var(--label); font-size: 7px; letter-spacing: .12em; }
.stripes {
  width: 34px;
  height: 12px;
  background: linear-gradient(180deg, var(--red) 0 33%, var(--green) 33% 66%, var(--blue) 66%);
  border-radius: 1px;
}

.deck-body { display: flex; gap: 14px; align-items: stretch; }

/* Puerta del casete: plástico ahumado con la cinta detrás. */
.deck-door {
  flex: 1;
  aspect-ratio: 1.75;
  padding: 7% 8%;
  border-radius: 6px;
  background:
    linear-gradient(160deg, rgba(255,255,255,.12), rgba(255,255,255,0) 35%),
    linear-gradient(180deg, #121212, #070707);
  box-shadow: inset 0 0 0 2px #0a0a0a, inset 0 0 0 4px #3e3e39, inset 0 6px 18px rgba(0,0,0,.8);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.deck-door::after { /* reflejo de la tapa */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255,255,255,0) 40%, rgba(255,255,255,.07) 48%, rgba(255,255,255,0) 56%);
  pointer-events: none;
}
.deck-window { width: 100%; display: grid; place-items: center; }
.deck-window:empty::before {
  content: "SIN CINTA";
  color: #4a4a45;
  font-size: 8px;
  letter-spacing: .2em;
}
.deck.ejecting .deck-door { animation: eject .35s ease-out; }
@keyframes eject { 30% { transform: translateY(-4px); } }

.deck-side {
  width: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.counter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 4px;
  background: #151514;
  box-shadow: inset 0 0 0 1px #3a3a35;
}
.counter-digits {
  flex: 1;
  padding: 6px 4px;
  border-radius: 2px;
  background: linear-gradient(180deg, #0b0b0b, #262626 50%, #0b0b0b);
  color: #f1eee4;
  font-size: 12px;
  letter-spacing: .3em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.counter-reset {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #dcd8cc, #8a877e);
  box-shadow: 0 1px 0 #000;
  cursor: pointer;
}

.turbo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 7px;
  line-height: 1.4;
  cursor: pointer;
}
.turbo input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none;
  width: 30px;
  height: 14px;
  border-radius: 2px;
  background: #121211;
  box-shadow: inset 0 0 0 1px #45453f;
  position: relative;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 10px;
  border-radius: 1px;
  background: linear-gradient(180deg, var(--key-hi), var(--key-lo));
  transition: transform .15s;
}
.turbo input:checked + .switch::after { transform: translateX(14px); }
.turbo input:checked + .switch { box-shadow: inset 0 0 0 1px #45453f, inset 18px 0 0 -4px rgba(157,255,138,.25); }
.turbo input:focus-visible + .switch { outline: 1px dashed var(--phosphor); outline-offset: 2px; }

/* Teclas de piano del datacorder. */
.deck-keys { display: flex; gap: 4px; margin-top: 14px; }
.deck-key {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  height: 46px;
  padding: 0 2px 8px;
  border: 0;
  border-radius: 2px 2px 5px 5px;
  background: linear-gradient(180deg, var(--key-hi), var(--key) 70%, var(--key-lo));
  box-shadow: 0 6px 0 #67645c, 0 7px 0 #000, inset 0 1px 0 #fff;
  color: var(--key-ink);
  font: 7px/1 var(--ui-font);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.deck-key[data-key="stop"] { flex-grow: 1.6; }
.deck-key:active, .deck-key.down {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #67645c, 0 2px 0 #000, inset 0 1px 0 #fff;
}
.deck-key.down { background: linear-gradient(180deg, var(--key), var(--key-lo)); }
.deck-key:focus-visible { outline: 1px dashed var(--phosphor); outline-offset: 3px; }
.rec-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.deck-key.refused { animation: refuse .3s; }
@keyframes refuse { 25%, 75% { transform: translateX(-2px); } 50% { transform: translateX(2px); } }

.deck-status {
  min-height: 3.4em;
  margin: 18px 0 0;
  padding: 8px 10px;
  border-radius: 3px;
  background: #0d130d;
  box-shadow: inset 0 0 0 1px #24331f;
  color: var(--phosphor);
  font-size: 8px;
  line-height: 1.7;
  text-shadow: 0 0 6px rgba(157,255,138,.35);
}

/* ---------- Cintas ---------- */

/* Casete de 100 × 64 mm: etiqueta arriba con la ventana de las bobinas y el trapecio de abajo. */
.cassette {
  width: 100%;
  aspect-ratio: 100 / 64;
  border-radius: 4% / 6%;
  background:
    radial-gradient(circle at 4% 6%, #555 0 1.2%, transparent 1.4%),
    radial-gradient(circle at 96% 6%, #555 0 1.2%, transparent 1.4%),
    radial-gradient(circle at 4% 94%, #555 0 1.2%, transparent 1.4%),
    radial-gradient(circle at 96% 94%, #555 0 1.2%, transparent 1.4%),
    linear-gradient(180deg, #2a2a2a, #151515);
  box-shadow: inset 0 0 0 1px #3a3a3a, 0 4px 10px rgba(0,0,0,.5);
  position: relative;
  container-type: inline-size;
}
.cassette-label {
  position: absolute;
  left: 7%;
  right: 7%;
  top: 7%;
  aspect-ratio: 1088 / 497;   /* proporción de la etiqueta de Cannon Duels */
  border-radius: 2px;
  overflow: hidden;
  background:
    repeating-linear-gradient(180deg, transparent 0 13%, rgba(40,60,160,.25) 13% 14%),
    #efeadb;
}
.cassette-label img { width: 100%; height: 100%; display: block; }
.cassette-handwriting {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 6%;
  color: #1d3fa8;
  font-size: 6.5cqw;
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transform: rotate(-1.5deg);
}
/* Ventana de la cinta: encaja con el óvalo blanco de la etiqueta (16,3–84 % de ancho y 37,6–75 %
   de alto de la etiqueta, que mide el 86 % del ancho y el 61,4 % del alto del casete). */
.cassette-window {
  position: absolute;
  left: 21%;
  width: 58.1%;
  top: 30.1%;
  height: 23%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(30,24,20,.92), rgba(12,10,9,.95));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15), inset 0 2px 6px rgba(0,0,0,.8);
  overflow: hidden;
}
.reel {
  --tape: calc(1 - var(--played, 0));
  position: absolute;
  top: 50%;
  width: 22%;
  aspect-ratio: 1;
  translate: -50% -50%;
}
.reel-l { left: 22%; }
.reel-r { left: 78%; --tape: var(--played, 0); }
.reel::before { /* cinta enrollada */
  content: "";
  position: absolute;
  inset: calc(50% - (42% + 110% * var(--tape)));
  border-radius: 50%;
  background: radial-gradient(circle, #4a2d1c 55%, #3a2214);
}
.reel::after { /* buje con dientes */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 34%, #f2efe6 35% 62%, transparent 63%),
    repeating-conic-gradient(#f2efe6 0 14deg, transparent 14deg 60deg);
  -webkit-mask: radial-gradient(circle, #000 0 72%, transparent 73%);
  mask: radial-gradient(circle, #000 0 72%, transparent 73%);
}
.deck.spinning .reel::after { animation: spin 1.6s linear infinite; }
.deck.spinning.fast .reel::after { animation-duration: .3s; }
.deck.spinning.reverse .reel::after { animation-direction: reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
.deck-window .cassette.inserting { animation: insert .4s cubic-bezier(.2,.8,.3,1); }
@keyframes insert { from { transform: translateY(35%) scale(.94); opacity: 0; } }

/* Estante */
.shelf {
  width: min(100%, 560px);
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.shelf-tapes { display: contents; }
.shelf-item, .own-tape {
  appearance: none;
  width: 150px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}
.shelf-item .cassette { transition: transform .15s; }
.shelf-item:hover .cassette, .shelf-item:focus-visible .cassette { transform: translateY(-4px) rotate(-1deg); }
.shelf-item:focus-visible, .own-tape:focus-within { outline: 1px dashed var(--phosphor); outline-offset: 4px; }
.shelf-item:disabled { cursor: default; opacity: .25; }
.shelf-item:disabled .cassette { transform: none; }
.shelf-info { display: flex; flex-direction: column; gap: 2px; font-size: 7px; line-height: 1.6; }
.shelf-info b { color: #e8e3c9; font-weight: normal; font-size: 8px; }
.own-tape input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.own-slot {
  aspect-ratio: 100 / 64;
  border: 2px dashed #4b4b45;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #6c6a62;
  font-size: 20px;
}
.own-tape:hover .own-slot { border-color: var(--label); color: var(--label); }

.how {
  width: min(100%, 560px);
  margin: 0;
  padding-left: 3.2em;
  font-size: 8px;
  line-height: 2;
}
.how kbd {
  padding: 2px 4px;
  border-radius: 2px;
  background: #33332f;
  color: #eceadf;
  font: inherit;
}
.how b { color: #e8e3c9; font-weight: normal; }
.fineprint { width: min(100%, 560px); margin: 0; font-size: 7px; color: #6f6d65; }
.fineprint a { color: var(--label); }

@media (max-width: 480px) {
  body { padding: 10px; }
  .deck { padding: 12px; }
  .deck-body { flex-direction: column; }
  .deck-side { width: auto; flex-direction: row; align-items: center; }
  .deck-key { font-size: 6px; height: 40px; }
  .shelf-item, .own-tape { width: calc(50% - 9px); }
}

@media (prefers-reduced-motion: reduce) {
  .deck, .deck-window .cassette.inserting, .deck.ejecting .deck-door { animation: none; }
  .deck.spinning .reel::after { animation-duration: 6s; }
}
