/* ── RESET + TOKENS ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:   #050c1a;
    --bg2:  #0c1830;
    --line: rgba(120,170,255,0.18);
    --soft: rgba(180,210,255,0.65);
    --text: #e8f0ff;

    /* Answer colors A B C D */
    --a: #00bcd4;  --a-bg: rgba(0,188,212,0.15);
    --b: #ff9800;  --b-bg: rgba(255,152,0,0.15);
    --c: #9c27b0;  --c-bg: rgba(156,39,176,0.15);
    --d: #4caf50;  --d-bg: rgba(76,175,80,0.15);

    --ok:   #45e58a;
    --bad:  #ff6b7a;
    --gold: #ffd740;
}

body {
    font-family: "Segoe UI", system-ui, Arial, sans-serif;
    background:
        radial-gradient(ellipse 130% 80% at 18% -12%, rgba(100,160,255,0.2) 0%, transparent 52%),
        radial-gradient(ellipse 100% 70% at 88% 4%,  rgba(140,80,255,0.18) 0%, transparent 50%),
        linear-gradient(180deg, var(--bg2) 0%, var(--bg) 100%);
    background-attachment: fixed;
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}
.hidden { display: none !important; }

.screen {
    width: 100vw;
    height: 100vh;
    position: fixed;
    inset: 0;
}

/* ── SETUP ──────────────────────────────────────────────── */
.setup-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
}
.globe-anim {
    font-size: 5rem;
    display: inline-block;
    animation: globe-spin 6s linear infinite;
}
@keyframes globe-spin {
    0%   { transform: scale(1)   rotateY(0deg); }
    50%  { transform: scale(1.1) rotateY(180deg); }
    100% { transform: scale(1)   rotateY(360deg); }
}
.setup-content h1 { font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 800; letter-spacing: 1px; }
.setup-content p  { color: var(--soft); font-size: 1.2rem; }
.back-link { color: #88b8ff; text-decoration: none; font-size: 1rem; }
.back-link:hover { text-decoration: underline; }

/* ── LOBBY ──────────────────────────────────────────────── */
.lobby-header {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: rgba(0,0,0,0.35);
    border-bottom: 1px solid var(--line);
    gap: 18px;
}
/* category + question count controls */
.lobby-controls {
    display: flex; align-items: center; gap: 20px; flex: 1; justify-content: center;
}
.qs-wrap, .category-wrap { display: flex; align-items: center; gap: 8px; }
.cat-label { font-size: 0.85rem; color: var(--soft); white-space: nowrap; }
.cat-select {
    padding: 7px 12px; border-radius: 10px;
    border: 1px solid rgba(120,170,255,0.35);
    background: rgba(8,15,32,0.8); color: #fff;
    font-size: 0.92rem; font-family: inherit; cursor: pointer; outline: none;
}
.cat-select:focus { border-color: rgba(120,170,255,0.65); }
.logo-text {
    font-size: clamp(1.4rem, 2.6vw, 2rem);
    font-weight: 800;
    letter-spacing: 2px;
    text-shadow: 0 0 30px rgba(100,180,255,0.45);
}
.room-badge {
    font-size: clamp(1rem, 1.8vw, 1.4rem);
    font-weight: 700;
    background: rgba(100,160,255,0.12);
    border: 1.5px solid rgba(100,160,255,0.35);
    border-radius: 999px;
    padding: 8px 24px;
    letter-spacing: 4px;
    color: #88c8ff;
}
.lobby-body {
    height: calc(100vh - 72px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    align-items: center;
}
.lobby-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    height: 100%;
    border-right: 1px solid var(--line);
    padding: 30px;
}
.qr-pulse-ring {
    position: relative;
    display: inline-block;
    padding: 14px;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 0 0 8px rgba(0,188,212,0.25), 0 0 0 16px rgba(0,188,212,0.12), 0 0 70px rgba(0,188,212,0.3);
    animation: qr-pulse 2.8s ease-in-out infinite;
}
@keyframes qr-pulse {
    0%,100% { box-shadow: 0 0 0 8px rgba(0,188,212,0.25), 0 0 0 16px rgba(0,188,212,0.12), 0 0 70px rgba(0,188,212,0.28); }
    50%      { box-shadow: 0 0 0 12px rgba(0,188,212,0.4), 0 0 0 24px rgba(0,188,212,0.18), 0 0 90px rgba(0,188,212,0.45); }
}
.qr-grid img {
    display: block;
    width: clamp(200px, 22vw, 310px);
    height: clamp(200px, 22vw, 310px);
    border-radius: 6px;
}
.scan-label {
    text-align: center;
    color: var(--soft);
    font-size: clamp(0.95rem, 1.7vw, 1.25rem);
    line-height: 1.7;
}
.scan-label strong { color: var(--text); }
.lobby-right {
    display: flex;
    flex-direction: column;
    padding: 30px 44px;
    gap: 16px;
    height: 100%;
    justify-content: center;
}
.lb-heading {
    font-size: clamp(1.1rem, 2.2vw, 1.6rem);
    font-weight: 700;
    color: #88c8ff;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
    letter-spacing: 1px;
}
.lobby-player-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 45vh;
    overflow-y: auto;
}
.lobby-player-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.05);
    border: 1.5px solid rgba(255,255,255,0.14);
    border-radius: 14px;
    padding: 12px 18px;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    font-weight: 600;
    animation: slide-in 0.3s ease;
    transition: border-color 0.3s, background 0.3s;
}
.lobby-player-list li.ready {
    border-color: var(--ok);
    background: rgba(69,229,138,0.08);
}
@keyframes slide-in {
    from { opacity: 0; transform: translateX(-14px); }
    to   { opacity: 1; transform: none; }
}
.lobby-status-text {
    color: var(--soft);
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    min-height: 1.3em;
}
.countdown-big {
    font-size: clamp(2.5rem, 6vw, 5rem);
    font-weight: 900;
    color: var(--ok);
    text-shadow: 0 0 50px rgba(69,229,138,0.55);
    text-align: center;
    min-height: 1.2em;
    animation: countdown-pop 0.45s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes countdown-pop {
    from { transform: scale(1.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* ── QUIZ: TOP PROGRESS BAR ──────────────────────────────── */
.progress-track {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: rgba(255,255,255,0.07);
    z-index: 20;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--a), #7b61ff);
    transition: width 0.55s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 14px rgba(0,229,255,0.55);
}

//* ── QUIZ: PER-QUESTION TIMER BAR ───────────────────────── */
.question-timer-track {
    position: absolute;
    top: 5px; left: 0; right: 0;   /* sits just below the thin progress bar */
    height: 6px;
    background: rgba(255,255,255,0.06);
    z-index: 19;
}
.question-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--bad) 0%, var(--gold) 50%, var(--ok) 100%);
    background-size: 200%;
    transform-origin: left center;
    transition: width 15s linear;
}

