/* ====== 호스트(TV) 화면 ======
   3~4m 거리 시청 기준. body 폰트 = 1em 기준 단위 (1280px→19px, 1920px→26px, 1024px→16px) */
body.host { font-size: clamp(16px, 1.38vw, 24px); line-height: 1.3; }
.host .screen { position: absolute; inset: 0; display: none; }
.host .screen.is-active { display: flex; animation: fadeIn .3s; }

/* ---- 로비 ---- */
#lobby { gap: 1.4vw; padding: 1.4vw; }
.lb-join {
  width: 22vw; min-width: 240px; max-width: 24em; display: flex; flex-direction: column; align-items: center; gap: .55em;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2em 1em;
  box-shadow: var(--shadow); min-height: 0; overflow: hidden;
}
.lb-brand { font-size: 1.25em; font-weight: 900; display: flex; gap: .4em; align-items: center; letter-spacing: -.01em; }
.lb-logo { font-size: 1.3em; animation: floatY 3s ease-in-out infinite; }
.lb-code-label { color: var(--muted); font-size: .85em; font-weight: 700; letter-spacing: .25em; margin-top: .4em; text-transform: uppercase; }
.lb-code {
  font-size: clamp(2.6em, 5.2vw, 4.2em); font-weight: 900; letter-spacing: .14em; line-height: 1.05; padding-left: .14em;
  background: linear-gradient(135deg, var(--accent2), var(--accent) 60%, var(--purple)); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 150, 110, .35)); animation: shimmer 6s linear infinite;
}
.lb-qr { width: 100%; max-width: min(280px, 32vh); aspect-ratio: 1; border-radius: 16px; background: #fff; padding: 8px; box-shadow: 0 0 0 4px rgba(255,255,255,.08), var(--shadow); flex-shrink: 0; }
.lb-url { font-size: .95em; font-weight: 800; word-break: break-all; text-align: center; background: rgba(0,0,0,.3); border: 1px solid var(--line); padding: .5em .8em; border-radius: 12px; line-height: 1.3; font-variant-numeric: tabular-nums; max-width: 100%; }
.lb-help { font-size: .8em; color: var(--muted); text-align: center; line-height: 1.5; }
.conn { margin-top: auto; font-size: .8em; font-weight: 700; color: var(--muted); padding-top: .3em; }
.conn.ok { color: var(--good); } .conn.bad { color: var(--bad); animation: timerBlink 1.2s infinite; }

.lb-games { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: .9em; }
.lb-toolbar { display: flex; justify-content: space-between; gap: .8em; align-items: center; flex-wrap: wrap; }
.lb-cats { display: flex; flex-wrap: wrap; gap: .4em; }
.cat { border: 1px solid var(--line2); background: var(--panel); color: var(--text); border-radius: 999px; padding: .4em 1em; font-size: .9em; font-weight: 800; min-height: 2.4em; transition: background .15s, transform .12s var(--ease-pop); }
.cat:hover { background: var(--panel2); }
.cat.is-active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; box-shadow: 0 4px 16px rgba(255, 95, 109, .4); }
.lb-actions { display: flex; gap: .5em; }
.lb-actions .btn { min-height: 2.6em; min-width: 2.6em; }

/* 게임 카드 그리드: 100장 스크롤 */
.lb-grid {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(10em, 100%), 1fr)); gap: .7em; align-content: start; align-items: start;
  padding: .3em .5em .8em .3em; margin: -.3em; scroll-padding: 1em; overscroll-behavior: contain; scrollbar-gutter: stable;
}
.g-card {
  position: relative; text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 18px; padding: .85em .9em .8em;
  display: flex; flex-direction: column; gap: .2em; min-height: 9.6em; color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 2px 10px rgba(0,0,0,.2);
  transition: transform .15s var(--ease-pop), background .15s, box-shadow .15s, border-color .15s;
}
.g-card::before { content: ''; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(145deg, rgba(255,255,255,.08), transparent 55%); pointer-events: none; }
.g-card:hover { background: var(--panel2); transform: translateY(-3px); border-color: var(--line2); }
.g-card:focus-visible, .g-card:focus { outline: none; background: var(--panel2); transform: translateY(-3px) scale(1.03); border-color: var(--accent2); box-shadow: var(--focus), 0 14px 32px rgba(0,0,0,.4); z-index: 2; }
.g-card:active { transform: scale(.97); }
.g-card.is-dim { opacity: .45; filter: saturate(.5); }
.g-card.is-dim:focus { opacity: .8; }
.g-emoji { font-size: 2.2em; line-height: 1.1; margin-bottom: .1em; filter: drop-shadow(0 4px 8px rgba(0,0,0,.35)); }
.g-name { font-weight: 900; font-size: 1.1em; letter-spacing: -.01em; line-height: 1.2; }
.g-meta { font-size: .8em; color: var(--accent2); font-weight: 700; font-variant-numeric: tabular-nums; }
.g-desc { font-size: .8em; color: var(--muted); line-height: 1.35; flex-shrink: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: .1em; }

