* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: var(--tg-theme-bg-color, #000000);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #18181b);
  --card-bg: #131315;
  --card-bg-hover: #1c1c1f;
  --text: var(--tg-theme-text-color, #ffffff);
  --text-secondary: var(--tg-theme-hint-color, #8b8b93);
  --accent: var(--tg-theme-button-color, #ffffff);
  --accent-text: var(--tg-theme-button-text-color, #000000);
  --link: var(--tg-theme-link-color, #5b9dff);
  --border: #232326;
  --success: #5dcaa5;
  --warning: #efb84a;
  --danger: #e0544f;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

button {
  border: none;
  background: none;
  cursor: pointer;
}

a {
  color: var(--link);
  text-decoration: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* ═══════════ Header ═══════════ */
.header {
  padding: 16px 16px 8px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ═══════════ Screens ═══════════ */
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen {
  padding: 8px 16px 24px;
  display: none;
  flex: 1;
}

.screen.active {
  display: block;
  animation: screenIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ═══════════ Cards ═══════════ */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 14px 16px;
}

.card + .card {
  margin-top: 8px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
}

.stat-value.accent-success { color: var(--success); }
.stat-value.accent-warning { color: var(--warning); }

/* ═══════════ Buttons ═══════════ */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary.selected {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-sm {
  height: 34px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: 8px;
  width: auto;
}

/* ═══════════ Liquid fill button (generate CTA) ═══════════ */
.btn-liquid {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.btn-liquid .btn-liquid-label {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-liquid::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: var(--text);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 1;
  border-radius: inherit;
}

.btn-liquid:active::before {
  transform: translateY(0%);
}

.btn-liquid:active .btn-liquid-label {
  color: var(--bg);
  transition: color 0.2s 0.05s;
}

/* ═══════════ Chip / filter grid ═══════════ */
.chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.chip-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 2px;
  scrollbar-width: none;
}

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

.chip-scroll .chip {
  flex: 0 0 auto;
  padding: 0 16px;
  white-space: nowrap;
}

.chip {
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.1s;
}

.chip:active {
  transform: scale(0.96);
}

.chip.selected {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.chip.locked {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip.locked i {
  font-size: 13px;
}

/* ═══════════ Search input ═══════════ */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 44px;
  margin-bottom: 10px;
}

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 15px;
}

.search-box input::placeholder {
  color: var(--text-secondary);
}

.search-box i {
  color: var(--text-secondary);
  font-size: 18px;
}

/* ═══════════ Result list ═══════════ */
@keyframes resultIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  animation: resultIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  transition: border-color 0.15s, transform 0.1s;
}

.result-item:active {
  transform: scale(0.985);
  border-color: var(--border-strong, #333);
}

.result-item + .result-item {
  margin-top: 8px;
}

.result-name {
  font-size: 15px;
  font-weight: 600;
  font-family: "SF Mono", "Roboto Mono", monospace;
}

.result-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.result-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  transition: transform 0.12s, background 0.15s;
}

.icon-btn:active {
  transform: scale(0.88);
}

.icon-btn.active {
  background: rgba(93, 202, 165, 0.15);
  color: var(--success);
}

/* ═══════════ Empty / loading states ═══════════ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 32px;
  margin-bottom: 12px;
  display: block;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

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

.loading-wrap {
  padding: 48px 24px;
  text-align: center;
}

.loading-text {
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ═══════════ Toast ═══════════ */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(84px + var(--safe-bottom));
  background: var(--card-bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: center;
  z-index: 100;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ═══════════ Tab bar ═══════════ */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 50;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  color: var(--text-secondary);
  font-size: 11px;
  transition: color 0.2s;
}

.tab i {
  font-size: 22px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tab:active i {
  transform: scale(0.85);
}

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

.tab.active i {
  transform: scale(1.08);
}

/* ═══════════ Plan cards ═══════════ */
.plan-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
}

.plan-card + .plan-card {
  margin-top: 12px;
}

.plan-card.featured {
  border: 2px solid var(--text);
}

.plan-badge {
  position: absolute;
  top: -10px;
  left: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}

.plan-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.plan-price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.plan-price-main {
  font-size: 26px;
  font-weight: 700;
}

.plan-price-period {
  font-size: 13px;
  color: var(--text-secondary);
}

.plan-price-alt {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.plan-features {
  list-style: none;
  margin-bottom: 16px;
}

.plan-features li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
}

.plan-features i {
  color: var(--success);
  font-size: 15px;
  flex-shrink: 0;
}

/* ═══════════ Duration switch (segmented) ═══════════ */
.seg-control {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.seg-btn {
  flex: 1;
  height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.seg-btn.selected {
  background: var(--text);
  color: var(--bg);
}

/* ═══════════ Section labels ═══════════ */
.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 20px 0 8px;
}

.section-label:first-child {
  margin-top: 0;
}

/* ═══════════ List rows (profile links) ═══════════ */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.list-row + .list-row {
  margin-top: 8px;
}

.list-row i.chevron {
  color: var(--text-secondary);
  font-size: 16px;
}

/* ═══════════ Wallet task row ═══════════ */
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  gap: 10px;
}

.task-row + .task-row {
  margin-top: 8px;
}

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

.task-reward {
  font-size: 12px;
  color: var(--warning);
  margin-top: 2px;
}

.task-btn-done {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* ═══════════ Modal sheet ═══════════ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: none;
  align-items: flex-end;
}

.sheet-overlay.show {
  display: flex;
}

.sheet {
  background: var(--bg-secondary);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 16px calc(24px + var(--safe-bottom));
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
