/* ===== 학생 화면(/play) =====
   운동회 '태블릿 입장'(벽돌 띠·만국기·종이 카드·큰 벽돌 버튼)과 '태블릿 경기'(남색 위 띠·칠판·나무 액자) 모양.
   휴대폰 세로(390) · 태블릿 세로(820) · 태블릿 가로(1180, 운동장 크게 + 옆 패널).
   글자 크기는 12px 격자(12·18·24·30·36·48·60), 둥근 모서리 없음. */
:root { --top-h: 72px; --ban-h: 48px; --ban: 0px; --gutter: max(var(--s4), env(safe-area-inset-left)); --gutter-r: max(var(--s4), env(safe-area-inset-right)); }

body { min-height: 100dvh; display: flex; flex-direction: column; }
/* 코드로 포커스를 주는 제목은 누르는 곳이 아니라 포커스 링을 그리지 않는다(버튼·입력칸은 그대로). */
[tabindex="-1"]:focus { outline: none; }

/* 입장 단계 장식: 벽돌 띠 + 만국기. 게임·결과에서는 남색 위 띠가 대신한다. */
.deco { flex: none; padding-top: env(safe-area-inset-top); background: var(--brick); }
.deco-top { position: relative; z-index: 1; height: 21px; background: var(--brick); box-shadow: inset 0 -3px 0 var(--brick-d), 0 3px 0 var(--ink); }
.deco .bunting { margin-top: 3px; background-color: var(--paper); }
body[data-step="game"] .deco, body[data-step="result"] .deco { display: none; }

/* 위 상태 줄(남색, 운동회 태블릿 경기 띠) + 연결 끊김 띠(같이 붙어 다닌다) */
.bar { position: sticky; top: 0; z-index: var(--z-overlay); }
.topbar {
  display: flex; align-items: center; gap: var(--s3); min-height: var(--top-h);
  padding: max(var(--s2), env(safe-area-inset-top)) var(--gutter-r) var(--s2) var(--gutter);
  position: relative; z-index: 1; /* 끊김 띠가 이 밑에서 내려온다 */
  background: var(--navy); color: var(--chalk); box-shadow: inset 0 -3px 0 var(--wood-d), 0 3px 0 var(--ink);
}
.topbar .face { width: 48px; height: 48px; box-shadow: -3px 0 0 var(--chalk), 3px 0 0 var(--chalk), 0 -3px 0 var(--chalk), 0 3px 0 var(--chalk); }
.topbar .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.topbar .who b { font-weight: 400; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: flex; align-items: center; gap: var(--s3); min-width: 0; font-size: var(--fs-xs); color: var(--chalk); }
.topbar #meClass { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar #meClass:empty { display: none; }
.topbar .conn { flex: none; }
.topbar .conn::before { box-shadow: 0 0 0 3px var(--chalk); }
.topbar .leave {
  flex: none; min-height: 48px; padding: 6px 12px; margin-bottom: 6px;
  box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 3px 0 var(--brick-l), inset 0 -6px 0 var(--brick-d);
}
/* 남색 위 띠에서는 청 포커스 링이 흐려(2.7:1) 분필 노랑으로 바꾼다. */
.topbar .btn:focus-visible { outline-color: var(--chalk-y); outline-offset: 6px; }

