/* "Try it yourself": a switched-off CRT TV; play.js turns it on and starts
   the emulator inside the screen. Drawn in CSS only, no artwork, no brand. */
.player {
  container-type: inline-size;
  margin: 0 0 28px;
}
.tv {
  --bezel: 4.5cqw;
  --chin: 10cqw;
  position: relative;
  padding: var(--bezel) var(--bezel) var(--chin);
  border-radius: 5cqw;
  background: linear-gradient(170deg, #45464b 0%, #2a2b2f 45%, #1c1d20 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -3px 0 rgba(0, 0, 0, 0.45),
    0 22px 36px -22px rgba(0, 0, 0, 0.7);
}
.tv-screen {
  position: relative;
  z-index: 1;
  aspect-ratio: 4 / 3;
  border-radius: 9% / 12%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, #2c312f 0%, #171b19 55%, #0a0c0b 100%);
  box-shadow:
    0 0 0 1.4cqw #131417,
    0 0 0 calc(1.4cqw + 1px) rgba(255, 255, 255, 0.06);
  transition: box-shadow 0.4s;
}
/* Curved glass: dark edges and a soft reflection, above the picture. */
.tv-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  background: radial-gradient(ellipse 55% 38% at 32% 20%, rgba(255, 255, 255, 0.13), transparent 70%);
  box-shadow: inset 0 0 5cqw rgba(0, 0, 0, 0.75);
  transition: opacity 0.6s;
}
.tv.on .tv-screen::after {
  opacity: 0.45;
}
/* Power-on beam: a thin line that widens, then opens to the full screen. */
.tv-screen::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 49.5%;
  height: 1%;
  background: #f4f7ff;
  box-shadow: 0 0 4cqw 1cqw rgba(190, 210, 255, 0.8);
  opacity: 0;
  transform: scaleX(0);
  pointer-events: none;
}
.tv.powering .tv-screen::before {
  animation: tv-beam 0.75s ease-out forwards;
}
.tv.powering .tv-screen {
  animation: tv-glow 0.75s ease-out;
}
@keyframes tv-beam {
  0% {
    opacity: 1;
    transform: scaleX(0) scaleY(1);
  }
  35% {
    opacity: 1;
    transform: scaleX(1) scaleY(1);
  }
  70% {
    opacity: 0.85;
    transform: scaleX(1) scaleY(100);
  }
  100% {
    opacity: 0;
    transform: scaleX(1) scaleY(100);
  }
}
@keyframes tv-glow {
  40% {
    box-shadow:
      0 0 0 1.4cqw #131417,
      0 0 7cqw 1cqw rgba(170, 195, 255, 0.45);
  }
}
#game {
  position: absolute !important;
  inset: 0;
  z-index: 1; /* own stacking context: the beam and the glass stay above */
  opacity: 0;
  transition: opacity 0.5s;
}
.tv.on #game {
  opacity: 1;
}
/* Chin: speaker grille on the left, power light on the right. */
.tv-panel {
  position: absolute;
  left: var(--bezel);
  right: var(--bezel);
  bottom: 0;
  height: var(--chin);
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.tv-grille {
  width: 22cqw;
  height: 3.2cqw;
  background: repeating-linear-gradient(90deg, #121315 0 2px, transparent 2px 6px);
  opacity: 0.9;
}
.tv-led {
  width: 1.6cqw;
  height: 1.6cqw;
  min-width: 6px;
  min-height: 6px;
  border-radius: 50%;
  background: #4a1d1d;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6);
  transition:
    background 0.3s,
    box-shadow 0.3s;
}
.tv.on .tv-led,
.tv.powering .tv-led {
  background: #7dff9a;
  box-shadow: 0 0 6px 1px rgba(125, 255, 154, 0.7);
}
/* The whole switched-off TV is the button. */
.tv-switch {
  position: absolute;
  inset: 0;
  z-index: 4;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tv-switch:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
  border-radius: 5cqw;
}
.tv-hint {
  position: absolute;
  right: calc(var(--bezel) + 3.4cqw);
  bottom: 0;
  height: var(--chin);
  display: flex;
  align-items: center;
  font:
    500 11px/1 "IBM Plex Mono",
    ui-monospace,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #a3a6ae;
}
.tv-switch:hover .tv-hint,
.tv-switch:focus-visible .tv-hint {
  color: #e8e9ee;
}
.tv:hover:not(.on) .tv-screen {
  box-shadow:
    0 0 0 1.4cqw #131417,
    0 0 3cqw rgba(170, 195, 255, 0.12);
}

/* Touch screen while playing (play.js adds .playing): the TV and pad act
   like an app, so taps never zoom the page or select text. */
html.playing {
  touch-action: manipulation; /* no double-tap zoom anywhere on the page */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.player.touch,
.player.touch * {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Touch screen held upright: the picture in the TV, the gamepad below it
   on a dark pad, so it never covers the game. */
@media (orientation: portrait) {
  .player.touch {
    --pad: 290px;
  }
  .player.touch .tv.on {
    margin-bottom: calc(var(--pad) + 12px);
  }
  .player.touch .tv.on::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 12px);
    height: var(--pad);
    border-radius: 5cqw;
    background: linear-gradient(170deg, #2a2b2f 0%, #1c1d20 100%);
  }
  .player.touch .tv-screen {
    overflow: visible;
  }
  .player.touch #game {
    bottom: auto;
    height: calc(100% + var(--chin) + 12px + var(--pad));
    background: transparent !important;
  }
  .player.touch #game .ejs_canvas_parent {
    height: calc(91cqw * 3 / 4);
    border-radius: 9% / 12%;
    overflow: hidden;
    background: #000;
  }
  .player.touch #game .ejs_virtualGamepad_parent {
    bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tv.powering .tv-screen::before,
  .tv.powering .tv-screen {
    animation: none;
  }
  #game,
  .tv-screen,
  .tv-screen::after,
  .tv-led {
    transition: none;
  }
}
