/* ==========================================================================
   Mod By Barcoll · WebGL Portal Theme System
   Đồng bộ 100% với 6 theme của UiButtonThemeManager trong client_7VNR:
   0: pink_chibi (Mặc định) | 1: pink_pastel | 2: pink_galaxy
   3: ssj_rose | 4: ssj_blue | 5: classic
   ========================================================================== */

:root,
html[data-theme="pink_chibi"] {
  --page-bg-1: #3b102b;
  --page-bg-2: #5b1b42;
  --page-bg-3: #2a0a1e;
  --stage-bg: #14040e;
  --stage-border: rgba(255, 134, 198, 0.42);
  --stage-glow: rgba(255, 79, 154, 0.32);
  --card-bg: rgba(34, 8, 25, 0.86);
  --card-border: rgba(255, 162, 209, 0.46);
  --card-inner-glow: rgba(255, 110, 188, 0.16);
  --bar-bg: linear-gradient(180deg, rgba(84, 22, 58, 0.96), rgba(58, 14, 41, 0.98));
  --bar-border: rgba(255, 146, 204, 0.36);
  --accent-1: #ff6eb8;
  --accent-2: #e12b83;
  --accent-glow: rgba(255, 92, 168, 0.45);
  --btn-secondary-bg: rgba(255, 110, 188, 0.18);
  --btn-secondary-hover: rgba(255, 110, 188, 0.32);
  --btn-secondary-border: rgba(255, 178, 218, 0.42);
  --text-main: #fff5fa;
  --text-muted: #f2c4dc;
  --petal-color: #ffb7dc;
  --bg-image: url("./assets/bg-sakura.jpg");
  --bg-filter: saturate(1.06) brightness(0.92);
  --show-sakura-corners: 1;
}

html[data-theme="pink_pastel"] {
  --page-bg-1: #4d223c;
  --page-bg-2: #6f3557;
  --page-bg-3: #36162a;
  --stage-bg: #1a0b15;
  --stage-border: rgba(255, 196, 224, 0.48);
  --stage-glow: rgba(246, 178, 212, 0.3);
  --card-bg: rgba(54, 22, 42, 0.85);
  --card-border: rgba(255, 206, 232, 0.52);
  --card-inner-glow: rgba(255, 176, 216, 0.18);
  --bar-bg: linear-gradient(180deg, rgba(102, 50, 82, 0.96), rgba(74, 34, 59, 0.98));
  --bar-border: rgba(255, 204, 230, 0.42);
  --accent-1: #ff9ed0;
  --accent-2: #e365a4;
  --accent-glow: rgba(255, 158, 208, 0.44);
  --btn-secondary-bg: rgba(255, 184, 220, 0.2);
  --btn-secondary-hover: rgba(255, 184, 220, 0.34);
  --btn-secondary-border: rgba(255, 214, 236, 0.48);
  --text-main: #fff8fc;
  --text-muted: #f8d8ea;
  --petal-color: #ffd6ec;
  --bg-image: url("./assets/bg-sakura.jpg");
  --bg-filter: saturate(0.86) brightness(1.04) hue-rotate(-6deg);
  --show-sakura-corners: 1;
}

html[data-theme="pink_galaxy"] {
  --page-bg-1: #1e0b3a;
  --page-bg-2: #361463;
  --page-bg-3: #130626;
  --stage-bg: #0c041a;
  --stage-border: rgba(202, 118, 255, 0.46);
  --stage-glow: rgba(182, 76, 255, 0.34);
  --card-bg: rgba(24, 9, 48, 0.86);
  --card-border: rgba(212, 142, 255, 0.46);
  --card-inner-glow: rgba(200, 75, 255, 0.18);
  --bar-bg: linear-gradient(180deg, rgba(50, 19, 92, 0.96), rgba(32, 11, 61, 0.98));
  --bar-border: rgba(202, 118, 255, 0.38);
  --accent-1: #d078ff;
  --accent-2: #9233ea;
  --accent-glow: rgba(196, 86, 255, 0.46);
  --btn-secondary-bg: rgba(192, 108, 255, 0.2);
  --btn-secondary-hover: rgba(192, 108, 255, 0.34);
  --btn-secondary-border: rgba(220, 166, 255, 0.44);
  --text-main: #f9f3ff;
  --text-muted: #dbc4f8;
  --petal-color: #e4a8ff;
  --bg-image: url("./assets/bg-galaxy.jpg");
  --bg-filter: saturate(1.08) brightness(0.95);
  --show-sakura-corners: 1;
}