/* 끊김 띠는 위 띠 바로 아래 자리를 차지해 본문(칠판 문제 등)을 가리지 않는다. 가로 운동장 크기 계산은 --ban만큼 줄인다. */
body:has(#banner:not(.hidden)) { --ban: var(--ban-h); }
.banner {
  min-height: var(--ban-h); display: flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: var(--s2) var(--gutter-r) var(--s2) var(--gutter);
  background: var(--brick); color: #fff7e6; text-shadow: 3px 3px 0 var(--brick-d); box-shadow: 0 3px 0 var(--ink);
  text-align: center; animation: drop 240ms var(--ease);
}
.banner .icon { width: 24px; height: 24px; flex: none; }
@keyframes drop { from { transform: translateY(-100%); } }

/* 기다림 표시: 둥근 바퀴 대신 깜빡이는 도트 세 개 */
.spin, .btn.busy::after {
  content: ""; width: 24px; height: 6px; flex: none;
  background: linear-gradient(90deg, currentColor 0 6px, transparent 6px 9px, currentColor 9px 15px, transparent 15px 18px, currentColor 18px 24px);
  animation: blink 800ms steps(2) infinite;
}
.btn.busy:disabled { cursor: progress; }

/* 본문 */
main {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--s4);
  padding: var(--s5) var(--gutter-r) max(var(--s5), env(safe-area-inset-bottom)) var(--gutter);
}
.step { animation: step-in 240ms var(--ease) both; }
@keyframes step-in { from { opacity: 0; transform: translateY(12px); } }
/* 입장 단계: 세로 가운데. 태블릿에서는 미리보기 패널(.pv)이 아래(세로)나 옆(가로)에 붙는다. */
.stage { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: center; gap: var(--s6); }

.note { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--gold-soft); line-height: 1.4; animation: step-in 240ms var(--ease); }
.note .icon { width: 24px; height: 24px; flex: none; color: var(--brick); }

/* 입장 카드 */
.panel { width: 100%; max-width: 480px; padding: var(--s5) var(--s4); display: flex; flex-direction: column; align-items: center; gap: var(--s4); text-align: center; }
.panel.wide { max-width: 700px; }
.panel h1 { word-break: keep-all; }
.panel h1 { font-size: var(--fs-xl); color: var(--brick-d); }
.panel > p { line-height: 1.5; }
/* 한글 문장은 낱말 중간에서 줄을 바꾸지 않는다. */
.panel > p, .note, .banner, .place, dialog.sheet p { word-break: keep-all; overflow-wrap: anywhere; }
.actions { display: flex; flex-direction: column; gap: var(--s3); width: 100%; }
.err { width: 100%; min-height: 1.4em; margin-top: calc(-1 * var(--s2)); color: var(--brick); line-height: 1.4; }
.err:empty { min-height: 0; margin: 0; }
/* 반 이름 꼬리표(운동회 '방 번호' 꼬리표) */
.tag { display: inline-block; padding: 0 9px; font-size: var(--fs-sm); line-height: 30px; color: #fff7e6; background: var(--brick); text-shadow: 3px 3px 0 var(--brick-d); box-shadow: 0 3px 0 var(--brick-d); }

/* 로고(O X 네모 타일) */
.logo { display: flex; gap: var(--s3); }
.logo span {
  width: 72px; height: 72px; display: grid; place-items: center; font-size: var(--fs-2xl); line-height: 1; color: #fff7e6;
  box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 3px 0 rgba(255, 255, 255, .3), inset 0 -6px 0 rgba(0, 0, 0, .2);
}
.logo .lo { background: var(--o); text-shadow: 3px 3px 0 var(--o-d); }
.logo .lx { background: var(--x); text-shadow: 3px 3px 0 var(--x-d); }
.logo.sm span { width: 48px; height: 48px; font-size: var(--fs-lg); }
#v-loading .logo span { animation: bob 900ms steps(2) infinite; }
#v-loading .logo .lx { animation-delay: 450ms; }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* 불러오기 막대: 칸 나뉜 픽셀 막대 */
.progress { position: relative; width: 100%; height: 24px; background: var(--navy); box-shadow: var(--step3); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--chalk-y); transition: width 200ms var(--ease); }
.progress::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 15px, var(--navy) 15px 18px); }

/* 방 번호: 스코어보드 숫자 칸 */
.input.code {
  min-height: 96px; font-size: var(--fs-3xl); line-height: 1; text-align: center; letter-spacing: .3em; padding: 0 0 0 .3em;
  color: var(--chalk); background: var(--navy); box-shadow: var(--step3), inset 0 6px 0 rgba(255, 255, 255, .08);
}
.input.code::placeholder { color: var(--chalk-b); }
.input.code::selection { background: var(--chalk-y); color: var(--navy); }
/* 틀린 번호: 운동회 숫자 칸처럼 벽돌색으로 */
#v-room:has(#roomErr:not(:empty)) .input.code { background: var(--brick-d); }
.input.name { min-height: 72px; font-size: var(--fs-xl); text-align: center; }

