:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --text: #232326;
  --muted: #5f6168;
  --border: #dcdde1;
  --accent: #3a5ccc;
  --accent-text: #ffffff;
  --success: #1f8a4c;
  --error: #c4322b;
  --code-bg: #f2f3f5;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --gutter: max(16px, env(safe-area-inset-left));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b1d;
    --surface: #232326;
    --text: #e8e8ea;
    --muted: #a3a5ad;
    --border: #3a3b40;
    --accent: #7d97f0;
    --accent-text: #0f1220;
    --success: #4fc283;
    --error: #ff7a70;
    --code-bg: #26272b;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1b1d; --surface: #232326; --text: #e8e8ea; --muted: #a3a5ad; --border: #3a3b40;
  --accent: #7d97f0; --accent-text: #0f1220; --success: #4fc283; --error: #ff7a70; --code-bg: #26272b;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: 0.9em; }

/* ---------- Challenge page ---------- */
.challenge {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.challenge__main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 6vh, 64px) var(--gutter);
}
.challenge__card {
  width: 100%;
  max-width: 560px;
}
.challenge__host {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 1.1rem + 2.4vw, 2.5rem);
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.challenge__lead {
  margin: 0 0 24px;
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.2rem);
}
.challenge__note {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.challenge__error { color: var(--error); }

.widget {
  min-height: 78px;
  max-width: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.widget__slot:empty { display: none; }
/* Once the dCAPTCHA iframe is in, it brings its own frame: drop ours. */
.widget:has(.widget__slot:not(:empty)) { border-color: transparent; background: none; min-height: 0; }
.widget:has(.widget__slot:not(:empty)) .widget__slot { justify-content: flex-start; padding: 0; }
.widget__slot { display: flex; justify-content: center; padding: 8px; }
.widget__state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  font-size: 0.95rem;
}
.widget__state[hidden] { display: none; }
.widget__state[data-state="error"] { color: var(--error); }
.widget__state[data-state="success"] { color: var(--success); font-weight: 600; }
.widget__state[data-state="error"] .spinner,
.widget__state[data-state="success"] .spinner { display: none; }
.widget__state[data-state="success"]::before {
  content: "";
  width: 22px; height: 22px; flex: none;
  border-radius: 50%;
  background: var(--success) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E") center/16px no-repeat;
}

.spinner {
  width: 22px; height: 22px; flex: none;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.challenge__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  padding: 16px var(--gutter) max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}
.challenge__footer code { overflow-wrap: anywhere; }
@media (max-width: 420px) { .challenge__footer .dot { display: none; } .challenge__footer { flex-direction: column; } }

/* ---------- Docs page ---------- */
.docs-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.docs-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); text-decoration: none; }
.docs-brand img { width: 26px; height: 26px; }
.docs-header nav a { font-size: 0.95rem; }

.docs-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px var(--gutter) 64px;
}
@media (min-width: 900px) {
  .docs-layout { grid-template-columns: 220px minmax(0, 1fr); padding-top: 40px; }
  .docs-toc { position: sticky; top: 80px; align-self: start; }
}
.docs-toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.docs-toc a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 0.93rem; }
.docs-toc a:hover { background: var(--surface); color: var(--text); }
@media (max-width: 899px) {
  .docs-toc { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
  .docs-toc ol { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

.docs-content { min-width: 0; }
.docs-content h1 { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.4rem); line-height: 1.2; margin: 0 0 12px; }
.docs-content h2 { font-size: 1.4rem; margin: 48px 0 12px; padding-top: 8px; scroll-margin-top: 80px; }
.docs-content h3 { font-size: 1.1rem; margin: 28px 0 8px; }
.docs-content p, .docs-content li { max-width: 72ch; }
.docs-content .lead { color: var(--muted); font-size: 1.1rem; }
.docs-content :not(pre) > code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; overflow-wrap: anywhere; }

.code { position: relative; margin: 12px 0 20px; }
.code pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: 0.86rem/1.55 var(--mono);
  tab-size: 2;
}
.code .copy {
  position: absolute; top: 8px; right: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--muted);
  font: 0.78rem var(--font); cursor: pointer;
}
.code .copy:hover { color: var(--text); }

.callout {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface);
}
.callout--warn { border-left-color: #d68a00; }

.table-wrap { overflow-x: auto; margin: 12px 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
