/* Player-facing quiz */
body.quiz-body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, .13) 0 140px, transparent 141px),
    radial-gradient(circle at 92% 22%, rgba(247, 183, 51, .22) 0 90px, transparent 91px),
    radial-gradient(circle at 80% 95%, rgba(255, 255, 255, .1) 0 200px, transparent 201px),
    linear-gradient(160deg, var(--red-500) 0%, var(--red-700) 55%, var(--red-900) 100%);
  background-attachment: fixed;
  display: flex; flex-direction: column;
}

.top-bar { padding: 18px 24px; color: #fff; display: flex; align-items: center; justify-content: space-between; }
.top-bar .brand-mark { background: #fff; color: var(--red-600); box-shadow: 0 2px 8px rgba(0,0,0,.25); font-weight: 800; }
.top-bar .tag { font-size: .8rem; opacity: .85; }

main.stage { flex: 1; display: grid; place-items: center; padding: 8px 16px 40px; }

.card {
  width: 100%; max-width: 640px; background: #fff; border-radius: 24px;
  box-shadow: var(--shadow); padding: 36px 36px 32px; position: relative; overflow: hidden;
  animation: rise .45s cubic-bezier(.2, .8, .2, 1);
}
.card::before { /* brand ribbon */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 8px;
  background: linear-gradient(90deg, var(--red-700), var(--red-500) 60%, var(--gold));
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* Welcome */
.welcome { text-align: center; }
.welcome .eyebrow { color: var(--red-600); font-weight: 700; font-size: .78rem; letter-spacing: .2em; text-transform: uppercase; }
.welcome h1 { font-size: clamp(1.7rem, 5vw, 2.3rem); line-height: 1.15; margin: .4rem 0 .6rem; color: var(--red-800); font-weight: 800; }
.welcome .lead { color: var(--ink-2); max-width: 44ch; margin: 0 auto 1.4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: 1.6rem; }
.chip { background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); padding: .35rem .85rem; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.welcome form { display: grid; gap: 1rem; }

/* Quiz header */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.q-count { font-weight: 600; color: var(--ink-2); font-size: .9rem; }
.q-count b { color: var(--red-700); font-size: 1.25rem; }
.player { font-size: .8rem; color: var(--ink-3); }

.timer { position: relative; width: 64px; height: 64px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; }
.timer .track { stroke: var(--red-100); }
.timer .bar { stroke: var(--red-600); stroke-linecap: round; transition: stroke .3s; }
.timer .secs { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; color: var(--red-800); font-variant-numeric: tabular-nums; }
.timer.low .bar { stroke: var(--gold-600); }
.timer.critical .bar { stroke: var(--red-600); }
.timer.critical .secs { color: var(--red-600); animation: pulse .6s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.18); } }

.progress { height: 8px; background: var(--red-50); border-radius: 99px; overflow: hidden; margin-bottom: 1.6rem; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red-500), var(--gold)); border-radius: 99px; transition: width .4s ease; }

.question { font-size: clamp(1.15rem, 3.4vw, 1.4rem); font-weight: 700; line-height: 1.35; color: var(--ink); margin-bottom: 1.3rem; }

.q-image { margin: 0 0 1.2rem; display: grid; place-items: center; background: var(--cream); border: 1px solid var(--line); border-radius: 16px; padding: .6rem; animation: rise .3s ease; }
.q-image img { display: block; max-width: 100%; max-height: min(280px, 38vh); width: auto; height: auto; border-radius: 10px; object-fit: contain; }
.rv-img { display: block; max-height: 90px; max-width: 100%; border-radius: 8px; margin-top: .5rem; border: 1px solid var(--line); }