/* 미리보기 패널(운동회 '내 머리 위에 이렇게 보여요'): 휴대폰에서는 숨긴다. */
.pv { display: none; width: 100%; flex-direction: column; }
.pv .band { justify-content: center; }
.pv-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s4); padding: var(--s6) var(--s4); }
.pv-tv { color: var(--chalk); background: var(--navy); }
.pv-tv .tiles { display: flex; gap: var(--s3); }
.pv-tv .tiles i { width: 72px; height: 96px; display: grid; place-items: center; font-style: normal; font-size: var(--fs-3xl); line-height: 1; color: var(--chalk-y); background: var(--board-d); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .25), 0 0 0 3px var(--chalk); }
.pv-tv .pv-cap { font-size: var(--fs-sm); }
/* 작은 운동장 바닥(종이 칸) 위 캐릭터 얼굴 + 노란 이름표 */
.pv-me { gap: var(--s3); background-color: var(--paper-2); background-image: repeating-linear-gradient(90deg, transparent 0 45px, var(--line) 45px 48px), repeating-linear-gradient(0deg, transparent 0 45px, var(--line) 45px 48px); }
.pv-tag { max-width: 100%; font-weight: 400; font-size: var(--fs-2xl); line-height: 1.2; color: var(--chalk-y); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
  text-shadow: -3px 0 0 var(--navy), 3px 0 0 var(--navy), 0 -3px 0 var(--navy), 0 3px 0 var(--navy), -3px -3px 0 var(--navy), 3px -3px 0 var(--navy), -3px 3px 0 var(--navy), 3px 3px 0 var(--navy); }
.pv-me .face { width: 168px; height: 168px; box-shadow: -6px 0 0 var(--ink), 6px 0 0 var(--ink), 0 -6px 0 var(--ink), 0 6px 0 var(--ink), 0 12px 0 var(--ink); }

/* 본인 확인: 큰 네모 얼굴 액자 */
#v-confirm h1 { font-size: var(--fs-2xl); line-height: 1.2; }
.bigface { padding: 6px 6px 15px; }
.bigface .face {
  width: 144px; height: 144px; animation: pop 240ms var(--ease) both;
  box-shadow: -6px 0 0 var(--ink), 6px 0 0 var(--ink), 0 -6px 0 var(--ink), 0 6px 0 var(--ink),
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 12px 0 var(--ink);
}
@keyframes pop { from { opacity: 0; transform: scale(.75); } }
.face.blank { display: inline-grid; place-items: center; color: var(--muted); background: var(--paper-2); }
.face.blank svg { width: 50%; height: 50%; }

