:root {
  --bg: var(--tg-theme-bg-color, #18181b);
  --surface: var(--tg-theme-secondary-bg-color, #232326);
  --text: var(--tg-theme-text-color, #f4f4f5);
  --muted: var(--tg-theme-hint-color, #a1a1aa);
  --accent: var(--tg-theme-button-color, #60a5fa);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #f87171);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.banner-figures {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.banner-label {
  font-size: 12px;
  color: var(--muted);
}

.banner-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.banner-meta {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Not an error: an unpriced portfolio is still a portfolio, and saying why the
   total is missing beats a red banner that reads as a failure. */
.banner-note {
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.icon-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spinning svg {
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}

#tonconnect:not(:empty) {
  margin-bottom: 12px;
}

.wallet-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
}

.chip-label {
  font-weight: 600;
}

.chip-address {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chip-remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* Two columns on a phone: the art is the point, and a single column wastes half
   the screen while a third column shrinks it below recognisable. */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 520px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-art {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  overflow: hidden;
}

.card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-art-fallback {
  font-size: 22px;
  font-weight: 700;
  color: var(--muted);
}

.card-count {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, #000 62%, transparent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: color-mix(in srgb, #000 62%, transparent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

.card h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-top: auto;
  font-size: 11px;
}

.card-source {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-value {
  flex: none;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 32px 8px;
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

button {
  font: inherit;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ghost {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 500;
}

dialog {
  width: min(420px, calc(100vw - 24px));
  padding: 0;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}

.sheet h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

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

.sheet input {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.sheet input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.error {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.sheet-actions button {
  flex: 1;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
