:root {
  --bg: #12141a;
  --panel: #1c2029;
  --accent: #f1c40f;
  --hp-color: #e74c3c;
  --xp-color: #3fa9f5;
  --text: #eee;
  --muted: #999;
}

* { box-sizing: border-box; }

html, body {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
}

/* Fills the actual device viewport (whatever its size/orientation) instead
   of a fixed 960x540 box scaled down — a landscape-shaped fixed canvas left
   huge unused letterbox space on tall phone screens. The canvas's internal
   drawing resolution is kept in sync with this box size by ui.js. */
#game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #0a0c10;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  pointer-events: none;
}
#hud.hidden { display: none; }

#hud-mid {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin: 4px 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.bar {
  position: relative;
  height: 16px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  transition: width 0.15s linear;
}
.bar-fill.hp { background: var(--hp-color); }
.bar-fill.xp { background: var(--xp-color); }
.bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  text-shadow: 0 1px 2px black;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(10, 12, 16, 0.85);
  text-align: center;
  padding: 20px;
  overflow-y: auto;
  /* İçerik ekrandan taşarsa (ör. telefonda seviye atlama seçenekleri) üstten
     kırpılmadan kaydırılabilsin: 'safe center' taşınca flex-start'a düşer.
     Desteklemeyen tarayıcılar ilk 'center' bildirimini kullanır. */
  justify-content: center;
  justify-content: safe center;
}
.screen.hidden { display: none; }

.screen h1 { margin: 0; font-size: 32px; color: var(--accent); }
.screen h2 { margin: 0; font-size: 26px; color: var(--accent); }
.screen p { margin: 0; color: var(--muted); max-width: 480px; }

button {
  background: var(--accent);
  color: #1c2029;
  border: none;
  padding: 10px 24px;
  font-size: 16px;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }

#levelup-choices {
  display: flex;
  gap: 12px;
}
.choice-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 180px;
}
.choice-card.locked .choice-btn { border-color: #d4af37; box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.35); }
.choice-btn {
  background: var(--panel);
  border: 2px solid var(--accent);
  color: var(--text);
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.choice-btn:hover { background: #262b38; }
.choice-tools { display: flex; gap: 6px; justify-content: center; }
.mini-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.16); filter: none; }
.mini-btn:disabled { opacity: 0.4; cursor: default; }

#levelup-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}
.levelup-info { color: var(--muted); font-size: 13px; }
.choice-btn .choice-key { color: var(--accent); font-weight: bold; }
.choice-btn .choice-name { font-weight: bold; margin: 4px 0; }
.choice-btn .choice-desc { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  #levelup-choices { flex-direction: column; gap: 8px; }
  .choice-card { width: min(320px, 82vw); }
  .choice-btn { padding: 9px 12px; }
  .choice-name { margin: 2px 0; }
  .choice-tools { gap: 8px; }
  .screen h1 { font-size: 24px; }
  .screen h2 { font-size: 20px; margin-top: 4px; }
  .screen p { font-size: 14px; max-width: 90vw; }
  #hud-mid { font-size: 12px; }
}
/* Kısa/yatay ekranlarda seviye atlama başlığı daha da küçülsün. */
@media (max-height: 560px) {
  #screen-levelup h2 { font-size: 18px; margin: 2px; }
  .choice-btn { padding: 8px 10px; }
  #levelup-choices { gap: 6px; }
}

#toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: bold;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 50;
  text-align: center;
  max-width: 80vw;
}
#toast.show { opacity: 1; }

/* En yüksek puanlar tablosu (start + game-over ekranları) */
.highscores { width: min(360px, 86vw); }
.highscores.hidden { display: none; }
.highscores h3 { margin: 6px 0; font-size: 16px; color: var(--accent); }

.hs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hs-table th, .hs-table td { padding: 3px 6px; text-align: right; }
.hs-table th:first-child, .hs-table td:first-child { text-align: left; }
.hs-table thead th {
  color: var(--muted);
  font-weight: normal;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.hs-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.04); }
.hs-table tr.me {
  background: rgba(241, 196, 15, 0.22);
  color: var(--accent);
  font-weight: bold;
}

