/* ============================================================================
   quiz.css | Quiz engine, result, review, leaderboard & dashboard components
   ========================================================================== */

/* ------------------------------------------------------------ QUIZ TOP BAR */
.quiz-topbar {
  position: sticky; top: var(--header-h); z-index: 60;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.quiz-topbar-inner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.quiz-title { font-size: 1rem; font-weight: 800; line-height: 1.2; }
.quiz-title small { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; }

.timers { display: flex; gap: 8px; margin-left: auto; }
.timer-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 0.85rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.timer-pill.small { font-size: 0.78rem; padding: 5px 11px; }
.timer-pill.warn { border-color: var(--warning); color: var(--warning); }
.timer-pill.danger { border-color: var(--danger); color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

/* Progress bar */
.progress-track {
  height: 8px; border-radius: 999px;
  background: var(--surface-2); overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%; border-radius: 999px;
  background: var(--brand-grad);
  transition: width 0.45s var(--ease);
}
.progress-meta {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--muted); font-weight: 700; margin-top: 7px;
}

/* ------------------------------------------------------------ QUIZ LAYOUT */
.quiz-layout {
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  padding: 22px 0 40px;
}

/* Question card */
.q-card { padding: clamp(18px, 3vw, 30px); }

/* --- STABLE GEOMETRY (kills Cumulative Layout Shift) -----------------------
   The question body keeps a constant footprint: 2 reserved lines of question
   text + 4 reserved option rows. Shorter content fills the reserve, longer
   content grows past it — but the nav buttons below never move vertically
   between questions, and selecting an answer changes nothing at all. */
.q-body { position: relative; }
.q-head {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.q-number {
  display: inline-grid; place-items: center;
  min-width: 44px; height: 34px; padding: 0 12px;
  border-radius: 10px;
  background: var(--brand-grad); color: #fff;
  font-weight: 800; font-size: 0.9rem;
}
.q-text {
  font-size: clamp(1.02rem, 2.2vw, 1.2rem);
  font-weight: 700; line-height: 1.55;
  min-height: 3.1em; /* reserve 2 lines — 1-line ↔ 3-line questions don't shift the options */
  margin-bottom: 20px;
}
.q-text + .q-text { margin-top: -12px; }

/* Options */
.options {
  --opt-row: 63px;  /* one option row: 28px padding + 32px key + 3px border */
  --opt-gap: 11px;
  display: grid; gap: var(--opt-gap);
  /* reserve 4 rows so the control bar sits at the same place on every question */
  min-height: calc(4 * var(--opt-row) + 3 * var(--opt-gap));
}
.option {
  display: flex; align-items: center; gap: 13px;
  width: 100%; text-align: left;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 0.97rem; font-weight: 500;
  transition: all 0.18s var(--ease);
}
.option:hover:not(:disabled) {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
  transform: translateX(4px);
}
.option .opt-key {
  flex: none; width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-weight: 800; font-size: 0.85rem;
}
.option.selected {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 11%, var(--surface));
  box-shadow: 0 0 0 4px var(--ring);
}
.option.selected .opt-key { background: var(--brand-grad); color: #fff; border-color: transparent; }
.option:disabled { cursor: not-allowed; opacity: 0.75; }

/* Question controls */
.q-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.q-controls .grow { flex: 1 1 auto; }

/* ------------------------------------------------- QUESTION FADE (JS-added)
   Runs ONLY when the question changes (never on answer selection). The
   transform is GPU-only — it cannot shift layout or move the scroll pos. */
.q-body.q-enter { animation: qFadeIn 0.17s var(--ease); }
@keyframes qFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .q-body.q-enter { animation: none; }
}

/* -------------------------------------------------------- QUESTION PALETTE */
.palette-card { padding: 20px; }
.palette-card h4 {
  font-size: 0.78rem; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px;
}
.palette {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 9px;
}
.pal-btn {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 11px;
  font-weight: 800; font-size: 0.88rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text-2);
  transition: all 0.16s var(--ease);
}
.pal-btn:hover { transform: translateY(-2px); border-color: var(--brand); }
.pal-btn.answered { background: color-mix(in srgb, var(--success) 16%, var(--surface)); border-color: var(--success); color: var(--success); }
.pal-btn.marked { background: color-mix(in srgb, var(--warning) 18%, var(--surface)); border-color: var(--warning); color: var(--warning); }
.pal-btn.answered.marked { background: color-mix(in srgb, var(--warning) 18%, var(--surface)); border-color: var(--warning); color: var(--warning); }
.pal-btn.current { box-shadow: 0 0 0 3px var(--ring); border-color: var(--brand); }
.pal-btn.visited:not(.answered):not(.marked) { border-style: dashed; }

