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

:root {
  --primary: #FF6B00;
  --primary-dark: #E05E00;
  --primary-light: #FF8533;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1c2a4a;
  --bg-input: #0f3460;
  --text-primary: #ffffff;
  --text-secondary: #a0a0c0;
  --text-muted: #6c6c8a;
  --success: #00c853;
  --danger: #ff1744;
  --warning: #ffab00;
  --orange-glow: rgba(255, 107, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --tab-bar-height: 64px;
  --header-height: 56px;
  --z-tab-bar: 1000;
  --z-modal: 2000;
  --z-toast: 3000;
  --z-loading: 4000;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  padding-bottom: var(--tab-bar-height);
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

/* ============ Loading Overlay ============ */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26, 26, 46, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  transition: opacity 0.3s;
}
.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-overlay p {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--text-muted);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Inline loading */
.inline-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}
.inline-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--text-muted);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: var(--z-toast);
  font-size: 14px;
  transition: all 0.3s ease;
  border-left: 4px solid var(--primary);
  max-width: 90vw;
  text-align: center;
}
.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
  pointer-events: none;
}
.toast.toast-error {
  border-left-color: var(--danger);
}
.toast.toast-success {
  border-left-color: var(--success);
}

/* ============ Page System ============ */
.page {
  display: none;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
}
.page.active {
  display: flex;
}

.page-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--bg-dark);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
  position: relative;
}
.page-header h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header-back {
  justify-content: flex-start;
  gap: 8px;
}
.page-header-back h1 {
  -webkit-text-fill-color: var(--text-primary);
  background: none;
  background-clip: unset;
  font-size: 16px;
}
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.back-btn:hover {
  background: rgba(255, 107, 0, 0.15);
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  padding-bottom: 20px;
  -webkit-overflow-scrolling: touch;
}

/* ============ Section ============ */
.section {
  margin-bottom: 20px;
}
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============ Sub Tabs ============ */
.sub-tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  background: var(--bg-dark);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}
.sub-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px 0;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}
.sub-tab::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 3px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  transition: width 0.2s;
}
.sub-tab.active {
  color: var(--primary);
}
.sub-tab.active::after {
  width: 40px;
}

/* ============ Cards ============ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:active {
  transform: scale(0.98);
}
.card-hover:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* ============ Live Match ============ */
.live-section {
  margin-bottom: 20px;
}
.live-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

.live-card {
  background: linear-gradient(135deg, var(--bg-card), #2a1a3e);
  border: 1px solid rgba(255, 107, 0, 0.3);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-shadow: 0 0 20px var(--orange-glow);
}
.live-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.live-team {
  flex: 1;
  text-align: center;
}
.live-team .team-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.live-team .team-score {
  font-size: 36px;
  font-weight: 900;
  color: var(--primary);
}
.score-colon {
  font-size: 36px;
  font-weight: 900;
  color: var(--text-muted);
  flex-shrink: 0;
}
.live-vs {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-muted);
  flex-shrink: 0;
}
.live-status {
  text-align: center;
  margin-top: 10px;
  font-size: 13px;
}
.live-status .qtr {
  color: var(--warning);
  font-weight: 600;
}

