/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--stroke);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16.5px;
  letter-spacing: .2px;
}
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,0) 48%),
    var(--gradient);
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--on-accent);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.22),
    inset 0 -3px 6px rgba(0,0,0,.28),
    0 4px 12px -2px rgba(var(--accent-rgb), 0.5);
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.brand .logo svg { width: 16px; height: 16px; }
.brand small {
  display: block;
  font-family: 'Manrope', sans-serif;
  font-size: 9px; color: var(--muted); font-weight: 800;
  letter-spacing: 2.2px;
}

.top-actions { display: flex; align-items: center; gap: 8px; }

.coin-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  font-weight: 700; font-size: 13.5px; color: var(--gold);
}
.coin-pill .coin-ic {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #FFE7A8, #F5B93E 70%);
  box-shadow: inset 0 -2px 3px rgba(120, 60, 0, .35);
}

.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--stroke);
  display: grid; place-items: center;
  color: var(--muted);
  transition: transform .15s ease, color .15s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 19px; height: 19px; }
.badge-dot {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px; font-weight: 800;
  display: grid; place-items: center;
  border: 2px solid var(--bg);
}

/* ===== Tabbar — floating dock ===== */
.tabbar {
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px)); left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 496px;
  height: var(--tabbar-h);
  display: flex;
  align-items: stretch;
  background: var(--nav-bg);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--stroke-strong);
  border-radius: 24px;
  z-index: 60;
  overflow: visible;
}
.tab-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px; font-weight: 700;
  transition: color .18s ease;
  position: relative;
}
.tab-item svg { width: 22px; height: 22px; }
.tab-item.active { color: var(--text); }
.tab-item.active::before {
  content: '';
  position: absolute; top: 0;
  width: 34px; height: 3px;
  border-radius: 0 0 6px 6px;
  background: var(--gradient);
}

.tab-spin-wrap { flex: 1; display: grid; place-items: center; }
.tab-spin {
  margin-top: -30px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,.5), rgba(255,255,255,0) 46%),
    var(--gradient);
  border: 2px solid rgba(255,255,255,.35);
  outline: 1px solid rgba(var(--accent-rgb), 0.4);
  outline-offset: 2px;
  display: grid; place-items: center;
  color: var(--on-accent);
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
  box-shadow:
    inset 0 -4px 8px rgba(0,0,0,.28),
    0 10px 26px rgba(var(--accent-b-rgb), 0.5),
    0 4px 14px rgba(var(--accent-rgb),  0.4);
  transition: transform .16s ease;
}
.tab-spin:active { transform: scale(.9); }
.tab-spin svg { width: 25px; height: 25px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px;
  padding: 13px 20px;
  font-weight: 800; font-size: 15px; letter-spacing: .2px;
  transition: transform .15s ease, opacity .15s ease, box-shadow .15s ease;
  user-select: none;
}
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible,
.tab-item:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(var(--accent-rgb), 0.65);
  outline-offset: 2px;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

.btn-primary { background: var(--gradient); color: var(--on-accent); box-shadow: 0 6px 20px rgba(var(--accent-b-rgb), 0.35); }
.btn-gold { background: linear-gradient(135deg, var(--gold), #C98A1B); color: #3A2500; box-shadow: 0 6px 20px rgba(255, 190, 80, .22); }
.btn-cyan { background: rgba(var(--accent-rgb),  0.12); color: var(--cyan); border: 1px solid rgba(var(--accent-rgb),  .3); }
.btn-danger { background: rgba(var(--danger-rgb),  0.13); color: var(--danger); border: 1px solid rgba(var(--danger-rgb),  .32); }
.btn-success { background: rgba(70, 170, 120,  0.12); color: var(--success); border: 1px solid rgba(70, 170, 120,  .3); }
.btn-ghost { background: var(--card); border: 1px solid var(--stroke-strong); color: var(--text); }
.btn-sm { padding: 9px 14px; font-size: 13px; border-radius: 11px; }
.btn-block { width: 100%; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 16px;
}
.card-2 { background: var(--card-2); }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 24px 2px 12px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 17.5px;
  letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}
.section-head h2::before {
  content: '';
  width: 4px; height: 15px;
  border-radius: 99px;
  background: var(--gradient);
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.45);
  flex-shrink: 0;
}
.section-link { font-size: 13px; color: var(--cyan); font-weight: 700; display: flex; align-items: center; gap: 3px; }

/* ===== Rarity ===== */
.rarity-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--rc, #888) 13%, transparent);
  color: var(--rc, #ccc);
  border: 1px solid color-mix(in srgb, var(--rc, #888) 30%, transparent);
}

.event-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 800;
  color: var(--gold);
  background: rgba(255, 209, 102, 0.1);
  border: 1px solid var(--gold-border);
  padding: 2px 8px; border-radius: 999px;
}

/* ===== Character card grid ===== */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.char-card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .16s ease, border-color .16s ease;
  animation: cardIn .25s ease both;
}
.char-card:active { transform: scale(.97); }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px);} to {opacity:1; transform:none;} }

