/* ==========================================================================
   X.com.ly — components.css
   Reusable UI primitives: buttons, cards, chips, progress, badges, toasts,
   modals, avatars, icon buttons.
   ========================================================================== */

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  --btn-bg: var(--c-surface-2);
  --btn-fg: var(--c-text-strong);
  --btn-bd: var(--c-border-strong);
  --btn-shadow: 0 -3px 0 rgba(0, 0, 0, 0.12) inset;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 48px;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 2px solid var(--btn-bd);
  box-shadow: var(--btn-shadow);
  font-weight: var(--fw-extrabold);
  font-size: var(--fs-md);
  letter-spacing: 0.2px;
  text-align: center;
  transition: transform var(--dur-fast) var(--ease),
    filter var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--c-primary);
  --btn-fg: var(--c-text-invert);
  --btn-bd: var(--c-primary-dark);
  text-transform: uppercase;
}
.btn--primary:hover { filter: brightness(1.05); }

.btn--secondary {
  --btn-bg: var(--c-secondary);
  --btn-fg: var(--c-text-invert);
  --btn-bd: var(--c-secondary-dark);
}
.btn--danger {
  --btn-bg: var(--c-danger);
  --btn-fg: var(--c-text-invert);
  --btn-bd: var(--c-danger-dark);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--c-secondary-dark);
  --btn-bd: transparent;
  --btn-shadow: none;
}
.btn--ghost:hover { background: var(--c-secondary-soft); }

.btn--block { display: flex; width: 100%; }
.btn--lg { min-height: 56px; font-size: var(--fs-lg); padding: var(--sp-4) var(--sp-6); }
.btn--sm { min-height: 38px; font-size: var(--fs-sm); padding: var(--sp-2) var(--sp-4); }

.btn--pill { border-radius: var(--r-pill); }

/* ---- Icon button ------------------------------------------------------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  color: var(--c-text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--c-surface-3); color: var(--c-text-strong); }

/* ---- Card -------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  box-shadow: var(--sh-1);
}
.card--flat { box-shadow: none; }
.card--interactive {
  cursor: pointer;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
  border-color: var(--c-primary-light);
}

/* ---- Chips / pills ----------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  border: 1px solid var(--c-border);
}
.chip--primary { background: var(--c-primary-soft); color: var(--c-primary-dark); border-color: transparent; }
.chip--accent { background: var(--c-accent-soft); color: var(--c-accent-dark); border-color: transparent; }

/* ---- Progress ---------------------------------------------------------- */
.progress {
  position: relative;
  height: 16px;
  border-radius: var(--r-pill);
  background: var(--c-surface-3);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0%;
  border-radius: var(--r-pill);
  background: var(--c-primary);
  transition: width var(--dur-slow) var(--ease);
}
.progress__fill::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 8px;
  right: 8px;
  height: 4px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.35);
}

/* ---- Stat pill (XP / hearts / gems) ------------------------------------ */
.stat {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-weight: var(--fw-extrabold);
  color: var(--c-text-muted);
  font-size: var(--fs-md);
}
.stat__icon { font-family: var(--font-emoji); font-size: var(--fs-lg); line-height: 1; }
.stat--hearts .stat__value { color: var(--c-danger-dark); }
.stat--xp .stat__value { color: var(--c-accent-dark); }
.stat--gems .stat__value { color: var(--c-secondary-dark); }

/* Free-hearts quick action (the header hearts pill is a button) */
.stat--btn {
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.stat--btn:hover { background: var(--c-surface-3); }
.stat--btn:active { transform: translateY(1px); }
.stat--btn .stat__plus {
  font-family: var(--font-sans);
  font-weight: var(--fw-black);
  font-size: var(--fs-xs);
  color: var(--c-primary-dark);
}
.stat--btn[data-state="ready"] { animation: heart-beat 1.8s var(--ease) infinite; }
.stat--btn[data-state="claimed"],
.stat--btn[data-state="full"] { opacity: 0.6; }
.stat--btn[data-state="claimed"] .stat__plus,
.stat--btn[data-state="full"] .stat__plus { color: var(--c-text-muted); }

@keyframes heart-beat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.09); }
  24% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .stat--btn[data-state="ready"] { animation: none; }
}

/* ---- Badge ------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--c-league-soft);
  color: var(--c-text-strong);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-extrabold);
  letter-spacing: 0.3px;
}
.badge__icon { font-family: var(--font-emoji); }

/* ---- Avatar ------------------------------------------------------------ */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  object-fit: cover;
  background: var(--c-surface-3);
  border: 2px solid var(--c-border);
}

/* ---- Toast ------------------------------------------------------------- */
.toast-layer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-3));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
  z-index: var(--z-toast);
}
.toast {
  pointer-events: auto;
  max-width: min(92vw, 440px);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--c-text-strong);
  color: var(--c-text-invert);
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  box-shadow: var(--sh-3);
  animation: toast-in var(--dur-slow) var(--ease-bounce);
}
.toast--success { background: var(--c-primary-dark); }
.toast--error { background: var(--c-danger-dark); }
.toast--info { background: var(--c-secondary-dark); }
.toast--out { animation: toast-out var(--dur) var(--ease) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(12px) scale(0.98); }
}

