/*
 * Shared base for every Polls page: reset, type, and the handful of controls
 * (buttons, inputs, cards, pills) the taker, builder and docs all use. It only
 * reads tokens.css; page sheets layer on top. Keep it generic: anything that
 * only one page needs belongs in that page's sheet.
 */

/* ---------- reset ---------- */

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol {
  margin: 0;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

/* The hidden attribute must win over any display rule a class sets. */
[hidden] {
  display: none !important;
}

/* ---------- typography ---------- */

h1, h2, h3, h4 {
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 650;
  text-wrap: balance;
}

h1 { font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.75rem); }
h2 { font-size: clamp(1.375rem, 1.1rem + 1.2vw, 1.875rem); }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }

p {
  text-wrap: pretty;
}

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

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

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

kbd {
  display: inline-block;
  padding: 0 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  line-height: 1.5;
}

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

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

/* ---------- focus ---------- */

/*
 * One visible ring everywhere, keyboard only. :focus-visible keeps mouse
 * clicks quiet without hiding focus from people who navigate by keyboard.
 */
:focus {
  outline: none;
}

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

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 44px;
  padding: 0.6em 1.15em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

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

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, var(--fg));
  border-color: color-mix(in srgb, var(--accent) 88%, var(--fg));
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg);
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 88%, #000);
}

.btn-sm {
  min-height: 34px;
  padding: 0.35em 0.8em;
  font-size: 0.875rem;
}

.btn-lg {
  min-height: 52px;
  padding: 0.7em 1.5em;
  font-size: 1.125rem;
}

.btn-icon {
  padding: 0;
  width: 44px;
}

/* ---------- inputs ---------- */

/* 16px minimum: iOS Safari zooms the page into any smaller field. */
.input,
.textarea,
.select {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.6em 0.8em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font-size: max(1rem, 16px);
  line-height: 1.4;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.textarea {
  resize: vertical;
  min-height: 6em;
}

.input::placeholder,
.textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: color-mix(in srgb, var(--border) 50%, var(--muted));
}

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

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

.label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.9375rem;
}

.hint {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.field-error {
  margin-top: 0.35rem;
  color: var(--danger);
  font-size: 0.875rem;
}

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.65em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pill-warning { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }
.pill-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.notice-danger {
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

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

/* Hidden on screen, still read by assistive technology. */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 100;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.container {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: 1rem;
}

@media (min-width: 640px) {
  .container {
    padding-inline: 1.5rem;
  }
}

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