/* 진행 화면: 16:9 큰 화면 기준. 글자 크기는 폭과 높이 중 더 빠듯한 쪽에 맞춤
   (폭에만 맞추면 북마크바·탭 때문에 낮아진 크롬 창에서 아래가 잘림) */
html { font-size: clamp(12px, min(1.05vw, 1.9vh), 26px); }
body { overflow: hidden; }
#app { height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .9rem 1.6rem; border-bottom: 1px dashed var(--line); }
.brand { width: 2.4rem; height: 2.4rem; display: block; background: none; }
.brand svg { display: block; width: 100%; height: 100%; }
#title { font-size: 1.35rem; font-weight: 800; cursor: pointer; }
#phase { font-size: .8rem; font-weight: 700; color: var(--on-accent); background: var(--accent); padding: .25rem .6rem; border-radius: 99px; }
.netstat { font-size: .85rem; color: var(--muted); }
.netstat.ok { color: var(--green); }
.netstat.warn { color: var(--accent2); }
.tb-btn { background: var(--panel); border: 1px solid var(--line); border-radius: .7rem; padding: .35rem .6rem; font-size: 1rem; }
#mini-qr { display: flex; align-items: center; gap: .6rem; background: var(--panel); border: 1px solid var(--line); border-radius: .8rem; padding: .3rem .7rem .3rem .3rem; cursor: pointer; }
#mini-qr-svg { width: 3rem; height: 3rem; border-radius: .4rem; overflow: hidden; }
#mini-qr-svg svg { width: 100%; height: 100%; display: block; }
#mini-qr small { display: block; color: var(--muted); font-size: .7rem; }
#mini-code { font-weight: 800; letter-spacing: .12em; }
body[data-view="lobby"] #mini-qr { visibility: hidden; }

#main { position: relative; overflow: hidden; padding: 1.4rem 1.6rem; }
#foot { display: flex; gap: .7rem; align-items: center; padding: .8rem 1.6rem 1.1rem; }
.fbtn { background: var(--panel); border: 1px solid var(--line); border-radius: .8rem; padding: .7rem 1.1rem; font-weight: 700; font-size: .95rem; display: inline-flex; align-items: center; }
.fbtn:hover { border-color: var(--muted); }
.fbtn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-size: 1.1rem; padding: .8rem 1.5rem; }
.fbtn.gold { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: var(--on-accent); border: 0; }
.fbtn.disabled { opacity: .4; pointer-events: none; }

