* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  width: 100%;
  font-family: "Reddit Mono", monospace;
  font-optical-sizing: auto;
  font-weight: 300;
  font-size: 3vmax;
  font-style: normal;
  text-align: center;
  overflow: hidden;
  user-select: none;
  background-color: var(--bgcolor);
}

main {
  height: 100%;
  width: 100%;
  display: grid;
  justify-content: center;
  justify-items: center;
  grid-template-rows: 1fr min-content 1fr;
  grid-template-columns: 100%;
}

.clock {
  &.analog {
    & h1 {
      display: none;
    }
    & .classic-clock {
      display: block;
    }
  }

  & h1 {
    font-size: 3em;
    font-weight: 200;
    color: var(--fgcolor);
  }

  & .classic-clock {
    --clock-size: 40vmin;
    --minute-hand-thickness: calc(0.025 * var(--clock-size));
    --hour-hand-thickness: calc(0.03 * var(--clock-size));
    --half-minute-hand: calc(var(--minute-hand-thickness) / 2);
    --half-hour-hand: calc(var(--hour-hand-thickness) / 2);
    --minutes: calc(var(--seconds) / 60);
    --hours: calc(var(--minutes) / 60);

    display: none;
    position: relative;
    width: var(--clock-size);
    height: var(--clock-size);
    border-radius: 50%;
    margin: 0 auto;

    /* Clock face */
    & > div {
      width: 100%;
      height: 100%;
      background-color: var(--fgcolor);
      mask-image: var(--face);
      mask-size: contain;
      mask-repeat: no-repeat;
      mask-position: center;
    }

    /* Hours hand */
    &:before,
    &:after {
      content: "";
      display: block;
      width: var(--hour-hand-thickness);
      height: calc(0.3 * var(--clock-size));
      background-color: var(--fgcolor);
      position: absolute;
      left: calc(50% - var(--half-hour-hand));
      top: calc(50% - 0.3 * var(--clock-size) + var(--half-hour-hand));
      transform: rotateZ(calc(360deg * var(--hours) / 12));
      transform-origin: var(--half-hour-hand) calc(100% - var(--half-hour-hand));
      border-top-left-radius: 50%;
      border-top-right-radius: 50%;
      border-bottom-left-radius: var(--half-hour-hand);
      border-bottom-right-radius: var(--half-hour-hand);
      /* box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2); */
    }

    /* Minutes hand */
    &:after {
      width: var(--minute-hand-thickness);
      height: calc(0.45 * var(--clock-size));
      background-color: var(--fgcolor);
      left: calc(50% - var(--half-minute-hand));
      top: calc(50% - 0.45 * var(--clock-size) + var(--half-minute-hand));
      transform: rotateZ(calc(360deg * var(--minutes) / 60));
      transform-origin: var(--half-minute-hand)
        calc(100% - var(--half-minute-hand));
    }
  }
}

.next-up {
  display: flex;
  flex-direction: column;
  justify-content: center;

  & h1 {
    font-size: 0.8em;
    font-weight: 200;
    color: var(--fgcolor);
  }
  & p {
    font-size: 1em;
    color: var(--fgcolor);
  }
}

.current {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;

  & p {
    font-size: 1em;
    color: var(--fgcolor);
  }

  --progress-bar-height: 1.5vh;

  & #progress {
    width: 80%;
    height: var(--progress-bar-height);
    margin: 1em auto 0 auto;
    border: 2px solid var(--fgcolor);
    border-radius: calc(var(--progress-bar-height) / 2);
    transition: background 1s linear;
    background: linear-gradient(
      to right,
      var(--fgcolor) 0%,
      var(--fgcolor) var(--progress),
      transparent var(--progress)
    );
  }

  & #day-progress {
    position: relative;
    display: flex;
    width: 80%;
    height: var(--progress-bar-height);
    margin: var(--progress-bar-height) auto 1em auto;
    border: 2px solid var(--fgcolor);
    border-radius: calc(var(--progress-bar-height) / 2);
    transition: opacity 0.3s linear;
    overflow: hidden;

    &:before {
      content: "";
      display: block;
      position: absolute;
      bottom: 0px;
      height: calc(calc(var(--progress-bar-height) / 2) - 2px);
      z-index: 1;
      width: var(--progress);
      background-color: var(--fgcolor);
    }

    & > div {
      opacity: 0.5;
    }
  }
}

section.buttons {
  z-index: 1;
  display: flex;
  flex-direction: row;
  column-gap: 0.5em;
  position: fixed;
  width: auto;
  height: auto;
  top: 2em;
  right: 2em;
  font-size: 1vmax;

  button {
    color: rgba(255, 255, 255, 0.6);
    border: none;
    border-radius: 5px;
    padding: 0.5em 0.8em;
    font-size: 1em;
    cursor: pointer;

    padding-left: 2.3em;
    background-size: 1em 1em;
    background-repeat: no-repeat;
    background-position: 0.8em center;

    background-color: rgba(0, 0, 0, 0.2);
    &:hover {
      background-color: rgba(0, 0, 0, 0.1);
    }

    &.full-screen {
      background-image: url("full-screen.svg");
    }
    &.schedule {
      background-image: url("settings.svg");
    }
  }
}

