/* ============================================
   VARIABLES
   ============================================ */
:root {
  --bg1: #050816;
  --bg2: #0b1020;
  --accent: #6c5ce7;
  --accent-soft: rgba(108, 92, 231, 0.2);
  --accent-strong: rgba(108, 92, 231, 0.9);
  --text: #f5f7ff;
  --text-muted: #8f96b8;
  --card-bg: rgba(15, 20, 40, 0.75);
  --border: rgba(255, 255, 255, 0.06);
  --danger: #ff7675;
  --success: #00b894;
  --tg-vh: 1vh; /* CSS переменная для корректной высоты viewport в Telegram WebView, устанавливается через JS */
  
  /* Field validation error colors */
  --field-error: #ff7675;
  --field-error-bg: rgba(255, 118, 117, 0.1);
  
  /* Glassmorphism variables */
  --glass-bg: rgba(15, 20, 40, 0.35);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 16px;
}

/* ============================================
   RESET / BASE
   ============================================ */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #141a33 0, #050816 45%, #000 100%);
  overflow: hidden; /* Prevent body scroll, scroll only inside .app-main */
}

body {
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ============================================
   BACKGROUND
   ============================================ */
.bg-animated {
  position: fixed;
  inset: -20%;
  /* Base fallback for all browsers */
  background-image: url("/img/home.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-blend-mode: overlay;
  filter: blur(0.3px);
  animation: bgFloat 22s infinite alternate ease-in-out;
  z-index: 0;
  pointer-events: none; /* Ensure background doesn't block clicks */
}

/* WebP support with image-set (progressive enhancement) */
@supports (background-image: image-set(url("/img/home.webp") type("image/webp"))) {
  .bg-animated {
    background-image: 
      image-set(
        url("/img/home.webp") type("image/webp"),
        url("/img/home.jpg") type("image/jpeg")
      ),
      url("/img/home.jpg");
  }
}

/* Dark overlay using ::before pseudo-element for better control */
.bg-animated::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(5, 8, 22, 0.40) 0%,
    rgba(11, 16, 32, 0.40) 50%,
    rgba(0, 0, 0, 0.40) 100%
  );
  pointer-events: none; /* Ensure overlay doesn't block clicks */
  z-index: 0;
}

/* Keep animated gradients on top of overlay for visual interest */
.bg-animated::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(108, 92, 231, 0.15), transparent 55%),
    radial-gradient(circle at 80% 0%, rgba(0, 184, 148, 0.12), transparent 55%),
    radial-gradient(circle at 50% 100%, rgba(9, 132, 227, 0.14), transparent 55%);
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: screen; /* Blend with overlay for subtle effect */
}

@keyframes bgFloat {
  0% { transform: translate3d(0, 0, 0) scale(1.02); }
  50% { transform: translate3d(-10px, -12px, 0) scale(1.04); }
  100% { transform: translate3d(8px, 10px, 0) scale(1.03); }
}

/* ============================================
   LAYOUT
   ============================================ */
.app-root {
  position: relative;
  z-index: 1; /* Ensure content is above background */
  width: 100%;
  height: 100%;
  min-height: calc(var(--tg-vh, 1vh) * 100);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top, 12px)) 12px max(18px, env(safe-area-inset-bottom, 18px));
  overflow: hidden; /* Prevent root scroll, scroll only inside main */
}

/* Support for safe-area viewport height on modern browsers */
@supports (min-height: 100svh) {
  .app-root {
    min-height: 100svh;
  }
}

.app-header {
  padding: 4px 2px 0;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
  padding-bottom: 10px;
  min-height: 0; /* Important for flex container with scroll */
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--glass-bg);
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  padding: 10px 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  /* Glassmorphism: backdrop-filter with webkit prefix for iOS/Telegram */
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
}

/* Fallback for browsers without backdrop-filter support */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card {
    background: rgba(15, 20, 40, 0.35);
  }
}

.loading-card {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

.card-header {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.card-header-with-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 32px; /* Совпадает с высотой .btn-header-icon для идеального выравнивания */
}

.card-header-title {
  display: flex;
  align-items: center;
  flex: 1;
  line-height: 1;
  margin: 0;
  padding: 0;
  height: 32px; /* Точная высота для выравнивания с иконками */
}

.card-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  height: 32px; /* Точная высота для выравнивания */
}

/* Ensure Profile header (title + icons) are on the same vertical line */
/* Use CSS Grid for perfect alignment: title centered, actions right-aligned */
.user-card .card-header-with-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 32px; /* match icon button height */
}

.user-card .card-header-title {
  grid-column: 2;
  justify-self: center;
  margin: 0;
  line-height: 1;
}

.user-card .card-header-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-card .btn-header-icon {
  margin-top: 0;
}

.btn-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-header-icon:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.btn-header-icon:active {
  transform: translateY(0);
}

.btn-header-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.claim-card-header {
  text-align: center;
}

/* Mobile: wrap buttons if needed */
@media (max-width: 480px) {
  .card-header-with-actions {
    flex-wrap: wrap;
  }
  
  .card-header-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 4px;
  }
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ============================================
   TYPOGRAPHY / ROWS
   ============================================ */
.app-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.row span:first-child {
  color: var(--text-muted);
}

.row span:last-child {
  font-weight: 500;
}

.rewards-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reward-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reward-info {
  display: flex;
  flex-direction: column;
}

.reward-title {
  font-size: 15px;
  font-weight: 600;
}

.reward-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.claims-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.claim-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.claim-info {
  display: flex;
  flex-direction: column;
}

.claim-title {
  font-size: 14px;
  font-weight: 500;
}

.claim-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.claim-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.verified-badge {
  display: inline-block;
  margin-left: 4px;
  font-size: 12px;
}

.verified-badge.hidden {
  display: none;
}

.ref-link {
  margin-top: 4px;
  word-break: break-all;
  font-size: 12px;
  color: var(--accent-strong);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent-strong), #4834d4);
  color: #fff;
  box-shadow: 0 6px 18px rgba(108, 92, 231, 0.6);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn.full {
  width: 100%;
  margin-top: 8px;
}

.btn:active {
  transform: scale(0.97) translateY(1px);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden {
  display: none !important;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(120%);
  min-width: min(90vw, 320px);
  max-width: 90vw;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(12, 17, 34, 0.96);
  color: var(--text);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.04);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 50;
}

.toast--error {
  border-color: rgba(255, 118, 117, 0.5);
}

.toast--success {
  border-color: rgba(0, 184, 148, 0.7);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   MEDIA QUERIES
   ============================================ */
@media (min-width: 480px) {
  .app-root {
    max-width: 420px;
    margin: 0 auto;
  }
}
