:root {
  --bg: #050407;
  --panel: rgba(16, 12, 20, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f4eee8;
  --muted: #a99fae;
  --accent: #ff4d5e;
  --accent-2: #ffb347;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: filter 0.15s, transform 0.1s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: scale(0.97); }
button.ghost { background: rgba(255, 255, 255, 0.08); font-weight: 500; }

input {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
input:focus { border-color: var(--accent-2); }

/* ---------- 3D 무대 ---------- */
#stage, #stage > * { position: fixed; inset: 0; }
#gl { z-index: 1; }
#css { z-index: 0; }

#screen {
  width: 1920px;
  height: 1080px;
  background: #000;
  position: relative;
  overflow: hidden;
}
#yt-mount, #yt-mount iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#screen-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 28px;
  background: radial-gradient(ellipse at center, #1c1630 0%, #07060c 70%);
}
#screen.has-video #screen-idle { display: none; }
.idle-title {
  font-size: 116px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.idle-sub { font-size: 54px; line-height: 1.5; color: #d9d0e6; }
.idle-error { font-size: 44px; color: #ffb3b3; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud > * { pointer-events: auto; }
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#room-box {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
}
.room-label { font-size: 13px; }
#room-title { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
#copy-link, #gfx-toggle, #leave-btn { padding: 6px 10px; font-size: 13px; white-space: nowrap; }

#url-form {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 560px));
  display: flex;
  gap: 6px;
  padding: 6px;
}
#url-form input { flex: 1; min-width: 0; }

#people {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 10px 14px;
  min-width: 150px;
  max-height: 40vh;
  overflow: auto;
}
#people-count { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
#people-list { list-style: none; margin: 0; padding: 0; font-size: 13px; display: grid; gap: 4px; }
#people-list li { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
#people-list .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#people-list .me { color: var(--muted); }
#people-list .crown { font-size: 12px; }
#people-list .kick { margin-left: auto; padding: 2px 8px; font-size: 11px; }
#max-form { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
#max-input { width: 54px; padding: 4px 6px; font-size: 13px; color: var(--text); text-align: center; }
#max-form button { padding: 4px 8px; font-size: 12px; }
.create-row { display: flex; gap: 6px; }
.create-row #create-title { flex: 1; min-width: 0; }
.card .max-field { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); flex: none; }
.max-field input { width: 64px; text-align: center; color: var(--text); }
#pvp-toggle { width: 100%; padding: 4px 10px; font-size: 12px; margin-bottom: 8px; white-space: nowrap; }
#pvp-toggle:disabled { opacity: 0.85; cursor: default; }

/* ---------- 싸움: 체력바, 맞았을 때 빨간 테두리, 쓰러짐 화면, 폰 버튼 */
#hp {
  position: absolute;
  top: 62px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  pointer-events: none !important;
}
.hp-track { width: 110px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#hp-fill { height: 100%; width: 100%; background: #5be37d; transition: width 0.2s, background 0.2s; }
#hurt {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 0, 0, 0.55));
}
#hurt.on { animation: hurt 0.45s ease-out; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }
#ko {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(40, 0, 0, 0.3), rgba(15, 0, 0, 0.82));
}
.ko-title { font-size: 48px; font-weight: 800; color: #ff6b6b; text-shadow: 0 4px 24px #000; }
.ko-sub { font-size: 16px; }
#kicked { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(5, 4, 7, 0.88); }
#crosshair.hit { display: block; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: #ff4d5e; }
#action-buttons { position: absolute; right: 16px; bottom: 150px; display: none; flex-direction: column; gap: 10px; }
body.touch #action-buttons { display: flex; }
#action-buttons button {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 0;
  font-size: 24px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  touch-action: none;
}

#player-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(700px, calc(100vw - 28px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}
#play-toggle { width: 42px; height: 42px; border-radius: 50%; padding: 0; font-size: 16px; flex: none; }
.pb-main { flex: 1; min-width: 0; }
#now-playing { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
#now-playing b { color: var(--text); font-weight: 600; }
.pb-row { display: flex; align-items: center; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
#seek { flex: 1; }
#volume { width: 80px; }
#mute-toggle { padding: 6px 8px; }
#cc-toggle { padding: 6px 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.04em; color: var(--muted); border: 1px solid rgba(255, 255, 255, 0.14); }
#cc-toggle[aria-pressed="true"] { background: #f4eee8; color: #120e14; border-color: #f4eee8; }
input[type="range"] { accent-color: var(--accent); padding: 0; border: 0; background: none; height: 18px; }
/* 내 영상이 아니고 방장도 아니면 재생·탐색은 잠김 (넘기기 투표만 가능) */
#player-bar.locked #play-toggle { background: rgba(255, 255, 255, 0.12); color: var(--muted); }
#player-bar.locked #seek { opacity: 0.45; }
#player-bar button:disabled { opacity: 0.4; cursor: default; }
#skip-btn, #queue-btn { padding: 6px 9px; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#skip-btn[aria-pressed="true"] { background: var(--accent-2); color: #1a1206; }
#queue-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.2); }

#queue-panel {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px));
  max-height: 46vh;
  overflow: auto;
  padding: 12px 14px;
  font-size: 13.5px;
  z-index: 3;
  background: rgba(18, 13, 22, 0.97);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
}
.qp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.qp-hint { color: var(--muted); font-size: 12px; }
#qp-now { color: var(--muted); padding: 6px 0 8px; border-bottom: 1px solid var(--panel-border); }
#qp-now b { color: var(--text); }
#qp-list { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 6px; }
#qp-list li { padding-left: 2px; }
#qp-list .row { display: flex; align-items: center; gap: 8px; }
#qp-list .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#qp-list .by { color: var(--muted); font-size: 12px; white-space: nowrap; }
#qp-list button { padding: 2px 8px; font-size: 12px; }
#qp-list .empty { list-style: none; margin-left: -22px; color: var(--muted); }

