/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0a0e1a;
  --surface:     #111827;
  --surface2:    #1a2236;
  --border:      #1f2d45;
  --border2:     #263550;
  --primary:     #7c3aed;
  --primary-lt:  #a78bfa;
  --accent:      #06b6d4;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --green:       #22c55e;
  --green-bg:    #052e16;
  --green-border:#166534;
  --red:         #f43f5e;
  --red-bg:      #2d0a14;
  --red-border:  #9f1239;
  --yellow:      #f59e0b;
  --orange:      #febc2e;
  --radius:      12px;
  --radius-sm:   8px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Background glow ─────────────────────────────────────────────────────── */
.bg-glow {
  position: fixed;
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 600px;
  background: radial-gradient(ellipse at center, rgba(124,58,237,.13) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,14,26,0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  /* transition for landing → quiz reveal */
  transition: transform 0.5s cubic-bezier(0.34, 1.1, 0.64, 1),
              opacity 0.4s ease;
}
.site-header.header-hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}
.header-inner {
  max-width: 740px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.logo-icon {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--primary-lt);
  background: rgba(124,58,237,.15);
  border: 1px solid rgba(124,58,237,.3);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  letter-spacing: -1px;
  transition: opacity 0.32s ease 0.22s; /* delay lets header slide in first */
}
.site-header.header-hidden .logo-icon {
  opacity: 0;
  transition: none;
}
.logo-icon-letters { color: var(--orange); }
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-title { font-family: 'JetBrains Mono', monospace; font-size: 1.1rem; font-weight: 600; color: var(--text); letter-spacing: -0.02em; }
.logo-u { color: var(--orange); }
.logo-sub   { font-size: .73rem; color: var(--text-muted); }
.question-counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: .88rem;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.main-content {
  max-width: 740px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px 80px;
  position: relative;
  z-index: 1;
  flex: 1;
}

/* Sidebar: fixed, floats right of the centered 740px column.
   Right edge of content = 50vw + 370px. Ad starts 20px beyond that.
   Minimum viewport to fit without overlap: 740 + 2×(20 + 160) = 1100px
   Hidden by default — JS adds .sidebar-visible when quiz starts. */
.quiz-sidebar {
  display: none;
  position: fixed;
  top: 140px; /* overridden by JS once question card is measured */
  left: calc(50% + 370px + 20px);
  width: 160px;
  z-index: 50;
}
@media (min-width: 1100px) {
  .quiz-sidebar { display: block; visibility: hidden; }
  .quiz-sidebar.sidebar-visible { visibility: visible; }
}

/* ── Ad slot placeholder (shown until Carbon Ads script is live) ─────────── */
.carbonads-placeholder {
  width: 160px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.carbonads-stripe {
  height: 260px;
  background: repeating-linear-gradient(
    -45deg,
    #12182a,
    #12182a 6px,
    #161d30 6px,
    #161d30 12px
  );
  border: 1px solid #1e2840;
  border-radius: var(--radius-sm);
  opacity: .5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .05em;
}
.carbonads-cq {
  color: var(--orange);
}

/* ── Carbon Ads — #carbonads is injected by their script; we style it here ── */
#carbonads {
  width: 160px;
  background: #0f1623;
  border: 1px solid #2a3a55;
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: 'Inter', sans-serif;
}
#carbonads .carbon-wrap {
  display: flex;
  flex-direction: column;
}
#carbonads .carbon-img img {
  display: block;
  width: 160px;
  height: auto;
  border-bottom: 1px solid #2a3a55;
}
#carbonads .carbon-text {
  font-size: .8rem;
  color: #cbd5e1;
  line-height: 1.5;
  padding: 12px 12px 10px;
  display: block;
  text-decoration: none;
}
#carbonads .carbon-text:hover { color: #fff; }
#carbonads .carbon-poweredby {
  display: block;
  font-size: .68rem;
  color: var(--text-muted);
  text-align: right;
  padding: 0 10px 10px;
  text-decoration: none;
}
#carbonads .carbon-poweredby:hover { color: var(--text-dim); }
/* Hide the "ads via Carbon" badge — optional, remove if Carbon requires it visible */
/* #carbonads .carbon-poweredby { display: none; } */

