/*
 * Semantic design tokens and light/dark theme resolution (WP-FE-02).
 *
 * Design System is the token authority: components read the semantic tokens
 * below and never hardcode a colour, spacing, or type value. This file is the
 * single place those tokens are given values, so re-skinning the platform is a
 * change here and nowhere else.
 *
 * THEME RESOLUTION
 * ----------------
 * Accessibility Architecture's cascade is OS preference, then platform
 * default, then explicit user preference. It is implemented entirely in CSS,
 * with no JavaScript and no flash of the wrong theme:
 *
 *   - `color-scheme: light dark` on :root makes every `light-dark()` value
 *     below resolve from the OS `prefers-color-scheme` signal. A visitor with
 *     no stored preference gets their OS theme on first paint, and the light
 *     branch is the platform default when the OS expresses nothing.
 *   - When a visitor HAS an explicit preference, the server stamps
 *     `data-theme="light|dark"` on <html> before the response is sent (see
 *     `src/theme.rs`), and the two rules at the bottom pin `color-scheme`
 *     accordingly. Same first paint, no client round-trip.
 *
 * `light-dark()` also means each token is declared exactly once. A duplicated
 * dark block (one copy in a `prefers-color-scheme` media query, another under
 * `[data-theme="dark"]`) would drift the moment someone edits one copy.
 *
 * Setting `color-scheme` rather than swapping variables has a second payoff:
 * form controls, scrollbars, and the canvas the UA paints behind the document
 * follow the theme too, which a variables-only switch cannot reach.
 *
 * Because `data-theme` is read on any element - not just :root - a container
 * can host the opposite scope (Component Catalog: "a second semantic scope
 * activated with data-theme="dark" on any container").
 *
 * COLOUR VALUES ARE PROVISIONAL
 * -----------------------------
 * Design System is the token authority and enumerates every name below; it
 * commits no hex values. The design baseline does, and that is WP-FE-08 /
 * WP-FE-09 scope. The palette here is a neutral placeholder chosen so every
 * governed contrast pair clears WCAG 2.2 AA in BOTH themes - enforced by
 * `theme_tokens_meet_wcag_aa_contrast_in_both_themes` in `src/theme.rs`, which
 * parses this file. Replacing these values is a single-file change; the test
 * will reject a replacement that breaks contrast.
 */

