/* Game Page Styles */
.game-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 10;
}

.game-header-left, .game-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-badge {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 0.9rem;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
}

.game-ad-top {
  flex-shrink: 0;
}

.game-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.game-sidebar {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  background: var(--surface);
  flex-shrink: 0;
}

.game-canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

#game-canvas {
  cursor: pointer;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: none;
}

#game-canvas.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.game-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  flex-shrink: 0;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  transition: all 0.15s;
  min-width: 70px;
}

.control-btn:hover { border-color: var(--primary); background: #e8f4fd; }
.control-btn:active { transform: scale(0.95); }
.control-btn .icon { font-size: 1.4rem; }

.game-ad-bottom {
  flex-shrink: 0;
}

/* Level Complete Overlay */
.complete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  padding: 16px;
}

.complete-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.complete-modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  animation: popIn 0.4s ease;
}

@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.complete-modal h2 {
  font-size: 1.6rem;
  margin-bottom: 16px;
  color: var(--success);
}

.complete-stars {
  font-size: 2rem;
  margin-bottom: 16px;
}

.complete-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.complete-stat {
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius-sm);
}

.complete-stat label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 4px;
}

.complete-stat span {
  font-size: 1.2rem;
  font-weight: 800;
}

.complete-coins {
  color: var(--warning);
  font-weight: 800;
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Level Selection */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
  padding: 8px 0;
}

.level-card {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s;
  position: relative;
  border: 2px solid transparent;
}

.level-card:hover { transform: scale(1.05); border-color: var(--primary); }
.level-card.completed { border-color: var(--success); }

.level-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.level-num {
  font-weight: 800;
  font-size: 1.1rem;
}

.level-stars {
  font-size: 0.6rem;
  margin-top: 2px;
}

.level-lock { font-size: 1.2rem; }

.theme-group {
  margin-bottom: 24px;
}

.theme-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--primary);
}

.theme-range {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.85rem;
}

/* Theme colors for level cards */
.level-card[data-theme="city-center"] { border-top: 3px solid #4a90d9; }
.level-card[data-theme="heavy-traffic"] { border-top: 3px solid #e74c3c; }
.level-card[data-theme="parking"] { border-top: 3px solid #f39c12; }
.level-card[data-theme="airport"] { border-top: 3px solid #0984e3; }
.level-card[data-theme="beach"] { border-top: 3px solid #00b894; }
.level-card[data-theme="night-city"] { border-top: 3px solid #a29bfe; }
.level-card[data-theme="snow-city"] { border-top: 3px solid #74b9ff; }
.level-card[data-theme="construction"] { border-top: 3px solid #fdcb6e; }
.level-card[data-theme="terminal"] { border-top: 3px solid #6c5ce7; }
.level-card[data-theme="ultimate"] { border-top: 3px solid #e17055; }

.star.filled { }
.star.empty { opacity: 0.3; }

/* Profile */
.profile-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 500px;
  margin: 0 auto 24px;
  text-align: center;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin: 0 auto 12px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.profile-stat {
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius-sm);
}

.profile-stat label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
}

.profile-stat span {
  font-size: 1.3rem;
  font-weight: 800;
}

/* Achievements */
.achievement-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}

.achievement-card.locked { opacity: 0.5; }
.ach-icon { font-size: 2rem; }
.ach-info h4 { font-size: 0.95rem; margin-bottom: 2px; }
.ach-info p { font-size: 0.8rem; color: var(--text-light); }
.ach-badge { margin-left: auto; font-size: 1.2rem; }

/* Daily rewards */
.daily-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.daily-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  border: 2px solid transparent;
}

.daily-card.current { border-color: var(--primary); background: #e8f4fd; }
.daily-card.claimed { opacity: 0.6; }
.daily-day { display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-light); }
.daily-reward-icon { font-size: 1.5rem; display: block; margin: 4px 0; }
.daily-amount { font-size: 0.8rem; font-weight: 700; }
.daily-check { position: absolute; top: 4px; right: 4px; color: var(--success); }

/* Missions */
.mission-card {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}

.mission-card.done { opacity: 0.6; }
.mission-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.mission-progress .progress-bar { flex: 1; height: 8px; }
.mission-reward { font-weight: 700; color: var(--warning); }

/* Settings */
.settings-group {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg);
}

.setting-row:last-child { border-bottom: none; }

.toggle {
  width: 48px;
  height: 26px;
  background: #dfe6e9;
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.toggle.active { background: var(--success); }

.toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle.active::after { transform: translateX(22px); }

/* Loading */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-screen {
  text-align: center;
  padding: 40px;
}

.error-screen h2 { color: var(--danger); margin-bottom: 12px; }

/* Editor */
.editor-layout {
  display: grid;
  grid-template-columns: 250px 1fr 250px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 60px);
}

.editor-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.editor-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--primary);
}

.editor-tool {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--bg);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all 0.15s;
}

.editor-tool:hover, .editor-tool.active {
  border-color: var(--primary);
  background: #e8f4fd;
}

.editor-canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}

#editor-canvas {
  cursor: crosshair;
}

.editor-field {
  margin-bottom: 10px;
}

.editor-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-light);
}

.editor-field input, .editor-field select {
  width: 100%;
  padding: 8px;
  border: 1px solid #dfe6e9;
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.editor-output {
  width: 100%;
  height: 200px;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 8px;
  border: 1px solid #dfe6e9;
  border-radius: var(--radius-sm);
  resize: vertical;
}

.validation-result {
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  font-size: 0.85rem;
}

.validation-result.valid { background: #d4edda; color: #155724; }
.validation-result.invalid { background: #f8d7da; color: #721c24; }

@media (max-width: 768px) {
  .game-sidebar { width: 56px; }
  .control-btn { min-width: 56px; padding: 8px 10px; }
  .control-btn span { display: none; }
  .game-main { flex-direction: column; }
  .editor-layout { grid-template-columns: 1fr; height: auto; }
}

@media (min-width: 769px) {
  .game-page {
    max-width: 900px;
    margin: 0 auto;
    border-left: 1px solid #dfe6e9;
    border-right: 1px solid #dfe6e9;
  }
}