/* ── Shared card ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 16px;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════════════════════
   LANDING
   ════════════════════════════════════════════════════════════════════════════ */
#landing-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow: hidden;
  background: var(--bg);
  /* height is animated by JS to collapse toward header height */
}

#hero-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  text-align: center;
  user-select: none;
  /* constrain to viewport so content never clips on narrow screens */
  max-width: calc(100vw - 40px);
  width: max-content;
}

/* ── Landing legal links ───────────────────────────────────────────────────── */
.landing-legal {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  white-space: nowrap;
}
.landing-legal a {
  font-size: .72rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .15s;
}
.landing-legal a:hover { color: var(--text-dim); }

/* ── Hero logo ─────────────────────────────────────────────────────────────── */
#hero-logo {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(2.4rem, 9vw, 5.5rem);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  margin: 0;
  white-space: nowrap;
}
.hero-u { color: var(--orange); }

/* ── Hero subtitle ─────────────────────────────────────────────────────────── */
#hero-sub {
  font-size: 1rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ── Language buttons ──────────────────────────────────────────────────────── */
#lang-buttons {
  display: flex;
  gap: 14px;
  width: 100%;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.lang-btn {
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 0;
  width: 100%;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background .18s, border-color .18s, transform .14s, box-shadow .18s;
}
.lang-btn:hover {
  background: #1b2c45;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(6,182,212,.18);
}
.lang-btn:active { transform: translateY(0); }

/* fade-out helpers applied by JS */
#hero-sub.fade-out,
#lang-buttons.fade-out {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}


/* ════════════════════════════════════════════════════════════════════════════
   QUIZ SCREEN
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Progress ────────────────────────────────────────────────────────────── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width .5s ease;
}


/* ── Difficulty badge ────────────────────────────────────────────────────── */
.difficulty-badge {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid;
  white-space: nowrap;
}
.difficulty-badge.easy   { color: var(--green);  background: rgba(34,197,94,.08);  border-color: rgba(34,197,94,.3);  }
.difficulty-badge.medium { color: var(--yellow); background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.3); }
.difficulty-badge.hard   { color: var(--red);    background: rgba(244,63,94,.08);  border-color: rgba(244,63,94,.3);  }
.difficulty-badge.boss   { color: var(--primary-lt); background: rgba(167,139,250,.08); border-color: rgba(167,139,250,.35); text-shadow: 0 0 10px rgba(167,139,250,.25); }

/* ── Question meta (category tag) ────────────────────────────────────────── */
.question-meta {
  margin-bottom: 10px;
}
.category-tag {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid;
  /* color set inline via JS */
}

/* ── Question text ───────────────────────────────────────────────────────── */
.question-text {
  font-size: .98rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 20px;
}

