/* ============================================================
   Global reset — tarayıcı varsayılan margin/padding'lerini temizle
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;              /* Sayfanın kaydırılmasını engelle (canvas tam ekran) */
  background: #202830;           /* Canvas dışı kalırsa görünecek koyu zemin */
  /* Kullanıcı sürükleyince metin seçimi olmasın (Faz 2 pan hazırlığı) */
  user-select: none;
  -webkit-user-select: none;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ============================================================
   Canvas — ekranı tamamen kaplar (responsive).
   Gerçek piksel çözünürlüğü JS'te DPR ile ayarlanır;
   buradaki width/height sadece CSS (görsel) boyutudur.
   ============================================================ */
#game-canvas {
  display: block;                /* inline-block kaynaklı alt boşluğu kaldır */
  width: 100%;
  height: 100%;
  /* Pan (sürükle) için "kavra" imleci; JS sürüklerken "grabbing" yapar */
  cursor: grab;
  /* Dokunmatik cihazlarda tarayıcının kendi pan/zoom davranışını kapat */
  touch-action: none;
}

/* ============================================================
   UI OVERLAY — canvas üstünde, tıklamaları bloklamayan katman
   ============================================================ */
#ui-root {
  position: fixed;
  inset: 0;                      /* tüm ekranı kapla */
  pointer-events: none;          /* fare olayları canvas'a geçsin */
  z-index: 10;
  color: #f0f4f0;
  font-size: 14px;
}

