:root {
  --ink: #17002f;
  --ink-2: #2d1260;
  --violet: #7548ff;
  --blue: #50b8ff;
  --mint: #43e1c2;
  --pink: #e779ff;
  --white: #fff;
  --muted: #b7aacb;
  --panel: rgba(255, 255, 255, 0.075);
  --line: rgba(255, 255, 255, 0.13);
  --danger: #ff6c97;
  --success: #55efc4;
  font-family: Inter, Manrope, Montserrat, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--white);
  background: var(--ink);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: linear-gradient(145deg, #100020 0%, #1a0037 52%, #271050 100%);
  overflow-x: hidden;
  isolation: isolate;
}
.host-page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: .16;
  background-image: linear-gradient(rgba(255,255,255,.22) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.22) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.screen-page::before, .player-page::before {
  content: "";
  position: fixed;
  inset: -8%;
  z-index: -1;
  pointer-events: none;
  opacity: .58;
  background: center / cover no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='0'%3E%3Cstop stop-color='%2343e1c2' stop-opacity='.08'/%3E%3Cstop offset='.48' stop-color='%237548ff' stop-opacity='.46'/%3E%3Cstop offset='1' stop-color='%2350b8ff' stop-opacity='.10'/%3E%3C/linearGradient%3E%3ClinearGradient id='p' x1='1' y1='0' x2='0' y2='1'%3E%3Cstop stop-color='%23e779ff' stop-opacity='.12'/%3E%3Cstop offset='.55' stop-color='%237548ff' stop-opacity='.30'/%3E%3Cstop offset='1' stop-color='%2343e1c2' stop-opacity='.06'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath d='M-180 280 C 170 40 420 430 790 230 S 1370 70 1780 330' fill='none' stroke='url(%23g)' stroke-width='150'/%3E%3Cpath d='M-160 790 C 180 560 490 910 840 700 S 1390 520 1770 760' fill='none' stroke='url(%23p)' stroke-width='190'/%3E%3C/svg%3E");
}
.screen-page::after, .player-page::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(8,0,24,.74), rgba(23,0,47,.18) 52%, rgba(8,0,24,.58));
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.logo { width: 154px; height: auto; object-fit: contain; }
.brand-bar { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.eyebrow { color: var(--mint); font-size: 12px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }
.glass { border: 1px solid var(--line); background: var(--panel); box-shadow: 0 28px 90px rgba(4,0,18,.35); backdrop-filter: blur(20px); }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.06); color: #eee7f7; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 16px var(--mint); }
.btn { border: 0; border-radius: 16px; padding: 14px 20px; color: white; background: rgba(255,255,255,.11); font-weight: 750; transition: transform .15s, background .15s, opacity .15s; }
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.17); }
.btn:disabled { cursor: not-allowed; opacity: .38; transform: none; }
.btn-primary { background: linear-gradient(120deg, var(--violet), #9678ff 52%, var(--blue)); box-shadow: 0 12px 34px rgba(117,72,255,.35); }
.btn-primary:hover { background: linear-gradient(120deg, #8259ff, #a48aff 52%, #65c1ff); }
.btn-danger { background: rgba(255,108,151,.18); border: 1px solid rgba(255,108,151,.4); }
.field { width: 100%; border: 1px solid var(--line); background: rgba(255,255,255,.07); border-radius: 14px; padding: 15px 16px; color: white; outline: none; }
.field:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(67,225,194,.12); }
.field::placeholder { color: #9185a5; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 12px 18px; border-radius: 14px; background: #fff; color: var(--ink); font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Big screen */
.screen-shell { min-height: 100vh; padding: clamp(20px, 2.2vw, 42px); display: grid; grid-template-rows: auto 1fr; gap: 24px; }
.screen-grid { display: grid; min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(300px, 26vw); gap: 22px; }
.stage { position: relative; min-height: 0; border-radius: 30px; padding: clamp(28px, 3vw, 56px); overflow: hidden; display: flex; flex-direction: column; }
.stage-content { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; }
.lobby { display: grid; grid-template-columns: minmax(300px, .9fr) 1.1fr; align-items: center; gap: clamp(30px, 5vw, 80px); height: 100%; }
.qr-card { justify-self: center; border-radius: 30px; padding: 18px; background: white; box-shadow: 0 0 70px rgba(80,184,255,.22); }
.qr-card img { display: block; width: min(31vw, 420px); aspect-ratio: 1; }
.join-title { font-size: clamp(44px, 5.2vw, 92px); line-height: .94; letter-spacing: -.055em; margin: 18px 0 26px; }
.join-title span { color: var(--mint); }
.join-note { color: var(--muted); font-size: clamp(17px, 1.35vw, 23px); line-height: 1.5; max-width: 700px; }
.question-meta { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; }
.screen-question-head { position: relative; min-height: clamp(300px, 34vh, 400px); display: flex; flex-direction: column; align-items: center; text-align: center; }
.screen-question-head .question-meta { position: relative; min-height: 74px; padding-right: 90px; padding-left: 90px; }
.screen-question-head .timer { position: absolute; right: 0; top: 0; }
.question-title { margin: auto; font-size: clamp(32px, 3.5vw, 64px); line-height: 1.06; letter-spacing: -.04em; max-width: 1100px; text-align: center; }
.question-title--long { font-size: clamp(29px, 2.85vw, 52px); line-height: 1.09; max-width: 1160px; }
.question-title--compact { font-size: clamp(26px, 2.45vw, 46px); line-height: 1.12; max-width: 1180px; }
.answers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.answer-card { position: relative; min-height: 92px; border-radius: 20px; border: 1px solid var(--line); background: rgba(255,255,255,.07); padding: 22px 22px 22px 68px; display: flex; align-items: center; font-size: clamp(17px, 1.4vw, 25px); font-weight: 650; }
.answer-key { position: absolute; left: 20px; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.11); color: var(--mint); font-weight: 850; }
.answer-card.correct { border-color: var(--success); background: rgba(85,239,196,.13); box-shadow: inset 0 0 0 1px rgba(85,239,196,.22); }
.timer { margin-left: auto; width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; font-size: 27px; font-weight: 850; border: 6px solid rgba(255,255,255,.12); color: var(--mint); box-shadow: inset 0 0 30px rgba(67,225,194,.08); }
.timer.urgent { color: var(--danger); border-color: rgba(255,108,151,.35); }
.progress { width: 100%; height: 4px; margin-top: 20px; border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.1); }
.progress--hidden { visibility: hidden; }
.progress > div { height: 100%; width: 100%; transform-origin: left; background: linear-gradient(90deg, var(--mint), var(--blue), var(--pink)); }
.explanation { margin-top: 18px; color: #ddd2ea; font-size: clamp(15px, 1.2vw, 20px); line-height: 1.45; }
.leaderboard { border-radius: 28px; padding: 24px; overflow: hidden; display: flex; flex-direction: column; }
.leaderboard h2 { font-size: 22px; margin: 8px 0 18px; }
.leader-list { display: flex; flex-direction: column; gap: 7px; min-height: 0; overflow: hidden; }
.leader-row { display: grid; grid-template-columns: 28px 38px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 48px; padding: 6px 10px; border-radius: 12px; background: rgba(255,255,255,.045); }
.leader-row:nth-child(1) { background: linear-gradient(90deg, rgba(67,225,194,.22), rgba(255,255,255,.05)); }
.rank { color: var(--mint); font-weight: 850; }
.leader-name { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-weight: 650; }
.leader-score { min-width: 44px; text-align: right; font-size: clamp(22px, 1.7vw, 30px); line-height: 1; font-weight: 900; color: white; }
.empty { color: var(--muted); text-align: center; margin: auto; line-height: 1.5; }
.podium { display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; gap: 14px; margin: auto 0; }
.final-heading { text-align: center; }
.final-heading .join-title { margin: 10px 0 28px; }
.winner { border: 1px solid var(--line); border-radius: 22px 22px 12px 12px; padding: 20px 12px; text-align: center; background: linear-gradient(180deg, rgba(117,72,255,.28), rgba(255,255,255,.06)); display: flex; flex-direction: column; align-items: center; }
.winner--1 { height: clamp(300px, 34vh, 360px); order: 3; background: linear-gradient(180deg, rgba(67,225,194,.38), rgba(255,255,255,.06)); }
.winner--2 { height: clamp(280px, 31vh, 330px); order: 2; }
.winner--3 { height: clamp(260px, 28vh, 300px); order: 4; }
.winner--4 { height: clamp(240px, 25vh, 270px); order: 1; }
.winner--5 { height: clamp(220px, 22vh, 240px); order: 5; }
.winner-rank { color: var(--mint); font-weight: 900; font-size: 28px; }
.winner-name { margin: 16px 0 8px; font-size: clamp(16px, 1.3vw, 23px); font-weight: 850; overflow-wrap: anywhere; }
.winner-score { margin-top: auto; font-weight: 800; }

.avatar { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center; background: linear-gradient(135deg, var(--mint), var(--violet)); color: white; font-weight: 900; box-shadow: 0 0 0 2px rgba(255,255,255,.14); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-leader { width: 34px; height: 34px; font-size: 14px; }
.winner-avatar { width: clamp(68px, 6vw, 104px); height: clamp(68px, 6vw, 104px); margin-bottom: 14px; font-size: 32px; box-shadow: 0 0 0 4px rgba(255,255,255,.13), 0 12px 38px rgba(80,184,255,.22); }

@media (min-width: 601px) and (max-height: 800px) {
  .leaderboard { padding: 18px; }
  .leaderboard h2 { font-size: 20px; margin: 4px 0 10px; }
  .leader-list { gap: 3px; }
  .leader-row { grid-template-columns: 22px 28px minmax(0, 1fr) auto; gap: 7px; min-height: 32px; padding: 2px 7px; font-size: 14px; }
  .avatar-leader { width: 26px; height: 26px; font-size: 11px; }
  .leader-score { min-width: 34px; font-size: 20px; }
  .final-heading .join-title { margin: 6px 0 12px; font-size: clamp(40px, 4.4vw, 60px); }
  .winner { padding: 14px 10px; }
  .winner--1 { height: 230px; }
  .winner--2 { height: 215px; }
  .winner--3 { height: 200px; }
  .winner--4 { height: 185px; }
  .winner--5 { height: 170px; }
  .winner-avatar { width: 56px; height: 56px; margin-bottom: 8px; font-size: 24px; }
  .winner-rank { font-size: 22px; }
  .winner-name { margin: 8px 0 4px; font-size: 15px; line-height: 1.1; }
  .winner-score { font-size: 14px; }
}

/* Host */
.host-shell { width: min(1180px, calc(100% - 34px)); margin: 0 auto; padding: 28px 0 70px; }
.host-card { margin-top: 28px; border-radius: 26px; padding: 28px; }
.host-title { font-size: clamp(34px, 5vw, 64px); letter-spacing: -.05em; margin: 30px 0 10px; }
.host-sub { color: var(--muted); max-width: 700px; line-height: 1.6; }
.create-grid { margin-top: 30px; display: grid; grid-template-columns: 1fr 180px auto; gap: 12px; }
.host-top { display: grid; grid-template-columns: 1fr auto; gap: 22px; align-items: start; }
.host-links { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.host-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.host-status { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 22px; }
.stat { border-radius: 16px; padding: 16px; background: rgba(255,255,255,.055); }
.stat span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.stat strong { display: block; margin-top: 7px; font-size: 24px; }
.host-question { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 20px; }
.host-question h3 { margin: 8px 0; font-size: 24px; }

/* Player */
.phone-shell { width: min(560px, 100%); min-height: 100vh; margin: 0 auto; padding: 22px 18px 34px; display: flex; flex-direction: column; }
.phone-header { display: flex; align-items: center; justify-content: center; }
.phone-card { margin-top: 22px; flex: 1; border-radius: 26px; padding: 24px; display: flex; flex-direction: column; }
.join-form { margin: auto 0; }
.join-form h1 { font-size: 46px; line-height: .97; letter-spacing: -.055em; margin: 14px 0 18px; }
.join-form p { color: var(--muted); line-height: 1.55; }
.join-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.join-submit { width: 100%; margin-top: 12px; }
.avatar-upload { display: flex; align-items: center; gap: 16px; margin: 24px 0 10px; }
.avatar-upload.has-photo { align-items: flex-end; }
.avatar-preview { width: 76px; height: 76px; font-size: 26px; }
.avatar-preview.editing {
  position: relative;
  width: 156px;
  height: 156px;
  display: block;
  touch-action: none;
  cursor: grab;
  background: #17002f;
  box-shadow: 0 0 0 3px rgba(255,255,255,.15), 0 14px 42px rgba(80,184,255,.22);
}
.avatar-preview.editing:focus-visible { outline: 3px solid var(--mint); outline-offset: 5px; }
.avatar-preview.editing.dragging { cursor: grabbing; }
.avatar-preview.editing img {
  position: absolute;
  top: 0;
  left: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.avatar-upload-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.avatar-upload-copy span { color: var(--muted); font-size: 12px; }
.avatar-button { display: inline-flex; width: auto !important; padding: 11px 15px; }
.player-status { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.player-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.player-identity strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-score { font-weight: 900; color: var(--mint); }
.phone-question-head { min-height: 238px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; padding-top: 18px; }
.phone-question-meta { position: relative; padding-right: 62px; min-height: 56px; margin-bottom: 18px; }
.phone-timer { position: absolute; right: 0; width: 52px; height: 52px; font-size: 19px; border-width: 5px; }
.phone-question { margin: auto 0; font-size: 29px; line-height: 1.08; letter-spacing: -.035em; text-align: center; }
.phone-answers { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.phone-answer { width: 100%; min-height: 68px; text-align: left; border: 1px solid var(--line); border-radius: 17px; color: white; background: rgba(255,255,255,.07); padding: 15px 16px; display: grid; grid-template-columns: 36px 1fr; align-items: center; gap: 10px; font-weight: 700; }
.phone-answer.selected { border-color: var(--blue); background: rgba(80,184,255,.16); }
.phone-answer.correct { border-color: var(--success); background: rgba(85,239,196,.16); }
.phone-answer.wrong { border-color: var(--danger); background: rgba(255,108,151,.14); }
.phone-answer:disabled { cursor: default; }
.phone-key { color: var(--mint); }
.answer-change-hint { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.wait-state { margin: auto; text-align: center; }
.avatar-lobby { width: 116px; height: 116px; margin: 0 auto 28px; font-size: 40px; box-shadow: 0 0 60px rgba(80,184,255,.2); }
.result-big { margin: 24px 0 8px; font-size: 64px; font-weight: 950; color: var(--mint); }
.result-big.wrong-result { color: #e8d8f2; filter: saturate(.72); }
.avatar-final-player { width: 112px; height: 112px; margin: 0 auto 22px; font-size: 40px; }
.final-rank { font-size: 84px; font-weight: 950; color: var(--mint); letter-spacing: -.08em; }

@media (max-width: 900px) {
  .screen-grid { grid-template-columns: 1fr; }
  .leaderboard { display: none; }
  .lobby { grid-template-columns: 1fr; text-align: center; }
  .qr-card img { width: min(48vw, 360px); }
  .answers-grid { grid-template-columns: 1fr; }
  .create-grid { grid-template-columns: 1fr; }
  .host-status { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .logo { width: 124px; }
  .phone-card { padding: 20px; }
  .join-fields { grid-template-columns: 1fr; }
  .avatar-upload.has-photo { align-items: center; flex-direction: column; text-align: center; }
  .avatar-upload.has-photo .avatar-upload-copy { align-items: center; }
  .phone-question-head { min-height: 228px; }
  .player-status { align-items: flex-start; }
  .player-score { font-size: 13px; white-space: nowrap; }
  .host-top { grid-template-columns: 1fr; }
  .podium { grid-template-columns: 1fr; align-items: stretch; }
  .winner, .winner:nth-child(n), .winner[class*="winner--"] { height: auto; min-height: 0; order: initial; }
}