.lb-players { width: 18vw; min-width: 220px; max-width: 20em; display: flex; flex-direction: column; gap: .7em; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1em .9em; box-shadow: var(--shadow); min-height: 0; }
.lb-ptitle { font-weight: 900; font-size: 1.15em; display: flex; align-items: baseline; gap: .3em; }
.lb-ptitle #pcount { color: var(--accent2); font-size: 1.1em; font-variant-numeric: tabular-nums; }
.lb-plist { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: .45em; padding-right: .2em; }
.lb-empty { color: var(--muted); white-space: pre-line; text-align: center; padding: 2em .5em; font-size: .95em; line-height: 1.5; border: 2px dashed var(--line); border-radius: 14px; margin: .2em 0; }
.lb-players .btn-ghost { color: var(--muted); }

/* ---- 플레이어 칩 (--pc) ---- */
.h-chip {
  display: flex; align-items: center; gap: .55em; position: relative;
  background: rgba(0,0,0,.28); background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 28%, transparent), rgba(0,0,0,.28) 70%);
  border: 1px solid rgba(255,255,255,.08); border-left: 6px solid var(--pc); border-radius: 12px; padding: .45em .7em .45em .6em; font-weight: 800;
  animation: fadeUp .35s var(--ease-pop) both; box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.h-chip-avatar { font-size: 1.45em; line-height: 1; width: 1.5em; height: 1.5em; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--pc); box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 14px color-mix(in srgb, var(--pc) 60%, transparent); flex-shrink: 0; }
.h-chip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05em; }
.h-chip-right { color: var(--accent2); font-variant-numeric: tabular-nums; font-weight: 900; }
.h-chip.is-offline { opacity: .4; filter: grayscale(.6); }