.options { display: grid; gap: .75rem; margin-bottom: 1.6rem; }
.option {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left; cursor: pointer;
  padding: .85rem 1rem; border-radius: 14px; background: #fff;
  border: 2px solid var(--line); transition: border-color .15s, background .15s, transform .1s;
}
.option:hover { border-color: var(--red-200); background: var(--red-50); }
.option .key {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--red-50); color: var(--red-700); font-weight: 700; transition: all .15s;
}
.option .txt { font-weight: 500; }
.option[aria-checked="true"] { border-color: var(--red-600); background: var(--red-50); box-shadow: 0 0 0 4px rgba(224, 38, 47, .12); }
.option[aria-checked="true"] .key { background: var(--red-600); color: #fff; }

/* After answering: the right option turns green, a wrong pick turns red */
.option .mark { margin-left: auto; font-weight: 800; font-size: 1.1rem; opacity: 0; }
.options.locked .option { cursor: default; }
.options.locked .option:hover { border-color: var(--line); background: #fff; }
.options.locked .option:not(.correct):not(.wrong) { opacity: .6; }
.option.correct, .options.locked .option.correct:hover { border-color: var(--green); background: var(--green-bg); box-shadow: 0 0 0 4px rgba(31, 138, 76, .15); }
.option.correct .key { background: var(--green); color: #fff; }
.option.correct .mark { color: var(--green); opacity: 1; }
.option.wrong, .options.locked .option.wrong:hover { border-color: var(--red-600); background: var(--red-100); box-shadow: 0 0 0 4px rgba(224, 38, 47, .15); }
.option.wrong .key { background: var(--red-600); color: #fff; }
.option.wrong .mark { color: var(--red-700); opacity: 1; }
.option.pop { animation: pop .3s ease; }
@keyframes pop { 40% { transform: scale(1.02); } }
.feedback { min-height: 1.6em; margin: -.6rem 0 1.2rem; font-weight: 600; font-size: .95rem; }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--red-700); }

.q-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.q-foot .hint { font-weight: 500; }

/* Result */
.result { text-align: center; }
.score-ring { --pct: 0; position: relative; width: 168px; height: 168px; margin: 0 auto 1rem; border-radius: 50%;
  background: conic-gradient(var(--ring, var(--red-600)) calc(var(--pct) * 1%), var(--red-50) 0);
  display: grid; place-items: center; transition: --pct 1s; }
.score-ring::after { content: ""; position: absolute; inset: 14px; background: #fff; border-radius: 50%; }
.score-ring > div { position: relative; z-index: 1; }
.score-ring .big { font-size: 2.6rem; font-weight: 800; line-height: 1; color: var(--red-800); }
.score-ring .of { font-size: .85rem; color: var(--ink-3); }
.result h2 { font-size: 1.6rem; font-weight: 800; color: var(--red-800); }
.result .sub { color: var(--ink-2); margin: .3rem 0 1.4rem; }
.badge { display: inline-block; padding: .25rem .9rem; border-radius: 99px; font-weight: 700; font-size: .8rem; margin-bottom: .6rem; }
.badge.pass { background: var(--green-bg); color: var(--green); }
.badge.fail { background: var(--red-100); color: var(--red-700); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1.5rem; }
.stat { background: var(--cream); border: 1px solid var(--line); border-radius: 14px; padding: .8rem .4rem; }
.stat b { display: block; font-size: 1.4rem; color: var(--red-800); }
.stat span { font-size: .75rem; color: var(--ink-3); }
.actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

.review { text-align: left; margin-top: 1.6rem; display: grid; gap: .6rem; }
.review h3 { font-size: 1rem; color: var(--red-800); }
.rv { border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; background: #fff; }
.rv.ok { border-left: 5px solid var(--green); }
.rv.no { border-left: 5px solid var(--red-600); }
.rv .qt { font-weight: 600; font-size: .92rem; }
.rv .ans { font-size: .83rem; color: var(--ink-2); margin-top: .25rem; }
.rv .ans b { color: var(--ink); }
.rv .tick { font-weight: 700; }
.rv.ok .tick { color: var(--green); }
.rv.no .tick { color: var(--red-600); }

.loading { text-align: center; color: var(--ink-3); padding: 2rem 0; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--red-100); border-top-color: var(--red-600); margin: 0 auto .8rem; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

footer.foot { text-align: center; color: rgba(255,255,255,.75); font-size: .78rem; padding: 0 16px 18px; }
footer.foot a { color: #fff; }

@media (max-width: 520px) {
  .card { padding: 28px 20px 24px; border-radius: 20px; }
  .top-bar { padding: 14px 16px; }
  .stats { gap: .5rem; }
  .timer { width: 56px; height: 56px; }
}

/* ---------- While a question is showing, fit it to the screen: no page scroll ---------- */
html:has(body.playing) { height: 100%; overflow: hidden; }
body.playing { height: 100vh; height: 100dvh; overflow: hidden; }
body.playing .top-bar { padding-top: 10px; padding-bottom: 6px; flex: none; }
body.playing footer.foot { display: none; }
body.playing main.stage { min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 16px 14px; }
body.playing #quiz {
  display: flex; flex-direction: column; max-height: 100%; min-height: 0; padding: 22px 28px 18px;
}
body.playing #quiz > * { flex: none; }
body.playing .q-head { margin-bottom: .7rem; }
body.playing .progress { margin-bottom: .9rem; }
body.playing .question { margin-bottom: .8rem; font-size: clamp(1.05rem, 2.6vw, 1.3rem); }
body.playing .options { gap: .5rem; margin-bottom: .6rem; }
body.playing .option { padding: .6rem .9rem; }
body.playing .option .key { width: 30px; height: 30px; }
body.playing .feedback { min-height: 1.4em; margin: 0 0 .6rem; }

/* The picture takes whatever height is left and shrinks to fit, never pushing the options off screen. */
body.playing #quiz > .q-image {
  flex: 1 1 clamp(130px, 30vh, 300px); min-height: 70px; margin: 0 0 .8rem; padding: 0; position: relative; display: block; overflow: hidden;
}
body.playing .q-image img {
  position: absolute; inset: .45rem; width: calc(100% - .9rem); height: calc(100% - .9rem);
  max-width: none; max-height: none; object-fit: contain;
}
@media (max-width: 520px) {
  body.playing #quiz { padding: 18px 16px 14px; }
  body.playing main.stage { padding: 2px 10px 10px; }
}

/* Short screens: tighten everything so the whole question, options and Quit button stay visible. */
@media (max-height: 760px) {
  body.playing .top-bar { padding-top: 6px; padding-bottom: 2px; }
  body.playing .top-bar .brand-mark { width: 32px; height: 32px; }
  body.playing main.stage { padding-bottom: 8px; }
  body.playing #quiz { padding: 14px 22px 12px; }
  body.playing .timer { width: 46px; height: 46px; }
  body.playing .timer .secs { font-size: 1rem; }
  body.playing .q-head { margin-bottom: .4rem; }
  body.playing .progress { margin-bottom: .6rem; height: 6px; }
  body.playing .question { margin-bottom: .5rem; font-size: 1.05rem; line-height: 1.25; }
  body.playing .options { gap: .35rem; margin-bottom: .4rem; }
  body.playing .option { padding: .38rem .8rem; }
  body.playing .option .key { width: 26px; height: 26px; font-size: .85rem; }
  body.playing .feedback { min-height: 1.2em; margin-bottom: .4rem; font-size: .85rem; }
  body.playing #quiz > .q-image { min-height: 44px; margin-bottom: .5rem; }
  body.playing .q-foot .btn { padding: .4rem 1.1rem; font-size: .9rem; }
}
/* If a question is still too tall for the screen, never cut the Quit button off. */
body.playing #quiz { overflow-y: auto; scrollbar-width: none; }
body.playing #quiz::-webkit-scrollbar { display: none; }

/* ---------- Logo in the top bar ---------- */
.brand-logo-wrap { display: inline-flex; align-items: center; gap: .8rem; }
.brand-logo { display: block; height: 100px; width: auto; filter: drop-shadow(0 2px 5px rgba(60, 5, 9, .35)); }
.brand-sub { padding-left: .8rem; border-left: 2px solid rgba(255, 255, 255, .45); color: #fff; font-weight: 700; font-size: .72rem; letter-spacing: .24em; text-transform: uppercase; line-height: 1.2; }
body.playing .brand-logo { height: 44px; }
@media (max-height: 760px) { body.playing .brand-logo { height: 34px; } }
@media (max-width: 520px) { .brand-logo { height: 46px; } .brand-sub { font-size: .66rem; letter-spacing: .18em; padding-left: .6rem; } }

/* Logo sits on the right of the top bar, with the page label on the left */
.top-bar .brand-logo-wrap { flex-direction: row-reverse; }
.top-bar .brand-sub { padding-left: 0; border-left: 0; padding-right: .8rem; border-right: 2px solid rgba(255, 255, 255, .45); }
@media (max-width: 520px) { .top-bar .brand-sub { padding-right: .6rem; } }
