:root {
  --panel-bg: #FFF8E7;
  --panel-border: #F5B041;
  --ink: #4A3728;
  --gold: #F1C40F;
  --accent: #E74C3C;
  --accent-2: #2E86C1;
  --green: #58D68D;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #0d1530;
  color: var(--ink);
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Baloo 2', system-ui, sans-serif;
}

#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; }

#game-area {
  position: absolute; inset: 0; overflow: hidden;
  background: #0d1530;
}
#game-canvas { width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* Ayarlar: aşağı açılan küçük panel (ekran modu, geliştirici modu, durdur/hızlandır/baştan başla) */
#settings-panel { position: fixed; top: 8px; right: 8px; z-index: 60; }
#settings-toggle {
  font-family: inherit; font-size: 13px; font-weight: bold; padding: 8px 14px;
  border-radius: 10px; border: none; background: rgba(0,0,0,0.55); color: #fff; cursor: pointer;
}
#settings-toggle:hover { filter: brightness(1.15); }
#settings-body {
  /* Mutlak konumlandırılır: açılınca #settings-panel kutusunun boyutunu büyütmesin,
     yoksa sağa hizalı panel sola doğru genişleyip "Ayarlar" butonunu da beraberinde
     kaydırır ve sol üstteki HUD kartının üzerine biner. */
  position: absolute; top: 100%; right: 0; margin-top: 6px;
  background: rgba(20,18,30,0.94); border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; gap: 10px; width: 200px;
  max-height: calc(100vh - 60px); overflow-y: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.settings-group { display: flex; flex-direction: column; gap: 6px; }
.settings-group:not(:last-child) { padding-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.settings-label { font-size: 11px; color: #cfcfe0; font-weight: bold; }
.settings-row { display: flex; gap: 4px; }
.settings-row button, .settings-full-btn {
  font-family: inherit; font-size: 11px; font-weight: bold; padding: 7px 8px; border-radius: 7px;
  border: none; background: rgba(255,255,255,0.9); color: var(--ink); cursor: pointer;
}
.settings-row button { flex: 1; }
.settings-full-btn { width: 100%; }
.settings-row button:hover, .settings-full-btn:hover { filter: brightness(1.05); }
.settings-row button.active, .settings-full-btn.active { background: var(--gold); }
.settings-full-btn.danger { background: #E74C3C; color: #fff; }
.settings-full-btn.danger:hover { background: #C0392B; }

#pause-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.62); color: #fff; padding: 16px 34px; border-radius: 18px;
  font-size: 26px; font-weight: bold; z-index: 8; pointer-events: none; text-align: center;
}

body.force-narrow #app,
body.force-narrow #shop-panel {
  max-width: 420px;
}
body.force-wide #app,
body.force-wide #shop-panel {
  max-width: 1400px;
}
body.force-narrow #app, body.force-wide #app { margin: 0 auto; }
body.force-narrow #shop-panel, body.force-wide #shop-panel { margin-left: auto; margin-right: auto; }

/* HUD: tek, düzenli kart — üstte isim+seviye, altında exp barı, altında can/altın/dalga */
#mert-hud {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  width: 248px;
  background: rgba(8, 10, 24, 0.68);
  border: 2px solid rgba(255,255,255,0.16);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 7px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.hud-header { display: flex; align-items: baseline; justify-content: space-between; }
.hud-name {
  font-family: inherit; font-weight: bold; font-size: 15px; color: #fff;
  background: none; border: none; padding: 0; cursor: pointer;
  text-decoration: underline dotted rgba(255,255,255,0.5); text-underline-offset: 3px;
}
.hud-name:hover { color: var(--gold); }
.hud-level-text { font-size: 11px; font-weight: bold; color: #cfe0ff; }

#exp-bar-wrap {
  position: relative; width: 100%; height: 9px;
  background: rgba(255,255,255,0.18); border-radius: 6px; overflow: hidden;
}
#exp-bar-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg,#5DADE2,#85C1E9);
  transition: width 0.25s ease;
}

