:root {
  --red-900: #14020a; --red-800: #2a040c; --red-700: #4a0710; --red-600: #7d0d1a; --red-500: #a8131f;
  --gold-200: #fff3c4; --gold-300: #ffe08a; --gold-400: #ffcf4a; --gold-500: #e0a321; --gold-700: #8a5a0b;
  --ink: #2a1200; --cream: #fff3c4; --muted: #cfa97a;
  --display: "Black Han Sans", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --logo: "Limelight", Georgia, serif;
  --body: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --vvh: 100dvh;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #090103; color: var(--cream); font-family: var(--body); overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: minmax(44dvh, 1fr) auto; overflow: hidden; }
#stage { position: relative; min-height: 0; background: #090103; }
#stage canvas { display: block; width: 100%; height: 100%; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0, 0, 0, .55) 100%); }

/* 위쪽 표시 */
#hud { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 2; }
#hud .chip { pointer-events: auto; }
#mute { margin-left: auto; }
.chip { border: 1px solid rgba(255, 243, 196, .16); background: rgba(20, 2, 10, .8); color: var(--gold-300); border-radius: 14px; height: 28px; padding: 0 12px; display: inline-flex; align-items: center; font: 14px/1 var(--display); }

/* 아래 패널: 커튼 무늬 + 전구 띠 */
#panel { position: relative; z-index: 1; padding: 20px 16px max(14px, env(safe-area-inset-bottom)); max-height: 56dvh; overflow-y: auto;
  background: repeating-linear-gradient(90deg, var(--red-800) 0 22px, #33050e 22px 44px);
  border-top: 3px solid var(--gold-500); box-shadow: 0 -10px 30px rgba(0, 0, 0, .6); }
#panel::before { content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 10px; pointer-events: none;
  background: radial-gradient(circle, var(--gold-200) 0 2.4px, rgba(255, 207, 74, .5) 2.6px 4px, transparent 4.4px) 0 0 / 20px 10px repeat-x; filter: drop-shadow(0 0 4px #ffb300); }
#panel > section { display: none; flex-direction: column; gap: 10px; max-width: 460px; margin: 0 auto; }
#app[data-view="home"] #v-home, #app[data-view="lobby"] #v-lobby, #app[data-view="play"] #v-play,
#app[data-view="reveal"] #v-reveal, #app[data-view="end"] #v-end { display: flex; }

.logo { margin: 0; text-align: center; font: 400 clamp(38px, 11vw, 54px)/1 var(--logo); letter-spacing: .02em;
  color: var(--gold-400); }
.tag { margin: 0 0 6px; text-align: center; font: 18px/1 var(--display); color: var(--muted); }
.label { font: 15px/1 var(--display); color: var(--muted); margin-top: 4px; }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; }
.row .field { flex: 1; min-width: 0; }

.field { height: 50px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--gold-700); background: rgba(10, 1, 4, .7); color: var(--cream); font: 20px/1 var(--display); outline: none; }
.field::placeholder { color: #8a6a4a; }
.field:focus { border-color: var(--gold-400); box-shadow: 0 0 0 3px rgba(255, 207, 74, .2); }
.field.code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: var(--logo); font-size: 24px; }

