/*
 * Site-wide styles: design tokens, base elements, layout (header/footer) and
 * shared components. Page-specific styles live in their own files.
 */

/* ---- Tokens ------------------------------------------------------------- */

:root {
  --red: #c8102e;
  --red-strong: #a50d26;
  --red-soft: #fcebed;

  --ink: #1c1e21;
  --ink-2: #464b52;
  --ink-3: #6c727a;
  --paper: #ffffff;
  --paper-2: #f6f4f0;
  --paper-3: #ece8e1;
  --line: #e2ded6;

  /* Polymer note colours, for small accents */
  --note-5: #2b6cb0;
  --note-10: #7a4ea3;
  --note-20: #2f8a52;
  --note-50: #c23b2c;
  --note-100: #a8743a;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --radius: 10px;
  --radius-small: 6px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.06);
  --container: 1120px;
  --gutter: clamp(16px, 4vw, 32px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --red: #f0566a;
    --red-strong: #ff7a8b;
    --red-soft: #3a1a20;

    --ink: #ecebe8;
    --ink-2: #c3c1bc;
    --ink-3: #96938d;
    --paper: #16181b;
    --paper-2: #1d2024;
    --paper-3: #262a2f;
    --line: #2e3238;

    --note-5: #6aa5e8;
    --note-10: #b590dc;
    --note-20: #5fc285;
    --note-50: #f07a6a;
    --note-100: #d9a568;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.3);
  }
}

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

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
}

main { flex: 1; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

a { color: var(--red); text-underline-offset: 0.15em; }
a:hover { color: var(--red-strong); }

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

input, button { font: inherit; }

input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="url"], input[type="number"] {
  width: 100%;
  padding: 0.6em 0.75em;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--paper);
  color: var(--ink);
}
input:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px var(--red-soft); }

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 16px; top: 16px; z-index: 10; background: var(--paper); padding: 0.5em 1em; }

.muted { color: var(--ink-3); }

