@layer base, demo, utilities;

@layer demo {
  [popover] {
    transition: display, overlay, translate 150ms ease;
    transition-behavior: allow-discrete;
    translate: 100% 0;
  }

  [popover]:popover-open {
    display: flex;
    translate: 0 0;
    backdrop-filter: blur(1px);

    @starting-style {
      translate: 100% 0;
    }
  }

  [popover] {
    position: fixed;
    width: min(100%, 25rem);
    height: min(100dvh, 37rem);
    left: unset;
    top: unset;
    right: 0;
    bottom: 0;
    background: hsl(0 0% 8% / 0.95);
    scrollbar-color: hsl(0, 0%, 10%) transparent;
    padding: 1rem;
    gap: 1rem;
    flex-direction: column;
    border-radius: 0.5rem 0 0 0.5rem;
    overflow-y: scroll !important;
    @media (width <= 30rem) {
      width: 100%;
      border-radius: 0.5rem 0.5rem 0 0;
      height: min(100dvh, 45rem);
      background: hsl(0 0% 8% / 0.75);
      backdrop-filter: blur(0) !important;
    }
  }

  aside {
    --color-primary: #e2e2e2;
    --color-secondary: hsl(0, 0%, 55%);
    --color-accent: hsl(45, 90%, 45%);

    & h2 {
      font-size: 1.5rem;
      margin-bottom: 1rem;
      text-align: center;
      color: var(--color-primary);
    }

    & fieldset {
      border: 1px solid color-mix(in oklab, var(--color-primary), transparent 70%);
      padding: 1rem;
      display: flex;
      flex-direction: column;
      gap: 0.5rem;

      & legend {
        font-size: 1rem;
        font-weight: bold;
        color: var(--color-primary);
      }
    }
    
    & label {
      font-size: 0.9rem;
      color: var(--color-primary);
      transition: color 150ms ease;
      &:has(+ input:user-invalid) { color: red; }
    }

    & input:where([type="number"], [type="range"], [type="color"], [type="text"]), select {
      padding: 0.3rem;
      font-size: 0.9rem;
      border: 1px solid var(--color-secondary);
      border-radius: 4px;
      background: transparent;
      > * { background: canvas; }
    }

    & button {
      padding: 0.5rem;
      font-size: 0.9rem;
      color: #111;
      background-color: var(--color-accent);
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.3s;
      &:hover {
        background-color: color-mix(in oklab, var(--color-accent), #693402 70%);
        color: #e1e1e1;
      }
    }

    & p {
      font-size: 0.9rem;
      color: var(--color-primary);
      text-align: left;
    }

    & span {
      font-weight: bold;
    }

    & input[type="range"] + span {
      display: inline-block;
      width: 100%;
      text-align: right;
      margin-top: -0.75rem;
      margin-bottom: 0.5rem;
    }
  }
}

@layer utilities {
  .button-menu {
    display: grid;
    place-items: center;
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    aspect-ratio: 1;
    cursor: pointer;
    z-index: 10;
    background: transparent;
    border-radius: 0.5rem;
    transition: background 150ms ease;
    animation: highlight 0.6s ease both;
    color: #fff;
      mix-blend-mode: difference;
    &:is(:hover, :focus) {
      background: oklch(0.97 0 0 / 0.15);
    }
    svg {
      width: 1.5rem;
      height: 1.5rem;
    }
  }

  .button-generate {
    width: 100%;
    height: 2rem;
    border-radius: 0.25rem;
    background: #1c1a1c;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-weight: 600;
    color: #cacaca;
    font-size: medium;

    &:is(:hover, :focus) {
      background: linear-gradient(0deg, color-mix(in oklab, var(--color-primary), yellow 80%), var(--color-primary));
      box-shadow:
        inset 0px 1px 0px 0px rgba(255, 255, 255, 0.4),
        inset 0px -4px 0px 0px rgba(0, 0, 0, 0.2),
        0px 0px 0px 4px rgba(255, 255, 255, 0.2),
        0px 0px 190px 0px var(--color-primary);
      transform: translateY(-2px);
      color: #101010;
    }
  }

  .input {
    height: 1.25rem;
    border-radius: 0.25rem;
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
    padding-left: 0.5rem;
    margin: 0.5rem 0 1rem;
    transition: 150ms ease-in-out;
    background: transparent;
    &:focus {
      outline-offset: 5px;
      border-radius: 0.05rem;
    }
    * {
      background: canvas;
    }
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  @keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes highlight {
    from { border: 2px solid transparent; }
    25% { border: 2px solid var(--color-primary); }
    50% { border: 2px solid transparent; }
    75% { border: 2px solid var(--color-primary); }
    to { border: 2px solid transparent; }
  }
}

@layer base {
  :root {
    --color-primary: #d9a90d;
  }

  html {
    color-scheme: only dark;
  }

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

  body {
    background: #111;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    align-content: center;
    display: grid;
    align-items: center;
  }
  
  canvas {
    border: 1px solid rgb(70 70 70 / 0.5);
    border-radius: 2px;
    image-rendering: pixelated;
    margin: auto;
    animation: fade-in 0.6s ease-in both;
    animation-delay: 1000ms;
    max-width: 100%;
    margin: auto;
  }
}
