:root {
  --bg: #0b0d10;
  --fg: #ffffff;
  --fg-muted: rgba(255, 255, 255, 0.64);
  --fg-dim: rgba(255, 255, 255, 0.36);
  --glass: rgba(12, 15, 20, 0.52);
  --glass-strong: rgba(10, 12, 16, 0.86);
  --glass-light: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.16);
  --border: rgba(255, 255, 255, 0.2);
  --border-strong: rgba(255, 255, 255, 0.45);
  --pill-radius: 999px;
  --card-radius: 18px;
  --font: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.ico svg {
  width: 100%;
  height: 100%;
  display: block;
}
.ico.lg {
  width: 24px;
  height: 24px;
}

.hidden {
  display: none !important;
}

/* Streamlined Monochrome Transparent Top-Center Bar */
.hud-top-center {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 7px;
  z-index: 20;
  max-width: calc(100vw - 16px);
  pointer-events: none;
}
.hud-top-center > * {
  pointer-events: auto;
}

.stat-pill,
.action-pill,
.icon-pill,
.mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px;
  border-radius: var(--pill-radius);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
  white-space: nowrap;
}

.stat-pill.solid {
  background: rgba(255, 255, 255, 0.1);
}
.stat-pill.danger {
  border-color: rgba(255, 118, 117, 0.85);
  color: #ffb8b8;
}

.stat-val {
  font-variant-numeric: tabular-nums;
}

button.action-pill,
button.icon-pill,
button.mini-pill {
  cursor: pointer;
}
button.action-pill:hover,
button.icon-pill:hover {
  background: var(--glass-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
button.action-pill:active,
button.icon-pill:active {
  transform: translateY(0) scale(0.96);
}

.action-pill.primary {
  background: #ffffff;
  color: #0b0d10;
  border-color: #ffffff;
}
.action-pill.primary:hover {
  background: #e9edf2;
}
.action-pill.lg {
  height: 44px;
  padding: 0 22px;
  font-size: 14px;
}

.icon-pill {
  width: 36px;
  padding: 0;
  justify-content: center;
}
.mini-pill {
  height: 28px;
  width: 28px;
  padding: 0;
  justify-content: center;
}

/* Top-Left Projectile Dock & Top-Right Skill Dock */
.hud-dock {
  position: fixed;
  top: max(58px, calc(env(safe-area-inset-top) + 52px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
.hud-top-left {
  left: max(12px, env(safe-area-inset-left));
}
.hud-top-right {
  right: max(12px, env(safe-area-inset-right));
  align-items: flex-end;
}

.dock-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  padding: 0 13px 0 10px;
  border-radius: var(--pill-radius);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
  min-width: 122px;
}
.dock-btn:hover {
  background: var(--glass-hover);
  border-color: var(--border-strong);
}
.dock-btn.active,
.dock-btn.targeting {
  background: #ffffff;
  color: #0b0d10;
  border-color: #ffffff;
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.28);
}
.dock-btn.locked {
  opacity: 0.4;
}
.dock-btn.empty {
  opacity: 0.36;
}

.dock-btn .ico {
  width: 20px;
  height: 20px;
  z-index: 2;
}
.dock-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  z-index: 2;
}
.dock-name {
  font-size: 12px;
  font-weight: 700;
}
.dock-sub {
  font-size: 10px;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}
.dock-key {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  opacity: 0.6;
  z-index: 2;
}
.dock-cooldown {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: currentColor;
  opacity: 0.65;
  z-index: 1;
}

/* Floating Banners */
.combo-banner,
.rush-banner,
.shield-banner,
.target-hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-radius: var(--pill-radius);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  z-index: 22;
  white-space: nowrap;
}

.combo-banner {
  top: 56px;
  background: var(--glass-strong);
  color: #ffffff;
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(10px);
}
.combo-track,
.rush-track {
  width: 52px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}
.combo-fill {
  height: 100%;
  width: 100%;
  background: #ffffff;
}

.rush-banner {
  top: 94px;
  background: rgba(255, 255, 255, 0.94);
  color: #0b0d10;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
}
.rush-banner .rush-track {
  background: rgba(11, 13, 16, 0.2);
}
.rush-fill {
  height: 100%;
  width: 100%;
  background: #0b0d10;
}

.shield-banner {
  top: 132px;
  background: var(--glass-strong);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px);
}

.target-hint {
  bottom: 22px;
  background: var(--glass-strong);
  color: #ffffff;
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(14px);
}

