:root {
  --bg-dark: #0f1923;
  --bg-panel: #1b2733;
  --primary: #00e676;
  --accent: #00e676;
  --text-main: #ffffff;
  --text-dim: #8b9bb4;
  --border: #2c3e50;
  --crash-color: #ff3d00;
}

* {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* Header */
.game-header {
  height: 60px;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  justify-content: space-between;
}

.logo {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--primary);
}

.history-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 0 20px;
  mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
}

.history-item {
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.85rem;
  font-weight: bold;
  white-space: nowrap;
}

.history-item.crash { color: var(--text-dim); }
.history-item.win { color: var(--accent); }
.history-item.high { color: #ffd700; box-shadow: 0 0 5px rgba(255, 215, 0, 0.3); }

.wallet-info {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 12px;
  border-radius: 20px;
  font-family: monospace;
  font-size: 1.1rem;
}

.currency-symbol {
  color: var(--accent);
  margin-right: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-auth {
  background: var(--accent);
  color: #003300;
  border: none;
  padding: 8px 14px;
  border-radius: 18px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 1px;
}

.btn-auth:hover {
  filter: brightness(1.05);
}

.btn-header-tool {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 18px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-header-tool:hover {
  background: rgba(255,255,255,0.08);
}

.mode-tag {
  margin-left: 10px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--accent);
  border: 1px solid rgba(0, 230, 118, 0.35);
  background: rgba(0, 230, 118, 0.08);
}

/* Stage */
.game-stage {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #1a2c3d 0%, var(--bg-dark) 100%);
  overflow: hidden;
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  gap: 14px;
  padding: 14px 20px;
}

.stage-left,
.stage-center {
  min-height: 0;
}

.canvas-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.multiplier-display {
  font-size: 5rem;
  font-weight: 800;
  text-shadow: 0 0 20px rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
}

.status-message {
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-top: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* 倒计时样式 */
.countdown-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.countdown-label {
  font-size: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.countdown-number {
  font-size: 6rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(0, 230, 118, 0.5);
  line-height: 1;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Control Panel */
.control-panel {
  background: var(--bg-panel);
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 20px;
  align-items: stretch;
  height: 180px;
}

.bet-panel-wrapper {
  flex: 1;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  gap: 15px;
  align-items: center;
  border: 1px solid var(--border);
  position: relative; /* 为 win-overlay 定位 */
}

/* 结算成功弹窗 */
.win-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  left: auto;
  bottom: auto;
  min-width: 170px;
  padding: 10px 12px;
  background: rgba(0, 230, 118, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 10;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  color: #003300;
  pointer-events: none;
}

.win-overlay.fade-out {
  opacity: 0;
  transition: opacity 0.5s;
}

.win-amt { font-size: 1.8rem; font-weight: 800; }
.win-mult { font-size: 1.2rem; font-weight: bold; opacity: 0.8; }

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 排行榜面板 */
.leaderboard-panel {
  width: 100%;
  height: 100%;
  background: rgba(27, 39, 51, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(10px);
  overflow: auto;
}

.leaderboard-panel h3 { margin: 0 0 10px 0; font-size: 1rem; color: var(--accent); }

.lb-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-title {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.72);
  letter-spacing: 0.5px;
}

.lb-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 10px 0;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  font-size: 0.85rem;
}

.rank-item.me { border: 1px solid var(--accent); background: rgba(0, 230, 118, 0.1); }
.rank-name { flex: 1; }
.rank-mult { color: var(--accent); font-weight: bold; width: 60px; text-align: right; }
.rank-win { width: 80px; text-align: right; font-family: monospace; }

.bet-type-toggle {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(0,0,0,0.3);
  padding: 4px;
  border-radius: 20px;
  height: fit-content;
}

.bet-type-toggle button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 15px;
  border-radius: 15px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.bet-type-toggle button.active {
  background: var(--border);
  color: white;
}

.bet-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-row {
  display: flex;
  gap: 15px;
  align-items: center;
}

.auto-config {
  background: rgba(0,0,0,0.15);
  padding: 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.auto-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.auto-row input {
  width: 70px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: white;
  border-radius: 4px;
  padding: 2px 5px;
  text-align: center;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch label {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255,255,255,0.12);
  transition: background-color .2s, box-shadow .2s;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
}

.toggle-switch label:before {
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 2px; bottom: 2px;
  background-color: white;
  transition: transform .2s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.toggle-switch input:checked + label {
  background-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 230, 118, 0.15);
  border-color: transparent;
}

.toggle-switch input:checked + label:before {
  transform: translateX(24px);
}

.input-group {
  display: flex;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 4px;
  border: 1px solid var(--border);
}

.input-group input {
  flex: 1;
  background: transparent;
  border: none;
  color: white;
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
}

.btn-adjust {
  width: 40px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.2rem;
}

.quick-bets {
  display: flex;
  gap: 8px;
}

.quick-bets button {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim);
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-bets button:hover {
  background: rgba(255,255,255,0.15);
  color: white;
}

.action-buttons {
  width: 200px;
  display: flex;
  flex-direction: column;
}

.btn-main {
  flex: 1;
  border: none;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 0.1s, filter 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

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

.btn-bet {
  background: linear-gradient(135deg, #00e676, #00c853);
  color: #003300;
  box-shadow: 0 4px 15px rgba(0, 230, 118, 0.3);
}

.btn-cashout {
  background: linear-gradient(135deg, #ffab00, #ff6d00);
  color: #3e2723;
  box-shadow: 0 4px 15px rgba(255, 171, 0, 0.3);
}

.btn-auto {
  background: linear-gradient(135deg, #2196f3, #1976d2);
  color: white;
  box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

.btn-auto:hover {
  filter: brightness(1.1);
}

.btn-bet:disabled, .btn-cashout:disabled, .btn-auto:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.2);
}

/* Education */
.education-rail {
  width: 100%;
  height: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(27, 39, 51, 0.75);
  backdrop-filter: blur(12px);
  box-shadow: 0 15px 40px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.education-header {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 10px;
}

.education-title {
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.education-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
}

#gamma-edu-canvas {
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
}

/* Panels */
.panel {
  position: absolute;
  top: 100px;
  right: 20px;
  width: 320px;
  background: rgba(27, 39, 51, 0.98);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  backdrop-filter: blur(15px);
  box-shadow: 0 15px 40px rgba(0,0,0,0.6);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 { margin: 0; font-size: 1rem; }

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}

.settings-content, .log-content, .fairness-content, .auth-content {
  padding: 15px;
  overflow-y: auto;
}

.auth-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.auth-tab {
  flex: 1;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-dim);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.auth-tab.active {
  background: rgba(0, 230, 118, 0.15);
  border-color: rgba(0, 230, 118, 0.35);
  color: var(--text-main);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-form label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.auth-form input {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: white;
  padding: 10px;
  border-radius: 8px;
}

.btn-auth-submit {
  margin-top: 6px;
  background: var(--accent);
  color: #003300;
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px 0;
  text-align: left;
}

.btn-link:hover {
  color: white;
}

.auth-user-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 10px;
}

.setting-item {
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.setting-item label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.setting-item input {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: white;
  padding: 8px;
  border-radius: 4px;
}

.fairness-row {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
}

.fairness-row label {
  color: var(--text-dim);
}

.fairness-value {
  font-family: monospace;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 4px;
  word-break: break-all;
}

.fairness-input {
  display: flex;
  gap: 8px;
}

.fairness-input input {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: white;
  padding: 6px 8px;
  border-radius: 4px;
}

.setting-item small {
  font-size: 0.7rem;
  color: #666;
}

.hidden { display: none; }

.log-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-item {
  font-size: 0.85rem;
  line-height: 1.4;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding-bottom: 5px;
}

.log-time { color: var(--text-dim); margin-right: 5px; }

.crash-record {
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
  border-radius: 4px;
}

.log-crash-point {
  color: var(--crash-color);
  font-weight: bold;
}

.log-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  font-family: monospace;
  font-size: 0.75rem;
}

.btn-verify {
  background: var(--border);
  border: none;
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-verify:hover {
  background: var(--text-dim);
}

/* Responsive */
@media (max-width: 900px) {
  .control-panel {
    flex-direction: column;
    height: auto;
    overflow-y: auto;
  }
  .bet-panel-wrapper {
    width: 100%;
    min-height: 100px;
  }
}

@media (max-width: 600px) {
  .multiplier-display {
    font-size: 3.5rem;
  }
  .history-bar {
    padding: 0 10px;
  }
}
