/* === CSS Variables === */
:root {
  --bg-primary: #0f1119;
  --bg-secondary: #1a1d2e;
  --bg-tertiary: #242840;
  --bg-card: #1e2138;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #5b6080;
  --accent-gold: #ffb347;
  --accent-green: #4caf84;
  --accent-blue: #5b9bd5;
  --accent-red: #e0556a;
  --border-default: #2d3148;
  --border-selected: #ffb347;
  --shadow-card: 0 4px 20px rgba(0,0,0,0.3);
  --radius-card: 12px;
  --radius-btn: 8px;
  --font-sans: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

button {
  cursor: pointer; border: none;
  font-family: var(--font-sans); font-size: 14px;
  transition: all var(--transition-fast);
}
button:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #3d7ec0);
  color: #fff; padding: 10px 24px; border-radius: var(--radius-btn);
  font-weight: 600; font-size: 15px;
}
.btn-primary:hover { background: linear-gradient(135deg, #6bb0e6, var(--accent-blue)); }
.btn-primary:disabled { background: #3a3d50; color: #6a6d80; cursor: not-allowed; }
.btn-primary:disabled:active { transform: none; }

.btn-secondary {
  background: var(--bg-tertiary); color: var(--text-primary);
  padding: 10px 20px; border-radius: var(--radius-btn); font-weight: 500;
}
.btn-secondary:hover { background: #2f3252; }

.btn-lg { padding: 14px 40px; font-size: 18px; border-radius: 12px; }

/* === Welcome === */
.welcome-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(ellipse at center, #1a1d3e 0%, var(--bg-primary) 70%);
  display: flex; align-items: center; justify-content: center;
}
.welcome-content { text-align: center; max-width: 500px; padding: 40px 32px; }
.welcome-icon { font-size: 64px; margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.welcome-title {
  font-size: 36px; font-weight: 800; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.welcome-subtitle { font-size: 16px; color: var(--text-secondary); margin-bottom: 32px; }
.welcome-rules { text-align: left; margin-bottom: 32px; display: flex; flex-direction: column; gap: 14px; }
.rule-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: rgba(255,255,255,0.04); border-radius: 10px;
  font-size: 15px; color: var(--text-secondary);
}
.rule-item strong { color: var(--text-primary); }
.rule-icon { font-size: 24px; flex-shrink: 0; }
.welcome-hint { margin-top: 16px; font-size: 13px; color: var(--text-muted); }

/* === Game Board === */
.game-board { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 80px; }

/* === Top Bar === */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-default);
  position: sticky; top: 0; z-index: 50;
}
.logo { font-size: 18px; font-weight: 700; }
.top-bar-center { display: flex; align-items: center; gap: 10px; }
.target-label { font-size: 14px; color: var(--text-secondary); }
.target-price { font-size: 28px; font-weight: 800; color: var(--accent-gold); font-family: var(--font-mono); }
.top-bar-right { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); }
.round-num { color: var(--text-primary); font-weight: 700; font-size: 18px; }

/* === Card Grid === */
.card-grid {
  flex: 1; display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 16px; padding: 24px; max-width: 1400px; width: 100%;
  margin: 0 auto; align-content: start;
}

/* === Game Card === */
.game-card {
  background: var(--bg-card); border: 2px solid var(--border-default);
  border-radius: var(--radius-card); overflow: hidden; cursor: pointer;
  transition: all var(--transition-normal); position: relative;
  animation: cardIn 0.4s ease both; user-select: none;
}
.game-card:hover { border-color: #4a4f6a; transform: translateY(-3px); box-shadow: var(--shadow-card); }
.game-card.selected {
  border-color: var(--border-selected);
  box-shadow: 0 0 20px rgba(255,179,71,0.3); transform: scale(1.03);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.card-cover {
  height: 100px; display: flex; align-items: flex-end; justify-content: flex-end;
  position: relative; overflow: hidden;
}
.card-cover-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transition: opacity 0.3s ease;
}
.card-cover-img.loaded { opacity: 1; }
.card-initials { font-size: 36px; font-weight: 900; color: rgba(255,255,255,0.12); pointer-events: none; }
.card-price-mask {
  position: absolute; bottom: 8px; right: 10px;
  font-size: 16px; font-weight: 700; color: rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 4px;
  font-family: var(--font-mono);
}
.card-price-real {
  display: none; position: absolute; bottom: 8px; right: 10px;
  font-size: 16px; font-weight: 700; color: var(--accent-green);
  background: rgba(0,0,0,0.6); padding: 2px 8px; border-radius: 4px;
  font-family: var(--font-mono);
}
.card-price-real.revealed { display: block; animation: pricePop 0.3s ease; }
@keyframes pricePop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.card-body { padding: 12px 14px; }
.card-title-zh { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.card-title-en {
  font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-genre {
  font-size: 11px; color: var(--accent-blue);
  background: rgba(91,155,213,0.1); padding: 2px 8px; border-radius: 10px; font-weight: 500;
}
.card-year { font-size: 11px; color: var(--text-muted); }

.card-checkmark {
  position: absolute; top: 8px; left: 8px; width: 28px; height: 28px;
  background: var(--accent-gold); color: var(--bg-primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; opacity: 0; transform: scale(0);
  transition: all var(--transition-normal);
}
.game-card.selected .card-checkmark { opacity: 1; transform: scale(1); }

/* === Bottom Bar === */
.bottom-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--bg-secondary);
  border-top: 1px solid var(--border-default);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
}
.bottom-bar-left { font-size: 15px; color: var(--text-secondary); }
.selected-count { font-weight: 700; font-size: 20px; color: var(--accent-gold); font-family: var(--font-mono); }
.bottom-bar-right { display: flex; gap: 10px; }

/* === Result Overlay === */
.result-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center;
  z-index: 200; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result-modal {
  background: var(--bg-secondary); border: 1px solid var(--border-default);
  border-radius: 20px; padding: 36px 32px; max-width: 480px;
  width: 90%; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 8px 50px rgba(0,0,0,0.5);
  animation: modalIn 0.4s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.85) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.result-tier { text-align: center; margin-bottom: 24px; }
.tier-emoji { font-size: 52px; display: block; margin-bottom: 8px; animation: pulse 0.6s ease 3; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
.tier-title { font-size: 32px; font-weight: 800; }

.result-numbers { display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 16px; }
.result-number-item { text-align: center; }
.result-label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.result-value { font-size: 28px; font-weight: 800; font-family: var(--font-mono); }
.result-number-divider { font-size: 24px; color: var(--text-muted); }
.result-diff { text-align: center; font-size: 16px; color: var(--text-secondary); margin-bottom: 24px; padding: 10px; background: rgba(255,255,255,0.03); border-radius: 8px; }
.result-diff strong { color: var(--accent-gold); font-family: var(--font-mono); font-size: 20px; }
.result-games-label { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; }
.result-game-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.result-game-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg-tertiary); border-radius: 8px; }
.rg-cover { width: 40px; height: 28px; border-radius: 4px; flex-shrink: 0; }
.rg-name { flex: 1; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rg-price { font-family: var(--font-mono); font-size: 16px; font-weight: 700; color: var(--accent-green); flex-shrink: 0; }
.result-modal .btn-lg { width: 100%; }

/* === Confetti === */
.confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -20px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* === Responsive === */
@media (max-width: 1200px) { .card-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 900px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px; }
  .target-price { font-size: 24px; }
  .bottom-bar { padding: 10px 16px; flex-direction: column; gap: 10px; }
  .bottom-bar-right { width: 100%; justify-content: center; }
}
@media (max-width: 640px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px; }
  .card-cover { height: 80px; }
  .welcome-title { font-size: 26px; }
  .top-bar { flex-wrap: wrap; gap: 8px; }
  .result-modal { padding: 24px 20px; }
  .result-value { font-size: 22px; }
  .tier-title { font-size: 24px; }
}
@media (max-width: 400px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 8px; }
  .card-cover { height: 64px; }
  .card-title-zh { font-size: 13px; }
}
