:root {
  --bg: #fffdf9;
  --bg-warm: #fff8ee;
  --surface: #ffffff;
  --surface-2: #faf6f0;
  --border: #ebe3d6;
  --text: #2d2a26;
  --text-muted: #7a7267;
  --coffee: #6f4e37;
  --accent: #ffdd00;
  --accent-hover: #f5d000;
  --accent-text: #1a1a1a;
  --accent-glow: rgba(255, 221, 0, 0.45);
  --danger: #e85d5d;
  --radius: 20px;
  --font: 'Nunito', system-ui, sans-serif;
  --font-ar: 'Noto Sans Arabic', 'Nunito', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body[dir='rtl'] {
  font-family: var(--font-ar);
}

.page {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 90% 50% at 50% -5%, rgba(255, 221, 0, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(111, 78, 55, 0.06), transparent),
    var(--bg);
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem max(1rem, env(safe-area-inset-right)) 0
    max(1rem, env(safe-area-inset-left));
  padding-top: max(0.85rem, env(safe-area-inset-top));
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 2rem 0.55rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 40px;
  touch-action: manipulation;
  box-shadow: 0 1px 3px rgba(45, 42, 38, 0.06);
}

.select-wrap select:hover,
.select-wrap select:focus {
  border-color: var(--coffee);
  outline: none;
}

.select-wrap::after {
  content: '▾';
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
}

body[dir='rtl'] .select-wrap::after {
  right: auto;
  left: 0.7rem;
}

body[dir='rtl'] .select-wrap select {
  padding: 0.55rem 0.85rem 0.55rem 2rem;
}

/* Layout */
.bmc-layout {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  padding-bottom: max(2rem, calc(1rem + env(safe-area-inset-bottom)));
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 768px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .donate-card {
    order: -1;
  }
}

/* Profile */
.profile-compact {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.profile-text {
  flex: 1;
  min-width: 0;
  text-align: start;
}

.avatar {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  background: linear-gradient(145deg, var(--accent) 0%, #ffc400 100%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  box-shadow: 0 6px 18px var(--accent-glow);
}

/* Animations */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes floatCoffee {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.92);
  }
  70% {
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes supporterIn {
  from {
    opacity: 0;
    transform: translateX(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

body[dir='rtl'] .donation-item {
  animation-name: supporterInRtl;
}

@keyframes supporterInRtl {
  from {
    opacity: 0;
    transform: translateX(-16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.donate-card.animate-in {
  animation: slideInLeft 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.08s both;
}

.supporters-card.animate-in {
  animation: slideInRight 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.16s both;
}

body[dir='rtl'] .donate-card.animate-in {
  animation-name: slideInRight;
}

body[dir='rtl'] .supporters-card.animate-in {
  animation-name: slideInLeft;
}

.profile-name {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.profile-bio {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 4px 20px rgba(45, 42, 38, 0.05);
}

.supporters-card {
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) {
  .supporters-card {
    position: static;
    max-height: none;
  }
}

/* Coffee amount buttons */
.amount-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.amount-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  background: var(--surface-2);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 0.75rem 0.35rem;
  border-radius: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 72px;
  touch-action: manipulation;
}

.amount-btn .coffee-cups {
  font-size: 1rem;
  line-height: 1;
  letter-spacing: -0.15em;
}

.amount-btn .coffee-price {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--coffee);
}

.amount-btn:hover,
.amount-btn:active {
  border-color: var(--accent-hover);
  background: #fffce8;
  transform: translateY(-1px);
}

.amount-btn.active {
  border-color: var(--accent-hover);
  background: #fff9d6;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.amount-btn.active .coffee-price {
  color: var(--accent-text);
}

.conversion-note {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--coffee);
  background: var(--bg-warm);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.85rem;
  line-height: 1.4;
}

.name-input {
  width: 100%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 0.75rem 1rem;
  outline: none;
  min-height: 48px;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}

.name-input:focus {
  border-color: var(--coffee);
}

.name-input::placeholder {
  color: var(--text-muted);
  font-weight: 600;
}

/* CTA — BMC yellow pill */
.donate-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 999px;
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 4px 0 #e6c700, 0 6px 20px var(--accent-glow);
  min-height: 54px;
  touch-action: manipulation;
}

.donate-btn:hover:not(:disabled),
.donate-btn:active:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #e6c700, 0 10px 28px var(--accent-glow);
}

.donate-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 0 #e6c700, 0 4px 12px var(--accent-glow);
}

.donate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.donate-btn .spinner {
  display: none;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.donate-btn.loading .btn-text {
  display: none;
}

.donate-btn.loading .spinner {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Alerts */
.alert {
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: none;
}

.alert.show { display: block; }

.alert-error {
  background: #fff0f0;
  border: 1px solid #ffc9c9;
  color: var(--danger);
}

.alert-info {
  background: #fff9e6;
  border: 1px solid #ffe08a;
  color: #8a6d00;
}

/* Supporters */
.donations-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  max-height: 420px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.donations-list::-webkit-scrollbar {
  width: 5px;
}

.donations-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.donation-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid transparent;
  animation: supporterIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.donation-item:hover {
  transform: translateX(4px);
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(111, 78, 55, 0.08);
}

body[dir='rtl'] .donation-item:hover {
  transform: translateX(-4px);
}

.donation-item .supporter-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ffc400);
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
  animation: popIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.donation-item .info {
  flex: 1;
  min-width: 0;
}

.donation-item .name {
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.donation-item .time {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.donation-item .amount {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--coffee);
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
}

/* Success page */
.success-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.success-card {
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.success-icon {
  width: 88px;
  height: 88px;
  background: linear-gradient(145deg, var(--accent), #ffc400);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  margin: 0 auto 1.25rem;
  box-shadow: 0 8px 24px var(--accent-glow);
}

.success-card h2 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.6rem;
}

.success-card p {
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.back-link {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  font-weight: 800;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  box-shadow: 0 4px 0 #e6c700;
}

.back-link:hover {
  background: var(--accent-hover);
}

/* Mobile */
@media (max-width: 640px) {
  .bmc-layout {
    padding-top: 0.25rem;
  }

  .donate-card .donate-btn {
    position: sticky;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    z-index: 10;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