.legend { display: grid; gap: 9px; margin-top: 18px; font-size: 0.79rem; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 9px; }
.legend .sw { width: 17px; height: 17px; border-radius: 5px; border: 1.5px solid var(--border); flex: none; }
.legend .sw.ok { background: color-mix(in srgb, var(--success) 30%, transparent); border-color: var(--success); }
.legend .sw.mk { background: color-mix(in srgb, var(--warning) 34%, transparent); border-color: var(--warning); }
.legend .sw.no { background: var(--surface-2); }
.legend .sw.vs { background: var(--surface-2); border-style: dashed; }

/* Telegram side card */
.side-telegram {
  padding: 20px; text-align: center;
  background: linear-gradient(150deg, #229ed9, #1c7fb4 60%, #4f46e5 160%);
  color: #fff; border: 0;
}
.side-telegram h4 { font-size: 1rem; margin-bottom: 6px; }
.side-telegram p { font-size: 0.85rem; opacity: 0.92; margin-bottom: 14px; }
.side-telegram .btn { background: #fff; color: #1478a8; border: 0; }

/* Locked / submitted overlay */
.lock-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn 0.3s var(--ease);
}
.lock-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 34px; max-width: 430px;
  text-align: center; box-shadow: var(--shadow-lg);
}
.lock-box .lk-icon {
  width: 66px; height: 66px; margin: 0 auto 15px;
  border-radius: 20px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--warning) 16%, transparent); font-size: 1.7rem;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ----------------------------------------------------------------- RESULTS */
.result-hero {
  text-align: center;
  padding: clamp(34px, 6vw, 58px) 0 clamp(24px, 4vw, 36px);
  background:
    radial-gradient(700px 320px at 50% -20%, color-mix(in srgb, var(--brand) 24%, transparent), transparent 65%),
    var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.score-ring {
  --pct: 0;
  width: 176px; height: 176px; margin: 0 auto 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  background:
    radial-gradient(closest-side, var(--surface) 78%, transparent 79% 100%),
    conic-gradient(var(--brand) calc(var(--pct) * 1%), var(--border) 0);
  box-shadow: var(--shadow-lg);
}
.score-ring .sr-inner { text-align: center; }
.score-ring .sr-val { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.score-ring .sr-lab { font-size: 0.75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }

.verdict { font-size: clamp(1.4rem, 3.4vw, 2rem); font-weight: 800; margin-bottom: 6px; }
.verdict.pass { color: var(--success); }
.verdict.fail { color: var(--danger); }
.perf-msg { color: var(--text-2); max-width: 60ch; margin: 0 auto 18px; }

.result-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-top: -30px; position: relative; z-index: 2; }
.rs-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px 14px; text-align: center;
  box-shadow: var(--shadow);
}
.rs-val { font-size: clamp(1.25rem, 3vw, 1.7rem); font-weight: 800; letter-spacing: -0.03em; }
.rs-lab { font-size: 0.76rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.rs-card.ok .rs-val { color: var(--success); }
.rs-card.bad .rs-val { color: var(--danger); }
.rs-card.warn .rs-val { color: var(--warning); }

/* Subject-wise performance bars */
.perf-list { display: grid; gap: 16px; }
.perf-row .pr-head { display: flex; justify-content: space-between; font-size: 0.9rem; font-weight: 700; margin-bottom: 7px; }
.perf-row .pr-track { height: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.perf-row .pr-fill { height: 100%; background: var(--brand-grad); border-radius: 999px; transition: width 0.8s var(--ease); }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 9px; }
.area-chip {
  padding: 8px 15px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 700;
  border: 1.5px solid var(--border); background: var(--surface);
}
.area-chip.weak { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.area-chip.strong { border-color: color-mix(in srgb, var(--success) 45%, transparent); color: var(--success); background: color-mix(in srgb, var(--success) 8%, var(--surface)); }

/* ------------------------------------------------------------ ANSWER REVIEW */
.review-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip-filter {
  padding: 8px 16px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 0.85rem; font-weight: 700; color: var(--text-2);
  transition: all 0.18s var(--ease);
}
.chip-filter:hover { border-color: var(--brand); color: var(--brand); }
.chip-filter.active { background: var(--brand-grad); color: #fff; border-color: transparent; }

.review-item {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px; margin-bottom: 14px;
}
.review-item.correct { border-left-color: var(--success); }
.review-item.wrong { border-left-color: var(--danger); }
.review-item.skipped { border-left-color: var(--muted); }
.review-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.review-q { font-weight: 700; font-size: 0.99rem; flex: 1; }
.review-ans { display: grid; gap: 8px; margin-bottom: 12px; }
.ans-line {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 0.92rem; padding: 9px 13px;
  border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border);
}
.ans-line .tag { font-weight: 800; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; flex: none; }
.ans-line.ok { border-color: color-mix(in srgb, var(--success) 40%, transparent); background: color-mix(in srgb, var(--success) 8%, var(--surface)); }
.ans-line.ok .tag { color: var(--success); }
.ans-line.bad { border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 7%, var(--surface)); }
.ans-line.bad .tag { color: var(--danger); }
.review-note {
  font-size: 0.89rem; color: var(--text-2);
  padding: 11px 14px; border-radius: 11px;
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--brand) 20%, transparent);
  margin-bottom: 8px;
}
.review-note b { color: var(--brand); }
.review-ref { font-size: 0.83rem; color: var(--muted); }

