@font-face {
  font-family: "Bobar";
  src: url("../fonts/bobar.otf") format("opentype");
}

html {
  container-name: tvKnob;
  overflow-y: hidden;
  --tv-width-outer: 72vw;
  --tv-height-outer: 63vh;
  --tv-width-inner: 66vw;
  --tv-height-inner: 57vh;
  --wood-inner: rgb(150 101 10);
  --wood-outer: rgb(176 121 19);
  --wood-dark-inner: rgb(116 84 25);
  --wood-dark-outer: rgb(107 74 12);
  --leg-color: #73421f;
  --leg-shadow: #673d1d;
  --circle-gradient: radial-gradient(
    circle at 50% 40%,
    #989393 0%,
    #222 60%,
    #111 100%
  );
  --dark-bg: rgba(3, 3, 3, 0.6);
}

/* https://github.com/jensimmons/cssremedy/blob/master/css/remedy.css  */
*,
::before,
::after {
  box-sizing: border-box;
}

/* ===================== */
/*  VARIABLES & THEMING  */
/* ===================== */

:root:has([value="dark"]:checked) {
  body {
    background-image:
      linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
      url(../images/retrobg.png);
  }
  main > div:first-child {
    background-color: var(--wood-dark-outer);
  }
  main aside {
    background-color: var(--wood-dark-inner);
  }
  main section {
    background: rgb(140, 130, 130);
    box-shadow:
      inset 0 0 40px 20px rgba(146, 108, 108, 0.5),
      inset 0 0 80px 40px rgba(146, 108, 108, 0.25),
      inset 0 0 120px 60px rgba(146, 108, 108, 0.1),
      0 0 11px 9px rgba(216, 205, 205, 0.2);
    filter: brightness(1.5);
  }

  main > div:first-child > div {
    border: 10px var(--wood-dark-inner) solid;
    background-color: var(--wood-dark-inner);
  }

  main aside > div ~ div {
    background-color: var(--wood-dark-inner);
  }

  input[type="range"] {
    background-image: radial-gradient(
      circle at 55% 25%,
      #58564f 0%,
      #444 35%,
      #000000 100%
    );
  }

  input[type="checkbox"]::after {
    background: radial-gradient(
      circle at 55% 25%,
      #58564f 0%,
      #444 35%,
      #000000 100%
    );
  }

  input[type="checkbox"] + div {
    background: radial-gradient(
      circle at 51% -15%,
      #3b3a3a 0%,
      #222 60%,
      #111 100%
    );
  }

  @container tvKnob style(--channel: 50) {
    main:has(aside input[type="checkbox"]:checked) {
      section video:nth-of-type(4) {
        display: none;
      }
    }

    section h1 {
      display: none;
    }
    section video:nth-of-type(1) {
      display: none;
    }
    section video:nth-of-type(4) {
      display: block;
    }

    body {
      background:
        linear-gradient(var(--dark-bg)), url("../images/pinkpantherdark.png"),
        #cc9596;
      background-repeat: repeat;
      background-size: 260px;
      background-position: 100% 31%;
    }
  }

  @container tvKnob style(--channel: 100) {
    body {
      background:
        linear-gradient(var(--dark-bg)), url(../images/scoobydoodark.jpg);
      background-size: 1600px;
      background-position: 50% 44%;
    }
  }
  @container tvKnob style(--channel: 150) {
    body {
      background:
        linear-gradient(var(--dark-bg)), url(../images/flintstonesdark.jpg);
      background-size: 550px;
      background-position: 50% 44%;
    }
  }
}

/* ===================== */
/*       LAYOUT          */
/* ===================== */

body {
  display: flex;
  margin: 0;
  justify-content: center;
  align-items: center;
  margin-top: 6em;
  background-image:
    linear-gradient(rgba(138, 103, 103, 0.4), rgba(138, 103, 103, 0.4)),
    url("../images/retrobg.png");
  background-size: 800px;
}

h1 {
  display: none;
  text-align: center;
}

/* https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Animations/Using */

h1 span {
  font-family: "Bobar", sans-serif;
  font-size: clamp(2rem, 9vw, 8rem);
  opacity: 0;
  color: #f5c400;
  text-shadow:
    4px 4px 0 #e8001d,
    8px 8px 0 rgba(232, 0, 29, 0.3);
  letter-spacing: 0.02em;
  line-height: 1;
  animation:
    appear 0.5s forwards,
    weightPulse 2s ease-in-out infinite,
    cycleStyles 4s steps(1) infinite;
}