html[data-theme="ssj_rose"] {
  --page-bg-1: #240515;
  --page-bg-2: #4a0a2a;
  --page-bg-3: #15020c;
  --stage-bg: #0b0106;
  --stage-border: rgba(255, 54, 150, 0.52);
  --stage-glow: rgba(255, 30, 122, 0.4);
  --card-bg: rgba(28, 4, 18, 0.88);
  --card-border: rgba(255, 74, 162, 0.52);
  --card-inner-glow: rgba(255, 30, 122, 0.2);
  --bar-bg: linear-gradient(180deg, rgba(64, 10, 38, 0.97), rgba(40, 5, 24, 0.99));
  --bar-border: rgba(255, 64, 154, 0.42);
  --accent-1: #ff429e;
  --accent-2: #c90f68;
  --accent-glow: rgba(255, 34, 134, 0.52);
  --btn-secondary-bg: rgba(255, 48, 146, 0.2);
  --btn-secondary-hover: rgba(255, 48, 146, 0.34);
  --btn-secondary-border: rgba(255, 118, 184, 0.46);
  --text-main: #fff2f8;
  --text-muted: #f5b4d5;
  --petal-color: #ff6cb3;
  --bg-image: url("./assets/bg-sakura.jpg");
  --bg-filter: saturate(1.32) contrast(1.12) brightness(0.76);
  --show-sakura-corners: 1;
}

html[data-theme="ssj_blue"] {
  --page-bg-1: #044a5c;
  --page-bg-2: #08687c;
  --page-bg-3: #033341;
  --stage-bg: #03070b;
  --stage-border: rgba(56, 216, 245, 0.36);
  --stage-glow: rgba(20, 188, 224, 0.3);
  --card-bg: rgba(7, 25, 36, 0.88);
  --card-border: rgba(72, 212, 240, 0.38);
  --card-inner-glow: rgba(34, 211, 238, 0.14);
  --bar-bg: linear-gradient(180deg, rgba(12, 112, 134, 0.96), rgba(9, 86, 106, 0.98));
  --bar-border: rgba(96, 224, 246, 0.34);
  --accent-1: #37c9f2;
  --accent-2: #128db8;
  --accent-glow: rgba(42, 206, 248, 0.44);
  --btn-secondary-bg: rgba(46, 202, 238, 0.22);
  --btn-secondary-hover: rgba(46, 202, 238, 0.36);
  --btn-secondary-border: rgba(122, 230, 250, 0.44);
  --text-main: #f0fbff;
  --text-muted: #b7dfe9;
  --petal-color: #6ceeff;
  --bg-image: url("./assets/bg-ssj-blue.jpg");
  --bg-filter: saturate(1.06) brightness(0.92);
  --show-sakura-corners: 0;
}

html[data-theme="classic"] {
  --page-bg-1: #2e1d11;
  --page-bg-2: #4b2d17;
  --page-bg-3: #1e120a;
  --stage-bg: #110904;
  --stage-border: rgba(242, 186, 68, 0.48);
  --stage-glow: rgba(242, 174, 46, 0.32);
  --card-bg: rgba(36, 22, 12, 0.88);
  --card-border: rgba(245, 198, 92, 0.5);
  --card-inner-glow: rgba(242, 186, 68, 0.18);
  --bar-bg: linear-gradient(180deg, rgba(76, 48, 25, 0.96), rgba(52, 32, 16, 0.98));
  --bar-border: rgba(242, 186, 68, 0.42);
  --accent-1: #f7c954;
  --accent-2: #d68516;
  --accent-glow: rgba(247, 192, 62, 0.45);
  --btn-secondary-bg: rgba(242, 186, 68, 0.2);
  --btn-secondary-hover: rgba(242, 186, 68, 0.34);
  --btn-secondary-border: rgba(250, 210, 118, 0.46);
  --text-main: #fff8eb;
  --text-muted: #ebd2aa;
  --petal-color: #ffd470;
  --bg-image: url("./assets/bg-classic.jpg");
  --bg-filter: saturate(1.06) brightness(0.9);
  --show-sakura-corners: 0;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 50% 18%, var(--page-bg-2) 0%, var(--page-bg-1) 52%, var(--page-bg-3) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  transition: background 0.35s ease, color 0.25s ease;
}