/* ---- Modal / sheet ----------------------------------------------------- */
.modal-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
}
.modal-layer[data-open="true"] { display: block; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 29, 0.55);
  backdrop-filter: blur(2px);
  animation: fade-in var(--dur) var(--ease);
}
.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 460px);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--c-surface);
  border-radius: var(--r-2xl);
  padding: var(--sp-6);
  box-shadow: var(--sh-3);
  animation: pop-in var(--dur-slow) var(--ease-bounce);
}
.modal__title {
  font-size: var(--fs-2xl);
  margin-bottom: var(--sp-3);
  text-align: center;
}
.modal__text { text-align: center; color: var(--c-text-muted); margin-bottom: var(--sp-5); }
.modal__actions { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-5); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---- Segmented control ------------------------------------------------- */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--c-surface-2);
  border-radius: var(--r-pill);
  border: 1px solid var(--c-border);
}
.segmented__item {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--c-text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented__item[aria-selected="true"] {
  background: var(--c-surface);
  color: var(--c-text-strong);
  box-shadow: var(--sh-1);
}

/* ---- Skeleton ---------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--c-surface-2) 25%, var(--c-surface-3) 37%, var(--c-surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ---- Support (donation) bar ------------------------------------------- */
.support-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--supportbar-h, 36px);
  padding: 4px var(--sp-3);
  padding-top: calc(4px + var(--safe-top));
  padding-bottom: 4px;
  background: linear-gradient(90deg, var(--c-primary-darker), var(--c-primary-dark));
  color: var(--c-text-invert);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  box-shadow: var(--sh-1);
  animation: bar-drop var(--dur-slow) var(--ease);
}
.support-bar__text {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.support-bar__emoji { font-family: var(--font-emoji); flex: none; }
.support-bar__cta {
  flex: none;
  color: var(--c-text-invert);
  background: rgba(255, 255, 255, 0.18);
  padding: 3px 12px;
  border-radius: var(--r-pill);
  font-weight: var(--fw-extrabold);
  white-space: nowrap;
}
.support-bar__cta:hover { background: rgba(255, 255, 255, 0.32); color: var(--c-text-invert); }
.support-bar__close {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  color: var(--c-text-invert);
  opacity: 0.85;
  font-size: 14px;
  line-height: 1;
}
.support-bar__close:hover { background: rgba(255, 255, 255, 0.2); opacity: 1; }
@keyframes bar-drop {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Floating action button (Telegram feedback) ----------------------- */
.fab-btn {
  position: fixed;
  left: var(--sp-4);
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-4));
  z-index: var(--z-nav);
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  font-family: var(--font-emoji);
  font-size: 24px;
  line-height: 1;
  background: var(--c-secondary);
  color: var(--c-text-invert);
  box-shadow: 0 6px 16px rgba(28, 176, 246, 0.4);
  transition: transform var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.fab-btn:hover { filter: brightness(1.06); transform: translateY(-2px); }
.fab-btn:active { transform: translateY(1px); box-shadow: var(--sh-1); }

/* ---- Feedback textarea ------------------------------------------------ */
.feedback-input {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: var(--sp-3) var(--sp-4);
  border: 2px solid var(--c-border-strong);
  border-radius: var(--r-lg);
  background: var(--c-surface-2);
  color: var(--c-text-strong);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
}
.feedback-input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: var(--sh-focus);
}

/* ---- Donation nudge (play-time reminder) ------------------------------ */
.donate-nudge {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-4));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: min(94vw, 460px);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-xl);
  background: var(--c-surface);
  border: 2px solid var(--c-primary);
  box-shadow: var(--sh-3);
  animation: nudge-in var(--dur-slow) var(--ease-bounce);
}
.donate-nudge--out { animation: nudge-out var(--dur) var(--ease) forwards; }
.donate-nudge__emoji { flex: none; font-family: var(--font-emoji); font-size: 26px; line-height: 1; }
.donate-nudge__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.donate-nudge__body strong { font-size: var(--fs-sm); color: var(--c-text-strong); }
.donate-nudge__body span { font-size: var(--fs-xs); color: var(--c-text-muted); }
.donate-nudge__cta {
  flex: none;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: var(--c-primary);
  color: var(--c-text-invert);
  font-weight: var(--fw-extrabold);
  font-size: var(--fs-sm);
}
.donate-nudge__cta:hover { color: var(--c-text-invert); filter: brightness(1.05); }
.donate-nudge__close {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  color: var(--c-text-muted);
}
.donate-nudge__close:hover { background: var(--c-surface-3); color: var(--c-text-strong); }
@keyframes nudge-in {
  from { opacity: 0; transform: translate(-50%, 16px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes nudge-out {
  to { opacity: 0; transform: translate(-50%, 12px) scale(0.98); }
}
