/* ═══════════════════════════════════════════════════════════════════
   base.css — reset, typography, form primitives, utilities.
   Element selectors only, plus the .field / .hint primitives every
   question renderer composes from. No component styling lives here.
   ═══════════════════════════════════════════════════════════════════ */

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

* { margin: 0; padding: 0; }

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

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  /* iOS: keep the sticky wizard nav clear of the home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 {
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--fw-bold);
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

p { line-height: var(--lh-body); }

a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
a:hover { text-decoration: underline; }

ul, ol { padding-left: var(--sp-4); }

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.95em; }

svg { flex-shrink: 0; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

::selection { background: var(--accent-light); color: var(--text); }

/* ── Focus: visible for keyboards, quiet for pointers ────────────── */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ── Form primitives ─────────────────────────────────────────────── */
input, textarea, select, button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--sp-3);
  font-size: var(--fs-lg);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea {
  min-height: 108px;
  line-height: var(--lh-snug);
  resize: vertical;
}

input:hover:not(:disabled),
textarea:hover:not(:disabled),
select:hover:not(:disabled) { border-color: var(--border-strong); }

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
  outline: none;
}

input:disabled,
textarea:disabled,
select:disabled {
  background: var(--bg-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

input::placeholder,
textarea::placeholder { color: var(--text-placeholder); }

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] { border-color: var(--red); }

select {
  appearance: none;
  padding-right: var(--sp-7);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

fieldset { border: none; }
legend { padding: 0; }

/* ── .field — the unit every question renders into ───────────────── */
.field { margin-bottom: var(--sp-5); }
.field:last-child { margin-bottom: 0; }

.field > label,
.field > .field-label {
  display: block;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  margin-bottom: var(--sp-1);
}

.field .optional,
.field .field-label .optional {
  font-weight: var(--fw-normal);
  color: var(--text-muted);
}

.field .hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: var(--lh-snug);
  margin-bottom: var(--sp-2);
}

.field .error {
  font-size: var(--fs-xs);
  color: var(--red-text);
  margin-top: var(--sp-1);
}

.field.with-divider {
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}

/* A checkbox and its label on one line — permission-to-publish, toggles */
.check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  cursor: pointer;
}

/* ── Utilities ───────────────────────────────────────────────────── */
/* Both spellings hide. [hidden] needs the override because component
   display rules (.btn is inline-flex) otherwise beat the UA stylesheet. */
.hidden,
[hidden] { display: none !important; }

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

.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
.text-sm { font-size: var(--fs-sm); }
.stack > * + * { margin-top: var(--sp-3); }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ── Reduced motion: honour it globally, once ────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
