:root {
  color-scheme: dark;
  --amber: #ff4a22;
  --amber-dim: #7a2414;
  --plastic: #2a2927;
  --plastic-deep: #141312;
  --wood: #1a120c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  min-height: 100%;
  background: #c9b7a4;
  color: #2a241e;
  font-family: "Segoe UI", system-ui, sans-serif;
}

button {
  font: inherit;
}

.room {
  height: 100%;
  min-height: 100%;
  position: relative;
  overflow: hidden;
  background: #1a1410;
  touch-action: none;
}

.spill {
  display: none;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

body.is-dragging,
body.is-dragging .tube {
  cursor: grabbing;
}

.set {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.cabinet {
  position: absolute;
  line-height: 0;
  cursor: grab;
  touch-action: none;
}

.cabinet-photo {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

/* Covers the standby lamp in the photo while the set is on. */
.standby {
  position: absolute;
  left: 63.564%;
  top: 51.565%;
  width: 0.829%;
  height: 0.921%;
  border-radius: 50%;
  background: radial-gradient(circle, #110e0c 0 46%, rgba(17, 14, 12, 0) 78%);
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.25s linear;
}

.set.is-off .standby {
  opacity: 0;
}

.tube {
  position: absolute;
  left: 37.85%;
  top: 18.23%;
  width: 29.49%;
  height: 27.81%;
  border-radius: 1.2% / 2%;
  overflow: hidden;
  background: #000;
  cursor: grab;
  z-index: 1;
  touch-action: none;
  box-shadow:
    inset 0 0 28px rgba(0, 0, 0, 0.28),
    0 0 22px rgba(186, 220, 255, 0.22);
  transform: translateZ(0);
}

.tube.is-link {
  cursor: pointer;
}

.lens-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.glass,
.fringe,
#snow {
  position: absolute;
  inset: 0;
}

.plate {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  filter: url(#glass-bend);
  --page-width: 0.8;
  --page-scale: 0.95;
}

.bloom-plate {
  z-index: 2;
  transform: scale(1.02);
  filter: url(#glass-bend) blur(3.5px) saturate(1.1) brightness(1.15);
  opacity: 0.16;
  mix-blend-mode: screen;
  pointer-events: none;
}

.sharp-plate {
  z-index: 1;
  animation: phosphor 0.38s steps(1, end) infinite;
  filter: url(#glass-bend) blur(0.9px);
}

.page,
.entry-glass {
  position: absolute;
  left: calc((1 - var(--page-width) * var(--page-scale)) * 50%);
  top: calc((1 - var(--page-scale)) * 50%);
  width: calc(var(--page-width) * var(--page-scale) * 100%);
  height: calc(var(--page-scale) * 100%);
  pointer-events: none;
  image-rendering: auto;
  image-rendering: smooth;
}

.page {
  object-fit: fill;
  user-select: none;
}

.fringe {
  mix-blend-mode: screen;
  opacity: 0.22;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 92%, rgba(255, 32, 64, 0.85) 97%, rgba(32, 200, 255, 0.75) 100%);
}

#snow {
  z-index: 3;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.21;
  image-rendering: pixelated;
  pointer-events: none;
  animation: noise-flicker 0.12s steps(2, end) infinite;
}

.scanlines,
.aperture,
.vignette,
.glare,
.shutoff,
.osd {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.28) 0 1px,
    transparent 1px 3px
  );
  z-index: 3;
  mix-blend-mode: multiply;
  animation: scan 12s linear infinite;
  opacity: 0.55;
}

.aperture {
  background: repeating-linear-gradient(
    to right,
    rgba(255, 40, 40, 0.07) 0 1px,
    rgba(40, 255, 80, 0.05) 1px 2px,
    rgba(40, 80, 255, 0.07) 2px 3px
  );
  mix-blend-mode: screen;
  opacity: 0.45;
}

.vignette {
  background: radial-gradient(ellipse at center, transparent 88%, rgba(0, 0, 0, 0.28) 100%);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.18);
}

.glare {
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.04) 18%, transparent 36%),
    linear-gradient(250deg, transparent 62%, rgba(255, 255, 255, 0.05) 78%, transparent 90%);
  mix-blend-mode: screen;
}

.raster {
  position: absolute;
  inset: 0;
  transform-origin: center center;
}

.shutoff {
  z-index: 5;
  background: #f4fff8;
  opacity: 0;
  transform: scaleY(0.004);
  transform-origin: center;
}

.set.powering-on .raster,
.set.powering-off .raster,
.set.is-off .raster {
  opacity: 0;
}

.set.fading-in .raster {
  animation: picture-in 0.5s ease-out forwards;
}

.set.fading-out .raster {
  animation: picture-out 0.5s ease-in forwards;
}

.set.is-off .glass,
.set.is-off .sharp-plate,
.set.is-off .fringe,
.set.is-off #snow,
.set.is-off .scanlines,
.set.is-off .aperture,
.set.is-off .glare,
.set.is-off .osd {
  opacity: 0;
  animation: none;
}

.set.is-off .tube {
  background: #000;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
}

.set.powering-off .shutoff {
  animation: power-off 0.45s ease-in forwards;
}

.set.powering-on .shutoff {
  animation: power-on 0.38s ease-out forwards;
}

.osd:empty {
  display: none;
}

.osd {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 0 7% 7%;
  color: #ffe14a;
  font-family: Consolas, "Courier New", monospace;
  font-size: clamp(13px, 1.5vw, 18px);
  letter-spacing: 0.14em;
  text-shadow: 0 0 6px #000, 0 1px 0 #000;
  opacity: 0;
  z-index: 4;
}

.osd.is-on {
  opacity: 1;
}

.bezel-key {
  position: absolute;
  z-index: 2;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
}

