:root {
  --bg-color: #0b0f19;
  --card-bg: #1e293b;
  --primary-color: #10b981;
  --primary-hover: #059669;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-red: #ef4444;
  --border-color: #334155;
  --radius: 16px;
  --font-family: 'Tajawal', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
}

.app-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.game-header {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-color);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Main */
.game-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Stats */
.stats-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-card.highlight {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.05);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Canvas Wrapper */
.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0f172a;
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Overlay */
.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 15, 25, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.game-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.overlay-icon {
  width: 56px;
  height: 56px;
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.large-icon {
  width: 28px;
  height: 28px;
}

.overlay-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.overlay-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.final-score-box {
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 1rem;
}

.final-score-box strong {
  color: var(--primary-color);
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

.primary-btn {
  background: var(--primary-color);
  color: #052e16;
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  width: 100%;
  justify-content: center;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

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

/* Controls */
.touch-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.touch-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dpad-row {
  display: flex;
  gap: 4px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.dpad-btn:active {
  background: var(--primary-color);
  color: #052e16;
}

/* Leaderboard */
.leaderboard-section {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-color);
}

.section-title h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

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

.loading-state, .empty-state {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 12px 0;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 12px;
  border-radius: 10px;
}

.rank-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #334155;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.rank-1 { background: #eab308; color: #422006; }
.rank-2 { background: #94a3b8; color: #0f172a; }
.rank-3 { background: #b45309; color: #fff; }

.player-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin: 0 12px;
}

.player-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.player-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.score-badge {
  font-weight: 700;
  color: var(--primary-color);
  font-size: 0.9rem;
}

/* Footer */
.game-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 8px 0;
}

/* Media Queries */
@media (min-width: 600px) {
  .touch-controls {
    display: none;
  }
}
