/* ============ Bird Nest Rise — UI ============ */
:root {
  --bg: var(--tg-theme-bg-color, #0e1a2b);
  --bg2: var(--tg-theme-secondary-bg-color, #16263d);
  --text: var(--tg-theme-text-color, #eef4ff);
  --hint: var(--tg-theme-hint-color, #8da3c0);
  --accent: var(--tg-theme-button-color, #ffb84d);
  --accent-text: var(--tg-theme-button-text-color, #1c1404);
  --card: color-mix(in srgb, var(--bg2) 82%, white 6%);
  --gold: #ffc94d;
  --danger: #ff6b6b;
  --ok: #5ad48a;
  --radius: 18px;
  --tg-top: 0px;    /* set from JS (Telegram content safe area) */
  --tg-bottom: 0px;
  --safe-top: calc(env(safe-area-inset-top, 0px) + var(--tg-top));
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-bottom));
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ============ Icons ============ */
.icon {
  width: 1.15em; height: 1.15em;
  display: inline-block;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon-coin { color: var(--gold); }

/* Numbers: always LTR + fixed-width digits so nothing jumps around */
.num {
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
}

/* ============ Screens ============ */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding-top: calc(var(--safe-top) + 14px);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg) 80%, transparent),
    color-mix(in srgb, var(--bg) 96%, black 4%));
  backdrop-filter: blur(2px);
  animation: screen-in 0.25s ease;
  z-index: 10;
}
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ============ Profile bar ============ */
.profile-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 14px 0;
  padding: 10px 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--gold);
  object-fit: cover;
  flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-name {
  font-weight: 700; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-level { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
#user-level-label { font-size: 12px; color: var(--gold); font-weight: 700; }
.xp-bar {
  flex: 1; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.12); overflow: hidden;
}
#xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ffc94d, #ff9f43);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.coin-badge {
  display: inline-flex; align-items: center; gap: 6px;
  direction: ltr;
  font-weight: 800; font-size: 14px;
  background: rgba(255,201,77,0.15);
  color: var(--gold);
  padding: 8px 12px; border-radius: 999px;
  white-space: nowrap;
}

/* ============ Home center ============ */
.home-center {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  padding: 0 22px;
  min-height: 0;
}
.game-logo { text-align: center; }
#logo-bird {
  width: 110px; height: 110px;
  animation: float 2.6s ease-in-out infinite;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.game-logo h1 {
  font-size: 30px; font-weight: 900; letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ffe6a3, #ffb84d);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline { color: var(--hint); font-size: 13px; margin-top: 6px; }

.stats-row { display: flex; gap: 12px; width: 100%; max-width: 380px; }
.stat-card {
  flex: 1; text-align: center;
  background: var(--card);
  padding: 12px 8px; border-radius: var(--radius);
}
.stat-head {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 12px; color: var(--hint); font-weight: 700;
}
.stat-head .icon { color: var(--gold); }
.stat-value { font-size: 22px; font-weight: 900; color: var(--gold); margin-top: 5px; }

.play-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 380px;
  padding: 16px;
  font-size: 18px; font-weight: 900;
  font-family: inherit;
  color: var(--accent-text);
  background: linear-gradient(180deg, #ffd166, var(--accent));
  border: none; border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(255,184,77,0.35), inset 0 -3px 0 rgba(0,0,0,0.18);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.play-btn:active { transform: scale(0.96); }

.daily-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 380px;
  padding: 12px;
  font-size: 15px; font-weight: 800;
  font-family: inherit;
  color: #06281a;
  background: linear-gradient(180deg, #7fe7ad, var(--ok));
  border: none; border-radius: var(--radius);
  cursor: pointer;
  animation: pulse-glow 1.8s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,100% { box-shadow: 0 0 0 0 rgba(90,212,138,0.45); }
  50% { box-shadow: 0 0 0 10px rgba(90,212,138,0); }
}
.ghost-btn {
  width: 100%;
  padding: 13px;
  font-size: 15px; font-weight: 700;
  font-family: inherit;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius);
  cursor: pointer;
}
.ghost-btn:active { transform: scale(0.97); }

/* ============ Bottom nav ============ */
.bottom-nav {
  display: flex;
  margin-top: auto;
  padding: 8px 10px calc(var(--safe-bottom) + 10px);
  background: color-mix(in srgb, var(--bg2) 92%, black 8%);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.nav-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 7px 0;
  background: none; border: none;
  color: var(--hint);
  font-size: 11px; font-weight: 700;
  font-family: inherit;
  border-radius: 12px;
  cursor: pointer;
}
.nav-btn .icon { width: 21px; height: 21px; }
.nav-btn.active { color: var(--gold); background: rgba(255,201,77,0.10); }

/* ============ HUD ============ */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 5;
  padding-top: calc(var(--safe-top) + 14px);
}
.hud-top {
  display: flex; justify-content: space-between;
  flex-direction: row-reverse; /* coins left, altitude right — fixed regardless of bidi */
  padding: 0 14px;
}
.hud-pill {
  display: inline-flex; align-items: center; gap: 7px;
  direction: ltr;
  background: rgba(10,18,32,0.55);
  backdrop-filter: blur(6px);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 900; font-size: 16px;
  border: 1px solid rgba(255,255,255,0.10);
}
.hud-pill.small { font-size: 12.5px; padding: 6px 11px; }
.coin-pill { color: var(--gold); }
.hud-flaps {
  display: flex; gap: 6px;
  justify-content: center;
  margin-top: 12px;
}
.hud-flaps .feather {
  width: 17px; height: 17px;
  color: #ffe082;
  opacity: 0.22; transition: opacity 0.15s;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}
.hud-flaps .feather.on { opacity: 1; }
.hud-stage {
  position: absolute; top: 42%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px; font-weight: 900;
  color: #fff; text-align: center;
  text-shadow: 0 2px 14px rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.4s;
  white-space: nowrap;
}
.hud-stage.show { opacity: 1; }
.hud-wind {
  position: absolute; top: calc(var(--safe-top) + 104px); left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center;
  font-size: 18px;
  color: #dfeefc;
  background: rgba(10,18,32,0.5);
  padding: 6px 13px; border-radius: 999px;
}
.hud-wind.flip .icon { transform: scaleX(-1); }

/* ============ Game over ============ */
#screen-gameover {
  align-items: center; justify-content: center;
  background: rgba(8,13,22,0.72);
}
.modal-card {
  width: min(92vw, 380px);
  background: var(--bg2);
  border-radius: 24px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,0.5);
  animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.go-icon { font-size: 46px; color: var(--gold); }
