:root {
  --bg: #0f1020; --panel: #1a1c33; --panel2: #23264a; --text: #e8e9ff; --muted: #9195c4;
  --accent: #7c5cff; --accent2: #22d3a6; --danger: #ff5c7a; --gold: #ffd166;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Pretendard', 'Malgun Gothic', system-ui, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
input, textarea, button { font: inherit; color: inherit; }
input, textarea { background: var(--panel2); border: 1px solid #343869; border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { font-family: Consolas, monospace; font-size: 13px; resize: vertical; }
button { background: var(--panel2); border: 1px solid #3a3f78; border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
button:hover { filter: brightness(1.2); }
a.btn { display: inline-block; background: var(--panel2); border: 1px solid #3a3f78; border-radius: 8px; padding: 8px 14px;
  color: var(--text); text-decoration: none; white-space: nowrap; }
a.btn:hover { filter: brightness(1.2); }
.guide-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 4px; }
.guide-row .muted { font-size: 12px; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 700; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .4; cursor: default; }
.row { display: flex; gap: 8px; margin: 10px 0; }
label { display: block; font-size: 14px; margin: 8px 0; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* 홈 */
#home { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.home-card { background: var(--panel); padding: 28px; border-radius: 16px; width: min(460px, 100%); }
.home-card h1 { margin: 0; font-size: 40px; }
.sub { color: var(--muted); margin-top: 4px; }
.lan-info { background: var(--panel2); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.lan-info b { color: var(--accent2); user-select: all; }
.room-list { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow: auto; }
.room-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--panel2); border-radius: 8px; margin-bottom: 6px; cursor: pointer; }
.room-list li.empty { cursor: default; color: var(--muted); justify-content: center; }

/* 방 */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); flex-wrap: wrap; }
.code { color: var(--muted); margin: 0 8px; }
.code b { color: var(--gold); letter-spacing: 2px; }
.badge { padding: 4px 12px; border-radius: 99px; background: var(--panel2); font-weight: 700; }
.vol input { width: 110px; padding: 0; vertical-align: middle; }
.layout { display: grid; grid-template-columns: 220px 1fr 320px; gap: 12px; padding: 12px; height: calc(100vh - 56px); }
.panel { background: var(--panel); border-radius: 12px; padding: 14px; overflow: auto; }
.panel h3 { margin: 0 0 10px; }
.center { display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow: auto; }

