/* Color System & Variables */
:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --card-bg: rgba(17, 24, 39, 0.7);
  --card-border: rgba(255, 255, 255, 0.08);
  
  --text-primary: #f3f4f6;
  --text-muted: #9ca3af;
  
  --accent-primary: #8b5cf6; /* Violet */
  --accent-primary-glow: rgba(139, 92, 246, 0.4);
  --accent-secondary: #06b6d4; /* Cyan */
  --accent-secondary-glow: rgba(6, 182, 212, 0.3);
  
  --player-car: #ef4444; /* Red */
  --player-car-glow: rgba(239, 68, 68, 0.5);
  
  --board-bg: #1e293b;
  --cell-border: rgba(255, 255, 255, 0.04);
  --cell-bg-dot: rgba(255, 255, 255, 0.03);
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* Decorative Glow Circles */
.glow {
  position: absolute;
  width: 40vw;
  height: 40vw;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.3;
  pointer-events: none;
}
.glow-1 {
  background: var(--accent-primary);
  top: -10%;
  left: -10%;
}
.glow-2 {
  background: var(--accent-secondary);
  bottom: -10%;
  right: -10%;
}

/* Main Container Layout */
.container {
  width: 100%;
  max-width: 1100px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  z-index: 10;
}

/* Header Styles */
.app-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, #fff 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-shadow: 0 0 20px rgba(139, 92, 246, 0.2);
}

.logo-emoji {
  -webkit-text-fill-color: initial;
  filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.3));
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 300;
  max-width: 500px;
}

.level-badge-container {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}

.badge-date {
  color: var(--accent-secondary);
  border-color: rgba(6, 182, 212, 0.2);
  background: rgba(6, 182, 212, 0.05);
}

.badge-difficulty {
  color: #fbbf24; /* Amber */
  border-color: rgba(251, 191, 36, 0.2);
  background: rgba(251, 191, 36, 0.05);
}

.badge-par {
  color: #c084fc; /* light violet */
  border-color: rgba(192, 132, 252, 0.2);
  background: rgba(192, 132, 252, 0.05);
}

/* Glassmorphism Cards */
.card-glass {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Main Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 2rem;
  width: 100%;
}

@media (max-width: 850px) {
  .game-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

/* Stats and Game Section */
.game-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 0.75rem 1.25rem;
  border-radius: 16px;
  gap: 1rem;
}

.stat-box {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
}

.font-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Buttons */
.btn {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary) 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.6);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.icon-btn {
  width: 1.1rem;
  height: 1.1rem;
}

/* Game Board Wrapper & Exit Gate */
.board-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 480px;
  margin: 0 auto;
  padding-right: 18px; /* Room for exit path styling */
}

/* Exit Gate styling on the right (row 2) */
.exit-gate {
  position: absolute;
  right: -10px;
  top: calc(2 * 100% / 6);
  height: calc(100% / 6);
  width: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0) 100%);
  border-right: 3px solid var(--player-car);
  border-top: 2px dashed rgba(239, 68, 68, 0.4);
  border-bottom: 2px dashed rgba(239, 68, 68, 0.4);
  z-index: 5;
  box-shadow: 10px 0 15px rgba(239, 68, 68, 0.15);
  animation: exit-glow 2s infinite alternate;
}

@keyframes exit-glow {
  0% {
    box-shadow: 0 0 5px rgba(239, 68, 68, 0.1);
    border-right-color: rgba(239, 68, 68, 0.6);
  }
  100% {
    box-shadow: 5px 0 20px rgba(239, 68, 68, 0.4);
    border-right-color: rgba(239, 68, 68, 1);
  }
}

.exit-arrow {
  color: var(--player-car);
  font-size: 1.1rem;
  font-weight: 800;
  animation: arrow-bounce 1s infinite alternate;
}

@keyframes arrow-bounce {
  0% { transform: translateX(-2px); }
  100% { transform: translateX(3px); }
}

