:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
  --bg-deep: #0b0e22;
  --bg-mid: #171b3d;
  --surface: rgba(28, 33, 74, 0.82);
  --surface-strong: #202654;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f8f9ff;
  --muted: #aeb5d8;
  --purple: #8b5cf6;
  --purple-light: #bca7ff;
  --brand: #f97316;
  --brand-light: #ffb26f;
  --cyan: #39d8ec;
  --green: #39df8f;
  --red: #ff4b68;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 15% 10%, rgba(139, 92, 246, 0.3), transparent 34%),
    radial-gradient(circle at 88% 80%, rgba(57, 216, 236, 0.16), transparent 38%),
    linear-gradient(145deg, var(--bg-deep), var(--bg-mid));
  color: var(--text);
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.app-shell {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.loading-card,
.home-screen,
.complete-screen,
.error-screen {
  width: min(100%, 560px);
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.loading-card {
  gap: 16px;
  color: var(--muted);
}

.loading-mark,
.brand-mark,
.complete-icon,
.error-icon {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: 28px;
  background: linear-gradient(145deg, var(--brand), #e34d18 58%, #713fe8);
  box-shadow: 0 22px 60px rgba(196, 74, 25, 0.36);
  color: white;
  font-size: 52px;
  font-weight: 900;
}

.loading-mark {
  animation: breathe 1.4s ease-in-out infinite alternate;
}

@keyframes breathe {
  to {
    transform: scale(1.05);
    box-shadow: 0 24px 72px rgba(139, 92, 246, 0.58);
  }
}

.brand-mark {
  position: relative;
  isolation: isolate;
  width: 104px;
  height: 104px;
  margin-bottom: 26px;
  border-radius: 34px;
  overflow: hidden;
}

.brand-question {
  position: relative;
  z-index: 2;
  font-size: 48px;
  font-weight: 950;
  line-height: 1;
}

.brand-dot {
  position: absolute;
  z-index: 1;
  border-radius: 999px;
  background: var(--cyan);
  opacity: 0.65;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 18px;
  direction: ltr;
  line-height: 1;
}

.brand-name {
  color: white;
  font-size: clamp(40px, 10vw, 64px);
  font-weight: 950;
  letter-spacing: -0.055em;
}

.brand-by {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.brand-by strong {
  color: var(--brand-light);
  letter-spacing: 0.16em;
}

.brand-lockup.is-compact {
  align-items: flex-start;
  gap: 2px;
  margin: 0 0 5px;
}

.brand-lockup.is-compact .brand-name {
  font-size: clamp(19px, 4.5vw, 25px);
  letter-spacing: -0.035em;
}

.brand-lockup.is-compact .brand-by {
  font-size: 8px;
}

[dir="rtl"] .brand-lockup.is-compact {
  align-items: flex-start;
}

.brand-dot-one {
  width: 42px;
  height: 42px;
  right: -10px;
  top: -8px;
}

.brand-dot-two {
  width: 24px;
  height: 24px;
  left: 10px;
  bottom: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: clamp(11px, 2.4vw, 13px);
  font-weight: 850;
  letter-spacing: 0.17em;
}

.complete-screen h1,
.error-screen h1 {
  margin: 0;
  font-size: clamp(38px, 10vw, 64px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.home-copy {
  max-width: 420px;
  margin: 12px auto 22px;
  color: var(--muted);
  font-size: clamp(15px, 3.5vw, 19px);
  line-height: 1.5;
}

.language-picker,
.session-picker {
  width: 100%;
  max-width: 390px;
  padding: 0;
  border: 0;
}

.language-picker {
  margin-bottom: 18px;
}

.language-picker legend,
.session-picker legend {
  width: 100%;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.language-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: rgba(5, 8, 26, 0.42);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.language-button.is-selected {
  border-color: rgba(249, 115, 22, 0.7);
  background: rgba(249, 115, 22, 0.14);
  color: var(--brand-light);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.12);
}

.segment-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(5, 8, 26, 0.42);
}

.segment {
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  cursor: pointer;
}

.segment.is-selected {
  background: var(--surface-strong);
  color: white;
  box-shadow: inset 0 0 0 1px rgba(188, 167, 255, 0.3);
}

.home-actions {
  width: 100%;
  max-width: 390px;
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 12px 18px;
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
  touch-action: manipulation;
}

.button:focus-visible,
.segment:focus-visible,
.language-button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

.button:disabled {
  cursor: default;
  opacity: 0.45;
}

.button-large {
  min-height: 58px;
  font-size: 17px;
}

.button-primary {
  background: linear-gradient(135deg, var(--brand), #e85d14);
  box-shadow: 0 14px 38px rgba(196, 74, 25, 0.3);
}

.button-ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.045);
}

.hint {
  margin: 22px 0 0;
  color: #848caf;
  font-size: 12px;
}

.game-screen {
  width: min(100%, 940px);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(112px, auto) minmax(0, 1fr) auto auto;
  gap: clamp(9px, 1.8vh, 17px);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.question-count {
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 2.8vw, 16px);
}

.question-count strong {
  color: white;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(255, 75, 104, 0.3);
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(255, 75, 104, 0.1);
  color: #ff8da0;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.live-pill span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 75, 104, 0.13);
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--cyan));
  transition: width 220ms ease;
}

.question-card {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  min-height: 112px;
  overflow: hidden;
  border: 1px solid rgba(188, 167, 255, 0.23);
  border-radius: clamp(20px, 4vw, 30px);
  padding: clamp(18px, 4vw, 34px);
  background:
    linear-gradient(135deg, rgba(139, 92, 246, 0.16), rgba(57, 216, 236, 0.06)),
    var(--surface);
  box-shadow: 0 18px 60px rgba(4, 7, 24, 0.28);
}

.question-card h1 {
  position: relative;
  z-index: 2;
  max-width: 880px;
  margin: 0;
  font-size: clamp(20px, 5vw, 38px);
  line-height: 1.18;
  letter-spacing: -0.025em;
}

.question-number {
  position: absolute;
  z-index: 1;
  right: 14px;
  bottom: -25px;
  color: rgba(255, 255, 255, 0.045);
  font-size: clamp(100px, 24vw, 180px);
  font-weight: 950;
  line-height: 1;
}

.answers {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(7px, 1.4vh, 12px);
}

.answer {
  min-height: 52px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(11px, 2.8vw, 18px);
  border: 1px solid var(--line);
  border-radius: clamp(15px, 3vw, 20px);
  padding: clamp(9px, 1.7vh, 15px) clamp(12px, 3vw, 18px);
  background: rgba(27, 32, 69, 0.78);
  transition: opacity 180ms ease, border-color 180ms ease, background 180ms ease;
}

.answer-letter {
  display: grid;
  place-items: center;
  width: clamp(34px, 8vw, 44px);
  height: clamp(34px, 8vw, 44px);
  border-radius: 13px;
  background: rgba(139, 92, 246, 0.17);
  color: var(--purple-light);
  font-size: clamp(14px, 3.4vw, 17px);
  font-weight: 950;
}

.answer-text {
  font-size: clamp(14px, 3.4vw, 19px);
  font-weight: 720;
  line-height: 1.25;
}

.answer.is-correct {
  border-color: rgba(57, 223, 143, 0.72);
  background: rgba(27, 116, 78, 0.42);
  box-shadow: 0 0 0 1px rgba(57, 223, 143, 0.18), 0 12px 34px rgba(10, 95, 59, 0.2);
}

.answer.is-correct .answer-letter {
  background: var(--green);
  color: #092c1e;
}

.answer.is-dimmed {
  opacity: 0.43;
}

.answer-check {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--green);
  color: #092c1e;
  font-weight: 950;
}

.answer-status {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: clamp(12px, 2.8vw, 15px);
}

.answer-status strong {
  color: var(--green);
}

.chat-prompt::before {
  content: "●";
  margin-right: 8px;
  color: var(--cyan);
}

.host-controls {
  display: grid;
  grid-template-columns: minmax(74px, 0.8fr) minmax(150px, 1.5fr) minmax(88px, 0.9fr);
  gap: clamp(7px, 1.8vw, 12px);
}

.button-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.button-reveal {
  background: linear-gradient(135deg, var(--brand), #e85d14);
}

.button-muted {
  border-color: rgba(57, 223, 143, 0.28);
  background: rgba(57, 223, 143, 0.1);
  color: var(--green);
}

.button-next {
  border-color: rgba(57, 216, 236, 0.26);
  background: rgba(57, 216, 236, 0.11);
  color: #85effb;
}

.complete-screen,
.error-screen {
  gap: 16px;
}

.complete-icon {
  margin-bottom: 14px;
  background: linear-gradient(145deg, var(--green), #179b5d);
  color: #062d1d;
}

.complete-screen p:not(.eyebrow),
.error-screen p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 17px;
}

.complete-screen .button {
  width: min(100%, 360px);
}

.error-icon {
  margin-bottom: 14px;
  background: linear-gradient(145deg, var(--red), #c72b48);
}

.pause-cover {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-deep);
  pointer-events: all;
}

@media (max-aspect-ratio: 3 / 4) {
  body.game-active .app-shell {
    padding-bottom: max(28vh, calc(150px + env(safe-area-inset-bottom)));
  }

  body.game-active .game-screen {
    grid-template-rows: auto 4px minmax(72px, auto) minmax(0, 1fr) auto auto;
    gap: clamp(5px, 0.9vh, 8px);
  }

  body.game-active .question-card {
    min-height: 72px;
    padding: clamp(11px, 2.2vh, 17px) 16px;
    border-radius: 19px;
  }

  body.game-active .question-card h1 {
    font-size: clamp(17px, 4.7vw, 24px);
    line-height: 1.12;
  }

  body.game-active .answers {
    gap: clamp(5px, 0.8vh, 8px);
  }

  body.game-active .answer {
    min-height: 38px;
    gap: 10px;
    border-radius: 14px;
    padding: 6px 10px;
  }

  body.game-active .answer-letter {
    width: clamp(29px, 7vw, 36px);
    height: clamp(29px, 7vw, 36px);
    border-radius: 10px;
  }

  body.game-active .answer-text {
    font-size: clamp(12px, 3.2vw, 16px);
  }

  body.game-active .answer-status {
    min-height: 24px;
    font-size: clamp(10px, 2.6vw, 13px);
  }

  body.game-active .button {
    min-height: 48px;
    padding: 8px 10px;
    border-radius: 14px;
    font-size: clamp(11px, 3vw, 14px);
  }

  body.game-active .host-controls {
    grid-template-columns: minmax(58px, 0.75fr) minmax(126px, 1.45fr) minmax(70px, 0.85fr);
    gap: 6px;
  }
}

/*
 * YouTube's tall live-viewer layout covers the first ~14% with stream chrome,
 * then places chat, reactions and the creator camera over the lower ~43%.
 * Keep every meaningful game element inside the unobstructed middle band.
 */
@media (max-aspect-ratio: 1 / 2) {
  body.game-active .app-shell,
  body.home-active .app-shell,
  body.complete-active .app-shell,
  body.error-active .app-shell {
    padding-top: max(14dvh, calc(8px + env(safe-area-inset-top)));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(44dvh, calc(8px + env(safe-area-inset-bottom)));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  body.game-active .game-screen {
    grid-template-rows: auto 3px minmax(56px, auto) minmax(0, 1fr) 18px 44px;
    gap: 4px;
  }

  body.game-active .brand-lockup.is-compact {
    gap: 0;
    margin-bottom: 2px;
  }

  body.game-active .brand-lockup.is-compact .brand-name {
    font-size: clamp(17px, 4.5vw, 21px);
  }

  body.game-active .brand-lockup.is-compact .brand-by {
    font-size: 6px;
  }

  body.game-active .question-count {
    font-size: clamp(10px, 2.7vw, 12px);
  }

  body.game-active .live-pill {
    gap: 5px;
    padding: 5px 8px;
    font-size: 9px;
  }

  body.game-active .live-pill span {
    width: 6px;
    height: 6px;
    box-shadow: 0 0 0 3px rgba(255, 75, 104, 0.13);
  }

  body.game-active .question-card {
    min-height: 56px;
    border-radius: 16px;
    padding: 8px 13px;
  }

  body.game-active .question-card h1 {
    display: -webkit-box;
    overflow: hidden;
    font-size: clamp(15px, 4.25vw, 20px);
    line-height: 1.1;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  body.game-active .question-number {
    bottom: -18px;
    font-size: clamp(76px, 20vw, 110px);
  }

  body.game-active .answers {
    gap: 4px;
  }

  body.game-active .answer {
    min-height: 32px;
    gap: 8px;
    border-radius: 11px;
    padding: 3px 8px;
  }

  body.game-active .answer-letter {
    width: clamp(25px, 6.7vw, 30px);
    height: clamp(25px, 6.7vw, 30px);
    border-radius: 8px;
    font-size: clamp(11px, 2.9vw, 13px);
  }

  body.game-active .answer-text {
    display: -webkit-box;
    overflow: hidden;
    font-size: clamp(11px, 3vw, 14px);
    line-height: 1.12;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  body.game-active .answer-check {
    width: 24px;
    height: 24px;
  }

  body.game-active .answer-status {
    min-height: 18px;
    overflow: hidden;
    font-size: clamp(9px, 2.4vw, 11px);
    line-height: 1;
    white-space: nowrap;
  }

  body.game-active .button {
    min-height: 44px;
    border-radius: 12px;
    padding: 5px 8px;
    font-size: clamp(10px, 2.7vw, 12px);
  }

  body.game-active .host-controls {
    grid-template-columns: minmax(52px, 0.72fr) minmax(118px, 1.55fr) minmax(62px, 0.83fr);
    gap: 5px;
  }

  body.home-active .home-screen {
    justify-content: flex-start;
    overflow: hidden;
    padding: 0;
  }

  body.home-active .brand-mark {
    display: none;
  }

  body.home-active .brand-lockup:not(.is-compact) {
    gap: 1px;
    margin-bottom: 3px;
  }

  body.home-active .brand-lockup:not(.is-compact) .brand-name {
    font-size: clamp(29px, 8vw, 36px);
  }

  body.home-active .brand-by {
    font-size: 7px;
  }

  body.home-active .eyebrow {
    margin-bottom: 2px;
    font-size: 9px;
  }

  body.home-active .home-copy {
    margin: 2px auto 7px;
    font-size: clamp(11px, 2.8vw, 13px);
    line-height: 1.2;
  }

  body.home-active .language-picker {
    margin-bottom: 6px;
  }

  body.home-active .language-picker legend,
  body.home-active .session-picker legend {
    margin-bottom: 4px;
    font-size: 10px;
  }

  body.home-active .language-grid {
    gap: 4px;
  }

  body.home-active .language-button {
    min-height: 34px;
    border-radius: 10px;
    padding: 3px;
    font-size: 10px;
  }

  body.home-active .segment-control {
    gap: 4px;
    border-radius: 13px;
    padding: 3px;
  }

  body.home-active .segment {
    min-height: 34px;
    border-radius: 10px;
    font-size: 11px;
  }

  body.home-active .home-actions {
    gap: 4px;
    margin-top: 6px;
  }

  body.home-active .button {
    min-height: 42px;
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 12px;
  }

  body.home-active .hint {
    display: none;
  }

  body.complete-active .complete-screen,
  body.error-active .error-screen {
    gap: 7px;
  }

  body.complete-active .complete-icon,
  body.error-active .error-icon {
    width: 56px;
    height: 56px;
    margin-bottom: 3px;
    border-radius: 18px;
    font-size: 32px;
  }

  body.complete-active .complete-screen h1,
  body.error-active .error-screen h1 {
    font-size: clamp(27px, 7vw, 36px);
  }

  body.complete-active .complete-screen p:not(.eyebrow),
  body.error-active .error-screen p {
    margin-bottom: 3px;
    font-size: 12px;
  }

  body.complete-active .button,
  body.error-active .button {
    min-height: 42px;
    padding: 7px 10px;
    font-size: 12px;
  }
}

@media (min-aspect-ratio: 4 / 3) {
  .game-screen {
    grid-template-columns: minmax(280px, 0.95fr) minmax(420px, 1.35fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    column-gap: clamp(16px, 3vw, 32px);
  }

  .game-header,
  .progress-track {
    grid-column: 1 / -1;
  }

  .question-card {
    grid-column: 1;
    grid-row: 3;
    align-self: stretch;
  }

  .answers {
    grid-column: 2;
    grid-row: 3;
  }

  .answer-status {
    grid-column: 1;
    grid-row: 4;
  }

  .host-controls {
    grid-column: 2;
    grid-row: 4;
  }
}

@media (max-height: 620px) and (max-aspect-ratio: 4 / 3) {
  body:not(.game-active) .app-shell {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  body.game-active .game-screen {
    gap: 6px;
  }

  body.game-active .question-card {
    min-height: 58px;
    padding: 9px 13px;
  }

  body.game-active .answer {
    min-height: 31px;
    padding-block: 3px;
  }

  body.game-active .answer-letter {
    width: 27px;
    height: 27px;
  }

  body.game-active .answer-status {
    min-height: 20px;
  }

  body.game-active .button {
    min-height: 48px;
    padding-block: 7px;
  }
}

@media (max-height: 760px) {
  .home-screen {
    justify-content: flex-start;
    overflow-y: auto;
    padding-block: 18px;
  }

  .brand-mark {
    width: 76px;
    height: 76px;
    margin-bottom: 14px;
    border-radius: 24px;
  }

  .brand-question {
    font-size: 38px;
  }

  .brand-lockup:not(.is-compact) {
    margin-bottom: 12px;
  }

  .brand-lockup:not(.is-compact) .brand-name {
    font-size: 42px;
  }
}

@media (max-width: 350px) {
  .button-icon span {
    display: none;
  }

  .host-controls {
    grid-template-columns: 56px 1fr 62px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