.control-hint {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 15px;
  border-radius: var(--pill-radius);
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  color: var(--fg-muted);
  font-size: 11.5px;
  z-index: 15;
  pointer-events: none;
  transition: opacity 0.6s ease;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.control-hint.fade-out {
  opacity: 0;
}

/* Skill Drag Ghost */
.skill-drag-ghost {
  position: fixed;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 1.5px solid #ffffff;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 40;
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.35);
}
.skill-drag-ghost .ico {
  width: 26px;
  height: 26px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.64);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 50;
}

.modal-panel {
  width: 100%;
  max-width: 800px;
  max-height: min(86vh, 720px);
  background: rgba(12, 15, 20, 0.9);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lb-panel {
  max-width: 560px;
}
.compact-panel {
  max-width: 440px;
  padding: 28px 24px;
  align-items: center;
  text-align: center;
  gap: 12px;
}
.compact-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--glass-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.compact-icon svg {
  width: 26px;
  height: 26px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.modal-title-group {
  display: flex;
  align-items: center;
  gap: 11px;
}
.modal-title-group h2 {
  font-size: 17px;
  font-weight: 700;
}
.modal-sub {
  font-size: 11.5px;
  color: var(--fg-muted);
  margin-top: 2px;
}
.modal-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shop-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  overflow-x: auto;
}
.shop-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--pill-radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}
.shop-tab:hover {
  background: var(--glass-light);
  color: var(--fg);
}
.shop-tab.active {
  background: #ffffff;
  color: #0b0d10;
  border-color: #ffffff;
}

.shop-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.shop-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--card-radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}
.shop-card.owned-current {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}
.shop-card.dimmed {
  opacity: 0.45;
}
.card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.card-icon .ico {
  width: 21px;
  height: 21px;
}
.card-title-wrap {
  min-width: 0;
  flex: 1;
}
.card-title {
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.card-desc {
  font-size: 12px;
  line-height: 1.45;
  color: var(--fg-muted);
  flex: 1;
}
.card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
}
.card-stat-chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.buy-btn {
  width: 100%;
  height: 36px;
  border-radius: var(--pill-radius);
  border: 1px solid #ffffff;
  background: #ffffff;
  color: #0b0d10;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.buy-btn:disabled {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border);
  cursor: not-allowed;
}
.buy-btn.equipped {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.5);
}

/* Leaderboard Table */
.lb-body {
  padding: 14px 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.lb-row.top3 {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.09);
}
.lb-rank {
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.lb-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-meta {
  font-size: 11.5px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.lb-time {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.lb-empty {
  text-align: center;
  padding: 28px 0;
  color: var(--fg-muted);
  font-size: 13px;
}

.lb-submit-row {
  width: 100%;
  display: flex;
  gap: 8px;
}
.name-input {
  flex: 1;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--pill-radius);
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-size: 13px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.name-input:focus {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.11);
}
.submit-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

.summary-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.summary-card {
  padding: 12px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.summary-label {
  font-size: 11px;
  color: var(--fg-muted);
}
.summary-card strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 860px) {
  .hide-sm { display: none !important; }
  .dock-btn { min-width: auto; padding: 0 10px; height: 42px; }
  .dock-name { display: none; }
  .dock-key { display: none; }
  .shop-body { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .hide-xs { display: none !important; }
  .stat-pill, .action-pill, .icon-pill { height: 33px; padding: 0 9px; font-size: 11.5px; }
  .icon-pill { width: 33px; padding: 0; }
  .btn-label { display: none; }
}

/* Mobile Portrait Ergonomic Layout: Thumb-Friendly Bottom Docks! */
@media (orientation: portrait) and (max-width: 860px) {
  .hud-top-center {
    flex-wrap: wrap;
    row-gap: 6px;
    width: calc(100vw - 16px);
  }
  .combo-banner { top: 92px; }
  .rush-banner { top: 128px; }
  .shield-banner { top: 164px; }

  /* Move Projectile & Skill Docks to ergonomic bottom thumb zone */
  .hud-dock {
    top: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    flex-direction: row;
    gap: 6px;
    max-width: calc(50vw - 14px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .hud-dock::-webkit-scrollbar { display: none; }

  .hud-top-left {
    left: max(10px, env(safe-area-inset-left));
  }
  .hud-top-right {
    right: max(10px, env(safe-area-inset-right));
    align-items: center;
  }
  .hud-dock .dock-btn {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    width: 48px;
    height: 52px;
    padding: 4px;
    border-radius: 16px;
    flex-shrink: 0;
  }
  .hud-dock .dock-meta {
    align-items: center;
  }
  .hud-dock .dock-sub {
    font-size: 9.5px;
  }
  .control-hint {
    bottom: 76px;
    font-size: 11px;
  }
  .target-hint {
    bottom: 78px;
    font-size: 11px;
  }
}