/* ---------- 참가 접수 ---------- */
.lobby { height: 100%; display: grid; grid-template-columns: auto 1fr; gap: 4rem; align-items: center; padding: 0 4rem; }
.qr-card { background: #fff; color: #111; border-radius: 1.6rem; padding: 1.2rem; box-shadow: 0 0 0 .5rem rgba(224, 122, 79, .9), 0 1.5rem 4rem rgba(0,0,0,.5); text-align: center; }
.qr-card .qr { width: min(30rem, 58vh); height: min(30rem, 58vh); }
.qr svg { width: 100%; height: 100%; display: block; }
.qr-code { font-size: 1.1rem; margin-top: .4rem; }
.qr-code b { letter-spacing: .18em; font-size: 1.4rem; }
.lobby-copy h1 { font-size: 3.6rem; line-height: 1.15; margin: 0 0 1.4rem; }
.lobby-copy h1 em { font-style: normal; color: var(--accent); }
.steps { list-style: none; padding: 0; margin: 0 0 1.8rem; display: flex; gap: 1rem; flex-wrap: wrap; }
.steps li { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: .45rem 1rem .45rem .45rem; font-weight: 600; }
.steps b { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent); color: var(--on-accent); margin-right: .5rem; }
.joined { font-size: 1.3rem; color: var(--muted); margin-bottom: .8rem; }
.joined b { color: var(--accent); font-size: 2rem; }
.chips { display: flex; flex-wrap: wrap; gap: .6rem; max-height: 30vh; overflow: hidden; }
.chip { display: inline-flex; align-items: center; gap: .5rem; background: var(--panel); border: 1.5px solid var(--c); border-radius: 99px; padding: .45rem .9rem; font-weight: 700; font-size: 1.15rem; }
.chip i { width: .8rem; height: .8rem; border-radius: 50%; background: var(--c); }
.chip small { color: var(--muted); font-weight: 500; font-size: .75rem; }
.chip.new { animation: pop .5s, glow 1s 2; }
.url { margin-top: 1.4rem; color: var(--muted); font-size: .8rem; word-break: break-all; }
.url-warn { margin-top: .6rem; max-width: 24rem; background: #b3261e; color: #fff; border-radius: .6rem; padding: .5rem .7rem; font-size: .8rem; font-weight: 700; line-height: 1.4; }

/* ---------- 게임 선택 ---------- */
.menu { height: 100%; display: grid; grid-template-columns: 1fr 19rem; gap: 1.4rem; }
.menu-left { display: flex; flex-direction: column; min-height: 0; }
.sec-title { font-size: 1.15rem; font-weight: 800; margin-bottom: .8rem; }
.sec-title small { color: var(--muted); font-weight: 500; font-size: .8rem; margin-left: .4rem; }
.game-grid { flex: 1; display: grid; grid-template-columns: repeat(6, 1fr); grid-auto-rows: 1fr; gap: .7rem; min-height: 0; }
.game-card { text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: 1rem; padding: .7rem .8rem; display: flex; flex-direction: column; gap: .15rem; min-height: 0; transition: transform .12s, border-color .12s; position: relative; overflow: hidden; }
.game-card.sel { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 .5rem 1.5rem rgba(224, 122, 79, .18); }
.game-card.played { opacity: .7; }
.gc-icon { width: 2.4rem; height: 2.4rem; }
.gc-icon svg, .intro-icon svg, .pm-icon svg, .lh-icon svg { display: block; width: 100%; height: 100%; }
.gc-name { font-weight: 800; font-size: 1.05rem; }
.gc-desc { color: var(--muted); font-size: .78rem; }
.gc-meta { margin-top: auto; display: flex; gap: .4rem; align-items: center; font-size: .7rem; color: var(--muted); }
.gc-meta .tag { background: var(--panel2); border-radius: 99px; padding: .1rem .45rem; color: var(--text); }
.gc-meta .done { color: var(--green); font-weight: 700; margin-left: auto; }
.side { background: var(--bg2); border: 1px solid var(--line); border-radius: 1rem; padding: .9rem; overflow: hidden; display: flex; flex-direction: column; gap: .3rem; }
.side-title { font-weight: 800; margin-bottom: .4rem; }
.side-title small { color: var(--muted); font-weight: 500; font-size: .75rem; margin-left: .3rem; }

/* ---------- 게임 안내 ---------- */
.intro { height: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 3rem; align-items: center; padding: 0 3rem; }
.intro-icon { width: 13rem; height: 13rem; border-radius: 1.6rem; background: var(--paper); border: .3rem solid var(--wood); padding: 2.2rem; box-shadow: 0 1.2rem 2.4rem rgba(0,0,0,.4); transform: rotate(-3deg); animation: pulse 2s infinite; }
.intro-tag { color: var(--accent); font-weight: 700; font-size: 1.05rem; }
.intro h1 { font-size: 4.4rem; margin: .3rem 0; }
.intro-desc { font-size: 1.4rem; color: var(--muted); margin: 0 0 1rem; }
.intro ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .6rem; }
.intro li { font-size: 1.35rem; font-weight: 600; padding-left: 2.2rem; position: relative; }
.intro li::before { content: "✓"; position: absolute; left: 0; width: 1.6rem; height: 1.6rem; border-radius: .4rem; background: var(--blue); display: grid; place-items: center; font-size: .9rem; top: .1rem; }
.intro-ready { margin-top: 1.6rem; display: inline-block; background: var(--panel); border: 1px dashed var(--line); padding: .6rem 1rem; border-radius: .8rem; color: var(--muted); }
.phone-mock { width: 13rem; height: 25rem; border-radius: 2rem; border: .5rem solid #2a1d12; background: linear-gradient(180deg, #2b6243, #183b29); box-shadow: 0 2rem 4rem rgba(0,0,0,.5); padding: 1rem; display: grid; place-items: center; transform: rotate(6deg); }
.pm-screen { text-align: center; font-weight: 800; font-size: 1.2rem; }
.pm-screen small { display: block; color: var(--muted); font-weight: 500; font-size: .75rem; margin-top: .4rem; }
.pm-icon { width: 4.5rem; height: 4.5rem; margin: 0 auto .4rem; animation: pulse 1s infinite; }

/* ---------- 카운트다운 ---------- */
.countdown { height: 100%; display: grid; place-items: center; align-content: center; }
.cd-num { font-size: 22rem; font-weight: 900; line-height: 1; color: var(--accent); text-shadow: .6rem .6rem 0 var(--accent2); }
.cd-num.pop { animation: pop .6s; }
.cd-game { font-size: 1.6rem; color: var(--muted); font-weight: 700; }

/* ---------- 실시간 중계 ---------- */
.live { height: 100%; display: flex; flex-direction: column; }
.live-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .8rem; }
.lh-icon { width: 2.6rem; height: 2.6rem; }
.lh-name { font-size: 1.8rem; font-weight: 900; }
.lh-note { background: var(--panel); border-radius: 99px; padding: .3rem .8rem; color: var(--accent); font-weight: 700; }
.ring { position: relative; width: 4.2rem; height: 4.2rem; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.4; }
.ring .bg { stroke: var(--panel2); }
.ring .fg { stroke: var(--accent); stroke-dasharray: 100.5; stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.ring.hurry .fg { stroke: var(--red); }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; font-weight: 900; }
.ring.hurry b { color: var(--red); animation: pulse 1s infinite; }

