/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #F8F9FA;
  --white: #FFFFFF;
  --primary: #4A90D9;
  --primary-dark: #357ABD;
  --accent: #FF9F43;
  --green: #2ECC71;
  --red: #E74C3C;
  --text: #2D3436;
  --text-secondary: #636E72;
  --border: #E9ECEF;
  --radius-card: 16px;
  --radius-btn: 12px;
  --shadow-card: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 70px;
}

/* === Toast === */
#toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 20px; border-radius: 8px; color: #fff; font-size: 14px;
  opacity: 0; transition: opacity 0.3s; white-space: nowrap;
}
.toast-show { opacity: 1; }
.toast-error { background: var(--red); }
.toast-success { background: var(--green); }
.toast-info { background: var(--primary); }

/* === Topbar === */
.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, #667eea 100%);
  color: #fff; padding: 14px 16px; display: flex;
  justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 100;
}
.topbar h1 { font-size: 1.2rem; }
.topbar-balance { font-size: 1rem; font-weight: 700; }

/* === Tab Bar === */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--white);
  border-top: 1px solid var(--border);
  padding: 6px 0 env(safe-area-inset-bottom, 8px);
  z-index: 100;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  text-decoration: none; color: var(--text-secondary); font-size: 10px;
  padding: 4px 0; transition: color 0.2s;
}
.tab-item .tab-icon { font-size: 22px; line-height: 1; }
.tab-item .tab-label { margin-top: 2px; }
.tab-item.active { color: var(--primary); }

/* === Cards === */
.card {
  background: var(--white); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); padding: 20px; margin-bottom: 16px;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 24px; border: none; border-radius: var(--radius-btn);
  font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #B0BEC5; cursor: not-allowed; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #E88E2A; }
.btn-large { width: 100%; padding: 16px; font-size: 18px; }
.btn-small { padding: 8px 16px; font-size: 14px; }
.btn-gray { background: #DFE6E9; color: var(--text-secondary); cursor: default; }

/* === Amount Selector === */
.amount-group { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.amount-btn {
  flex: 1; min-width: 60px; padding: 10px; border: 2px solid var(--border);
  border-radius: var(--radius-btn); background: var(--white); text-align: center;
  font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.amount-btn.active { border-color: var(--primary); background: #EBF5FB; color: var(--primary); }

/* === Mining Ore Grid === */
.ore-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; max-width: 360px; margin: 20px auto;
}
.ore-card { aspect-ratio: 1; perspective: 600px; cursor: pointer; }
.ore-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform 0.6s ease; transform-style: preserve-3d;
}
.ore-card.flipped .ore-inner { transform: rotateY(180deg); }
.ore-card.disabled { pointer-events: none; }
.ore-face {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius-btn);
  backface-visibility: hidden; font-size: 40px;
}
.ore-back {
  background: linear-gradient(135deg, #B0BEC5, #90A4AE);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.15);
}
.ore-front { transform: rotateY(180deg); background: var(--white); box-shadow: var(--shadow-card); }

/* === Result Popup === */
.result-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.result-card {
  background: var(--white); border-radius: var(--radius-card);
  padding: 32px; text-align: center; min-width: 280px;
  animation: bounceIn 0.5s ease;
}
.result-amount { font-size: 48px; font-weight: 700; margin: 12px 0; font-variant-numeric: tabular-nums; }
.result-gain { color: var(--green); }
.result-loss { color: var(--red); animation: shake 0.4s ease; }
.result-flat { color: var(--text-secondary); }
.result-actions { display: flex; gap: 12px; margin-top: 20px; }
.result-actions .btn { flex: 1; }

/* === List === */
.list-item {
  display: flex; align-items: center; padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-icon { font-size: 24px; margin-right: 12px; flex-shrink: 0; }
.list-content { flex: 1; }
.list-title { font-size: 14px; font-weight: 500; }
.list-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.list-amount { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.list-amount.positive { color: var(--green); }
.list-amount.negative { color: var(--red); }

/* === Rank === */
.rank-medal { font-size: 28px; }
.rank-row { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.rank-num { width: 36px; text-align: center; font-weight: 700; font-size: 16px; color: var(--text-secondary); }
.rank-info { flex: 1; margin-left: 12px; }
.rank-bet { font-weight: 700; color: var(--accent); }

/* === Tab Switch (in-page) === */
.tab-switch { display: flex; background: var(--border); border-radius: 8px; padding: 3px; margin-bottom: 16px; }
.tab-switch-item {
  flex: 1; padding: 8px; text-align: center; border-radius: 6px;
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.tab-switch-item.active { background: var(--white); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* === Checkin === */
.checkin-btn {
  width: 80px; height: 80px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 12px rgba(255,159,67,0.4);
}
.checkin-btn:disabled { background: #DFE6E9; color: var(--text-secondary); box-shadow: none; cursor: default; }

/* === Section Title === */
.section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* === Loading & Error === */
.loading { text-align: center; padding: 40px; color: var(--text-secondary); }
.error-page { text-align: center; padding: 40px; color: var(--red); }
.empty { text-align: center; padding: 32px; color: var(--text-secondary); font-size: 14px; }

/* === Invite Code === */
.invite-code-display {
  font-size: 32px; font-weight: 700; letter-spacing: 4px;
  text-align: center; color: var(--primary); padding: 20px;
}
.copy-btn {
  display: block; margin: 0 auto; padding: 8px 24px;
  border: 2px solid var(--primary); border-radius: var(--radius-btn);
  background: transparent; color: var(--primary); font-weight: 600; cursor: pointer;
}
.copy-btn:hover { background: var(--primary); color: #fff; }

/* === Stat Row === */
.stat-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-box {
  flex: 1; text-align: center; padding: 16px;
  background: var(--white); border-radius: var(--radius-btn); box-shadow: var(--shadow-card);
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* === Input === */
.input {
  width: 100%; padding: 12px; border: 2px solid var(--border);
  border-radius: var(--radius-btn); font-size: 16px; outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--primary); }

/* === Animations === */
@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* === Auto-mine === */
.auto-results { max-height: 300px; overflow-y: auto; }
.auto-status { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.auto-dot { width: 10px; height: 10px; border-radius: 50%; }
.auto-dot.running { background: var(--green); animation: pulse 1s infinite; }
.auto-dot.stopped { background: var(--red); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* === Responsive: PC === */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabbar {
    position: sticky; top: 0; bottom: auto; border-top: none;
    border-bottom: 1px solid var(--border); padding: 0; order: -1;
  }
  .tab-item { flex-direction: row; gap: 6px; padding: 12px 16px; font-size: 14px; }
  .tab-item .tab-icon { font-size: 18px; }
  main#app { max-width: 480px; margin: 20px auto; padding: 0 16px; }
}

/* === Page-level padding === */
.page { padding: 16px; }