/* 누구인가요? 학생 카드 */
.people { list-style: none; margin: 0; padding: 3px 3px 6px; width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: var(--s4) var(--s3); }
.person {
  width: 100%; min-height: 156px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  padding: var(--s3) var(--s2); border: 0; background: var(--paper-3);
  box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 -3px 0 var(--paper-2);
}
.person:hover { background: #fff; }
.person:active { transform: translateY(3px); box-shadow: var(--step3), 0 3px 0 var(--ink); }
.person .face { width: 84px; height: 84px; }
.person b { max-width: 100%; font-weight: 400; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person.new { background: var(--gold-soft); }
.person.new .face { color: var(--ink); background: var(--chalk-y); }
.person:disabled { cursor: progress; opacity: .7; }
/* 두 줄 높이를 미리 잡아 [한 번 더 누르면 지워져요]로 바뀌어도 카드 높이가 그대로다. */
.person .del { display: none; align-items: center; justify-content: center; min-height: 2.6em; gap: 3px; font-size: var(--fs-sm); color: var(--brick); line-height: 1.3; }
.person .del .icon { width: 18px; height: 18px; flex: none; }
.people.editing .person { box-shadow: -3px 0 0 var(--brick), 3px 0 0 var(--brick), 0 -3px 0 var(--brick), 0 3px 0 var(--brick), 0 6px 0 var(--brick-d); }
.people.editing .person .del { display: inline-flex; }
.person.armed, .person.armed:hover { background: var(--brick); color: #fff7e6; }
.person.armed .del { color: #fff7e6; }
/* 지우기 모드: 끝내기 버튼이라 휴지통 아이콘을 뺀다. [다 했어요]가 화면 아래에 붙어 있어 목록이 길어도 바로 끝낼 수 있다. */
.people.editing ~ #whoEdit .icon, .people.editing ~ .reroom { display: none; }
.people.editing ~ #whoEdit {
  position: sticky; bottom: max(var(--s3), env(safe-area-inset-bottom)); z-index: 2; margin-bottom: 6px;
  background: var(--paper-3); text-decoration: none; box-shadow: var(--step3), 0 6px 0 var(--ink), inset 0 -3px 0 var(--paper-2);
}

/* 이름 입력: 추천 칩 */
.suggest { width: 100%; display: flex; flex-direction: column; gap: var(--s2); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s3); max-height: 192px; overflow-y: auto; padding: 6px; }
.chips .chip { min-height: 48px; padding: 6px 18px; font-size: var(--fs-md); }
.chips .chip:hover { background: var(--gold-soft); }

/* ===== 게임: 칠판 문제 · 운동장 · 내 자리 · 친구 격자 / O·X ===== */
/* 세로 화면: 남는 높이는 아래 친구 격자(대기실)나 O/X 버튼(문제, 엄지 닿는 곳)이 채운다.
   칠판 테두리(12px)·운동장 나무 액자(9px)가 칸 밖으로 나가므로 칸 사이를 24px 띄운다. */
.game { flex: 1; display: grid; gap: var(--s5); padding-top: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; grid-template-areas: "q" "field" "place" "go"; }
.qcard { grid-area: q; display: flex; flex-direction: column; gap: var(--s3); margin: 0 6px; padding: var(--s3) var(--s4); min-height: 96px; justify-content: center; }
.qtext { min-width: 0; }
.qnum { display: block; font-size: var(--fs-sm); color: var(--chalk-y); }
.qcard h2 { font-size: var(--fs-md); line-height: 1.4; color: var(--chalk); word-break: keep-all; overflow-wrap: anywhere; }

/* 남은 시간: 스코어보드 숫자 + 계단 칸 막대 */
.timer { display: flex; align-items: center; gap: var(--s3); }
.timer b { flex: none; min-width: 60px; padding: 0 6px; font-weight: 400; font-size: var(--fs-xl); line-height: 48px; text-align: center; color: var(--chalk-y); background: var(--board-d); box-shadow: inset 0 3px 0 rgba(0, 0, 0, .2); }
.timer .cells { flex: 1; display: flex; gap: 3px; height: 24px; }
.timer .cells i { flex: 1; background: var(--board-d); }
.timer .cells i.on { background: var(--chalk-y); box-shadow: inset 0 -3px 0 var(--wood-l); }
.timer.urgent b { color: var(--chalk-r); animation: blink 1s steps(2) infinite; }
.timer.urgent .cells i.on { background: var(--chalk-r); box-shadow: inset 0 -3px 0 var(--brick-l); }

/* 운동장: 나무 액자(운동회 미니 운동장) */
.kidfield {
  grid-area: field; position: relative; width: calc(100% - 18px); aspect-ratio: 2112 / 1392; justify-self: center; overflow: hidden; touch-action: none; background: var(--navy);
  box-shadow: -6px 0 0 var(--wood), 6px 0 0 var(--wood), 0 -6px 0 var(--wood), 0 6px 0 var(--wood),
    -9px 0 0 var(--ink), 9px 0 0 var(--ink), 0 -9px 0 var(--ink), 0 9px 0 var(--ink);
}
.kidfield canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

/* 내 자리 / 공개 쪽지 */
.place { grid-area: place; min-height: 66px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: var(--s2) var(--s3); text-align: center; font-size: var(--fs-md); line-height: 1.4; }
.place small { font-size: var(--fs-sm); color: var(--muted); }
.place.warn { background: var(--gold-soft); }
/* 공개 때는 O/X 버튼이 숨으므로 쪽지가 그 자리까지 차지한다. */
.place.reveal {
  grid-row: place-start / go-end; align-self: stretch; margin: 6px; gap: var(--s4); padding: var(--s4); font-size: var(--fs-xl); line-height: 1.3; animation: pop 240ms var(--ease);
  box-shadow: -6px 0 0 var(--ink), 6px 0 0 var(--ink), 0 -6px 0 var(--ink), 0 6px 0 var(--ink),
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink);
}
.place.reveal b { color: var(--brick-d); font-weight: 400; }
/* '친구 N명'은 한 덩어리로 줄을 바꿔 숫자가 혼자 떨어지지 않는다. */
.place .nw { white-space: nowrap; }
.tally { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: var(--s2); font-size: var(--fs-md); }
.trow { display: grid; grid-template-columns: auto minmax(0, 1fr) 72px; align-items: center; gap: var(--s3); }
.trow b { font-weight: 400; text-align: right; }
.tcells { display: flex; gap: 3px; height: 24px; }
.tcells i { flex: 1; background: var(--paper-2); }
.trow.o .tcells i.on { background: var(--o); box-shadow: inset 0 -3px 0 var(--o-d); }
.trow.x .tcells i.on { background: var(--x); box-shadow: inset 0 -3px 0 var(--x-d); }
.pill { display: inline-grid; place-items: center; min-width: 1.6em; padding: 0 9px; color: #fff7e6; }
.pill.o { background: var(--o); text-shadow: 3px 3px 0 var(--o-d); }
.pill.x { background: var(--x); text-shadow: 3px 3px 0 var(--x-d); }

/* 대기실: 지금 들어온 친구 */
.lobby { grid-area: go; align-self: stretch; display: flex; flex-direction: column; min-height: 0; }
.lobby .band { font-size: var(--fs-md); }
.lobby .cnt { margin-left: auto; }
.friends { list-style: none; margin: 0; padding: var(--s3); display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: var(--s3) var(--s2); }
.friends li { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: var(--fs-xs); line-height: 1.25; animation: pop 240ms var(--ease) both; }
.friends li > span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friends .face { width: 48px; height: 48px; }
.friends li.me .face { background: var(--chalk-y); box-shadow: -3px 0 0 var(--ink), 3px 0 0 var(--ink), 0 -3px 0 var(--ink), 0 3px 0 var(--ink), 0 0 0 6px var(--chalk-y); }
.friends li.me > span { color: var(--brick-d); }
/* 끊긴 친구: 얼굴만 흐리게, 이름은 읽히게(--muted 6.5:1) */
.friends li.off .face { opacity: .4; }
.friends li.off > span { color: var(--muted); }
.friends li.none { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--muted); }

/* O/X: 청·벽돌 큰 나무 버튼 */
/* 남는 높이만큼 버튼이 커진다(최대 240px). 버튼 아래 9px 그림자 자리를 뺀다. */
.go { grid-area: go; align-self: stretch; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.go .btn { min-height: 108px; height: calc(100% - 9px); max-height: 240px; align-self: end; flex-direction: column; gap: 0; }
.go .big { font-size: var(--fs-3xl); line-height: 1; }
.go small { font-size: var(--fs-md); }
/* 지금 내 자리: 분필 노랑 안쪽 띠(포커스 outline과 겹치지 않게 box-shadow로). */
.go .btn[aria-pressed="true"] { box-shadow: var(--step3), 0 9px 0 var(--ink), inset 0 0 0 6px var(--chalk-y); }

/* ===== 결과: 머리 띠로 구획 ===== */
.result { display: flex; flex-direction: column; gap: var(--s5); }
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); }
.result-head h1 { font-size: var(--fs-xl); color: var(--brick-d); }
#resultBody { display: flex; flex-direction: column; gap: var(--s5); }
.sect { min-width: 0; }
.sect .band { font-size: var(--fs-md); }
.sect .band small { margin-left: auto; font-size: var(--fs-md); }
.mapcard .mymap { display: block; width: 100%; height: auto; max-width: 520px; margin: 0 auto; padding: var(--s2); background: var(--paper-3); }
.mymap.wide { max-width: none; }
.result-grid { display: grid; gap: var(--s5); }
.result .profile { padding: var(--s4); }
.ranklist { list-style: none; margin: 0; padding: var(--s3); display: flex; flex-direction: column; gap: var(--s3); }
.ranklist li { display: grid; grid-template-columns: 30px 48px minmax(0, 1fr) 72px; align-items: center; gap: var(--s2) var(--s3); padding: 6px 9px; background: var(--paper); box-shadow: -3px 0 0 var(--line), 3px 0 0 var(--line), 0 -3px 0 var(--line), 0 3px 0 var(--line); }
.ranklist li.top { background: var(--sim-soft); box-shadow: -3px 0 0 var(--sim), 3px 0 0 var(--sim), 0 -3px 0 var(--sim), 0 3px 0 var(--sim); }
.ranklist li.none { display: block; text-align: center; }
.ranklist .face { width: 48px; height: 48px; }
.ranklist .k { color: var(--muted); text-align: center; font-size: var(--fs-md); }
.ranklist .nm b { display: block; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 칸 나뉜 픽셀 막대 */
.ranklist .bar { height: 12px; margin-top: 3px; background: repeating-linear-gradient(90deg, var(--paper-2) 0 9px, transparent 9px 12px); }
.ranklist .bar span { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--sim) 0 9px, transparent 9px 12px); }
.ranklist .n { text-align: right; font-size: var(--fs-md); white-space: nowrap; }
.panel.empty { max-width: none; }
.panel.empty h2 { font-size: var(--fs-lg); color: var(--brick-d); }