/* ---- 게임 화면 ---- */
#game { flex-direction: column; }
#hud { display: flex; align-items: center; gap: 1.2vw; padding: .55em 1.2vw; background: rgba(0,0,0,.35); border-bottom: 1px solid var(--line); min-height: 3.6em; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 5; }
.hud-left { min-width: 0; flex: 0 1 auto; }
.hud-title { font-weight: 900; font-size: 1.3em; white-space: nowrap; letter-spacing: -.01em; }
.hud-sub { font-size: .8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.hud-timer { flex: 1; height: 1.9em; border-radius: 999px; background: rgba(0,0,0,.4); border: 1px solid var(--line); position: relative; overflow: hidden; visibility: hidden; box-shadow: inset 0 2px 6px rgba(0,0,0,.4); }
.hud-timer.is-on { visibility: visible; }
.hud-timer-fill { position: absolute; inset: 0; background: linear-gradient(90deg, var(--good), var(--info)); transform-origin: left; transition: transform .1s linear, background .3s; box-shadow: 0 0 16px rgba(79, 172, 254, .45); }
.hud-timer-fill.is-low { background: linear-gradient(90deg, var(--accent), var(--accent2)); box-shadow: 0 0 18px rgba(255, 95, 109, .6); animation: timerBlink .5s infinite; }
.hud-timer-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.05em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0,0,0,.7); letter-spacing: .02em; }
.hud-right { display: flex; gap: .5em; align-items: center; }
.hud-pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .35em .9em; font-size: .9em; font-weight: 700; white-space: nowrap; }
.hud-pill b { color: var(--accent2); letter-spacing: .08em; font-weight: 900; }
.hud-abort { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 50%; width: 2.2em; height: 2.2em; font-size: 1em; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; transition: background .15s, color .15s; }
.hud-abort:hover { background: rgba(255,95,109,.2); color: #fff; border-color: var(--bad); }
.game-root { flex: 1; position: relative; overflow: hidden; display: flex; flex-direction: column; }

/* ---- 공용 호스트 UI ---- */
.h-countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(20, 18, 43, .35), rgba(10, 8, 30, .7)); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); z-index: 50; animation: fadeIn .2s; }
.h-countdown-num {
  font-size: min(16em, 38vh); font-weight: 900; line-height: 1; letter-spacing: -.04em; color: #fff;
  background: linear-gradient(180deg, #fff, var(--accent2) 55%, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 12px 40px rgba(0,0,0,.6)) drop-shadow(0 0 30px rgba(255, 195, 113, .45));
  font-variant-numeric: tabular-nums;
}
.h-countdown-num.pop { animation: countPop .55s var(--ease-pop); }
.h-banner {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%) scale(.8);
  background: rgba(14, 11, 36, .9); border: 1px solid var(--line2); border-radius: 26px; padding: 1em 2.2em; text-align: center;
  opacity: 0; transition: .28s var(--ease-pop); z-index: 60; pointer-events: none; max-width: 80%;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,.04) inset, 0 0 60px rgba(166, 108, 255, .2);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.h-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.h-banner-emoji { font-size: 3.2em; line-height: 1.1; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.h-banner-text { font-size: 2.4em; font-weight: 900; letter-spacing: -.01em; line-height: 1.15; text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.h-banner-sub { color: var(--muted); font-size: 1.05em; margin-top: .35em; font-weight: 700; }
.h-banner.small .h-banner-text { font-size: 1.35em; }
.h-banner.small { top: 12%; padding: .6em 1.5em; border-radius: 999px; }
.h-banner.error { border-color: var(--bad); box-shadow: var(--shadow-lg), 0 0 40px rgba(255, 95, 109, .35); }
.h-banner.error .h-banner-text { color: var(--bad); font-size: 1.4em; }
.h-header { text-align: center; padding: .8em 1em .3em; }
.h-title { font-size: 1.9em; font-weight: 900; letter-spacing: -.01em; line-height: 1.15; }
.h-sub { color: var(--muted); font-size: 1.05em; margin-top: .25em; font-weight: 700; }
.h-bigtext { font-size: 5.5em; font-weight: 900; text-align: center; animation: pop .4s var(--ease-pop); line-height: 1.1; text-shadow: 0 8px 30px rgba(0,0,0,.45); }

/* 순위표 */
.h-board { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1em 1.1em; min-width: min(22em, 90vw); box-shadow: var(--shadow); }
.h-board-title { font-weight: 800; color: var(--muted); margin-bottom: .6em; font-size: .85em; text-transform: uppercase; letter-spacing: .14em; }
.h-board-row {
  display: grid; grid-template-columns: 2.2em 1.9em 1fr auto; align-items: center; gap: .55em; padding: .5em .7em .5em .6em; border-radius: 12px; margin-bottom: .35em;
  background: rgba(0,0,0,.22); background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 22%, transparent), rgba(0,0,0,.22) 60%);
  border: 1px solid rgba(255,255,255,.06); border-left: 6px solid var(--pc); animation: fadeUp .45s var(--ease-pop) both; font-weight: 800; font-size: 1.05em;
}
.h-board-row.rank-1 { background: linear-gradient(90deg, rgba(255, 209, 102, .32), rgba(255, 195, 113, .1) 55%, rgba(0,0,0,.2)); border-color: rgba(255, 209, 102, .55); border-left-color: var(--pc); font-size: 1.3em; animation: fadeUp .45s var(--ease-pop) both, glow 2.2s ease-in-out 0.5s infinite; }
.h-board-row.rank-1 .h-board-score { color: var(--gold); }
.h-board-row.rank-2 { background: linear-gradient(90deg, rgba(217, 220, 234, .2), rgba(0,0,0,.22) 60%); font-size: 1.12em; }
.h-board-row.rank-3 { background: linear-gradient(90deg, rgba(227, 162, 111, .22), rgba(0,0,0,.22) 60%); }
.h-board-rank { font-size: 1.25em; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
.h-board-row.rank-1 .h-board-rank, .h-board-row.rank-2 .h-board-rank, .h-board-row.rank-3 .h-board-rank { color: inherit; font-size: 1.4em; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.h-board-avatar { font-size: 1.3em; line-height: 1; width: 1.45em; height: 1.45em; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--pc); box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.h-board-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-board-score { font-variant-numeric: tabular-nums; color: var(--accent2); font-weight: 900; white-space: nowrap; }

/* 플레이어 그리드 (점수판) */
.h-pgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5em, 15em)); justify-content: center; gap: .7em; padding: .8em 1.2em; align-content: start; }
.h-pcell {
  position: relative; background: var(--panel); background: linear-gradient(180deg, color-mix(in srgb, var(--pc) 22%, transparent), rgba(255,255,255,.05) 60%);
  border: 1px solid var(--line); border-top: 6px solid var(--pc); border-radius: 16px; padding: .6em .5em .55em; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); transition: transform .15s var(--ease-pop), box-shadow .2s, opacity .3s; animation: fadeUp .35s var(--ease-pop) both;
}
.h-pcell-avatar { font-size: 2.1em; line-height: 1.1; filter: drop-shadow(0 4px 8px rgba(0,0,0,.35)); }
.h-pcell-name { font-weight: 800; font-size: .9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: .1em; }
.h-pcell-value { font-size: 1.8em; font-weight: 900; color: var(--accent2); font-variant-numeric: tabular-nums; min-height: 1.2em; line-height: 1.2; }
.h-pcell.pulse { animation: pulse .3s var(--ease-pop); box-shadow: 0 0 24px color-mix(in srgb, var(--pc) 55%, transparent), 0 6px 18px rgba(0,0,0,.25); }
.h-pcell.is-out { opacity: .35; filter: grayscale(.7); }
.h-pcell.is-win { box-shadow: 0 0 0 3px var(--good) inset, 0 0 30px rgba(71, 224, 165, .45); animation: glow 1.6s infinite; }
.h-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