/* Help from Claude: prompt: combine and randomize the timings */
h1 div:nth-child(1) {
  & span:nth-child(1) {
    animation-delay: 0s, 1s, 1s;
  }
  & span:nth-child(2) {
    animation-delay: 0.7s, 1s, 1s;
  }
  & span:nth-child(3) {
    animation-delay: 1.4s, 1s, 1s;
  }
  & span:nth-child(4) {
    animation-delay: 0.3s, 1s, 1s;
  }
}

h1 div:nth-child(2) {
  & span:nth-child(1) {
    animation-delay: 1.1s, 1s, 1s;
  }
  & span:nth-child(2) {
    animation-delay: 0.5s, 1s, 1s;
  }
  & span:nth-child(3) {
    animation-delay: 1.8s, 1s, 1s;
    padding-left: 0.15em;
  }
  & span:nth-child(4) {
    animation-delay: 0.9s, 1s, 1s;
  }
  & span:nth-child(5) {
    animation-delay: 1.6s, 1s, 1s;
  }
}

h1 div:nth-child(3) {
  & span:nth-child(1) {
    animation-delay: 0.4s, 1s, 1s;
  }
  & span:nth-child(2) {
    animation-delay: 1.2s, 1s, 1s;
  }
  & span:nth-child(3) {
    animation-delay: 2s, 1s, 1s;
  }
  & span:nth-child(4) {
    animation-delay: 0.8s, 1s, 1s;
  }
}

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

@keyframes weightPulse {
  0%,
  100% {
    text-shadow:
      4px 4px 0 #e8001d,
      8px 8px 0 rgba(232, 0, 29, 0.3);
  }
  50% {
    text-shadow:
      6px 6px 0 #e8001d,
      10px 10px 0 rgba(232, 0, 29, 0.4);
  }
}

@keyframes cycleStyles {
  0% {
    font-feature-settings: normal;
  }
  50% {
    font-feature-settings: "salt" on;
  }
}

/* https://codepen.io/ynef/pen/yvvyGv */

/* ===================== */
/*      TV SCREEN        */
/* ===================== */

main section > div:first-of-type {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 16px 18px rgba(16, 16, 16, 1);
  z-index: 10;
  pointer-events: none;
}

main section {
  overflow: hidden;
  position: relative;
  background: rgb(171 144 144);
  border-radius: 50px;
  padding: 1em;
  display: flex;
  justify-content: center;
  align-items: center;

  &::before,
  &::after {
    display: block;
    pointer-events: none;
    content: "";
    position: absolute;
  }

  &::before {
    width: 100%;
    height: 6px;
    z-index: 6;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0.2;
    animation: scanline 12s linear infinite;
  }

  &::after {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    background: linear-gradient(
      to bottom,
      transparent 40%,
      rgba(0, 0, 0, 0.06) 52%
    );
    background-size: 100% 4.3px;
    animation: scanlines 1s steps(60) infinite;
  }
}

@keyframes scanline {
  0% {
    transform: translate3d(0, 100vh, 0);
  }
  100% {
    transform: translate3d(0, -100vh, 0);
  }
}
@keyframes scanlines {
  0% {
    background-position: 0 50%;
  }
}

/* ===================== */
/*     TV STRUCTURE      */
/* ===================== */

/* tv-outer */
main > div {
  display: flex;
  justify-content: center;
  align-items: center;
  width: var(--tv-width-outer);
  max-width: 800px;
  height: var(--tv-height-outer);
  border-radius: 20px;
}

main > div:first-child {
  background-color: var(--wood-outer);
}

/* tv-inner */
main > div > div {
  display: grid;
  gap: 0.6em;
  grid-template-columns: 3fr 1fr;
  border: 10px var(--wood-inner) solid;
  width: var(--tv-width-inner);
  height: var(--tv-height-inner);
  max-width: 730px;
  border-radius: 20px;
  corner-shape: squircle;
  background-color: var(--wood-inner);
}

/* ===================== */
/*     TV SIDEPANEL      */
/* ===================== */

main aside {
  background-color: var(--wood-inner);
  display: grid;
  grid-template-rows: 2fr 1fr;
}

/* tv-buttonarea */
main aside > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-direction: column;
  gap: 1em;
  padding: 1em;
}

main aside > div > div {
  display: flex;
}

main aside > div ~ div {
  grid-row: 2 / 3;
  width: 100%;
  height: 100%;
  background-color: var(--wood-inner);

  background-image: repeating-linear-gradient(
    180deg,
    transparent 0px,
    transparent 6px,
    hsl(0deg 3.42% 16.57%) 12px,
    #555 14.6px
  );
  border-radius: 4px;
  corner-shape: squircle;

  @media (max-width: 768px) {
    width: 95%;
    margin: auto;
  }
}

