:root {
  --bg: #050812;
  --panel: rgba(11, 17, 34, 0.88);
  --panel-border: rgba(130, 170, 255, 0.18);
  --text: #f3f7ff;
  --muted: #8ea0c6;
  --cyan: #38e8ff;
  --coral: #ff7a5c;
  --gold: #ffd45a;
  --purple: #c57bff;
  --crimson: #ff355e;
  --emerald: #3df29d;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 20%, #101830 0%, #050812 72%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage-shell {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: calc(100dvh * 9 / 16);
  max-height: 100dvh;
  background: #070b16;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(120, 165, 255, 0.12);
}

@media (max-aspect-ratio: 9/16) {
  #stage-shell {
    max-width: 100vw;
    box-shadow: none;
  }
}

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

.hidden {
  display: none !important;
}

/* ==================== HUD ==================== */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(180deg, rgba(6, 10, 22, 0.92) 0%, rgba(6, 10, 22, 0.55) 75%, transparent 100%);
  pointer-events: none;
  z-index: 10;
}

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

.hud-top {
  margin-bottom: 6px;
}

.hud-stage {
  display: flex;
  flex-direction: column;
  min-width: 78px;
}

#hud-stage-num {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

#hud-stage-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.hud-progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#hud-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  transition: width 0.12s linear;
}

#hud-progress-fill.boss {
  background: linear-gradient(90deg, var(--crimson), #ff8e53);
}

#hud-progress-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#hud-score {
  font-size: 14px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.hud-hearts {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
}

.hud-meters {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-meter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mini-meter .m-ico {
  font-size: 11px;
}

.m-bar {
  width: 44px;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.m-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  transition: width 0.1s linear;
}

.m-fill.clap {
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

.m-fill.clap.ready {
  background: #ffffff;
  box-shadow: 0 0 10px var(--gold);
}

.m-fill.fever {
  background: linear-gradient(90deg, var(--purple), var(--coral));
}

.m-fill.fever.active {
  background: linear-gradient(90deg, var(--gold), #ff5599);
}

.heart-icon {
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.heart-icon.empty {
  opacity: 0.22;
  filter: grayscale(1);
}

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

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.badge-combo {
  background: rgba(197, 123, 255, 0.22);
  color: #e6c6ff;
  border: 1px solid rgba(197, 123, 255, 0.4);
}

.badge-aegis {
  background: rgba(56, 232, 255, 0.16);
  border: 1px solid rgba(56, 232, 255, 0.4);
}

.badge-retry {
  color: var(--muted);
}

.icon-btn {
  pointer-events: auto;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 22, 42, 0.72);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ==================== LOBBY BARS ==================== */

#lobby-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 15;
  pointer-events: none;
}

.room-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}

.room-label {
  font-size: 11px;
  color: var(--muted);
}

#lobby-room-code {
  font-size: 18px;
  letter-spacing: 0.14em;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.mini-btn {
  padding: 5px 10px;
  border-radius: 9px;
  border: none;
  background: rgba(56, 232, 255, 0.18);
  color: var(--cyan);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.lobby-actions-right {
  display: flex;
  gap: 6px;
}

#lobby-footer {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 15;
}

.player-slots {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 99px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.slot-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.45;
  transition: opacity 0.2s;
}

.slot-chip.connected {
  opacity: 1;
}

.slot-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.slot-chip.p1 .dot {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.slot-chip.p2 .dot {
  background: var(--coral);
  box-shadow: 0 0 10px var(--coral);
}

.slot-link {
  color: var(--muted);
}

.lobby-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

/* ==================== STAGE BANNER ==================== */

#stage-banner {
  position: absolute;
  top: 28%;
  left: 16px;
  right: 16px;
  text-align: center;
  pointer-events: none;
  z-index: 18;
  animation: bannerPop 0.35s ease-out;
}

@keyframes bannerPop {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.banner-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 99px;
  background: rgba(56, 232, 255, 0.16);
  border: 1px solid rgba(56, 232, 255, 0.4);
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.banner-tag.boss {
  background: rgba(255, 53, 94, 0.2);
  border-color: rgba(255, 53, 94, 0.55);
  color: #ff708d;
}

#banner-title {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-shadow: 0 0 24px rgba(56, 232, 255, 0.4);
}

#banner-sub {
  margin: 0;
  font-size: 13px;
  color: #cdd8f5;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

/* ==================== OVERLAYS & CARDS ==================== */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 7, 18, 0.62);
  backdrop-filter: blur(8px);
  z-index: 30;
}

.home-card,
.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 22px 18px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.brand {
  text-align: center;
  margin-bottom: 16px;
}

.brand-emblem {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 10px;
}

.orb-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.orb-dot.cyan {
  background: var(--cyan);
  box-shadow: 0 0 16px var(--cyan);
}

.orb-dot.coral {
  background: var(--coral);
  box-shadow: 0 0 16px var(--coral);
}

.beam-line {
  width: 72px;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--coral));
  box-shadow: 0 0 12px var(--gold);
}

.brand h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.brand .en {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--cyan);
  vertical-align: middle;
}

.tagline {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.rules-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.rule-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-weight: 600;
}

.rule-pill .ico.gold { color: var(--gold); }
.rule-pill .ico.purple { color: var(--purple); }
.rule-pill .ico.red { color: var(--crimson); }

.form-group {
  margin-bottom: 10px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(5, 10, 22, 0.72);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(56, 232, 255, 0.16);
}