body {
  cursor: none;
  transition: background-color 1s linear, color 1s ease-in-out,
    transform 30s linear;

  & .current,
  & .next-up,
  & .buttons {
    opacity: 0;
    transition: opacity 0.3s linear;
  }

  &.mousefocus {
    cursor: auto;

    & .current,
    & .buttons {
      opacity: 1;
    }
  }

  &.coming-up {
    & #progress,
    & .next-up {
      opacity: 1;
      transition-duration: 10s;
    }
  }

  &.animate {
    & main {
      animation: dip-to-black 2s linear;
    }

    & .clock {
      animation: wiggle 1s 2 linear;
    }
  }
}

@keyframes wiggle {
  0%,
  17.5% {
    transform: rotateZ(0);
  }
  37.5% {
    transform: rotateZ(-15deg);
  }
  50% {
    transform: rotateZ(10deg);
  }
  62.5% {
    transform: rotateZ(-10deg);
  }
  75% {
    transform: rotateZ(6deg);
  }
  87.5% {
    transform: rotateZ(-4deg);
  }
  100% {
    transform: rotateZ(0);
  }
}

@keyframes dip-to-black {
  0% {
    background-color: rgba(0, 0, 0, 0);
  }
  50% {
    background-color: rgba(0, 0, 0, 1);
  }
  100% {
    background-color: rgba(0, 0, 0, 0);
  }
}

/* Settings modal styling */

dialog#settings {
  width: 70vw;
  max-width: 800px;
  height: 50vh;
  top: 50%;
  margin: -25vh auto auto auto;

  z-index: 1;
  padding: 0.5em;
  overflow-y: auto;
  cursor: auto;
  border-radius: 20px;
  border: 2px solid rgba(0, 0, 0, 0.9);
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.3);
  font-size: 16px;

  @media (max-width: 768px) {
    width: 100vw;
    height: 100%;
    top: 0px;
    bottom: 0px;
    margin: 0px;
    font-size: 14px;
    border-radius: 0px;
  }

  animation: fade-out 0.3s ease-out;
  &[open] {
    animation: fade-in 0.3s ease-out;
  }
  &::backdrop {
    animation: background-out 0.3s ease-out;
  }
  &[open]::backdrop {
    animation: background-in 0.3s ease-out forwards;
  }

  color: white;

  & h1 {
    font-size: 3em;
    margin: 1em;
  }

  & ul {
    list-style: none;
    padding: 0;
    margin: 0 3em;

    @media (max-width: 768px) {
      margin: 0 1em;
    }

    & li {
      padding: 0;
      margin: 1em;

      display: flex;
      flex-direction: row;
      justify-content: center;
      gap: 0.5em;
    }
  }

  input,
  button {
    font-family: Tahoma, Arial, sans-serif;
  }

  input {
    flex: 0 0 auto;
    height: 2em;
    padding: 0.6em 0.8em;
    vertical-align: middle;
    font-size: 1em;
    background-color: rgba(255, 255, 255, 0.9);
    border: 0;
    border-radius: 5px;

    &[type="color"] {
      width: 2em;
      border-radius: 50%;
      overflow: hidden;
      padding: 0;
      &::-webkit-color-swatch,
      &::-webkit-color-swatch-wrapper {
        width: 100%;
        height: 100%;
        padding: 0;
        border: none;
      }
    }

    &[type="text"] {
      flex: 1 1 auto;
      width: 0px;
    }
  }

  button {
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 0.5em 0.8em;
    font-size: 1em;
    cursor: pointer;

    &:hover {
      background-color: rgba(0, 0, 0, 0.6);
    }

    &[type="submit"] {
      margin: 2em 0;
      background-color: rgba(28, 107, 16, 0.9);

      &:hover {
        background-color: rgba(28, 107, 16, 0.8);
      }
    }

    &.add:before {
      content: "+ ";
    }

    &.remove {
      border-radius: 50%;
    }
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
    transform: scale(0.6);
    display: none;
  }
  100% {
    opacity: 1;
    transform: scale(1);
    display: block;
  }
}

@keyframes fade-out {
  0% {
    opacity: 1;
    transform: scale(1);
    display: block;
  }
  100% {
    opacity: 0;
    transform: scale(0.6);
    display: none;
  }
}

@keyframes background-in {
  0% {
    background: rgba(0, 0, 0, 0);
  }
  100% {
    background: rgba(0, 0, 0, 0.3);
  }
}

@keyframes background-out {
  0% {
    background: rgba(0, 0, 0, 0.3);
  }
  100% {
    background: rgba(0, 0, 0, 0);
  }
}
