:root {
  --navy: #0f1729; --navy-2: #1b2a55;
  --cream: #fff8f0; --cream-2: #ffeedd; --sand: #ffd59e; --coral: #ff7a59; --coral-d: #e2553a;
  --teal: #0f766e; --teal-l: #2dd4bf; --ink: #2b1d1a; --muted: #8a7468;
  --line: #f0d9c4; --red: #dc2626; --green: #16a34a;
  --r: 18px; --shadow: 0 10px 30px rgba(15, 23, 41, .25);
  --head: "Baloo 2", system-ui, sans-serif; --body: "Be Vietnam Pro", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background: var(--navy); color: var(--ink); font: 15px/1.45 var(--body);
}
input, textarea, select, .chat-log, .dlg { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, strong.title { font-family: var(--head); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.small-gap { gap: 6px; } .row.center { justify-content: center; } .row.end { justify-content: flex-end; }
.card { background: var(--cream); border-radius: var(--r); box-shadow: var(--shadow); }
.glass { background: rgba(255, 248, 240, .92); backdrop-filter: blur(8px); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.hint.err { color: var(--red); }
.badge { background: var(--sand); color: #7c2d12; border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 700; }
.center { text-align: center; }

/* ───────── controls ───────── */
.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: #fff; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 14px;
  padding: 7px 14px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: transform .06s, background .15s;
}
.btn:hover { background: var(--cream-2); }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--coral); border-color: var(--coral-d); color: #fff; }
.btn.primary:hover { background: #ff8c6e; }
.btn.teal { background: var(--teal); border-color: #0b5c56; color: #fff; }
.btn.danger { color: var(--red); }
.btn.on { background: var(--teal); border-color: #0b5c56; color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 10px; border-bottom-width: 3px; }
.btn.xl { width: 100%; padding: 14px 18px; font-size: 18px; font-family: var(--head); }
.btn.xl small { font: 500 12px var(--body); opacity: .8; }
.btn.link { background: none; border: 0; color: var(--teal); padding: 4px; font-weight: 600; }
.btn.icon { padding: 6px 10px; min-width: 40px; }
.btn.round { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 20px; }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }

input, select {
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
  padding: 9px 12px; min-width: 0; outline: none;
}
input:focus { border-color: var(--coral); }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }

.screen { display: none; position: fixed; inset: 0; }
.screen.active { display: block; }

/* ───────── auth ───────── */
#s-auth, #s-creator { background: linear-gradient(180deg, #1b2a55 0%, #6b3f7a 45%, #ff8a65 78%, #ffd59e 100%); overflow: auto; }
.auth-bg { position: absolute; inset: 0; overflow: hidden; }
.auth-bg .sun {
  position: absolute; left: 50%; bottom: 14%; width: 360px; height: 360px; margin-left: -180px;
  border-radius: 50%; background: radial-gradient(circle, #fff1c1 0%, #ffb37a 45%, transparent 70%);
}
.auth-bg .glow {
  position: absolute; inset: 0;
  background: radial-gradient(600px 320px at 20% 10%, rgba(255,122,89,.35), transparent 60%),
              radial-gradient(600px 320px at 85% 25%, rgba(45,212,191,.22), transparent 60%);
}
.auth-bg .skyline {
  position: absolute; left: 0; right: 0; bottom: 0; height: 22%;
  background: repeating-linear-gradient(90deg, #1a2342 0 60px, #222c50 60px 95px, #1a2342 95px 150px, #151d38 150px 210px);
  clip-path: polygon(0 40%, 5% 40%, 5% 10%, 11% 10%, 11% 35%, 18% 35%, 18% 0, 24% 0, 24% 30%, 31% 30%, 31% 15%, 38% 15%, 38% 45%, 46% 45%, 46% 5%, 52% 5%, 52% 30%, 60% 30%, 60% 12%, 67% 12%, 67% 40%, 74% 40%, 74% 2%, 80% 2%, 80% 28%, 88% 28%, 88% 10%, 94% 10%, 94% 35%, 100% 35%, 100% 100%, 0 100%);
}
.auth-wrap { position: relative; max-width: 440px; margin: 7vh auto 40px; padding: 16px; text-align: center; }
.logo {
  margin: 0; font: 800 72px/1 var(--head); color: #fff7ed; letter-spacing: -1px;
  text-shadow: 0 4px 0 #e2553a, 0 10px 30px rgba(0,0,0,.35);
}
.logo span { color: var(--sand); }
.tagline { color: #fff1e6; font-size: 16px; margin: 10px 0 22px; text-shadow: 0 1px 6px rgba(0,0,0,.4); }
.auth-card {
  background: var(--cream); border-radius: 22px; padding: 20px; display: grid; gap: 12px;
  box-shadow: var(--shadow); text-align: left;
}
.auth-card h2 { margin: 0; text-align: center; }
.form-error { color: var(--red); margin: 0; min-height: 1.2em; font-size: 13px; }
.lang-btn { position: absolute; top: 14px; right: 14px; }

/* ───────── creator ───────── */
.creator { display: flex; gap: 16px; height: 100%; padding: 16px; }
.creator-stage { flex: 1; position: relative; border-radius: 24px; overflow: hidden; background: linear-gradient(180deg, #2a1f4a, #6d3d63); }
#creator-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.creator-stage .hint { position: absolute; bottom: 56px; left: 0; right: 0; text-align: center; color: #ffe9d6; }
.creator-stage .row { position: absolute; bottom: 12px; left: 0; right: 0; }
.creator-panel { width: 380px; max-width: 46vw; padding: 16px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.creator-panel h2 { margin: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font-weight: 600; font-size: 13px;
}
.tabs button.active { background: var(--coral); border-color: var(--coral-d); color: #fff; }
.cr-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.cr-opt {
  aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--line); cursor: pointer;
  display: grid; place-items: center; font-size: 22px; background: #fff;
}
.cr-opt.active { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,122,89,.25); }
.cr-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.cr-swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.cr-swatch.active { box-shadow: 0 0 0 3px var(--coral); }

/* ───────── game stage ───────── */
#s-game { background: #05070d; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#stage-host { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
#yt-frame {
  position: absolute; top: 0; left: 0; transform-origin: 0 0; background: #000;
  border-radius: 4px; overflow: hidden; box-shadow: 0 0 60px rgba(255,122,89,.25);
  opacity: 0; transition: opacity .3s;
}
#yt-frame.on { opacity: 1; }
#yt-frame iframe { width: 100%; height: 100%; border: 0; display: block; pointer-events: none; }

.nametag {
  display: flex; align-items: center; gap: 4px; transform: translateY(-4px);
  background: rgba(15,23,41,.72); color: #fff; border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 600; white-space: nowrap; backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.16);
}
.nametag.clickable { cursor: pointer; pointer-events: auto; }
.nametag.me { background: rgba(255,122,89,.9); }
.nametag .mic { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.28); }
.nametag.mic-on .mic { background: #34d399; box-shadow: 0 0 8px #34d399; animation: pulse 1s infinite; }
.nametag.tag-gold { border-color: #ffd700; color: #ffe9a3; }
.nametag.tag-neon { border-color: #22d3ee; color: #a5f3fc; text-shadow: 0 0 6px #22d3ee; }
@keyframes pulse { 50% { opacity: .45; } }

/* HUD */
.hud-top {
  position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between;
  align-items: flex-start; gap: 10px; z-index: 4; pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-left { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; }
.hud-left strong { font-family: var(--head); font-size: 17px; }
.hud-right { display: flex; align-items: center; gap: 8px; position: relative; }
.coins { padding: 7px 14px; border-radius: 999px; font-weight: 700; }
.coins.bump { animation: bump .4s; }
@keyframes bump { 50% { transform: scale(1.18); background: var(--sand); } }
.menu-btn { font-size: 18px; }
.menu-sheet {
  position: absolute; top: 52px; right: 0; background: var(--cream); border-radius: 18px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); z-index: 6; min-width: 220px;
}
.menu-sheet .row { justify-content: flex-start; }
.menu-sheet .btn { flex: 1; }

/* room panel */
.room-panel {
  position: absolute; top: 64px; right: 10px; bottom: 96px; width: 336px; z-index: 4;
  background: rgba(255,248,240,.94); backdrop-filter: blur(10px); border-radius: 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s, opacity .25s;
}
.room-panel.collapsed { transform: translateX(calc(100% - 46px)); }
.room-panel.collapsed .panel-content { opacity: 0; pointer-events: none; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head strong { font-family: var(--head); }
.panel-mini { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-toggle { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.panel-content { padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; overflow: auto; transition: opacity .2s; }
.panel-content h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.panel-content section { display: flex; flex-direction: column; }
.panel-content .grow { flex: 1; min-height: 90px; }

.np { display: flex; gap: 10px; align-items: center; }
.np.empty { color: var(--muted); font-size: 13px; }
.np img { width: 62px; height: 44px; object-fit: cover; border-radius: 8px; background: #000; }
.np .title { font-weight: 700; font-size: 13px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.np .who { font-size: 12px; color: var(--muted); }
.progress { height: 5px; background: var(--cream-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--coral), var(--sand)); transition: width .4s linear; }
.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.queue li { display: flex; align-items: center; gap: 6px; font-size: 13px; background: #fff; border-radius: 10px; padding: 6px 8px; }
.queue li > div { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .who { color: var(--muted); font-size: 11px; }
.queue .acts { display: flex; gap: 4px; }
.queue .acts button { padding: 2px 6px; font-size: 11px; }

/* center stack */
.center-stack {
  position: absolute; left: 50%; bottom: 132px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 3; pointer-events: none;
}
.center-stack > * { pointer-events: auto; }
.prompt {
  background: rgba(15,23,41,.82); color: #fff; border-radius: 999px; padding: 8px 16px;
  font-size: 14px; backdrop-filter: blur(6px); cursor: pointer; border: 1px solid rgba(255,255,255,.18);
}
.prompt b {
  background: #fff; color: var(--navy); border-radius: 6px; padding: 1px 7px; margin-right: 8px;
  font-family: var(--head);
}
.mic-banner {
  background: var(--coral); color: #fff; border: 0; border-radius: 999px; padding: 10px 20px;
  font-weight: 700; cursor: pointer; box-shadow: 0 8px 24px rgba(255,122,89,.4); animation: bob 2s infinite;
}
@keyframes bob { 50% { transform: translateY(-4px); } }
.unmute {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8; font-size: 16px;
}

/* chat */
.chat-log {
  position: absolute; left: 10px; bottom: 172px; width: min(360px, 46vw); max-height: 32vh; overflow: hidden;
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; justify-content: flex-end;
  gap: 4px; z-index: 3; pointer-events: none;
}
.chat-log li {
  background: rgba(15,23,41,.62); color: #fff; padding: 5px 10px; border-radius: 12px;
  font-size: 13px; backdrop-filter: blur(4px); animation: fadeUp .25s; word-break: break-word;
}
.chat-log li b { color: var(--sand); }
.chat-log li.sys { background: rgba(15,118,110,.75); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }

/* bottom hud */
.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 12px 12px; z-index: 4; pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.tray { display: flex; flex-direction: column; gap: 6px; }
.tray .row { background: rgba(255,248,240,.9); border-radius: 999px; padding: 4px 6px; backdrop-filter: blur(8px); }
.emo {
  border: 0; background: #fff; border-radius: 50%; width: 34px; height: 34px; font-size: 17px;
  cursor: pointer; box-shadow: 0 2px 0 rgba(0,0,0,.12); transition: transform .08s;
}
.emo:active { transform: scale(.9); }
.tray.on .emo { animation: pop .3s; }
@keyframes pop { 50% { transform: scale(1.15); } }
.chat-form { flex: 1; display: flex; gap: 6px; min-width: 0; }
.chat-form input {
  flex: 1; min-width: 0; background: rgba(255,248,240,.94); border: 0; border-radius: 999px; padding: 10px 16px;
}
.mic-btn {
  display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--line);
  border-bottom-width: 4px; border-radius: 999px; padding: 8px 16px; font-weight: 700; cursor: pointer;
}
.mic-btn.on { background: var(--teal); color: #fff; border-color: #0b5c56; }
.mic-btn .meter { width: 54px; height: 8px; background: rgba(0,0,0,.12); border-radius: 99px; overflow: hidden; }
.mic-btn .meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444); transition: width .1s; }
.touch-pad { display: none; gap: 8px; }

/* joystick */
.joystick {
  position: absolute; left: 22px; bottom: 120px; width: 116px; height: 116px; border-radius: 50%;
  background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.28); display: none;
  z-index: 3; touch-action: none;
}
.joystick i {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: rgba(255,255,255,.75);
}

/* toasts */
.toasts {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%); display: flex;
  flex-direction: column; gap: 8px; z-index: 9; pointer-events: none; align-items: center;
}
.toast {
  background: rgba(15,23,41,.9); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow); animation: fadeUp .2s; max-width: 80vw; text-align: center;
}
.toast.err { background: rgba(220,38,38,.94); }
.toast.ok { background: rgba(22,163,74,.94); }

/* ───────── dialogs ───────── */
.dlg {
  border: 0; border-radius: 22px; padding: 0; width: min(520px, 94vw); max-height: 88vh;
  background: var(--cream); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.45);
  overflow: hidden; display: none; flex-direction: column;
}
.dlg[open] { display: flex; }
.dlg.wide { width: min(760px, 96vw); }
.dlg::backdrop { background: rgba(5,7,13,.62); backdrop-filter: blur(3px); }
.dlg > header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.dlg > header strong { font-family: var(--head); font-size: 18px; }
.dlg > header p { margin: 0; font-size: 12px; }
.dlg-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.dlg-body p { margin: 0; }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plain-list li { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 12px; padding: 8px 12px; }
.plain-list li .grow { flex: 1; }

.genres { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px 0; }
.genres button { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; font-weight: 600; }
.genres button.active { background: var(--teal); border-color: #0b5c56; color: #fff; }
.results { padding: 10px 16px 16px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.res { display: flex; gap: 10px; align-items: center; background: #fff; border-radius: 12px; padding: 8px; }
.res img { width: 76px; height: 44px; object-fit: cover; border-radius: 8px; background: #000; flex: none; }
.res .meta { flex: 1; min-width: 0; }
.res .meta b { display: block; font-size: 13px; font-weight: 600; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.res .meta span { font-size: 11px; color: var(--muted); }
.kiosk #kiosk-form { padding: 10px 16px; }
.kiosk #kiosk-form input { flex: 1; }

.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-item { background: #fff; border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; }
.shop-item .ico { font-size: 28px; }
.shop-item .nm { font-size: 12px; font-weight: 600; line-height: 1.25; }
.shop-item .pr { font-size: 12px; color: var(--muted); }
.shop-item .btn { width: 100%; }
.shop-item.owned { outline: 3px solid var(--teal-l); }

.switches { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: 12px; padding: 10px 14px; }
.switch input { width: 20px; height: 20px; }

.quest { background: #fff; border-radius: 14px; padding: 12px; display: flex; gap: 12px; align-items: center; }
.quest .ico { font-size: 26px; }
.quest .meta { flex: 1; }
.quest .meta b { font-size: 14px; }
.quest .meta p { font-size: 12px; color: var(--muted); margin: 0; }
.quest .bar { height: 6px; background: var(--cream-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.quest .bar i { display: block; height: 100%; background: var(--teal); }

.tabs.nav { padding: 10px 16px 0; }
.wallet { font-weight: 700; color: var(--coral-d); }

/* ───────── responsive ───────── */
@media (max-width: 900px) {
  .creator { flex-direction: column; padding: 8px; }
  .creator-panel { width: auto; max-width: none; max-height: 48vh; }
  .room-panel { width: min(320px, 86vw); bottom: 150px; }
  .chat-log { width: 60vw; max-height: 22vh; bottom: 196px; }
  #controls-hint { display: none; }
}
@media (max-width: 640px) {
  .logo { font-size: 56px; }
  .hud-left strong { font-size: 15px; }
  .hud-left { padding: 6px 10px; }
  .tray { display: none; }
  .tray.on { display: flex; position: absolute; bottom: 76px; left: 12px; }
  .chat-form { display: none; }
  .chat-form.on { display: flex; position: absolute; bottom: 64px; left: 12px; right: 12px; }
  .touch-pad { display: flex; margin-left: auto; }
  .joystick { display: block; }
  .coin { font-size: 13px; }
  .center-stack { bottom: 160px; }
}
@media (pointer: coarse) {
  .joystick { display: block; }
  .touch-pad { display: flex; }
}

/* world labels */
.door-label {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(10, 10, 18, .78); color: #fff; border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px; padding: 5px 12px; font-size: 12px; white-space: nowrap;
  backdrop-filter: blur(6px); transform: translateY(-6px);
}
.door-label b { font-family: var(--head); font-size: 14px; }
.door-label span { color: var(--sand); font-size: 11px; }
.door-label.full { opacity: .5; }

.nametag.bounce { animation: tagBounce .45s; }
@keyframes tagBounce { 50% { transform: translateY(-10px) scale(1.12); } }

#yt-frame.off { opacity: 0; }

/* embedded mode (?embed=1): only the room, no lobby chrome */
body.embed .hud-left,
body.embed .menu-btn,
body.embed .tray-tools,
body.embed .coins { display: none; }
body.embed #menu-sheet { display: none !important; }

/* NPC nametags */
.nametag.bot { opacity: .9; }
.nametag.bot::before { content: "🤖"; font-size: 10px; margin-right: 3px; }


/* chế độ nhúng từ game Office Empire */
body.game-mode .hud-left strong::after {
  content: " · Office Empire";
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
