:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #f59e0b;
  --shadow: 0 10px 30px rgba(2, 6, 23, .08);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { overflow-x: hidden; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f1f5f9;
  color: var(--ink);
  line-height: 1.55;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand-mark { font-size: 28px; }
.brand-text { font-weight: 800; font-size: 20px; display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 500; font-size: 11px; opacity: .85; letter-spacing: 1px; text-transform: uppercase; }

.header-stats { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat-pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.16);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; backdrop-filter: blur(4px);
}
.stat-pill strong { font-size: 15px; }
.nav-btn {
  border: 0; cursor: pointer; font-weight: 600;
  background: #fff; color: var(--brand);
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
  transition: transform .15s ease;
}
.nav-btn:hover { transform: translateY(-2px); }

/* ===== Ads ===== */
.ad-row { display: flex; justify-content: center; padding: 14px; overflow: hidden; }
.ad-inline { margin: 28px 0; }
.ad-row ins { max-width: 100%; }
.ad-side { padding-top: 20px; display: flex; justify-content: center; }
.ad-mobile { display: none; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 320px;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 20px 40px;
  align-items: start;
}
.content { min-width: 0; }

/* ===== Screens ===== */
.screen { display: none; animation: fade .3s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Hero ===== */
.hero {
  background: linear-gradient(120deg, #312e81, #6d28d9);
  color: #fff; border-radius: var(--radius); padding: 34px;
  box-shadow: var(--shadow); margin-bottom: 26px;
}
.hero h1 { font-size: 30px; margin-bottom: 10px; }
.hero p { max-width: 720px; opacity: .92; }

.section-title { font-size: 20px; margin: 30px 0 16px; }

/* ===== Cards ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.captcha-card, .reward-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.captcha-card { cursor: pointer; }
.captcha-card:hover, .reward-card:hover { transform: translateY(-4px); box-shadow: 0 16px 40px rgba(2,6,23,.14); }
.card-emoji { font-size: 34px; }
.captcha-card h3, .reward-card h3 { font-size: 17px; }
.captcha-card p, .reward-card p { color: var(--muted); font-size: 14px; }
.reward-tag {
  align-self: flex-start; background: #eef2ff; color: var(--brand);
  font-weight: 700; font-size: 13px; padding: 4px 12px; border-radius: 999px;
}

/* ===== Steps ===== */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; }
.step { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; margin-bottom: 10px;
  background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700;
}
.step p { font-size: 14px; }

.features { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 10px; }
.features li { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-weight: 500; color: #334155; }

/* ===== Solve ===== */
.back-btn { background: none; border: 0; color: var(--brand); font-weight: 600; cursor: pointer; font-size: 15px; margin-bottom: 16px; }
.solve-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.solve-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.solve-head h2 { font-size: 22px; }
.solve-sub { color: var(--muted); margin: 6px 0 20px; }

.captcha-area { min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; margin-bottom: 22px; }

/* number/text captcha box */
.captcha-display {
  font-family: 'Courier New', monospace; font-weight: 700;
  font-size: 42px; letter-spacing: 8px;
  padding: 22px 36px; border-radius: 14px; user-select: none;
  background: repeating-linear-gradient(45deg, #e0e7ff, #e0e7ff 10px, #f1f5f9 10px, #f1f5f9 20px);
  color: #1e1b4b; position: relative; overflow: hidden;
}
.captcha-display span { display: inline-block; }
.captcha-math {
  font-size: 40px; font-weight: 800; color: #1e1b4b;
  background: #eef2ff; padding: 20px 40px; border-radius: 14px;
}

/* slider captcha */
.slider-wrap { width: 100%; max-width: 420px; }
.slider-track {
  position: relative; height: 56px; border-radius: 12px;
  background: #e2e8f0; overflow: hidden; border: 1px solid var(--line);
}
.slider-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #c7d2fe, #a5b4fc); }
.slider-target { position: absolute; top: 0; bottom: 0; width: 4px; background: var(--green); }
.slider-target::after { content: 'target'; position: absolute; top: -20px; left: -16px; font-size: 11px; color: var(--green); font-weight: 700; }
.slider-knob {
  position: absolute; top: 4px; left: 4px; width: 48px; height: 46px;
  background: #fff; border-radius: 9px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; cursor: grab; font-weight: 700; color: var(--brand);
  touch-action: none;
}
.slider-knob:active { cursor: grabbing; }
.slider-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* puzzle captcha */
.puzzle-grid { display: grid; grid-template-columns: repeat(3, 80px); gap: 8px; }
.puzzle-cell {
  width: 80px; height: 80px; border-radius: 10px; border: 2px solid var(--line);
  background: #fff; font-size: 28px; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .12s ease;
}
.puzzle-cell:hover { border-color: var(--brand); }
.puzzle-cell.selected { background: var(--brand); color: #fff; border-color: var(--brand); }
.puzzle-instruction { font-weight: 600; }

.solve-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.answer-input {
  flex: 1; min-width: 200px; padding: 14px 16px; font-size: 16px;
  border: 2px solid var(--line); border-radius: 12px; outline: none; transition: border .15s ease;
}
.answer-input:focus { border-color: var(--brand); }
.answer-input:disabled { background: #f1f5f9; }
.primary-btn {
  border: 0; cursor: pointer; font-weight: 700; font-size: 16px; color: #fff;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  padding: 14px 26px; border-radius: 12px; transition: transform .15s ease, opacity .15s ease;
}
.primary-btn:hover { transform: translateY(-2px); }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.solve-tools { display: flex; align-items: center; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.ghost-btn { background: #f1f5f9; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; }
.ghost-btn:hover { background: #e2e8f0; }
.feedback { font-weight: 700; }
.feedback.ok { color: var(--green); }
.feedback.bad { color: var(--red); }

/* ===== Rewards ===== */
.rewards-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.rewards-head h2 { font-size: 24px; }
.balance { background: #eef2ff; color: var(--brand); padding: 10px 18px; border-radius: 999px; font-weight: 600; }
.redeem-btn {
  margin-top: auto; border: 0; cursor: pointer; font-weight: 700; color: #fff;
  background: var(--green); padding: 11px 16px; border-radius: 10px; transition: opacity .15s ease;
}
.redeem-btn:disabled { background: #cbd5e1; cursor: not-allowed; }
.history { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.history li { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; font-size: 14px; display: flex; justify-content: space-between; }
.history li.empty { color: var(--muted); justify-content: center; }

/* ===== Footer ===== */
.site-footer { background: var(--bg); color: #cbd5e1; padding: 36px 24px; margin-top: 20px; }
.site-footer h3 { color: #fff; margin-bottom: 14px; }
.site-footer ul { list-style: disc; padding-left: 22px; max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.site-footer ul li { color: #94a3b8; }
.copyright { text-align: center; margin-top: 24px; font-size: 13px; color: #64748b; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: #0f172a; color: #fff; padding: 14px 22px; border-radius: 12px;
  box-shadow: var(--shadow); font-weight: 600; z-index: 100; transition: transform .35s ease; max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--green); }
.toast.bad { background: var(--red); }

/* ===== Responsive ===== */

/* Scale any over-wide ad unit down on small screens */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .ad-side { display: none; }
}

/* Tablet */
@media (max-width: 820px) {
  .ad-row ins { transform-origin: top center; }
  .hero { padding: 26px; }
  .hero h1 { font-size: 26px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

/* ===== Phone ===== */
@media (max-width: 640px) {
  body { -webkit-text-size-adjust: 100%; }

  /* show the small banner, hide the giant top leaderboard */
  .ad-mobile { display: flex; }
  .ad-row:not(.ad-mobile):not(.ad-inline) { display: none; }
  /* shrink inline desktop ads so they never cause horizontal scroll */
  .ad-inline { margin: 20px 0; }
  .ad-inline ins {
    transform: scale(.42);
    transform-origin: top center;
    margin-bottom: -150px; /* pull following content up after scale */
  }

  /* header becomes a tidy stacked bar */
  .site-header { padding: 12px 14px; gap: 10px; }
  .brand-text { font-size: 17px; }
  .brand-mark { font-size: 24px; }
  .header-stats { width: 100%; justify-content: space-between; gap: 8px; }
  .stat-pill { flex: 1; justify-content: center; padding: 7px 8px; font-size: 12px; }
  .stat-pill span:not(.stat-icon) { display: none; } /* hide the label, keep icon + number */
  .nav-btn { padding: 8px 12px; font-size: 13px; }

  .layout { padding: 8px 12px 30px; gap: 14px; }

  /* hero */
  .hero { padding: 22px 18px; border-radius: 14px; margin-bottom: 18px; }
  .hero h1 { font-size: 22px; }
  .hero p { font-size: 14px; }
  .section-title { font-size: 18px; margin: 22px 0 12px; }

  /* one-column cards */
  .card-grid { grid-template-columns: 1fr; gap: 12px; }
  .captcha-card, .reward-card { padding: 16px; }
  .steps { grid-template-columns: 1fr 1fr; gap: 10px; }
  .step { padding: 14px; }
  .features { grid-template-columns: 1fr; }

  /* solve screen */
  .solve-card { padding: 18px; }
  .solve-head h2 { font-size: 19px; }
  .captcha-display { font-size: 28px; letter-spacing: 4px; padding: 14px 16px; }
  .captcha-math { font-size: 30px; padding: 16px 22px; }
  .solve-actions { flex-direction: column; }
  .answer-input { width: 100%; min-width: 0; font-size: 16px; }
  .primary-btn { width: 100%; }
  .solve-tools { justify-content: space-between; }

  /* puzzle grid scales to screen */
  .puzzle-grid { grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 300px; }
  .puzzle-cell { width: 100%; aspect-ratio: 1 / 1; height: auto; font-size: 26px; }

  /* slider full width */
  .slider-wrap { max-width: 100%; }

  /* rewards */
  .rewards-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .rewards-head h2 { font-size: 20px; }
  .history li { flex-direction: column; gap: 2px; }

  /* footer */
  .site-footer { padding: 26px 16px; }
  .site-footer ul { font-size: 13px; }

  .toast { bottom: 14px; font-size: 14px; padding: 12px 18px; width: calc(100% - 28px); text-align: center; }
}

/* very small phones */
@media (max-width: 380px) {
  .captcha-display { font-size: 24px; letter-spacing: 3px; }
  .steps { grid-template-columns: 1fr; }
  .puzzle-cell { font-size: 22px; }
}