/* ---- Buttons ------------------------------------------------------------ */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.65em 1.2em;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--red);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { background: var(--red-strong); color: #fff; }
.button--small { padding: 0.45em 0.9em; font-size: 0.9rem; }
.button--block { width: 100%; }

@media (prefers-color-scheme: dark) {
  .button, .button:hover { color: #16181b; }
}

/* ---- Header ------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.site-header__bar {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: var(--ink); }
.brand__leaf { width: 26px; height: 26px; color: var(--red); flex: none; }

.site-menu {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-nav { display: flex; gap: 4px; }
.site-nav a {
  padding: 0.4em 0.55em;
  border-radius: var(--radius-small);
  color: var(--ink-2);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.site-nav a:hover { background: var(--paper-2); color: var(--ink); }

.site-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.site-search input { width: 120px; padding: 0.4em 0.7em; background: var(--paper-2); transition: width 0.15s; }
.site-search input:focus { width: 180px; }
.site-actions__lang, .site-actions__login, .site-actions__logout, .site-actions__admin {
  color: var(--ink-2);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.site-actions__lang { font-size: 0.85rem; letter-spacing: 0.04em; }

.menu-toggle { display: none; }

/* Collapses before the bar runs out of room with a logged-in username showing. */
@media (max-width: 1100px) {
  .menu-toggle {
    display: inline-flex;
    margin-left: auto;
    width: 44px; height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    background: var(--paper);
    cursor: pointer;
  }
  .menu-toggle__bars,
  .menu-toggle__bars::before,
  .menu-toggle__bars::after {
    display: block;
    width: 18px; height: 2px;
    background: var(--ink);
    border-radius: 2px;
    position: relative;
    content: "";
  }
  .menu-toggle__bars::before { position: absolute; top: -6px; }
  .menu-toggle__bars::after { position: absolute; top: 6px; }

  .site-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 16px var(--gutter) 24px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  .site-menu.is-open { display: flex; }
  .site-nav { flex-direction: column; }
  .site-nav a { padding: 0.7em 0.5em; font-size: 1.05rem; }
  .site-actions { margin-left: 0; flex-wrap: wrap; }
  .site-search { flex-basis: 100%; }
  .site-search input, .site-search input:focus { width: 100%; }
}

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

.site-footer {
  margin-top: 64px;
  padding-block: 32px;
  background: var(--paper-2);
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 0.9rem;
}
.site-footer__inner { display: grid; gap: 16px; }
.site-footer__brand { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 600; }
.site-footer__leaf { width: 18px; height: 18px; color: var(--red); }
.site-footer__links { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.site-footer__links a { color: var(--ink-2); text-decoration: none; }
.site-footer__links a:hover { color: var(--red); text-decoration: underline; }
.site-footer__copyright { margin: 0; }

/* ---- Shared components -------------------------------------------------- */

.eyebrow {
  margin-bottom: 0.75em;
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section { margin-bottom: 48px; }
.section__title { font-size: 1.4rem; }

.card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.card + .card { margin-top: 20px; }
.card__title { font-size: 1.05rem; margin-bottom: 14px; }
.card__footnote { margin-top: 14px; font-size: 0.85rem; color: var(--ink-3); }

.panel {
  padding: 28px;
  border-radius: var(--radius);
  background: var(--paper-2);
  margin-bottom: 48px;
}
.panel--accent { background: var(--red-soft); }
.panel__title { font-size: 1.3rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ink-2); }
.checkbox input { accent-color: var(--red); width: 16px; height: 16px; }

.checklist { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.checklist li { position: relative; padding-left: 28px; }
.checklist li::before {
  content: "";
  position: absolute;
  left: 0; top: 0.3em;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--red) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.link-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}
.link-grid a {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}
.link-grid a::after { content: " →"; color: var(--red); }
.link-grid a:hover { border-color: var(--red); }

.site-actions__logout { padding: 0; border: 0; background: none; cursor: pointer; }
.site-actions__logout:hover, .site-actions__login:hover, .site-actions__admin:hover { color: var(--red); }
.site-actions form { margin: 0; }
.site-actions__user {
  max-width: 12ch;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-left: 4px solid var(--red);
  border-radius: var(--radius-small);
  background: var(--red-soft);
  color: var(--ink);
  font-size: 0.925rem;
}

.narrow-page { max-width: 440px; padding-block: 48px 0; }
.card__title--page { font-size: 1.5rem; }
.alert--notice { border-left-color: var(--note-20); background: color-mix(in srgb, var(--note-20) 12%, var(--paper)); }

.lead { font-size: 1.1rem; color: var(--ink-2); }

.field__hint { margin: 2px 0 0; font-size: 0.825rem; color: var(--ink-3); }
.field__error { margin: 2px 0 0; font-size: 0.85rem; font-weight: 600; color: var(--red); }
input[aria-invalid="true"] { border-color: var(--red); }

.card--notice { border-color: var(--note-10); box-shadow: inset 4px 0 0 var(--note-10); }

/* A button that looks like a link, for actions that must POST. */
.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--red);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}
.link-button:hover { color: var(--red-strong); }
.inline-form { display: inline; }

/* A page that's mostly one form, with an introduction beside it on wide screens. */
.form-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  gap: clamp(28px, 5vw, 64px);
  align-items: start;
  padding-top: 48px;
}
.form-page__intro h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800; letter-spacing: -0.02em; }

.next-steps {
  grid-column: 1 / -1;
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  counter-reset: step;
}
.next-steps .card + .card { margin-top: 0; }
.next-steps .card__title::before {
  counter-increment: step;
  content: counter(step) ". ";
  color: var(--red);
}
.next-steps p { color: var(--ink-2); font-size: 0.95rem; }

@media (max-width: 860px) {
  .form-page { grid-template-columns: 1fr; padding-top: 32px; }
}
.form-page--wide .form-page__intro { grid-column: 1 / -1; max-width: 46em; }