/* ---------- 결과 ---------- */
.result { height: 100%; display: flex; flex-direction: column; }
.res-head { font-size: 1.8rem; font-weight: 900; }
.res-head small { color: var(--accent); font-size: 1rem; }
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; align-items: end; padding: 0 6rem; flex: 1; }
.pod { text-align: center; animation: pop .6s backwards; }
.pod.p1 { animation-delay: .5s; }
.pod.p2 { animation-delay: .25s; }
.pod-medal { font-size: 3rem; }
.pod-name { font-size: 1.8rem; font-weight: 900; }
.pod-val { color: var(--muted); font-weight: 700; margin-bottom: .5rem; }
.pod-block { border-radius: 1rem 1rem 0 0; background: linear-gradient(180deg, var(--c), color-mix(in srgb, var(--c) 45%, #000)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; }
.pod-block b { font-size: 3.5rem; color: rgba(255,255,255,.95); text-shadow: 0 .2rem 0 rgba(0,0,0,.25); }
.pts { background: var(--accent2); color: var(--on-accent); font-weight: 900; border-radius: 99px; padding: .2rem .8rem; font-size: 1.1rem; }
.pod.p1 .pod-block { height: 15rem; }
.pod.p2 .pod-block { height: 11rem; }
.pod.p3 .pod-block { height: 8rem; }
.pod.p1 .pod-name { color: var(--accent); }
.rest { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem .8rem; padding: 1rem 6rem 0; }
.rrow { display: flex; gap: .6rem; align-items: center; background: var(--panel); border-radius: .6rem; padding: .45rem .8rem; }
.rrow .rk { width: 1.4rem; color: var(--muted); font-weight: 800; }
.rrow i { width: .6rem; height: .6rem; border-radius: 50%; }
.rrow .nm { flex: 1; font-weight: 700; }
.rrow .v { color: var(--muted); font-size: .85rem; }
.rrow b { color: var(--accent); }
.rrow.absent { opacity: .5; }

/* ---------- 최종 발표 ---------- */
.final { height: 100%; display: flex; flex-direction: column; align-items: center; }
.final h1 { font-size: 2.6rem; margin: 0; }
.final-sub { color: var(--muted); margin-bottom: 1rem; }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; background: rgba(8, 24, 16, .72); display: grid; place-items: center; z-index: 100; backdrop-filter: blur(4px); }
.modal-box { position: relative; background: var(--bg2); border: 1px solid var(--line); border-radius: 1.4rem; padding: 1.8rem; max-width: 92vw; max-height: 90vh; overflow: auto; animation: pop .25s; }
.modal-x { position: absolute; right: .8rem; top: .8rem; background: none; border: 0; font-size: 1.2rem; color: var(--muted); }
.bigqr { display: flex; gap: 2.5rem; align-items: center; }
.bigqr .qr { width: min(70vh, 34rem); height: min(70vh, 34rem); background: #fff; border-radius: 1rem; padding: .6rem; }
.bigqr h2 { font-size: 2.6rem; margin: 0 0 .6rem; }
.bigqr p { color: var(--muted); font-size: 1.2rem; }
.settings { width: min(44rem, 88vw); display: flex; flex-direction: column; gap: .8rem; font-size: .95rem; }
.settings h2 { margin: 0; }
.settings h3 { margin: .6rem 0 0; font-size: 1rem; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 700; }
.check { display: flex; gap: .5rem; align-items: center; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.tm-list { display: flex; flex-direction: column; gap: .35rem; max-height: 50vh; overflow: auto; }
.tm-search { width: 100%; box-sizing: border-box; margin-bottom: .5rem; padding: .5rem .7rem; border-radius: .5rem; border: 1.5px solid var(--wood); font: inherit; }
.chip.more { border-style: dashed; color: var(--muted); }
.joined.big b { font-size: 2.6rem; }
.tm-row { display: flex; gap: .6rem; align-items: center; background: var(--panel); border-radius: .6rem; padding: .4rem .6rem; }
.tm-row i { width: .8rem; height: .8rem; border-radius: 50%; flex: none; }
.tm-row input { flex: 1; padding: .35rem .6rem; }
.tm-row .nm { flex: 1; font-weight: 700; }
.tm-row small { color: var(--muted); min-width: 5rem; }
.adj-v { min-width: 4rem; text-align: right; }
.mini { background: var(--panel2); border: 1px solid var(--line); border-radius: .5rem; padding: .35rem .7rem; font-weight: 700; font-size: .85rem; }
.mini.danger { color: var(--red); }

/* ---------- 팀전 / 개인전 선택 ---------- */
.mode-switch { display: inline-flex; gap: .4rem; background: var(--bg2); border: 1px solid var(--line); border-radius: 1rem; padding: .3rem; margin-bottom: 1.2rem; }
.mode-btn { background: none; border: 0; border-radius: .75rem; padding: .5rem 1rem; display: flex; flex-direction: column; align-items: flex-start; color: var(--muted); }
.mode-btn b { font-size: 1.1rem; }
.mode-btn small { font-size: .72rem; }
.mode-btn.on { background: var(--accent); color: var(--on-accent); }
.settings .mode-switch { margin: 0; }

.side { overflow: auto; }
.chips { overflow: auto; }

/* =====================================================================
   휴대폰·작은 화면에서 진행할 때: 세로로 쌓고, 스크롤되게, 버튼은 아래 고정
   ===================================================================== */
@media (max-width: 820px), (max-height: 520px) {
  html { font-size: 14px; }
  body { overflow: auto; }
  #app { height: auto; min-height: 100dvh; display: flex; flex-direction: column; }
  kbd { display: none; }

  .topbar { position: sticky; top: 0; z-index: 30; background: var(--bg); gap: .5rem; padding: .55rem .8rem; padding-top: calc(env(safe-area-inset-top) + .55rem); flex-wrap: wrap; }
  .brand { width: 2rem; height: 2rem; }
  #title { font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #phase { font-size: .7rem; }
  .topbar .grow { display: none; }
  .netstat { order: 10; width: 100%; font-size: .75rem; }
  #mini-qr { padding: .2rem .5rem .2rem .2rem; }
  #mini-qr-svg { width: 2.2rem; height: 2.2rem; }
  #mini-code { font-size: 1rem; }
  .tb-btn { padding: .3rem .5rem; }

  #main { flex: 1; overflow: visible; padding: .9rem .8rem 1rem; }
  #foot { position: sticky; bottom: 0; z-index: 30; flex-wrap: wrap; gap: .45rem; padding: .6rem .8rem; padding-bottom: calc(env(safe-area-inset-bottom) + .6rem); background: rgba(24, 59, 41, .96); border-top: 1px solid var(--line); backdrop-filter: blur(6px); }
  #foot .grow { display: none; }
  .fbtn { flex: 1 1 40%; justify-content: center; padding: .45rem .5rem; font-size: .8rem; min-height: 2.4rem; }
  .fbtn.primary, .fbtn.gold { flex: 1 1 100%; order: -1; font-size: 1.1rem; min-height: 3.3rem; }

  /* 참가 접수 */
  .lobby { display: flex; flex-direction: column; gap: 1.2rem; padding: 0; height: auto; }
  .qr-card { align-self: center; padding: .8rem; border-radius: 1.2rem; box-shadow: 0 0 0 .35rem rgba(224, 122, 79, .9); }
  .qr-card .qr { width: min(62vw, 16rem); height: min(62vw, 16rem); }
  .qr-code b { font-size: 1.8rem; }
  .lobby-copy { text-align: center; }
  .lobby-copy h1 { font-size: 1.7rem; margin-bottom: .8rem; }
  .lobby-copy h1 br { display: none; }
  .steps { justify-content: center; gap: .4rem; margin-bottom: 1rem; }
  .steps li { font-size: .85rem; padding: .3rem .7rem .3rem .3rem; }
  .steps b { width: 1.3rem; height: 1.3rem; }
  .joined { font-size: 1rem; }
  .joined b { font-size: 1.5rem; }
  .chips { justify-content: center; max-height: none; }
  .chip { font-size: .95rem; padding: .35rem .7rem; }

  /* 게임 선택 */
  .menu { display: flex; flex-direction: column; gap: 1rem; height: auto; }
  .sec-title small { display: block; margin: .2rem 0 0; }
  .game-grid { grid-template-columns: repeat(3, 1fr); grid-auto-rows: auto; gap: .45rem; }
  .game-card { padding: .55rem .5rem; border-radius: .8rem; align-items: center; text-align: center; }
  .game-card.sel { transform: none; }
  .gc-icon { width: 2rem; height: 2rem; }
  .gc-name { font-size: .88rem; line-height: 1.2; }
  .gc-desc { display: none; }
  .gc-meta { margin-top: .2rem; justify-content: center; font-size: .65rem; flex-wrap: wrap; }
  .gc-meta .tag { display: none; }
  .gc-meta .done { margin-left: 0; }
  .side { overflow: visible; }

  /* 게임 안내 */
  .intro { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 1rem; padding: .5rem 0; height: auto; }
  .intro-icon { width: 7rem; height: 7rem; border-radius: 1rem; padding: 1.1rem; }
  .intro h1 { font-size: 2.2rem; }
  .intro-desc { font-size: 1.05rem; }
  .intro ul { text-align: left; }
  .intro li { font-size: 1rem; }
  .intro-ready { font-size: .85rem; }
  .phone-mock { display: none; }

  /* 카운트다운 */
  .countdown { min-height: 55dvh; }
  .cd-num { font-size: 9rem; text-shadow: .3rem .3rem 0 var(--accent2); }
  .cd-game { font-size: 1.1rem; }

  /* 실시간 중계 */
  .live { height: auto; }
  .lh-icon { width: 1.9rem; height: 1.9rem; }
  .lh-name { font-size: 1.3rem; }
  .live-head { flex-wrap: wrap; }
  .lh-note { font-size: .75rem; order: 5; }
  .ring { width: 3.2rem; height: 3.2rem; }
  .ring b { font-size: 1.1rem; }

  /* 결과 */
  .result { height: auto; }
  .res-head { font-size: 1.3rem; }
  .podium { padding: 1rem 0 0; gap: .4rem; flex: none; }
  .pod-medal { font-size: 1.8rem; }
  .pod-name { font-size: 1rem; word-break: keep-all; }
  .pod-val { font-size: .8rem; }
  .pod-block b { font-size: 2rem; }
  .pts { font-size: .85rem; padding: .1rem .5rem; }
  .pod.p1 .pod-block { height: 8rem; }
  .pod.p2 .pod-block { height: 6rem; }
  .pod.p3 .pod-block { height: 4.6rem; }
  .rest { grid-template-columns: 1fr; padding: .8rem 0 0; }

  /* 최종 발표 */
  .final { height: auto; }
  .final h1 { font-size: 1.7rem; }

  /* 모달 */
  .modal { align-items: start; padding: calc(env(safe-area-inset-top) + 1rem) .6rem 1rem; overflow: auto; }
  .modal-box { padding: 1.2rem 1rem; max-height: none; width: 100%; }
  .bigqr { flex-direction: column; gap: 1rem; text-align: center; }
  .bigqr .qr { width: min(80vw, 22rem); height: min(80vw, 22rem); }
  .bigqr h2 { font-size: 1.6rem; }
  .bigqr p { font-size: 1rem; }
  .settings { width: 100%; }
  .tm-row { flex-wrap: wrap; }
  .tm-row small { min-width: 0; }

  .mode-switch { display: flex; width: 100%; margin-bottom: .9rem; }
  .mode-btn { flex: 1; align-items: center; padding: .45rem .4rem; }
  .mode-btn b { font-size: 1rem; }
}