/* ── QUIZ: HEADER ROW ────────────────────────────────────── */
.quiz-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 60px;
    background: rgba(0,0,0,0.38);
    border-bottom: 1px solid var(--line);
    position: relative;
}
.q-num {
    font-size: clamp(0.9rem, 1.6vw, 1.25rem);
    font-weight: 700;
    color: #88c8ff;
    letter-spacing: 1px;
}
.q-title {
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--soft);
}
.answers-chip {
    font-size: clamp(0.85rem, 1.4vw, 1.1rem);
    font-weight: 700;
    background: rgba(100,180,255,0.12);
    border: 1px solid rgba(100,180,255,0.28);
    border-radius: 999px;
    padding: 6px 18px;
    color: #aacfff;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}
.answers-chip.all-answered {
    background: rgba(69,229,138,0.18);
    border-color: var(--ok);
    color: var(--ok);
}

/* ── QUIZ: BODY LAYOUT ───────────────────────────────────── */
.quiz-body {
    display: grid;
    grid-template-columns: 270px 1fr;
    height: calc(100vh - 65px);
    overflow: hidden;
}

/* ── LEADERBOARD ─────────────────────────────────────────── */
.leaderboard {
    background: rgba(0,0,0,0.28);
    border-right: 1px solid var(--line);
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.lb-label {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 4px;
    color: var(--soft);
    text-align: center;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}
.stats-panel { display: flex; flex-direction: column; gap: 8px; }

.stat-card {
    background: rgba(255,255,255,0.045);
    border: 1.5px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 9px 12px;
    position: relative;
    transition: border-color 0.4s, background 0.4s, transform 0.3s;
}
.stat-card.rank-1 { border-color: rgba(255,215,64,0.55); background: rgba(255,215,64,0.07); }
.stat-card.rank-2 { border-color: rgba(192,192,192,0.45); }
.stat-card.rank-3 { border-color: rgba(205,127,50,0.4); }
.stat-card .rank-num {
    position: absolute; top: 8px; right: 10px;
    font-size: 0.72rem; font-weight: 900; color: var(--soft);
}
.stat-card.rank-1 .rank-num { color: var(--gold); }
.stat-card .sname {
    font-size: 0.92rem; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    padding-right: 22px;
}
.stat-card .sscore {
    font-size: 1.1rem; font-weight: 900; color: var(--gold); margin-top: 3px;
}
.stat-card .sacc { font-size: 0.72rem; color: var(--soft); margin-top: 2px; }

/* ── QUESTION AREA ───────────────────────────────────────── */
.q-area {
    display: flex;
    flex-direction: column;
    padding: 16px 28px 12px;
    gap: 12px;
    overflow: hidden;
    height: calc(100vh - 65px);
}
.question-text {
    flex: 1;                    /* fills all space above options */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.8rem, 3.8vw, 3.6rem);
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    padding: 0 24px;
    text-shadow: 0 2px 28px rgba(120,180,255,0.3);
    animation: q-enter 0.38s cubic-bezier(.4,0,.2,1);
}
@keyframes q-enter {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: none; }
}