.exit-text {
  font-size: 0.5rem;
  font-weight: 800;
  color: var(--player-car);
  letter-spacing: 0.05em;
  margin-top: -2px;
}

/* Game Board */
.board {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: var(--board-bg);
  border-radius: 20px;
  border: 4px solid #334155;
  box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.5), 0 10px 35px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

/* Grid lines overlay */
.board-grid-bg {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.board-grid-bg::after {
  content: '';
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  background-image: 
    linear-gradient(to right, var(--cell-border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--cell-border) 1px, transparent 1px);
  background-size: calc(100% / 6) calc(100% / 6);
  pointer-events: none;
}

/* Optional Dot pattern in the middle of each cell for raw premium texture */
.board-grid-bg::before {
  content: '';
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  background-image: radial-gradient(var(--cell-bg-dot) 2px, transparent 2px);
  background-size: calc(100% / 6) calc(100% / 6);
  background-position: calc(100% / 12) calc(100% / 12);
  pointer-events: none;
}

/* Vehicles styling */
.vehicle {
  position: absolute;
  padding: 6px;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s ease;
  z-index: 10;
}

.vehicle:active {
  cursor: grabbing;
}

.vehicle.dragging {
  transition: none; /* No transition during mouse drag */
  z-index: 20;
}

/* Inside vehicle design card container (Simplified for SVGs) */
.vehicle svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
  transition: filter 0.15s ease;
}

.vehicle:hover svg,
.vehicle.dragging svg {
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}

/* Target Car Red Sports glow */
.vehicle-target {
  filter: drop-shadow(0 0 8px var(--player-car-glow));
}

/* Tips section */
.tips-box {
  display: flex;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  align-items: flex-start;
}

.icon-tip {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--accent-secondary);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* Leaderboard Section Styling */
.leaderboard-section {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: fit-content;
}

.section-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.5rem;
}

.leaderboard-container {
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.leaderboard-table th {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard-table td {
  padding: 0.85rem 0.5rem;
  font-size: 0.95rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.leaderboard-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Rank numbers styling */
.rank-badge {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
}

.rank-1 {
  background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}
.rank-2 {
  background: linear-gradient(135deg, #94a3b8 0%, #475569 100%);
  box-shadow: 0 0 10px rgba(148, 163, 184, 0.3);
}
.rank-3 {
  background: linear-gradient(135deg, #b45309 0%, #78350f 100%);
  box-shadow: 0 0 10px rgba(180, 83, 9 0.3);
}
.rank-other {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent-secondary); }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }

/* Modal & Dialog Styling */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--card-border);
  padding: 2.25rem;
  width: 90%;
  max-width: 420px;
  color: var(--text-primary);
  outline: none;
  z-index: 100;
}

.modal::backdrop {
  background: rgba(4, 6, 12, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade-in 0.3s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  text-align: center;
}

.victory-header h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, #fff 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.trophy-emoji {
  font-size: 3.5rem;
  animation: trophy-bounce 0.8s infinite alternate cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes trophy-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.1); }
}

.victory-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 16px;
}

.v-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.v-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.v-value {
  font-size: 1.3rem;
  font-weight: 800;
}

.leaderboard-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.leaderboard-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.5rem;
  text-align: left;
}

.leaderboard-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 1rem;
  outline: none;
  transition: all 0.2s;
  text-align: center;
}

.leaderboard-form input:focus {
  border-color: var(--accent-primary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.modal-actions button {
  flex: 1;
  justify-content: center;
}

/* Footer Styling */
.app-footer {
  text-align: center;
  color: rgba(255, 255, 255, 0.2);
  font-size: 0.8rem;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

/* Adsense Container Styling */
.ads-container {
  margin-top: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.ad-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.ad-placeholder-content {
  width: 100%;
  min-height: 90px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.ad-mock-text {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.15);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* Modal Submission Prevention Styles */
.already-submitted-msg {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  border: 1px solid rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.05);
  color: #f87171; /* red-400 */
  margin-top: 0.25rem;
}

.hidden {
  display: none !important;
}
