@layer reset, base, components, utilities;

@layer reset {
  html {
    box-sizing: border-box;
    color-scheme: light dark;
  }

  :where(html, body, header, main, footer, section, article, figure, div, button, select) {
    box-sizing: border-box;
  }

  body,
  h1,
  p,
  figure,
  blockquote {
    margin: 0;
  }
}

:root {
  --bg-page: light-dark(#fff8ef, #14131a);
  --bg-card: light-dark(#ffffff, #1e1c26);
  --bg-subtle: light-dark(#fef1dc, #292635);
  --text-main: light-dark(#1e1b24, #f5f3fa);
  --text-muted: light-dark(#5c5569, #b3acc4);
  --border-color: light-dark(#e6d7c3, #3a364a);

  --accent-primary: light-dark(#ff5a36, #ff6d4d);
  --accent-primary-hover: light-dark(#e64825, #ff8468);
  --accent-primary-text: #ffffff;

  --accent-secondary: light-dark(#2b59ff, #5c82ff);
  --accent-secondary-hover: light-dark(#1e46d6, #7898ff);
  --accent-secondary-text: #ffffff;

  --focus-ring: light-dark(#111111, #ffd166);
  --shadow-card: light-dark(
    0 12px 32px -8px rgba(45, 28, 12, 0.12),
    0 12px 32px -8px rgba(0, 0, 0, 0.45)
  );

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

@layer base {
  body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    min-block-size: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    line-height: 1.55;
  }

  :where(button, select, a):focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px;
  }
}

@layer components {
  .site-header {
    padding-block: 1.5rem 1rem;
    padding-inline: 1.25rem;
    display: flex;
    justify-content: center;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    max-inline-size: 46rem;
    inline-size: 100%;

    & h1 {
      font-size: clamp(1.6rem, 3vw, 2.2rem);
      font-weight: 800;
      letter-spacing: -0.02em;
      line-height: 1.15;
    }
  }

  .brand-badge {
    display: grid;
    place-items: center;
    inline-size: 3.1rem;
    block-size: 3.1rem;
    border-radius: var(--radius-md);
    background-color: var(--bg-subtle);
    border: 2px solid var(--border-color);
    font-size: 1.65rem;
    flex-shrink: 0;
  }

  .tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
  }

  .app-shell {
    inline-size: 100%;
    max-inline-size: 46rem;
    margin-inline: auto;
    padding-block: 0.5rem 2.5rem;
    padding-inline: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .controls-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
  }

  .select-label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-muted);
  }

  .category-select {
    min-block-size: 2.6rem;
    padding-block: 0.4rem;
    padding-inline: 0.85rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-main);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
  }

  .joke-card {
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: clamp(1.25rem, 3vw, 2rem);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .joke-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
  }

  .joke-badge {
    display: inline-flex;
    align-items: center;
    padding-block: 0.25rem;
    padding-inline: 0.75rem;
    border-radius: var(--radius-pill);
    background-color: var(--bg-subtle);
    color: var(--text-main);
    font-weight: 700;
    border: 1px solid var(--border-color);
  }

  .joke-counter {
    color: var(--text-muted);
    font-weight: 500;
  }

  .joke-output {
    min-block-size: 6.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.65rem;
    font-size: clamp(1.1rem, 2.2vw, 1.3rem);
    line-height: 1.55;
  }

  .joke-placeholder {
    color: var(--text-muted);
    font-size: 1.05rem;
  }

  .joke-setup {
    font-weight: 600;
  }

  .joke-punchline {
    font-weight: 500;
    color: var(--text-main);
  }

  .actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-block-start: 0.25rem;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-block-size: 3rem;
    min-inline-size: 3rem;
    padding-block: 0.65rem;
    padding-inline: 1.25rem;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 120ms ease, background-color 150ms ease, opacity 150ms ease;

    &:active:not(:disabled) {
      transform: translateY(1px);
    }

    &:disabled {
      opacity: 0.48;
      cursor: not-allowed;
    }
  }

  .btn-primary {
    background-color: var(--accent-primary);
    color: var(--accent-primary-text);

    &:hover:not(:disabled) {
      background-color: var(--accent-primary-hover);
    }
  }

  .btn-secondary {
    background-color: var(--accent-secondary);
    color: var(--accent-secondary-text);

    &:hover:not(:disabled) {
      background-color: var(--accent-secondary-hover);
    }
  }

  .btn-ghost {
    background-color: transparent;
    color: var(--text-main);
    border-color: var(--border-color);

    &:hover:not(:disabled) {
      background-color: var(--bg-subtle);
    }
  }

  .status-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-block-size: 1.2em;
  }

  .image-stage {
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: clamp(1rem, 2.5vw, 1.5rem);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    animation: pop-in 220ms ease-out;
  }

  .image-stage[hidden] {
    display: none;
  }

  .illustration-container {
    inline-size: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: var(--bg-subtle);

    & svg {
      display: block;
      inline-size: 100%;
      block-size: auto;
      aspect-ratio: 16 / 9;
    }
  }

  .illustration-caption {
    text-align: center;
    font-size: 0.92rem;
    color: var(--text-muted);
    font-style: italic;
  }

  .site-footer {
    text-align: center;
    padding-block: 1rem 1.5rem;
    padding-inline: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .image-stage {
    animation: none;
    transition: none;
  }
}