/* 나가기 확인 창: 두꺼운 쪽지 */
dialog.sheet { width: min(calc(100vw - 48px), 420px); padding: var(--s5); border: 0; color: var(--ink); text-align: center; }
dialog.sheet[open] { display: flex; flex-direction: column; gap: var(--s4); animation: pop 240ms var(--ease); }
dialog.sheet h2 { font-size: var(--fs-xl); color: var(--brick-d); }
dialog::backdrop { background: rgba(42, 42, 58, .6); }

@media (min-width: 720px) {
  .deco .bunting { height: 48px; background-size: 192px 48px; }
  .panel { max-width: 640px; padding: var(--s7) var(--s6); }
  .pv { display: flex; max-width: 640px; }
  /* 본인 확인: 큰 얼굴은 미리보기 패널이 보여 준다(세로는 카드 위, 가로는 오른쪽). */
  #v-confirm .pv { order: -1; }
  #v-confirm .bigface { display: none; }
  /* 누구인가요: 카드 4장이 한 줄에 들어가게 좌우 여백을 줄인다. */
  .panel.wide { max-width: 960px; padding-left: var(--s4); padding-right: var(--s4); }
  .input.code { min-height: 120px; }
  .place.reveal { font-size: var(--fs-2xl); }
  .panel h1 { font-size: var(--fs-2xl); }
  /* auto-fit은 칸 수를 최대 폭(160)으로 센다: 세로 태블릿(682px)에 4장, 가로에 5장 */
  .people { grid-template-columns: repeat(auto-fit, minmax(156px, 160px)); justify-content: center; }
  .qcard h2 { font-size: var(--fs-xl); }
  .go .btn { min-height: 132px; }
  .friends { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--s2); }
  .friends li { gap: 3px; }
  .friends .face { width: 60px; height: 60px; }
  .friends li { font-size: var(--fs-sm); }
  .result-head h1 { font-size: var(--fs-2xl); }
}

