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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 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: #8e44ad;
  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: #e74c3c;
}

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

.difficulty-btn {
  flex: 1;
  padding: 14px;
  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;
}

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

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

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

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

.start-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #e74c3c 0%, #8e44ad 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(231, 76, 60, 0.4);
}

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

/* ===== OYUN EKRANI ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 6px;
  flex-wrap: wrap;
}

/* ===== HEARTS DISPLAY ===== */
.hearts-display {
  display: flex;
  gap: 2px;
  font-size: 1.1rem;
  white-space: nowrap;
}

.heart-icon {
  display: inline-block;
  transition: transform 0.3s;
}

.heart-icon.empty {
  opacity: 0.4;
}

.hearts-display.heart-lost {
  animation: heartLostShake 0.5s ease;
}

.hearts-display.heart-gained {
  animation: heartGainedPop 0.5s ease;
}

@keyframes heartLostShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes heartGainedPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ===== LEVEL DISPLAY ===== */
.level-display {
  font-size: 0.9rem;
  font-weight: 700;
  color: #9b59b6;
  background: #f3e8ff;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.streak-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: #e67e22;
  background: #fef5e7;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  animation: streakPop 0.4s ease;
}

.streak-badge.hidden {
  display: none !important;
}

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

/* ===== POWER-UP DISPLAY ===== */
.powerup-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #f0f4ff;
  border-radius: 10px;
  margin-bottom: 6px;
}

.powerup-display.hidden {
  display: none !important;
}

.pu-icon {
  font-size: 1.2rem;
}

.pu-timer-bar {
  flex: 1;
  height: 6px;
  background: #ddd;
  border-radius: 3px;
  overflow: hidden;
}

.pu-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #3498db, #9b59b6);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* ===== ANAHTAR PROGRESS BAR (Formula mesafe bar stili) ===== */
.hud-keys {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

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

.keys-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #9b59b6, #e74c3c);
  border-radius: 5px;
  transition: width 0.4s ease;
}

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

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

.keys-dot.done {
  background: rgba(255,255,255,0.9);
  transform: scale(1.3);
}

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

/* ===== SORU BARI (Formula stili — feedback icinde) ===== */
.question-bar {
  background: linear-gradient(135deg, #fdf2f8 0%, #f3e8ff 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(142, 68, 173, 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(142, 68, 173, 0.08); border-color: rgba(142, 68, 173, 0.2); }
  50% { box-shadow: 0 0 14px rgba(142, 68, 173, 0.25); border-color: rgba(142, 68, 173, 0.45); }
}

.question-text {
  font-size: 1.5rem;
  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, overlay) ===== */
.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);
}

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

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

/* ===== D-PAD (sag hizali, kaliteli) ===== */
.controls-area {
  display: flex;
  justify-content: flex-end;
  padding: 0 4px;
}

.dpad {
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 4px;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: rgba(142, 68, 173, 0.12);
  color: #8e44ad;
  font-size: 1.2rem;
  font-weight: 700;
  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;
  box-shadow: 0 2px 6px rgba(142, 68, 173, 0.08);
}

.dpad-btn svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: rgba(142, 68, 173, 0.35);
  transform: scale(0.93);
}

.dpad-center {
  background: transparent;
  cursor: default;
  pointer-events: none;
  box-shadow: none;
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
  background: rgba(142, 68, 173, 0.18);
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-center {
  grid-column: 2;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
  background: rgba(142, 68, 173, 0.18);
}

/* ===== 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: #8e44ad;
  margin-bottom: 8px;
}

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

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

.stat-card {
  background: #f3e8ff;
  border-radius: 16px;
  padding: 14px 6px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: #8e44ad;
}

.stat-label {
  font-size: 0.75rem;
  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, #e74c3c 0%, #8e44ad 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(231, 76, 60, 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;
  }

  .dpad-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }

  .dpad {
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
  }
}

/* ===== 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;
  }

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

  .game-header {
    gap: 4px;
    justify-content: center;
  }

  .hearts-display {
    font-size: 0.95rem;
  }

  .level-display {
    font-size: 0.8rem;
    padding: 3px 8px;
  }

  .streak-badge {
    font-size: 0.78rem;
    padding: 3px 8px;
  }

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

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

  .dpad-btn {
    width: 46px;
    height: 46px;
    border-radius: 12px;
  }

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

  .dpad {
    grid-template-columns: 46px 46px 46px;
    grid-template-rows: 46px 46px 46px;
  }

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

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

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

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

  .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.1rem;
  }

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

  .dpad-btn {
    width: 42px;
    height: 42px;
  }

  .dpad {
    grid-template-columns: 42px 42px 42px;
    grid-template-rows: 42px 42px 42px;
  }
}

/* ===== 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;
  }

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

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

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

  .dpad {
    grid-template-columns: 40px 40px 40px;
    grid-template-rows: 40px 40px 40px;
  }

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

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

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