/* 참가자 화면. 360x640 기준으로 설계하고 위로 확장한다. */

.quiz-body {
  min-height: 100vh;   /* 폴백 */
  min-height: 100dvh;  /* iOS Safari 주소창 접힘 대응 */
  overflow-x: hidden;
}

.screen {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(1.25rem + env(safe-area-inset-top))
    calc(1.25rem + env(safe-area-inset-right))
    calc(1.25rem + env(safe-area-inset-bottom))
    calc(1.25rem + env(safe-area-inset-left));
}

.muted { color: var(--text-dim); }
.small { font-size: .82rem; }

/* ── 배경 블롭 ────────────────────────────────── */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bg-blobs span {
  position: absolute;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .28;
  animation: drift 22s ease-in-out infinite;
}
.bg-blobs span:nth-child(1) { background: #7c5cff; top: -14vmax; left: -12vmax; }
.bg-blobs span:nth-child(2) { background: #2f86e8; bottom: -18vmax; right: -12vmax; animation-delay: -7s; }
.bg-blobs span:nth-child(3) { background: #e84a63; top: 32%; right: -20vmax; animation-delay: -14s; }

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(4vmax, -3vmax) scale(1.08); }
  66%      { transform: translate(-3vmax, 4vmax) scale(.94); }
}

/* ── 연결 상태 배너 ───────────────────────────── */
.conn-banner {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .5rem;
  padding: .45rem .9rem;
  border-radius: var(--r-full);
  background: #1a1f4ded;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
  font-size: .8rem;
  font-weight: 600;
  animation: banner-in .3s var(--ease);
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse-dot 1.1s ease-in-out infinite;
}
.conn-banner.is-ok      { color: var(--ok); }
.conn-banner.is-ok .conn-dot     { background: var(--ok); animation: none; }
.conn-banner.is-failed  { color: var(--danger); }
.conn-banner.is-failed .conn-dot { background: var(--danger); }

@keyframes banner-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
}
@keyframes pulse-dot {
  50% { opacity: .3; transform: scale(.75); }
}

/* ── ① 닉네임 입력 ────────────────────────────── */
#screen-join { justify-content: center; align-items: center; }

.join-card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 2rem 1.6rem;
  background: #171b45cc;
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: rise-in .45s var(--ease);
}
.join-title {
  margin: 0;
  font-size: clamp(1.6rem, 7vw, 2.1rem);
  letter-spacing: -.02em;
}
.join-sub { margin: 0 0 .4rem; font-size: .92rem; color: var(--text-dim); }

.join-input {
  min-height: 56px;       /* 모바일 터치 타겟 */
  font-size: 1.05rem;
  text-align: center;
}
.join-submit { min-height: 54px; font-size: 1.02rem; margin-top: .3rem; }

.join-error {
  margin: 0;
  color: var(--danger);
  font-size: .87rem;
  text-align: center;
  animation: shake .4s var(--ease);
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}