.score-line { font-size: 18px; font-weight: bold; color: var(--accent); }
.gold-line { font-size: 15px; font-weight: bold; color: #d4af37; }
.summary-line { font-size: 13px; color: var(--muted); max-width: 90vw; }

.gameover-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Kalıcı yükseltme mağazası */
.shop { width: min(380px, 88vw); text-align: left; }
.shop.hidden { display: none; }
.shop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.shop-head h3 { margin: 0; font-size: 16px; color: var(--accent); }
.shop-head .gold { color: #d4af37; font-weight: bold; }
.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 5px;
}
.shop-name { font-weight: bold; font-size: 14px; }
.shop-lvl { color: var(--muted); font-size: 12px; margin-left: 6px; }
.shop-desc { color: var(--muted); font-size: 12px; }
.shop-buy {
  background: #d4af37;
  color: #1c2029;
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: bold;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}
.shop-buy:disabled { background: #3a3f4a; color: var(--muted); cursor: default; }

/* Başarımlar listesi */
.ach-list { width: min(380px, 88vw); text-align: left; }
.ach-list.hidden { display: none; }
.ach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 5px;
  opacity: 0.6;
}
.ach-row.done { opacity: 1; }
.ach-icon { font-size: 18px; }
.ach-info { display: flex; flex-direction: column; }
.ach-name { font-weight: bold; font-size: 14px; }
.ach-desc { color: var(--muted); font-size: 12px; }

/* Codex / rehber */
.codex-h {
  color: var(--accent);
  font-weight: bold;
  font-size: 14px;
  margin: 10px 0 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.codex-row { font-size: 13px; padding: 2px 0; }
.codex-evo { color: var(--accent); font-weight: bold; }
.codex-sub { color: var(--muted); font-size: 12px; }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: normal;
}
.ghost-btn:hover { color: var(--text); filter: none; }
.ghost-btn.hidden { display: none; }

/* Ses ayarları — ⚙️ butonu + efekt/müzik anahtarlı panel. Sağ altta durur,
   her ekranda erişilebilir. */
#sound-controls {
  position: absolute;
  right: 14px;
  bottom: 16px;
  z-index: 60;
}

#settings-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
}
#settings-btn:hover { background: rgba(0, 0, 0, 0.72); filter: none; }

#settings-panel {
  position: absolute;
  bottom: 52px;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  min-width: 168px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}
#settings-panel.hidden { display: none; }

.toggle-row {
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 10px;
  font-size: 14px;
  font-weight: normal;
  border-radius: 6px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.toggle-row:hover { background: rgba(0, 0, 0, 0.5); filter: none; }
.toggle-row.off { opacity: 0.55; }

.vol-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.vol-row input[type="range"] { width: 96px; accent-color: var(--accent); }

.settings-sep {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 6px;
}

/* Duraklat butonu — sol üstte, HUD barlarının altında (çakışmaz). Yalnız
   oyun içinde görünür (setHudVisible ile). */
#pause-btn {
  position: absolute;
  left: 12px;
  top: 72px;
  z-index: 60;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
}
#pause-btn:hover { background: rgba(0, 0, 0, 0.72); filter: none; }
#pause-btn.hidden { display: none; }

/* Atılma butonu — yalnız dokunmatik cihazda, alt-orta (masaüstünde boşluk
   tuşu kullanılır). */
#dash-btn {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 20;
  width: 60px;
  height: 60px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
  background: rgba(74, 222, 128, 0.25);
  color: var(--text);
  border: 2px solid rgba(74, 222, 128, 0.7);
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
}
body.touch-enabled #dash-btn { display: block; }
#dash-btn.hidden { display: none !important; }

/* Kayan joystick: parmağın bastığı yere JS ile konumlanır (inline left/top) ve
   sadece dokunulduğunda (.active) görünür. pointer-events:none → altındaki
   canvas dokunuşları alır, böylece görsel joystick input'u engellemez. */
#joystick {
  display: none;
  position: absolute;
  width: 120px;
  height: 120px;
  z-index: 20;
  pointer-events: none;
  touch-action: none;
}
body.touch-enabled #joystick.active { display: block; }

/* Başlangıç ekranı karakter seçici */
.char-select { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.char-title { color: var(--muted); font-size: 14px; }
.char-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.char-btn {
  background: var(--panel);
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.2);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
}
.char-btn.active { border-color: var(--accent); color: var(--accent); }
.char-btn.locked { opacity: 0.5; cursor: default; }
.char-desc { color: var(--muted); font-size: 13px; max-width: 320px; }

#joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

#joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(241, 196, 15, 0.6);
  border: 2px solid rgba(241, 196, 15, 0.9);
  pointer-events: none;
}