aside div:nth-of-type(2) {
  gap: 0;
}

main > div:nth-of-type(2) {
  position: absolute;
  gap: 40%;
  height: fit-content;
}

main > div:nth-of-type(2) > div {
  border: none;
  width: 5vh;
  height: 40vh;
  border-radius: 8px;
  background-color: var(--leg-color);
  z-index: -1;
  transform: rotate(13deg);
  box-shadow: 11px -20px 2px 7px var(--leg-shadow);
}

main > div:nth-of-type(2) > div:nth-of-type(2) {
  transform: rotate(347deg);
  box-shadow: -11px -20px 2px 7px var(--leg-shadow);
}

/* ===================== */
/*     CONTROLS          */
/* ===================== */

/* Hulp van Sanne */
/* https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Images/Using_gradients#using_radial_gradients */

input[type="range"] {
  position: relative;
  appearance: none;
  display: grid;
  width: 7em;
  height: 7em;
  cursor: pointer;
  border-radius: 64%;
  border: 3px solid #504e4e;
  background: transparent;
  background-image: radial-gradient(
    circle at 55% 25%,
    #878473 0%,
    #444 35%,
    #000 100%
  );

  &::before {
    grid-area: 1/1;
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(
      0deg,
      transparent 45%,
      hsl(0deg 0% 0%) 45%,
      hsl(339deg 0% 0%) 47%,
      hsl(344deg 0% 19%) 49%,
      hsl(344deg 0% 78%) 51%,
      hsl(300deg 100% 100%) 53%,
      hsl(0deg 0% 100%) 55%,
      transparent 55%
    );
    border-radius: 50%;
    pointer-events: none;
    opacity: 1;
    z-index: 1;
    transition: rotate 1s cubic-bezier(0.1, 1.3, 0.5, 1);
    rotate: calc(var(--channel) / 100 * 0.5turn);
    background-size:
      80% 100%,
      cover;
    background-repeat: no-repeat;
    background-position: center;
  }

  &::after {
    content: "";
    grid-area: 1/1;
    display: block;
    place-self: center;
    position: absolute;
    left: calc(50% - 0.75em);
    width: 1.5em;
    height: 1.5em;
    z-index: 3;
    background-color: #4a4a4a;
    transition: rotate 1s cubic-bezier(0.1, 1.3, 0.5, 1);
    clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%, 0 50%);
    transition: transform 1s cubic-bezier(0.1, 1.3, 0.5, 1);
    /* https://www.joshwcomeau.com/gradient-generator/ */
    background-image: linear-gradient(
      0deg,
      hsl(0deg 0% 0%) 0%,
      hsl(344deg 0% 19%) 27%,
      hsl(344deg 0% 37%) 49%,
      hsl(344deg 0% 57%) 68%,
      hsl(344deg 0% 78%) 85%,
      hsl(0deg 0% 100%) 100%
    );
    transform: rotate(calc(var(--channel) / 100 * 0.5turn))
      translateX(calc(-2.5em));
  }
}

input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  opacity: 0;
}

aside div label {
  display: grid;
  place-items: center;
}

aside div label > * {
  grid-area: 1/1;
  place-self: center;
}

aside div label div {
  z-index: 2;
  color: white;
  font-family: monospace;
  font-size: 1.2em;
}

/* inspired by / based on https://www.joshwcomeau.com/animation/3d-button/   */

input[type="checkbox"]:first-of-type {
  appearance: none;
  border-radius: 50%;
  background-color: #444;
  cursor: pointer;
  position: relative;
  border: none;
  padding: 1px;
  margin-top: 1em;

  &::after {
    content: "";
    display: block;
    padding: 1.1em;
    border-radius: 50%;
    background: var(--circle-gradient);
    transform: translate(-1px, -4px);
    transition:
      transform 0.2s,
      box-shadow 0.2s;
  }

  &:checked::after,
  &:active::after {
    transform: translate(-1px, -1px);
  }
}

main:has(aside input[type="checkbox"]:checked) {
  section {
    video,
    h1 {
      display: none;
    }
  }
}

video {
  height: 100%;
}

section video {
  display: none;
}

@container tvKnob style(--channel: 0) {
  section h1 {
    display: block;
  }
}

@container tvKnob style(--channel: 50) {
  section h1 {
    display: none;
  }
  section video:nth-of-type(1) {
    display: block;
  }
  body {
    background:
      linear-gradient(rgba(255, 255, 255, 0.6)), url(../images/pinkpanther.png);
    background-repeat: repeat;
    background-size: 206px;
    background-position: 100% 14%;
    background-color: rgba(135, 91, 91, 0.4);
    background-blend-mode: darken;
  }
  main section {
    background: rgb(109 109 109);
  }
}

