* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  background: #0a0508;
  color: #fff;
  font-family: 'Kanit', 'Noto Sans Thai', 'Sarabun', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

body.obs-mode .streamer-panel,
body.obs-mode .show-panel-trigger {
  display: none !important;
}

/* 🎛️ แผงควบคุมสตรีมเมอร์ */
.streamer-panel {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 336px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  background: rgba(18, 18, 28, 0.96);
  border: 2px solid #ffcc00;
  border-radius: 12px;
  padding: 14px;
  z-index: 9999;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.85);
  font-size: 13px;
  backdrop-filter: blur(10px);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.streamer-panel.hidden {
  transform: translateX(380px);
  opacity: 0;
  pointer-events: none;
}

.show-panel-trigger {
  position: fixed;
  top: 14px;
  right: 14px;
  background: #ffcc00;
  color: #000;
  font-weight: bold;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  z-index: 9998;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #3c3c52;
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.panel-title {
  font-weight: 800;
  color: #ffdd44;
  font-size: 14px;
}

.btn-mini {
  background: #3d3d50;
  color: #fff;
  border: none;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
}
.btn-mini:hover {
  background: #55556e;
}

.input-group label,
.control-section > label {
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
  color: #c8c8d8;
}

.input-row {
  display: flex;
  gap: 6px;
}

.input-row input {
  flex: 1;
  min-width: 0;
  background: #282838;
  border: 1px solid #55556e;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  user-select: text;
}
.input-row input:focus {
  border-color: #ffcc00;
}

.btn {
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  transition: filter 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover {
  filter: brightness(1.1);
}
.btn:active {
  transform: scale(0.97);
}

.btn-connect {
  background: #28a745;
  color: #fff;
}

.btn-disconnect {
  background: #dc3545;
  color: #fff;
}

.btn-audio {
  background: #17a2b8;
  color: #fff;
}

.btn-secondary {
  background: #5c5f77;
  color: #fff;
}

.btn-mini-file {
  background: #474761;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  display: inline-block;
}

.btn-obs {
  background: #6f42c1;
  color: #fff;
  flex: 1;
}

.btn-danger {
  background: #9e2a2b;
  color: #fff;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #e4e4ef;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected {
  background: #00ff66;
  box-shadow: 0 0 8px #00ff66;
}
.status-dot.connecting {
  background: #ffbb00;
  box-shadow: 0 0 8px #ffbb00;
  animation: pulseDot 0.9s infinite alternate;
}
.status-dot.disconnected {
  background: #ff3344;
  box-shadow: 0 0 8px #ff3344;
}

@keyframes pulseDot {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #ccc;
  cursor: pointer;
}
.checkbox-row input {
  accent-color: #ffcc00;
  cursor: pointer;
}

.tikfinity-row {
  margin-top: 8px;
}

.sub-status {
  font-size: 11px;
  color: #9be7ff;
  margin-top: 3px;
  min-height: 14px;
}

.webhook-helper {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}

.webhook-helper input {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: #9be7ff;
}

.control-section {
  margin-top: 11px;
  border-top: 1px solid #303044;
  padding-top: 10px;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.audio-controls input[type='range'] {
  flex: 1;
  min-width: 60px;
  accent-color: #ffcc00;
}

.audio-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 7px;
  gap: 6px;
}

.custom-audio-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.audio-file-label {
  margin-top: 4px;
  font-size: 10px;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.test-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.btn-test {
  background: #3b3b4e;
  color: #fff;
  font-size: 11px;
  padding: 6px 4px;
}
.btn-test:hover {
  background: #52526a;
}
.btn-test-wide {
  grid-column: span 2;
}

.panel-footer-actions {
  display: flex;
  gap: 6px;
}

/* 📱 Viewport จัดขนาด 9:16 อัตโนมัติ */
.stage-viewport {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.stage-screen {
  width: 540px;
  height: 960px;
  transform: scale(var(--stage-scale, 1));
  transform-origin: center center;
  flex-shrink: 0;
  background: radial-gradient(circle at 50% 30%, #5a101b, #1a0508 85%);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
  border: 3px solid #ffcc00;
}

/* ป้ายไฟนีออนงานวัดด้านบน */
.carnival-marquee {
  background: linear-gradient(180deg, #ff0033 0%, #99001a 100%);
  padding: 5px 0;
  border-bottom: 3px solid #ffcc00;
  text-align: center;
  position: relative;
  box-shadow: 0 4px 15px rgba(255, 0, 50, 0.4);
  flex-shrink: 0;
}

.bulb-row {
  display: flex;
  justify-content: space-around;
  padding: 2px 10px;
}

.bulb {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  animation: bulbBlink 1s infinite alternate;
}
.bulb:nth-child(odd) {
  animation-delay: 0.5s;
  background: #ffea00;
}
.bulb:nth-child(3n) {
  background: #00f0ff;
}
.bulb:nth-child(4n) {
  background: #ff0077;
}

@keyframes bulbBlink {
  0% { opacity: 0.3; transform: scale(0.85); box-shadow: none; }
  100% { opacity: 1; transform: scale(1.1); box-shadow: 0 0 10px currentColor; }
}

.glow-text {
  font-family: 'Chakra Petch', 'Kanit', sans-serif;
  font-size: 21px;
  font-weight: 800;
  color: #fffb00;
  text-shadow: 0 0 10px #ff3b00, 0 0 20px #ff0055, 2px 2px 0 #000;
  letter-spacing: 1.5px;
}

/* ส่วนหัว: Dashboard (3 กล่อง) */
.header-dashboard {
  display: grid;
  grid-template-columns: 1.08fr 1.24fr 0.98fr;
  gap: 6px;
  padding: 7px 8px;
  background: rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
}

.hud-box {
  background: rgba(30, 10, 15, 0.88);
  border: 1.5px solid #ffaa00;
  border-radius: 8px;
  padding: 6px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hud-title {
  font-weight: 800;
  color: #ffdd44;
  text-align: center;
  border-bottom: 1px solid rgba(255, 200, 0, 0.3);
  padding-bottom: 3px;
  margin-bottom: 4px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* ขวัญใจหน้าฮ้าน */
.leader-item.top-1 {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 215, 0, 0.16);
  border-radius: 6px;
  padding: 3px 5px;
}

.crown-badge {
  font-size: 13px;
  flex-shrink: 0;
}

.leader-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #ffea00;
  object-fit: cover;
  flex-shrink: 0;
  background: #2b1318;
}

.leader-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.leader-name {
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
}

.leader-coins {
  color: #ffd700;
  font-weight: 700;
  font-size: 10px;
}

.sub-leaders {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 9.5px;
  color: #ddd;
}

.leader-item.mini {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.mini-name {
  color: #ffe8a3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* จอเพลงกำลังเล่น */
.queue-badge {
  background: #ff0066;
  color: #fff;
  border-radius: 10px;
  padding: 0 5px;
  font-size: 9px;
}

.now-playing-container {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #000;
  border-radius: 4px;
  padding: 4px 6px;
  overflow: hidden;
  border: 1px solid #44ffaa;
}

.music-note-icon {
  animation: bounceNote 0.8s infinite alternate;
  flex-shrink: 0;
}

@keyframes bounceNote {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px) rotate(10deg); }
}

.marquee-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.now-playing-title {
  display: inline-block;
  color: #55ff99;
  font-weight: 700;
  font-size: 11px;
  padding-left: 100%;
  animation: scrollText 10s linear infinite;
}

@keyframes scrollText {
  0% { transform: translateX(0%); }
  100% { transform: translateX(-100%); }
}

.next-song-pill {
  font-size: 9.5px;
  color: #eee;
  margin-top: 4px;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 5px;
  border-radius: 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-hint {
  margin-top: 3px;
  font-size: 8.5px;
  color: #ffcc66;
  text-align: center;
}

/* กติกา */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rule-badge {
  font-size: 9.5px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.badge-coin {
  background: #ffaa00;
  color: #000;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 8.5px;
}

.badge-free {
  background: #ff3366;
  color: #fff;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 8.5px;
}

/* แถบสถิติไลฟ์สด */
.live-stats-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(18, 4, 8, 0.85);
  border-top: 1px solid rgba(255, 204, 0, 0.25);
  border-bottom: 1px solid rgba(255, 204, 0, 0.35);
  padding: 3px 8px;
  font-size: 10.5px;
  color: #f3d69b;
  flex-shrink: 0;
}

.stat-pill strong {
  color: #fff;
  margin-left: 2px;
}

/* 🎁 ป้ายเตือนของขวัญ Pop-up */
.gift-banner-overlay {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  max-width: 92%;
  background: linear-gradient(90deg, #ff0055, #ffaa00);
  border: 2px solid #fff;
  border-radius: 50px;
  padding: 6px 16px;
  z-index: 900;
  box-shadow: 0 0 25px rgba(255, 200, 0, 0.9);
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

.gift-banner-overlay.show {
  transform: translateX(-50%) scale(1);
}

.gift-banner-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.gift-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #fff;
  object-fit: cover;
  flex-shrink: 0;
  background: #333;
}

.gift-text-wrap {
  min-width: 0;
}

.gift-user-name {
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  text-shadow: 1px 1px 2px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.gift-desc {
  font-size: 14px;
  font-weight: 800;
  color: #ffff00;
  text-shadow: 1px 1px 3px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.gift-sparkles {
  flex-shrink: 0;
}

/* 🎪 ลานเวทีรำวง */
.stage-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 80%, #7d1526 0%, #200408 80%);
}

/* ธงราวงานวัดประดับ */
.stage-flags {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  background-image: repeating-linear-gradient(
    45deg,
    #ff3366 0, #ff3366 15px,
    #ffcc00 15px, #ffcc00 30px,
    #33ccff 30px, #33ccff 45px,
    #33ff66 45px, #33ff66 60px
  );
  clip-path: polygon(
    0 0, 100% 0, 100% 20%,
    90% 100%, 80% 20%, 70% 100%, 60% 20%,
    50% 100%, 40% 20%, 30% 100%, 20% 20%,
    10% 100%, 0 20%
  );
  z-index: 5;
}

/* ลำแสงสปอตไลท์ */
.spotlight {
  position: absolute;
  top: 0;
  width: 150px;
  height: 100%;
  pointer-events: none;
  opacity: 0.25;
  filter: blur(15px);
}

.spotlight-left {
  left: 10%;
  background: linear-gradient(135deg, rgba(255, 255, 100, 0.8), transparent 70%);
  animation: swingLeft 4s infinite alternate ease-in-out;
}

.spotlight-right {
  right: 10%;
  background: linear-gradient(225deg, rgba(255, 100, 200, 0.8), transparent 70%);
  animation: swingRight 4s infinite alternate ease-in-out;
}

@keyframes swingLeft {
  0% { transform: rotate(-15deg); }
  100% { transform: rotate(15deg); }
}
@keyframes swingRight {
  0% { transform: rotate(15deg); }
  100% { transform: rotate(-15deg); }
}

/* พื้นเวทีไม้ */
.stage-floor {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 175px;
  background: linear-gradient(180deg, #d38b47 0%, #87491b 60%, #462208 100%);
  border-top: 4px solid #f6b26b;
  box-shadow: inset 0 10px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.stage-front-board {
  background: #990011;
  color: #ffdd44;
  border: 2px solid #ffcc00;
  padding: 3px 18px;
  border-radius: 8px 8px 0 0;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 2px;
  text-shadow: 1px 1px 2px #000;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.4);
  z-index: 30;
}

/* 💃 ชั้นตัวละครเต้น (Dancers Layer) */
.dancers-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.dancer-node {
  position: absolute;
  transform: translate(-50%, -100%);
  transform-origin: center bottom;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.dancer-node.exiting {
  opacity: 0;
  transform: translate(-50%, -65%) scale(0.45);
}

.dancer-scale {
  transform-origin: center bottom;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  animation: dancerEnter 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes dancerEnter {
  0% { opacity: 0; transform: scale(0.35) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.dancer-sprite {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: ramwongDance var(--dance-duration, 1.1s) infinite ease-in-out alternate;
}

@keyframes ramwongDance {
  0% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(0deg); }
  100% { transform: translateY(0) rotate(4deg); }
}

.dancer-head-wrap {
  position: relative;
  width: 46px;
  height: 46px;
}

.dancer-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid #ffcc00;
  object-fit: cover;
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.6);
  background: #333;
}

.dancer-crown {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 17px;
  animation: crownBob 0.6s infinite alternate;
}

@keyframes crownBob {
  0% { transform: translateX(-50%) translateY(0); }
  100% { transform: translateX(-50%) translateY(-3px); }
}

.dancer-body {
  width: 50px;
  height: 58px;
  margin-top: -6px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

.dancer-tag {
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid #ffaa00;
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 10px;
  color: #fff;
  white-space: nowrap;
  margin-top: 2px;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 3px;
}

.dancer-tag .coin-val {
  color: #ffd700;
  font-weight: 700;
}

/* 4 ระดับตัวละครตามกติกา */
.dancer-node.tier-free .dancer-scale {
  transform: scale(0.86);
}
.dancer-node.tier-free .dancer-avatar {
  border-color: #ff88aa;
  box-shadow: 0 0 8px rgba(255, 136, 170, 0.55);
}
.dancer-node.tier-free .dancer-tag {
  border-color: #ff6699;
}

.dancer-node.tier-basic .dancer-scale {
  transform: scale(1);
}

.dancer-node.tier-mid .dancer-scale {
  transform: scale(1.13);
}
.dancer-node.tier-mid .dancer-avatar {
  border-color: #00e5ff;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.75);
}
.dancer-node.tier-mid .dancer-tag {
  border-color: #00e5ff;
  background: rgba(0, 35, 65, 0.88);
}

.dancer-node.vip .dancer-scale {
  transform: scale(1.28);
}
.dancer-node.vip .dancer-avatar {
  border-color: #ff0077;
  box-shadow: 0 0 18px #ff0077, 0 0 8px #ffd700;
}
.dancer-node.vip .dancer-tag {
  border-color: #ff3388;
  background: rgba(85, 0, 25, 0.9);
}

/* 🎉 เอฟเฟกต์พลุ & หัวใจลอย */
.particles-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 800;
}

.floating-heart {
  position: absolute;
  pointer-events: none;
  font-size: 20px;
  animation: floatUp 2s forwards linear;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  100% { opacity: 0; transform: translateY(-160px) scale(1.4); }
}

/* 💬 แชทด้านล่าง */
.footer-chat-box {
  height: 105px;
  background: rgba(10, 5, 8, 0.94);
  border-top: 2px solid #ffaa00;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  flex-shrink: 0;
}

.chat-ticker-title {
  font-size: 10px;
  color: #ffdd44;
  font-weight: 700;
  margin-bottom: 3px;
}

.chat-list {
  flex: 1;
  overflow-y: hidden;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
}

.chat-bubble {
  font-size: 11px;
  line-height: 1.3;
  color: #eee;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 8px;
  border-radius: 6px;
  animation: fadeInChat 0.25s ease;
  word-break: break-word;
}

.chat-bubble .chat-user {
  color: #ffcc00;
  font-weight: 700;
  margin-right: 5px;
}

.chat-bubble.song-request {
  background: rgba(0, 255, 150, 0.15);
  border-left: 3px solid #00ff99;
  color: #88ffcc;
}

@keyframes fadeInChat {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
