@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; }
  img, svg { display: block; max-width: 100%; }
  input { font: inherit; color: inherit; }
  fieldset { border: none; margin: 0; padding: 0; }
  legend { padding: 0; }
}

@layer tokens {
  :root {
    --ref-color-teal-50: oklch(97% 0.02 200);
    --ref-color-teal-500: oklch(58% 0.1 200);
    --ref-color-teal-700: oklch(42% 0.09 200);
    --ref-color-neutral-0: oklch(100% 0 0);
    --ref-color-neutral-50: oklch(98% 0.003 250);
    --ref-color-neutral-200: oklch(90% 0.005 250);
    --ref-color-neutral-500: oklch(58% 0.01 250);
    --ref-color-neutral-700: oklch(38% 0.01 250);
    --ref-color-neutral-900: oklch(18% 0.01 250);
    --ref-color-amber-100: oklch(93% 0.06 80);
    --ref-color-amber-700: oklch(45% 0.12 60);
    --ref-space-1: 0.25rem;
    --ref-space-2: 0.5rem;
    --ref-space-3: 0.75rem;
    --ref-space-4: 1rem;
    --ref-space-6: 1.5rem;
    --ref-space-8: 2rem;
    --ref-space-12: 3rem;
    --ref-radius-md: 10px;
    --ref-radius-lg: 16px;

    --color-bg: var(--ref-color-neutral-50);
    --color-surface: var(--ref-color-neutral-0);
    --color-fg: var(--ref-color-neutral-900);
    --color-muted: var(--ref-color-neutral-500);
    --color-line: var(--ref-color-neutral-200);
    --color-brand: var(--ref-color-teal-500);
    --color-brand-strong: var(--ref-color-teal-700);
    --color-warn-bg: var(--ref-color-amber-100);
    --color-warn-fg: var(--ref-color-amber-700);
    --radius-card: var(--ref-radius-lg);
    --radius-chip: 999px;

    --kind-rau: oklch(62% 0.12 220);
    --kind-lac: oklch(58% 0.13 250);
    --kind-cascada: oklch(60% 0.11 190);
    --kind-strand: oklch(68% 0.13 50);
    --kind-altele: oklch(60% 0.06 140);
    --kind-not-for-swimming: oklch(55% 0.02 30);
  }

  :root[data-theme="dark"] {
    --color-bg: oklch(16% 0.01 250);
    --color-surface: oklch(21% 0.01 250);
    --color-fg: oklch(95% 0.005 250);
    --color-muted: oklch(70% 0.01 250);
    --color-line: oklch(30% 0.01 250);
    --color-warn-bg: oklch(30% 0.06 60);
    --color-warn-fg: oklch(88% 0.08 80);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --color-bg: oklch(16% 0.01 250);
      --color-surface: oklch(21% 0.01 250);
      --color-fg: oklch(95% 0.005 250);
      --color-muted: oklch(70% 0.01 250);
      --color-line: oklch(30% 0.01 250);
      --color-warn-bg: oklch(30% 0.06 60);
      --color-warn-fg: oklch(88% 0.08 80);
    }
  }
}

@layer base {
  html {
    font-family: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
    background: var(--color-bg);
    color: var(--color-fg);
    line-height: 1.5;
  }

  body {
    min-height: 100dvh;
  }

  h1, h2 {
    line-height: 1.2;
    margin: 0;
  }

  p {
    margin: 0;
  }

  a {
    color: var(--color-brand-strong);
  }

  :focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
  }
}