/* 가로(태블릿 가로 1180x820 등): 운동장을 크게 왼쪽에, 문제·자리·버튼은 오른쪽에 */
@media (orientation: landscape) and (min-width: 720px) {
  body[data-step="result"] main { max-width: 1600px; }
  /* 게임은 넓은 화면(1920)에서도 운동장이 화면 높이만큼 커지게 폭을 더 쓴다. */
  body[data-step="game"] main { max-width: 1920px; }
  /* 입장: 왼쪽 양식 + 오른쪽 미리보기 두 칸, 제목은 왼쪽 정렬 */
  main { max-width: 1240px; }
  .stage.entry { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: stretch; gap: var(--s7); }
  .stage.entry .panel, .stage.entry .pv { max-width: none; }
  .stage.entry .panel { align-items: stretch; text-align: left; justify-content: center; padding: var(--s6); }
  .stage.entry .panel .actions { align-items: stretch; }
  .stage.entry .chips { justify-content: flex-start; }
  .stage.entry .btn.ghost { align-self: flex-start; }
  #v-confirm .pv { order: 0; }
  .stage.entry .panel > .tag, .stage.entry .logo { align-self: flex-start; }
  .result-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  /* 성향 카드가 더 길어서, 순위 칸은 스크롤해도 위 띠 아래에 붙어 따라온다. */
  .rankcard { position: sticky; top: calc(var(--top-h) + var(--s4)); }
  /* 공개 쪽지는 운동장 아래끝까지, 글자는 36px로 키워 칸을 채운다. */
  .place.reveal { font-size: var(--fs-xl); }
  /* 게임 판(운동장 + 오른쪽 칸)은 운동장 높이에 맞춘다. 오른쪽 맨 아래 칸(O/X·친구 격자)이 남는 높이를 채워 운동장과 아래끝이 맞는다. */
  .game { flex: initial; grid-template-columns: minmax(0, 1fr) clamp(300px, 28vw, 380px); grid-template-rows: auto auto 1fr; grid-template-areas: "field q" "field place" "field go"; align-items: start; }
  .kidfield { width: min(calc(100% - 18px), calc((100dvh - var(--top-h) - var(--ban) - 72px) * 2112 / 1392)); align-self: start; }
  .qcard h2 { font-size: var(--fs-lg); }
  .go .btn { min-height: 144px; max-height: none; }
  /* 친구 격자는 판 높이를 늘리지 않고(contain: size) 남는 높이 안에서 넘기며 본다. */
  .lobby { align-self: stretch; contain: size; min-height: 240px; }
  .friends { flex: 1; min-height: 0; overflow-y: auto; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); align-content: start; gap: var(--s3) var(--s2); }
  .friends .face { width: 72px; height: 72px; }
  .friends li { font-size: var(--fs-sm); }
}

/* 태블릿 가로(1180x820, 1024x768처럼 3:2보다 덜 넓은 화면): 옆에 두면 운동장이 폭에 막혀 위아래가 빈다.
   칠판 문제를 위에 한 줄로 길게 두고(남은 시간은 오른쪽 칸 폭만큼), 운동장 높이를 그만큼 줄여 화면을 채운다. */
@media (orientation: landscape) and (min-width: 720px) and (max-aspect-ratio: 3/2) {
  .game { grid-template-areas: "q q" "field place" "field go"; }
  .qcard { flex-direction: row; align-items: center; gap: var(--s5); }
  .qtext { flex: 1; }
  .timer { flex: none; width: calc(clamp(300px, 28vw, 380px) - var(--s5)); }
  /* 192px = 칠판 한 줄(96) + 칸 사이(24) + 위아래 여백·테두리 */
  .kidfield { width: min(calc(100% - 18px), calc((100dvh - var(--top-h) - var(--ban) - 192px) * 2112 / 1392)); }
  .tally { font-size: var(--fs-lg); gap: var(--s3); }
  .tcells { height: 36px; }
}
