/* =========================================================
   RETRO TV (hero intro video)
   Everything is scoped under .retro-tv so it can't clash with
   the rest of the site. Uses native CSS nesting (no PostCSS).
========================================================= */
.retro-tv {
  --television-width: 430px;
  --television-height: 360px;
  --television-bgcolor: #2b2b2b;
  --television-bgcolor-dark: #1a1a1a;
  --television-edge: #0d0d0d;
  --antenna-gradient: linear-gradient(to top, #444 10%, #999 25% 40%, #444 70%, #2224 90%);

  /* the site has a global border-box reset; the original TV was
     built with content-box, so restore it to keep the exact sizes */
  &, & *, & *::before, & *::after { box-sizing: content-box; }
  line-height: normal;

  width: 100%;
  max-width: var(--television-width);
  height: var(--television-height);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: left;

  & .antenna-container {
    width: 235px;
    height: 85px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    & .antenna {
      width: 100%;
      height: 4px;
      background: var(--antenna-gradient);
      transform-origin: 100% 50%;
      transform: rotate(20deg) translateY(3px);
      z-index: 0;
      display: flex;
      align-items: center;

      &::before {
        content: "";
        display: block;
        width: 8px;
        height: 10px;
        background: var(--antenna-gradient);
        border-radius: 24% 53% 53% 24% / 36% 40% 40% 36%;
        border: 1px solid #444;
        border-left: 0;
        border-bottom: 0;
        transform: translateY(-1px);
      }
    }
  }

  & .television-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;

    & .television {
      width: 425px;
      height: 300px;
      border-radius: 35px / 45px;
      box-shadow:
        2px 2px 5px #0004,
        2px -2px 2px var(--television-edge) inset,
        2px 1px 1px #fff inset,
        0 0 3px 5px #0002;
      background: linear-gradient(var(--television-bgcolor), var(--television-bgcolor-dark));
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 2;

      & .television-inner {
        width: 93%;
        height: 90%;
        background: linear-gradient(to bottom, #454545 5%, var(--color-dark, #1a1a1a) 35% 45%);
        border-bottom: 1px solid #fff;
        box-shadow: 0 1px 2px var(--television-edge) inset;
        border-radius: 25px / 25px;
        position: relative;
        display: grid;
        grid-template-columns: 3fr 1fr;
        grid-template-rows: 0.8fr;
        align-content: center;
        gap: 3px;

        & .television-screen-container {
          border: 1px solid #222;
          box-shadow:
            0 2px 2px #888,
            2px 0 2px #444,
            -2px 0 2px #444,
            0 -2px 2px #111;
          border-radius: 35px / 25px;
          margin: 10px;
          overflow: hidden;
          display: flex;
          justify-content: center;
          align-items: center;
          background:
            linear-gradient(70deg, #555 15%, transparent 30%),
            repeating-conic-gradient(#222 0 30deg, #333 60deg, #222 90deg);

          & .television-crt {
            width: 99%;
            height: 95%;
            background: #111;
            box-shadow:
              0 0 5px 2px #111,
              0 0 10px 2px #1112;
            border-radius: 85px / 100px;
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;

            & .television-screen {
              background: #1c1d26;
              width: 95%;
              height: 95%;
              border-radius: 30%;
              box-shadow: 0 0 5px 2px #111 inset;
              overflow: hidden;
              position: relative;
              cursor: pointer;

              /* the video itself */
              & .tv-video {
                position: absolute;
                inset: 0;
                width: 100%;
                height: 100%;
                object-fit: cover;
                background: #000;
                opacity: 0;
                z-index: 1;
                transition: opacity 0.3s, filter 0.15s;
              }

              /* scanlines + rolling band, sits above the video */
              & .noise {
                width: 100%;
                height: 100%;
                background:
                  linear-gradient(to bottom, transparent, #aaa4, #8881, #6664, #4445, #2228, #4443, transparent),
                  repeating-linear-gradient(transparent 0 2px, #25242950 2px 4px);
                animation: retroTvMoveBand 8s linear infinite;
                z-index: 4;
                position: relative;
                pointer-events: none;
                transition: opacity 0.3s;
              }

              /* black overlay when the TV is switched off */
              & .off {
                width: 100%;
                height: 100%;
                background: radial-gradient(#222, #1a1a1a, #111);
                z-index: 5;
                position: absolute;
                top: 0;
                opacity: 0;
                transition: opacity 0.5s;
                pointer-events: none;
              }

              /* idle screen (before you press play) */
              & .logo-container {
                position: absolute;
                z-index: 2;
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                gap: 8px;
                transition: opacity 0.3s;

                & .logo {
                  background: #1a1a1a;
                  width: 45px;
                  height: 32px;
                  border-radius: 8px;
                  display: grid;
                  place-items: center;
                  box-shadow: 0 0 14px #ffffff40;
                  border: 1px solid #3a3a3a;

                  & .play {
                    width: 15px;
                    height: 15px;
                    background: #fff;
                    clip-path: polygon(0 0, 100% 50%, 0 100%);
                  }
                }

                & .screen-title {
                  font-family: var(--font-serif-italic, 'Instrument Serif', serif);
                  font-style: italic;
                  font-size: 26px;
                  color: #fff;
                  letter-spacing: -0.02em;
                }

                & .screen-hint {
                  font-family: var(--font-mono, 'Geist Mono', monospace);
                  font-weight: 700;
                  font-size: 8px;
                  letter-spacing: 0.125em;
                  text-transform: uppercase;
                  color: #b0b0b0;
                }
              }

            }
          }
        }

        & .television-lateral {
          display: grid;
          grid-template-rows: 1.1fr 1fr;
          gap: 12px;
          margin: 15px;
          margin-left: 0;

          & .dial-container {
            border: 2px solid #333;
            border-left: 1px solid #444;
            border-bottom: 2px solid #444;
            border-radius: 5px;
            box-shadow:
              -2px 2px 6px #111 inset,
              -1px 2px 3px #aaa;
            display: flex;
            flex-direction: column;
            justify-content: center;
            gap: 6px;
            align-items: center;

            & .dial {
              width: 42px;
              height: 42px;
              border: 2px solid #6e706f;
              border-radius: 50%;
              box-shadow:
                -4px 2px 4px #111,
                0 0 1px 2px #000;
              display: flex;
              justify-content: center;
              align-items: center;
              position: relative;
              cursor: grab;
              user-select: none;

              & .data-container {
                display: flex;
                justify-content: center;
                width: 100%;
                height: 100%;

                & .data {
                  color: #888;
                  font-family: var(--font-mono, monospace);
                  font-size: 6px;
                  text-shadow: 0 0 2px #888;
                  position: absolute;
                  top: 0;
                  height: 100%;
                  transform-origin: 50% 50%;

                  &:nth-child(2) { transform: rotate(30deg); }
                  &:nth-child(3) { transform: rotate(60deg); }
                  &:nth-child(4) { transform: rotate(90deg); }
                  &:nth-child(5) { transform: rotate(120deg); }
                  &:nth-child(6) { transform: rotate(150deg); }
                  &:nth-child(7) { transform: rotate(180deg); }
                  &:nth-child(8) { transform: rotate(210deg); }
                  &:nth-child(9) { transform: rotate(240deg); }
                  &:nth-child(10) { transform: rotate(270deg); }
                  &:nth-child(11) { transform: rotate(300deg); }
                  &:nth-child(12) { transform: rotate(330deg); }
                }
              }

              & .dial-core {
                width: 28px;
                height: 28px;
                border-radius: 50%;
                background: conic-gradient(#eee 0deg 45deg, #666 70deg 285deg, #eee 320deg);
                position: absolute;
              }

              & .selector {
                position: absolute;
                width: 75%;
                background: linear-gradient(#666 30%, #aaa 40%);
                height: 4px;
                border: 1px solid #666;
                border-radius: 4px / 8px;
                transform: rotate(calc(var(--value) - 90deg));
                transition: transform 0.25s linear;
              }

              &.channel-button { background: #000; }

              &.volume-button {
                background: #ccc;
                & .data { color: #444; }
              }

              &:focus-visible {
                outline: 2px solid #b0b0b0;
                outline-offset: 3px;
              }
            }
          }

          & .speaker-container {
            display: grid;
            grid-template-columns: repeat(6, 1fr);
            gap: 1px 0;
            margin-bottom: 12px;
            margin-left: 2px;
            margin-right: 2px;

            & div {
              width: 10px;
              height: 10px;
              background: radial-gradient(#000, #222);
              border-radius: 50%;
              border-bottom: 1px solid #fff;
            }
          }
        }

        & .buttons {
          position: absolute;
          bottom: 5px;
          right: 30px;
          width: 60px;
          display: flex;
          justify-content: space-between;

          & .button-container {
            width: 20px;
            height: 20px;
            background: linear-gradient(to bottom, #fff 40%, #aaa 50% 55%, #666 70%);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;

            & .tv-button {
              width: 10px;
              height: 10px;
              padding: 0;
              border: 0;
              border-radius: 50%;
              background: linear-gradient(to top, #fff 40%, #aaa 50% 55%, #666 70%);
              box-shadow: -1px -1px 1px 2px #000;
              transform: translate(2px, 1px);
              transition: transform 0.1s, box-shadow 0.1s;
              cursor: pointer;

              &:active {
                transform: translate(0, 0);
                box-shadow: 0 0 1px 2px #000;
              }

              &:focus-visible {
                outline: 2px solid #b0b0b0;
                outline-offset: 4px;
              }
            }
          }
        }
      }
    }

    & .television-base {
      width: 350px;
      height: 25px;
      background: linear-gradient(var(--television-bgcolor), var(--television-bgcolor-dark));
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0 8px 4px #0009;

      &::before,
      &::after {
        content: "";
        display: block;
        width: 8px;
        height: 100%;
        background-color: var(--television-bgcolor);
        background-image: linear-gradient(var(--television-bgcolor), var(--television-bgcolor-dark));
        transform: translateX(var(--x)) skewX(var(--skew-x));
      }
      &::before { --skew-x: 10deg; --x: -2px; }
      &::after  { --skew-x: -10deg; --x: 2px; }

      & .slots {
        width: 50%;
        height: 15px;
        display: flex;
        justify-content: center;

        & .slot {
          width: 4px;
          height: 100%;
          background: #0B0000;
          margin-left: 3px;
          border-radius: 2px / 1px;
        }
      }
    }

    & .foot-container {
      width: 70%;
      display: flex;
      justify-content: space-between;

      & .foot {
        width: 20px;
        height: 10px;
        background: var(--television-bgcolor);

        &.left  { box-shadow: 4px 0 var(--television-edge); }
        &.right { box-shadow: -4px 0 var(--television-edge); }
      }
    }
  }
}

/* ---------- Screen states (data-state on .retro-tv) ---------- */
/* idle = static + "press play" (default) | playing | off */
.retro-tv[data-state="playing"] .tv-video { opacity: 1; }
.retro-tv[data-state="playing"] .logo-container { opacity: 0; }
.retro-tv[data-state="playing"] .noise { opacity: 0.35; }
.retro-tv[data-state="off"] .off { opacity: 1; }
.retro-tv[data-state="off"] .logo-container { opacity: 0; }

/* channel-change flash */
.retro-tv .television-screen.is-tuning .tv-video {
  filter: brightness(2) contrast(1.8) grayscale(1) blur(1px);
}
.retro-tv .television-screen.is-tuning .noise { opacity: 1; }

@keyframes retroTvMoveBand {
  0%   { background-position-y: 0, 0; }
  100% { background-position-y: -221px, -150px; }
}

/* caption under the TV */
.retro-tv-wrap {
  position: relative; /* anchor for the annotation */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ---- Power button idle blink ---- */
/* The second .tv-button is the power button (index 1). We target it via
   the parent .button-container:last-child so no HTML change is needed. */
.retro-tv[data-state="idle"] .buttons .button-container:last-child .tv-button {
  box-shadow: -1px -1px 1px 2px #000, 0 0 6px 3px rgba(255, 255, 255, 0.6);
  animation: powerBlink 1.8s ease-in-out infinite;
}

@keyframes powerBlink {
  0%, 100% { box-shadow: -1px -1px 1px 2px #000, 0 0 4px 2px rgba(255, 255, 255, 0.3); }
  50%       { box-shadow: -1px -1px 1px 2px #000, 0 0 10px 5px rgba(255, 255, 255, 0.85); }
}

/* Stop blinking once playing or off */
.retro-tv[data-state="playing"] .buttons .button-container:last-child .tv-button,
.retro-tv[data-state="off"] .buttons .button-container:last-child .tv-button {
  animation: none;
}

.retro-tv-caption {
  font-family: var(--font-mono, monospace);
  font-weight: 700;
  font-size: var(--fs-small);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-muted, #343434);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .retro-tv .noise { animation: none; }
}

/* Coming-soon broadcast sequence; these rules style only its added elements. */
.retro-tv .tv-sequence-layer {
  position: absolute;
  z-index: 6;
  inset: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
}

.retro-tv .tv-sequence-layer.is-active { visibility: visible; }

.retro-tv .tv-sequence-flash {
  position: absolute;
  z-index: 4;
  inset: 0;
  background: #fff;
  opacity: 0;
}

.retro-tv .tv-sequence-flash.is-visible { opacity: 1; }

.retro-tv .tv-sequence-static,
.retro-tv .tv-sequence-scanlines {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 200ms linear;
}

.retro-tv .tv-sequence-static {
  object-fit: cover;
  image-rendering: pixelated;
}

.retro-tv .tv-sequence-scanlines {
  z-index: 2;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgb(0 0 0 / 78%) 2px 4px
  );
  transition-duration: 200ms;
}

.retro-tv .tv-sequence-copy {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px;
  color: #fff;
  text-align: center;
  text-shadow: 0 0 8px rgb(255 255 255 / 70%);
}

.retro-tv .tv-sequence-headline,
.retro-tv .tv-sequence-subline {
  margin: 0;
  opacity: 0;
  transition: opacity 300ms ease;
}

.retro-tv .tv-sequence-headline {
  font: 700 clamp(9px, 2.7vw, 13px)/1.4 var(--font-mono, monospace);
  letter-spacing: 0.06em;
  max-width: 20ch;
  text-wrap: balance;
}

.retro-tv .tv-sequence-character {
  opacity: 0;
  animation: tvSequenceTypeIn 1ms steps(1, end) forwards;
  animation-delay: calc(var(--character-index) * 32ms);
}

@keyframes tvSequenceTypeIn {
  to { opacity: 1; }
}

.retro-tv .tv-sequence-subline {
  font: 500 clamp(9px, 2.4vw, 12px)/1.4 var(--font-mono, monospace);
}

@media (max-width: 640px) {
  .retro-tv .tv-sequence-headline { font-size: clamp(12px, 4vw, 16px); }
  .retro-tv .tv-sequence-subline { font-size: clamp(12px, 3.5vw, 14px); }
}

.retro-tv .tv-sequence-headline.is-visible,
.retro-tv .tv-sequence-subline.is-visible { opacity: 1; }

.retro-tv .tv-sequence-arrow {
  display: inline-block;
  margin-left: 4px;
  animation: tvSequenceArrowBob 900ms ease-in-out infinite alternate;
}

.retro-tv .tv-sequence-layer.is-fading .tv-sequence-headline,
.retro-tv .tv-sequence-layer.is-fading .tv-sequence-subline { opacity: 0; }

.retro-tv .tv-sequence-layer.is-static .tv-sequence-static,
.retro-tv .tv-sequence-layer.is-static .tv-sequence-scanlines { opacity: 0.55; }

.retro-tv .tv-sequence-layer.is-fading .tv-sequence-static,
.retro-tv .tv-sequence-layer.is-fading .tv-sequence-scanlines { opacity: 0; }

@keyframes tvSequenceArrowBob {
  from { transform: translateY(-2px); }
  to { transform: translateY(3px); }
}

@media (prefers-reduced-motion: reduce) {
  .retro-tv .tv-sequence-arrow { animation: none; }
}