.portal-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 20px 14px;
  gap: 10px;
}

/* Main rounded container holding Stage + Docked Bottom Bar (like reference screenshot) */
.portal-frame {
  width: min(1240px, 96vw);
  border-radius: 14px;
  overflow: hidden;
  background: var(--stage-bg);
  border: 1px solid var(--stage-border);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.56),
    0 0 38px var(--stage-glow);
  display: flex;
  flex-direction: column;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100dvh - 118px);
  background: var(--stage-bg);
  overflow: hidden;
  user-select: none;
}

/* Fullscreen mode fills entire screen cleanly */
.stage-wrap:fullscreen,
.stage-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
}

.stage-backdrop {
  position: absolute;
  inset: 0;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center center;
  filter: var(--bg-filter);
  opacity: 0.72;
  transform: scale(1.02);
  transition: opacity 0.45s ease, filter 0.35s ease, background-image 0.35s ease;
  pointer-events: none;
}

.stage-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 48%, rgba(8, 3, 12, 0.22) 0%, rgba(5, 2, 10, 0.74) 82%);
}

/* Hide backdrop & petals once Unity is actively rendering */
body.game-running .stage-backdrop,
body.game-running .petal-layer {
  opacity: 0;
  pointer-events: none;
}

body.game-running .petal {
  animation-play-state: paused !important;
}

/* Unity WebGL Canvas */
#unity-canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  outline: none;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

body.game-running #unity-canvas {
  opacity: 1;
}

/* Lightweight GPU-only drifting sakura petals / energy motes (pauses in-game) */
.petal-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.petal {
  position: absolute;
  top: -24px;
  width: 11px;
  height: 7px;
  border-radius: 75% 15% 75% 15%;
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, var(--petal-color) 65%);
  opacity: 0.75;
  box-shadow: 0 0 8px var(--accent-glow);
  will-change: transform, opacity;
  animation: petal-fall linear infinite;
}

@keyframes petal-fall {
  0% {
    transform: translate3d(0, -10px, 0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 0.8;
  }
  88% {
    opacity: 0.75;
  }
  100% {
    transform: translate3d(90px, 680px, 0) rotate(320deg);
    opacity: 0;
  }
}

/* Centered Launch / Loading Overlay */
.launch-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.launch-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.launch-card {
  position: relative;
  width: min(410px, 92%);
  padding: 26px 26px 24px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 20px 54px rgba(0, 0, 0, 0.62),
    inset 0 0 28px var(--card-inner-glow),
    0 0 28px var(--stage-glow);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* 4 Sakura Corner Blossoms matching client_7VNR loading dialog */
.corner-blossom {
  position: absolute;
  width: 28px;
  height: 28px;
  pointer-events: none;
  opacity: var(--show-sakura-corners);
  transition: opacity 0.3s ease;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}
.corner-blossom.tl { top: -8px; left: -8px; }
.corner-blossom.tr { top: -8px; right: -8px; transform: rotate(90deg); }
.corner-blossom.bl { bottom: -8px; left: -8px; transform: rotate(-90deg); }
.corner-blossom.br { bottom: -8px; right: -8px; transform: rotate(180deg); }

.card-badges {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: -4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.badge-pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--btn-secondary-bg);
  border: 1px solid var(--btn-secondary-border);
  color: var(--text-main);
}

.card-avatar-wrap {
  position: relative;
  width: 82px;
  height: 82px;
  border-radius: 16px;
  padding: 3px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 8px 24px var(--accent-glow);
  margin-top: 2px;
}

.card-avatar {
  width: 100%;
  height: 100%;
  border-radius: 13px;
  object-fit: cover;
  display: block;
}

.card-title {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--text-main);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}

.card-subtitle {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 340px;
}

