﻿:root {
  --qw-paper: #f3efe4;
  --qw-panel: #fffdf6;
  --qw-ink: #182628;
  --qw-muted: #667273;
  --qw-line: #d7d1c2;
  --qw-dark: #102f32;
  --qw-board: #0e4145;
  --qw-orange: #ff7a1a;
  --qw-yellow: #ffd44a;
  --qw-green: #26a568;
  --qw-red: #dc4f42;
  --qw-sky: #63c8df;
  --qw-ring: rgba(255, 122, 26, .46);
  --qw-shadow: 0 18px 48px rgba(20, 39, 40, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--qw-ink);
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 212, 74, .22), transparent 28rem),
    var(--qw-paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.qw-topbar {
  width: min(1480px, calc(100% - 40px));
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  margin-inline: auto;
}
.qw-brand { display: inline-flex; align-items: center; gap: 11px; color: var(--qw-ink); font-weight: 950; text-decoration: none; }
.qw-brand span { width: 40px; height: 40px; display: grid; place-items: center; border: 3px solid var(--qw-ink); border-radius: 14px; color: white; background: var(--qw-orange); transform: rotate(-5deg); }
.qw-room-summary { display: flex; gap: 8px; }
.qw-room-summary > span, .qw-code-button { min-width: 90px; display: grid; padding: 7px 11px; border: 2px solid var(--qw-dark); border-radius: 10px; background: var(--qw-panel); text-align: left; box-shadow: 0 3px 0 var(--qw-dark); }
.qw-room-summary small { color: var(--qw-muted); font-size: 10px; font-weight: 900; }
.qw-room-summary strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.qw-code-button { cursor: pointer; }
.qw-code-button strong { color: var(--qw-orange); letter-spacing: .08em; }
.qw-leave { min-height: 42px; border: 0; border-radius: 10px; padding: 0 16px; color: white; background: var(--qw-dark); font-weight: 900; cursor: pointer; }

main { width: min(1480px, calc(100% - 40px)); margin-inline: auto; }
.qw-ad-layout { width: min(1780px, calc(100% - 20px)); display: grid; grid-template-columns: clamp(72px, 10vw, 140px) minmax(0, 1480px) clamp(72px, 10vw, 140px); align-items: start; justify-content: center; gap: 10px; margin-inline: auto; }
.qw-ad-layout > main { width: 100%; min-width: 0; margin-inline: 0; }
.qw-side-ad { position: sticky; top: 12px; min-width: 0; min-height: 600px; display: grid; grid-template-rows: auto 1fr; overflow: hidden; border: 2px solid var(--qw-line); border-radius: 12px; color: var(--qw-muted); background: rgba(255,253,246,.82); text-align: center; }
.qw-side-ad > span, .qw-bottom-ad > span { padding: 7px 8px; border-bottom: 1px solid var(--qw-line); font-size: 10px; font-weight: 900; }
.qw-side-ad > div, .qw-bottom-ad > div { display: grid; place-items: center; min-height: 0; color: var(--qw-muted); font-size: 11px; }
.qw-ad-layout.is-ad-free { grid-template-columns: minmax(0, 1480px); }
.qw-ad-layout.is-ad-free .qw-side-ad { display: none; }
.qw-bottom-ad { width: min(720px, calc(100% - 22px)); min-height: 110px; display: none; grid-template-rows: auto 1fr; margin: 0 auto 36px; overflow: hidden; border: 2px solid var(--qw-line); border-radius: 12px; color: var(--qw-muted); background: rgba(255,253,246,.82); text-align: center; }
.qw-entry { min-height: calc(100vh - 72px); display: grid; grid-template-columns: minmax(380px, .9fr) minmax(560px, 1.1fr); gap: 44px; align-items: center; padding: 32px 0 52px; }
.qw-kicker { margin: 0; color: var(--qw-orange); font-size: 12px; font-weight: 950; letter-spacing: .12em; }
.qw-entry-copy h1 { margin: 10px 0 18px; font-size: clamp(46px, 6vw, 82px); line-height: .98; letter-spacing: 0; }
.qw-entry-copy h1 em { color: var(--qw-orange); font-style: normal; }
.qw-entry-copy > p:not(.qw-kicker) { max-width: 610px; margin: 0; color: var(--qw-muted); font-size: 18px; line-height: 1.6; }
.qw-entry-copy dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 22px 0 0; }
.qw-entry-copy dl div { padding: 13px; border: 2px solid var(--qw-dark); border-radius: 12px; background: var(--qw-panel); box-shadow: 0 4px 0 var(--qw-dark); }
.qw-entry-copy dt { color: var(--qw-orange); font-size: 15px; font-weight: 950; }
.qw-entry-copy dd { margin: 4px 0 0; font-size: 12px; font-weight: 750; line-height: 1.45; }
.qw-entry-arena { position: relative; height: 205px; margin-top: 22px; overflow: hidden; border: 4px solid var(--qw-dark); border-radius: 20px; background: url("assets/quiz-race-arena.png") center 62% / cover; box-shadow: var(--qw-shadow); }
.qw-entry-arena::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 40%, rgba(9, 32, 35, .38)); }
.qw-entry-arena b { position: absolute; top: 22px; left: 50%; z-index: 2; transform: translateX(-50%); color: #d7fff1; font-size: 18px; letter-spacing: .18em; text-shadow: 0 2px 0 #0b2d30; white-space: nowrap; }
.qw-entry-character { position: absolute; left: 25%; bottom: -8px; z-index: 2; width: 112px; height: 112px; filter: drop-shadow(0 7px 4px rgba(0,0,0,.34)); }
.qw-entry-character--two { left: auto; right: 25%; transform: scale(.92); }

.qw-entry-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.qw-entry-form { display: grid; align-content: start; gap: 13px; padding: 20px; border: 2px solid var(--qw-dark); border-radius: 16px; background: var(--qw-panel); box-shadow: 0 5px 0 var(--qw-dark); }
.qw-entry-form--primary { border-color: var(--qw-orange); box-shadow: 0 5px 0 #c74f00; }
.qw-entry-form > div span, .qw-teacher-entry summary span { color: var(--qw-orange); font-size: 11px; font-weight: 950; }
.qw-entry-form h2 { margin: 3px 0 0; font-size: 22px; }
.qw-entry-form label { display: grid; gap: 6px; font-size: 12px; font-weight: 900; }
.qw-entry-form input, .qw-chat-form input { min-width: 0; min-height: 44px; border: 2px solid var(--qw-line); border-radius: 9px; padding: 0 11px; color: var(--qw-ink); background: white; }
.qw-primary, .qw-dark, .qw-host-controls button, .qw-file-button, .qw-chat-form button, .qw-choice { border: 0; border-radius: 10px; font-weight: 950; cursor: pointer; }
.qw-primary, .qw-dark { min-height: 46px; padding: 0 15px; }
.qw-primary { color: white; background: var(--qw-orange); box-shadow: 0 4px 0 #b74700; }
.qw-dark { color: white; background: var(--qw-dark); box-shadow: 0 4px 0 #06191b; }
.qw-form-status { min-height: 18px; margin: 0; color: var(--qw-red); font-size: 12px; }
.qw-teacher-entry { grid-column: 1 / -1; border: 2px solid var(--qw-dark); border-radius: 14px; background: var(--qw-panel); box-shadow: 0 5px 0 var(--qw-dark); }
.qw-teacher-entry summary { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 20px; cursor: pointer; }
.qw-teacher-entry .qw-entry-form { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; border: 0; border-top: 2px solid var(--qw-dark); border-radius: 0; box-shadow: none; }
.qw-teacher-entry .qw-form-status { grid-column: 1 / -1; }

.qw-room { padding: 10px 0 42px; }
.qw-mode-banner { min-height: 48px; display: flex; align-items: center; gap: 14px; padding: 9px 18px; border: 3px solid var(--qw-dark); border-radius: 14px 14px 0 0; color: white; background: var(--qw-dark); }
.qw-mode-banner strong { color: var(--qw-yellow); }
.qw-mode-banner span { color: #d5ebea; }
.qw-room-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; border-inline: 3px solid var(--qw-dark); background: var(--qw-dark); }
.qw-room-grid.is-solo { grid-template-columns: 1fr; }
.qw-room-grid.is-solo .qw-side-panel { display: none; }
.qw-quiz-stage { min-width: 0; background: #071f22; }
.qw-arena { position: relative; aspect-ratio: 16 / 9; min-height: 590px; overflow: hidden; background: #123d40 url("assets/quiz-race-arena.png") center / cover no-repeat; isolation: isolate; }
.qw-arena::after { content: ""; position: absolute; inset: auto 0 0; z-index: -1; height: 44%; background: linear-gradient(180deg, transparent, rgba(5, 25, 27, .28)); pointer-events: none; }
.qw-arena-lights { position: absolute; inset: 0; z-index: 7; pointer-events: none; box-shadow: inset 0 0 70px rgba(0,0,0,.3); }

.qw-lobby-panel, .qw-finished-panel { position: absolute; inset: 5% 16% 43%; z-index: 3; display: grid; place-items: center; align-content: center; padding: 18px; color: #e9fffa; text-align: center; text-shadow: 0 2px 0 #082c2f; }
.qw-lobby-panel > p:first-child, .qw-finished-panel > p { margin: 0; color: var(--qw-yellow); font-size: 11px; font-weight: 950; letter-spacing: .12em; }
.qw-lobby-panel > strong { margin: 2px 0 7px; color: white; font-size: clamp(42px, 6vw, 76px); letter-spacing: .14em; font-variant-numeric: tabular-nums; }
.qw-lobby-panel h1, .qw-finished-panel h1 { margin: 0 0 6px; font-size: clamp(25px, 3vw, 40px); }
.qw-lobby-panel > p:not(:first-child) { margin: 0 0 12px; color: #b9dcda; }
.qw-lobby-panel button { min-height: 42px; padding: 0 20px; }

.qw-question-panel { position: absolute; inset: 3.5% 14% 43%; z-index: 4; display: grid; align-content: center; color: #effff9; }
.qw-question-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; color: #b9dcda; font-size: 12px; font-weight: 900; }
.qw-question-meta strong { color: var(--qw-yellow); }
.qw-question-lead { display: grid; place-items: center; margin-bottom: 12px; }
.qw-question-lead.has-media { grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 14px; }
.qw-question-lead.has-video { grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); }
.qw-question-lead.has-portrait { grid-template-columns: minmax(108px, 150px) minmax(0, 1fr); }
.qw-question-panel h1 { margin: 0; font-size: clamp(21px, 2.4vw, 34px); line-height: 1.2; text-align: center; text-wrap: balance; text-shadow: 0 2px 0 #082c2f; }
.qw-question-media { position: relative; width: 100%; aspect-ratio: 16 / 9; margin: 0; overflow: hidden; border: 3px solid rgba(255,255,255,.82); border-radius: 10px; background: #06191b; box-shadow: 0 4px 0 rgba(3,24,26,.76); }
.qw-question-media img, .qw-question-media iframe { display: block; width: 100%; height: 100%; border: 0; object-fit: cover; }
.qw-question-media.is-portrait { aspect-ratio: 4 / 5; max-height: 176px; justify-self: center; }
.qw-question-media.is-portrait img { object-position: center 22%; }
.qw-video-launch { position: relative; width: 100%; height: 100%; padding: 0; overflow: hidden; border: 0; border-radius: 0; background: #06191b; box-shadow: none; }
.qw-video-launch::after { content: ""; position: absolute; inset: 0; background: rgba(6,25,27,.22); }
.qw-video-launch img { filter: saturate(.9) brightness(.78); }
.qw-video-launch span { position: absolute; z-index: 1; left: 50%; top: 50%; min-width: 106px; padding: 8px 10px; border: 2px solid white; border-radius: 8px; color: white; background: rgba(6,25,27,.9); font-size: 11px; font-weight: 950; transform: translate(-50%, -50%); }
.qw-media-status { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; padding: 12px; color: #d8eeeb; background: #06191b; font-size: 11px; font-weight: 850; text-align: center; }
.qw-media-status[hidden] { display: none; }
.qw-question-media.has-load-error .qw-media-status { color: #fff3bd; }
.qw-video-launch .qw-media-status { inset: 0; left: 0; top: 0; min-width: 0; padding: 12px; border: 0; border-radius: 0; background: #06191b; transform: none; }
.qw-video-launch:hover img { filter: saturate(1) brightness(.9); }
.qw-video-launch:focus-visible { outline: 3px solid var(--qw-yellow); outline-offset: -4px; }
.qw-question-media figcaption { position: absolute; right: 4px; bottom: 4px; max-width: calc(100% - 8px); overflow: hidden; padding: 2px 5px; border-radius: 4px; color: #effff9; background: rgba(6,25,27,.84); font-size: 9px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.qw-question-media figcaption a { color: inherit; pointer-events: auto; }
.qw-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.qw-choice { min-height: 54px; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 7px 10px; border: 2px solid rgba(255,255,255,.7); color: var(--qw-ink); background: rgba(255,253,246,.95); box-shadow: 0 4px 0 rgba(3,24,26,.7); text-align: left; }
.qw-choice span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: white; background: var(--qw-orange); }
.qw-choice:nth-child(2) span { background: var(--qw-sky); color: var(--qw-dark); }
.qw-choice:nth-child(3) span { background: var(--qw-yellow); color: var(--qw-dark); }
.qw-choice:nth-child(4) span { background: var(--qw-green); }
.qw-choice small { color: var(--qw-muted); }
.qw-choice:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.04); }
.qw-choice.is-selected { border-color: var(--qw-yellow); background: #fff3bd; }
.qw-choice.is-correct { border-color: #82f2b8; background: #c9f7dd; }
.qw-choice.is-wrong { border-color: #ff968c; background: #ffe0dc; }
.qw-choice:disabled { cursor: default; }
.qw-answer-note { min-height: 30px; display: grid; place-items: center; margin-top: 7px; padding: 4px 8px; border-radius: 8px; color: white; background: rgba(5,34,36,.82); font-size: 12px; font-weight: 850; text-align: center; }
.qw-explanation { position: absolute; top: calc(100% + 4px); left: 5%; right: 5%; padding: 8px 12px; border-radius: 9px; color: var(--qw-dark); background: #fff7cf; box-shadow: 0 4px 0 rgba(3,24,26,.6); font-size: 12px; line-height: 1.45; }

.qw-race-course { position: absolute; inset: 51% 5% 4%; z-index: 2; }
.qw-racer { --race-progress: 0; --row-offset: 0; position: absolute; left: var(--lane-x); bottom: calc(2% + var(--row-offset) * 12% + var(--race-progress) * 34%); width: clamp(54px, 8vw, 100px); transform: translateX(-50%); transition: bottom .72s cubic-bezier(.2,.9,.28,1.2); text-align: center; filter: drop-shadow(0 6px 3px rgba(0,0,0,.45)); }
.qw-racer.is-correct .qw-avatar { animation: qw-celebrate .8s ease-in-out infinite alternate; }
.qw-racer.is-wrong .qw-avatar, .qw-racer.is-miss .qw-avatar { filter: grayscale(.45) brightness(.75); animation: qw-shake .32s linear 2; }
.qw-racer.is-self .qw-avatar-wrap { outline: 4px solid var(--qw-yellow); box-shadow: 0 0 0 4px rgba(16,47,50,.7), 0 0 24px var(--qw-yellow); }
.qw-avatar-wrap { display: block; width: 100%; aspect-ratio: 1; border-radius: 50%; }
.qw-avatar { display: block; width: 100%; height: 100%; background-image: url("assets/quiz-avatars.png"); background-repeat: no-repeat; background-size: 400% 300%; }
.qw-custom-avatar { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--qw-panel); object-fit: cover; }
.qw-avatar--0 { background-position: 0 10%; } .qw-avatar--1 { background-position: 33.333% 10%; } .qw-avatar--2 { background-position: 66.666% 10%; } .qw-avatar--3 { background-position: 100% 10%; }
.qw-avatar--4 { background-position: 0 54%; } .qw-avatar--5 { background-position: 33.333% 54%; } .qw-avatar--6 { background-position: 66.666% 54%; } .qw-avatar--7 { background-position: 100% 54%; }
.qw-avatar--8 { background-position: 0 96%; } .qw-avatar--9 { background-position: 33.333% 96%; } .qw-avatar--10 { background-position: 66.666% 96%; } .qw-avatar--11 { background-position: 100% 96%; }
.qw-racer-name { position: relative; display: inline-block; max-width: 105px; margin-top: -5px; overflow: hidden; padding: 3px 7px; border: 2px solid #082c2f; border-radius: 999px; color: var(--qw-dark); background: white; box-shadow: 0 3px 0 #082c2f; font-size: 11px; font-weight: 950; text-overflow: ellipsis; white-space: nowrap; }
.qw-racer-progress { display: block; margin-top: 2px; color: white; font-size: 10px; font-weight: 900; text-shadow: 0 2px 0 #082c2f; }
.qw-room-grid.is-classroom .qw-racer { width: clamp(34px, 4.1vw, 56px); }
.qw-room-grid.is-classroom .qw-racer { bottom: calc(1% + var(--row-offset) * 15% + var(--race-progress) * 20%); }
.qw-room-grid.is-classroom .qw-racer-name { max-width: 62px; padding: 2px 4px; font-size: 8px; }
.qw-room-grid.is-classroom .qw-racer-progress { display: none; }

.qw-score-strip { min-height: 70px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; margin: 0; padding: 5px; background: var(--qw-dark); list-style: none; }
.qw-score-strip li { min-width: 0; display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 7px; padding: 8px 10px; border-radius: 9px; background: #e8f5ed; }
.qw-score-strip small { color: var(--qw-orange); font-weight: 950; }
.qw-score-strip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qw-score-player { display: flex; align-items: center; gap: 6px; }
.qw-score-avatar { width: 24px !important; height: 24px !important; flex: 0 0 24px; }
.qw-score-strip span { color: var(--qw-muted); font-size: 11px; }
.qw-finished-panel { overflow-y: auto; }
.qw-finished-panel ol { width: min(480px, 100%); margin: 8px 0 0; padding: 0; list-style: none; }
.qw-finished-panel li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; padding: 7px 10px; border-bottom: 1px solid rgba(255,255,255,.2); text-align: left; }

.qw-side-panel { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); color: var(--qw-ink); background: var(--qw-panel); }
.qw-side-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 2px solid var(--qw-dark); }
.qw-side-tabs button { min-height: 52px; border: 0; border-bottom: 5px solid transparent; background: var(--qw-panel); font-weight: 950; cursor: pointer; }
.qw-side-tabs button[aria-selected="true"] { color: var(--qw-orange); border-bottom-color: var(--qw-orange); }
.qw-chat-panel { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; }
.qw-messages { min-height: 0; max-height: 560px; overflow-y: auto; margin: 0; padding: 12px; list-style: none; }
.qw-messages li { padding: 9px; border-bottom: 1px solid var(--qw-line); }
.qw-messages strong { display: block; margin-bottom: 3px; font-size: 12px; }
.qw-messages strong.is-host { color: var(--qw-orange); }
.qw-messages p { margin: 0; overflow-wrap: anywhere; line-height: 1.4; }
.qw-messages time { color: var(--qw-muted); font-size: 9px; }
.qw-messages .qw-empty { color: var(--qw-muted); border: 0; }
.qw-chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; padding: 10px; border-top: 2px solid var(--qw-line); }
.qw-chat-form button { min-width: 60px; color: white; background: var(--qw-orange); }
.qw-chat-form input:disabled, .qw-chat-form button:disabled { cursor: not-allowed; opacity: .55; }
.qw-chat-state { min-height: 26px; margin: 0; padding: 0 10px 7px; color: var(--qw-muted); font-size: 11px; }
.qw-people-panel { overflow-y: auto; padding: 10px; }
.qw-people-panel ol { margin: 0; padding: 0; list-style: none; }
.qw-people-panel li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 8px 3px; border-bottom: 1px solid var(--qw-line); }
.qw-people-panel li .qw-mini-avatar { width: 34px; height: 34px; }
.qw-people-panel li small { color: var(--qw-muted); }

.qw-host-controls { min-height: 82px; display: grid; grid-template-columns: minmax(140px, 1fr) repeat(7, auto); align-items: center; gap: 7px; padding: 13px; border: 3px solid var(--qw-dark); border-top: 2px solid #396467; border-radius: 0 0 14px 14px; color: white; background: var(--qw-dark); }
.qw-host-controls > div { display: grid; }
.qw-host-controls small { color: var(--qw-yellow); font-weight: 900; }
.qw-host-controls button, .qw-file-button { min-height: 44px; display: grid; place-items: center; padding: 0 12px; color: var(--qw-ink); background: var(--qw-panel); }
.qw-host-controls button.is-primary { color: white; background: var(--qw-orange); }
.qw-host-controls button:disabled { cursor: not-allowed; opacity: .4; }
.qw-file-button input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.qw-toast { position: fixed; left: 50%; bottom: 22px; z-index: 20; width: min(420px, calc(100% - 30px)); transform: translateX(-50%); padding: 13px 15px; border: 2px solid white; border-radius: 10px; color: white; background: var(--qw-dark); text-align: center; font-weight: 850; }
button:focus-visible, input:focus-visible, summary:focus-visible, .qw-file-button:focus-within { outline: 3px solid var(--qw-ring); outline-offset: 3px; }
button:active { transform: translateY(2px); }

@keyframes qw-celebrate { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-10px) rotate(3deg); } }
@keyframes qw-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

@media (max-width: 1100px) {
  .qw-entry { grid-template-columns: 1fr; }
  .qw-entry-copy { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; }
  .qw-entry-copy dl, .qw-entry-arena { grid-column: 1 / -1; }
  .qw-room-grid { grid-template-columns: minmax(0, 1fr) 290px; }
  .qw-host-controls { grid-template-columns: repeat(3, 1fr); }
  .qw-host-controls > div { grid-column: 1 / -1; }
}

@media (max-width: 780px) {
  .qw-topbar, main { width: min(100% - 22px, 1480px); }
  .qw-topbar { grid-template-columns: minmax(0, 1fr) auto; padding: 9px 0; }
  .qw-room-summary { grid-column: 1 / -1; grid-row: 2; }
  .qw-room-summary > span, .qw-code-button { min-width: 0; flex: 1; }
  .qw-entry { min-height: auto; gap: 28px; padding: 24px 0 40px; }
  .qw-entry-copy { display: block; }
  .qw-entry-copy h1 { font-size: clamp(43px, 13vw, 66px); }
  .qw-entry-copy > p:not(.qw-kicker) { font-size: 15px; }
  .qw-entry-copy dl { grid-template-columns: 1fr; }
  .qw-entry-arena { height: 185px; }
  .qw-entry-actions { grid-template-columns: 1fr; }
  .qw-teacher-entry { grid-column: auto; }
  .qw-teacher-entry .qw-entry-form { grid-template-columns: 1fr; }
  .qw-room { padding-top: 4px; }
  .qw-mode-banner { align-items: flex-start; flex-direction: column; gap: 2px; border-radius: 12px 12px 0 0; }
  .qw-room-grid { grid-template-columns: 1fr; }
  .qw-arena { aspect-ratio: auto; min-height: 680px; background-position: center; }
  .qw-question-panel, .qw-lobby-panel, .qw-finished-panel { inset: 3% 4% 47%; }
  .qw-question-panel h1 { font-size: 22px; }
  .qw-question-lead.has-media { grid-template-columns: minmax(120px, 180px) minmax(0, 1fr); gap: 9px; }
  .qw-question-lead.has-portrait { grid-template-columns: 140px minmax(0, 1fr); }
  .qw-choice { min-height: 58px; grid-template-columns: 30px minmax(0,1fr) auto; padding: 6px 8px; font-size: 13px; }
  .qw-choice span { width: 28px; height: 28px; }
  .qw-explanation { left: 0; right: 0; }
  .qw-race-course { inset: 52% 2% 3%; }
  .qw-racer { width: clamp(52px, 16vw, 72px); }
  .qw-racer-name { max-width: 70px; font-size: 9px; }
  .qw-room-grid.is-classroom .qw-racer { width: clamp(28px, 7vw, 42px); }
  .qw-room-grid.is-classroom .qw-racer-name { display: none; }
  .qw-score-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); overflow-x: auto; }
  .qw-score-strip li:nth-child(n+4) { display: none; }
  .qw-side-panel { min-height: 480px; border-top: 3px solid var(--qw-dark); }
  .qw-messages { max-height: none; }
  .qw-host-controls { grid-template-columns: repeat(2, 1fr); border-radius: 0 0 12px 12px; }
}

@media (max-width: 720px) {
  .qw-ad-layout { width: min(100% - 22px, 1480px); grid-template-columns: minmax(0, 1fr); }
  .qw-side-ad { display: none; }
  .qw-bottom-ad { display: grid; }
}

@media (min-width: 721px) and (max-width: 1680px) {
  .qw-room-grid { grid-template-columns: minmax(0, 1fr); }
  .qw-arena { min-height: 0; }
  .qw-side-panel { min-height: 480px; border-top: 3px solid var(--qw-dark); }
  .qw-messages { max-height: none; }
}

@media (min-width: 721px) and (max-width: 780px) {
  .qw-arena { min-height: 680px; }
}

@media (min-width: 781px) {
  .qw-category-card:last-child:nth-child(4n + 1) { grid-column: 2 / span 2; width: calc(50% - 7px); justify-self: center; }
}

@media (max-width: 430px) {
  .qw-brand strong { font-size: 14px; }
  .qw-room-summary strong { font-size: 14px; }
  .qw-entry-character { left: 15%; }
  .qw-entry-character--two { left: auto; right: 15%; }
  .qw-arena { min-height: 650px; }
  .qw-question-panel { inset-inline: 3%; }
  .qw-question-lead { margin-bottom: 8px; }
  .qw-question-lead.has-media { grid-template-columns: 118px minmax(0, 1fr); gap: 8px; }
  .qw-question-lead.has-video { grid-template-columns: 142px minmax(0, 1fr); }
  .qw-question-lead.has-portrait { grid-template-columns: 96px minmax(0, 1fr); }
  .qw-question-media.is-portrait { max-height: 130px; }
  .qw-question-lead.has-media h1 { font-size: 18px; text-align: left; }
  .qw-question-media { border-width: 2px; border-radius: 7px; }
  .qw-choices { gap: 6px; }
  .qw-choice { min-height: 62px; }
  .qw-answer-note { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
  button:active { transform: none; }
}

/* Entry flow: one decision per screen */
.qw-entry {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 24px 0 48px;
}
.qw-entry-shell { width: min(680px, 100%); }
.qw-entry-shell:has(.qw-category-screen:not([hidden])) { width: min(980px, calc(100% - 40px)); }
.qw-entry-shell:has(.qw-admin-screen:not([hidden])) { width: min(1120px, 100%); }
.qw-entry-screen { position: relative; display: grid; justify-items: center; animation: qw-screen-in .24s ease-out; }
.qw-entry-screen[hidden] { display: none; }
.qw-entry-screen h1 { margin: 5px 0 24px; font-size: clamp(34px, 6vw, 54px); line-height: 1; letter-spacing: 0; text-align: center; }
.qw-game-logo {
  position: relative;
  width: min(540px, 100%);
  height: 250px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  margin-bottom: 24px;
  overflow: hidden;
  border: 4px solid var(--qw-dark);
  border-radius: 22px;
  background: url("assets/quiz-race-arena.png") center 56% / cover;
  box-shadow: 0 8px 0 var(--qw-dark), var(--qw-shadow);
}
.qw-game-logo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(8,43,46,.05), rgba(8,43,46,.35)); }
.qw-game-logo .qw-avatar { z-index: 1; width: 155px; height: 155px; margin-bottom: -7px; filter: drop-shadow(0 7px 3px rgba(0,0,0,.38)); }
.qw-game-logo strong { position: absolute; top: 28px; left: 50%; z-index: 2; transform: translateX(-50%); color: #effff9; font-size: 27px; line-height: .9; letter-spacing: .12em; text-align: center; text-shadow: 0 3px 0 #082c2f; }
.qw-main-menu { width: min(520px, 100%); display: grid; gap: 12px; }
.qw-menu-button {
  min-height: 86px;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border: 3px solid var(--qw-dark);
  border-radius: 14px;
  background: var(--qw-panel);
  box-shadow: 0 5px 0 var(--qw-dark);
  text-align: left;
  cursor: pointer;
}
.qw-menu-button strong { font-size: 25px; }
.qw-menu-button span { color: var(--qw-muted); font-size: 13px; font-weight: 850; }
.qw-menu-button--primary { color: white; border-color: #c74f00; background: var(--qw-orange); box-shadow: 0 5px 0 #c74f00; }
.qw-menu-button--primary span { color: #fff7cf; }
.qw-menu-button:disabled { color: #7d8686; background: #e4e0d6; box-shadow: 0 3px 0 #9ca2a0; cursor: not-allowed; }
.qw-menu-button:disabled span { color: #737b7b; }
.qw-text-button, .qw-back-button { border: 0; color: var(--qw-dark); background: transparent; font-weight: 900; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.qw-text-button { margin-top: 24px; padding: 10px 14px; }
.qw-back-button { justify-self: start; margin-bottom: 28px; padding: 8px 0; }
.qw-mode-menu { width: min(620px, 100%); display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.qw-mode-card {
  min-height: 330px;
  display: grid;
  justify-items: center;
  align-content: end;
  padding: 20px;
  border: 3px solid var(--qw-dark);
  border-radius: 18px;
  background: var(--qw-panel);
  box-shadow: 0 7px 0 var(--qw-dark);
  cursor: pointer;
}
.qw-mode-card:hover, .qw-mode-card:focus-visible { border-color: var(--qw-orange); transform: translateY(-3px); }
.qw-mode-characters { width: 100%; height: 190px; display: flex; justify-content: center; align-items: end; margin-bottom: 10px; overflow: hidden; }
.qw-mode-characters i { width: 165px; height: 165px; flex: none; }
.qw-mode-characters i + i { margin-left: -85px; transform: scale(.76) translateY(15px); }
.qw-mode-card strong { font-size: 27px; }
.qw-mode-card small { margin-top: 5px; color: var(--qw-muted); font-weight: 800; }
.qw-category-screen { width: min(980px, calc(100vw - 40px)); }
.qw-category-screen h1 { margin-bottom: 10px; }
.qw-category-count { margin: 0 0 20px; color: var(--qw-muted); font-size: 14px; font-weight: 800; text-align: center; }
.qw-category-grid { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.qw-category-card {
  min-height: 156px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  align-items: center;
  gap: 5px 10px;
  padding: 16px;
  border: 3px solid var(--qw-dark);
  border-radius: 14px;
  background: var(--qw-panel);
  box-shadow: 0 5px 0 var(--qw-dark);
  text-align: left;
  cursor: pointer;
}
.qw-category-card:hover, .qw-category-card:focus-visible { border-color: var(--qw-orange); transform: translateY(-3px); }
.qw-category-card.is-selected { border-color: var(--qw-orange); background: #fff3bd; }
.qw-category-icon { grid-row: 1 / 3; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--qw-dark); font-size: 12px; font-weight: 950; }
.qw-category-card strong { font-size: 18px; }
.qw-category-card small { color: var(--qw-muted); font-size: 12px; font-weight: 800; }
.qw-category-card em { grid-column: 1 / -1; align-self: end; color: var(--qw-orange); font-size: 12px; font-style: normal; font-weight: 950; }
.qw-selected-category { margin: -12px 0 16px; color: var(--qw-muted); font-size: 13px; font-weight: 800; }
.qw-selected-category strong { color: var(--qw-orange); }
.qw-entry-screen .qw-entry-form {
  width: min(600px, 100%);
  gap: 16px;
  padding: 24px;
  border: 3px solid var(--qw-dark);
  border-radius: 18px;
  box-shadow: 0 7px 0 var(--qw-dark);
}
.qw-entry-screen .qw-entry-form label { gap: 8px; font-size: 14px; }
.qw-entry-screen .qw-entry-form input { min-height: 52px; font-size: 16px; }
.qw-profile-stage { display: grid; gap: 16px; }
.qw-profile-stage[hidden] { display: none; }
.qw-profile-back { justify-self: start; border: 0; padding: 4px 0; color: var(--qw-dark); background: transparent; font-weight: 900; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.qw-profile-message { margin: 0; padding: 10px 12px; border-left: 4px solid var(--qw-orange); background: #fff3bd; font-weight: 900; }
.qw-entry-screen fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.qw-entry-screen legend { margin-bottom: 9px; font-size: 14px; font-weight: 900; }
.qw-avatar-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.qw-avatar-option {
  aspect-ratio: 1;
  padding: 2px;
  overflow: hidden;
  border: 2px solid var(--qw-line);
  border-radius: 12px;
  background: #f3efe4;
  cursor: pointer;
}
.qw-avatar-option .qw-avatar { width: 100%; height: 100%; }
.qw-avatar-option:hover { border-color: var(--qw-orange); }
.qw-avatar-option.is-selected { border: 4px solid var(--qw-orange); background: #fff3bd; box-shadow: 0 3px 0 #c74f00; }
.qw-entry-screen .qw-primary { min-height: 54px; font-size: 18px; }
.qw-rule-picker { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.qw-rule-picker label { position: relative; min-height: 92px; display: grid; align-content: center; gap: 4px; padding: 12px 14px 12px 46px; border: 2px solid var(--qw-line); border-radius: 12px; background: var(--qw-panel); cursor: pointer; }
.qw-rule-picker label:has(input:checked) { border: 4px solid var(--qw-orange); padding: 10px 12px 10px 44px; background: #fff3bd; }
.qw-rule-picker input { position: absolute; left: 15px; top: 50%; width: 20px; min-height: 20px !important; transform: translateY(-50%); accent-color: var(--qw-orange); }
.qw-rule-picker strong { font-size: 16px; }
.qw-rule-picker span { color: var(--qw-muted); font-size: 12px; font-weight: 800; }
.qw-avatar-drawer {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px;
  grid-template-rows: auto auto auto 1fr;
  gap: 10px 14px;
  align-items: start;
}
.qw-drawing-canvas {
  grid-row: 1 / 5;
  width: 100%;
  aspect-ratio: 1;
  border: 3px solid var(--qw-dark);
  border-radius: 16px;
  background: var(--qw-panel);
  box-shadow: inset 0 0 0 1px var(--qw-line);
  cursor: crosshair;
  touch-action: none;
}
.qw-drawing-colors { display: grid; grid-template-columns: repeat(4, 38px); gap: 7px; }
.qw-color-button {
  width: 38px;
  height: 38px;
  border: 2px solid var(--qw-dark);
  border-radius: 50%;
  background: var(--draw-color);
  cursor: pointer;
}
.qw-color-button.is-selected { outline: 4px solid var(--qw-orange); outline-offset: 2px; }
.qw-drawing-sizes, .qw-drawing-actions { display: grid; gap: 6px; }
.qw-drawing-sizes { grid-template-columns: repeat(3, 1fr); }
.qw-drawing-sizes button, .qw-drawing-actions button {
  min-height: 38px;
  border: 2px solid var(--qw-dark);
  border-radius: 8px;
  background: var(--qw-panel);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
.qw-drawing-sizes button.is-selected { color: white; background: var(--qw-dark); }
.qw-drawing-actions { grid-template-columns: 1fr; }
.qw-drawing-status { align-self: end; margin: 0; color: var(--qw-muted); font-size: 12px; font-weight: 800; }
.qw-admin-login-form { max-width: 460px; }
.qw-admin-screen { width: min(1120px, calc(100vw - 40px)); }
.qw-admin-toolbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.qw-admin-tabs { display: flex; gap: 6px; }
.qw-admin-tabs button, #adminRefresh {
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid var(--qw-dark);
  border-radius: 9px;
  background: var(--qw-panel);
  font-weight: 900;
  cursor: pointer;
}
.qw-admin-tabs button[aria-selected="true"] { color: white; background: var(--qw-dark); }
.qw-room-filter { width: 100%; display: grid; grid-template-columns: auto minmax(220px, 420px); align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 900; }
.qw-room-filter select { min-height: 44px; border: 2px solid var(--qw-dark); border-radius: 9px; padding: 0 10px; background: var(--qw-panel); font: inherit; }
.qw-admin-table-wrap { width: 100%; max-height: 510px; overflow: auto; border: 3px solid var(--qw-dark); border-radius: 14px; background: var(--qw-panel); box-shadow: 0 6px 0 var(--qw-dark); }
.qw-admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.qw-admin-table th { position: sticky; top: 0; z-index: 1; padding: 0; color: white; background: var(--qw-dark); white-space: nowrap; }
.qw-admin-table th button { width: 100%; min-height: 46px; border: 0; padding: 0 12px; color: inherit; background: transparent; font-weight: 900; cursor: pointer; }
.qw-admin-table td { padding: 11px 12px; border-bottom: 1px solid var(--qw-line); text-align: center; white-space: nowrap; }
.qw-admin-table td:nth-child(3), .qw-admin-table td:nth-child(4) { text-align: left; }
.qw-admin-table tr:last-child td { border-bottom: 0; }
.qw-admin-table .qw-empty-row td { padding: 40px 16px; color: var(--qw-muted); text-align: center; }
.qw-admin-updated { min-height: 20px; margin: 12px 0 0; color: var(--qw-muted); font-size: 12px; }

@keyframes qw-screen-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 620px) {
  .qw-entry { min-height: calc(100vh - 66px); padding: 18px 0 36px; }
  .qw-game-logo { height: 210px; margin-bottom: 20px; }
  .qw-game-logo .qw-avatar { width: 128px; height: 128px; }
  .qw-entry-screen h1 { margin-bottom: 20px; }
  .qw-menu-button { min-height: 78px; padding-inline: 18px; }
  .qw-menu-button strong { font-size: 22px; }
  .qw-menu-button span { max-width: 130px; text-align: right; }
  .qw-mode-menu { grid-template-columns: 1fr; }
  .qw-mode-card { min-height: 220px; grid-template-columns: 180px 1fr; grid-template-rows: auto auto; align-content: center; text-align: left; }
  .qw-mode-characters { grid-row: 1 / 3; height: 175px; margin: 0; }
  .qw-mode-card strong, .qw-mode-card small { justify-self: start; }
  .qw-avatar-picker { grid-template-columns: repeat(4, 1fr); }
  .qw-avatar-drawer { grid-template-columns: 1fr; grid-template-rows: auto; }
  .qw-drawing-canvas { grid-row: auto; width: min(270px, 100%); justify-self: center; }
  .qw-drawing-colors { justify-content: center; grid-template-columns: repeat(7, 38px); }
  .qw-drawing-sizes { grid-template-columns: repeat(3, 1fr); }
  .qw-drawing-actions { grid-template-columns: repeat(3, 1fr); }
  .qw-drawing-status { text-align: center; }
  .qw-entry-screen .qw-entry-form { padding: 18px; }
  .qw-rule-picker { grid-template-columns: 1fr; }
  .qw-admin-screen { width: 100%; }
  .qw-admin-toolbar { align-items: stretch; flex-direction: column; }
  .qw-admin-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .qw-room-filter { grid-template-columns: 1fr; }
  .qw-admin-table-wrap { max-height: 560px; }
  .qw-category-screen { width: 100%; }
  .qw-category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qw-category-card { min-height: 138px; padding: 13px; }
}

@media (max-width: 390px) {
  .qw-drawing-colors { grid-template-columns: repeat(7, 34px); gap: 5px; }
  .qw-color-button { width: 34px; height: 34px; }
  .qw-drawing-actions button { padding-inline: 4px; }
  .qw-category-grid { gap: 9px; }
  .qw-category-card { min-height: 126px; grid-template-columns: 38px minmax(0, 1fr); padding: 10px; border-width: 2px; border-radius: 12px; }
  .qw-category-icon { width: 38px; height: 38px; font-size: 10px; }
  .qw-category-card strong { font-size: 15px; }
  .qw-category-card small { font-size: 10px; }
}