/* --------------------------------------------------------------- LEADERBOARD */
.lead-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.lead-table { width: 100%; border-collapse: collapse; }
.lead-table th, .lead-table td { padding: 13px 12px; text-align: left; font-size: 0.92rem; }
.lead-table th {
  font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--border);
}
.lead-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
.lead-table tbody tr:hover { background: var(--surface-2); }
.lead-table tbody tr.is-me { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.rank-badge {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  font-weight: 800; font-size: 0.88rem;
  background: var(--surface-2); border: 1.5px solid var(--border);
}
.rank-badge.r1 { background: linear-gradient(135deg, #fde68a, #f59e0b); border-color: #f59e0b; color: #7c4a03; }
.rank-badge.r2 { background: linear-gradient(135deg, #e5e7eb, #9ca3af); border-color: #9ca3af; color: #374151; }
.rank-badge.r3 { background: linear-gradient(135deg, #fdba74, #ea580c); border-color: #ea580c; color: #7c2d12; }
.table-scroll { overflow-x: auto; }

/* --------------------------------------------------------------- DASHBOARD */
.dash-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px;
  box-shadow: var(--shadow);
}
.dash-card .dc-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.15rem;
  background: color-mix(in srgb, var(--brand) 12%, transparent); margin-bottom: 10px;
}
.dash-card .dc-val { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.03em; }
.dash-card .dc-lab { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.streak-flame { display: inline-flex; align-items: center; gap: 6px; color: var(--brand-3); font-weight: 800; }

.badge-grid { display: grid; gap: 13px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.badge-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--r-md); padding: 16px 12px; text-align: center;
  transition: transform 0.2s var(--ease);
}
.badge-card:hover { transform: translateY(-4px); }
.badge-card .bd-emoji { font-size: 1.9rem; margin-bottom: 7px; filter: grayscale(1); opacity: 0.4; }
.badge-card.earned { border-color: color-mix(in srgb, var(--success) 45%, transparent); background: color-mix(in srgb, var(--success) 7%, var(--surface)); }
.badge-card.earned .bd-emoji { filter: none; opacity: 1; }
.badge-card h5 { font-size: 0.87rem; font-weight: 800; margin-bottom: 3px; }
.badge-card p { font-size: 0.74rem; color: var(--muted); }

/* ----------------------------------------------------------- MOCK BUILDER */
.mock-option {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border: 1.5px solid var(--border);
  border-radius: var(--r-md); background: var(--surface);
  cursor: pointer; transition: all 0.18s var(--ease);
  font-weight: 600; font-size: 0.94rem;
}
.mock-option:hover { border-color: var(--brand); transform: translateY(-2px); }
.mock-option input { accent-color: var(--brand); width: 18px; height: 18px; }
.mock-option.selected { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); box-shadow: 0 0 0 3px var(--ring); }

.field label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--text-2); margin-bottom: 7px; }
.field select, .field input[type="text"], .field input[type="email"], .field textarea {
  width: 100%; padding: 12px 15px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field select:focus, .field input:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring);
}

/* -------------------------------------------------------------- BOOKMARKS */
.bookmark-card { padding: 18px 20px; }
.bm-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.bm-q { font-weight: 700; margin-bottom: 12px; }
.bm-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 12px; }
.bm-answer { display: none; margin-top: 10px; }
.bm-answer.show { display: block; animation: fadeIn 0.25s var(--ease); }

/* ----------------------------------------------------------- RESPONSIVE */
@media (min-width: 760px) {
  .result-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1000px) {
  .quiz-layout {
    grid-template-columns: minmax(0, 1fr) 330px;
    align-items: start;
    /* STICKY TRAVEL ROOM: a grid item can only stick inside its own row, and
       the palette column is nearly as tall as the question column. This floor
       guarantees ≥ ~200px of pinning range at every viewport height, so the
       palette stays parked below the top bar while you answer. Adds ~110px of
       breathing space below the columns when natural content is shorter. */
    min-height: 800px;
  }
  /* STICKY side panel: parks exactly below header + top bar (JS publishes
     --topbar-h). Capped so it always stays shorter than its grid row; inner
     scroll + overscroll containment → wheeling over the palette scrolls ONLY
     the palette, never the page. */
  .quiz-side {
    position: sticky;
    top: calc(var(--header-h) + var(--topbar-h, 90px) + 12px);
    display: grid; gap: 16px;
    max-height: min(680px, calc(100vh - var(--header-h) - var(--topbar-h, 90px) - 26px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 999px) {
  .quiz-side { display: grid; gap: 16px; }
}

@media (max-width: 480px) {
  .q-controls .btn { flex: 1 1 calc(50% - 10px); }
  .timers { width: 100%; margin-left: 0; justify-content: space-between; }
}