.bezel-key:hover,
.bezel-key:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: 1px solid rgba(255, 255, 255, 0.35);
}

.bezel-key:active {
  background: rgba(0, 0, 0, 0.28);
}

.vol-down {
  left: 70.05%;
  top: 42.55%;
  width: 1.55%;
  height: 1.66%;
}

.vol-up {
  left: 71.6%;
  top: 42.55%;
  width: 1.55%;
  height: 1.66%;
}

.mute {
  left: 70.05%;
  top: 44.2%;
  width: 1.55%;
  height: 1.66%;
}

.power-key {
  left: 71.6%;
  top: 44.2%;
  width: 1.55%;
  height: 1.66%;
}

.remote {
  position: absolute;
  right: 22px;
  bottom: 18px;
  width: 214px;
  z-index: 4;
}

.remote-body {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.25)),
    linear-gradient(#3a3936, #232220 40%, #1a1918);
  border-radius: 36px 36px 42px 42px;
  padding: 18px 18px 22px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -16px 20px rgba(0, 0, 0, 0.35),
    0 18px 30px rgba(0, 0, 0, 0.45),
    0 0 0 1px #0c0c0c;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ir {
  width: 46px;
  height: 8px;
  border-radius: 8px;
  background: linear-gradient(#1a1a1a, #3a0d12);
  box-shadow: inset 0 1px 2px #000;
}

.remote-top {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.led {
  flex: 1;
  min-width: 0;
  height: 42px;
  border-radius: 6px;
  background: #140805;
  color: var(--amber);
  font-family: Consolas, "Courier New", monospace;
  font-size: 26px;
  letter-spacing: 0.22em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 8px var(--amber);
  box-shadow:
    inset 0 0 0 2px #2a120e,
    inset 0 8px 12px rgba(0, 0, 0, 0.65);
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 8px;
  justify-content: center;
}

.key {
  border: 0;
  color: #f3f1ec;
  background: linear-gradient(#55524d, #2e2c29);
  box-shadow:
    0 4px 0 #0e0d0c,
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  cursor: pointer;
  user-select: none;
}

.key:active,
.key.is-down {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 #0e0d0c,
    inset 0 2px 5px rgba(0, 0, 0, 0.55);
}

.key:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.digit {
  width: 52px;
  height: 46px;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 650;
}

.power {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6a55, #9d1b12 62%, #5c0d09);
  box-shadow:
    0 3px 0 #3a0907,
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  display: grid;
  place-items: center;
}

.power svg,
.arrow svg,
.mute-key svg,
.index-row svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff4f2;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arrow {
  width: 52px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sound-row .wide {
  flex: 1;
}

.mute-key {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #f3f1ec;
}

.mute-key .speaker {
  fill: currentColor;
  stroke: none;
}

.mute-key .slash {
  display: none;
}

.mute-key.is-muted {
  color: var(--amber);
}

.mute-key.is-muted .waves {
  display: none;
}

.mute-key.is-muted .slash {
  display: block;
  stroke: currentColor;
}

.sub-block {
  width: 100%;
}

.index-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.index-row .wide {
  flex: 1;
  height: 42px;
  display: grid;
  place-items: center;
}

.wide {
  height: 38px;
  border-radius: 10px;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.index {
  width: 42px;
  height: 42px;
  flex: none;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(#6a6238, #3d3818);
  display: grid;
  place-items: center;
}

.sub-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sub-block span {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #9a958c;
}


@keyframes phosphor {
  0%,
  16%,
  40%,
  66%,
  100% { opacity: 1; }
  7% { opacity: 0.88; }
  20% { opacity: 0.96; }
  46% { opacity: 0.8; }
  50% { opacity: 1; }
  73% { opacity: 0.9; }
}

@keyframes noise-flicker {
  0% { opacity: 0.144; }
  30% { opacity: 0.255; }
  55% { opacity: 0.114; }
  80% { opacity: 0.225; }
  100% { opacity: 0.156; }
}

@keyframes scan {
  from { background-position: 0 0; }
  to { background-position: 0 9px; }
}

@keyframes power-off {
  0% { opacity: 0.9; transform: scaleY(1) scaleX(1); }
  45% { opacity: 1; transform: scaleY(0.02) scaleX(1); }
  100% { opacity: 0; transform: scaleY(0.02) scaleX(0.2); }
}

@keyframes power-on {
  0% { opacity: 0; transform: scaleY(0.02) scaleX(0.15); }
  40% { opacity: 1; transform: scaleY(0.025) scaleX(1); }
  100% { opacity: 0; transform: scaleY(1) scaleX(1); }
}

@keyframes picture-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes picture-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.turn {
  display: none;
}

@media (max-width: 900px) and (orientation: portrait) {
  .room {
    display: flex;
    flex-direction: column;
  }

  .stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    inset: auto;
    overflow: hidden;
  }

  .remote {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    flex: 0 0 auto;
    transform: none;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  }

  .remote-body {
    width: min(420px, 100%);
    margin: 0 auto;
    border-radius: 28px 28px 22px 22px;
    padding: 10px 14px 12px;
    gap: 6px;
  }

  .ir,
  .sub-block span {
    display: none;
  }

  .led {
    height: 36px;
    font-size: 22px;
  }

  .pad {
    width: min(280px, 100%);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .digit,
  .arrow,
  .wide {
    height: 42px;
  }

  .digit,
  .arrow {
    width: 100%;
  }

  .sound-row .wide {
    width: auto;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .turn {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 20;
    margin: 0;
    align-items: center;
    justify-content: center;
    background: #1a1410;
    color: #f3f1ec;
    font-size: 18px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sharp-plate,
  #snow,
  .scanlines,
  .shutoff,
  .raster {
    animation: none;
  }
}
