:root {
  --bg: #070b17;
  --panel: rgba(15, 23, 42, 0.92);
  --border: rgba(148, 163, 184, 0.22);
  --cyan: #22d3ee;
  --amber: #fbbf24;
  --emerald: #34d399;
  --violet: #c084fc;
  --rose: #fb7185;
  --text: #f8fafc;
  --muted: #94a3b8;
}

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

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 28%, #162244 0%, var(--bg) 72%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang TC", "Noto Sans TC", sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.text-amber { color: var(--amber); }
.text-cyan { color: var(--cyan); }
.text-emerald { color: var(--emerald); }
.text-violet { color: var(--violet); }
.hidden { display: none !important; }

.app-shell {
  max-width: 540px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* --- HUD Top --- */
.hud-top {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

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

.stage-pill {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-label {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--cyan);
}

.wave-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.14);
  border: 1px solid rgba(34, 211, 238, 0.32);
  color: var(--cyan);
}

.wave-badge.is-boss {
  background: rgba(251, 113, 133, 0.18);
  border-color: rgba(251, 113, 133, 0.55);
  color: #fecdd3;
}

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

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}

.monster-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.monster-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
}

.hp-track {
  height: 11px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef4444, #f59e0b);
  transition: width 60ms linear;
}

.boss-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.boss-timer-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.9);
  overflow: hidden;
}

.boss-timer-fill {
  height: 100%;
  width: 100%;
  background: var(--rose);
}

.boss-sec {
  font-size: 0.74rem;
  color: #fda4af;
}

.retry-boss-btn {
  width: 100%;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(251, 113, 133, 0.55);
  background: rgba(244, 63, 94, 0.2);
  color: #ffe4e6;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.stat-chip {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-chip .k {
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.stat-chip .v {
  font-size: 0.82rem;
  font-weight: 800;
}

/* --- Center Battle Arena --- */
.arena-wrap {
  position: relative;
  flex: 1;
  min-height: 180px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 48%, rgba(34, 211, 238, 0.09), rgba(7, 11, 23, 0.95));
  overflow: hidden;
  touch-action: none;
}

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

.combo-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.55);
  color: #fde68a;
  font-size: 0.78rem;
  font-weight: 800;
  pointer-events: none;
}

.tap-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.74rem;
  color: rgba(203, 213, 225, 0.72);
  pointer-events: none;
}

/* --- Bottom Thumb Deck --- */
.thumb-deck {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 41%;
  min-height: 225px;
  flex-shrink: 0;
}

.skills-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.skill-btn, .prestige-btn {
  border-radius: 10px;
  padding: 7px 6px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.9);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

.skill-btn.is-active {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.18);
}

.skill-btn:disabled, .prestige-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.prestige-btn:not(:disabled) {
  border-color: rgba(251, 191, 36, 0.75);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(168, 85, 247, 0.28));
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.25);
}

.sk-title {
  font-size: 0.78rem;
  font-weight: 800;
}

.sk-sub {
  font-size: 0.66rem;
  color: var(--muted);
}

.deck-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.deck-tab {
  padding: 6px 4px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(2, 6, 23, 0.5);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.deck-tab.is-active {
  background: rgba(34, 211, 238, 0.15);
  border-color: rgba(34, 211, 238, 0.35);
  color: var(--cyan);
}

.deck-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.upgrade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  padding: 8px 10px;
}

.upgrade-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.upgrade-info strong {
  font-size: 0.86rem;
}

.upgrade-info span {
  font-size: 0.72rem;
  color: var(--muted);
}

.buy-btn {
  min-width: 88px;
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.16);
  color: #ecfeff;
  font-weight: 800;
  font-size: 0.78rem;
  cursor: pointer;
}

.buy-btn:disabled {
  opacity: 0.4;
  border-color: var(--border);
  background: rgba(30, 41, 59, 0.5);
  cursor: not-allowed;
}

/* --- Relic Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  z-index: 90;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  background: #0f172a;
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.relic-preview {
  display: flex;
  align-items: center;
  gap: 14px;
}

.relic-preview svg {
  width: 92px;
  height: 92px;
  flex-shrink: 0;
  border-radius: 14px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-exhibit {
  width: 100%;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid rgba(52, 211, 153, 0.5);
  background: rgba(16, 185, 129, 0.25);
  color: #ecfdf5;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-secondary-link {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 700;
}

.toast-host {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast-pill {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(52, 211, 153, 0.55);
  color: #d1fae5;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