.players ol { padding-left: 20px; margin: 0; }
.players li { padding: 4px 0; display: flex; justify-content: space-between; }
.players li .host::after { content: ' 👑'; }
.players li.me { color: var(--accent2); font-weight: 700; }
.kick-btn { padding: 1px 6px; font-size: 11px; border-radius: 6px; opacity: .35; background: transparent; border: 1px solid transparent; }
.players li:hover .kick-btn, .kick-btn.has { opacity: 1; }
.kick-btn.has { border-color: var(--danger); color: var(--danger); }
.kick-btn.on { background: var(--danger); color: #fff; border-color: var(--danger); opacity: 1; }
.team { background: var(--panel2); padding: 10px; border-radius: 8px; margin-bottom: 10px; }
.team b { color: var(--gold); font-size: 20px; }

.filerow { flex-wrap: wrap; margin: 6px 0; }
button.toggle.on { background: var(--accent2); color: #062; border-color: var(--accent2); }
textarea.drag { outline: 2px dashed var(--accent2); }
.mode-pick label { background: var(--panel2); padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; align-items: end; }
.check { display: flex; gap: 6px; align-items: center; }
.check input { width: auto; }

.round-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.timer { flex: 1; height: 10px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
#timerBar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .25s linear; }
.video-wrap { position: relative; aspect-ratio: 16/9; max-height: 45vh; margin: 0 auto; width: 100%; background: #000; border-radius: 10px; overflow: hidden; }
.video-wrap iframe, #ytPlayer { position: absolute; inset: 0; width: 100%; height: 100%; }
/* 덮개: 가릴 때는 즉시(다음 곡 영상이 비치지 않게), 정답 공개 때만 서서히 걷힘 */
.cover { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle, #2b2470, #0b0b1a); z-index: 2; transition: none; }
.cover.off { opacity: 0; pointer-events: none; transition: opacity .5s; }
.pause-overlay { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: rgba(8, 8, 20, .82); backdrop-filter: blur(4px); color: #fff; }
.pause-overlay .pause-icon { font-size: 64px; line-height: 1; animation: pausePulse 1.4s ease-in-out infinite; }
.pause-overlay b { font-size: 24px; }
.pause-overlay span { color: var(--muted); }
@keyframes pausePulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.play-time { color: var(--muted); font-size: 13px; white-space: nowrap; }
#resultTime { font-size: 16px; margin-top: -6px; }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: min(22vh, 140px); font-weight: 900; color: #fff; background: rgba(11, 11, 26, .75);
  text-shadow: 0 0 30px var(--accent); }
.countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .85; } }
#btnPlay { margin-top: 12px; }
.eq { display: flex; gap: 6px; height: 60px; align-items: flex-end; }
.eq i { width: 10px; background: var(--accent2); border-radius: 3px; animation: eq 1s infinite ease-in-out; }
.eq i:nth-child(2) { animation-delay: .2s } .eq i:nth-child(3) { animation-delay: .4s } .eq i:nth-child(4) { animation-delay: .1s } .eq i:nth-child(5) { animation-delay: .3s }
@keyframes eq { 0%,100% { height: 10px } 50% { height: 60px } }

/* 순위 이름표: 그라데이션 닉네임 + 은은한 후광 */
.ntag { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 10px;
  position: relative; isolation: isolate; white-space: nowrap; max-width: 100%; overflow: visible; vertical-align: middle; }
.ntag::before { /* 뒤쪽 후광 */
  content: ''; position: absolute; inset: -2px; border-radius: 12px; z-index: -1;
  background: radial-gradient(ellipse at 50% 50%, var(--halo) 0%, var(--halo) 25%, transparent 75%);
  filter: blur(3px);
  animation: halo 2.4s ease-in-out infinite; }
.ntag .stars { font-size: .95em; letter-spacing: -1px; color: var(--star);
  text-shadow: 0 0 4px var(--star), 0 0 10px var(--star), 0 0 18px var(--halo);
  animation: twinkle 1.6s ease-in-out infinite alternate; }
.ntag .rtitle, .ntag .rname { font-weight: 900; background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  animation: shine 3.2s linear infinite; }
.ntag .rname { overflow: hidden; text-overflow: ellipsis; animation-direction: reverse; }
.ntag .rtitle { filter: drop-shadow(0 0 5px var(--tglow)); }
.ntag .rname  { font-size: 1.08em; letter-spacing: .2px; filter: drop-shadow(0 0 3px var(--nglow)) drop-shadow(0 0 9px var(--nglow)); }

/* 1등: 금별 + 노랑→연두→하늘 칭호 + 보라→핑크 닉네임 */
.ntag.r1 { --star: #ffc93c; --halo: rgba(255, 220, 110, .45); --tglow: rgba(220, 255, 140, .7); --nglow: rgba(255, 210, 120, .85); }
.ntag.r1 .rtitle { background-image: linear-gradient(90deg, #ffe45c, #b6f06a, #5fe3e0, #b6f06a, #ffe45c); }
.ntag.r1 .rname  { background-image: linear-gradient(90deg, #ffe45c, #b6f06a, #5fe3e0, #c86bff, #ff5fb4, #ffe45c); }
/* 2등: 은별 + 은→하늘 칭호 + 파랑→라벤더 닉네임 */
.ntag.r2 { --star: #e3ecf7; --halo: rgba(190, 215, 255, .38); --tglow: rgba(200, 230, 255, .7); --nglow: rgba(130, 170, 255, .7); }
.ntag.r2 .rtitle { background-image: linear-gradient(90deg, #f2f6fb, #a9c9f5, #e6f0ff, #a9c9f5, #f2f6fb); }
.ntag.r2 .rname  { background-image: linear-gradient(90deg, #6fa8ff, #b4a2ff, #63d3ff, #b4a2ff, #6fa8ff); }
/* 3등: 동별 + 주황→살구 칭호 + 코랄→핑크 닉네임 */
.ntag.r3 { --star: #f0a35e; --halo: rgba(240, 160, 90, .38); --tglow: rgba(255, 190, 130, .7); --nglow: rgba(255, 120, 130, .65); }
.ntag.r3 .rtitle { background-image: linear-gradient(90deg, #ffb36b, #ffd8a8, #ff9f5a, #ffd8a8, #ffb36b); }
.ntag.r3 .rname  { background-image: linear-gradient(90deg, #ff8a6b, #ff6fa3, #ffb07a, #ff6fa3, #ff8a6b); }

@keyframes shine { from { background-position: 0% 0; } to { background-position: 300% 0; } }
@keyframes twinkle { from { opacity: .75; transform: scale(.96); } to { opacity: 1; transform: scale(1.06); } }
@keyframes halo { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }
.chat-log .ntag { padding: 0 6px; }
.players li .pname { display: flex; align-items: center; min-width: 0; }
.locked { background: var(--panel2); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); margin: 10px 0; }
.profile { display: flex; gap: 14px; align-items: center; margin-top: 12px; }
.profile-side { flex: 1; }
.avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; background: var(--accent) center/cover no-repeat;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; vertical-align: middle; }
.avatar.big { width: 84px; height: 84px; font-size: 32px; cursor: pointer; border: 3px solid var(--panel2); }
.avatar.mid { width: 44px; height: 44px; font-size: 18px; }
.players li { align-items: center; gap: 8px; }
.players li .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-log .m, .chat-log .correct { display: flex; gap: 6px; align-items: flex-start; }
.chat-log .avatar { width: 22px; height: 22px; font-size: 11px; }
.solver { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
#resultList li { display: flex; align-items: center; gap: 10px; }
select { background: var(--panel2); border: 1px solid #343869; border-radius: 8px; padding: 8px 10px; width: 100%; color: var(--text); font: inherit; }
.question { margin-top: 12px; background: var(--panel2); border-radius: 10px; padding: 12px; text-align: center; font-size: 18px; font-weight: 700; }
.question .sub { display: block; font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 4px; }
.slots { display: flex; gap: 10px; margin-top: 12px; }
.slot { flex: 1; background: var(--panel2); border-radius: 10px; padding: 10px; text-align: center; border: 2px dashed #3a3f78; }
.slot.solved { border: 2px solid var(--accent2); }
.slot .lbl { color: var(--muted); font-size: 13px; }
.slot .ans { font-size: 20px; font-weight: 700; margin-top: 4px; }
.slot .by { font-size: 12px; color: var(--accent2); }
.hints { margin-top: 10px; color: var(--gold); }
.reveal { margin-top: 10px; background: var(--panel2); border-radius: 10px; padding: 12px; }

.chat { display: flex; flex-direction: column; }
.chat-log { flex: 1; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.chat-log .m b { color: var(--accent2); }
.chat-log .system { color: var(--muted); }
.chat-log .correct { color: var(--gold); font-weight: 700; }

#resultList li { font-size: 18px; padding: 4px 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--danger); padding: 10px 18px; border-radius: 10px; z-index: 10; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .chat { height: 50vh; }
  .grid { grid-template-columns: 1fr 1fr; }
}
#timerText { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* 게임 중단 버튼은 일시정지 등 다른 버튼과 떨어뜨려 오른쪽 끝에 */
.stop-btn { margin-left: auto; }

/* 영상 노출 방지
   1) 덮개가 씌워져 있는 동안은 영상 자체도 투명하게 (덮개 그리기가 늦어도 비치지 않게)
   2) 창을 벗어나면(.away) 곧바로 영상을 가림 → 다른 창에 있다 돌아올 때 브라우저가 보여 주는
      '마지막으로 그려 둔 화면'에 영상이 남아 있지 않게 함 (소리는 계속 나옴) */
.video-wrap:has(.cover:not(.off)) iframe,
.video-wrap.away iframe { opacity: 0; }

/* 정답을 어떤 표기로 맞췄는지 [ ] */
.matched { color: var(--gold); font-weight: 700; }

/* 스크램블 텍스트: 아직 맞춰지지 않은 글자는 흐리게, 맞춰진 글자는 원래 색. 끝에 깜빡이는 블록 커서 */
.sc { color: var(--muted); }
.sc.ok { color: inherit; }
.sc-caret { display: inline-block; width: .5em; height: 1em; margin-left: .08em; vertical-align: -.15em;
  background: var(--accent2); border-radius: 2px; }
.join-name { font-weight: 700; color: var(--text); }

/* 구글 로그인 */
.google-box { background: var(--panel2); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.google-box p { margin: 6px 0 0; font-size: 12px; }
.g-user { display: flex; align-items: center; gap: 8px; }
.g-user img { width: 28px; height: 28px; border-radius: 50%; }
.g-user span { flex: 1; }
.g-badge { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 4px;
  border-radius: 4px; background: #fff; color: #4285f4; font-size: 10px; font-weight: 900; flex: none; vertical-align: middle; }
