:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --border: #24314b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button {
  font: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.wallet {
  width: 100%;
  max-width: min(100%, 34rem);
  margin: 0 auto;
  padding: calc(1.25rem + env(safe-area-inset-top)) 1rem calc(3rem + env(safe-area-inset-bottom));
}

.wallet-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0 1.25rem;
}

.brand {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.brand span {
  color: var(--accent);
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
}

.card-link {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 2.75rem 0.9rem 0.9rem;
  min-height: 4.5rem;
  color: inherit;
  text-decoration: none;
}

.avatar,
.initials {
  width: clamp(2.5rem, 12vw, 3rem);
  height: clamp(2.5rem, 12vw, 3rem);
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 1rem;
}

.card-name {
  display: block;
  font-weight: 600;
}

.card-subtitle {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.card-arrow {
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
}

.card-remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
}

.card-remove:hover,
.card-remove:focus-visible {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.12);
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty h2 {
  color: var(--text);
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.empty p {
  margin: 0 0 1.5rem;
}

.empty a {
  color: var(--accent);
}

.empty nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.25rem;
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 3rem 0;
}

@media (orientation: landscape) and (max-height: 40rem) {
  .wallet {
    max-width: 54rem;
    padding: calc(1rem + env(safe-area-inset-top)) 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  }
  .wallet-header {
    padding-bottom: 0.75rem;
  }
  .brand {
    font-size: 1.25rem;
  }
  .card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.6rem;
  }
  .card-link {
    min-height: 3.75rem;
  }
  .avatar,
  .initials {
    width: 2.5rem;
    height: 2.5rem;
  }
}

.cardx-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 3rem;
  padding: 0.55rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  transition: transform 0.05s ease, opacity 0.15s ease;
}

.cardx-btn:active {
  transform: scale(0.98);
}

.cardx-btn[disabled] {
  opacity: 0.55;
  pointer-events: none;
}

.cardx-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.cardx-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.cardx-close {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top));
  left: calc(0.75rem + env(safe-area-inset-left));
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(19, 28, 46, 0.75);
  color: #e2e8f0;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.cardx-close svg {
  width: 1.4rem;
  height: 1.4rem;
}

.cardx-modal-box .cardx-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.cardx-install-bar {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  min-height: 3.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.45);
  z-index: 45;
}

body.cardx-install-open .wallet {
  padding-bottom: calc(6rem + env(safe-area-inset-bottom));
}

.cardx-install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(5.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(0.5rem);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(92vw, 26rem);
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 55;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.5);
}

.cardx-install-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.cardx-install-banner .msg {
  flex: 1;
  text-align: left;
}

.cardx-install-banner .go {
  flex-shrink: 0;
  min-height: 2.5rem;
  padding: 0.4rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  cursor: pointer;
}

.cardx-install-banner .x {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.cardx-install-hint p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.cardx-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(0.5rem);
  max-width: min(90vw, 26rem);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}

.cardx-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.cardx-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(2, 6, 23, 0.75);
  z-index: 50;
  overflow-y: auto;
}

.cardx-modal[hidden] {
  display: none;
}

.cardx-modal-box {
  width: 100%;
  max-width: min(88vw, 21rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.5rem;
  text-align: center;
}

.cardx-modal-lead {
  order: 1;
  width: 100%;
}

.cardx-modal-info {
  order: 2;
  width: 100%;
}

.cardx-modal-box h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.cardx-qr {
  display: block;
  margin: 0 auto 1rem;
  width: min(100%, 16rem);
  height: auto;
  border-radius: 0.75rem;
}

.cardx-share-url {
  display: block;
  color: var(--accent);
  font-size: 0.85rem;
  word-break: break-all;
  margin-bottom: 1.25rem;
}

@media (orientation: landscape) and (max-height: 600px) {
  .cardx-modal-box {
    flex-direction: row;
    align-items: center;
    gap: 1.25rem;
    text-align: left;
    max-width: min(94vw, 44rem);
    padding: 1rem 1.25rem;
  }
  .cardx-modal-lead {
    order: 1;
    flex: 0 0 auto;
    width: auto;
  }
  .cardx-modal-lead h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
  }
  .cardx-modal-lead .cardx-qr {
    width: min(38vh, 12rem);
    margin: 0;
  }
  .cardx-modal-info {
    order: 2;
    flex: 1;
    min-width: 0;
  }
  .cardx-actions {
    margin-top: 0.75rem;
    gap: 0.5rem;
  }
}
