/* layout: a full-bleed 3D stage; glass docks hug the corners and the transport sits bottom-centre */
:root {
  --ink: #fff6ea;
  --ink-dim: #cdc5e6;
  --ink-faint: #9a93c0;
  --dusk: #1b1a40;
  --dusk-2: #2c2a63;
  --glass: rgba(26, 24, 62, 0.64);
  --glass-strong: rgba(22, 20, 54, 0.86);
  --line: rgba(255, 238, 220, 0.16);
  --peach: #ffb58c;
  --coral: #ff8472;
  --sky: #a6d6ff;
  --gold: #ffdc92;
  --paper: #fff7ea;
  --paper-ink: #2b2550;
  --danger: #ff9d9d;
  --font-display: 'Jua', 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-ui: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --r-panel: 16px;
  --r-ctl: 10px;
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; background: #14132e; color: var(--ink);
  font-family: var(--font-ui); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.tnum { font-variant-numeric: tabular-nums; }

#app { position: fixed; inset: 0; overflow: hidden; }
#stage, #css3d, #gl, #labels { position: absolute; inset: 0; }
#stage { background: #000; }
#css3d { z-index: 0; pointer-events: none; overflow: hidden; }
#css3d > div { pointer-events: none; }
#gl { z-index: 1; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }
#labels { z-index: 2; pointer-events: none; overflow: hidden; }
/* soft vignette, lifted while the film fills the view */
#stage::after { content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; transition: opacity 0.4s;
  background: radial-gradient(ellipse 120% 105% at 50% 46%, transparent 52%, rgba(14, 10, 40, 0.42) 100%); }
body.theater #stage::after { opacity: 0; }
.yt-stage iframe { display: block; border: 0; }

body.theater #gl { pointer-events: none; }
body.theater #css3d, body.theater #css3d > div, body.theater .yt-stage, body.theater .yt-stage iframe { pointer-events: auto; }

/* ── labels that float over avatars */
.tag, .bubble, .emote { position: absolute; left: 0; top: 0; will-change: transform; }
.tag {
  display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px;
  background: rgba(22, 20, 54, 0.6); border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--peach)); flex: none; }
.tag.me { border-color: rgba(255, 220, 146, 0.55); }
.bubble {
  max-width: 240px; padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: var(--paper); color: var(--paper-ink);
  font-size: 14px; line-height: 1.35; box-shadow: 0 6px 18px rgba(10, 8, 40, 0.35); word-break: break-word;
  opacity: 0; transition: opacity 0.25s;
}
.bubble.on { opacity: 1; }
.emote { font-size: 34px; animation: floatUp 2.2s ease-out forwards; filter: drop-shadow(0 4px 8px rgba(10, 8, 40, 0.4)); }
@keyframes floatUp {
  0% { opacity: 0; margin-top: 0; scale: 0.4; }
  15% { opacity: 1; scale: 1.15; }
  30% { scale: 1; }
  100% { opacity: 0; margin-top: -90px; }
}

/* ── shared pieces */
.glass {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-panel);
  backdrop-filter: blur(16px) saturate(1.25); -webkit-backdrop-filter: blur(16px) saturate(1.25);
  box-shadow: 0 10px 34px rgba(8, 6, 30, 0.32);
}
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; flex: none;
  border: 1px solid transparent; border-radius: var(--r-ctl); background: transparent; color: var(--ink);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(255, 240, 220, 0.1); border-color: var(--line); }
.icon-btn[aria-pressed="true"] { background: rgba(255, 181, 140, 0.2); border-color: rgba(255, 181, 140, 0.5); color: var(--gold); }
.icon-btn svg { width: 20px; height: 20px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 240, 220, 0.06); color: var(--ink); white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.pill-btn:hover { background: rgba(255, 240, 220, 0.14); border-color: rgba(255, 238, 220, 0.3); }
.pill-btn svg { width: 16px; height: 16px; }
.field {
  height: 38px; padding: 0 12px; border-radius: var(--r-ctl); border: 1px solid var(--line);
  background: rgba(12, 10, 40, 0.5); color: var(--ink); min-width: 0; user-select: text; -webkit-user-select: text;
}
.field::placeholder { color: var(--ink-faint); }
.field:focus { outline: none; border-color: var(--sky); }
kbd {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 6px;
  background: rgba(255, 240, 220, 0.12); border: 1px solid var(--line); border-bottom-width: 2px;
  font-family: var(--font-ui); font-size: 12px; color: var(--ink);
}

