:root {
  --blue: #0052FF;
  --blue-dark: #0040CC;
  --text: #0A0A0B;
  --text-soft: #64748B;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --nav-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100dvh; overflow-x: hidden;
}

/* ── Header ── */
header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.logo { font-size: 1.4rem; font-weight: 900; color: var(--blue); text-decoration: none; }
.logo span { color: var(--text); }
.credit-badge {
  background: #FEF9C3; color: #854D0E;
  padding: 4px 12px; border-radius: 99px;
  font-size: 0.85rem; font-weight: 700;
}
.lang-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 10px;
  font-size: 0.8rem; cursor: pointer; color: var(--text-soft);
}

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h); background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100; padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 1.4rem; color: var(--text-soft);
  text-decoration: none; flex: 1; padding: 8px 0;
}
.nav-item span { font-size: 0.65rem; }
.nav-item.active { color: var(--blue); }
.nav-post-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--blue); color: #fff;
  border: none; font-size: 1.8rem; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,82,255,.35);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.nav-post-btn:active { transform: scale(.93); }

/* ── Main ── */
main { padding-bottom: calc(var(--nav-h) + 24px); min-height: calc(100dvh - 56px); }

/* ── Categories / Pill Nav ── */
.categories-nav {
  display: flex; gap: 8px; padding: 12px 16px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.categories-nav::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0; padding: 6px 16px; border-radius: 99px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.pill.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Post CTA Bar ── */
.post-cta-bar {
  margin: 0 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1.5px dashed var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  cursor: pointer; color: var(--text-soft); font-size: 0.9rem;
}
.post-cta-btn {
  background: var(--blue); color: #fff;
  padding: 6px 14px; border-radius: 99px;
  font-size: 0.8rem; font-weight: 700;
}

/* ── Feed / Ad Cards ── */
.feed { padding: 0 8px 8px; }

/* Wrap is always position:relative so the upvote button can escape the <a> */
.ad-card-wrap { position: relative; }

.ad-card {
  display: block; background: var(--surface);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); text-decoration: none; color: var(--text);
  transition: transform .15s;
}
.ad-card:active { transform: scale(.98); }
.ad-card img { width: 100%; object-fit: cover; display: block; }

.tier-hero { margin-bottom: 8px; }
.tier-hero img { aspect-ratio: 16/9; }
.tier-large-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.tier-large img { aspect-ratio: 4/3; }
.tier-medium-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.tier-medium img { aspect-ratio: 1/1; }
.tier-small-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.tier-small img { aspect-ratio: 1/1; }