@layer layout {
  .lb-skip {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--color-surface);
    color: var(--color-fg);
    padding: var(--ref-space-2) var(--ref-space-4);
    z-index: 10;
  }

  .lb-skip:focus {
    left: var(--ref-space-4);
    top: var(--ref-space-4);
  }

  .lb-header {
    padding-block: var(--ref-space-8) var(--ref-space-6);
    background: linear-gradient(180deg, var(--ref-color-teal-50), var(--color-bg));
  }

  :root[data-theme="dark"] .lb-header {
    background: linear-gradient(180deg, oklch(24% 0.03 200), var(--color-bg));
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .lb-header {
      background: linear-gradient(180deg, oklch(24% 0.03 200), var(--color-bg));
    }
  }

  .lb-header__inner {
    max-width: 90rem;
    margin-inline: auto;
    padding-inline: var(--ref-space-4);
  }

  .lb-header__title {
    font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .lb-header__subtitle {
    margin-top: var(--ref-space-2);
    color: var(--color-muted);
    max-width: 60ch;
  }

  .lb-shell {
    max-width: 90rem;
    margin-inline: auto;
    padding-inline: var(--ref-space-4);
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: var(--ref-space-8);
    align-items: start;
  }

  .lb-sidebar {
    position: sticky;
    top: var(--ref-space-4);
    display: flex;
    flex-direction: column;
    gap: var(--ref-space-6);
    padding: var(--ref-space-6);
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-card);
    margin-block-start: var(--ref-space-8);
  }

  .lb-main {
    padding-block: var(--ref-space-8) var(--ref-space-12);
    min-width: 0;
  }

  .lb-footer {
    border-top: 1px solid var(--color-line);
    padding: var(--ref-space-6) var(--ref-space-4) var(--ref-space-12);
  }

  .lb-footer__text {
    max-width: 90rem;
    margin-inline: auto;
    color: var(--color-muted);
    font-size: 0.8125rem;
    max-width: 65ch;
  }

  .lb-grid {
    list-style: none;
    margin: var(--ref-space-6) 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--ref-space-4);
  }

  @media (max-width: 1024px) {
    .lb-shell {
      grid-template-columns: 1fr;
    }
    .lb-sidebar {
      position: static;
    }
    .lb-grid {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  @media (max-width: 640px) {
    .lb-grid {
      grid-template-columns: 1fr;
    }
  }
}

@layer components {
  .lb-search {
    display: flex;
    flex-direction: column;
    gap: var(--ref-space-1);
  }

  .lb-search__label {
    font-size: 0.875rem;
    color: var(--color-muted);
  }

  .lb-search__input {
    padding: var(--ref-space-3) var(--ref-space-4);
    border: 1px solid var(--color-line);
    border-radius: var(--ref-radius-md);
    background: var(--color-bg);
    min-height: 44px;
    width: 100%;
  }

  .lb-filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--ref-space-2);
  }

  .lb-filter-group__title {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    margin-bottom: var(--ref-space-1);
  }

  .lb-radio,
  .lb-check {
    display: flex;
    align-items: center;
    gap: var(--ref-space-2);
    font-size: 0.9375rem;
    min-height: 28px;
    cursor: pointer;
  }

  .lb-radio input,
  .lb-check input {
    accent-color: var(--color-brand);
    width: 18px;
    height: 18px;
  }

  .lb-reset {
    align-self: flex-start;
    padding: var(--ref-space-2) var(--ref-space-4);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-chip);
    background: transparent;
    color: var(--color-brand-strong);
    cursor: pointer;
    font-size: 0.875rem;
    min-height: 40px;
  }

  .lb-count {
    color: var(--color-muted);
    font-size: 0.875rem;
  }

  .lb-card {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .lb-card__hide {
    position: absolute;
    top: var(--ref-space-2);
    right: var(--ref-space-2);
    z-index: 1;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 999px;
    background: oklch(20% 0 0 / 55%);
    color: var(--ref-color-neutral-0);
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1;
  }

  .lb-card__hide:hover {
    background: oklch(20% 0 0 / 80%);
  }

  .lb-card[data-confidence="low"] {
    border-style: dashed;
  }

  .lb-card[data-category="not-for-swimming"] {
    opacity: 0.85;
  }

  .lb-card__visual {
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, color-mix(in oklch, var(--kind-color) 85%, transparent), color-mix(in oklch, var(--kind-color) 55%, transparent));
  }

  .lb-card[data-kind="rau"] { --kind-color: var(--kind-rau); }
  .lb-card[data-kind="lac"] { --kind-color: var(--kind-lac); }
  .lb-card[data-kind="cascada"] { --kind-color: var(--kind-cascada); }
  .lb-card[data-kind="strand"] { --kind-color: var(--kind-strand); }
  .lb-card[data-kind="altele"] { --kind-color: var(--kind-altele); }
  .lb-card[data-kind="not-for-swimming"] { --kind-color: var(--kind-not-for-swimming); }

  .lb-card__icon {
    width: 40px;
    height: 40px;
    color: var(--ref-color-neutral-0);
  }

  .lb-card__photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .lb-card:has(.lb-card__photo) .lb-card__visual {
    padding: 0;
    height: 160px;
  }

  .lb-card__photo-credit {
    font-size: 0.6875rem;
    color: var(--color-muted);
    padding: var(--ref-space-1) var(--ref-space-6) 0;
  }

  .lb-card__photo-credit a {
    color: inherit;
  }

  .lb-card__body {
    padding: var(--ref-space-6);
    display: flex;
    flex-direction: column;
    gap: var(--ref-space-2);
    flex: 1;
  }

  .lb-card__top {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: var(--ref-space-2);
  }

  .lb-card__title {
    font-size: 1.0625rem;
    font-weight: 600;
  }

  .lb-card__type {
    font-size: 0.75rem;
    color: var(--color-brand-strong);
    white-space: nowrap;
  }

  .lb-card__area {
    color: var(--color-muted);
    font-size: 0.875rem;
  }

  .lb-card__rating {
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
  }

  .lb-card__note {
    font-size: 0.9375rem;
  }

  .lb-card__safety {
    background: var(--color-warn-bg);
    color: var(--color-warn-fg);
    padding: var(--ref-space-2) var(--ref-space-3);
    border-radius: var(--ref-radius-md);
    font-size: 0.875rem;
  }

  .lb-card__links {
    display: flex;
    gap: var(--ref-space-4);
    margin-top: auto;
    padding-top: var(--ref-space-2);
  }

  .lb-card__link {
    font-size: 0.8125rem;
    color: var(--color-brand-strong);
    text-decoration: none;
  }

  .lb-card__link:hover {
    text-decoration: underline;
  }

  .lb-card__link--button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
  }

  .lb-hidden-count {
    font-size: 0.8125rem;
    color: var(--color-muted);
  }

  .lb-modal {
    border: none;
    border-radius: var(--radius-card);
    padding: 0;
    width: min(90vw, 640px);
    background: var(--color-surface);
    color: var(--color-fg);
  }

  .lb-modal::backdrop {
    background: oklch(0% 0 0 / 55%);
  }

  .lb-modal__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--ref-space-4) var(--ref-space-6);
    border-bottom: 1px solid var(--color-line);
  }

  .lb-modal__title {
    font-size: 1.0625rem;
    font-weight: 600;
  }

  .lb-modal__close {
    border: none;
    background: transparent;
    color: var(--color-fg);
    cursor: pointer;
    font-size: 1.125rem;
    width: 32px;
    height: 32px;
  }

  .lb-modal__body {
    aspect-ratio: 4 / 3;
  }

  .lb-modal__body iframe {
    width: 100%;
    height: 100%;
    border: none;
  }

  .lb-empty {
    margin-top: var(--ref-space-8);
    color: var(--color-muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
