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

:root {
  --bg-dark: #0c0e14;
  --bg-card: #13161f;
  --bg-card-hover: #1a1e2a;
  --bg-input: #0f1119;
  --accent: #f0a500;
  --accent-glow: rgba(240, 165, 0, 0.2);
  --accent-dim: rgba(240, 165, 0, 0.5);
  --accent-subtle: rgba(240, 165, 0, 0.06);
  --text: #e2e4e9;
  --text-dim: #8b8f9a;
  --text-muted: #555a66;
  --gold: #f0a500;
  --silver: #94a3b8;
  --bronze: #cd7f32;
  --green: #34d399;
  --red: #f87171;
  --blue: #60a5fa;
  --twitch: #9146ff;
  --discord: #5865f2;
  --border: rgba(255, 255, 255, 0.06);
  --radius: 12px;
}

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* === Ambient Glow Background === */
.bg-ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.07;
  animation: orbFloat 20s infinite ease-in-out;
}

.orb-1 { width: 400px; height: 400px; background: var(--accent); top: -10%; right: -5%; animation-delay: 0s; }
.orb-2 { width: 300px; height: 300px; background: #8b5cf6; bottom: 10%; left: -5%; animation-delay: -7s; animation-duration: 25s; }
.orb-3 { width: 250px; height: 250px; background: var(--accent); top: 40%; right: 50%; animation-delay: -12s; animation-duration: 30s; }

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.1); }
  66% { transform: translate(-20px, 30px) scale(0.9); }
}

/* === Layout === */
.app {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

/* === Header === */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

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

.header-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  transition: transform 0.2s;
}

.logo:hover { transform: scale(1.05); }

.logo-icon {
  font-size: 2rem;
  line-height: 1;
}

.logo-text {
  font-size: 1.7rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), #ffd166);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 3px;
}

/* Social buttons */
.social-links {
  display: flex;
  gap: 6px;
}

.social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: all 0.2s;
  text-decoration: none;
}

.twitch-btn:hover { color: var(--twitch); background: rgba(145, 70, 255, 0.1); }
.discord-btn:hover { color: var(--discord); background: rgba(88, 101, 242, 0.1); }

/* Auth */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-twitch {
  background: var(--twitch);
  color: white;
}

.btn-twitch:hover { background: #7c3aed; transform: translateY(-1px); }

.btn-twitch svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #0c0e14;
  font-weight: 800;
}

.btn-primary:hover { background: #d4920a; }

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-logout:hover { border-color: var(--accent); color: var(--accent); }

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-twitch-icon {
  color: var(--twitch);
  display: flex;
  align-items: center;
}

.user-name {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}

/* === Main === */
.main {
  padding: 28px 0 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === Sections === */
.section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-subtitle {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-dim);
}

/* === Balance Card === */
.balance-card {
  background: linear-gradient(135deg, #1a1508, #1f1a0a);
  border: 1px solid rgba(240, 165, 0, 0.15);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.balance-card::after {
  content: '\2B50';
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 4rem;
  opacity: 0.06;
}

.balance-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.balance-icon {
  color: var(--accent);
  font-size: 1.2rem;
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

.balance-label {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 600;
}

.balance-bottom {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.balance-amount {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
  direction: ltr;
  unicode-bidi: bidi-override;
}

.balance-unit {
  font-size: 1rem;
  color: var(--text-dim);
}

/* === Transfer === */
.transfer-box {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.transfer-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.transfer-form input {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.transfer-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.transfer-form input::placeholder { color: var(--text-muted); }

.message {
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.message.success { background: rgba(52, 211, 153, 0.1); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.15); }
.message.error { background: rgba(248, 113, 113, 0.1); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.15); }

/* === Games Grid === */
.games-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px 18px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.25s;
  text-decoration: none;
  color: var(--text);
  position: relative;
}

.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 30px var(--accent-glow);
}

.game-icon-wrap {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--accent-subtle);
  border: 1px solid rgba(240, 165, 0, 0.1);
}

.game-icon {
  font-size: 1.8rem;
}

.game-name {
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
}

.game-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 1px;
}

/* === Leaderboard === */
.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--bg-dark);
  border: 1px solid transparent;
  transition: all 0.2s;
}

.lb-item:hover { background: var(--bg-card-hover); }

.lb-item.top-1 { border-color: rgba(240, 165, 0, 0.2); background: rgba(240, 165, 0, 0.04); }
.lb-item.top-2 { border-color: rgba(148, 163, 184, 0.15); background: rgba(148, 163, 184, 0.03); }
.lb-item.top-3 { border-color: rgba(205, 127, 50, 0.15); background: rgba(205, 127, 50, 0.03); }

.lb-rank {
  width: 36px;
  text-align: center;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text-muted);
}

.top-1 .lb-rank { color: var(--gold); font-size: 1.2rem; }
.top-2 .lb-rank { color: var(--silver); }
.top-3 .lb-rank { color: var(--bronze); }

.lb-name {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
}

.lb-points {
  font-weight: 800;
  color: var(--accent);
  font-size: 0.95rem;
  direction: ltr;
}

.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 30px;
  font-size: 0.9rem;
}

/* === Commands === */
.commands-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-dark);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.cmd-code {
  background: var(--accent-subtle);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  direction: rtl;
  font-family: 'Cairo', monospace;
  border: 1px solid rgba(240, 165, 0, 0.1);
}

.cmd-bang {
  color: var(--accent);
  font-weight: 900;
}

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

/* === Game Page Shared Styles === */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-link:hover { color: var(--accent); }

.game-page-title {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--accent);
}

.game-balance-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: var(--text);
  font-size: 0.95rem;
}

.game-balance-display .pts {
  color: var(--accent);
  direction: ltr;
}

.game-area {
  max-width: 500px;
  margin: 0 auto;
}

.game-bet-section {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

.game-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  transition: border-color 0.2s;
  text-align: center;
}

.game-input:focus { outline: none; border-color: var(--accent); }
.game-input::placeholder { color: var(--text-muted); }

.game-btn {
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--accent);
  color: #0c0e14;
}

.game-btn:hover { background: #d4920a; transform: translateY(-1px); }
.game-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.game-result {
  text-align: center;
  padding: 20px;
  border-radius: var(--radius);
  margin-top: 16px;
  font-weight: 700;
  font-size: 1rem;
}

.game-result.win { background: rgba(52, 211, 153, 0.08); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.15); }
.game-result.lose { background: rgba(248, 113, 113, 0.08); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.15); }
.game-result.tie { background: rgba(96, 165, 250, 0.08); color: var(--blue); border: 1px solid rgba(96, 165, 250, 0.15); }
.game-result.info { background: var(--accent-subtle); color: var(--accent); border: 1px solid rgba(240, 165, 0, 0.15); }

.game-login-prompt {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.game-login-prompt a {
  color: var(--twitch);
  text-decoration: none;
  font-weight: 700;
}

/* === Utilities === */
.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 768px) {
  .games-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .app { padding: 0 14px; }

  .header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 0;
  }

  .header-right, .header-left {
    width: 100%;
    justify-content: center;
  }

  .balance-amount { font-size: 2.2rem; }
  .transfer-form { flex-direction: column; }

  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .game-card { padding: 18px 12px 14px; }
  .game-icon-wrap { width: 48px; height: 48px; }
  .game-icon { font-size: 1.5rem; }
  .game-name { font-size: 0.8rem; }
  .commands-grid { grid-template-columns: 1fr; }
  .section { padding: 18px 14px; }

  .game-header { flex-direction: column; gap: 10px; }
}
