:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2ea6ff);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  /* Bottom padding clears the fixed bottom navigation. */
  padding: 16px 14px calc(92px + env(safe-area-inset-bottom));
}

/* Compact balance row — label left, accent amount right (no heavy block). */
.balance {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 4px;
  border-radius: 14px;
  background: var(--secondary-bg);
  border: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
}

.balance-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--hint);
}

.balance-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.balance-amount {
  font-size: 22px;
  font-weight: 700;
  color: var(--btn);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.balance-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--hint);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
  margin: 26px 4px 12px;
}

/* The first section title under the hero shouldn't double the gap. */
.tab-content > .section-title:first-child {
  margin-top: 18px;
}

/* Subtle premium entrance when switching tabs. */
.tab-content {
  animation: tab-in 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes tab-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Fixed bottom navigation — Liquid Glass: frosted translucent over the scrolling
   content, with a hairline edge and soft lift. Falls back to a solid bar where
   backdrop-filter / color-mix aren't supported. */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  display: flex;
  background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--text) 9%, transparent);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.07);
  padding-bottom: env(safe-area-inset-bottom);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .bottom-nav {
    background: color-mix(in srgb, var(--bg) 65%, transparent);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    backdrop-filter: blur(22px) saturate(180%);
  }
}

.nav-item {
  position: relative;
  flex: 1 1 0;
  appearance: none;
  border: none;
  cursor: pointer;
  background: transparent;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  color: var(--hint);
  transition: color 0.16s ease, transform 0.16s ease;
}

/* Accent indicator bar above the active tab. */
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 26px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--btn);
  transform: translateX(-50%);
}

.nav-item.active {
  color: var(--btn);
}

.nav-item:active {
  transform: scale(0.92);
}

.nav-icon {
  font-size: 21px;
  line-height: 1;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* History rows */
.history {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg);
}

.history:last-child {
  border-bottom: none;
}

.history-delta {
  flex: 0 0 auto;
  min-width: 44px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-delta.pos {
  color: #2ea043;
}

.history-delta.neg {
  color: var(--hint);
}

.history-reason {
  font-weight: 600;
}

.history-date {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
}

.more-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  appearance: none;
  border: none;
  cursor: pointer;
  background: var(--secondary-bg);
  color: var(--link);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  border-radius: 12px;
  transition: opacity 0.12s ease;
}

.more-btn:active {
  opacity: 0.7;
}

.more-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.card {
  background: var(--secondary-bg);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--text) 6%, transparent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.model {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg);
}

.model:last-child {
  border-bottom: none;
}

.model-emoji {
  font-size: 24px;
  line-height: 1.3;
  flex: 0 0 auto;
}

.model-body {
  flex: 1 1 auto;
  min-width: 0;
}

.model-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.model-title {
  font-weight: 600;
}

.model-cost {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--btn);
  white-space: nowrap;
}

.model-desc {
  font-size: 14px;
  color: var(--hint);
  margin-top: 2px;
}

.preset {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg);
  cursor: pointer;
  transition: opacity 0.12s ease;
}

.preset:last-child {
  border-bottom: none;
}

.preset:active {
  opacity: 0.6;
}

/* Accent bar + coloured name marks the selected preset (theme-var friendly). */
.preset.active {
  box-shadow: inset 3px 0 0 var(--btn);
}

.preset-name {
  font-weight: 600;
}

.preset.active .preset-name {
  color: var(--btn);
}

.method {
  margin-bottom: 18px;
}

.method-name {
  font-size: 14px;
  font-weight: 600;
  margin: 0 4px 10px;
}

.pkg-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pkg-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  background: var(--btn);
  color: var(--btn-text);
  border-radius: 12px;
  padding: 14px 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 60px;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--btn) 35%, transparent);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.pkg-btn:active {
  opacity: 0.85;
  transform: scale(0.97);
}

.pkg-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.pkg-price {
  font-size: 17px;
}

.pkg-tokens {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}

.empty {
  color: var(--hint);
  text-align: center;
  padding: 24px 12px;
  font-size: 15px;
}

.fatal {
  text-align: center;
  padding: 60px 24px;
  color: var(--hint);
  font-size: 17px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 88%;
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1000;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.toast.show {
  opacity: 0.96;
}
