/* ==========================================================================
   Shared base for all three pages (landing, GeoAPP, KittyCats)
   Tokens, reset, typography, header, footer, buttons, theme toggle.
   Each page sets --accent / --accent-soft for its own colour.

   Everything lives in cascade layers. The two unlayered rules at the end
   ([hidden] and reduced motion) therefore always win - no !important needed.
   ========================================================================== */

@layer tokens, reset, base, components, page;

/* ---------- Design tokens ---------- */

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Colour system - every text pair is checked against WCAG 2.1 AA */
    --c-bg: light-dark(#f7f5f0, #14161a);
    --c-surface: light-dark(#ffffff, #1d2026);
    --c-surface-2: light-dark(#efebe3, #262a31);
    --c-border: light-dark(#ddd7cb, #343943);
    --c-border-strong: light-dark(#8b8478, #767d8a); /* >= 3:1 for form controls */
    --c-text: light-dark(#1c1b19, #ece9e3); /* 15.8:1 / 15.0:1 */
    --c-text-muted: light-dark(#5c5850, #a9a59c); /* 6.5:1 / 6.6:1 */

    --c-geo: light-dark(#0f766e, #2dd4bf);
    --c-geo-soft: light-dark(#e1f2ef, #12302d);
    --c-kitty: light-dark(#b4490c, #fb923c);
    --c-kitty-soft: light-dark(#fbe9dc, #3a2414);
    --c-kitty-deco: #da6517; /* decoration only, never text */
    --c-danger: light-dark(#b91c1c, #f87171);
    --c-danger-soft: light-dark(#fde8e8, #3b1d1f);
    --c-on-accent: light-dark(#ffffff, #14161a);

    --accent: var(--c-text);
    --accent-soft: var(--c-surface-2);

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --font-serif: ui-serif, "Iowan Old Style", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
    --font-ka: "Noto Sans Georgian", "Segoe UI", Sylfaen, "BPG Nino Mtavruli", system-ui, sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

    --step--1: clamp(0.83rem, 0.8rem + 0.15vw, 0.9rem);
    --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
    --step-1: clamp(1.2rem, 1.12rem + 0.4vw, 1.4rem);
    --step-2: clamp(1.44rem, 1.3rem + 0.7vw, 1.75rem);
    --step-3: clamp(1.73rem, 1.5rem + 1.15vw, 2.2rem);
    --step-4: clamp(2.07rem, 1.7rem + 1.9vw, 2.75rem);

    /* Spacing (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: clamp(3rem, 2rem + 4vw, 5rem);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-pill: 999px;

    --shadow-1: 0 1px 2px rgb(20 18 15 / 0.06), 0 8px 24px -12px rgb(20 18 15 / 0.18);
    --shadow-2: 0 2px 4px rgb(20 18 15 / 0.06), 0 22px 44px -18px rgb(20 18 15 / 0.3);

    --container: 72rem;
    --gutter: clamp(1rem, 0.6rem + 2vw, 2rem);
    --header-h: 4rem;

    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --dur: 180ms;
  }

  :root[data-theme="light"] {
    color-scheme: light;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
  }

  @media (min-width: 120em) {
    :root {
      --container: 80rem;
    }
  }
}

/* ---------- Reset ---------- */

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: calc(var(--header-h) + var(--space-4));
  }

  body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: 1.6;
    color: var(--c-text);
    background-color: var(--c-bg);
    -webkit-font-smoothing: antialiased;
  }

  main {
    flex: 1 0 auto;
  }

  h1,
  h2,
  h3,
  h4 {
    margin: 0;
    font-family: var(--font-serif);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.015em;
    text-wrap: balance;
    overflow-wrap: break-word;
  }

  h1 {
    font-size: var(--step-4);
  }

  h2 {
    font-size: var(--step-3);
  }

  h3 {
    font-size: var(--step-1);
  }

  p,
  ul,
  ol,
  dl,
  dd,
  figure,
  blockquote {
    margin: 0;
  }

  p {
    text-wrap: pretty;
  }

  img,
  svg,
  video {
    display: block;
    max-width: 100%;
    height: auto;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  button {
    cursor: pointer;
  }

  /* No grey flash on tap (mobile); every control has its own pressed state. */
  a,
  button,
  label,
  summary {
    -webkit-tap-highlight-color: transparent;
  }

  a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
  }

  a:hover {
    text-decoration-thickness: 2px;
  }

  :focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
  }

  /* Headings / main that receive focus from script are not controls - no ring. */
  main[tabindex="-1"]:focus,
  :is(h1, h2, h3, h4)[tabindex="-1"]:focus {
    outline: none;
  }
}

/* ---------- Base utilities ---------- */

@layer base {
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .container {
    width: min(100% - 2 * var(--gutter), var(--container));
    margin-inline: auto;
  }

  .skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    font-weight: 700;
    color: var(--c-on-accent);
    background: var(--accent);
    border-radius: var(--radius-sm);
    transform: translateY(-200%);
    transition: transform var(--dur) var(--ease);
  }

  .skip-link:focus {
    transform: none;
  }

  .eyebrow {
    font-family: var(--font-sans);
    font-size: var(--step--1);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--c-text-muted);
  }

  .lead {
    max-width: 60ch;
    font-size: var(--step-1);
    line-height: 1.55;
    color: var(--c-text-muted);
  }
}

/* ---------- Components ---------- */

@layer components {
  /* Header */

  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--c-bg) 88%, transparent);
    border-bottom: 1px solid var(--c-border);
    backdrop-filter: saturate(1.4) blur(10px);
  }

  .site-header__inner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--header-h);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    margin-right: auto;
    font-weight: 700;
    color: var(--c-text);
    text-decoration: none;
  }

  .brand__mark {
    flex: none;
    width: 32px;
    height: 32px;
  }

  .brand__mark-bg {
    fill: var(--c-text);
  }

  .brand__mark-a {
    fill: var(--c-geo);
  }

  .brand__mark-b {
    fill: var(--c-kitty);
    fill-opacity: 0.9;
  }

  .brand__name {
    white-space: nowrap;
  }

  .brand__name--long {
    display: none;
  }

  @media (min-width: 40em) {
    .brand__name--short {
      display: none;
    }

    .brand__name--long {
      display: inline;
    }
  }

  .site-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    padding: 0;
    list-style: none;
  }

  .site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding-inline: var(--space-3);
    font-size: var(--step--1);
    font-weight: 600;
    color: var(--c-text-muted);
    text-decoration: none;
    border-radius: var(--radius-pill);
    transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
  }

  .site-nav a:hover,
  .site-nav a[aria-current] {
    color: var(--c-text);
    background: var(--c-surface-2);
  }

  /* Theme toggle */

  .theme-toggle {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-pill);
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
  }

  .theme-toggle:hover {
    background: var(--c-surface-2);
    border-color: var(--c-border-strong);
  }

  .theme-toggle svg {
    width: 20px;
    height: 20px;
  }

  .theme-toggle .icon-sun,
  .theme-toggle[aria-pressed="true"] .icon-moon {
    display: none;
  }

  .theme-toggle[aria-pressed="true"] .icon-sun {
    display: block;
  }

  /* Buttons */

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 48px;
    padding: var(--space-3) var(--space-5);
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    border: 2px solid transparent;
    border-radius: var(--radius-pill);
    transition:
      background-color var(--dur) var(--ease),
      border-color var(--dur) var(--ease),
      color var(--dur) var(--ease),
      transform var(--dur) var(--ease),
      box-shadow var(--dur) var(--ease);
  }

  .btn--primary {
    color: var(--c-on-accent);
    background: var(--accent);
    box-shadow: var(--shadow-1);
  }

  .btn--primary:hover {
    background: color-mix(in srgb, var(--accent) 85%, var(--c-text));
    transform: translateY(-1px);
  }

  .btn--outline {
    color: var(--c-text);
    background: var(--c-surface);
    border-color: var(--c-border-strong);
  }

  .btn--outline:hover {
    background: var(--c-surface-2);
    border-color: var(--c-text);
  }

  .btn--quiet {
    min-height: 44px;
    padding-inline: var(--space-3);
    font-weight: 600;
    color: var(--c-text-muted);
    background: transparent;
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .btn--quiet:hover {
    color: var(--c-text);
  }

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

  .btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
  }

  .btn svg {
    width: 1.1em;
    height: 1.1em;
    flex: none;
  }

  /* Footer */

  .site-footer {
    margin-top: var(--space-8);
    padding-block: var(--space-6);
    font-size: var(--step--1);
    color: var(--c-text-muted);
    background: var(--c-surface);
    border-top: 1px solid var(--c-border);
  }

  .site-footer__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
  }

  .site-footer__who {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .site-footer__name {
    font-size: var(--step-0);
    font-weight: 700;
    color: var(--c-text);
  }

  .site-footer__links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    margin-left: calc(-1 * var(--space-2));
    padding: 0;
    list-style: none;
  }

  .site-footer__links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding-inline: var(--space-2);
    font-weight: 600;
    color: var(--c-text);
  }
}

/* ---------- Unlayered: these must beat every layer ---------- */

[hidden] {
  display: none;
}

/* Touch screens keep :hover after a tap - no "lifted" cards stuck in the air. */
@media (hover: none) {
  .btn:hover,
  .project:hover,
  .cat-card:hover,
  .option:hover {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    transition-duration: 0.01ms;
    scroll-behavior: auto;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}
