:root {
  --bg: #0b0e14;
  --bg-soft: #12161f;
  --card: #161b26;
  --border: rgba(255,255,255,0.08);
  --text: #f2f4f8;
  --muted: #9aa4b2;
  --ton: #0098ea;
  --ton-2: #40c4ff;
  --accent-grad: linear-gradient(135deg, #0098ea 0%, #6a5cff 100%);
  --nav-height: 64px;
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-bottom: var(--nav-height);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
  background: radial-gradient(circle at 20% 0%, #12213a 0%, var(--bg) 45%) fixed;
  color: var(--text);
  min-height: 100vh;
}

#app { max-width: 720px; margin: 0 auto; padding: 0 14px 20px; }

/* === TOPBAR === */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 2px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}
.topbar__brand {
  font-weight: 700;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 0 12px var(--ton-2);
}

#ton-connect button { border-radius: 12px !important; }

/* === PAGE SYSTEM === */

.page { display: none; }
.page--active { display: block; }

/* === BOTTOM NAV === */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(11, 14, 20, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  z-index: 100;
}
.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 12px;
  transition: color .15s;
}
.bottom-nav__item--active { color: var(--ton-2); }
.bottom-nav__icon { font-size: 20px; line-height: 1; }
.bottom-nav__label { font-size: 10.5px; font-weight: 600; }

/* === COLLECTION HEAD (market page) === */

.collection-head {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.collection-head__banner {
  height: 100px;
  background: var(--accent-grad);
  background-size: cover;
  background-position: center;
}
.collection-head__info {
  display: flex;
  gap: 12px;
  padding: 0 14px 14px;
  margin-top: -32px;
}
.collection-head__avatar {
  width: 64px; height: 64px;
  border-radius: 16px;
  object-fit: cover;
  border: 3px solid var(--card);
  background: #222;
}
.collection-head__text {
  padding-top: 34px;
  flex: 1;
}
.collection-head__text h2 {
  margin: 0 0 2px;
  font-size: 17px;
}
.collection-head__text p {
  margin: 0 0 4px;
  font-size: 12.5px;
  color: var(--muted);
}
.collection-head__count {
  font-size: 11px;
  color: var(--ton-2);
  font-weight: 600;
}

/* === PROFILE HEAD (profile page) === */

.profile-head {
  margin-bottom: 14px;
}
.profile-head__inner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.profile-head__avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.profile-head__info { flex: 1; }
.profile-head__name {
  font-weight: 700;
  font-size: 16px;
}
.profile-head__id {
  font-size: 12px;
  color: var(--muted);
}

/* === CONNECT PROMPT === */

.connect-prompt {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  margin-bottom: 14px;
}
.connect-prompt__icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.connect-prompt__title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
}
.connect-prompt__text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 280px;
  margin: 0 auto;
}

/* === BALANCE CARD === */

.balance-card {
  background: linear-gradient(135deg, #1a2a4a 0%, var(--card) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.balance-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.balance-card__item { display: flex; flex-direction: column; }
.balance-card__amount {
  font-size: 22px;
  font-weight: 800;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.balance-card__actions { display: flex; gap: 8px; }

.btn--small {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn--deposit { background: #00c853; color: white; }
.btn--withdraw { background: var(--ton); color: white; }
.btn--outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 10px;
}

/* === WALLET CARD === */

.wallet-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.wallet-card__row { display: flex; justify-content: space-between; align-items: center; }
.wallet-card__addr { font-size: 13px; font-weight: 600; }
.wallet-card__balance { text-align: right; }

/* === GALLERY === */

.gallery, .profile-nfts {
  margin-bottom: 16px;
}
.gallery__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 12px;
}
.gallery__head h2 { font-size: 17px; margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.nft-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
}
.nft-card:active { transform: scale(0.97); }
.nft-card img {
  width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block;
  background: #1c2230;
}
.nft-card__body { padding: 10px 10px 12px; }
.nft-card__collection {
  font-size: 10.5px;
  color: var(--ton-2);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 3px;
  display: block;
}
.nft-card__name { font-size: 13.5px; font-weight: 600; }

.skeleton {
  aspect-ratio: 1/1;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--card) 25%, #1c2230 37%, var(--card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 40px 10px;
  font-size: 14px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  color: var(--ton-2);
  background: rgba(0,152,234,0.12);
  padding: 3px 9px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.btn {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn--primary { background: var(--accent-grad); color: white; }

/* === MODAL === */

.modal {
  position: fixed; inset: 0;
  display: none;
  align-items: flex-end;
  z-index: 50;
}
.modal.open { display: flex; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}
.modal__card {
  position: relative;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--border);
  padding: 0 0 18px;
  animation: slideUp .18s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0;} to { transform: translateY(0); opacity: 1; } }
.modal__close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
}
#modal-image {
  width: 100%; aspect-ratio: 1/1; object-fit: cover;
  border-radius: 22px 22px 0 0;
}
.modal__body { padding: 16px 18px 0; }
.modal__body h3 { margin: 0 0 8px; font-size: 18px; }
.modal__body p { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin-bottom: 16px; }

/* === INPUTS === */

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 16px;
  margin: 8px 0 14px;
  box-sizing: border-box;
}
.input:focus { outline: none; border-color: var(--ton); }

.address-box {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
  margin: 8px 0;
  color: var(--muted);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0;
}

.status-msg {
  margin-top: 10px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}
.status-msg.success { color: #00c853; }
.status-msg.error { color: #ff5252; }

/* === STAT === */

.stat__label { font-size: 11.5px; color: var(--muted); }
.stat__value { font-size: 16px; font-weight: 700; }

/* === RESPONSIVE === */

@media (min-width: 480px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