:root {
  /* Enables the OS-preference branch of every light-dark() pair below. */
  color-scheme: light dark;

  /* --- Surfaces ------------------------------------------------------- */
  --surface-primary: light-dark(#ffffff, #14171a);
  --surface-secondary: light-dark(#f4f5f7, #1c2024);
  --surface-sunken: light-dark(#e9ebef, #0e1113);
  --surface-elevated: light-dark(#ffffff, #22262b);
  --surface-inverse: light-dark(#1b1f24, #f2f4f6);

  /* --- Text ----------------------------------------------------------- */
  --text-primary: light-dark(#16191d, #eef1f4);
  --text-secondary: light-dark(#4a5058, #b9c1ca);
  --text-muted: light-dark(#5f6670, #99a3ae);
  /* Exempt from the contrast minimum: WCAG 2.2 1.4.3 excludes text that is
     part of an inactive control. Kept legible anyway, but not asserted. */
  --text-disabled: light-dark(#8b929c, #6a7078);
  --text-inverse: light-dark(#ffffff, #14171a);
  --text-link: light-dark(#8a4300, #ffa46b);

  /* --- Accent ---------------------------------------------------------
     The accent hue is theme-invariant; only the text/icon tone lightens on
     dark so accent text keeps its contrast there (Design System, Theme
     Support). */
  --accent: #c24a00;
  --accent-strong: light-dark(#8a4300, #ffa46b);
  --accent-soft: light-dark(#ffe8d6, #3a1d0a);
  --accent-contrast: #ffffff;

  /* --- Borders --------------------------------------------------------
     border-default is a divider/decorative rule and is deliberately not held
     to 3:1 - WCAG 1.4.11 covers boundaries needed to *identify* a control,
     which is border-strong's job. */
  --border-default: light-dark(#d8dce1, #2e343a);
  --border-strong: light-dark(#6b7480, #6d7681);
  --border-focus: light-dark(#c24a00, #ffa46b);

  /* --- State ---------------------------------------------------------- */
  --state-success: light-dark(#1a6c37, #6ed295);
  --state-success-soft: light-dark(#e3f4e8, #10281a);
  --state-warning: light-dark(#8a5300, #f0b45c);
  --state-warning-soft: light-dark(#fdf0d8, #2b2008);
  --state-error: light-dark(#b3261e, #f2837c);
  --state-error-soft: light-dark(#fdeceb, #2c1413);
  --state-info: light-dark(#14558a, #7fbdf0);
  --state-info-soft: light-dark(#e4f0fa, #0f2333);

  /* --- Ranking dimension visualisation --------------------------------
     The radar's web and axis lines are decorative scaffolding; stroke and dot
     carry the data and are held to the 3:1 graphical-object minimum. */
  --ranking-web: light-dark(#e2e6ea, #262c32);
  --ranking-axis: light-dark(#c4cad1, #39414a);
  --ranking-fill: light-dark(rgba(194, 74, 0, 0.16), rgba(255, 164, 107, 0.18));
  --ranking-stroke: light-dark(#c24a00, #ffa46b);
  --ranking-dot: light-dark(#c24a00, #ffa46b);

  /* --- Typography ----------------------------------------------------- */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --font-size-h1: 2.25rem;
  --font-size-h2: 1.75rem;
  --font-size-h3: 1.375rem;
  --font-size-h4: 1.125rem;
  --font-size-body-large: 1.125rem;
  --font-size-body-default: 1rem;
  --font-size-body-small: 0.875rem;
  --font-size-label: 0.875rem;
  --font-size-caption: 0.75rem;
  --font-size-overline: 0.6875rem;

  --line-height-heading: 1.25;
  --line-height-body: 1.55;
  --line-height-ui: 1.4;

  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-bold: 700;

  --letter-spacing-overline: 0.08em;

  /* --- Spacing -------------------------------------------------------- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* --- Elevation ------------------------------------------------------
     Shadows are tuned per theme: the light-theme recipe disappears on a dark
     canvas, so dark leans on a deeper, tighter shadow. Never the sole signal
     for interactive state (Design System). */
  --elevation-0: none;
  --elevation-1: light-dark(
    0 1px 2px rgba(16, 20, 26, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.5)
  );
  --elevation-2: light-dark(
    0 2px 8px rgba(16, 20, 26, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.6)
  );
  --elevation-3: light-dark(
    0 8px 24px rgba(16, 20, 26, 0.18),
    0 8px 24px rgba(0, 0, 0, 0.7)
  );

  /* --- Border radius --------------------------------------------------- */
  --radius-none: 0;
  --radius-small: 2px;
  --radius-default: 6px;
  --radius-large: 12px;
  --radius-full: 9999px;

  /* --- Motion ---------------------------------------------------------
     Durations are tokens, never hardcoded (Design System). */
  --duration-instant: 0ms;
  --duration-fast: 120ms;
  --duration-default: 200ms;
  --duration-slow: 320ms;
  --easing-standard: cubic-bezier(0.2, 0, 0.2, 1);

  /* --- Focus ----------------------------------------------------------
     A visible focus indicator is mandatory; suppressing it without a
     replacement is prohibited (Accessibility Guidelines). */
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;

  /* --- Interactive target sizing (WCAG 2.2 2.5.8) ----------------------
     Minimum 48x48 CSS pixels for interactive targets; buttons, menu items,
     form fields, and dialog controls must meet this minimum. */
  --min-interactive-size: 48px;

  /* --- Form field states ---------------------------------------------- */
  --form-field-border: light-dark(#c4cad1, #39414a);
  --form-field-border-focus: var(--border-focus);
  --form-field-error-text: var(--state-error);
  --form-field-error-bg: var(--state-error-soft);
}

/*
 * An explicit user preference. These override the OS branch because pinning
 * `color-scheme` re-resolves every light-dark() above for this subtree.
 *
 * The `light` rule is NOT redundant: without it, a visitor who explicitly
 * chose light while running a dark-mode OS would still be served dark.
 */
[data-theme="light"] {
  color-scheme: light;
}

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

/* ---------------------------------------------------------------------
 * Baseline element styling. Deliberately minimal: WP-FE-02 owns the token
 * system and theme resolution, not component styling. This is only enough to
 * prove the tokens resolve and to keep the WP-FE-01 layout shell legible and
 * keyboard-accessible in both themes.
 * ------------------------------------------------------------------- */

/* Shared reflow: long user text must wrap, and control padding/borders
   must fit the available column even when the user enlarges text. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

button,
input,
select,
textarea {
  max-inline-size: 100%;
  font: inherit;
}

body {
  overflow-wrap: anywhere;
  margin: 0;
  background-color: var(--surface-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-size-body-default);
  line-height: var(--line-height-body);
}

main {
  padding: var(--space-6);
}

a {
  color: var(--text-link);
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--border-focus);
  outline-offset: var(--focus-ring-offset);
}

/*
 * The skip link is the first focusable element (WP-FE-01). Off-screen until
 * focused, then visible - it must never be hidden from keyboard users.
 */
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: calc(-1 * var(--space-16));
  z-index: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-default);
  background-color: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: var(--elevation-2);
  transition: top var(--duration-fast) var(--easing-standard);
}

.skip-link:focus {
  top: var(--space-2);
}

header,
footer {
  padding: var(--space-3) var(--space-6);
  background-color: var(--surface-secondary);
  color: var(--text-secondary);
}

header {
  border-bottom: 1px solid var(--border-default);
}

footer {
  border-top: 1px solid var(--border-default);
}

nav a {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
}

/*
 * Reduced motion disables nonessential transitions (Design System). The skip
 * link still moves into view - its position IS its visibility, so removing
 * the transition is correct but removing the movement would hide it.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: var(--duration-instant) !important;
    animation-iteration-count: 1 !important;
    transition-duration: var(--duration-instant) !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================================================
 * Accessibility Utilities (WP-FE-06)
 * ======================================================================== */

/* Visually-hidden text (screen reader only) ----------------------------- */
.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;
}

/* Interactive element minimum target size (WCAG 2.2 2.5.8) --------------- */
button,
a[role="button"],
input[type="button"],
input[type="submit"],
input[type="reset"],
input[type="checkbox"],
input[type="radio"],
[role="button"],
[role="menuitem"],
[role="tab"] {
  min-width: var(--min-interactive-size);
  min-height: var(--min-interactive-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Form field base styling ------------------------------------------------ */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--form-field-border);
  border-radius: var(--radius-default);
  background-color: var(--surface-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
input[type="search"]:focus-visible,
input[type="number"]:focus-visible,
input[type="date"]:focus-visible,
input[type="time"]:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--form-field-border-focus);
  outline: none;
}

/* Form field error state ------------------------------------------------- */
input:invalid,
textarea:invalid,
select:invalid {
  border-color: var(--form-field-error-text);
  background-color: var(--form-field-error-bg);
}

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--form-field-error-text);
  background-color: var(--form-field-error-bg);
}

/* Form label styling (visible labels required by WP-FE-06) -------------- */
label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
}

/* Error and help text ---------------------------------------------------- */
.form-error,
.form-help {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--font-size-body-small);
  line-height: var(--line-height-ui);
}

.form-error {
  color: var(--form-field-error-text);
}

.form-help {
  color: var(--text-secondary);
}

/* Confirmed creator-room media remains within the wizard's content column. */
.confirmed-media-preview {
  max-inline-size: 100%;
  block-size: auto;
}

/* Modal/dialog focus styling --------------------------------------------- */
dialog {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-default);
  background-color: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: var(--elevation-3);
}

/* Menu and disclosure item focus ----------------------------------------- */
[role="menuitem"],
[role="option"],
.menu-item,
.disclosure-item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
}

[role="menuitem"]:focus-visible,
[role="option"]:focus-visible,
.menu-item:focus-visible,
.disclosure-item:focus-visible {
  background-color: var(--surface-secondary);
  outline: none;
}

/* Creator Room wizard (WP-ER-12) ----------------------------------------- */
#city-options:not([hidden]) {
  max-height: 14rem;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-default);
  background: var(--surface-elevated);
}

#city-options [role="option"] {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

#city-options [role="option"]:hover,
#city-options [aria-selected="true"] {
  background: var(--surface-secondary);
}

/* On narrow screens the step list collapses to the current step's label. */
@media (max-width: 40rem) {
  .wizard-steps li:not([aria-current="step"]) {
    display: none;
  }
}
