:root {
  --tg-bg: #ffffff;
  --tg-text: #1c1c1e;
  --tg-hint: #8e8e93;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f2f2f7;
  --card-bg: #ffffff;
  --border-color: #e5e5ea;
  --success: #34c759;
  --danger: #ff3b30;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tg-bg: #1c1c1e;
    --tg-text: #ffffff;
    --tg-hint: #98989f;
    --tg-secondary-bg: #2c2c2e;
    --card-bg: #2c2c2e;
    --border-color: #3a3a3c;
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--tg-bg);
  z-index: 10;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
}

#content {
  flex: 1;
  padding: 12px 12px 90px 12px;
  overflow-y: auto;
}

.state-message {
  text-align: center;
  padding: 40px 16px;
  color: var(--tg-hint);
  font-size: 15px;
}

.state-message.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 4px 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--tg-hint);
  font-family: inherit;
  cursor: pointer;
}

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

.tab-icon {
  font-size: 20px;
}

.tab-label {
  font-size: 11px;
  font-weight: 600;
}

/* --- Umumiy kartochka --- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  color: var(--tg-hint);
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.row + .row {
  border-top: 1px solid var(--border-color);
}

.row-label {
  color: var(--tg-text);
  font-size: 15px;
}

.row-value {
  font-weight: 700;
  font-size: 15px;
}

/* --- Profil --- */

.profile-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 2px;
}

.profile-rank {
  color: var(--tg-hint);
  font-size: 13px;
  margin-bottom: 14px;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.balance-item {
  background: var(--tg-secondary-bg);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}

.balance-item .icon {
  font-size: 22px;
  display: block;
  margin-bottom: 4px;
}

.balance-item .value {
  font-weight: 700;
  font-size: 15px;
}

/* --- Reyting --- */

.metric-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.metric-btn {
  flex: 1;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.metric-btn.active {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border-color: var(--tg-button);
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.lb-row + .lb-row {
  border-top: 1px solid var(--border-color);
}

.lb-rank {
  width: 26px;
  text-align: center;
  font-weight: 700;
  color: var(--tg-hint);
}

.lb-name {
  flex: 1;
  font-size: 15px;
}

.lb-value {
  font-weight: 700;
}

/* --- Tarix --- */

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

.history-row + .history-row {
  border-top: 1px solid var(--border-color);
}

.history-role {
  font-size: 15px;
  font-weight: 600;
}

.history-meta {
  font-size: 12px;
  color: var(--tg-hint);
  margin-top: 2px;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.badge.win {
  background: rgba(52, 199, 89, 0.15);
  color: var(--success);
}

.badge.loss {
  background: rgba(255, 59, 48, 0.15);
  color: var(--danger);
}

/* --- Do'kon --- */

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.shop-item + .shop-item {
  border-top: 1px solid var(--border-color);
}

.shop-item .icon {
  font-size: 28px;
}

.shop-item .info {
  flex: 1;
}

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

.shop-item .price-options {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.price-btn {
  border: 1px solid var(--border-color);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

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

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 0 8px 0;
}

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

/* --- Convert (valyuta almashtirish) --- */

.convert-pairs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.convert-pair-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal-sheet {
  background: var(--card-bg);
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0)) 16px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
}

.amount-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 12px;
}

.preset-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.preset-btn {
  flex: 1;
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: none;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.secondary-btn {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--tg-hint);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
}

.toast {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  background: var(--tg-text);
  color: var(--tg-bg);
  padding: 12px 16px;
  border-radius: 12px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

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