/* ── OPTIONS GRID ────────────────────────────────────────── */
.options-grid {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    flex: 0 0 50vh;             /* exactly half the screen height */
    min-height: 0;
}
.options-grid li {
    display: flex;
    align-items: center;
    gap: 14px;
    border-radius: 16px;
    padding: 0 20px;
    font-size: clamp(1.05rem, 1.9vw, 1.65rem);
    font-weight: 700;
    border: 2.5px solid;
    transition: transform 0.28s, opacity 0.32s, filter 0.32s, box-shadow 0.32s;
    animation: opt-pop 0.32s cubic-bezier(.34,1.56,.64,1) backwards;
    overflow: hidden;
    position: relative;
}
/* All options — uniform blue-slate colour */
.options-grid li:nth-child(1) { background: rgba(80,115,220,0.16); border-color: rgba(110,150,240,0.65); animation-delay: 0.04s; }
.options-grid li:nth-child(2) { background: rgba(80,115,220,0.16); border-color: rgba(110,150,240,0.65); animation-delay: 0.09s; }
.options-grid li:nth-child(3) { background: rgba(80,115,220,0.16); border-color: rgba(110,150,240,0.65); animation-delay: 0.14s; }
.options-grid li:nth-child(4) { background: rgba(80,115,220,0.16); border-color: rgba(110,150,240,0.65); animation-delay: 0.19s; }
@keyframes opt-pop {
    from { opacity: 0; transform: scale(0.88); }
    to   { opacity: 1; transform: none; }
}
.opt-letter {
    width: 40px; height: 40px; min-width: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 900;
    flex-shrink: 0;
    background: rgba(110,150,240,0.55);
    color: #fff;
}
.opt-text { flex: 1; line-height: 1.25; }