.hud-stats { display: flex; align-items: center; gap: 8px; }
#hp-bar-wrap {
  position: relative; flex: 1; min-width: 0; height: 22px; border-radius: 11px;
  background: #5b1f1f; overflow: hidden;
}
#hp-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: linear-gradient(90deg, #2ECC71, #7EE08B);
  transition: width 0.25s ease, background 0.25s ease;
}
#hp-bar-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 12px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.hud-stat {
  font-size: 13px; font-weight: bold; color: #fff; white-space: nowrap;
  display: flex; align-items: center; gap: 3px;
}
#wave-progress-row {
  font-size: 11px; color: #d8dcf0; text-align: right; font-weight: bold;
}

#wave-banner {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  background: rgba(20,15,35,0.85); color: #fff; padding: 12px 28px; border-radius: 16px;
  font-size: 26px; font-weight: bold; z-index: 6; text-align: center;
  animation: pop-in 0.25s ease;
}

#intermission-banner {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.92); border: 3px solid var(--green); border-radius: 14px;
  padding: 8px 20px; font-weight: bold; font-size: 15px; z-index: 5; white-space: nowrap;
}

#boss-hp-wrap {
  /* HUD kartının (sol üst) ve Ayarlar düğmesinin (sağ üst) altında, ayrı bir satırda durur —
     aksi halde dar ekranlarda ikisiyle de çakışıyordu. */
  position: absolute; top: 108px; left: 50%; transform: translateX(-50%);
  width: min(60%, 520px); height: 26px;
  background: rgba(0,0,0,0.5); border: 3px solid #A93226; border-radius: 14px; overflow: hidden; z-index: 6;
}
#boss-hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg,#E74C3C,#C0392B); transition: width 0.2s; }
#boss-hp-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: bold; letter-spacing: 2px; font-size: 13px; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

