@layer layout, components, utilities;

:root {
  --color-primary: light-dark(hsl(176, 96%, 23%), hsl(176, 96%, 69%));
  --color-secondary: light-dark(hsl(213, 24%, 84%), hsl(213, 24%, 16%));
  --color-secondary-accent: light-dark(hsl(213, 24%, 16%), hsl(213, 24%, 84%));
  --color-accent: hsl(43, 86%, 50%);
  --color-text: light-dark(hsl(210, 2%, 22%), hsl(210, 2%, 78%));
  --color-background: light-dark(hsl(228, 20%, 95%), hsl(228, 20%, 8%));
  --color-background-accent: light-dark(hsl(218, 22%, 91%), hsl(218, 22%, 14%));
  --color-danger: light-dark(hsl(0, 100%, 50%), hsl(0, 100%, 27%));
  --color-success: light-dark(hsl(120, 100%, 27%), hsl(120, 100%, 40%));

  --color-dialog-primary: light-dark(hsl(176, 96%, 31%), hsl(43, 86%, 50%));
  --color-dialog-background: light-dark(hsl(228, 20%, 95%), hsl(213, 24%, 16%));
  --color-dialog-backdrop: light-dark(hsl(210, 2%, 22%), hsl(228, 20%, 8%));

  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --default-line-height: 1.5;

  --screen-sm: 576px;
  --screen-md: 768px;
  --screen-lg: 992px;
  --screen-xl: 1200px;

  &:has([data-theme="dark" i]) {
    color-scheme: dark;
  }

  &:has([data-theme="light" i]) {
    color-scheme: light;
  }
}

#app[data-theme] {
  transition: background 750ms ease-in-out;
  background: var(--color-background);
}

html {
  color-scheme: dark light;
}

body {
  font-family: 'Montserrat', system-ui;
  font-size: var(--font-size-md);
  line-height: var(--default-line-height);
  background-color: var(--color-background);
  color: var(--color-primary);
}

@layer layout {
  #app {
    --header-height: 66px;
    display: grid;
    min-height: 100svh;
    grid-template-columns: auto minmax(auto, 512px) auto;
    grid-template-rows: var(--header-height) 1fr auto;
    grid-template-areas:
      ". header ."
      ". main ."
      ". footer .";

    & > header {
      grid-area: header;
    }

    & > main {
      grid-area: main;
    }

    & > footer {
      grid-area: footer;
      place-self: center;
    }

    @media only screen and (max-width: 768px) {
      grid-template-areas:
        "header header header"
        ". main ."
        ". footer .";
    }
  }
}

@layer components {
  .link {
    cursor: pointer;
    position: relative;
    text-decoration: none;
    color: var(--color-primary);

    i + span {
      margin-inline-start: 4px;
    }

    &:after {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 2px;
      background: currentColor;
      transform: scaleX(0);
      transform-origin: right;
      transition: transform 250ms ease-in;
    }

    &:hover::after {
      transform: scaleX(1);
      transform-origin: left;
    }
  }

  :is(a, .link):focus-visible {
    outline: 1px solid var(--color-accent);
    outline-offset: 0.25rem;
  }

  input, button, .btn-link {
    color: var(--color-text);
    background: var(--color-secondary);
    padding: 0.5em 0.75em;
    border: none;
    border-radius: 8px;
  }

  input {
    font-weight: bold;

    &:focus-visible {
      outline: 2px solid var(--color-accent);
    }

    &::placeholder {
      font-style: italic;
      font-weight: normal;
      color: var(--color-secondary-accent);
    }
  }

  button, .btn-link {
    cursor: pointer;
    border: 1px solid var(--color-text);
    transition: background 250ms;
    outline: none;
    text-decoration: none;

    &:disabled {
      opacity: 0.5;
      cursor: unset;
    }

    &:hover:not([disabled]), &:focus-visible:not([disabled]) {
      background: var(--color-secondary-accent);
      color: var(--color-secondary)
    }
  }

  select {
    color: var(--color-text);
    padding: 0.5em 0.75em;

    &:focus-visible {
      outline: 2px solid var(--color-accent);
    }
  }

  .spinner {
    display: inline-block;
    width: 48px;
    height: 48px;
    border: 5px solid var(--color-accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: rotation 1s linear infinite;
  }

  @keyframes rotation {
    to {
      transform: rotate(1turn);
    }
  }

  dialog.modal {
    --width: 950px;
    --animation-speed: 700ms;
    width: var(--width);
    height: calc((var(--width) * 9) / 16);
    border: 1px solid var(--color-dialog-primary);
    border-radius: 8px;
    margin-block-start: 6em;
    padding: 12px 16px;
    z-index: 2;
    outline: none;
    opacity: 0;
    translate: 0 25vh;
    transition: all var(--animation-speed) allow-discrete;

    .close {
      display: flex;
      font-size: 1.75rem;
      cursor: pointer;

      &:focus-visible {
        outline: 1px solid var(--color-dialog-primary);
      }

      &:hover {
        color: var(--color-dialog-primary);
      }
    }

    &::backdrop {
      opacity: 0;
      background: var(--color-dialog-backdrop);
      transition: all var(--animation-speed) allow-discrete;
    }

    &[open] {
      opacity: 1;
      translate: 0 0;

      &::backdrop {
        opacity: .75;
      }

      @starting-style {
        opacity: 0;
        translate: 0 -25vh;

        &::backdrop {
          opacity: 0;
        }
      }
    }
  }
}

@layer changelog {
  .version {
    margin-block-start: 0.5em;
    margin-block-end: 1.5em;
  }

  .section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-block: 0.5em;
    padding-inline-start: 1.5em;
  }
}

@layer game {
  .game {
    --max-game-width: 320px;

    display: grid;
    gap: 2em;
    padding-block: 1.5rem;
    min-width: var(--max-game-width);
    justify-content: center;
    grid-template-rows: auto 1fr;
    grid-template-areas: "picture" "content" "actions";

    & > :is(picture, .placeholder) {
      grid-area: picture;
      width: var(--max-game-width);
      aspect-ratio: 2 / 1;
      cursor: zoom-in;

      img {
        border: 1px solid var(--color-text);
      }
    }

    & > .placeholder {
      background: var(--color-secondary-accent);
      cursor: wait;
      animation: placeholder-glow 2.5s ease-in-out infinite;
    }

    & > .content {
      grid-area: content;
      display: flex;
      justify-content: center;
    }

    & > .actions {
      grid-area: actions;
      display: flex;
      width: var(--max-game-width);
      justify-content: space-between;
      align-items: center;
    }
  }
}

@layer difficulties {
  .blur-6 {
    filter: blur(0);
  }

  .blur-5 {
    filter: blur(5px);
  }

  .blur-4 {
    filter: blur(10px);
  }

  .blur-3 {
    filter: blur(15px);
  }

  .blur-2 {
    filter: blur(20px);
  }

  .blur-1 {
    filter: blur(25px);
  }

  .blur-0 {
    filter: blur(30px);
  }

  .grayscale {
    filter: grayscale(1);
  }

  .invert {
    filter: invert(1);
  }

  .shift {
    filter: hue-rotate(90deg);
  }
}

@keyframes placeholder-glow {
  0% {
    opacity: 0.5;
  }

  50% {
    opacity: 0.2;
  }

  100% {
    opacity: 0.5;
  }
}