/* ---- HUD (sol üst durum paneli) ---- */
.hud {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: rgba(20, 30, 25, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.hud-icon { font-size: 18px; }

/* Zorunlu giriş kapısı aktifken oyun arayüzünü gizle (yalnızca giriş ekranı görünür) */
.gate-active .hud,
.gate-active .topbar-right,
.gate-active .br-controls { display: none; }

/* ---- Sağ üst köşe: kullanıcı adı + Ayarlar düğmesi (HUD'dan ayrı) ---- */
.topbar-right {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;          /* tıklanabilir */
}
/* Giriş yapılınca ayarların solunda görünen kullanıcı adı rozeti */
.user-badge {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(20, 30, 25, 0.78);
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  font-weight: 600;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  /* HUD paneliyle uyumlu koyu cam zemin: açık gökyüzünde görünür kalsın */
  background: rgba(20, 30, 25, 0.78);
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  color: #f0f4f0;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.hud-btn:hover { background: rgba(35, 48, 40, 0.9); }
.hud-btn:active { transform: translateY(1px); }

/* ---- XP çubuğu ---- */
.hud-xp {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 150px;
}
.hud-xp-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  overflow: hidden;
}
.hud-xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7ed957, #3fae2a);
  border-radius: 5px;
  transition: width 0.25s ease;
}
.hud-xp-text {
  font-size: 11px;
  opacity: 0.8;
  text-align: right;
}

/* ============================================================
   EKİN SEÇİCİ (alt orta) — tıklayınca ürün menüsü modalı açılır
   ============================================================ */
/* Sağ alt köşe kontrol yığını: Özelleştir (üstte) + Market (altta) */
.br-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}
/* Özelleştir düğmesi */
.br-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: rgba(20, 30, 25, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  color: #f0f4f0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.br-btn:hover { background: rgba(35, 48, 40, 0.9); }
.br-btn:active { transform: translateY(1px); }
/* Taşıma modu aktifken vurgulanır */
.br-btn.active {
  border-color: rgba(126, 217, 87, 0.6);
  background: rgba(126, 217, 87, 0.22);
  color: #eafff0;
}

.crop-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: rgba(20, 30, 25, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  color: #f0f4f0;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.crop-selector:hover { background: rgba(35, 48, 40, 0.9); }
.crop-selector:active { transform: translateY(1px); }
.cs-emoji { font-size: 24px; line-height: 1; }
.cs-name { font-weight: 600; }
.cs-caret { opacity: 0.7; font-size: 12px; }

/* ============================================================
   MODAL (ürün menüsü, ayarlar, giriş/kayıt için ortak kabuk)
   ============================================================ */
.modal-backdrop {
  position: absolute;
  inset: 0;
  display: none;                   /* .open ile flex olur */
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  pointer-events: auto;            /* arka plana tıklayınca kapansın */
  z-index: 20;
}
.modal-backdrop.open { display: flex; animation: fade-in 0.15s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow-y: auto;
  background: #1b2620;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  animation: pop-in 0.18s ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 17px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f0f4f0;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-close:hover { background: rgba(255, 90, 90, 0.35); }
.modal-hint {
  padding: 12px 18px 16px;
  font-size: 12px;
  opacity: 0.7;
}

/* ---- Market kartları (grid) — etiketli, okunur ---- */
.crop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px 18px 6px;
}
.crop-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 14px 12px 12px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #f0f4f0;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.crop-card:hover { background: rgba(255, 255, 255, 0.13); }
.crop-card:active { transform: translateY(1px); }
.cc-emoji { font-size: 40px; line-height: 1; }
.cc-name { font-size: 15px; font-weight: 700; }
.cc-info { width: 100%; display: flex; flex-direction: column; gap: 3px; margin-top: 2px; }
.cc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.cc-row:last-child { border-bottom: none; }
.cc-lbl { opacity: 0.6; }
.cc-val { font-weight: 600; white-space: nowrap; }
.cc-lock { display: none; font-size: 12px; color: #ffd27a; font-weight: 600; }
.cc-act { display: none; font-size: 11px; color: #9be36f; }
.crop-card:hover .cc-act { display: block; }

/* Seçili ürün */
.crop-card.selected { border-color: #7ed957; background: rgba(126, 217, 87, 0.18); }
.crop-card.selected .cc-act { display: block; color: #eafff0; }
/* Altın yetmiyor: fiyatı kırmızı vurgula */
.crop-card.cant-afford .cc-price { color: #ff7a7a; }
/* Kilitli ürün: karart, kilit rozetini göster, bilgileri gizle */
.crop-card.locked { cursor: not-allowed; opacity: 0.55; filter: grayscale(0.7); }
.crop-card.locked .cc-info,
.crop-card.locked .cc-act { display: none; }
.crop-card.locked .cc-lock { display: block; }

/* ============================================================
   MARKET — geniş, sekmeli menü (ekinler / ağaçlar / hayvanlar)
   ============================================================ */
.modal.market { max-width: 720px; }

.market-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 18px 0;
}
.market-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  background: rgba(255, 255, 255, 0.04);
  color: #cdd6cf;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.market-tab:hover { background: rgba(255, 255, 255, 0.1); }
.market-tab.active {
  background: rgba(126, 217, 87, 0.18);
  border-color: rgba(126, 217, 87, 0.5);
  color: #f0f4f0;
}
.mt-icon { font-size: 18px; }

.market-body {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 4px;
}
/* Kategori gridlerinin görünürlüğü JS ile (display) yönetilir. */

/* ============================================================
   AYARLAR MENÜSÜ
   ============================================================ */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}
.settings-row {
  display: block;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #f0f4f0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-row:hover { background: rgba(255, 255, 255, 0.14); }
.settings-row.primary {
  border-color: rgba(126, 217, 87, 0.5);
  background: rgba(126, 217, 87, 0.16);
}
.settings-row.primary:hover { background: rgba(126, 217, 87, 0.28); }
.settings-row.danger { color: #ff8a8a; }
.settings-row.danger:hover { background: rgba(200, 55, 55, 0.28); }

/* Hesap alanı (giriş yapılmışsa kullanıcı adı + çıkış) */
.account-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.acc-user {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 14px;
}
.acc-user b { color: #9be36f; }

/* ---- Onay diyaloğu ---- */
.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}
.confirm-body p {
  font-size: 14px;
  line-height: 1.5;
  opacity: 0.95;
}
.confirm-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  opacity: 0.9;
  cursor: pointer;
  user-select: none;
}
.confirm-remember input { width: 16px; height: 16px; cursor: pointer; }
.confirm-actions {
  display: flex;
  gap: 10px;
}
.confirm-actions .settings-row {
  flex: 1;
  text-align: center;
}

/* ============================================================
   GİRİŞ / KAYIT FORMU
   ============================================================ */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
}
.auth-form input {
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #f0f4f0;
  font-family: inherit;
  font-size: 14px;
}
.auth-form input:focus {
  outline: none;
  border-color: #7ed957;
  background: rgba(255, 255, 255, 0.1);
}
.auth-form input::placeholder { color: rgba(240, 244, 240, 0.5); }
.auth-error {
  min-height: 16px;
  font-size: 12px;
  color: #ff8a8a;
}
.auth-error:empty { min-height: 0; }
#ui-auth-submit {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, #7ed957, #3fae2a);
  color: #0e1a10;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
}
#ui-auth-submit:hover { filter: brightness(1.08); }
#ui-auth-submit:disabled { opacity: 0.6; cursor: default; }
.auth-switch {
  text-align: center;
  font-size: 13px;
  opacity: 0.85;
}
.auth-switch a {
  color: #9be36f;
  font-weight: 600;
  text-decoration: none;
  margin-left: 4px;
}
.auth-switch a:hover { text-decoration: underline; }

/* ---- Toast bildirimleri (ÜST orta: oyun alanını kapatmaz, tıklamayı engellemez) ---- */
.toasts {
  position: absolute;
  top: 16px;                       /* üstte; alt-orta tıklama alanını kapatmasın */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;          /* en yeni en altta eklenir, aşağı doğru büyür */
  align-items: center;
  gap: 6px;
  max-width: 90%;
  pointer-events: none;            /* KRİTİK: toast'lar asla tıklamayı yakalamaz */
  z-index: 5;
}
.toast {
  padding: 7px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  background: rgba(40, 50, 45, 0.92);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease;
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;            /* fare olayları canvas'a geçsin */
  max-width: 100%;
  text-align: center;
}
.toast-success { background: rgba(46, 160, 67, 0.95); }
.toast-error   { background: rgba(200, 55, 55, 0.95); }
.toast-out {
  opacity: 0;
  transform: translateY(-8px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   MOBİL / DAR EKRAN (dikey telefon dahil)
   - Sağ-alt buton yığını: dikey sütun yerine YATAY sıra (alt kenar boyunca,
     sağa yaslı). Yeni butonlar eklenirse üst satıra sarar (wrap-reverse) —
     asla ekran dışına taşmaz.
   - HUD / üst bar / market sıkılaştırılır; güvenli alan (çentik) payı verilir.
   ============================================================ */
@media (max-width: 640px) {
  #ui-root { font-size: 13px; }

  /* HUD (sol üst): sıkı */
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    gap: 10px;
    padding: 7px 10px;
    border-radius: 10px;
  }
  .hud-icon { font-size: 15px; }
  .hud-xp { min-width: 88px; }

  /* Üst sağ: kullanıcı + ayarlar */
  .topbar-right {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }
  .user-badge { height: 36px; padding: 0 9px; font-size: 12px; max-width: 26vw; }
  .hud-btn { width: 36px; height: 36px; font-size: 16px; }

  /* Sağ-alt kontroller: yatay sıra, sağa yaslı, yukarı doğru sarar */
  .br-controls {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: row;
    flex-wrap: wrap-reverse;      /* taşan butonlar ÜST satıra geçer */
    justify-content: flex-end;
    align-items: stretch;
    gap: 6px;
  }
  .br-btn { padding: 8px 11px; font-size: 13px; border-radius: 10px; }
  .crop-selector { padding: 7px 11px; font-size: 13px; gap: 7px; border-radius: 10px; }
  .cs-emoji { font-size: 19px; }

  /* Toast'lar: üst bar ile çakışmasın diye biraz aşağıda */
  .toasts { top: calc(max(8px, env(safe-area-inset-top)) + 48px); }
  .toast { font-size: 12px; padding: 6px 11px; }

  /* Modallar: tam genişlik, dar kenar boşluğu */
  .modal-backdrop { padding: 10px; }
  .modal { max-height: 92vh; }
  .modal.market { max-width: 100%; }
  .crop-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 8px;
    padding: 10px 12px 4px;
  }
  .market-tab { padding: 8px 10px; font-size: 13px; }
}

/* Çok dar ekran (küçük telefon, dikey): market düğmesinde ürün adını gizle */
@media (max-width: 380px) {
  .cs-name { display: none; }
  .hud { gap: 7px; padding: 6px 8px; }
  .hud-xp { min-width: 64px; }
}
