:root {
  --bg: #0d0b1e;
  --bg2: #1b1440;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-line: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --muted: #a9a3d1;
  --A: #ff4d7e;
  --B: #37b6ff;
  --gold: #ffd23f;
  --ok: #3ddc97;
  --bad: #ff5c5c;
  --radius: 16px;
  --title: 'Black Han Sans', 'Pretendard', sans-serif;
  --ui: 'Pretendard', -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  color: var(--text);
  background: radial-gradient(ellipse at 20% 0%, #2a1a6b 0%, transparent 55%),
              radial-gradient(ellipse at 90% 100%, #4a1043 0%, transparent 50%),
              var(--bg);
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
  user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font-family: inherit; color: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ── 점수판 ── */
#scorebar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 6px 10px; min-height: 52px; flex: none;
  background: rgba(0, 0, 0, 0.35); border-bottom: 1px solid var(--panel-line);
}
.team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.team.B { flex-direction: row-reverse; }
.team .name { font-family: var(--title); font-size: clamp(16px, 3.4vmin, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team .pts { font-family: var(--title); font-size: clamp(26px, 6.5vmin, 48px); min-width: 1.4em; text-align: center; line-height: 1; transition: transform .25s; }
.team.A .name, .team.A .pts { color: var(--A); }
.team.B .name, .team.B .pts { color: var(--B); }
.team .pts.bump { transform: scale(1.35); }
.pm { display: flex; gap: 4px; }
.pm button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--panel-line); background: var(--panel); font-size: 18px; font-weight: 700; }
.home-btn { border: 0; background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: 20px; }

/* ── 메인 ── */
#main { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px 16px; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.head h2 { margin: 0; font-family: var(--title); font-weight: 400; font-size: clamp(20px, 4.6vmin, 34px); }
.head .sub { color: var(--muted); font-size: clamp(13px, 2.6vmin, 18px); }

/* ── 홈 ── */
.hero { text-align: center; margin: 4px 0 6px; }
.hero h1 { margin: 0; font-family: var(--title); font-weight: 400; font-size: clamp(30px, 8vmin, 64px);
  background: linear-gradient(90deg, var(--A), var(--gold), var(--B)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }
@media (orientation: portrait) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (orientation: landscape) and (max-height: 500px) {
  .grid { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  #main { padding-top: 8px; }
  .card { padding: 8px 6px; gap: 2px; }
  .card .ic { font-size: 26px; }
  .card .d { display: none; }
  .hero { margin: 0; }
  .hero h1 { font-size: 30px; }
}
.card {
  border: 1px solid var(--panel-line); background: var(--panel); border-radius: var(--radius);
  padding: 14px 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .12s, background .12s;
}
.card:active { transform: scale(.96); background: rgba(255, 255, 255, .12); }
.card .ic { font-size: clamp(30px, 7vmin, 44px); }
.card .t { font-family: var(--title); font-size: clamp(16px, 3.4vmin, 22px); }
.card .d { color: var(--muted); font-size: 12px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }

/* ── 버튼 ── */
.btn {
  border: 1px solid var(--panel-line); background: var(--panel); border-radius: 12px;
  padding: 10px 14px; font-size: clamp(14px, 3vmin, 19px); font-weight: 700; min-height: 44px;
  transition: transform .1s;
}
.btn:active { transform: scale(.95); }
.btn.big { font-size: clamp(18px, 4vmin, 26px); padding: 12px 22px; }
.btn.primary { background: linear-gradient(135deg, #7b5cff, #c04bff); border-color: transparent; }
.btn.gold { background: var(--gold); color: #221; border-color: transparent; }
.btn.A { background: var(--A); border-color: transparent; }
.btn.B { background: var(--B); border-color: transparent; color: #031; }
.btn.ok { background: var(--ok); color: #032; border-color: transparent; }
.btn.bad { background: var(--bad); border-color: transparent; }
.btn.on { outline: 3px solid var(--gold); }
.btn:disabled { opacity: .35; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.row.spread { justify-content: space-between; }

/* 가로 화면: 무대 + 조작 패널 2단 */
.stage-wrap { flex: 1; display: grid; gap: 12px; min-height: 0; grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
@media (orientation: landscape) {
  .stage-wrap { grid-template-columns: 1fr minmax(240px, 34%); grid-template-rows: 1fr; }
  .controls { justify-content: center; }
}
.stage {
  position: relative; border-radius: var(--radius); background: rgba(0, 0, 0, .3); border: 1px solid var(--panel-line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 0; overflow: hidden; padding: 12px; text-align: center;
}
.controls { display: flex; flex-direction: column; gap: 8px; }
.controls .row { justify-content: stretch; }
.controls .row > .btn { flex: 1; }

/* ── 노래 퀴즈 ── */
.disc {
  width: clamp(90px, 30vmin, 200px); aspect-ratio: 1; border-radius: 50%;
  background: repeating-radial-gradient(circle, #222 0 2px, #111 2px 5px);
  display: grid; place-items: center; box-shadow: 0 0 40px rgba(123, 92, 255, .35);
}
.disc::after { content: ''; width: 34%; aspect-ratio: 1; border-radius: 50%; background: linear-gradient(135deg, var(--A), var(--B)); }
.disc.spin { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.qno { font-family: var(--title); font-size: clamp(22px, 5vmin, 38px); color: var(--muted); }
.hint { font-family: var(--title); font-size: clamp(28px, 8vmin, 64px); letter-spacing: .12em; color: var(--gold); }
.answer { font-family: var(--title); font-size: clamp(26px, 7vmin, 56px); line-height: 1.15; }
.answer small { display: block; font-family: var(--ui); font-size: .42em; color: var(--muted); font-weight: 600; margin-top: 6px; }
.pop { animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.bar { width: 80%; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--A), var(--gold)); }

/* ── 사진 퀴즈 ── */
.photo {
  position: relative; height: 100%; max-height: 100%; aspect-ratio: 3 / 4; max-width: 100%;
  border-radius: 12px; overflow: hidden; background: #000;
}
.photo img { width: 100%; height: 100%; object-fit: cover; transition: transform .9s cubic-bezier(.3, .7, .2, 1); }
.photo .lvl { position: absolute; top: 8px; left: 8px; background: rgba(0, 0, 0, .65); padding: 4px 10px; border-radius: 999px; font-weight: 800; }
.photo .credit { position: absolute; bottom: 4px; right: 6px; font-size: 10px; color: rgba(255, 255, 255, .7); text-shadow: 0 0 3px #000; }
.photo .reveal { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 8px 18px; background: linear-gradient(transparent, rgba(0, 0, 0, .85)); }
.stage.photo-stage { padding: 8px; }

/* ── 제시어 (몸으로 말해요) ── */
.word { font-family: var(--title); font-size: clamp(34px, 11vmin, 96px); line-height: 1.1; word-break: keep-all; }
.timer { font-family: var(--title); font-size: clamp(30px, 9vmin, 72px); }
.timer.warn { color: var(--bad); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line); font-weight: 700; font-size: 14px; }
.notice { color: var(--gold); font-weight: 800; font-size: clamp(15px, 3.4vmin, 22px); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--panel-line); background: var(--panel); font-weight: 700; font-size: 15px; }
.chip.on { background: var(--gold); color: #221; border-color: transparent; }
.results { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-height: 40%; overflow: auto; }
.results span { padding: 4px 10px; border-radius: 8px; font-size: 14px; font-weight: 700; }
.results .o { background: rgba(61, 220, 151, .2); color: var(--ok); }
.results .x { background: rgba(255, 92, 92, .15); color: var(--bad); text-decoration: line-through; }

/* ── 캐치마인드 ── */
.canvas-box { position: relative; flex: 1; width: 100%; min-height: 0; border-radius: 12px; background: #fff; overflow: hidden; touch-action: none; }
.canvas-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.canvas-box .ov { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; pointer-events: none; color: #222; font-weight: 800; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--gold); }

/* ── 폭탄 ── */
.bomb { font-size: clamp(80px, 30vmin, 200px); line-height: 1; }
.bomb.shake { animation: shake .15s infinite; }
@keyframes shake { 25% { transform: translate(-3px, 2px) rotate(-4deg); } 75% { transform: translate(3px, -2px) rotate(4deg); } }
.category { font-family: var(--title); font-size: clamp(28px, 8vmin, 64px); color: var(--gold); word-break: keep-all; }
.boom { font-family: var(--title); font-size: clamp(60px, 22vmin, 160px); color: var(--bad); text-shadow: 0 0 30px #ff9800; }

/* ── 올인 ── */
.bets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.bet { border-radius: var(--radius); padding: 10px; border: 2px solid; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.bet.A { border-color: var(--A); }
.bet.B { border-color: var(--B); }
.bet .amt { font-family: var(--title); font-size: clamp(30px, 8vmin, 56px); }
.bet .row .btn { min-height: 38px; padding: 6px 10px; }
.question { font-family: var(--title); font-size: clamp(22px, 6vmin, 44px); word-break: keep-all; line-height: 1.25; }

/* ── 룰렛 ── */
.wheel-box { position: relative; height: 100%; aspect-ratio: 1; max-width: 100%; }
.wheel-box canvas { width: 100%; height: 100%; }
.wheel-box .pin { position: absolute; top: -4px; left: 50%; transform: translateX(-50%); width: 0; height: 0;
  border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--gold); filter: drop-shadow(0 2px 3px #000); }
.result-big { font-family: var(--title); font-size: clamp(28px, 8vmin, 60px); color: var(--gold); }

/* ── 팀 나누기 ── */
.names { flex: 1; width: 100%; min-height: 160px; resize: none; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-line);
  background: rgba(0, 0, 0, .3); color: var(--text); font-size: 17px; line-height: 1.5; user-select: text; -webkit-user-select: text; }
.tboard { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 10px; }
.tcol { border-radius: var(--radius); border: 2px solid; padding: 8px; display: flex; flex-direction: column; gap: 5px; overflow-y: auto; background: rgba(0, 0, 0, .25); }
.tcol.A { border-color: var(--A); }
.tcol.B { border-color: var(--B); }
.tname { font-family: var(--title); font-size: clamp(18px, 4.4vmin, 30px); text-align: center; }
.tname small { font-family: var(--ui); font-size: 13px; color: var(--muted); }
.tcol.A .tname { color: var(--A); }
.tcol.B .tname { color: var(--B); }
.tmember { text-align: center; font-weight: 800; font-size: clamp(15px, 3.6vmin, 24px); padding: 4px; border-radius: 8px; background: var(--panel); }
.tcenter { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-width: 0; }
.tactions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 280px; }
.slot { font-family: var(--title); font-size: clamp(30px, 10vmin, 76px); text-align: center; word-break: keep-all; min-height: 1.2em; }
.slot.A { color: var(--A); text-shadow: 0 0 24px var(--A); }
.slot.B { color: var(--B); text-shadow: 0 0 24px var(--B); }
@media (orientation: portrait) {
  .tboard { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; }
  .tcenter { grid-column: 1 / -1; grid-row: 1; }
}

/* ── 설정 ── */
.form { display: grid; gap: 10px; max-width: 640px; width: 100%; margin: 0 auto; }
.form label { font-weight: 700; color: var(--muted); font-size: 14px; }
.form input, .form textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-line); background: rgba(0, 0, 0, .3); color: var(--text); font-size: 16px; }
.form textarea { min-height: 160px; }

/* ── YouTube ── */
#yt-wrap.yt-hidden { position: fixed; left: 0; bottom: 0; width: 200px; height: 200px; opacity: 0; pointer-events: none; z-index: -1; }
#yt-wrap.yt-setup { position: fixed; z-index: 50; left: 50%; top: 58%; transform: translate(-50%, -50%); width: min(90vw, 480px); aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 4px var(--gold); }
.sound-screen .spacer { flex: 1; min-height: calc(min(90vw, 480px) * 9 / 16 + 16px); }
@media (orientation: landscape) {
  #yt-wrap.yt-setup { left: 16px; top: calc(50% + 26px); transform: translateY(-50%); width: min(52vw, 520px); }
  .sound-screen { padding-left: calc(min(52vw, 520px) + 16px); justify-content: center; }
  .sound-screen .spacer { display: none; }
}
#yt-wrap iframe { width: 100%; height: 100%; }

/* ── 토스트/플래시 ── */
#toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(120px); background: #222; border: 1px solid var(--panel-line);
  padding: 10px 16px; border-radius: 12px; font-weight: 700; transition: transform .25s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 90; opacity: 0; }
#flash.go { animation: flash .6s; }
@keyframes flash { 0% { opacity: .75; } 100% { opacity: 0; } }