/* ── Code window ─────────────────────────────────────────────────────────── */
.code-window {
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 24px;
  background: #0d1117;
}
.code-titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #161b22;
  border-bottom: 1px solid var(--border2);
}
.dots { display: flex; gap: 6px; }
.dot  { width: 12px; height: 12px; border-radius: 50%; }
.dot-r { background: #ff5f57; }
.dot-y { background: #febc2e; }
.dot-g { background: #28c840; }
.code-filename {
  font-family: 'JetBrains Mono', monospace;
  font-size: .75rem;
  color: var(--text-muted);
  margin-left: auto;
}
.code-body {
  margin: 0;
  padding: 0;
  background: #0d1117 !important;
  overflow-x: auto;
}
.code-body code {
  font-family: 'JetBrains Mono', monospace !important;
  font-size: .9rem !important;
  line-height: 1.75;
  padding: 18px 20px !important;
  background: #0d1117 !important;
  display: block;
}
.hljs { background: #0d1117 !important; }

/* ── Choices ─────────────────────────────────────────────────────────────── */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 600px) { .choices { grid-template-columns: 1fr; } }

.choice-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: .86rem;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  line-height: 1.5;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: pre-wrap;
  word-break: break-word;
}
.choice-btn:hover:not(:disabled) {
  background: #1f2d45;
  border-color: var(--primary);
  transform: translateY(-1px);
}
.choice-btn:disabled { cursor: default; }
.choice-btn.correct  { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.choice-btn.incorrect{ background: var(--red-bg);   border-color: var(--red);   color: var(--red);   }

/* ── Feedback card ───────────────────────────────────────────────────────── */
.feedback-card { border-color: var(--border2); transition: border-color .2s; }
.feedback-card.correct   { border-color: var(--green); }
.feedback-card.incorrect { border-color: var(--red);   }

.feedback-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: .9rem;
  font-weight: 700;
  flex-shrink: 0;
}
.feedback-card.correct   .status-icon { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.feedback-card.incorrect .status-icon { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red);   }
.status-text { font-size: 1.1rem; font-weight: 700; }
.feedback-card.correct   .status-text { color: var(--green); }
.feedback-card.incorrect .status-text { color: var(--red);   }

.feedback-answer {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: rgba(6,182,212,.05);
  border: 1px solid rgba(6,182,212,.18);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.answer-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  white-space: nowrap;
}
.answer-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: .88rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
}

.feedback-explanation {
  font-size: .93rem;
  color: var(--text-dim);
  line-height: 1.75;
  margin-bottom: 20px;
}
.feedback-explanation code {
  font-family: 'JetBrains Mono', monospace;
  font-size: .85em;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--primary-lt);
}
.feedback-explanation strong { color: var(--text); font-weight: 600; }

/* ── Tooltip term (replaces <strong> when a glossary match exists) ─────────── */
.tooltip-term {
  font-weight: 600;
  color: var(--text);
  cursor: help;
  border-bottom: 1px dashed rgba(167, 139, 250, 0.5); /* subtle purple underline */
  transition: border-color .15s;
}
.tooltip-term:hover {
  border-bottom-color: var(--primary-lt);
}

/* ── Floating tooltip popup ─────────────────────────────────────────────────── */
.tooltip-popup {
  position: fixed;
  z-index: 9999;
  width: 248px;
  background: #1a2236;
  color: var(--text-dim);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-family: 'Inter', sans-serif;
  font-size: .8rem;
  font-weight: 400;
  line-height: 1.55;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
  opacity: 0;
  transition: opacity .14s ease;
}
.tooltip-popup.visible { opacity: 1; }