.btn {
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-lg {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, #2bd8ff 0%, #7d6dff 52%, #ff7a5c 100%);
  color: #060913;
  box-shadow: 0 8px 24px rgba(56, 232, 255, 0.28);
}

.btn-secondary {
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  white-space: nowrap;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

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

.join-row input {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.error-msg {
  margin: 10px 0 0;
  font-size: 13px;
  color: #ff6b86;
  text-align: center;
}

.home-footer {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta-note {
  font-size: 11px;
  color: var(--muted);
}

.text-btn {
  pointer-events: auto;
  background: none;
  border: none;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 8px;
}

.danger-text {
  color: var(--muted);
  margin-top: 10px;
  width: 100%;
}

/* ==================== UPGRADE MODAL ==================== */

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.pill-tag {
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(197, 123, 255, 0.2);
  color: #e3beff;
  font-size: 12px;
  font-weight: 700;
}

.timer-pill {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.modal-card h3,
.modal-card h2 {
  margin: 0 0 4px;
  text-align: center;
}

.modal-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upgrade-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.upgrade-item:active {
  transform: scale(0.98);
}

.upgrade-item.picked-self {
  border-color: var(--cyan);
  background: rgba(56, 232, 255, 0.12);
}

.upgrade-icon {
  font-size: 24px;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.upgrade-body {
  flex: 1;
}

.upgrade-name {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 2px;
}

.upgrade-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.upgrade-votes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vote-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.vote-dot.p1 { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.vote-dot.p2 { background: var(--coral); box-shadow: 0 0 8px var(--coral); }

/* ==================== RETRY & END MODALS ==================== */

.near-miss-badge {
  display: inline-block;
  margin: 0 auto 10px;
  padding: 5px 14px;
  border-radius: 99px;
  background: rgba(255, 53, 94, 0.18);
  border: 1px solid rgba(255, 53, 94, 0.45);
  color: #ff7e98;
  font-size: 14px;
  font-weight: 800;
}

.near-miss-badge.victory {
  background: rgba(61, 242, 157, 0.18);
  border-color: rgba(61, 242, 157, 0.5);
  color: var(--emerald);
}

.retry-card,
.end-card {
  text-align: center;
}

.ready-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.r-dot {
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid transparent;
}

.r-dot.p1.ready {
  color: var(--cyan);
  border-color: var(--cyan);
  background: rgba(56, 232, 255, 0.14);
}

.r-dot.p2.ready {
  color: var(--coral);
  border-color: var(--coral);
  background: rgba(255, 122, 92, 0.14);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-box {
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.stat-box strong {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.end-links {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 18px;
}

/* ==================== LEADERBOARD ==================== */

.lb-card {
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
}

.lb-stats {
  display: flex;
  justify-content: space-around;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.lb-stats strong {
  color: var(--gold);
}

.lb-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 52dvh;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
}

.lb-rank {
  width: 24px;
  font-weight: 900;
  color: var(--gold);
  text-align: center;
}

.lb-main {
  flex: 1;
  min-width: 0;
}

.lb-names {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-meta {
  font-size: 11px;
  color: var(--muted);
}

.lb-score {
  font-weight: 800;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

/* ==================== TOAST ==================== */

.toast {
  position: absolute;
  top: max(68px, calc(env(safe-area-inset-top) + 56px));
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(15, 25, 48, 0.94);
  border: 1px solid rgba(56, 232, 255, 0.4);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  z-index: 50;
  white-space: nowrap;
  pointer-events: none;
}

/* ==================== TOP BAR, TRIAL & PAYWALL ==================== */

.home-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.trial-pill-btn,
.trial-chip {
  pointer-events: auto;
  border: 1px solid rgba(56, 232, 255, 0.35);
  background: rgba(56, 232, 255, 0.12);
  color: var(--cyan);
  border-radius: 99px;
  font-weight: 700;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.trial-pill-btn {
  font-size: 11.5px;
  padding: 5px 10px;
}

.trial-chip {
  font-size: 10.5px;
  padding: 3px 7px;
}

.trial-pill-btn.warn,
.trial-chip.warn {
  border-color: rgba(255, 212, 90, 0.55);
  background: rgba(255, 212, 90, 0.16);
  color: var(--gold);
}

.trial-pill-btn.expired,
.trial-chip.expired {
  border-color: rgba(255, 53, 94, 0.65);
  background: rgba(255, 53, 94, 0.18);
  color: #ff7e98;
}

.trial-pill-btn.pro,
.trial-chip.pro {
  border-color: rgba(61, 242, 157, 0.5);
  background: rgba(61, 242, 157, 0.14);
  color: var(--emerald);
}

.lang-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  border-radius: 99px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.paywall-card {
  max-height: 90dvh;
  overflow-y: auto;
}

.paywall-price-box {
  background: linear-gradient(135deg, rgba(56, 232, 255, 0.1), rgba(197, 123, 255, 0.1));
  border: 1px solid rgba(130, 170, 255, 0.25);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.price-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.price-big {
  font-size: 32px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.price-unit {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.paywall-features {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: #d6e1ff;
  line-height: 1.5;
}

.paywall-features li {
  margin-bottom: 4px;
}

.recovery-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.recovery-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.recovery-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.recovery-code-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
}

.restore-section {
  margin-top: 12px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}

.restore-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.restore-row input {
  font-size: 13px;
  padding: 10px 12px;
}
