/* 퀴즈 땅따먹기 공통 모양 */
:root {
  --bg: #fff8ec;
  --paper: #ffffff;
  --ink: #2b2a33;
  --muted: #6d6a78;
  --line: #2b2a33;
  --t0: #ff6b81;
  --t0-soft: #ffd3da;
  --t1: #4d7cff;
  --t1-soft: #d3defc;
  --t2: #f2b705;
  --t2-soft: #fdf0bf;
  --t3: #2fb36b;
  --t3-soft: #cdeedb;
  --water: #9fd3e6;
  --gold: #ffc23d;
  --empty: #efe6d4;
  --ok: #2bb673;
  --shadow: 0 4px 0 rgba(43, 42, 51, 0.9);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

.title { text-align: center; margin: 18px 0 8px; font-size: clamp(30px, 7vw, 56px); letter-spacing: -0.03em; }
.title span { color: var(--t0); }
.title span + span { color: var(--t1); }
.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 16px; }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  padding: 12px 22px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--gold);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(43, 42, 51, 0.9); }
.btn.ghost { background: #fff; }
.btn.big { font-size: 22px; padding: 16px 30px; }
.btn:disabled { opacity: 0.5; cursor: default; }

input, textarea, select {
  font: inherit;
  font-size: 18px;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
textarea { min-height: 160px; resize: vertical; font-size: 15px; }
label { display: block; font-weight: 700; margin: 12px 0 6px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* 팀 */
.badge { display: inline-block; padding: 4px 14px; border: 3px solid var(--line); border-radius: 999px; font-weight: 800; }
.badge.t0 { background: var(--t0); color: #fff; }
.badge.t1 { background: var(--t1); color: #fff; }
.badge.t2 { background: var(--t2); color: var(--ink); }
.badge.t3 { background: var(--t3); color: #fff; }

/* 점수판 */
.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin-bottom: 12px; }
.score { border: 3px solid var(--line); border-radius: 14px; padding: 8px 14px; font-weight: 800; font-size: clamp(16px, 2.6vw, 26px); color: #fff; box-shadow: var(--shadow); }
.score.t0 { background: var(--t0); }
.score.t1 { background: var(--t1); text-align: right; }
.score.t2 { background: var(--t2); color: var(--ink); }
.score.t3 { background: var(--t3); }
.score b { font-size: 1.4em; }
/* 팀 수만큼 점수판 (spec 13절) */
.scores { display: flex; gap: 8px; flex: 1; min-width: 0; }
.scores .score { flex: 1; text-align: center; padding: 6px 8px; white-space: nowrap; overflow: hidden; }
.scores .score.lead { outline: 4px solid var(--gold); outline-offset: 1px; }
.scorebar.multi { display: flex; align-items: center; }
.scorebar.multi .clock { order: -1; }
.clock { font-size: clamp(22px, 4vw, 40px); font-weight: 900; font-variant-numeric: tabular-nums; text-align: center; min-width: 3.5em; }
.clock.hurry { color: var(--t0); }

/* 땅 */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
  gap: 5px;
  padding: 8px;
  background: var(--line);
  border-radius: 16px;
  aspect-ratio: calc(var(--cols, 10) / var(--rows, 7));
  width: 100%;
}
.cell {
  border: 0;
  border-radius: 8px;
  background: var(--empty);
  font-size: clamp(12px, 2.6vw, 30px);
  padding: 0;
  cursor: default;
  transition: background-color 0.25s, transform 0.15s;
  display: grid;
  place-items: center;
  color: var(--ink);
}
.cell.star { background: #fff1c4; }
.cell.t0 { background: var(--t0); }
.cell.t1 { background: var(--t1); }
.cell.t2 { background: var(--t2); }
.cell.t3 { background: var(--t3); }
.cell.void { background: var(--water); cursor: default; opacity: 0.85; background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255, 255, 255, 0.35) 6px 9px); }
.board.maze .cell.void { background: #6d6a78; background-image: none; }
.cell.locked { animation: blink 0.8s infinite alternate; }
.cell.locked.lk0 { outline: 4px dashed var(--t0); outline-offset: -4px; }
.cell.locked.lk1 { outline: 4px dashed var(--t1); outline-offset: -4px; }
.cell.locked.lk2 { outline: 4px dashed var(--t2); outline-offset: -4px; }
.cell.locked.lk3 { outline: 4px dashed var(--t3); outline-offset: -4px; }
.cell.pickable { cursor: pointer; box-shadow: inset 0 0 0 4px var(--gold); }
.cell.pickable:hover { transform: scale(1.06); }
@keyframes blink { from { filter: brightness(1); } to { filter: brightness(1.25); } }

/* 아이템·이벤트 (spec 10·11절) */
.cell.gold { box-shadow: inset 0 0 0 3px var(--gold), 0 0 10px rgba(255, 194, 61, 0.8); }
.cell.chest { background: #ffe9a8; animation: blink 0.6s infinite alternate; }
.board.golden { background: linear-gradient(135deg, #b8860b, #ffc23d, #b8860b); }
.board.aiming .cell.pickable { box-shadow: inset 0 0 0 4px #fff, 0 0 0 3px var(--ink); animation: blink 0.5s infinite alternate; }
.cell.pop { animation: pop 0.45s ease-out; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
.cell.boom { animation: boom 0.5s ease-out; }
@keyframes boom { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-4px, 2px) rotate(-6deg); } 40% { transform: translate(4px, -2px) rotate(6deg); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, -1px); } }

/* 끝 화면 과일 비 (spec 14절) */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti span { position: absolute; top: -50px; font-size: 34px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }

/* 효과음 단추 */
#sound-btn { position: fixed; bottom: 12px; right: 12px; z-index: 15; font-size: 20px; padding: 6px 10px; border-radius: 12px; }

/* 맵 고르기 */
.maps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.map-opt { font: inherit; text-align: left; border: 3px solid var(--line); border-radius: 12px; background: #fff; padding: 8px 10px; cursor: pointer; }
.map-opt b { display: block; }
.map-opt small { color: var(--muted); font-size: 12px; }
.map-opt.on { background: var(--gold); box-shadow: var(--shadow); }
.preview { margin-top: 10px; pointer-events: none; }
.preview .cell { font-size: 10px; border-radius: 3px; }
.preview.board { gap: 2px; padding: 4px; border-radius: 10px; }

.bag { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.bag .slot { min-width: 96px; font-size: 16px; padding: 8px 12px; background: #fff; }
.bag .slot.empty { opacity: 0.35; cursor: default; box-shadow: none; }
.bag .slot.on { background: var(--gold); transform: translateY(3px); box-shadow: 0 1px 0 rgba(43, 42, 51, 0.9); }
.bag .ready { font-weight: 800; color: var(--ok); }

#banner {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -120%); z-index: 25;
  background: var(--ink); color: #fff; border: 3px solid var(--gold); border-radius: 16px;
  padding: 12px 22px; font-weight: 800; font-size: clamp(16px, 3vw, 26px); text-align: center;
  transition: transform 0.3s, opacity 0.3s; max-width: calc(100% - 24px); pointer-events: none; opacity: 0;
}
#banner.show { transform: translate(-50%, 0); opacity: 1; }
#banner.golden { background: linear-gradient(135deg, #b8860b, #ffc23d); color: var(--ink); }
#banner.chest { background: #ffe9a8; color: var(--ink); }
.quiz .hint { color: var(--ok); font-weight: 800; margin: 0; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-top: 14px; cursor: pointer; }
.switch input { width: 22px; height: 22px; }

/* 문제 창 */
.overlay { position: fixed; inset: 0; background: rgba(43, 42, 51, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.quiz { width: min(560px, 100%); }
.quiz .q { font-size: clamp(20px, 4.5vw, 28px); font-weight: 800; line-height: 1.4; margin: 8px 0 16px; word-break: keep-all; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices .btn { background: #fff; font-size: 20px; word-break: keep-all; }
.timer-bar { height: 10px; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.timer-bar i { display: block; height: 100%; background: var(--gold); transition: width 0.25s linear; }

.result { text-align: center; font-size: clamp(22px, 5vw, 34px); font-weight: 900; }
.result.ok { color: var(--ok); }
.result.no { color: var(--t0); }

/* 사람 목록 */
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-col { border: 3px solid var(--line); border-radius: 14px; padding: 10px; min-height: 80px; }
.team-col.t0 { background: var(--t0-soft); }
.team-col.t1 { background: var(--t1-soft); }
.team-col.t2 { background: var(--t2-soft); }
.team-col.t3 { background: var(--t3-soft); }
.teams.n4 { grid-template-columns: 1fr 1fr; }
.team-col h3 { margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; margin: 3px; padding: 5px 12px; background: #fff; border: 2px solid var(--line); border-radius: 999px; font-weight: 700; font: inherit; font-weight: 700; }
button.chip { cursor: pointer; }
.chip.off { opacity: 0.45; }
.chip small { color: var(--muted); font-weight: 600; }

.code { font-size: clamp(48px, 12vw, 110px); font-weight: 900; letter-spacing: 0.08em; text-align: center; line-height: 1; }
.url { text-align: center; font-size: clamp(16px, 2.6vw, 24px); font-weight: 700; word-break: break-all; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; border-bottom: 2px solid var(--empty); text-align: left; }
th { font-size: 14px; color: var(--muted); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 999px; background: var(--empty); overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ok); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 700;
  transition: 0.25s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#offline { position: fixed; top: 0; left: 0; right: 0; background: var(--t0); color: #fff; text-align: center; padding: 6px; font-weight: 700; z-index: 30; }

/* 입장 카드 (QR + 방 번호) */
.join-card { display: flex; gap: 18px; align-items: center; }
.join-text { flex: 1; min-width: 0; text-align: center; }
.qr-btn { flex: none; border: 3px solid var(--line); border-radius: 14px; background: #fff; padding: 6px; cursor: zoom-in; display: grid; gap: 2px; font: inherit; font-size: 12px; color: var(--muted); }
.qr-btn canvas { width: 160px; height: 160px; image-rendering: pixelated; display: block; }
.qr-overlay { cursor: zoom-out; }
.qr-overlay canvas { width: min(78vh, 86vw); height: min(78vh, 86vw); image-rendering: pixelated; display: block; }
@media (max-width: 560px) { .join-card { flex-direction: column; } }

/* 내 문제 모음 (spec 27절) */
.qsets { margin-top: 14px; padding-top: 12px; border-top: 2px dashed rgba(43, 42, 51, 0.2); }
.qsets .qs-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
/* '한 번 더 누르세요' 기다리는 단추 */
.btn.armed { background: #ff5a6e !important; color: #fff !important; }
.q-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.btn.sm { font-size: 14px; padding: 6px 10px; box-shadow: 0 2px 0 rgba(43, 42, 51, 0.9); border-width: 2px; }
/* 문제 목록 (spec 28절) */
#q-text { min-height: 64px; height: 64px; font-size: 13px; }
.q-preview { position: relative; margin-top: 8px; border: 3px solid var(--line, #2b2a33); background: #fffdf5; overflow-y: auto; }
.q-preview .qp-empty { padding: 14px; text-align: center; color: #8a8494; font-size: 14px; }
.q-preview .qp-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; padding: 6px 10px; background: #2b2a33; color: #fff; font-size: 13px; }
.qp-item { display: flex; align-items: flex-start; gap: 6px; padding: 7px 10px 7px 4px; border-bottom: 2px solid rgba(43, 42, 51, 0.12); }
.qp-item:nth-child(odd) { background: rgba(255, 207, 58, 0.12); }
.qp-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.qp-no { flex: none; width: 2.2em; text-align: right; font-weight: 800; color: #8a8494; }
.qp-q { font-size: 14px; line-height: 1.35; word-break: keep-all; overflow-wrap: anywhere; }
.qp-opts { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px; }
.qp-opts > * { line-height: 1.5; white-space: nowrap; font-family: inherit; }
.qp-opts > * { font-size: 12px; padding: 1px 7px; border: 2px solid; border-radius: 0; }
.qp-opts button { cursor: pointer; }
.qp-opts button.no:hover { background: #d9f7d2; border-color: #3aa64a; color: #1d5e27; } /* 누르면 정답이 된다는 미리보기 */
.qp-opts button.ok:hover { filter: brightness(0.95); text-decoration: underline; }
.qp-edit { font-size: 13px; padding: 1px 6px; width: 12em; border: 2px solid #3aa64a; }
.q-preview .qp-head { align-items: center; }
.qp-toggle { font: inherit; font-size: 13px; color: #fff; background: transparent; border: 2px solid rgba(255, 255, 255, 0.6); padding: 1px 8px; cursor: pointer; }
.qp-toggle.on { background: #3aa64a; border-color: #3aa64a; }
.qp-tip { padding: 4px 10px; font-size: 12px; color: #6a6474; background: #f4f1f7; border-bottom: 2px solid rgba(43, 42, 51, 0.12); }
.qp-opts .ok { background: #d9f7d2; border-color: #3aa64a; color: #1d5e27; }
.qp-opts .no { background: #f4f1f7; border-color: #c4bfcc; color: #6a6474; }
.qp-opts .essay { background: #fff3c4; border-color: #e0b020; color: #7a5a00; }
textarea.drop { outline: 4px dashed var(--gold); outline-offset: 2px; }

.layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.layout.lobby { grid-template-columns: 1fr 380px; } /* 대기 화면: 문제 목록이 보이게 오른쪽을 조금 넓게 */
/* 대기 화면 두 단계 (spec 31절): 1단계는 문제 준비(QR 숨김), 2단계는 QR·학생(문제 숨김) */
#s-lobby.prep .join-card, #s-lobby.prep #students-card, #s-lobby.prep #q-summary, #s-lobby.prep #btn-start { display: none; }
#s-lobby.open #q-card, #s-lobby.open #step-prep { display: none; }
#s-lobby.prep .layout.lobby { grid-template-columns: 1fr 460px; }
/* 놀이 시간 고르기 (spec 32절) */
.time-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.min-arrows { display: inline-flex; flex-direction: column; height: 42px; box-sizing: border-box; margin-right: -9px; position: relative; z-index: 1; border: 3px solid var(--line, #2b2a33); background: #fffdf5; }
.min-arrows button { flex: 1; font: inherit; font-size: 11px; line-height: 1; padding: 0 7px; border: 0; background: transparent; color: var(--line, #2b2a33); cursor: pointer; }
.min-arrows button + button { border-top: 2px solid var(--line, #2b2a33); }
.min-arrows button:hover { background: var(--gold, #ffcf3a); }
/* 숫자 칸 안의 브라우저 기본 위아래 화살표는 숨긴다 (왼쪽 ▲▼ 로 대신) */
.time-pick #in-min { -moz-appearance: textfield; appearance: textfield; }
.time-pick #in-min::-webkit-inner-spin-button, .time-pick #in-min::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.time-pick #in-min { height: 42px; box-sizing: border-box; width: 3.2em; text-align: center; font-size: 20px; font-weight: 800; padding: 6px 4px; }
.time-pick .time-quick { display: flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; }
.time-pick .time-quick .on { background: var(--gold, #ffcf3a); }
.step-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.step-card .btn.big { flex: none; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 480px) {
  .wrap { padding: 10px; }
  .board { gap: 3px; padding: 5px; border-radius: 12px; }
  .cell { border-radius: 5px; }
  .choices { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