.char-art {
  position: relative;
  aspect-ratio: 3 / 3.6;
  overflow: hidden;
  background: linear-gradient(160deg, var(--card-2), var(--surface-deep));
}
.char-art img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .4s ease;
}
.char-art::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 55%, var(--scrim));
}
.rarity-ring { box-shadow: inset 0 0 0 2px var(--rc, transparent), inset 0 -46px 42px -22px var(--scrim); }

.count-chip {
  position: absolute; top: 8px; right: 8px;
  z-index: 2;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  border: 1px solid var(--stroke-strong);
  color: #fff;
  font-size: 11px; font-weight: 800;
  padding: 3px 8px; border-radius: 999px;
}
.fav-heart {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  color: var(--danger);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.6));
}
.fav-heart svg { width: 16px; height: 16px; }

.char-info { padding: 10px 12px 12px; position: relative; }
.char-name {
  font-size: 13.5px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.char-sub {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 5px;
  font-size: 11px; color: var(--muted); font-weight: 600;
}
.char-anime { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62%; }

/* ===== Chips / filters ===== */
.chips-row {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
  margin-bottom: 14px;
}
.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 12.5px; font-weight: 700;
  transition: all .15s ease;
}
.chip.active {
  background: var(--gradient);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(var(--accent-b-rgb),  0.3);
}

/* ===== Skeletons ===== */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--card-2);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: '';
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-hi), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.skel-card .skel-img { aspect-ratio: 3/3.6; border-radius: var(--radius) var(--radius) 0 0; }
.skel-line { height: 12px; margin: 10px 12px; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .es-icon {
  width: 74px; height: 74px;
  margin: 0 auto 16px;
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--stroke);
  display: grid; place-items: center;
  color: var(--muted);
  opacity: .9;
}
.empty-state .es-icon svg { width: 32px; height: 32px; }
.empty-state h3 { color: var(--text); font-size: 16.5px; margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; max-width: 260px; margin: 0 auto; }

/* ===== Modal ===== */
.overlay {
  position: fixed; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .18s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 520px;
  background: var(--card);
  border: 1px solid var(--stroke-strong);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: sheetUp .24s cubic-bezier(.2,.9,.3,1) both;
  max-height: 86dvh;
  overflow-y: auto;
}
@keyframes sheetUp { from { transform: translateY(40%); opacity: .4;} to { transform: none; opacity: 1;} }
.sheet-title { font-family: var(--font-display); font-size: 19px; font-weight: 800; letter-spacing: .2px; margin-bottom: 6px; }
.sheet-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.grabber {
  width: 44px; height: 4.5px;
  border-radius: 99px;
  background: var(--stroke-strong);
  margin: 0 auto 16px;
}

/* ===== Toast ===== */
#toast-root {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--card-2);
  border: 1px solid var(--stroke-strong);
  border-left: 3px solid var(--grad-a);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn .22s ease both;
  display: flex; gap: 10px; align-items: center;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.gold { border-left-color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px);} to {opacity:1; transform:none;} }
.toast.out { animation: toastOut .25s ease both; }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px);} }

/* ===== Misc ===== */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.mt-8{margin-top:8px}.mt-12{margin-top:12px}.mt-16{margin-top:16px}.mt-20{margin-top:20px}
.mb-8{margin-bottom:8px}.mb-12{margin-bottom:12px}.mb-16{margin-bottom:16px}
.fs-12{font-size:12px}.fs-13{font-size:13px}.fs-14{font-size:14px}.fs-18{font-size:18px}.fs-22{font-size:22px}.fw-700{font-weight:700}.fw-800{font-weight:800}
.center{text-align:center}

.divider { height: 1px; background: var(--stroke); margin: 14px 0; }

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--gradient);
  display: grid; place-items: center;
  font-weight: 800; color: var(--on-accent);
  object-fit: cover;
  flex-shrink: 0;
}

.load-more { display: grid; place-items: center; padding: 18px; }
.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid var(--stroke-strong);
  border-top-color: var(--grad-a);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Artwork fallback (dead/missing img_url) ===== */
.art-fallback {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background:
    radial-gradient(120% 80% at 20% 0%, color-mix(in srgb, var(--rc) 38%, transparent), transparent 60%),
    linear-gradient(160deg, var(--surface-2), var(--surface-deep));
  padding: 10px;
  text-align: center;
}
.art-fallback .af-glyph {
  font-size: clamp(30px, 9vw, 52px);
  font-weight: 800;
  color: var(--rc);
  text-shadow: 0 0 22px color-mix(in srgb, var(--rc) 55%, transparent);
  line-height: 1;
}
.art-fallback .af-name {
  font-size: 12px; font-weight: 800; color: var(--text);
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.art-fallback .af-anime {
  font-size: 10px; font-weight: 600; color: var(--muted);
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
