* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #2ecc71 0%, #e67e22 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  padding: calc(20px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 20px)) max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 20px));
  -webkit-tap-highlight-color: transparent;
}

.container {
  position: relative;
  background: white;
  border-radius: 24px;
  padding: 36px;
  max-width: 640px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ANA EKRAN ===== */
.game-title {
  text-align: center;
  font-size: 2.5rem;
  color: #27ae60;
  margin-bottom: 8px;
  font-weight: 800;
}

.game-subtitle {
  text-align: center;
  font-size: 1.1rem;
  color: #888;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.form-group input[type="text"] {
  width: 100%;
  padding: 14px 18px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 14px;
  outline: none;
  transition: border-color 0.3s;
  -webkit-appearance: none;
}

.form-group input[type="text"]:focus {
  border-color: #2ecc71;
}

.difficulty-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.difficulty-btn {
  flex: 1;
  padding: 14px 8px;
  font-size: 1rem;
  font-weight: 600;
  border: 3px solid #ddd;
  border-radius: 14px;
  background: white;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.difficulty-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.difficulty-btn:active {
  transform: translateY(0);
}

.grade-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.difficulty-btn.selected {
  border-color: var(--grade-color, #2ecc71);
  background: #f0f4ff;
  color: var(--grade-color, #2ecc71);
}

.car-preview {
  text-align: center;
  font-size: 3rem;
  margin: -8px 0 8px;
  animation: carBounce 0.5s ease;
}

@keyframes carBounce {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.start-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.3s;
  min-height: 52px;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(46, 204, 113, 0.4);
}

.start-btn:active {
  transform: translateY(0);
}

/* ===== OYUN EKRANI ===== */
.question-bar {
  background: linear-gradient(135deg, #e8f8f0 0%, #fef5e7 100%);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 8px;
  text-align: center;
  transition: box-shadow 0.3s, border-color 0.3s;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.question-bar.waiting {
  border-color: rgba(46, 204, 113, 0.35);
  animation: barGlow 1.8s ease-in-out infinite;
}

.question-bar.answered {
  border-color: transparent;
  box-shadow: none;
  animation: none;
}

@keyframes barGlow {
  0%, 100% { box-shadow: 0 0 6px rgba(46, 204, 113, 0.08); border-color: rgba(46, 204, 113, 0.2); }
  50% { box-shadow: 0 0 14px rgba(46, 204, 113, 0.25); border-color: rgba(46, 204, 113, 0.45); }
}

.question-text {
  font-size: 1.6rem;
  font-weight: 800;
  color: #333;
  line-height: 1.3;
}

.question-bar.waiting .question-text {
  animation: textPulse 2s ease-in-out infinite;
}

@keyframes textPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* ===== FEEDBACK (question-bar icinde, absolute) ===== */
.feedback {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  border-radius: 12px;
}

.feedback.visible {
  opacity: 1;
}

.feedback.correct-feedback {
  font-size: 1.1rem;
  color: #27ae60;
  background: rgba(232, 248, 240, 0.92);
}

.feedback.wrong-feedback {
  font-size: 1.1rem;
  color: #e74c3c;
  background: rgba(255, 245, 245, 0.95);
}

.wrong-label {
  font-size: 0.85rem;
  color: #999;
  margin-bottom: 2px;
}

.wrong-answer {
  font-size: 1.5rem;
  font-weight: 900;
  color: #27ae60;
}

/* ===== HUD: MESAFE BAR ===== */
.hud-distance {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.distance-track {
  flex: 1;
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  position: relative;
  overflow: hidden;
}

.distance-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  border-radius: 5px;
  transition: width 0.4s ease;
}

.distance-dots {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  pointer-events: none;
}

.distance-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  transition: background 0.3s;
}

.distance-dot.done {
  background: rgba(255,255,255,0.9);
}

.distance-text {
  font-size: 0.8rem;
  font-weight: 700;
  color: #555;
  white-space: nowrap;
  min-width: 62px;
  text-align: right;
}

/* ===== HUD: SKOR + SURE + STREAK ===== */
.hud-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.hud-stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-stat-value {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.1;
}

.hud-score .hud-stat-value {
  color: #27ae60;
  transition: transform 0.15s, color 0.15s;
}

.hud-score.pop .hud-stat-value {
  transform: scale(1.25);
  color: #f1c40f;
}

.hud-timer .hud-stat-value {
  color: #555;
  font-variant-numeric: tabular-nums;
}

.hud-streak {
  background: rgba(230, 126, 34, 0.12);
  padding: 2px 10px;
  border-radius: 12px;
}

.hud-streak .hud-stat-value {
  color: #e67e22;
  font-size: 0.9rem;
}

/* ===== LEFT CONTROLS (gas/brake + gear) ===== */
.ctrl-left {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.gear-indicator {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
}

.gear-bar {
  height: 0;
  flex: 1;
  border-radius: 3px;
  background: #e0e0e0;
  transition: background 0.15s;
}

.gear-bar[data-gear="1"] { width: 10px; }
.gear-bar[data-gear="2"] { width: 14px; }
.gear-bar[data-gear="3"] { width: 18px; }
.gear-bar[data-gear="4"] { width: 22px; }
.gear-bar[data-gear="5"] { width: 26px; }

.gear-bar.active[data-gear="1"] { background: #27ae60; }
.gear-bar.active[data-gear="2"] { background: #2ecc71; }
.gear-bar.active[data-gear="3"] { background: #f1c40f; }
.gear-bar.active[data-gear="4"] { background: #e67e22; }
.gear-bar.active[data-gear="5"] { background: #e74c3c; }

.gear-num {
  font-size: 0.75rem;
  font-weight: 800;
  color: #555;
  line-height: 1;
}

/* ===== CANVAS ===== */
.canvas-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

#game-canvas {
  width: 100%;
  max-width: 700px;
  border-radius: 12px;
  display: block;
  touch-action: none;
}

/* ===== SPLIT RACING CONTROLS ===== */
.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 4px;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== CONTROL LABELS (canvas ile butonlar arasi) ===== */
.ctrl-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 12px;
  margin-bottom: 6px;
}

.ctrl-label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ctrl-icon {
  width: 24px;
  height: 24px;
  color: #888;
}

.ctrl-label-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: none;
  font-size: 1.4rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
  transform: scale(0.93);
}

/* Lane buttons — left side (green tint) */
.lane-up,
.lane-down {
  background: rgba(46, 204, 113, 0.15);
  color: #27ae60;
}

.lane-up:active, .lane-up.pressed,
.lane-down:active, .lane-down.pressed {
  background: rgba(46, 204, 113, 0.4);
}

/* Gas button — right side top (green) */
.gas-btn {
  background: rgba(46, 204, 113, 0.3);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  position: relative;
  overflow: hidden;
}

.gas-btn::before,
.gas-btn::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background: rgba(46, 204, 113, 0.5);
  border-radius: 1px;
}

.gas-btn::before { top: 5px; }
.gas-btn::after { bottom: 5px; }

.gas-btn:active, .gas-btn.pressed {
  background: rgba(46, 204, 113, 0.55);
}

/* Brake button — right side bottom (orange) */
.brake-btn {
  background: rgba(230, 126, 34, 0.25);
  color: #e67e22;
}

.brake-btn:active, .brake-btn.pressed {
  background: rgba(230, 126, 34, 0.5);
}

/* Horn button — center (round, pulsing border) */
.horn-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(230, 126, 34, 0.1);
  color: #e67e22;
  font-size: 1.3rem;
  box-shadow: 0 0 0 2px rgba(230, 126, 34, 0.3);
  animation: hornPulse 2s ease-in-out infinite;
}

@keyframes hornPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(230, 126, 34, 0.2); }
  50% { box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.5), 0 0 12px rgba(230, 126, 34, 0.15); }
}

.horn-btn:active, .horn-btn.pressed {
  background: rgba(230, 126, 34, 0.35);
  animation: none;
  box-shadow: 0 0 0 3px #e67e22, 0 0 16px rgba(230, 126, 34, 0.4);
}

/* ===== SONUC EKRANI ===== */
.result-container {
  text-align: center;
}

.result-emoji {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.result-title {
  font-size: 2rem;
  font-weight: 800;
  color: #27ae60;
  margin-bottom: 8px;
}

.result-player {
  font-size: 1.1rem;
  color: #888;
  margin-bottom: 24px;
}

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

.stat-card {
  background: #e8f8f0;
  border-radius: 16px;
  padding: 18px 10px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: #27ae60;
}

.stat-label {
  font-size: 0.85rem;
  color: #888;
  margin-top: 4px;
}

.result-message {
  font-size: 1.1rem;
  color: #555;
  margin-bottom: 24px;
  line-height: 1.6;
}

.restart-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.3s;
  min-height: 52px;
}

.restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(46, 204, 113, 0.4);
}

.restart-btn:active {
  transform: translateY(0);
}

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

/* ===== TABLET (768px) ===== */
@media (max-width: 768px) {
  body {
    padding: 16px;
  }

  .container {
    padding: 30px 24px;
  }

  .game-title {
    font-size: 2.2rem;
  }

  .ctrl-btn {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
  }

  .horn-btn {
    width: 44px;
    height: 44px;
  }

  .ctrl-icon {
    width: 22px;
    height: 22px;
  }
}

/* ===== TELEFON (500px) ===== */
@media (max-width: 500px) {
  body {
    padding: 8px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 8px)) max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 8px));
  }

  .container {
    padding: 22px 16px;
    border-radius: 18px;
  }

  .game-title {
    font-size: 1.7rem;
  }

  .game-subtitle {
    font-size: 1rem;
    margin-bottom: 24px;
  }

  .difficulty-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .difficulty-btn {
    font-size: 0.9rem;
    padding: 12px 8px;
  }

  .grade-emoji {
    font-size: 1.4rem;
  }

  .start-btn {
    font-size: 1.15rem;
  }

  .question-bar {
    padding: 10px 12px;
  }

  .question-text {
    font-size: 1.35rem;
  }

  .feedback {
    font-size: 0.9rem;
    min-height: 24px;
  }

  .hud-stat-value {
    font-size: 1.1rem;
  }

  .hud-stat-label {
    font-size: 0.65rem;
  }

  .distance-text {
    font-size: 0.75rem;
  }

  .gear-bar {
    width: 24px;
    height: 4px;
  }

  .ctrl-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
    border-radius: 10px;
  }

  .ctrl-icon {
    width: 20px;
    height: 20px;
  }

  .ctrl-label-text {
    font-size: 0.7rem;
  }

  .horn-btn {
    width: 40px;
    height: 40px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 12px 6px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  .result-title {
    font-size: 1.6rem;
  }

  .result-message {
    font-size: 1rem;
  }
}