/* ── lobby */
#lobby {
  position: absolute; inset: 0; z-index: 20; display: grid; grid-template-rows: auto 1fr auto; gap: 16px;
  padding: clamp(18px, 3.2vw, 44px); padding-inline: clamp(16px, 3.6vw, 56px);
  background:
    linear-gradient(180deg, rgba(20, 18, 52, 0.62) 0%, rgba(20, 18, 52, 0) 30%),
    linear-gradient(0deg, rgba(20, 18, 52, 0.88) 0%, rgba(20, 18, 52, 0.5) 34%, rgba(20, 18, 52, 0) 62%);
  transition: opacity 0.6s ease, visibility 0.6s; overflow-y: auto;
}
#lobby.leaving { opacity: 0; visibility: hidden; pointer-events: none; }
.lobby-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand h1 {
  margin: 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(44px, 7vw, 92px); line-height: 1;
  letter-spacing: 0.01em; text-wrap: balance; text-shadow: 0 6px 30px rgba(20, 10, 60, 0.5);
}
.brand p { margin: 10px 0 0 4px; color: var(--ink-dim); font-size: clamp(15px, 1.5vw, 19px); }
.keys { display: grid; grid-template-columns: auto auto; gap: 6px 12px; padding: 12px 14px; font-size: 13px; color: var(--ink-dim); align-items: center; }
.keys span.k { display: flex; gap: 3px; justify-content: flex-end; }
.lobby-foot { display: grid; gap: 14px; }
.lobby-foot h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 22px; letter-spacing: 0.01em; }
.pick-row { display: flex; align-items: flex-end; gap: clamp(10px, 1.6vw, 20px); flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 168px)); gap: clamp(8px, 1.2vw, 16px); flex: 1 1 520px; min-width: 0; }
.card {
  position: relative; display: grid; grid-template-rows: 1fr auto; justify-items: center; gap: 4px; padding: 10px 8px 12px;
  border-radius: var(--r-panel); border: 1px solid var(--line); background: rgba(26, 24, 62, 0.5); color: var(--ink);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform 0.2s cubic-bezier(.2, .9, .3, 1.3), border-color 0.2s, background 0.2s;
}
.card img { width: 100%; height: clamp(110px, 21vh, 200px); object-fit: contain; object-position: bottom; pointer-events: none; transition: transform 0.25s cubic-bezier(.2, .9, .3, 1.4); transform-origin: 50% 100%; }
.card .nm { font-family: var(--font-display); font-size: clamp(13px, 1.25vw, 17px); white-space: nowrap; }
.card .st { font-size: 12px; color: var(--ink-faint); min-height: 17px; }
.card:hover:not(:disabled) { transform: translateY(-4px); border-color: rgba(255, 238, 220, 0.4); }
.card:hover:not(:disabled) img { transform: rotate(-2deg) scale(1.03); }
.card[aria-checked="true"] { background: rgba(255, 181, 140, 0.17); border-color: var(--peach); transform: translateY(-8px); }
.card[aria-checked="true"] img { transform: scale(1.06); }
.card[aria-checked="true"] .st { color: var(--gold); }
.card:disabled { opacity: 0.45; cursor: not-allowed; }
.enter-box { display: grid; gap: 8px; justify-items: stretch; flex: 0 1 240px; min-width: 200px; }
.enter-btn {
  height: 58px; padding: 0 26px; border: 0; border-radius: 16px; font-family: var(--font-display); font-size: 24px;
  color: #3a1d2c; background: linear-gradient(180deg, #ffd9a8, var(--peach) 55%, #ff9c7c);
  box-shadow: 0 10px 30px rgba(255, 140, 100, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.15s, filter 0.15s;
}
.enter-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.enter-btn:disabled { filter: grayscale(0.6) brightness(0.75); cursor: default; }
.enter-note { margin: 0; font-size: 13px; color: var(--ink-dim); }

/* ── HUD */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; transition: opacity 0.4s; }
#hud > * { pointer-events: auto; }
.dock { position: absolute; transition: opacity 0.3s, transform 0.3s; }
.top-left { top: 14px; left: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: calc(100% - 200px); }
.top-right { top: 14px; right: 16px; display: flex; gap: 2px; padding: 4px; }
.room { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; }
.room b { font-family: var(--font-display); font-weight: 400; font-size: 19px; letter-spacing: 0.01em; white-space: nowrap; }
.people { display: flex; align-items: center; gap: 6px; }
.person { display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; background: rgba(255, 240, 220, 0.08); font-size: 13px; white-space: nowrap; }
.person img { width: 26px; height: 26px; border-radius: 50%; background: var(--c, #666); object-fit: cover; }
.mode-chip { padding: 5px 11px; border-radius: 999px; font-size: 12px; color: var(--paper-ink); background: var(--gold); }

.bottom {
  left: 16px; right: 16px; bottom: 16px; display: grid; justify-content: center; align-items: end; gap: 14px;
  grid-template-columns: minmax(0, 320px) minmax(0, 760px) minmax(0, 320px); pointer-events: none !important;
}
.bottom > * { pointer-events: auto; min-width: 0; }
.transport { grid-column: 2; padding: 10px 14px 12px; display: grid; gap: 8px; }
.now { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.now .lbl { flex: none; font-size: 12px; color: var(--gold); letter-spacing: 0.04em; }
.now .ttl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now .ttl.idle { color: var(--ink-dim); }
.ctl { display: flex; align-items: center; gap: 8px; }
.seek { position: relative; flex: 1 1 auto; height: 22px; min-width: 60px; cursor: pointer; touch-action: none; }
.seek::before { content: ''; position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 4px; background: rgba(255, 240, 220, 0.18); }
.seek .fill { position: absolute; left: 0; top: 9px; height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--gold), var(--coral)); width: 0; }
.seek .knob { position: absolute; top: 4px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--paper); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); left: 0; scale: 0; transition: scale 0.15s; }
.seek:hover .knob, .seek.drag .knob { scale: 1; }
.seek.off { opacity: 0.4; pointer-events: none; }
.time { font-size: 13px; color: var(--ink-dim); white-space: nowrap; min-width: 92px; text-align: center; }
.vol { display: flex; align-items: center; }
.vol input { width: 76px; accent-color: var(--peach); }
.play-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--paper); color: var(--paper-ink); border: 0; }
.play-btn:hover { background: #fff; border: 0; }
.play-btn svg { width: 22px; height: 22px; }
.kick {
  position: absolute; left: 50%; top: 44%; translate: -50% -50%; z-index: 12; padding: 14px 22px; border-radius: 999px; border: 0;
  font-family: var(--font-display); font-size: 20px; color: #3a1d2c; background: var(--gold); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.chat { grid-column: 1; display: grid; gap: 8px; pointer-events: none !important; }
.chat > * { pointer-events: auto; }
.log { pointer-events: none !important; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; max-height: 190px; overflow: hidden; mask-image: linear-gradient(180deg, transparent, #000 28%); -webkit-mask-image: linear-gradient(180deg, transparent, #000 28%); }
.chat.open .log { overflow-y: auto; mask-image: none; -webkit-mask-image: none; pointer-events: auto !important; }
.msg { align-self: flex-start; max-width: 100%; padding: 4px 10px; border-radius: 10px; background: rgba(22, 20, 54, 0.58); font-size: 14px; word-break: break-word; transition: opacity 0.6s; user-select: text; -webkit-user-select: text; }
.msg b { font-weight: 400; color: var(--c, var(--gold)); margin-right: 6px; }
.msg.sys { color: var(--ink-dim); font-size: 13px; }
.msg.old { opacity: 0; }
.chat.open .msg.old { opacity: 0.85; }
.chat-box { display: grid; gap: 6px; padding: 8px; }
.reacts { display: flex; gap: 2px; }
.reacts button { flex: 1; height: 32px; border: 0; background: transparent; border-radius: 8px; font-size: 18px; transition: background 0.15s, transform 0.15s; }
.reacts button:hover { background: rgba(255, 240, 220, 0.12); transform: translateY(-2px) scale(1.12); }
.chat-box .field { width: 100%; box-sizing: border-box; }

.queue { right: 16px; top: 68px; width: min(320px, calc(100% - 32px)); box-sizing: border-box; padding: 12px; display: grid; gap: 10px; max-height: calc(100% - 210px); grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
.queue[hidden] { display: none; }
.queue h3 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.add { display: flex; gap: 6px; min-width: 0; }
.add .field { flex: 1 1 0; width: 0; }
.add button { flex: none; height: 38px; padding: 0 14px; border-radius: var(--r-ctl); border: 0; background: var(--peach); color: #3a1d2c; font-family: var(--font-display); font-size: 16px; }
.add button:hover { filter: brightness(1.07); }
.items { display: grid; gap: 6px; overflow-y: auto; align-content: start; min-height: 0; }
.item { display: grid; grid-template-columns: 76px 1fr auto; gap: 8px; align-items: center; padding: 5px; border-radius: 10px; background: rgba(255, 240, 220, 0.06); }
.item img { width: 76px; height: 43px; border-radius: 6px; object-fit: cover; background: #0c0a28; }
.item .t { min-width: 0; font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .act { display: flex; }
.item .icon-btn { width: 30px; height: 30px; }
.item .icon-btn svg { width: 16px; height: 16px; }
.empty { color: var(--ink-faint); font-size: 13px; padding: 6px 2px; }

.prompt { left: 50%; bottom: 132px; translate: -50% 0; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; font-size: 14px; pointer-events: none !important; }
.prompt[hidden] { display: none; }

#toasts { position: absolute; z-index: 30; top: 16px; left: 50%; translate: -50% 0; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(520px, calc(100% - 32px)); }
.toast { padding: 9px 16px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; animation: toastIn 0.3s ease-out; text-align: center; }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

.help { position: absolute; z-index: 25; inset: 0; display: grid; place-items: center; background: rgba(12, 10, 36, 0.55); padding: 16px; }
.help[hidden] { display: none; }
.help .sheet { width: min(460px, 100%); padding: 20px 22px; display: grid; gap: 14px; background: var(--glass-strong); }
.help h3 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 24px; }
.help .keys { padding: 0; grid-template-columns: auto 1fr; font-size: 14px; }
.help .keys span.k { justify-content: flex-start; }
.help p { margin: 0; color: var(--ink-dim); font-size: 13px; }

/* theater: the film fills the view above a slim control band */
body.theater .top-left, body.theater .top-right, body.theater .queue, body.theater .prompt { opacity: 0; pointer-events: none !important; }
body.theater #labels { opacity: 0; }
body.theater .bottom { left: 0; right: 0; bottom: 0; grid-template-columns: minmax(0, 1fr); gap: 0; }
body.theater .transport { grid-column: 1; border-radius: 0; border-width: 1px 0 0; background: rgba(12, 11, 34, 0.94); padding: 8px 16px; }
body.theater .transport .now { display: none; }
body.theater .chat { position: absolute; left: 16px; bottom: calc(100% + 10px); width: min(320px, calc(100vw - 32px)); }
body.theater .chat .chat-box { display: none; }
body.theater .chat.open .chat-box { display: grid; }

@media (max-width: 1180px) {
  .bottom { grid-template-columns: minmax(0, 300px) minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keys.lobby-keys { display: none; }
  .bottom { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .transport, .chat { grid-column: 1; }
  .log { max-height: 96px; }
  .vol input { width: 44px; }
  .time { min-width: 0; font-size: 12px; }
  .top-left { right: 16px; max-width: none; }
  .room { flex-wrap: wrap; row-gap: 6px; }
  .person { font-size: 12px; }
  .top-right { top: 112px; }
  .queue { top: 164px; max-height: calc(100% - 440px); }
  .prompt { bottom: 250px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