.card-content { padding: 10px 12px 12px; }
.card-title {
  font-size: 0.85rem; font-weight: 700; margin: 2px 0 4px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta-row {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
}

/* ── Card Upvote Button ── */
.card-upvote-btn {
  display: inline-flex; align-items: center; gap: 3px;
  background: #F1F5F9; border: 1.5px solid var(--border);
  border-radius: 99px; padding: 3px 10px;
  font-size: 0.75rem; font-weight: 700; color: var(--text-soft);
  cursor: pointer; transition: all .15s;
  white-space: nowrap; flex-shrink: 0;
  position: relative; z-index: 2;
}
.card-upvote-btn:hover  { background: #EEF2FF; border-color: var(--blue); color: var(--blue); }
.card-upvote-btn.voted  { background: var(--blue); color: #fff; border-color: var(--blue); }
.card-upvote-btn:disabled { opacity: 0.6; cursor: default; }

.upvote-pos-card-meta {
  position: absolute;
  bottom: 12px;
  right: 12px;
}
.upvote-pos-overlay {
  position: absolute;
  bottom: 6px;
  right: 6px;
  padding: 2px 7px;
  font-size: 0.7rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(4px);
}
.upvote-pos-text-row {
  position: static;
  flex-shrink: 0;
}

.price { font-size: 1.1rem; font-weight: 900; color: var(--blue); }
.price-tag {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(0,0,0,.6); color: #fff;
  padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; font-weight: 700;
}
.meta {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.75rem; color: var(--text-soft);
}

/* ── Text tier ── */
.tier-text-list { display: flex; flex-direction: column; gap: 1px; margin-bottom: 8px; }
.tier-text-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* ── Detail View ── */
.detail-view { padding-bottom: 40px; }
.back-btn { margin: 12px 16px; }
.detail-content { padding: 16px; }
.detail-title { font-size: 1.3rem; font-weight: 900; margin: 4px 0 8px; line-height: 1.3; }
.detail-desc { color: var(--text-soft); font-size: 0.9rem; line-height: 1.6; margin-bottom: 16px; }

.owner-controls {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.btn-danger { color: #dc2626 !important; border-color: #dc2626 !important; }

.vote-row { display: flex; gap: 8px; margin-bottom: 20px; }
.vote-btn {
  flex: 1; padding: 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 0.9rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.vote-cost { font-size: 0.75rem; font-weight: 400; color: var(--text-soft); }
.vote-btn.voted-up   { background: var(--blue); color: #fff; border-color: var(--blue); }
.vote-btn.voted-down { background: #FEE2E2; color: #dc2626; border-color: #dc2626; }

.action-stack { display: flex; flex-direction: column; gap: 10px; }
.action-btn { width: 100%; padding: 14px; font-size: 1rem; }

/* ── Gallery ── */
.gallery { position: relative; overflow: hidden; background: #f1f5f9; }
.gallery-track { display: flex; transition: transform .3s ease; }
.gallery-img { flex-shrink: 0; width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.gallery-dots {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); cursor: pointer; }
.dot.active { background: #fff; }
.gallery-empty {
  aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center;
  font-size: 3rem; color: var(--text-soft); background: #f1f5f9;
}

/* Gallery prev/next arrow buttons
   Hidden by default (touch devices use swipe).
   Shown only on devices that support hover (= real pointer/mouse). */
.gallery-arrow {
  display: none; /* hidden on touch */
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.88); backdrop-filter: blur(6px);
  border: none; border-radius: 50%;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  font-size: 1.1rem; cursor: pointer; z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  transition: background .15s, opacity .15s;
  color: var(--text);
}
.gallery-arrow:hover { background: #fff; }
.gallery-arrow.prev { left: 10px; }
.gallery-arrow.next { right: 10px; }
.gallery-arrow:disabled { opacity: 0.25; cursor: default; }

/* Show arrows only for pointer (mouse/trackpad) devices */
@media (hover: hover) and (pointer: fine) {
  .gallery-arrow { display: flex; }
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 20px; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 700; cursor: pointer;
  border: 1.5px solid transparent; transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:active { background: var(--blue-dark); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost   { background: transparent; color: var(--text-soft); border-color: transparent; }
.btn-full    { width: 100%; }
.btn-sm      { padding: 6px 14px; font-size: 0.85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ── */
input, select, textarea {
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--blue); }
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 0; }
.form-row .form-group { margin-bottom: 12px; }
.char-count { font-size: 0.75rem; color: var(--text-soft); text-align: right; }
.char-count.warn { color: #f59e0b; }
.field-error { font-size: 0.8rem; color: #dc2626; }
.field-hint  { font-size: 0.75rem; color: var(--text-soft); }

/* ── Image Picker ── */
.image-picker { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.image-slot {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  border: 2px dashed var(--border); display: flex;
  align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; background: var(--bg);
  transition: border-color .15s;
}
.image-slot:hover { border-color: var(--blue); }
.image-slot img { width: 100%; height: 100%; object-fit: cover; }
.image-slot span { font-size: 0.75rem; color: var(--text-soft); text-align: center; white-space: pre-line; }
.slot-main { aspect-ratio: 4/3; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end;
}
.modal-sheet {
  width: 100%; background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
  animation: slideUp .25s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.2rem; font-weight: 900; }
.icon-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-soft); padding: 4px; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Auth Modal ── */
.auth-icon { font-size: 3rem; margin-bottom: 12px; }
.dev-banner {
  background: #FEF9C3; color: #854D0E;
  padding: 8px 12px; border-radius: 8px;
  font-size: 0.8rem; margin-bottom: 16px; text-align: left;
}
.dev-banner a { color: #854D0E; }

/* ── OTP ── */
.otp-wrapper { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.otp-input {
  font-size: 2rem; letter-spacing: 0.4em; text-align: center;
  width: 100%; padding: 16px 8px; border-radius: var(--radius-sm);
  border: 2px solid var(--border);
}
.otp-input:focus { border-color: var(--blue); }
.otp-input-error { border-color: #dc2626 !important; }
.otp-progress { display: flex; gap: 8px; margin-top: 4px; }
.otp-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); transition: background .15s;
}
.otp-dot.filled { background: var(--blue); }

/* ── Wallet / Credits Page ── */
.credits-page { padding: 16px 16px 100px; }
.balance-banner {
  background: linear-gradient(135deg, var(--blue) 0%, #0073FF 100%);
  border-radius: var(--radius); padding: 32px 24px;
  display: flex; flex-direction: column; align-items: center;
  color: #fff; margin-bottom: 24px;
}
.balance-icon { font-size: 2.5rem; margin-bottom: 8px; }
.balance-amount { font-size: 3.5rem; font-weight: 900; line-height: 1; }
.balance-label { font-size: 0.9rem; opacity: .8; margin-top: 4px; }
.section-label { font-size: 0.75rem; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px; }
.pack-list { display: flex; flex-direction: column; gap: 10px; }
.pack-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  cursor: pointer; text-align: left; width: 100%;
}
.pack-featured { border-color: var(--blue); }
.pack-badge { font-size: 0.7rem; font-weight: 700; color: var(--blue); margin-bottom: 2px; }
.pack-credits { font-size: 1rem; font-weight: 700; }
.pack-price { font-size: 1rem; font-weight: 900; color: var(--blue); }
.txn-list { display: flex; flex-direction: column; gap: 1px; }
.txn-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.txn-reason { color: var(--text-soft); text-transform: capitalize; }
.txn-delta { font-weight: 700; }
.txn-delta.positive { color: #16a34a; }
.txn-delta.negative { color: #dc2626; }

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1e293b; color: #fff; padding: 10px 20px;
  border-radius: 99px; font-size: 0.9rem; font-weight: 600;
  opacity: 0; transition: all .25s; z-index: 9999; white-space: nowrap;
  pointer-events: none;
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: #16a34a; }
.toast-error   { background: #dc2626; }

/* ── Misc ── */
.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.empty-feed { text-align: center; padding: 60px 20px; color: var(--text-soft); font-size: 0.95rem; }
.empty-page { text-align: center; padding: 60px 20px; color: var(--text-soft); }