/* ---- 결과 ---- */
#results { flex-direction: column; align-items: center; justify-content: center; gap: 1.2em; padding: 1.5em 2em; }
.rs-title {
  font-size: clamp(2.2em, 5vw, 3.4em); font-weight: 900; animation: pop .55s var(--ease-pop); text-align: center; line-height: 1.15; letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff, var(--gold) 70%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 24px rgba(255, 209, 102, .3));
}
.rs-cols { display: flex; gap: 1.5em; flex-wrap: wrap; justify-content: center; max-height: 62vh; overflow: auto; padding: .4em; width: 100%; }
.rs-cols .h-board { flex: 1 1 22em; max-width: 32em; min-width: min(20em, 90vw); }
.rs-cols .h-board:first-child { border-color: rgba(255, 209, 102, .35); }
.rs-actions { display: flex; gap: 1em; flex-wrap: wrap; justify-content: center; animation: fadeUp .5s .4s both; }

/* ---- 반응형: 태블릿 가로 / 낮은 높이 ---- */
@media (max-width: 1366px) {
  .lb-join { width: 24vw; }
  .lb-players { width: 19vw; }
}
@media (max-width: 1100px) {
  #lobby { gap: 1vw; padding: 1vw; }
  .lb-join { min-width: 210px; padding: .9em .7em; }
  .lb-players { min-width: 200px; padding: .8em .6em; }
  .lb-help { display: none; }
  .h-chip { gap: .4em; padding: .4em .5em .4em .45em; }
  .h-chip-avatar { font-size: 1.2em; }
  .h-chip-name { font-size: .95em; }
  .lb-ptitle { font-size: 1.05em; }
  .lb-grid { grid-template-columns: repeat(auto-fill, minmax(min(9.5em, 100%), 1fr)); }
}
@media (max-height: 760px) {
  .lb-qr { max-width: min(220px, 30vh); }
  .lb-help { display: none; }
  .h-countdown-num { font-size: min(14em, 40vh); }
}
@media (orientation: portrait) {
  #lobby { flex-wrap: wrap; overflow: auto; }
  .lb-join, .lb-players { width: calc(50% - .7vw); max-width: none; }
  .lb-games { flex-basis: 100%; order: 3; min-height: 60vh; }
}

/* ---- 코어 보완 ---- */
.h-board.no-anim .h-board-row { animation: none; }
/* small 배너는 게임 헤더(제목/부제)와 겹치지 않도록 더 위로 */
.h-banner.small { top: 4%; }
.rs-auto { font-size: 1.2em; font-weight: 800; color: var(--accent2); text-align: center; animation: fadeUp .4s; }
.h-chip.no-anim { animation: none; }
.ui-choices.is-center .ui-choice-label { text-align: center; }
.h-pgrid.is-dense { grid-template-columns: repeat(auto-fit, minmax(5.5em, 1fr)); gap: .35em; padding: .4em .8em; }
.h-pgrid.is-dense .h-pcell { padding: .3em; border-top-width: 3px; }
.h-pgrid.is-dense .h-pcell-avatar { font-size: 1.3em; }
.h-pgrid.is-dense .h-pcell-name { font-size: .7em; }
.h-pgrid.is-dense .h-pcell-value { font-size: 1.1em; }
.h-banner.xl .h-banner-text { font-size: 3em; }
.h-banner.xl .h-banner-sub { font-size: 1.8em; color: var(--text); font-weight: 800; }

/* 방 개설 비밀번호 / 입장 PIN */
.lb-pin { font-size: 1.1rem; color: var(--muted); margin: -.2em 0 .6em; letter-spacing: .02em; }
.lb-pin b { font-size: 1.6rem; color: var(--accent2); letter-spacing: .15em; margin-left: .1em; font-variant-numeric: tabular-nums; }
.pw-input { font-size: 1.6rem; padding: .5em .8em; border-radius: 14px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; text-align: center; width: min(80vw, 14em); letter-spacing: .2em; }
.pw-input:focus { outline: none; border-color: var(--accent2); }
