/*
 * Zip Weather — design tokens and layout. Spec §3.6.
 *
 * Workspace rule: colours come from tokens, never hard-coded, and blue is never
 * a brand colour. A blue sky gradient is the lazy default for a weather app, so
 * the palette here is deliberately warm and grounded instead — sand paper,
 * warm ink, terracotta. It reads like a printed almanac page, which is the right
 * register for a small tool you check and close.
 *
 * Every rule below the token block references a token. The only colour literals
 * in this file are the nine in that block, each annotated with the WCAG
 * contrast ratio it actually computes to (relative-luminance formula, verified
 * with a script rather than estimated). Text pairs are >= 4.5:1; the focus ring
 * and the control border are >= 3:1. An e2e test asserts positionally that no
 * colour literal appears below the block.
 */

:root {
  /* --- Surfaces and ink ------------------------------------------------- */
  --color-bg: #faf6f0; /* warm sand paper */
  --color-surface: #f3ece2; /* #f3ece2 on #faf6f0 = 1.09:1 — a decorative card tint, paired with a border so the edge is never the only cue */
  --color-text: #2e2823; /* #2e2823 on #faf6f0 = 13.51:1 | on #f3ece2 = 12.40:1 */
  --color-muted: #635445; /* #635445 on #faf6f0 = 6.76:1 | on #f3ece2 = 6.21:1 — secondary text, still well past AA */

  /* --- Accent (terracotta, not blue) ----------------------------------- */
  --color-accent: #9a3b12; /* #9a3b12 on #faf6f0 = 6.48:1 | on #f3ece2 = 5.95:1 — also the focus ring, >= 3:1 non-text */
  --color-accent-strong: #7d2f0d; /* hover/active; #fffaf4 on #7d2f0d = 8.86:1 */
  --color-accent-ink: #fffaf4; /* #fffaf4 on #9a3b12 = 6.73:1 — button label on accent */

  /* --- Failure ---------------------------------------------------------- */
  --color-error: #962222; /* #962222 on #faf6f0 = 7.65:1 | on #f3ece2 = 7.03:1 */

  /* --- Borders ---------------------------------------------------------- */
  --color-border: #8a7764; /* #8a7764 on #faf6f0 = 3.98:1 | on #f3ece2 = 3.65:1 — input/button edges, >= 3:1 per WCAG 1.4.11 */
  --color-border-subtle: #ddd0bf; /* #ddd0bf on #f3ece2 = 1.29:1 — purely decorative hairlines between forecast rows; no information depends on seeing them */

  /* --- Type ------------------------------------------------------------- */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  /* --- Space ------------------------------------------------------------ */
  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;

  /* --- Shape ------------------------------------------------------------ */
  --radius: 0.5rem;
  --radius-sm: 0.25rem;
  --measure: 34rem; /* single-column max width; holds at 375 and 1440 without breakpoints */
  --control-min: 44px; /* tap-target floor at every width (spec §2.4) */
  --focus-ring: 3px solid var(--color-accent);
}

/* `hidden` is the whole state machine, so it must win over every display rule
   below. Without !important, `.results { display: grid }` would beat the UA
   sheet's `[hidden] { display: none }` and every state would render at once. */
[hidden] {
  display: none !important;
}

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

/* Deliberately no `html { overflow-x: hidden }`. That hides a layout fault
   instead of fixing it, and it would blunt the e2e no-horizontal-scroll
   assertion into a tautology. If the column ever overflows, the test should say
   so. */

body {
  margin: 0;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

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

a:hover {
  color: var(--color-accent-strong);
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* --- Page frame --------------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  width: 100%;
  max-width: var(--measure);
  min-height: 100vh;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-sm) var(--space-md);
}

.masthead__title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 7vw, 2.5rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.masthead__standfirst {
  max-width: 28rem;
  margin-top: var(--space-2xs);
  color: var(--color-muted);
}

