:root {
  --bg-color: #ffffff;
  --card-bg: #ffffff;
  --card-border: #f3c1c6;
  --card-hover: #fff5f5;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --gold: #e30613;
  --gold-glow: rgba(227, 6, 19, 0.15);
  --red: #e30613;
  --red-glow: rgba(227, 6, 19, 0.2);
  --green: #059669;
  --cyan: #0369a1;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: hidden;
  background-image:
    radial-gradient(circle at 50% 0%, rgba(227, 6, 19, 0.07) 0%, transparent 60%),
    radial-gradient(circle at 90% 100%, rgba(227, 6, 19, 0.04) 0%, transparent 40%);
}

.container {
  width: 100%;
  max-width: 520px;
  padding: 16px 20px 40px;
}

.container-wide {
  width: 100%;
  max-width: 1100px;
  padding: 24px 32px 50px;
}

/* Player horizontal layout: 1 cot tren mobile, 2 cot tu desktop */
.play-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.play-grid .card {
  margin-bottom: 0;
}

@media (min-width: 900px) {
  .container {
    max-width: 1020px;
  }
  .play-grid {
    grid-template-columns: 1.15fr 1fr;
    align-items: start;
  }
  #cardPlayer,
  #cardActions,
  #resultSection {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  /* Tránh huy hiệu đè lên nút Âm thanh (absolute góc phải) */
  .container {
    padding-top: 60px;
  }
}

/* Header & Banner */
header {
  text-align: center;
  margin-bottom: 20px;
  position: relative;
}

.badge-tag {
  display: inline-block;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold);
  background: rgba(227, 6, 19, 0.08);
  border: 1px solid rgba(227, 6, 19, 0.3);
  border-radius: 999px;
  margin-bottom: 8px;
}

h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.25;
  background: linear-gradient(135deg, #e30613 20%, #7f1d1d 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Card Box */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 10px 25px -5px rgba(227, 6, 19, 0.12);
  position: relative;
  overflow: hidden;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Inputs */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: #f9fafb;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-size: 15px;
  color: #111827;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

/* Big Balance Display */
.balance-display {
  text-align: center;
  padding: 16px 0;
}

.balance-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.balance-amount {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: -1px;
  color: #111827;
  font-variant-numeric: tabular-nums;
  margin: 4px 0;
}

.balance-change {
  font-size: 14px;
  font-weight: 700;
}

.loss-negative {
  color: var(--red);
}

.profit-positive {
  color: var(--green);
}

/* Stat Grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.stat-item {
  background: rgba(227, 6, 19, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-val {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #111827;
}

.stat-lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Prize List */
.prize-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.prize-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.prize-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
}

.pill-jackpot {
  background: #f59e0b;
  color: #000;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

.pill-1 { background: #ef4444; color: #fff; }
.pill-2 { background: #3b82f6; color: #fff; }
.pill-3 { background: #10b981; color: #fff; }

.prize-count {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

/* Buttons */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, #f5222d, #c00511);
  color: #fff;
  box-shadow: 0 4px 15px var(--red-glow);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff4d4f, #e30613);
  box-shadow: 0 6px 20px var(--red-glow);
}

.btn-gold {
  background: linear-gradient(135deg, #f5222d, #c00511);
  color: #fff;
  box-shadow: 0 4px 15px var(--gold-glow);
}

.btn-gold:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff4d4f, #e30613);
}

.btn-secondary {
  background: #f3f4f6;
  border: 1px solid var(--card-border);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
}

/* Progress Bar */
.progress-container {
  margin: 12px 0 6px;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #fee2e2;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), #7f1d1d);
  border-radius: 999px;
  transition: width 0.15s linear;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Cash-flow chart */
.chart-container {
  margin: 12px 0 4px;
}

.chart-title {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

#cashChart {
  width: 100%;
  height: 120px;
  display: block;
  background: #fff5f5;
  border: 1px solid var(--card-border);
  border-radius: 10px;
}

/* Audio control toggle */
.audio-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #ffffff;
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Host / Projector Layout */
.host-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .host-grid {
    grid-template-columns: 1fr;
  }
}

.qr-box {
  background: #fff;
  border: 2px solid var(--card-border);
  padding: 16px;
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px auto;
  width: 200px;
  height: 200px;
}

.qr-box svg, .qr-box img {
  width: 100%;
  height: 100%;
}

.timer-box {
  text-align: center;
  padding: 16px;
  background: rgba(227, 6, 19, 0.06);
  border: 1px solid rgba(227, 6, 19, 0.25);
  border-radius: 14px;
  margin-bottom: 16px;
}

.timer-val {
  font-size: 48px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--red);
  letter-spacing: -1px;
}

/* Leaderboard Table */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--card-border);
}

td {
  padding: 12px;
  border-bottom: 1px solid #f3f4f6;
}

tr:hover td {
  background: #fff5f5;
}

.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 12px;
}

.rank-1 { background: var(--gold); color: #fff; box-shadow: 0 0 10px var(--gold-glow); }
.rank-2 { background: #94a3b8; color: #000; }
.rank-3 { background: #b45309; color: #fff; }
.rank-other { background: #f3f4f6; color: var(--text-muted); }

/* Animation pulse */
@keyframes pulseGlow {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.animate-pulse {
  animation: pulseGlow 1.5s infinite ease-in-out;
}

/* Welcome Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 0 40px var(--gold-glow), 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: modalPop 0.3s ease-out;
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: -0.5px;
  margin: 4px 0 2px;
}

.modal-joke {
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.55;
  margin: 10px 0 18px;
}

.modal-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
}

@keyframes modalPop {
  from { transform: scale(0.9) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
