:root {
  --bg-deep: #130b1c;
  --bg-panel: rgb(20 14 34 / 0.86);
  --bg-panel-solid: #1a122b;
  --border-glass: rgb(255 255 255 / 0.14);
  --border-gold: rgb(251 191 36 / 0.45);
  --text-main: #fffbeb;
  --text-muted: #cbd5e1;
  --gold: #fbbf24;
  --gold-bright: #fef08a;
  --mango-green: #22c55e;
  --mango-ripe: #f59e0b;
  --danger: #ef4444;

  --font-sans: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 25% 20%, #2d1838 0%, var(--bg-deep) 70%);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.workspace {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  height: 100dvh;
  padding: 12px 18px;
}

/* OBS Clean Mode */
body.obs-mode {
  background: #000;
}

body.obs-mode .workspace {
  padding: 0;
  gap: 0;
}

body.obs-mode .streamer-dock {
  display: none;
}

/* 9:16 Vertical Stage */
.live-stage {
  position: relative;
  height: min(96dvh, 960px);
  aspect-ratio: 9 / 16;
  max-width: 100vw;
  border-radius: 22px;
  overflow: hidden;
  background: #1a1026;
  border: 1.5px solid var(--border-gold);
  box-shadow:
    0 24px 60px rgb(0 0 0 / 0.72),
    0 0 36px rgb(251 191 36 / 0.12);
  flex-shrink: 0;
  user-select: none;
}

body.obs-mode .live-stage {
  height: 100dvh;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Top HUD */
.stage-hud-top {
  position: absolute;
  inset: 10px 10px auto 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.hud-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgb(16 11 28 / 0.8);
  border: 1px solid var(--border-gold);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fb7185;
  box-shadow: 0 0 8px #fb7185;
}

@media (prefers-reduced-motion: no-preference) {
  .live-dot {
    animation: pulse-dot 1.8s ease-in-out infinite;
  }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; scale: 1; }
  50% { opacity: 0.45; scale: 0.75; }
}

.hud-center-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.match-timer {
  padding: 4px 9px;
  border-radius: 999px;
  background: rgb(16 11 28 / 0.85);
  border: 1px solid var(--border-glass);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 800;
  color: #fff;
}

.fever-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f97316, #dc2626);
  font-size: 10px;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 0 12px rgb(249 115 22 / 0.5);
  opacity: 1;
  transition: display, opacity ease-out;
  transition-duration: 0.25s;
  transition-behavior: allow-discrete;
}

@starting-style {
  .fever-badge { opacity: 0; }
}

.fever-badge:where([hidden], [data-closing]) { opacity: 0; }
.fever-badge[hidden] { display: none; }

.hud-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border-glass);
  background: rgb(18 12 32 / 0.82);
  color: var(--text-main);
  border-radius: 999px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: rgb(42 29 68 / 0.92);
  border-color: var(--border-gold);
}

.icon-btn:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Noise Meter & Garden Stats */
.status-strip {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.noise-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 9px;
  border-radius: 12px;
  background: rgb(16 11 28 / 0.78);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(8px);
}

.noise-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 800;
  color: #fde68a;
}

.chu-bay-state {
  font-weight: 700;
  color: #e2e8f0;
}

.chu-bay-state.is-angry {
  color: #fca5a5;
}

.noise-track {
  height: 7px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.1);
  overflow: hidden;
}

.noise-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22c55e 0%, #facc15 55%, #ef4444 100%);
  transition: width 0.2s ease-out;
}

.garden-stats {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 12px;
  background: rgb(16 11 28 / 0.78);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 700;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}

/* Top 3 Leaderboard */
.mvp-board {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px 9px;
  border-radius: 12px;
  background: rgb(16 11 28 / 0.74);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(8px);
  max-width: 210px;
}

.mvp-header {
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--gold);
}

.mvp-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 10.5px;
}

.mvp-empty {
  color: var(--text-muted);
  font-size: 10px;
}

.mvp-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}

.mvp-rank {
  font-weight: 900;
  color: var(--gold-bright);
  width: 15px;
}

.mvp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mvp-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mvp-pts {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: #fde68a;
  font-size: 10px;
}