.btn-play {
  margin-top: 8px;
  width: 100%;
  height: 46px;
  border: none;
  border-radius: 11px;
  cursor: pointer;
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: 0.9px;
  color: #ffffff;
  background: linear-gradient(180deg, var(--accent-1) 0%, var(--accent-2) 100%);
  box-shadow:
    0 8px 24px var(--accent-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
  transition: transform 0.14s ease, filter 0.18s ease, box-shadow 0.2s ease;
}

.btn-play:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow:
    0 12px 30px var(--accent-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.btn-play:active {
  transform: translateY(1px) scale(0.99);
}

.btn-play:disabled {
  cursor: default;
  opacity: 0.72;
  transform: none;
}

/* Progress UI while downloading & initializing WebGL */
.progress-box {
  width: 100%;
  margin-top: 8px;
  display: none;
  flex-direction: column;
  gap: 8px;
}

.progress-box.is-active {
  display: flex;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-pct {
  color: var(--text-main);
  font-weight: 800;
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--btn-secondary-border);
  overflow: hidden;
  padding: 2px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent-1), #ffffff);
  background-size: 200% 100%;
  box-shadow: 0 0 14px var(--accent-glow);
  transition: width 0.22s ease;
  animation: shimmer-bar 1.8s linear infinite;
}

@keyframes shimmer-bar {
  0% { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

.error-box {
  display: none;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(185, 28, 28, 0.26);
  border: 1px solid rgba(248, 113, 113, 0.55);
  color: #fecaca;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: left;
}

.error-box.is-active {
  display: block;
}

/* ==========================================================================
   Docked Bottom Control Bar (matches reference screenshot layout)
   ========================================================================== */
.control-bar {
  min-height: 54px;
  padding: 8px 14px;
  background: var(--bar-bg);
  border-top: 1px solid var(--bar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.bar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bar-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1.5px solid var(--btn-secondary-border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.bar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.bar-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
}

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #facc15;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.7);
}

.status-dot.online {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.85);
}

.status-dot.offline {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.85);
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
}

.bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px;
  border-radius: 9px;
  border: 1px solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.12s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.bar-btn:hover {
  background: var(--btn-secondary-hover);
  transform: translateY(-1px);
}

.bar-btn:active {
  transform: translateY(0);
}

.bar-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.bar-btn.icon-only {
  padding: 0 10px;
}

/* Theme Popover synced with 6 client themes */
.theme-popover {
  position: fixed;
  z-index: 60;
  bottom: 72px;
  right: 24px;
  width: 276px;
  padding: 12px;
  border-radius: 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
  display: none;
  flex-direction: column;
  gap: 8px;
}

.theme-popover.is-open {
  display: flex;
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-main);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--btn-secondary-border);
}

.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.18s ease, background 0.18s ease;
}

.theme-option:hover {
  background: rgba(255, 255, 255, 0.13);
  transform: translateY(-1px);
}

.theme-option.is-active {
  border-color: var(--accent-1);
  background: var(--btn-secondary-hover);
  box-shadow: 0 0 14px var(--accent-glow);
}

.theme-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.72);
}

/* Footer status line (matches reference screenshot bottom caption) */
.portal-footer {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.92;
  padding: 2px 12px;
}

/* Modal for Keys / iOS Install Help */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(6, 2, 10, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-dialog {
  width: min(440px, 95vw);
  padding: 20px 22px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
  color: var(--text-main);
}

.modal-dialog h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 800;
}

.key-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--btn-secondary-bg);
  border: 1px solid var(--btn-secondary-border);
  font-family: Consolas, monospace;
  font-weight: 700;
  font-size: 12px;
}

.secure-input-box {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  margin-bottom: 14px;
  border-radius: 10px;
  border: 1px solid var(--btn-secondary-border);
  background: rgba(0, 0, 0, 0.38);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}

.secure-input-box:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.secure-input-actions {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  align-items: center;
}

/* Responsive Mobile Optimization */
@media (max-width: 780px) {
  .portal-shell {
    padding: 8px;
    gap: 8px;
  }
  .portal-frame {
    width: 100%;
    border-radius: 10px;
  }
  .stage-wrap {
    aspect-ratio: 16 / 10;
    max-height: calc(100dvh - 108px);
  }
  .launch-card {
    padding: 18px 16px 16px;
    gap: 8px;
  }
  .card-avatar-wrap {
    width: 66px;
    height: 66px;
  }
  .card-title {
    font-size: 18px;
  }
  .bar-btn span.hide-xs {
    display: none;
  }
}