.main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: var(--space-lg);
}

/* --- Search form -------------------------------------------------------- */

.search {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.search__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xs);
}

.search__label {
  font-weight: 600;
}

.search__input {
  width: 100%;
  min-height: var(--control-min);
  padding: var(--space-2xs) var(--space-xs);
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1.125rem;
  /* A 5-digit field does not need to be 34rem wide; tabular digits keep it steady. */
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.search__input[aria-invalid="true"] {
  border-color: var(--color-error);
  border-width: 2px;
}

.search__hint,
.search__error {
  font-size: 0.875rem;
}

.search__hint {
  color: var(--color-muted);
}

.search__error {
  color: var(--color-error);
  font-weight: 600;
}

.button {
  min-height: var(--control-min);
  padding: var(--space-2xs) var(--space-md);
  background-color: var(--color-accent);
  color: var(--color-accent-ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.button:hover {
  background-color: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
}

.button--secondary {
  align-self: flex-start;
  background-color: var(--color-bg);
  color: var(--color-accent);
  border-color: var(--color-border);
}

.button--secondary:hover {
  background-color: var(--color-surface);
  color: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
}

/* One breakpoint, one job: below 30rem the button is full width so it stays a
   comfortable thumb target; above it the button sizes to its label. */
@media (min-width: 30rem) {
  .button {
    align-self: flex-start;
    min-width: 11rem;
  }
}

/* --- Status region ------------------------------------------------------ */

.status__loading {
  color: var(--color-muted);
  font-size: 1.0625rem;
}

.notice {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius);
}

.notice--quiet {
  border-inline-start: 4px solid var(--color-border);
}

.notice--error {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  border-inline-start: 4px solid var(--color-error);
}

/* --- Results ------------------------------------------------------------ */

.results {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.results__place {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 6vw, 1.875rem);
  font-weight: 600;
  line-height: 1.15;
}

.results__heading {
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.current {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xs);
  padding: var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius);
}

.current__temp {
  font-family: var(--font-display);
  /* 12vw at 375px is ~45px, and the clamp ceiling stops it growing at 1440px —
     so the number never pushes the column wider than --measure. */
  font-size: clamp(2.75rem, 12vw, 4rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}

.current__conditions {
  display: flex;
  align-items: baseline;
  gap: var(--space-2xs);
  font-size: 1.125rem;
}

.current__icon {
  font-size: 1.375rem;
  line-height: 1;
}

.current__wind {
  color: var(--color-muted);
}

/* --- Five-day list ----------------------------------------------------- */

.forecast {
  display: flex;
  flex-direction: column;
}

.day {
  display: grid;
  /* Name over conditions in column one, temperatures held to the right. The
     same two-row shape at 375 and 1440: nothing reflows, nothing clips, and the
     longest label ("Thunderstorm with hail") wraps instead of overflowing. */
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name temps"
    "weather temps";
  column-gap: var(--space-sm);
  row-gap: var(--space-3xs);
  align-items: center;
  padding-block: var(--space-xs);
  border-block-start: 1px solid var(--color-border-subtle);
}

.day:first-child {
  border-block-start: 0;
}

.day__name {
  grid-area: name;
  font-weight: 600;
}

.day__weather {
  display: flex;
  grid-area: weather;
  align-items: baseline;
  gap: var(--space-3xs);
  color: var(--color-muted);
  font-size: 0.9375rem;
}

.day__temps {
  display: flex;
  grid-area: temps;
  align-items: baseline;
  gap: var(--space-2xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.day__high {
  font-weight: 600;
}

.day__low {
  color: var(--color-muted);
}

/* --- Footer ------------------------------------------------------------ */

.footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xs);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border-subtle);
}

.footer__attribution {
  font-weight: 600;
}

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

/* Honour the OS reduced-motion preference. There is no motion in this page
   today; the rule is here so adding a transition later cannot skip the check. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