/* Live Voice Subtitle Caption */
.voice-caption {
  position: absolute;
  left: 50%;
  top: 19%;
  translate: -50% 0;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgb(14 10 26 / 0.88);
  border: 1px solid var(--border-gold);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
  font-size: 11.5px;
  font-weight: 700;
  color: #fef3c7;
  pointer-events: none;
  opacity: 1;
  scale: 1;
  transition:
    display,
    opacity ease-out,
    scale ease-out;
  transition-duration: 0.24s;
  transition-behavior: allow-discrete;
}

@starting-style {
  .voice-caption {
    opacity: 0;
    scale: 0.9;
  }
}

.voice-caption:where([hidden], [data-closing]) {
  opacity: 0;
  scale: 0.92;
}

.voice-caption[hidden] {
  display: none;
}

/* Cinematic Ultimate Banner */
.ultimate-banner {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 38%;
  translate: 0 -50%;
  z-index: 16;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgb(66 24 16 / 0.95), rgb(34 17 58 / 0.95));
  border: 2px solid var(--gold);
  box-shadow:
    0 18px 42px rgb(0 0 0 / 0.65),
    0 0 32px rgb(251 191 36 / 0.4);
  pointer-events: none;
  opacity: 1;
  scale: 1;
  transition:
    display,
    opacity ease-out,
    scale cubic-bezier(0.2, 1.25, 0.4, 1);
  transition-duration: 0.32s;
  transition-behavior: allow-discrete;
}

@starting-style {
  .ultimate-banner {
    opacity: 0;
    scale: 0.78;
  }
}

.ultimate-banner:where([hidden], [data-closing]) {
  opacity: 0;
  scale: 0.85;
}

.ultimate-banner[hidden] {
  display: none;
}

.ult-tag {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin-bottom: 4px;
}

.ult-main-text {
  font-size: 19px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 12px rgb(251 191 36 / 0.55);
}

.ult-sub-text {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-bright);
}

/* Flanking Gift Rails along left & right of the Mango Tree */
.gift-rail {
  position: absolute;
  top: 29%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 84px;
  pointer-events: none;
}

.gift-rail-left {
  left: 7px;
}

.gift-rail-right {
  right: 7px;
  top: 31%;
}

.rail-card {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 11px;
  background: rgb(14 10 26 / 0.78);
  border: 1px solid rgb(255 255 255 / 0.14);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.35);
}

.rail-card.is-hot {
  background: rgb(52 22 14 / 0.84);
  border-color: rgb(249 115 22 / 0.55);
}

.rail-card.is-ult {
  background: linear-gradient(135deg, rgb(66 32 10 / 0.9), rgb(44 16 48 / 0.9));
  border-color: rgb(251 191 36 / 0.7);
}

.rail-ico {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.rail-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.rail-coins {
  font-size: 9px;
  font-weight: 900;
  color: var(--gold-bright);
}

.rail-name {
  font-size: 8.5px;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Victory Overlay */
.victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgb(10 6 18 / 0.8);
  backdrop-filter: blur(8px);
  opacity: 1;
  scale: 1;
  transition:
    display,
    opacity ease-out,
    scale ease-out;
  transition-duration: 0.35s;
  transition-behavior: allow-discrete;
}

@starting-style {
  .victory-overlay {
    opacity: 0;
    scale: 0.94;
  }
}

.victory-overlay:where([hidden], [data-closing]) {
  opacity: 0;
  scale: 0.94;
}

.victory-overlay[hidden] {
  display: none;
}

.victory-card {
  width: 100%;
  padding: 20px 18px;
  border-radius: 20px;
  background: linear-gradient(160deg, #27183d 0%, #140d24 100%);
  border: 1.5px solid var(--gold);
  box-shadow: 0 24px 55px rgb(0 0 0 / 0.75);
  text-align: center;
}

.victory-crown {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--gold);
}

.victory-winner {
  margin: 8px 0 4px;
  font-size: 26px;
  font-weight: 900;
  color: var(--gold-bright);
}

.victory-sub {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.victory-podium {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.podium-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  border-radius: 10px;
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.1);
  font-size: 12.5px;
  font-weight: 700;
}

.podium-row.is-first {
  background: rgb(251 191 36 / 0.15);
  border-color: rgb(251 191 36 / 0.45);
}

.victory-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Streamer Control Dock */
.streamer-dock {
  width: min(445px, 44vw);
  max-height: 96dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 13px;
  border-radius: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(12px);
}

.dock-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.dock-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
}