@container tvKnob style(--channel: 100) {
  section video:nth-of-type(1) {
    display: none;
  }
  section video:nth-of-type(2) {
    display: block;
  }
  body {
    background:
      linear-gradient(rgba(119, 63, 63, 0.4)), url(../images/scoobydoo.jpg);
    background-size: 1700px;
    background-position: 50% 14%;
  }
  main section {
    background: rgb(109 109 109);
  }
}

@container tvKnob style(--channel: 150) {
  section video:nth-of-type(2) {
    display: none;
  }
  section video:nth-of-type(3) {
    display: block;
  }
  body {
    background:
      linear-gradient(rgba(119, 63, 63, 0.4)), url(../images/flintstones.webp);
    background-position: 50% 50%;
  }
  main section {
    background: rgb(109 109 109);
  }
}

@container tvKnob style(--channel: 200) {
  section video:nth-of-type(3) {
    display: none;
  }
  section h1 {
    display: block;
  }
}

aside div label div:nth-child(1) {
  transform: rotate(0deg) translateY(-3.5em) rotate(0deg);
}
aside div label div:nth-child(2) {
  transform: rotate(88deg) translateY(-3.5em) rotate(275deg);
}
aside div label div:nth-child(3) {
  transform: rotate(180deg) translateY(-3.5em) rotate(181deg);
}
aside div label div:nth-child(4) {
  display: none;
  transform: rotate(216deg) translateY(-3.5em) rotate(-216deg);
}
aside div label div:nth-child(5) {
  transform: rotate(270deg) translateY(-3.5em) rotate(88deg);
}
aside div label div:nth-child(6) {
  transform: rotate(0deg) translateY(-3.5em) rotate(-360deg);
}

/* ===================== */
/*      ANTENNA          */
/* ===================== */

input[type="checkbox"] + div {
  position: absolute;
  top: 65px;
  z-index: 3;
  height: 2rem;
  width: 8rem;
  border-radius: 5rem 5rem 0 0;
  background: radial-gradient(
    circle at 51% -15%,
    #989393 0%,
    #222 60%,
    #111 100%
  );

  &::before,
  &::after {
    content: "";
    position: absolute;
    bottom: 96%;
    width: 9px;
    height: 10rem;
    background: rgb(125, 118, 111);
    border-radius: 4px;
  }

  &::before {
    left: 30%;
    transform: rotate(-15deg);
    transform-origin: bottom center;
    transition: transform 0.3s ease;
  }

  &::after {
    right: 30%;
    transform: rotate(15deg);
    transform-origin: bottom center;
    transition: transform 0.3s ease;
  }
}

label[for="antenna"] {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 10rem;
  height: 10rem;
  z-index: 10;
  cursor: pointer;
}

/* screen noise filter */
svg {
  width: 0;
  height: 0;
  position: absolute;
}

body > input[type="checkbox"]:first-of-type {
  appearance: auto;
  display: none;
}

body > input[type="checkbox"]:first-of-type:checked ~ div main section video {
  filter: url(#filter) opacity(0.5);
}

body > input[type="checkbox"]:first-of-type:checked ~ div main section h1 {
  width: 100%;
  height: 100%;
  filter: url(#filter) opacity(0.5);
}

body > input[type="checkbox"]:first-of-type:checked + div::before {
  transform: rotate(-35deg);
}

body > input[type="checkbox"]:first-of-type:checked + div::after {
  transform: rotate(55deg);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 50px;
}

body > input[type="checkbox"]:nth-of-type(2) {
  appearance: none;
  border-radius: 50%;
  background-color: #444;
  cursor: pointer;
  position: relative;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.8em;
  position: absolute;
  top: 14px;
  left: 30px;

  &::after {
    content: "";
    position: absolute;
    width: 0.4em;
    height: 2em;
    border-radius: 4px;
    background: linear-gradient(180deg, #989393 0%, #222 60%, #111 100%);
    transform-origin: center bottom;
    transform: rotate(-30deg);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  &:checked::after,
  &:active::after {
    transform: rotate(30deg);
  }
}

/* Media queries  */

@media (max-width: 768px) {
  main > div > div {
    grid-template-columns: 1fr;
    grid-template-rows: 3fr 1fr;
  }
  main aside > div {
    flex-direction: row;
    padding: 1em;
    justify-content: space-around;
  }
  input[type="range"] {
    width: 6em;
    height: 6em;
  }
  main > div:nth-of-type(2) {
    gap: 55%;
  }
}
