.app-topnav-wrap {
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
}

.app-topnav {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-md);
  min-block-size: 3.5rem;
  padding-inline: var(--space-lg);
  background: color-mix(in srgb, var(--theme-surface) 82%, transparent);
  border-block-end: 1px solid color-mix(in srgb, var(--theme-border) 72%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.app-topnav__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--theme-text);
  font-weight: 700;
  font-size: var(--text-base);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.app-topnav__logo {
  block-size: 2rem;
  inline-size: auto;
  margin-block-start: -0.15rem;
}

.app-topnav__identity {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-topnav__links {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  justify-content: center;
}

.app-topnav__icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  block-size: 2rem;
  inline-size: 2rem;
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-sm);
  color: var(--theme-text);
  text-decoration: none;
  transition: all var(--transition-fast);

  &:hover {
    background: color-mix(in srgb, var(--color-primary) 12%, transparent);
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    color: var(--theme-text);
  }

  &.is-active {
    background: color-mix(in srgb, var(--color-primary) 14%, transparent);
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    color: var(--theme-text);
  }

  &.is-disabled {
    color: var(--theme-muted);
    border-color: color-mix(in srgb, var(--theme-border) 75%, transparent);
    background: color-mix(in srgb, var(--theme-surface) 88%, transparent);
  }

  &.is-disabled:hover {
    color: var(--theme-muted);
    border-color: color-mix(in srgb, var(--theme-border) 75%, transparent);
    background: color-mix(in srgb, var(--theme-surface) 88%, transparent);
  }

  &[data-label] {
    position: relative;
  }

  &[data-label]:hover::after {
    content: attr(data-label);
    position: absolute;
    inset-block-start: calc(100% + 0.35rem);
    inset-inline-start: 50%;
    transform: translateX(-50%);
    padding: 0.15rem 0.4rem;
    background: var(--theme-text);
    color: var(--theme-surface);
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    pointer-events: none;
    z-index: 25;
  }
}

.app-topnav__icon {
  block-size: 1rem;
  inline-size: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-topnav__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  block-size: 2rem;
  inline-size: 2rem;
  padding: 0;
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--theme-text);
  cursor: pointer;
  transition: background var(--transition-fast);

  &:hover {
    background: var(--theme-surface-muted);
  }
}

.wallet-modal__dialog {
  inline-size: min(26rem, calc(100vw - 2rem));
  border: 1px solid color-mix(in srgb, var(--color-primary) 18%, var(--theme-border));
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-surface) 92%, var(--theme-surface-subtle));
  box-shadow: var(--shadow-lg);
  padding: 0;
}

.wallet-modal__dialog::backdrop {
  background: color-mix(in srgb, var(--theme-text) 35%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.wallet-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-md) var(--space-sm);
  border-block-end: 1px solid var(--theme-border);
}

.wallet-modal__title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 700;
}

.wallet-modal__close {
  appearance: none;
  border: 1px solid var(--theme-border);
  background: transparent;
  color: var(--theme-text-subtle);
  border-radius: var(--radius-sm);
  inline-size: 1.8rem;
  block-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.wallet-modal__close:hover {
  color: var(--theme-text);
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

.wallet-modal__balances {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm);
  padding: var(--space-md);
}

.wallet-modal__balance {
  padding: var(--space-sm);
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--theme-surface-subtle) 88%, transparent);
}

.wallet-modal__label {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--theme-text-subtle);
}

.wallet-modal__amount {
  margin: 0.2rem 0 0;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--theme-text);
}

.wallet-modal__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md) var(--space-md);
}

@media (max-inline-size: 48rem) {
  .app-topnav {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
  }

  .app-topnav__links {
    flex-wrap: wrap;
  }

  .app-topnav__identity {
    flex-wrap: wrap;
    justify-content: center;
  }

  .wallet-modal__balances {
    grid-template-columns: 1fr;
  }

  .wallet-modal__actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .wallet-modal__actions .btn {
    inline-size: 100%;
  }
}