/* ── Ad placeholder (horizontal banner — end screen) ────────────────────── */
.ad-placeholder {
  position: relative;
  width: 100%;
  height: 90px;
  background: #0f1623;
  border: 1px solid #2a3a55;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
}
.ad-badge {
  position: absolute;
  top: 5px;
  right: 8px;
  font-family: 'Inter', sans-serif;
  font-size: .6rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .6;
}
.ad-inner {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 16px;
  padding: 0 16px 0 0;
}
.ad-thumb {
  width: 90px;
  height: 90px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f2340 100%);
  border-right: 1px solid #2a3a55;
  position: relative;
}
.ad-thumb::after {
  content: '{ }';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: #3b82f6;
  opacity: .7;
}
.ad-copy {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.ad-headline {
  font-family: 'Inter', sans-serif;
  font-size: .88rem;
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ad-sub {
  font-family: 'Inter', sans-serif;
  font-size: .74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ad-cta {
  flex-shrink: 0;
  font-family: 'Inter', sans-serif;
  font-size: .78rem;
  font-weight: 600;
  color: #fff;
  background: #2563eb;
  border-radius: 6px;
  padding: 7px 14px;
  white-space: nowrap;
}

@media (max-width: 540px) {
  .ad-placeholder  { height: 50px; }
  .ad-thumb        { width: 50px; height: 50px; }
  .ad-thumb::after { font-size: .8rem; }
  .ad-sub          { display: none; }
  .ad-headline     { font-size: .78rem; }
  .ad-cta          { font-size: .72rem; padding: 5px 10px; }
  .ad-inner        { gap: 10px; }
}

.feedback-footer { display: flex; justify-content: flex-end; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Inter', sans-serif;
  font-size: .93rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 11px 22px;
  transition: opacity .15s, transform .12s;
}
.btn:hover  { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #5b21b6);
  color: #fff;
  box-shadow: 0 4px 18px rgba(124,58,237,.28);
}
.btn-primary:disabled {
  opacity: .38;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}


/* ════════════════════════════════════════════════════════════════════════════
   END SCREEN
   ════════════════════════════════════════════════════════════════════════════ */
.end-card { text-align: center; padding: 48px 32px; }
.end-trophy {
  font-family: 'JetBrains Mono', monospace;
  font-size: .9rem;
  color: var(--yellow);
  background: rgba(245,158,11,.08);
  border: 1px solid rgba(245,158,11,.28);
  border-radius: var(--radius-sm);
  display: inline-block;
  padding: 4px 14px;
  margin-bottom: 20px;
  letter-spacing: .05em;
}
.end-title  { font-size: 2rem; font-weight: 800; margin-bottom: 6px; letter-spacing: -.03em; }
.end-subtitle { color: var(--text-dim); margin-bottom: 20px; font-size: 1.05rem; }
.end-grade  { font-size: 1.4rem; font-weight: 700; margin-bottom: 32px; }
.grade-perfect { color: var(--yellow); }
.grade-expert  { color: var(--green);  }
.grade-mid     { color: var(--accent); }
.grade-low     { color: var(--text-dim); }

.end-actions { display: flex; justify-content: center; }

/* ── Site footer ─────────────────────────────────────────────────────────── */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 18px 20px;
  margin-top: 40px;
}
.site-footer-copy {
  font-size: .75rem;
  color: var(--text-muted);
}
.site-footer-links {
  display: flex;
  gap: 16px;
}
.site-footer-links a {
  font-size: .75rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .15s;
}
.site-footer-links a:hover { color: var(--text-dim); }

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes slideIn    { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }
@keyframes slideOut   { from { opacity:1; transform:translateX(0);     } to { opacity:0; transform:translateX(-18px); } }
@keyframes quizReveal { from { opacity:0; transform:translateY(22px); } to { opacity:1; transform:translateY(0); } }

.quiz-reveal {
  animation: quizReveal 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.slide-in  { animation: slideIn  .26s ease forwards; }
.slide-out { animation: slideOut .17s ease forwards; }

.feedback-card:not(.hidden) { animation: slideIn .23s ease forwards; }

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Tablet / large phone (≤ 680px) ─────────────────────────────────────── */
@media (max-width: 680px) {
  .main-content    { padding: 24px 16px 60px; }
  .card            { padding: 22px 18px; }
  .end-card        { padding: 36px 20px; }
}

/* ── Phone portrait (≤ 480px) ───────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Header */
  .header-inner  { padding: 10px 14px; }
  .logo-icon     { font-size: 1rem; padding: 3px 7px; }
  .logo-title    { font-size: .92rem; }

  /* Cards */
  .card          { padding: 16px 14px; }
  .end-card      { padding: 28px 16px; }
  .end-title     { font-size: 1.5rem; }

  /* Code block */
  .code-body code {
    font-size: .78rem !important;
    padding: 14px 14px !important;
    line-height: 1.65;
  }

  /* Feedback answer: stack label above value on small screens */
  .feedback-answer {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .answer-label { width: 100%; }

  /* Tooltip: narrower so it fits without edge-clipping */
  .tooltip-popup { width: 200px; font-size: .76rem; }

  /* Progress badge text fits */
  .difficulty-badge { font-size: .66rem; padding: 2px 8px; }
}

/* ── Landscape phone / very short viewport ──────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  #hero-content { gap: 16px; }
  #hero-logo    { font-size: clamp(1.8rem, 6vw, 2.8rem); }
  #hero-sub     { font-size: .85rem; }
  .lang-btn     { padding: 8px 0; }
}
