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

:root {
  --bg: #0f172a;
  --bg-grad-1: #0b1220;
  --bg-grad-2: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-3: #475569;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #4285f4;
  --primary-light: #5e9bff;
  --primary-dark: #1a73e8;
  --green: #10b981;
  --green-light: #34d399;
  --red: #ef4444;
  --red-light: #f87171;
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --shadow: 0 10px 40px rgba(0,0,0,0.4);
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(66,133,244,0.10), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(236,72,153,0.06), transparent 50%),
    linear-gradient(180deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  background: rgba(15, 23, 42, 0.75);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.back-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.brand-mark { font-size: 1.1rem; }
.brand-text b { color: var(--primary-light); font-weight: 700; }

.level-pill {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--primary-light);
  background: rgba(66,133,244,0.12);
  border: 1px solid rgba(66,133,244,0.3);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

/* ── Captcha shell ── */
.captcha-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem 1rem;
  gap: 0.75rem;
}

.captcha-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--surface-3);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.captcha-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.captcha-logo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.logo-shield {
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: rgba(66,133,244,0.15);
  border: 1px solid rgba(66,133,244,0.35);
  border-radius: 8px;
}
.logo-name { font-size: 0.95rem; font-weight: 700; }
.logo-sub { font-size: 0.72rem; color: var(--text-muted); }

.captcha-progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.captcha-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transition: width 0.4s ease;
}

/* ── Body ── */
.captcha-body {
  padding: 1.4rem 1.25rem;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.loader {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 0;
}

/* ── Footer ── */
.captcha-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  background: var(--surface-2);
  border-top: 1px solid var(--surface-3);
}
.footer-status {
  flex: 1;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.verify-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.55rem 1.3rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.verify-btn:hover { background: var(--primary-dark); }
.verify-btn:active { transform: translateY(1px); }
.verify-btn:disabled { background: var(--surface-3); color: var(--text-dim); cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface-3);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border); }

.legal-line {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  max-width: 520px;
}

/* ── Challenge instruction ── */
.challenge-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}
.challenge-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

/* ── Level 1: classic checkbox ── */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  position: relative;
}
.fancy-checkbox {
  width: 28px;
  height: 28px;
  border: 2px solid var(--surface-3);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: var(--primary);
  position: absolute;
  transition: top 0.18s ease, left 0.18s ease;
}
.fancy-checkbox.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.fancy-checkbox.ghost {
  opacity: 0;
  pointer-events: none;
}
.checkbox-label {
  font-size: 0.85rem;
  color: var(--text);
  margin-left: 38px;
}
.checkbox-helper {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  margin-left: 38px;
}

/* ── Image grid (reCAPTCHA style) ── */
.img-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface-3);
  padding: 4px;
  border-radius: 6px;
}
.img-tile {
  aspect-ratio: 1 / 1;
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
  position: relative;
  overflow: hidden;
}
.img-tile:hover { background: var(--surface-2); transform: scale(1.02); }
.img-tile.selected {
  border-color: var(--primary-light);
  background: rgba(66,133,244,0.18);
}
.img-tile.selected::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 6px;
  color: var(--primary-light);
  font-size: 0.9rem;
  font-weight: 700;
}
.img-tile .icon {
  width: 75%;
  height: 75%;
  display: block;
  pointer-events: none;
}

/* ── Audio captcha ── */
.audio-box {
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.play-btn:hover { background: var(--primary-dark); }
.play-btn:disabled { background: var(--surface-3); }
.audio-wave {
  flex: 1;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 0.5rem;
}
.audio-wave .bar {
  flex: 1;
  background: var(--surface-3);
  border-radius: 2px;
  height: 20%;
}
.audio-wave .bar.active { background: var(--primary-light); }

.audio-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}
.audio-input:focus { outline: none; border-color: var(--primary); }

.audio-hint { font-size: 0.72rem; color: var(--text-muted); }

/* ── Slider captcha ── */
.slider-track {
  position: relative;
  height: 50px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}
.slider-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: rgba(66,133,244,0.18);
  width: 0%;
  transition: width 0.05s linear;
}
.slider-target {
  position: absolute;
  top: 5px; bottom: 5px;
  width: 40px;
  background: rgba(16,185,129,0.18);
  border: 2px dashed var(--green);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 1rem;
}
.slider-handle {
  position: absolute;
  top: 5px; left: 5px;
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 4px;
  cursor: grab;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1rem;
  z-index: 2;
  user-select: none;
  transition: transform 0.05s linear;
}
.slider-handle:active { cursor: grabbing; }
.slider-handle.snapped { background: var(--green); }

.slider-hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Distorted text ── */
.distorted-canvas {
  width: 100%;
  height: 100px;
  background: linear-gradient(135deg, #f0f4ff 0%, #d9e4ff 100%);
  border-radius: 6px;
  display: block;
}
.distorted-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.1em;
  font-family: 'Courier New', monospace;
}
.distorted-input:focus { outline: none; border-color: var(--primary); }
.refresh-link {
  font-size: 0.78rem;
  color: var(--primary-light);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* ── Math problem ── */
.math-display {
  text-align: center;
  font-size: 1.4rem;
  font-family: 'Courier New', monospace;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1.2rem;
  letter-spacing: 0.08em;
}
.math-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
}
.math-input:focus { outline: none; border-color: var(--primary); }

/* ── Emotion picker ── */
.emotion-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}
.emotion-tile {
  aspect-ratio: 1 / 1;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.emotion-tile:hover { background: var(--surface-2); transform: translateY(-2px); }
.emotion-tile.selected {
  border-color: var(--primary-light);
  background: rgba(66,133,244,0.18);
}

/* ── Maze ── */
.maze-canvas {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}
.maze-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Catch the button ── */
.catch-arena {
  position: relative;
  width: 100%;
  height: 220px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}
.catch-target {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.55rem 1.2rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: top 0.18s ease, left 0.18s ease;
}
.catch-target.caught { background: var(--green); }
.catch-counter {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Overlays ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.overlay.show { display: flex; }
.overlay-card {
  background: var(--surface);
  border: 1px solid var(--surface-3);
  border-radius: 12px;
  padding: 2rem 2.2rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card--success {
  background: linear-gradient(135deg, #1e293b 0%, #0b1220 100%);
  border-color: var(--green);
}
.overlay-icon { font-size: 2.6rem; margin-bottom: 0.6rem; }
.overlay-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 0.5rem; }
.overlay-desc { font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 1.2rem; }
.overlay-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.overlay-btn:hover { background: var(--primary-dark); }

.cert {
  background: rgba(0,0,0,0.3);
  border: 1px dashed var(--surface-3);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: 0 0 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.cert-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}
.cert-row span { color: var(--text-muted); }
.cert-row strong { color: var(--text); }

/* ── Responsive ── */
@media (max-width: 540px) {
  .top-bar { padding: 0.7rem 1rem; }
  .brand-text { display: none; }
  .captcha-body { padding: 1.1rem 1rem; }
  .emotion-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Confetti ── */
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px;
  height: 14px;
  z-index: 1100;
  pointer-events: none;
}