/* ── ② 대기실 ────────────────────────────────── */
.lobby-head { text-align: center; margin-bottom: 1.25rem; }
.lobby-eyebrow {
  margin: 0;
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--text-dim);
}
.lobby-count {
  margin: .1rem 0 .2rem;
  font-size: clamp(2.8rem, 14vw, 4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  background: linear-gradient(135deg, #fff, var(--accent-soft));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.lobby-unit { font-size: .38em; font-weight: 700; margin-left: .12em; }
.lobby-me { margin: 0; font-size: .92rem; color: var(--text-dim); }
.lobby-me b { color: var(--accent-soft); }

.chips {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: .5rem;
  align-content: start;
  overflow-y: auto;
}
@media (min-width: 700px) {
  .chips { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

.chip-player {
  padding: .55rem .5rem;
  border-radius: var(--r-md);
  background: #212759cc;
  border: 1px solid var(--border-soft);
  text-align: center;
  font-size: .86rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: chip-pop .42s var(--ease) backwards;
}
/* 끊긴 참가자 — 사라지게 하지 않고 흐리게 둔다. 모바일은 잠깐씩 끊긴다. */
.chip-player.is-away { opacity: .38; }
.chip-player.is-me {
  border-color: var(--accent);
  background: #7c5cff2e;
  color: var(--accent-soft);
}

@keyframes chip-pop {
  0%   { opacity: 0; transform: scale(.6) translateY(10px); }
  70%  { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

.lobby-foot { text-align: center; padding-top: 1rem; font-size: .9rem; }

.shimmer {
  background: linear-gradient(90deg,
    var(--text-mute) 0%, var(--text) 45%, var(--text-mute) 90%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.4s linear infinite;
}
@keyframes shimmer {
  to { background-position: -220% 0; }
}

/* ── ③ 진행 중 안내 ───────────────────────────── */
#screen-wait-next { justify-content: center; align-items: center; }

.notice-card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .7rem;
  padding: 2.2rem 1.6rem;
  text-align: center;
  background: #171b45cc;
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: rise-in .45s var(--ease);
}
.notice-icon { font-size: 2.4rem; }
.notice-card h2 { margin: 0; font-size: 1.25rem; }
.notice-card p  { margin: 0; font-size: .92rem; line-height: 1.65; }

/* ── ④ 카운트다운 ────────────────────────────── */
.screen-center { justify-content: center; align-items: center; }

.cd-label {
  margin: 0 0 .5rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .04em;
}
.cd-number {
  font-size: clamp(6rem, 34vw, 11rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  background: linear-gradient(135deg, #fff, var(--accent-soft));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.cd-number.tick { animation: cd-tick .85s var(--ease); }

@keyframes cd-tick {
  0%   { opacity: 0; transform: scale(1.7); }
  35%  { opacity: 1; transform: scale(1); }
  100% { opacity: .85; transform: scale(.97); }
}

/* ── ⑤ 문제 ─────────────────────────────────── */
.screen-question { gap: .75rem; }

.q-top {
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-shrink: 0;
}
.q-index {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
}
.q-bar-track {
  flex: 1;
  height: 10px;
  border-radius: var(--r-full);
  background: #ffffff14;
  overflow: hidden;
}
.q-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: var(--r-full);
  background: var(--ok);
  transform-origin: left center;
  /* 남은 시간에 따라 색이 바뀐다 — 숫자를 안 봐도 촉박함이 전달된다 */
  transition: background-color .5s linear;
}
.q-bar-fill.warn   { background: var(--warn); }
.q-bar-fill.danger { background: var(--danger); }
.q-secs {
  min-width: 2.1ch;
  text-align: right;
  font-size: 1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.q-secs.urgent { color: var(--danger); animation: pulse-num .9s ease-in-out infinite; }

@keyframes pulse-num {
  50% { transform: scale(1.18); }
}

.q-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  min-height: 0;
}
.q-image {
  max-width: 100%;
  max-height: 28dvh;
  border-radius: var(--r-md);
  object-fit: contain;
  animation: pop-in .35s var(--ease);
}
.q-text {
  margin: 0;
  text-align: center;
  font-size: clamp(1.05rem, 4.4vw, 1.5rem);
  font-weight: 700;
  line-height: 1.45;
  animation: rise-in .35s var(--ease);
}

/* 선택지는 화면 하단에 둔다 — 한 손 조작 시 엄지 도달 범위 */
.choices-grid {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}
/* 긴 선택지는 2열에서 읽기 어려우므로 1열로 편다 */
.choices-grid.stacked { grid-template-columns: 1fr; }

.choice-btn {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 88px;
  padding: .8rem .85rem;
  border-radius: var(--r-md);
  text-align: left;
  font-size: clamp(.9rem, 3.6vw, 1.05rem);
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  box-shadow: var(--shadow-sm);
  transition: transform var(--fast), opacity var(--fast), filter var(--fast);
  animation: choice-in .38s var(--ease) backwards;
}
.choice-btn[data-i="0"] { background: var(--c0); }
.choice-btn[data-i="1"] { background: var(--c1); }
.choice-btn[data-i="2"] { background: var(--c2); }
.choice-btn[data-i="3"] { background: var(--c3); }

.choice-shape {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: #00000030;
  font-size: .95rem;
}
.choice-btn:active { transform: scale(.96); }

/* 선택 후: 고른 것만 남기고 나머지는 물러난다 */
.choice-btn.picked { transform: scale(1.03); box-shadow: 0 0 0 3px #fff8, var(--shadow-md); }
.choice-btn.dimmed { opacity: .32; filter: saturate(.5); }

/* 정답 공개 */
.choice-btn.is-correct { box-shadow: 0 0 0 3px var(--ok), 0 0 22px #16c79a88; opacity: 1; }
.choice-btn.is-wrong   { animation: shake .42s var(--ease); }

@keyframes choice-in {
  from { opacity: 0; transform: translateY(14px); }
}

.answered-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0d1030d0;
  backdrop-filter: blur(6px);
  z-index: 40;
  animation: fade-in .25s var(--ease);
}
.answered-card {
  text-align: center;
  animation: pop-in .4s var(--ease);
}
.answered-check {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  margin: 0 auto .8rem;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 2.1rem;
  font-weight: 800;
}
.answered-title { margin: 0; font-size: 1.35rem; font-weight: 800; }
.answered-sub   { margin: .35rem 0 0; font-size: .92rem; color: var(--text-dim); }

@keyframes fade-in { from { opacity: 0; } }

/* ── ⑥ 정답 공개 ─────────────────────────────── */
.reveal-card {
  text-align: center;
  padding: 2rem 1.5rem;
  animation: pop-in .4s var(--ease);
}
.reveal-icon {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  font-size: 2.6rem;
  font-weight: 800;
  color: #fff;
  background: var(--ok);
}
.reveal-card.wrong .reveal-icon   { background: var(--danger); }
.reveal-card.missed .reveal-icon  { background: var(--text-mute); }
.reveal-title  { margin: 0 0 .5rem; font-size: 1.6rem; }
.reveal-answer { margin: 0; font-size: 1rem; color: var(--text-dim); }
.reveal-answer b { color: var(--text); }

.reveal-gain {
  margin: 0 0 .6rem;
  font-size: 2rem;
  font-weight: 800;
  color: var(--ok);
  animation: gain-float .9s var(--ease);
}
@keyframes gain-float {
  0%   { opacity: 0; transform: translateY(14px) scale(.8); }
  45%  { opacity: 1; transform: translateY(-4px) scale(1.1); }
  100% { opacity: 1; transform: none; }
}

/* ── ⑦ 순위 ─────────────────────────────────── */
.lb-head { text-align: center; margin-bottom: .9rem; flex-shrink: 0; }
.lb-eyebrow {
  margin: 0;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text-dim);
}
.lb-heading { margin: .15rem 0 0; font-size: clamp(1.3rem, 5.5vw, 1.7rem); }

.lb-rows {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  overflow-y: auto;
  min-height: 0;
}

.lb-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto auto;
  align-items: center;
  gap: .6rem;
  min-height: 52px;
  padding: .45rem .7rem;
  border-radius: var(--r-md);
  background: #212759b3;
  border: 1px solid transparent;
  /* FLIP 애니메이션이 transform 을 쓰므로 transition 대상은 transform 이다 */
  will-change: transform;
}
.lb-row.is-me { border-color: var(--accent); background: #7c5cff2b; }

.lb-row[data-place="1"] { border-color: #ffd45c; background: #ffd45c1f; }
.lb-row[data-place="2"] { border-color: #cfd6e6; background: #cfd6e618; }
.lb-row[data-place="3"] { border-color: #e0a06a; background: #e0a06a18; }

.lb-rank {
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.lb-name {
  font-size: .95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-delta {
  font-size: .74rem;
  font-weight: 700;
  padding: .1rem .35rem;
  border-radius: var(--r-full);
  white-space: nowrap;
}
.lb-delta.up   { color: var(--ok);     background: #16c79a24; }
.lb-delta.down { color: var(--danger); background: #ff5f7e24; }
.lb-delta.same { color: var(--text-mute); }

.lb-score {
  font-size: 1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 4.2ch;
}
.lb-gain {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  color: var(--ok);
}

.lb-foot {
  flex-shrink: 0;
  padding-top: .7rem;
  text-align: center;
}
.lb-me {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: center;
  gap: .6rem;
  padding: .65rem .7rem;
  margin-bottom: .55rem;
  border-radius: var(--r-md);
  background: var(--accent);
  box-shadow: var(--shadow-md);
  animation: rise-in .4s var(--ease);
}
.lb-me-rank  { font-size: 1.1rem; font-weight: 800; text-align: center; }
.lb-me-label { font-size: .88rem; font-weight: 600; text-align: left; }
.lb-me-score { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-me.is-final { background: linear-gradient(120deg, var(--accent), #b06cff); }

/* ── ⑧ 최종 결과 ─────────────────────────────── */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

.final-head { text-align: center; margin-bottom: .8rem; flex-shrink: 0; }
.final-eyebrow {
  margin: 0;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--text-dim);
}
.final-heading { margin: .15rem 0 0; font-size: clamp(1.4rem, 6vw, 1.9rem); }

.podium {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  align-items: end;
  gap: .4rem;
  margin-bottom: 1rem;
}
.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  /* 아래에서 솟아오르는 연출. JS 가 하나씩 is-in 을 붙인다. */
  opacity: 0;
  transform: translateY(28px);
  transition: opacity .5s var(--ease), transform .55s var(--ease);
}
.podium-slot.is-in { opacity: 1; transform: none; }
.podium-slot:empty { display: none; }

.podium-crown { font-size: 1.5rem; line-height: 1; }
.podium-name {
  max-width: 100%;
  font-size: .86rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.podium-score {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.podium-block {
  width: 100%;
  display: grid;
  place-items: center;
  border-radius: var(--r-md) var(--r-md) 0 0;
  font-weight: 800;
}
.podium-slot[data-place="1"] .podium-block {
  height: 96px;
  background: linear-gradient(180deg, #ffd45c, #d9a520);
  color: #4a3400;
  box-shadow: 0 0 26px #ffd45c55;
}
.podium-slot[data-place="2"] .podium-block {
  height: 70px;
  background: linear-gradient(180deg, #e6ebf5, #a9b3c7);
  color: #2b3140;
}
.podium-slot[data-place="3"] .podium-block {
  height: 54px;
  background: linear-gradient(180deg, #e8b183, #b8763f);
  color: #3d2410;
}
.podium-num { font-size: 1.3rem; }

.final-rows { max-height: 34dvh; }

/* 가로 모드 — 이미지와 선택지를 나란히 */
@media (orientation: landscape) and (max-height: 520px) {
  .screen-question { flex-direction: row; flex-wrap: wrap; align-items: stretch; }
  .q-top { width: 100%; }
  .q-body { flex: 1 1 45%; }
  .q-image { max-height: 42dvh; }
  .choices-grid { flex: 1 1 45%; align-content: center; }
  .choice-btn { min-height: 62px; }
}

/* 저사양 단말 배려 — 배경 애니메이션은 부가 요소다 */
@media (prefers-reduced-motion: reduce) {
  .bg-blobs span { animation: none; }
  .q-secs.urgent { animation: none; }
}