/* Blinking score for live */
.blink-score {
  animation: blink-score 1s ease-in-out infinite;
}
@keyframes blink-score {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ============ Match Card ============ */
.match-card {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.2s;
}
.match-card:hover {
  background: var(--bg-card-hover);
}
.match-teams {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.match-team {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}
.match-vs {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}
.match-score-display {
  flex-shrink: 0;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--primary);
  min-width: 60px;
}
.match-score-display.final {
  color: var(--text-primary);
}
.match-score-display .winner {
  color: var(--success);
}
.match-info {
  flex-shrink: 0;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 50px;
}
.match-info .match-time {
  font-size: 12px;
}
.match-info .match-location {
  font-size: 11px;
  opacity: 0.7;
}

/* ============ Rankings ============ */
.rank-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.rank-item:last-child {
  border-bottom: none;
}
.rank-number {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  margin-right: 12px;
  flex-shrink: 0;
}
.rank-1 {
  background: linear-gradient(135deg, #ffd700, #ffb300);
  color: #1a1a2e;
}
.rank-2 {
  background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
  color: #1a1a2e;
}
.rank-3 {
  background: linear-gradient(135deg, #cd7f32, #b8860b);
  color: #1a1a2e;
}
.rank-other {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 13px;
}

.rank-info {
  flex: 1;
}
.rank-name {
  font-size: 15px;
  font-weight: 600;
}
.rank-team {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.rank-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
}

/* ============ Betting ============ */
.betting-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.betting-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}
.betting-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  border: 2px solid transparent;
}
.bet-option:hover {
  background: rgba(255, 255, 255, 0.08);
}
.bet-option.selected {
  border-color: var(--primary);
  background: rgba(255, 107, 0, 0.1);
}
.bet-option .option-label {
  font-size: 14px;
  font-weight: 500;
}
.bet-option .option-odds {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

/* Betting Record */
.section-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 0 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.bet-record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.bet-record:last-child {
  border-bottom: none;
}
.bet-record-title {
  flex: 1;
  color: var(--text-secondary);
}
.bet-record-option {
  flex: 1;
  text-align: center;
  font-size: 12px;
}
.bet-record-amount {
  font-weight: 700;
  font-size: 14px;
}
.bet-record-amount.won {
  color: var(--success);
}
.bet-record-amount.pending {
  color: var(--warning);
}
.bet-record-amount.lost {
  color: var(--danger);
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: 20px;
  transition: opacity 0.25s;
}
.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-body {
  padding: 20px;
}
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.modal-footer .btn {
  flex: 1;
}

.bet-modal-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.bet-modal-option {
  font-size: 13px;
  color: var(--primary);
  margin-bottom: 16px;
}
.bet-input-group {
  margin-bottom: 12px;
}
.bet-input-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.bet-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.bet-input:focus {
  border-color: var(--primary);
}
.bet-input::-webkit-outer-spin-button,
.bet-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.bet-input[type=number] {
  -moz-appearance: textfield;
}

.bet-quick-btns {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.quick-btn {
  flex: 1;
  background: rgba(255, 107, 0, 0.1);
  border: 1px solid rgba(255, 107, 0, 0.2);
  color: var(--primary);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.quick-btn:hover,
.quick-btn.active {
  background: var(--primary);
  color: #fff;
}

.bet-error {
  font-size: 13px;
  color: var(--danger);
  margin-top: 8px;
}
.bet-error.hidden {
  display: none;
}

/* ============ Buttons ============ */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}
.btn-block {
  display: block;
  width: 100%;
}

/* ============ Profile ============ */
.profile-header-card {
  background: linear-gradient(135deg, var(--bg-card), #2a1a3e);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 107, 0, 0.2);
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 12px;
  box-shadow: 0 0 20px var(--orange-glow);
}
.profile-name {
  font-size: 18px;
  font-weight: 700;
}
.profile-points {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}
.profile-points-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.checkin-btn {
  margin-top: 14px;
  padding: 10px 32px;
  border-radius: 24px;
  font-size: 15px;
}
.checkin-btn.done {
  background: rgba(0, 200, 83, 0.15);
  color: var(--success);
  border: 1px solid rgba(0, 200, 83, 0.3);
  cursor: default;
}
.checkin-btn.done:hover {
  background: rgba(0, 200, 83, 0.15);
}

/* Points log */
.points-log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.points-log-item:last-child {
  border-bottom: none;
}
.points-log-desc {
  flex: 1;
}
.points-log-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.points-log-amount {
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.points-log-amount.positive {
  color: var(--success);
}
.points-log-amount.negative {
  color: var(--danger);
}

/* ============ Match Detail ============ */
.detail-match-header {
  text-align: center;
  padding: 20px 0;
}
.detail-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.detail-team {
  flex: 1;
  text-align: center;
}
.detail-team .team-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}
.detail-team .team-score {
  font-size: 48px;
  font-weight: 900;
}
.detail-team .team-score.winner {
  color: var(--primary);
}
.detail-vs {
  font-size: 28px;
  color: var(--text-muted);
  font-weight: 800;
  flex-shrink: 0;
}
.detail-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}
.detail-info span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Player Stats Table */
.player-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}
.player-stats-table th {
  text-align: left;
  padding: 8px 6px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  white-space: nowrap;
}
.player-stats-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  white-space: nowrap;
}
.player-stats-table .player-name-cell {
  font-weight: 600;
}

/* Vote Section */
.vote-section {
  margin-top: 16px;
}
.vote-btn {
  display: block;
  width: 100%;
  padding: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-top: 10px;
}
.vote-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--orange-glow);
}
.vote-btn:disabled {
  opacity: 0.5;
  transform: none;
  cursor: not-allowed;
}

.vote-stats {
  margin-top: 16px;
}
.vote-stat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 13px;
}
.vote-stat-name {
  min-width: 60px;
  font-weight: 600;
}
.vote-stat-bar-wrap {
  flex: 1;
  height: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
.vote-stat-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  transition: width 0.6s ease;
}
.vote-stat-count {
  min-width: 36px;
  text-align: right;
  font-weight: 600;
  color: var(--primary);
}

/* Vote Modal */
.vote-hint {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.vote-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.vote-player-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.vote-player-option:hover {
  background: rgba(255, 255, 255, 0.08);
}
.vote-player-option.selected {
  border-color: var(--primary);
  background: rgba(255, 107, 0, 0.1);
}
.vote-player-option .vp-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
}
.vote-player-option .vp-team {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============ Empty State ============ */
.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ============ Tab Bar ============ */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-height);
  background: var(--bg-dark);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  z-index: var(--z-tab-bar);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  padding: 6px 0;
}
.tab-item .tab-icon {
  font-size: 22px;
  line-height: 1;
}
.tab-item .tab-label {
  font-size: 11px;
  font-weight: 500;
}
.tab-item.active {
  color: var(--primary);
}
.tab-item.active .tab-icon {
  transform: scale(1.1);
}

/* ============ Responsive Desktop ============ */
@media (min-width: 768px) {
  body {
    display: flex;
    justify-content: center;
    background: #0d0d1a;
  }
  .page, .tab-bar {
    max-width: 480px;
    margin: 0 auto;
  }
  .tab-bar {
    left: auto;
    right: auto;
    width: 480px;
    border-radius: 0 0 16px 16px;
  }
  .page-header {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }
  .page-header-back {
    max-width: 480px;
  }
}
