:root {
  --bg: #1C1410;
  --card: #2A1F1A;
  --accent: #C9A96E;
  --accent-hover: #B8944F;
  --text: #F5F0EB;
  --text-muted: #A89080;
  --border: #3E2723;
  --success: #7CB07C;
  --success-bg: #2A3A2A;
  --radius: 16px;
  --radius-sm: 10px;
  --tab-height: 64px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  padding-bottom: var(--tab-height);
  padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: calc(var(--tg-viewport-stable-height, 100vh) - var(--tab-height));
}

.view {
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── Tab Bar ── */

#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-height);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab-btn.active { color: var(--accent); }

.tab-btn svg { width: 22px; height: 22px; }

/* ── Chips ── */

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip {
  padding: 6px 16px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.chip.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ── Featured Card ── */

.featured-card {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 16 / 9;
}

.featured-card .card-bg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.featured-card .card-overlay {
  width: 100%;
  padding: 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.featured-card .badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
  background: rgba(201,169,110,0.2);
  color: var(--accent);
}

.featured-card .card-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.featured-card .card-price {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Trend Grid ── */

.trend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.trend-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 3 / 4;
}

.trend-card.disabled {
  opacity: 0.5;
  cursor: default;
}

.trend-card .card-bg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.trend-card .card-overlay {
  width: 100%;
  padding: 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
}

.trend-card .card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.trend-card .card-price {
  font-size: 12px;
  color: var(--text-muted);
}

.trend-card .badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: var(--bg);
}

.trend-card .badge.soon {
  background: var(--card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Section ── */

.section-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
}

.section-gap { margin-top: 24px; }

/* ── Trend Detail ── */

.trend-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.trend-header .back-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

.trend-header h1 {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
}

.examples-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.examples-row::-webkit-scrollbar { display: none; }

.example-item {
  flex: 0 0 110px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
}

.trend-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Upload ── */

.upload-area {
  width: 100%;
  height: 180px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.upload-area:active { border-color: var(--accent); }

.upload-area.has-file {
  border-color: var(--accent);
  padding: 8px;
}

.upload-area.has-file img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

.upload-icon {
  font-size: 36px;
  color: var(--accent);
  font-weight: 300;
}

.upload-text {
  font-size: 15px;
  color: var(--text-muted);
}

.upload-hint {
  font-size: 12px;
  color: #5D4037;
}

.cost-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-align: center;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 28px;
  background: var(--accent);
  color: var(--bg);
  font-size: 17px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:active { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ── Result ── */

.result-image {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
}

.result-buttons {
  display: flex;
  gap: 12px;
}

.btn-outline {
  flex: 1;
  padding: 14px;
  border-radius: 26px;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-outline:active { background: rgba(201,169,110,0.1); }

.btn-accent {
  flex: 1;
  padding: 14px;
  border-radius: 26px;
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-accent:active { background: var(--accent-hover); }

/* ── Profile ── */

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: var(--bg);
  overflow: hidden;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-name {
  font-size: 22px;
  font-weight: 700;
}

.profile-username {
  font-size: 14px;
  color: var(--text-muted);
}

.balance-card {
  width: 100%;
  border-radius: var(--radius);
  background: var(--card);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.balance-label {
  font-size: 13px;
  color: var(--text-muted);
}

.balance-amount {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

.btn-topup {
  width: 100%;
  padding: 14px;
  border-radius: 24px;
  background: var(--accent);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.btn-topup:active { background: var(--accent-hover); }

/* ── History ── */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--card);
}

.history-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

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

.history-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.status-badge {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-badge.spent {
  background: transparent;
  color: var(--text-muted);
}

.status-badge.refund {
  background: var(--success-bg);
  color: var(--success);
}

/* ── Top Up ── */

.package-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.package-card {
  display: flex;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s;
}

.package-card.selected {
  border-color: var(--accent);
  border-width: 2px;
  padding: 15px;
}

.package-info {
  flex: 1;
}

.package-stars {
  font-size: 18px;
  font-weight: 700;
}

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

.package-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.package-badge {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
}

.package-badge.popular {
  background: var(--accent);
  color: var(--bg);
}

.package-badge.best {
  background: var(--border);
  color: var(--accent);
}

.package-price {
  font-size: 18px;
  font-weight: 700;
}

.payment-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
}

.payment-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--bg);
  flex-shrink: 0;
}

.payment-name {
  font-size: 15px;
  font-weight: 600;
}

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

/* ── Loading ── */

.spinner {
  width: 100%;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner::before {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-text {
  font-size: 14px;
  color: var(--text-muted);
}

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

/* ── Empty State ── */

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
  line-height: 1.5;
}