.dock-sub {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgb(255 255 255 / 0.12);
  border: 1px solid rgb(255 255 255 / 0.2);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
}

.ws-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.08);
  border: 1px solid var(--border-glass);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.ws-status-pill[data-state="connected"] .ws-dot {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.ws-status-pill[data-state="connecting"] .ws-dot {
  background: #fbbf24;
}

.dock-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 11px;
  border-radius: 14px;
  background: rgb(255 255 255 / 0.04);
  border: 1px solid rgb(255 255 255 / 0.09);
}

.card-heading {
  margin: 0;
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
}

.control-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tiktok-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
}

.dock-status-msg {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-primary,
.btn-secondary,
.btn-accent,
.btn-toggle,
.btn-danger,
.gift-test-btn {
  appearance: none;
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  padding: 7px 11px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  background: rgb(255 255 255 / 0.08);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover,
.gift-test-btn:hover {
  background: rgb(255 255 255 / 0.15);
}

.btn-primary {
  background: linear-gradient(135deg, #fbbf24, #d97706);
  border-color: #fde047;
  color: #140d1d;
  font-weight: 800;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #fde047, #f59e0b);
}

.btn-accent {
  background: linear-gradient(135deg, #f97316, #dc2626);
  border-color: #fb923c;
  color: #fff;
}

.btn-toggle {
  flex: 1;
}

.btn-toggle.is-on {
  background: rgb(34 197 94 / 0.18);
  border-color: rgb(34 197 94 / 0.55);
  color: #86efac;
}

.btn-danger {
  background: rgb(239 68 68 / 0.18);
  border-color: rgb(239 68 68 / 0.45);
  color: #fca5a5;
}

.range-field,
.select-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.range-field strong {
  color: var(--text-main);
}

input[type="range"] {
  accent-color: var(--gold);
  cursor: pointer;
}

input[type="text"],
input[type="url"],
select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-glass);
  background: rgb(10 6 18 / 0.85);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
}

.sim-form {
  display: grid;
  grid-template-columns: 0.9fr 1.25fr auto;
  gap: 6px;
}

.quick-gift-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.gift-test-btn {
  text-align: left;
  font-size: 11.5px;
  padding: 7px 9px;
}

.gift-test-btn.is-hot {
  background: rgb(249 115 22 / 0.16);
  border-color: rgb(249 115 22 / 0.45);
  color: #fed7aa;
}

.gift-test-btn.is-ult {
  background: rgb(251 191 36 / 0.2);
  border-color: rgb(251 191 36 / 0.6);
  color: #fef08a;
}

.dock-note p {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-muted);
}

.dock-note code {
  color: var(--gold-bright);
  background: rgb(255 255 255 / 0.1);
  padding: 1px 5px;
  border-radius: 5px;
}

/* Native Modal Dialog */
dialog {
  padding: 0;
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  background: var(--bg-panel-solid);
  color: var(--text-main);
  width: min(510px, 92vw);
  max-height: 88dvh;
  box-shadow: 0 28px 65px rgb(0 0 0 / 0.8);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgb(8 4 14 / 0.74);
  backdrop-filter: blur(6px);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-glass);
}

.dialog-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.dialog-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-heading {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold-bright);
}

.setting-desc {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.ws-connect-row {
  display: flex;
  gap: 8px;
}

.ws-dialog-status {
  font-size: 12px;
  color: var(--text-muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border-glass);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .ultimate-banner,
  .victory-overlay,
  .voice-caption,
  .feed-item {
    transition-duration: 0.1s;
    scale: none;
    translate: none;
  }

  @starting-style {
    .ultimate-banner,
    .victory-overlay,
    .voice-caption,
    .feed-item {
      scale: none;
      translate: none;
    }
  }

  .ultimate-banner:where([hidden], [data-closing]),
  .victory-overlay:where([hidden], [data-closing]),
  .voice-caption:where([hidden], [data-closing]),
  .feed-item:where([hidden], [data-closing]) {
    scale: none;
    translate: none;
  }
}

@media (max-width: 920px) {
  html,
  body {
    overflow: auto;
  }

  .workspace {
    flex-direction: column;
    height: auto;
  }

  .live-stage {
    height: auto;
    width: min(460px, 95vw);
  }

  .streamer-dock {
    width: min(460px, 95vw);
    max-height: none;
  }
}