/* ── Reveal: correct answer → GREEN ─────────────────────── */
.options-grid li.answer-correct {
    background: rgba(69,229,138,0.22) !important;
    border-color: var(--ok) !important;
    box-shadow: 0 0 0 3px var(--ok), 0 0 52px rgba(69,229,138,0.55);
    animation: correct-bounce 0.5s cubic-bezier(.34,1.56,.64,1) forwards,
               correct-glow   1.8s 0.5s ease-in-out infinite;
    z-index: 2;
}
.options-grid li.answer-correct .opt-letter {
    background: var(--ok);
    color: #001a08;
}
@keyframes correct-bounce {
    0%   { transform: scale(1);     }
    55%  { transform: scale(1.07);  }
    100% { transform: scale(1.045); }
}
@keyframes correct-glow {
    0%,100% { filter: brightness(1.35); }
    50%     { filter: brightness(1.65); }
}
/* big ✓ badge */
.options-grid li.answer-correct::after {
    content: '✓';
    position: absolute; right: 18px;
    font-size: 2.6rem; font-weight: 900; color: var(--ok); opacity: 0;
    animation: check-pop 0.42s 0.18s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes check-pop {
    from { transform: scale(0) rotate(-25deg); opacity: 0; }
    to   { transform: scale(1) rotate(0deg);   opacity: 0.85; }
}

/* ── Reveal: wrong answers (fade in after 320 ms delay set in JS) ── */
.options-grid li.answer-wrong {
    opacity: 0.22;
    filter: grayscale(0.75);
    transform: scale(0.96);
    transition: opacity 0.35s ease, filter 0.35s ease, transform 0.35s ease;
}

/* ── ACTION BUTTONS ──────────────────────────────────────── */
.quiz-actions {
    display: flex; gap: 12px; justify-content: flex-end; flex-shrink: 0;
}
.action-btn {
    border: 0; border-radius: 12px;
    padding: 12px 24px;
    font-size: clamp(0.9rem, 1.4vw, 1.1rem); font-weight: 700;
    color: #fff; cursor: pointer; letter-spacing: 0.3px;
    background: linear-gradient(135deg, #3b68e0 0%, #5b36c6 100%);
    transition: transform 0.15s, filter 0.15s, box-shadow 0.15s;
}
.action-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.1); box-shadow: 0 8px 22px rgba(80,70,220,0.4); }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.next-btn { background: linear-gradient(135deg, #1b7a5a 0%, #0d5e40 100%); }
.next-btn:hover:not(:disabled) { box-shadow: 0 8px 22px rgba(20,180,100,0.38); }

/* ── RESULT PANEL ────────────────────────────────────────── */
.result-panel {
    position: absolute;
    bottom: 0; left: 270px; right: 0;
    max-height: 40vh;
    overflow-y: auto;
    background: linear-gradient(0deg, rgba(4,10,22,0.97) 0%, rgba(6,14,28,0.92) 100%);
    border-top: 1px solid var(--line);
    padding: 16px 28px 20px;
    animation: slide-up 0.35s cubic-bezier(.4,0,.2,1);
}
@keyframes slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
.result-panel h3 {
    font-size: clamp(0.95rem, 1.7vw, 1.35rem);
    margin-bottom: 10px; color: var(--gold);
}
.result-panel .result-timer {
    color: var(--soft); font-size: 0.88rem; margin-bottom: 10px;
}
.result-chips {
    display: flex; flex-wrap: wrap; gap: 8px;
}
.result-chip {
    font-size: clamp(0.8rem, 1.3vw, 0.96rem);
    font-weight: 700;
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.14);
}
.result-ok  { color: var(--ok);  border-color: rgba(69,229,138,0.4)  !important; background: rgba(69,229,138,0.1) !important; }
.result-bad { color: var(--bad); border-color: rgba(255,107,122,0.4) !important; background: rgba(255,107,122,0.08) !important; }

/* Final ranking (full-screen result state) */
.result-panel.final {
    position: absolute;
    inset: 60px 0 0 0;
    max-height: none;
    left: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 40px;
    background: rgba(4,10,22,0.97);
    border-top: none;
    animation: fade-in 0.5s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.result-panel.final h3 {
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    text-align: center;
    color: var(--gold);
    text-shadow: 0 0 40px rgba(255,215,64,0.4);
    letter-spacing: 1px;
}
.final-rows { display: flex; flex-direction: column; gap: 12px; width: min(620px, 88%); }
.final-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 20px;
    border-radius: 16px;
    background: rgba(255,255,255,0.05);
    border: 1.5px solid rgba(255,255,255,0.12);
    font-size: clamp(1rem, 1.8vw, 1.3rem);
    animation: slide-in 0.4s ease backwards;
}
.final-row:nth-child(1) { border-color: rgba(255,215,64,0.6); background: rgba(255,215,64,0.08); animation-delay: 0.1s; }
.final-row:nth-child(2) { border-color: rgba(192,192,192,0.5); animation-delay: 0.2s; }
.final-row:nth-child(3) { border-color: rgba(205,127,50,0.45); animation-delay: 0.3s; }
.final-row:nth-child(n+4) { animation-delay: 0.4s; }
.final-medal { font-size: 1.5rem; }
.final-name  { flex: 1; font-weight: 700; }
.final-pts   { font-weight: 900; color: var(--gold); font-size: 1.1em; }
.final-pct   { font-size: 0.82rem; color: var(--soft); }
.final-corr  { font-size: 0.82rem; color: var(--soft); }

@media (max-width: 1100px) { .quiz-body { grid-template-columns: 220px 1fr; } }
@media (max-width: 860px) {
    .quiz-body { grid-template-columns: 1fr; }
    .leaderboard { display: none; }
    .result-panel { left: 0; }
    .lobby-body { grid-template-columns: 1fr; }
    .options-grid { grid-template-columns: 1fr; }
}
