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

:root {
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --border: #d3d3d3;
  --border-dark: #b0b0b0;
  --text: #1a1a1a;
  --text-muted: #5f6368;
  --header-bg: #f9f9f9;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-light: #e8f0fe;
  --danger: #d93025;
  --meter-bg: #e8eaed;
  --meter-fill: #ea4335;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  --radius: 3px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Site header / logo */
.site-header {
  display: flex;
  justify-content: center;
  padding: 20px 16px 0;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.08));
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

/* Page overlay */
.page-overlay {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  position: relative;
}

.page-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.page-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Captcha widget */
.captcha-widget {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}

.widget-instruction {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  flex: 1;
  padding-right: 8px;
}

.widget-icons {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

.widget-body {
  padding: 14px 12px;
  min-height: 200px;
}

.widget-footer {
  padding: 0 12px 12px;
  display: flex;
  justify-content: flex-end;
}

.verify-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}

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

.verify-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Robot meter */
.robot-meter {
  padding: 0 12px 10px;
}

.robot-meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.robot-meter-track {
  height: 6px;
  background: var(--meter-bg);
  border-radius: 3px;
  overflow: hidden;
}

.robot-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #fbbc04, var(--meter-fill));
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* Image grid */
.image-grid {
  display: grid;
  gap: 3px;
  border: 1px solid var(--border);
}

.image-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.image-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1;
  background: #e8eaed;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.1s, background 0.1s;
  user-select: none;
  position: relative;
}

.grid-cell:hover {
  background: #dfe1e5;
}

.grid-cell.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.grid-cell.selected::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 12px;
  color: var(--accent);
  font-weight: bold;
}

/* Slider */
.slider-challenge {
  padding: 8px 0;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.slider-input {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-value-display {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
  min-height: 20px;
}

.slider-comment {
  text-align: center;
  font-size: 12px;
  color: var(--danger);
  margin-top: 6px;
  font-style: italic;
}

/* Word grid */
.word-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.word-cell {
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.word-cell:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.word-cell.clicked {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Text input */
.text-challenge input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-family: var(--font);
  outline: none;
}

.text-challenge input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.distorted-text {
  font-family: "Courier New", monospace;
  font-size: 28px;
  letter-spacing: 6px;
  text-align: center;
  padding: 16px;
  background: repeating-linear-gradient(
    -5deg,
    #f5f5f5,
    #f5f5f5 2px,
    #e0e0e0 2px,
    #e0e0e0 4px
  );
  border: 1px solid var(--border);
  margin-bottom: 12px;
  user-select: none;
  color: #333;
  transform: skewX(-3deg);
  position: relative;
  overflow: hidden;
}

.distorted-text::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 40%, rgba(255,255,255,0.4) 50%, transparent 60%);
}

/* Checkbox challenge */
.checkbox-challenge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 8px;
  position: relative;
  min-height: 60px;
}

.checkbox-box {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-dark);
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  background: #fff;
}

.checkbox-box:hover {
  border-color: var(--accent);
}

.checkbox-box.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-box.checked::after {
  content: "✓";
  color: #fff;
  font-size: 18px;
  font-weight: bold;
}

.checkbox-label {
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox-followup {
  margin-top: 12px;
  padding: 10px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.checkbox-followup select {
  margin-top: 8px;
  width: 100%;
  padding: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Rotate challenge */
.rotate-challenge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.rotate-canvas-wrap {
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 50%;
  background: var(--header-bg);
}

.animal-emoji {
  font-size: 72px;
  line-height: 1;
  transition: transform 0.1s;
  cursor: grab;
  user-select: none;
}

.animal-emoji:active {
  cursor: grabbing;
}

.rotate-slider {
  width: 80%;
}

.stability-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Audio challenge */
.audio-challenge {
  text-align: center;
  padding: 8px 0;
}

.audio-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  margin-bottom: 14px;
  transition: background 0.15s;
}

.audio-play-btn:hover {
  background: #eee;
}

.audio-challenge input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-family: var(--font);
}

/* Drag and drop */
.drag-challenge {
  position: relative;
  height: 180px;
  border: 1px solid var(--border);
  background: linear-gradient(to bottom, #e3f2fd 0%, #bbdefb 40%, #a5d6a7 40%);
  border-radius: var(--radius);
  overflow: hidden;
}

.drag-item {
  position: absolute;
  font-size: 36px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 2;
  transition: none;
}

.drag-item:active {
  cursor: grabbing;
}

.drag-target-zone {
  position: absolute;
  font-size: 36px;
  z-index: 1;
}

.drag-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* Single click */
.click-target-challenge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
}

.click-target {
  font-size: 80px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s;
  user-select: none;
}

.click-target:hover {
  transform: scale(1.08);
}

.click-target.hit {
  filter: hue-rotate(90deg);
}

/* Verifying overlay */
.verifying-overlay {
  position: absolute;
  inset: 0;
  background: rgba(240, 242, 245, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  color: var(--text-muted);
  z-index: 10;
}

/* Verdict */
.verdict-panel {
  text-align: center;
  max-width: 400px;
  padding: 32px 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.verdict-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.verdict-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.verdict-text {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.verdict-stat {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  font-style: italic;
}

.try-again-btn {
  width: 100%;
  padding: 12px;
  font-size: 14px;
}

/* Footer */
.page-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--text-muted);
}

.page-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.page-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-dot {
  margin: 0 6px;
}

/* Toast for icon buttons */
.toast {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  z-index: 100;
  animation: fadeInOut 2.5s ease forwards;
  pointer-events: none;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* Mobile */
@media (max-width: 440px) {
  .captcha-widget {
    max-width: 100%;
  }

  .widget-body {
    min-height: 180px;
    padding: 12px 10px;
  }

  .grid-cell {
    font-size: 26px;
  }

  .logo-title {
    font-size: 16px;
  }

  .distorted-text {
    font-size: 22px;
    letter-spacing: 4px;
  }
}