/* Captcha Lab — design system (tokens, reset, shared components).
   Dark-first with a light theme; colour-blind-friendly status palette (Okabe–Ito based). */
:root {
  --bg: #07080f;
  --bg-2: #0c0e1a;
  --surface: rgba(20, 23, 40, 0.72);
  --surface-solid: #141728;
  --surface-2: #1a1e33;
  --surface-3: #232843;
  --border: rgba(148, 163, 220, 0.14);
  --border-strong: rgba(148, 163, 220, 0.28);
  --text: #eef0fa;
  --text-2: #b9bfd9;
  --muted: #8189ab;
  --accent: #7c6cff;
  --accent-2: #22d3ee;
  --accent-3: #f472b6;
  --accent-ink: #0b0b16;
  --grad: linear-gradient(135deg, #7c6cff 0%, #22d3ee 100%);
  --grad-warm: linear-gradient(135deg, #f472b6 0%, #7c6cff 100%);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #f5b041;
  --warn-soft: rgba(245, 176, 65, 0.14);
  --bad: #ff6b81;
  --bad-soft: rgba(255, 107, 129, 0.14);
  --info: #56b4e9;
  --info-soft: rgba(86, 180, 233, 0.14);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.25);
  --ring: 0 0 0 3px rgba(124, 108, 255, 0.45);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --scale: 1;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-2: #eceef8;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-2: #f1f2fa;
  --surface-3: #e5e7f4;
  --border: rgba(30, 36, 80, 0.12);
  --border-strong: rgba(30, 36, 80, 0.24);
  --text: #12142a;
  --text-2: #3b4066;
  --muted: #646a8f;
  --accent: #5b4bea;
  --accent-2: #0891b2;
  --accent-ink: #ffffff;
  --ok: #0f8a5f;
  --ok-soft: rgba(15, 138, 95, 0.12);
  --warn: #a35f00;
  --warn-soft: rgba(163, 95, 0, 0.12);
  --bad: #c2273d;
  --bad-soft: rgba(194, 39, 61, 0.1);
  --info: #0868a8;
  --info-soft: rgba(8, 104, 168, 0.1);
  --shadow: 0 1px 2px rgba(16, 20, 50, 0.06), 0 10px 30px rgba(16, 20, 50, 0.08);
  --shadow-sm: 0 2px 8px rgba(16, 20, 50, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f5fb; --bg-2: #eceef8; --surface: rgba(255, 255, 255, 0.82); --surface-solid: #fff; --surface-2: #f1f2fa;
    --surface-3: #e5e7f4; --border: rgba(30, 36, 80, 0.12); --border-strong: rgba(30, 36, 80, 0.24); --text: #12142a;
    --text-2: #3b4066; --muted: #646a8f; --accent: #5b4bea; --accent-2: #0891b2; --accent-ink: #fff; --ok: #0f8a5f;
    --ok-soft: rgba(15, 138, 95, 0.12); --warn: #a35f00; --warn-soft: rgba(163, 95, 0, 0.12); --bad: #c2273d;
    --bad-soft: rgba(194, 39, 61, 0.1); --info: #0868a8; --info-soft: rgba(8, 104, 168, 0.1);
    --shadow: 0 1px 2px rgba(16, 20, 50, 0.06), 0 10px 30px rgba(16, 20, 50, 0.08); --shadow-sm: 0 2px 8px rgba(16, 20, 50, 0.08);
    color-scheme: light;
  }
}
:root.high-contrast { --border: currentColor; --border-strong: currentColor; --muted: var(--text-2); }
:root.reduce-motion *, :root.reduce-motion *::before, :root.reduce-motion *::after { animation: none !important; transition: none !important; }
@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; }
}

[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(15px * var(--scale)); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 400 1rem/1.55 var(--font); -webkit-font-smoothing: antialiased; }
img, svg, canvas, video { max-width: 100%; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
::selection { background: rgba(124, 108, 255, 0.35); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
p { margin: 0; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.9em; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 12px; z-index: 1000; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.skip-link:focus { left: 12px; }

/* --- Buttons -------------------------------------------------------- */
.btn { --b: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--b); color: var(--text); font: 600 0.95rem/1 var(--font);
  cursor: pointer; text-decoration: none; transition: transform 0.12s var(--ease), background 0.2s, border-color 0.2s, box-shadow 0.2s; white-space: nowrap; }
.btn:hover { border-color: var(--border-strong); text-decoration: none; background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 8px 24px rgba(124, 108, 255, 0.35); }
.btn-primary:hover { background: var(--grad); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); }
.btn-sm { min-height: 32px; padding: 0 11px; font-size: 0.85rem; border-radius: 9px; }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: 1.02rem; border-radius: 14px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

/* --- Forms ---------------------------------------------------------- */
.field { display: grid; gap: 6px; }
.field > span, label.lbl { font-size: 0.82rem; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input { width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font: 400 0.95rem/1.4 var(--font); transition: border-color 0.2s, box-shadow 0.2s; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea.input { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 0.85rem; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-2); cursor: pointer; }

/* --- Surfaces ------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); min-width: 0; }
.card.flat { box-shadow: none; background: var(--surface-2); backdrop-filter: none; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title h2, .card-title h3 { font-size: 1.02rem; }
.badge, .pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: rgba(124, 108, 255, 0.16); color: var(--accent); }
.kbd { font-family: var(--mono); font-size: 0.75rem; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; color: var(--text-2); }
.muted { color: var(--muted); }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* --- Layout helpers --------------------------------------------------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; min-width: 0; }
.row.center { align-items: center; }
.stack { display: grid; gap: 12px; }
.grid { display: grid; gap: 16px; }
.g2, .cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.g3, .cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.g4, .cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.spacer, .row > .grow { flex: 1 1 auto; }
.row > .btn, .row > button, .row > .pill, .row > .toolbar, .row > .check, .row > .spinner, .row > h3:not(.grow), .row > b { flex: 0 0 auto; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 8px; }

/* --- Feedback ------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 900; display: grid; gap: 10px; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface-solid); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); animation: toast-in 0.25s var(--ease); }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); } .toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: 99px; transition: width 0.3s var(--ease); }
.progress.indeterminate > i { width: 35%; animation: indet 1.1s infinite var(--ease); }
@keyframes indet { 0% { transform: translateX(-110%); } 100% { transform: translateX(300%); } }
.meter { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.4s var(--ease); }
.meter.ok > i { background: var(--ok); } .meter.warn > i { background: var(--warn); } .meter.bad > i { background: var(--bad); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-solid); color: var(--text); padding: 22px;
  width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(4, 5, 12, 0.6); backdrop-filter: blur(4px); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; }
.table-wrap { overflow-x: auto; }
pre.json { margin: 0; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-height: 420px; overflow: auto;
  font: 0.78rem/1.5 var(--mono); color: var(--text-2); }
details > summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
