@layer reset, base, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, p, ul { margin: 0; }
  ul { padding: 0; list-style: none; }
  button, select { font: inherit; color: inherit; }
}

@layer base {
  :root {
    color-scheme: light dark;
    --bg: light-dark(#fffaf3, #17130f);
    --fg: light-dark(#2b2118, #f3e9dc);
    --muted: light-dark(#6f5f50, #b7a897);
    --card: light-dark(#fff, #221c16);
    --line: light-dark(#ead9c6, #3a3027);
    --accent: light-dark(#c2410c, #ff8a50);
    --on-accent: light-dark(#fff, #1b0f08);
    --radius: 0.75rem;
    --control-h: 3rem;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  }

  body {
    min-block-size: 100dvh;
    display: grid;
    grid-template-rows: 1fr auto;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
  }

  main {
    inline-size: min(34rem, 100% - 2rem);
    margin-inline: auto;
    padding-block: clamp(1.5rem, 8vh, 4rem) 2rem;
    display: grid;
    gap: 1.25rem;
    align-content: start;
  }

  h1 { font-size: clamp(2.25rem, 8vw, 3.25rem); line-height: 1.1; color: var(--accent); letter-spacing: -0.02em; }
  header p { color: var(--muted); margin-block-start: 0.5rem; }
  a { color: var(--accent); text-underline-offset: 0.2em; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

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

@layer components {
  .controls {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 0.25rem);
  }

  .field { display: grid; gap: 0.25rem; font-size: 0.875rem; color: var(--muted); }

  /* custom chevron: the native arrow can't be positioned or padded consistently */
  .select {
    position: relative;
    display: block;
    &::after {
      content: '';
      position: absolute;
      inset-inline-end: 1rem;
      inset-block-start: 50%;
      inline-size: 0.5rem;
      block-size: 0.5rem;
      border-inline-end: 2px solid var(--accent);
      border-block-end: 2px solid var(--accent);
      translate: 0 -75%;
      rotate: 45deg;
      pointer-events: none;
    }
  }

  select {
    appearance: none;
    inline-size: 100%;
    block-size: var(--control-h);
    padding: 0 2.5rem 0 0.9rem;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    &:hover { border-color: var(--accent); }
  }

  button {
    block-size: var(--control-h);
    padding: 0 1.25rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
    &:hover:not(:disabled) { filter: brightness(1.08); }
    &:disabled { opacity: 0.6; cursor: progress; }
  }
  .primary { background: var(--accent); color: var(--on-accent); }
  .secondary { background: transparent; color: var(--accent); border-color: var(--accent); }

  #status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--muted);
  }

  /* fixed height so "Pick another" stays put whatever the content length */
  article {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    block-size: 17rem;
    overflow: hidden;
    gap: 0.9rem;
    padding: 1.25rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 0.25rem);
    box-shadow: 0 6px 20px -12px light-dark(rgb(80 40 10 / 0.35), rgb(0 0 0 / 0.6));
  }
  h2 {
    font-size: 1.5rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }

  .chips { display: flex; gap: 0.4rem; overflow: hidden; }
  .chips li {
    padding: 0.15rem 0.7rem;
    border-radius: 999px;
    font-size: 0.85rem;
    flex-shrink: 0;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    &::first-letter { text-transform: uppercase; }
  }

  .details {
    display: grid;
    align-content: start;
    gap: 0.25rem;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.95rem;
    overflow-wrap: anywhere;
    & li {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
    }
  }
  .links { display: flex; flex-wrap: wrap; gap: 1.25rem; font-weight: 600; }

  .spinner {
    flex: none;
    inline-size: 1.25rem;
    block-size: 1.25rem;
    border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
    border-block-start-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { rotate: 360deg; } }
  @keyframes pulse { 50% { opacity: 0.35; } }

  @media (min-width: 30rem) {
    .controls { grid-template-columns: 1fr auto; align-items: end; }
  }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .spinner { animation: pulse 1.6s ease-in-out infinite; border-radius: 50%; border-color: var(--accent); }
  }
}