@keyframes pop-in {
  from { transform: translateX(-50%) scale(0.6); opacity: 0; }
  to   { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Overlays */
.overlay {
  position: absolute; inset: 0; background: rgba(8,8,18,0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  text-align: center; z-index: 10; padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* Kısa/mobil yükseklikte (özellikle mobil Chrome'un adres çubuğu alanı düşünce) içerik
   sığmayıp "Oyunu Başlat" butonuna ulaşılamaması ihtimaline karşı kompakt bir düzen. */
@media (max-height: 640px) {
  .overlay h1 { font-size: 24px; margin-bottom: 6px; }
  .overlay p { font-size: 13px; margin: 6px 0; }
  .overlay .tips { font-size: 12px; margin: 8px 0; }
  .overlay .tips li { margin-bottom: 4px; }
  .overlay button { margin-top: 10px; font-size: 16px; padding: 10px 24px; }
}
.overlay h1 { font-size: 34px; color: #fff; margin-bottom: 10px; text-shadow: 0 3px 0 rgba(0,0,0,0.3); }
.overlay p { color: #fff; font-size: 15px; max-width: 520px; line-height: 1.5; }
.overlay .tips { color: #fff; text-align: left; font-size: 14px; margin: 14px 0; padding-left: 20px; max-width: 480px; }
.overlay .tips li { margin-bottom: 6px; }
.overlay button {
  margin-top: 18px; font-family: inherit; font-size: 20px; font-weight: bold;
  background: var(--gold); border: 4px solid #B7950B; color: #4A3728;
  padding: 12px 32px; border-radius: 16px; cursor: pointer;
  box-shadow: 0 5px 0 #B7950B;
  transition: transform 0.08s ease;
}
.overlay button:active { transform: translateY(4px); box-shadow: 0 1px 0 #B7950B; }
.overlay button:hover { filter: brightness(1.06); }

/* Market: alttan açılıp kapanan çekmece */
#shop-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--panel-bg); border-top: 5px solid var(--panel-border);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  max-height: 58px;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -6px 20px rgba(0,0,0,0.35);
}
#shop-panel.expanded { max-height: min(72vh, 620px); }

#shop-toggle {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 15px; margin: 0; border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-weight: bold; font-size: 17px; color: var(--ink);
}
#shop-toggle .chev { font-size: 12px; opacity: 0.55; transition: transform 0.3s ease; }
#shop-panel.expanded #shop-toggle .chev { transform: rotate(180deg); }

#shop-body { overflow-y: auto; padding: 0 16px 16px; display: flex; flex-direction: column; gap: 14px; }

/* Market sekmeleri: Güçlendirmeler / Arkadaşlar / Kıyafetler ayrı ayrı gösterilir, karışıklığı önler */
.shop-tabs {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 6px;
  padding: 10px 0 4px; margin-bottom: 2px; background: var(--panel-bg);
}
.shop-tab-btn {
  flex: 1; font-family: inherit; font-weight: bold; font-size: 12.5px; text-align: center;
  padding: 10px 4px; border-radius: 12px; border: 2px solid var(--panel-border);
  background: #fff; color: var(--ink); cursor: pointer;
}
.shop-tab-btn:hover { filter: brightness(1.05); }
.shop-tab-btn.active { background: var(--gold); }
.shop-tab-panel { display: flex; flex-direction: column; gap: 14px; }

.shop-section { display: flex; flex-direction: column; gap: 12px; }

.shop-item {
  display: flex; align-items: center; gap: 10px; background: #fff;
  border: 3px solid var(--panel-border); border-radius: 14px; padding: 10px;
}
.shop-item.special { border-color: #A569BD; background: #FBF3FF; }
#asena-upgrades { margin-top: -4px; padding-top: 2px; border-top: 2px dashed #d8c3e8; }
#aslan-upgrades { margin-top: -4px; padding-top: 2px; border-top: 2px dashed #f0c896; }
#cino-upgrades { margin-top: -4px; padding-top: 2px; border-top: 2px dashed #a9d4ec; }
.shop-icon { font-size: 28px; }
.shop-info { flex: 1; min-width: 0; }
.shop-title { font-weight: bold; font-size: 14px; }
.shop-desc { font-size: 12px; color: #7d6a58; }
.buy-btn {
  font-family: inherit; font-weight: bold; font-size: 13px; white-space: nowrap;
  background: var(--green); border: none; border-radius: 10px; padding: 12px 14px;
  min-height: 42px; min-width: 64px;
  cursor: pointer; box-shadow: 0 3px 0 #2E9C5A; color: #fff;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.buy-btn:disabled { background: #BDC3C7; box-shadow: 0 3px 0 #909497; cursor: not-allowed; opacity: 0.7; }
.buy-btn:not(:disabled):active { transform: translateY(3px); box-shadow: none; }
#shop-footer { margin-top: 2px; font-size: 11.5px; color: #8a7862; text-align: center; }

@media (min-width: 700px) {
  .shop-section { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .shop-section .shop-item { flex: 1 1 260px; max-width: 320px; }
}

/* İsme tıklayınca açılan güncel özellik/istatistik ekranı */
#stats-modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(8,8,18,0.72);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#stats-modal-content {
  width: min(360px, 100%); max-height: 80vh; overflow-y: auto;
  background: var(--panel-bg); border: 3px solid var(--panel-border); border-radius: 18px;
  padding: 16px 18px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.stats-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.stats-modal-header h2 { margin: 0; font-size: 18px; color: var(--ink); }
#stats-modal-close {
  font-family: inherit; font-weight: bold; font-size: 15px; line-height: 1;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.1); color: var(--ink); cursor: pointer;
}
#stats-modal-close:hover { background: rgba(0,0,0,0.18); }
.stats-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 2px; font-size: 13.5px; color: var(--ink);
}
.stats-row strong { font-size: 13.5px; color: #4A3728; }
.stats-divider { height: 2px; background: rgba(0,0,0,0.08); margin: 6px 0; border-radius: 2px; }