#chat {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: min(340px, calc(100vw - 28px));
}
#chat-log {
  max-height: 34vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 2px;
  font-size: 14px;
  text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.8);
  mask-image: linear-gradient(to bottom, transparent, #000 30px);
}
#chat-log .sys { color: var(--muted); font-size: 12.5px; }
#chat-log .name { font-weight: 700; margin-right: 6px; }
#chat-log .msg { word-break: break-word; }
#chat-input { flex: 1; min-width: 0; background: var(--panel); backdrop-filter: blur(10px); }
#chat-form { display: flex; gap: 6px; }
#chat-toggle { flex: none; padding: 6px 9px; }
#chat-toggle[aria-pressed="true"] { background: var(--accent-2); color: #1a1206; }
body.chat-hidden #chat-log { display: none; }

#help {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}
#help .reactions { font-size: 15px; letter-spacing: 4px; margin-top: 2px; }
kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font: 600 11.5px var(--font);
}

#lock-hint {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 14px;
  pointer-events: none !important;
  animation: pulse 2.4s ease-in-out infinite;
}
body.locked #lock-hint, body.touch #lock-hint { display: none; }
@keyframes pulse { 50% { opacity: 0.55; } }

#crosshair {
  position: fixed;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  display: none;
  pointer-events: none;
}
body.locked #crosshair { display: block; }

#unmute-btn {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-2);
  color: #1a1206;
}

#self-reactions { position: absolute; left: 50%; bottom: 90px; width: 0; height: 0; pointer-events: none !important; }
#self-reactions span {
  position: absolute;
  font-size: 40px;
  transform: translateX(-50%);
  animation: floatUp 1.6s ease-out forwards;
}
@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 0) scale(0.6); }
  20% { transform: translate(-50%, -20px) scale(1.1); }
  to { opacity: 0; transform: translate(-50%, -140px) scale(1); }
}

/* ---------- 입장 화면 ---------- */
#join {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 4, 7, 0.35), rgba(5, 4, 7, 0.85));
}
#join.hidden { display: none; }
.card {
  width: min(460px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: 20px;
  background: rgba(18, 13, 22, 0.86);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.marquee {
  justify-self: start;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--accent-2);
  border: 1px solid currentColor;
  border-radius: 6px;
  padding: 3px 8px;
}
.card h1 { margin: 0; font-size: 30px; letter-spacing: -0.01em; }
.lead { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.card label input { color: var(--text); font-size: 15px; }
.card section, #create-form { display: grid; gap: 8px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; }
.sec-title { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; color: var(--accent-2); }
button.small { padding: 4px 10px; font-size: 12px; }
button.big { padding: 12px; font-size: 15.5px; }
#lobby button:disabled { opacity: 0.55; cursor: wait; }
#join-error { margin: 0; min-height: 1em; color: #ff8a8a; font-size: 13px; }

#room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 32vh; overflow-y: auto; }
#room-list .empty { color: var(--muted); font-size: 13px; padding: 10px 2px; line-height: 1.5; }
#room-list button.room {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  font-weight: 500;
}
#room-list button.room:hover { background: rgba(255, 255, 255, 0.1); }
#room-list button.room:disabled { opacity: 0.5; cursor: not-allowed; }
#room-list .r-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#room-list .r-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#room-list .r-now { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#create-form input { color: var(--text); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg label { display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
.seg small { display: block; font-size: 11.5px; font-weight: 400; opacity: 0.8; margin-top: 2px; }
.seg input:checked + span { border-color: var(--accent-2); color: var(--text); background: rgba(255, 179, 71, 0.1); }
.seg input:focus-visible + span { outline: 2px solid var(--accent-2); }

#code-join summary { cursor: pointer; font-size: 13px; color: var(--muted); }
#code-form { display: flex; gap: 6px; margin-top: 8px; }
#code-form input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; }

#toast {
  position: fixed;
  z-index: 20;
  top: 74px;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 16, 24, 0.92);
  border: 1px solid var(--panel-border);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 터치 ---------- */
#touch-stick {
  position: absolute;
  left: 24px;
  bottom: 120px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  touch-action: none;
}
#touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}

/* 하단 세 패널(채팅·재생바·도움말)이 한 줄에 안 들어가면 채팅/도움말을 재생바 위로 올림 */
@media (max-width: 1300px) {
  #chat, #help { bottom: 84px; }
  #chat-log { max-height: 26vh; }
}

@media (max-width: 900px) {
  #help { display: none; }
  #gfx-toggle .gfx-label { display: none; }
  #room-title { max-width: 90px; }
  #copy-link, #leave-btn { font-size: 0; }
  #copy-link::after { content: "🔗"; font-size: 13px; }
  #leave-btn::after { content: "🚪"; font-size: 13px; }
  #room-box { gap: 6px; padding-left: 10px; }
  #volume { display: none; }
  #player-bar { gap: 6px; padding: 8px; }
  #queue-panel { bottom: 76px; }
  .card { padding: 22px 18px; }
  #url-form { top: 62px; width: calc(100vw - 28px); }
  #people { top: 14px; min-width: 0; padding: 8px 12px; }
  #people-list { display: none; }
  #people-count { margin: 0; }
  #chat { bottom: 84px; width: min(300px, calc(100vw - 28px)); }
  #chat-log { max-height: 22vh; }
  #touch-stick { bottom: auto; top: 50%; }
  #hp { top: 112px; }
  #unmute-btn { top: 116px; }
}