.go-icon .icon { stroke-width: 1.6; }
.go-icon.record { color: #ffd700; }
.modal-card h2 { margin: 10px 0 4px; font-size: 22px; }
.record-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 8px 0;
  padding: 7px 16px;
  background: linear-gradient(90deg, #ffd166, #ff9f43);
  color: #3a2403; font-weight: 900; font-size: 14px;
  border-radius: 999px;
  animation: pulse-glow 1.5s infinite;
}
.go-stats { margin: 16px 0; }
.go-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  margin-bottom: 7px;
  font-size: 14px;
}
.go-row span { display: inline-flex; align-items: center; gap: 7px; color: var(--hint); font-weight: 700; }
.go-row b { color: var(--gold); font-size: 15px; }
.go-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ============ Panel screens (shop / leaderboard / achievements) ============ */
.panel-screen { background: var(--bg); }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
}
.panel-header h2 {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 19px;
}
.panel-header h2 .icon { color: var(--gold); }
.panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px 18px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.shop-tabs { display: flex; gap: 8px; padding: 4px 14px 10px; }
.tab-btn {
  flex: 1; padding: 9px;
  background: rgba(255,255,255,0.06);
  border: none; border-radius: 12px;
  color: var(--hint); font-weight: 800; font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.tab-btn.active { background: rgba(255,201,77,0.16); color: var(--gold); }

.shop-item, .lb-row, .ach-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 14px;
}
.shop-icon {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  color: var(--gold);
  flex-shrink: 0;
}
.shop-icon .icon { width: 24px; height: 24px; }
.shop-icon canvas { width: 40px; height: 40px; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-weight: 800; font-size: 14px; }
.shop-desc { font-size: 12px; color: var(--hint); margin-top: 3px; }
.shop-level { font-size: 11px; color: var(--gold); font-weight: 700; margin-top: 4px; }
.level-dots { display: inline-flex; gap: 3px; margin-inline-start: 5px; vertical-align: middle; }
.level-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,0.14);
}
.level-dots i.on { background: var(--gold); }
.buy-btn {
  display: inline-flex; align-items: center; gap: 5px;
  direction: ltr;
  padding: 9px 14px;
  background: linear-gradient(180deg, #ffd166, var(--accent));
  color: var(--accent-text);
  border: none; border-radius: 12px;
  font-weight: 900; font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.buy-btn .icon-coin { color: #8a5b00; }
.buy-btn:active { transform: scale(0.94); }
.buy-btn:disabled { opacity: 0.45; }
.buy-btn.owned { background: rgba(90,212,138,0.2); color: var(--ok); }
.buy-btn.selected { background: var(--ok); color: #06281a; }

/* leaderboard */
.lb-rank {
  font-size: 14px; font-weight: 900; width: 34px;
  display: flex; align-items: center; justify-content: center;
  color: var(--hint); flex-shrink: 0;
}
.lb-rank .icon { width: 22px; height: 22px; }
.lb-rank.top1 { color: #ffd700; } .lb-rank.top2 { color: #c8d2dc; } .lb-rank.top3 { color: #d99a64; }
.lb-row .avatar { width: 38px; height: 38px; border-width: 1px; }
.avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  color: var(--gold);
}
.lb-name { flex: 1; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-name small { display: block; color: var(--hint); font-size: 11px; font-weight: 500; }
.lb-score { font-weight: 900; color: var(--gold); font-size: 14px; }
.lb-row.me { border: 1px solid var(--gold); }

/* achievements */
.ach-item.locked { opacity: 0.55; }
.ach-icon {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,201,77,0.10);
  border-radius: 13px;
  color: var(--gold);
  flex-shrink: 0;
}
.ach-icon .icon { width: 22px; height: 22px; }
.ach-item.locked .ach-icon { background: rgba(255,255,255,0.06); color: var(--hint); }
.ach-reward {
  display: inline-flex; align-items: center; gap: 4px;
  direction: ltr;
  font-size: 12px; color: var(--gold); font-weight: 800; margin-top: 3px;
}
.claim-btn {
  display: inline-flex; align-items: center; gap: 5px;
  direction: ltr;
  padding: 8px 14px;
  background: linear-gradient(180deg, #7fe7ad, var(--ok));
  color: #06281a;
  border: none; border-radius: 12px;
  font-weight: 900; font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  animation: pulse-glow 1.8s infinite;
}
.claim-done { color: var(--ok); flex-shrink: 0; }
.claim-done .icon { width: 20px; height: 20px; }

/* ============ Loading ============ */
.loading-overlay {
  position: absolute; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  z-index: 100;
}
.loading-bird { color: var(--gold); animation: float 1.4s ease-in-out infinite; }
.loading-bird .icon { width: 54px; height: 54px; stroke-width: 1.4; }
.loading-text { color: var(--hint); font-size: 14px; }

/* ============ Toasts ============ */
#toasts {
  position: absolute;
  top: calc(var(--safe-top) + 74px);
  left: 0; right: 0;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  pointer-events: none;
  z-index: 200;
}
.toast {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(14,22,38,0.92);
  border: 1px solid rgba(255,201,77,0.35);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  max-width: 88vw;
  text-align: center;
}
.toast .icon { color: var(--gold); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ============ NEST currency & attempts ============ */
.badges-col { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
.badges-col .coin-badge { padding: 5px 10px; font-size: 13px; }
.nest-badge {
  display: inline-flex; align-items: center; gap: 6px;
  direction: ltr;
  font-weight: 800; font-size: 13px;
  background: rgba(108,196,255,0.14);
  color: #6cc4ff;
  padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}

.attempts-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 380px;
}
.attempts-pips { display: flex; gap: 5px; direction: ltr; }
.attempts-pips .icon {
  width: 19px; height: 19px;
  color: #ffd166;
  opacity: 0.22;
}
.attempts-pips .icon.on { opacity: 1; filter: drop-shadow(0 0 6px rgba(255,209,102,0.5)); }
.attempts-timer { font-size: 12px; color: var(--hint); font-weight: 700; }
.attempts-buy {
  display: inline-flex; align-items: center; gap: 2px;
  background: rgba(108,196,255,0.14);
  color: #6cc4ff;
  border: none; border-radius: 999px;
  padding: 6px 11px;
  font-weight: 900; font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.attempts-buy:active { transform: scale(0.94); }

.go-attempts {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 12px;
  font-size: 13px; color: var(--hint); font-weight: 700;
}
.go-attempts .icon { color: #ffd166; }
.go-attempts b { color: var(--text); }

/* NEST store tab */
.tab-nest { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.tab-nest .icon { width: 14px; height: 14px; }
.nest-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
}
.nest-card h3 {
  display: flex; align-items: center; gap: 7px;
  font-size: 14px; margin-bottom: 4px;
}
.nest-card h3 .icon { color: #6cc4ff; }
.nest-card .nest-sub { font-size: 12px; color: var(--hint); margin-bottom: 11px; }
.nest-pack {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 13px;
  padding: 11px 12px;
  margin-bottom: 8px;
}
.nest-pack-info { flex: 1; }
.nest-pack-amount {
  display: inline-flex; align-items: center; gap: 5px;
  direction: ltr;
  font-weight: 900; font-size: 15px; color: #6cc4ff;
}
.nest-pack-name { font-size: 11.5px; color: var(--hint); margin-top: 2px; }
.stars-btn {
  display: inline-flex; align-items: center; gap: 5px;
  direction: ltr;
  padding: 9px 14px;
  background: linear-gradient(180deg, #8ecbff, #4da3e8);
  color: #06223a;
  border: none; border-radius: 12px;
  font-weight: 900; font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.stars-btn:active { transform: scale(0.94); }
.exchange-row { display: flex; gap: 8px; }
.exchange-row .buy-btn { flex: 1; justify-content: center; }
.split-row { display: flex; gap: 8px; }
.split-row > * { flex: 1; justify-content: center; }