.btn { height: 50px; padding: 0 18px; border-radius: 10px; border: 2px solid var(--gold-500); background: linear-gradient(#5a0a14, #2a040c); color: var(--gold-300); font: 20px/1 var(--display); letter-spacing: .03em; transition: transform .06s, filter .15s; white-space: nowrap; }
.btn:active { transform: translateY(2px) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.gold { border-color: #fff3c4; background: linear-gradient(#fff3c4, #ffcf4a 45%, #c98a12); color: var(--ink); box-shadow: 0 4px 0 #6a4406; }
.btn.gold:active { box-shadow: 0 2px 0 #6a4406; }
.btn.big { height: 58px; font-size: 26px; margin-top: 4px; }
.btn.small { height: 36px; font-size: 15px; padding: 0 12px; }
.btn.on { border-color: #fff3c4; background: linear-gradient(#fff3c4, #ffcf4a 45%, #c98a12); color: var(--ink); }
.link { background: none; border: 0; color: var(--muted); font-size: 14px; text-decoration: underline; padding: 6px; align-self: center; }

.codebar { display: flex; align-items: center; gap: 12px; }
.codebar span { font: 15px/1 var(--display); color: var(--muted); }
.codebar b { font: 400 32px/1 var(--logo); letter-spacing: .16em; color: var(--gold-400); flex: 1; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid3 .btn { height: 40px; padding: 0 4px; font-size: 16px; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg .btn { height: 40px; padding: 0; font: 20px/1 var(--logo); }
.pick { text-align: center; font: 26px/1.3 var(--display); color: var(--gold-400); padding: 14px 0 4px; }
#hostbox, #guestbox { display: flex; flex-direction: column; gap: 10px; }
#app[data-host="1"] #guestbox, #app[data-host="0"] #hostbox { display: none; }

/* 버저 */
#status { text-align: center; font: 22px/1.2 var(--display); min-height: 28px; color: var(--cream); }
#buzzer { align-self: center; width: min(46vw, 190px); aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0; position: relative;
  background: radial-gradient(circle at 50% 38%, #2a2a2a, #050505 70%); box-shadow: 0 10px 22px rgba(0, 0, 0, .7), inset 0 2px 3px rgba(255, 255, 255, .25); }
#buzzer span { position: absolute; inset: 9%; border-radius: 50%; display: grid; place-items: center; font: clamp(26px, 8vw, 38px)/1 var(--display); color: #fff3e8; letter-spacing: .08em;
  background: radial-gradient(circle at 38% 28%, #ff9a8a, #e8281c 38%, #8a0a08 100%);
  box-shadow: 0 9px 0 #5a0504, 0 0 34px rgba(255, 60, 40, .55), inset 0 -8px 16px rgba(0, 0, 0, .35), inset 0 6px 10px rgba(255, 255, 255, .35);
  transform: translateY(-9px); transition: transform .05s, box-shadow .05s, filter .2s; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
#buzzer:active:not(:disabled) span, #buzzer.down span { transform: translateY(-1px); box-shadow: 0 1px 0 #5a0504, 0 0 50px rgba(255, 90, 60, .9), inset 0 -4px 10px rgba(0, 0, 0, .4); }
#buzzer:disabled { cursor: default; }
#buzzer:disabled span { filter: grayscale(.85) brightness(.55); box-shadow: 0 9px 0 #222, inset 0 -8px 16px rgba(0, 0, 0, .35); }
.hint.key { display: none; }

/* 정답 공개 */
.card { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 12px; border: 2px solid var(--gold-500); background: rgba(10, 1, 4, .72); }
.card img { width: 104px; height: 104px; border-radius: 8px; object-fit: cover; background: #1a0a02; flex: none; }
.meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta b { font: 24px/1.15 var(--display); color: var(--gold-400); }
.meta span { color: var(--cream); font-size: 15px; }
.meta a { color: var(--gold-200); font-size: 14px; margin-top: 4px; }
.meta small { color: #a88a66; font-size: 11px; }
#rwho { text-align: center; font: 24px/1.2 var(--display); }
#rwho em { font-style: normal; color: var(--gold-400); font-family: var(--logo); }

/* 결과 */
#ranks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#ranks li { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 10px; background: rgba(10, 1, 4, .65); border: 1px solid var(--gold-700); font: 20px/1 var(--display); }
#ranks li:first-child { border: 2px solid var(--gold-400); background: linear-gradient(90deg, rgba(255, 207, 74, .28), rgba(10, 1, 4, .65)); font-size: 24px; }
#ranks i { font: 400 24px/1 var(--logo); color: var(--gold-400); width: 26px; font-style: normal; }
#ranks b { flex: 1; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ranks span { color: var(--gold-300); font-family: var(--logo); }
#ranks .me b::after { content: " (나)"; color: var(--muted); font-size: .7em; }
#app[data-host="1"] #waithost, #app[data-host="0"] #again { display: none; }

/* 답 고르기 시트: 폰에서는 키보드 위 화면 전체 */
#sheet { position: fixed; left: 0; right: 0; top: 0; height: var(--vvh); z-index: 5; display: flex; flex-direction: column; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 12px 0;
  background: repeating-linear-gradient(90deg, #22030a 0 22px, #2a040c 22px 44px); }
.sheethead { display: flex; justify-content: space-between; align-items: baseline; }
.sheethead b { font: 22px/1 var(--display); color: var(--gold-400); }
.sheethead span { font: 400 30px/1 var(--logo); color: var(--cream); }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .14); overflow: hidden; flex: none; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffcf4a, #fff3c4); transform-origin: left; }
#sheet.low .bar i { background: #ff5a3c; }
#sheet.low .sheethead span { color: #ff7a5c; }
#sheet.wait #q, #sheet.wait #list { opacity: .35; pointer-events: none; }
#list { list-style: none; margin: 0 -4px; padding: 0 0 max(12px, env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
#list li { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; min-height: 64px; padding: 8px; border-radius: 10px; cursor: pointer; transition: background-color .12s ease-out; }
#list li + li { margin-top: 4px; }
#list .art { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #1a0a02; box-shadow: 0 0 0 1px rgba(255, 243, 196, .08); }
#list .art.none { visibility: hidden; }
#list .txt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
#list li b { font: 18px/1.2 var(--display); font-weight: 400; color: var(--cream); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list li span { font-size: 13px; line-height: 16px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list li:hover { background: rgba(255, 243, 196, .05); }
#list li:active, #list li.first { background: rgba(255, 243, 196, .08); box-shadow: inset 0 0 0 1px rgba(255, 207, 74, .35); }
#list li.none { display: block; min-height: 0; padding: 24px 0; color: var(--muted); cursor: default; text-align: center; }

#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); z-index: 9; padding: 10px 18px; border-radius: 999px; background: rgba(10, 1, 4, .9); border: 2px solid var(--gold-500); color: var(--gold-200); font: 18px/1 var(--display); white-space: nowrap; animation: pop .25s; }
@keyframes pop { from { transform: translateX(-50%) scale(.8); opacity: 0; } }

/* 가로 화면, PC: 무대 왼쪽, 패널 오른쪽 */
@media (min-width: 820px) and (min-aspect-ratio: 5/4) {
  #app { grid-template-rows: 1fr; grid-template-columns: 1fr 390px; }
  #panel { max-height: none; border-top: 0; border-left: 3px solid var(--gold-500); padding: 34px 22px; display: flex; flex-direction: column; justify-content: center; box-shadow: -10px 0 30px rgba(0, 0, 0, .6); }
  #panel::before { left: 4px; top: 0; bottom: 0; right: auto; width: 10px; height: auto; background-size: 10px 20px; background-repeat: repeat-y; }
  #panel > section { width: 100%; }
  #hud { right: 402px; }
  #sheet { left: auto; width: 390px; border-left: 3px solid var(--gold-500); padding-top: 22px; }
  #buzzer { width: 210px; }
  .hint.key { display: block; }
}
@media (prefers-reduced-motion: reduce) { .btn, #buzzer span { transition: none; } #toast { animation: none; } }