/* ===== COK KUCUK TELEFON (360px) ===== */
@media (max-width: 360px) {
  .container {
    padding: 18px 12px;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .question-text {
    font-size: 1.2rem;
  }

  .ctrl-btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
    border-radius: 10px;
  }

  .horn-btn {
    width: 36px;
    height: 36px;
  }

  .ctrl-icon {
    width: 18px;
    height: 18px;
  }

  .ctrl-label-text {
    font-size: 0.65rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }
}

/* ===== LANDSCAPE TELEFON ===== */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 12px 20px;
    align-items: flex-start;
  }

  .container {
    padding: 20px 24px;
  }

  .game-title {
    font-size: 1.6rem;
    margin-bottom: 4px;
  }

  .game-subtitle {
    margin-bottom: 16px;
    font-size: 0.95rem;
  }

  .form-group {
    margin-bottom: 12px;
  }

  .difficulty-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .difficulty-btn {
    padding: 10px 6px;
    font-size: 0.8rem;
  }

  .grade-emoji {
    font-size: 1.2rem;
  }

  .question-bar {
    padding: 8px 12px;
    margin-bottom: 4px;
  }

  .question-text {
    font-size: 1.1rem;
  }

  .ctrl-btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
  }

  .horn-btn {
    width: 36px;
    height: 36px;
  }

  .stats-grid {
    gap: 8px;
    margin-bottom: 16px;
  }

  .result-emoji {
    font-size: 2.5rem;
    margin-bottom: 8px;
  }

  .result-title {
    font-size: 1.5rem;
  }
}
