:root{
  --header-h: 56px;
  --bottomnav-h: 64px;
  --sidebar-w: 260px;
  --gutter: 16px;
  --radius: 14px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* DVH fallback for webviews */
html, body { height: 100%; }
body{
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
}

/* App shell */
.ts-app{
  background: #0b0f14;
  color: #e7eef7;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Sticky header with safe-area top */
.ts-header{
  position: sticky;
  top: 0;
  z-index: 50;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(11,15,20,0.78);
}
.ts-header-inner{
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gutter);
  gap: 12px;
}
.ts-brand-link{ color: inherit; text-decoration: none; font-weight: 700; }
.ts-brand{
  display: flex;
  align-items: center;
  gap: 10px;
}
.ts-brand-logo{
  width: 28px;
  height: 28px;
}

.ts-header-right{
  display: flex;
  align-items: center;
  gap: 12px;
}

.ts-wallet{
  display: flex;
  align-items: center;
  gap: 12px;
}
.ts-wallet-summary{
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 0.78rem;
  line-height: 1.2;
  color: rgba(231,238,247,0.9);
}
.ts-wallet-summary .muted{ opacity: 0.7; }

@media (max-width: 720px){
  .ts-wallet-summary{ display: none; }
}

/* Shell grid */
.ts-shell{
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100dvh - (var(--header-h) + var(--safe-top)));
}

@media (min-width: 1024px){
  .ts-shell{ grid-template-columns: var(--sidebar-w) 1fr; }
}

/* Desktop sidebar */
.ts-sidebar{ display: none; }
@media (min-width: 1024px){
  .ts-sidebar{
    display: block;
    position: sticky;
    top: calc(var(--header-h) + var(--safe-top));
    height: calc(100dvh - (var(--header-h) + var(--safe-top)));
    overflow: auto;
    border-right: 1px solid rgba(255,255,255,0.08);
    padding: 12px;
  }
}

/* SINGLE scroll container */
.ts-content{
  height: calc(100dvh - (var(--header-h) + var(--safe-top)));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--gutter);
  padding-bottom: calc(var(--gutter) + var(--bottomnav-h) + var(--safe-bottom));
}
@media (min-width: 1024px){
  .ts-content{ padding-bottom: var(--gutter); }
}

.ts-content-inner{
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Mobile bottom nav with safe-bottom */
.ts-bottomnav{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  background: rgba(11,15,20,0.78);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
@media (min-width: 1024px){
  .ts-bottomnav{ display: none; }
}

/* Nav items (both sidebar + bottom) */
.ts-nav-item{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--bottomnav-h);
  text-decoration: none;
  color: inherit;
  opacity: 0.85;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.ts-nav-item.active{
  opacity: 1;
  font-weight: 700;
}
.ts-nav-item:hover{ opacity: 1; }

/* Sidebar nav items */
.ts-sidebar .ts-nav-item{
  justify-content: flex-start;
  height: 44px;
  border-radius: 10px;
  padding: 0 12px;
}
.ts-sidebar .ts-nav-item.active{
  background: rgba(0,255,128,0.10);
}

/* Generic card helper */
.ts-card{
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 16px;
  background: rgba(255,255,255,0.02);
}

.ts-sticky-card{
  position: sticky;
  top: 0;
  z-index: 10;
  margin-bottom: var(--gutter);
  backdrop-filter: blur(10px);
  background: rgba(15,20,30,0.9);
}

.ts-grow-wallet{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: center;
}
.ts-grow-wallet .mono{ font-weight: 600; }
.ts-grow-wallet-actions{ display: flex; justify-content: flex-end; }
@media (max-width: 700px){
  .ts-grow-wallet-actions{ justify-content: flex-start; }
}

.ts-grow-chain-line{
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ts-chain-badge{
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .12rem .4rem;
  border-radius: .4rem;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: rgba(231,238,247,0.85);
}
.ts-chain-badge.ethereum{
  background: rgba(34,115,255,0.18);
  border-color: rgba(34,115,255,0.4);
  color: #cfe4ff;
}
.ts-chain-badge.arbitrum{
  background: rgba(0,200,255,0.18);
  border-color: rgba(0,200,255,0.4);
  color: #c8f5ff;
}

/* Avoid nested scroll jail */
.ts-content .scroll-y,
.ts-content .help-body{
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.ts-content .inner-scroll{
  max-height: 60vh;
  overflow: auto;
}

.ts-home-actions .ts-nav-item{
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 10px 14px;
  height: auto;
}

.ts-footer{
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 12px;
  color: rgba(231,238,247,0.7);
}

.ts-badge { font-size: .75rem; padding: .15rem .4rem; border-radius: .4rem; background: #eee; color: #111; }
.ts-btn-disabled { opacity: .5; pointer-events: none; }
.ts-banner { background: #111; color: #fff; padding: .6rem .9rem; border-radius: .5rem; margin: 1rem 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(1px,1px,1px,1px); white-space: nowrap; }
