/* ===== 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;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.topbar, .topbar * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand small {
  display: block;
  font-family: 'Manrope', sans-serif;
  font-size: 9px; color: var(--muted); font-weight: 800;
  letter-spacing: 2.2px;
}

/* Hand-drawn fox crest — the app's one signature mark. */
.brand-mark {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: var(--bm, 30px);
  height: var(--bm, 30px);
  border-radius: calc(var(--bm, 30px) * .34);
  color: #F6E9DC;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, .22), transparent 46%),
    linear-gradient(150deg, color-mix(in srgb, var(--accent) 58%, #2A1720), #160F15 72%);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .22),
    inset 0 -2px 4px rgba(0, 0, 0, .38),
    0 4px 10px -4px rgba(0, 0, 0, .65);
}
.brand-mark svg {
  width: 76%;
  height: 76%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .45));
}
[data-theme="ivory"] .brand-mark, [data-theme="light"] .brand-mark,
[data-theme="soda"] .brand-mark {
  color: #FFF8EF;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, .28), transparent 46%),
    linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 58%, #301018));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .5),
    inset 0 -2px 4px rgba(60, 10, 20, .24),
    0 5px 12px -5px rgba(80, 30, 45, .45);
}

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

.coin-pill {
  display: flex; align-items: center; gap: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .10), transparent 45%),
    var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  font-weight: 800; font-size: 13.5px; color: var(--gold);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .14),
    0 3px 9px -5px rgba(0, 0, 0, .45);
}
.coin-pill .coin-ic,
.coin-dot,
.coin-big,
.price-tag::before,
.sp-coin,
.bs-coin-dot,
.mn-coin-dot {
  background: var(--coin-asset) center / contain no-repeat;
  border-radius: 50%;
  box-shadow: none;
}
.coin-pill .coin-ic {
  width: 18px; height: 18px;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 1px rgba(80, 40, 0, .35));
}
.coin-dot {
  display: inline-block;
  width: var(--cs, 18px);
  height: var(--cs, 18px);
  flex-shrink: 0;
  filter: drop-shadow(0 1px 1px rgba(80, 40, 0, .28));
}

.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 12px;
  background:
    var(--sheen-soft),
    var(--card);
  border: 1px solid var(--stroke);
  display: grid; place-items: center;
  color: var(--muted);
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    0 3px 8px -6px rgba(0, 0, 0, .45);
  transition: transform .15s ease, color .15s ease, background .15s ease;
}
.icon-btn:active {
  transform: scale(.93);
  color: var(--text);
  background: var(--card-2);
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, .22),
    0 1px 2px rgba(0, 0, 0, .16);
}
.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-family: inherit;
  font-size: 10.5px; font-weight: 700;
  transition: color .18s ease;
  position: relative;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.tabbar, .tabbar * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.tab-item svg {
  width: 22px; height: 22px;
  transition: transform .18s ease, filter .18s ease;
}
.tab-item.active { color: var(--text); }
.tab-item.active svg {
  filter: drop-shadow(0 3px 7px rgba(var(--accent-rgb), .45));
}
.tab-item:active svg { transform: scale(.9); }
.tab-item.active::before {
  content: '';
  position: absolute; top: 0;
  width: 30px; height: 2.5px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(90deg, transparent, var(--accent) 20%, var(--accent) 80%, transparent);
  box-shadow: 0 2px 10px rgba(var(--accent-rgb), .55);
}

.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: 11px; height: 11px;
  border-radius: 3px;
  background: var(--gradient);
  transform: rotate(45deg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .38),
    0 2px 7px -1px rgba(var(--accent-rgb), 0.55);
  flex-shrink: 0;
  margin: 0 1px;
}
.section-link { font-size: 13px; color: var(--cyan); font-weight: 700; display: flex; align-items: center; gap: 3px; }

/* ===== Rarity ===== */
.rarity-gem {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--rg, 10px);
  height: var(--rg, 10px);
  color: var(--rc, #9691AE);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .28));
}
.rarity-gem svg { width: 100%; height: 100%; display: block; }

.rarity-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 800;
  padding: 3px 8px 3px 7px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .08), transparent 60%),
    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);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .10),
    0 2px 6px -4px rgba(0, 0, 0, .45);
}

.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: rgba(11, 10, 20, .62);
  border: 1px solid rgba(255, 255, 255, .17);
  color: #fff;
  font-size: 11px; font-weight: 800;
  padding: 3px 8px; border-radius: 999px;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .18),
    0 2px 7px -3px rgba(0, 0, 0, .55);
}
.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-rarity {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--rc);
  font-weight: 800;
  font-size: 10.5px;
  white-space: nowrap;
}
.char-rarity > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}
.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 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background:
    var(--sheen-soft),
    var(--card);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 12.5px; font-weight: 700;
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    0 2px 7px -6px rgba(0, 0, 0, .45);
  transition: background .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.chip.active {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .18), transparent 55%),
    var(--gradient);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .32),
    inset 0 -2px 5px rgba(0, 0, 0, .18),
    0 3px 12px -5px rgba(var(--accent-b-rgb), .55);
}
.chip.active .rarity-gem { color: #fff; opacity: .92; }
.chip:active { transform: scale(.97); }

/* ===== 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 {
  position: relative;
  width: 74px; height: 74px;
  margin: 0 auto 18px;
  border-radius: 26px;
  background:
    radial-gradient(70% 60% at 30% 18%, rgba(var(--accent-rgb), .13), transparent 70%),
    var(--card);
  border: 1px solid var(--stroke);
  display: grid; place-items: center;
  color: var(--accent);
  opacity: 1;
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    var(--elev-2);
}
.empty-state .es-icon::before {
  content: '';
  position: absolute; inset: -9px;
  border-radius: 32px;
  border: 1px solid color-mix(in srgb, var(--accent) 13%, transparent);
  pointer-events: none;
}
.empty-state .es-icon::after {
  content: '';
  position: absolute; top: -4px; right: -4px;
  width: 9px; height: 9px;
  border-radius: 2px;
  transform: rotate(45deg);
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(var(--accent-rgb), .45);
}
.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);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .16s ease both;
  touch-action: manipulation;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 520px;
  background:
    var(--sheen-soft),
    var(--card);
  border: 1px solid var(--stroke-strong);
  border-bottom: none;
  border-radius: 26px 26px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    0 -8px 24px -18px rgba(0, 0, 0, .55),
    0 -24px 60px -28px rgba(0, 0, 0, .72);
  animation: sheetUp .26s cubic-bezier(.2,.9,.3,1) both;
  max-height: 86dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transition: transform .26s cubic-bezier(.32,.72,0,1), opacity .18s ease;
}
@keyframes sheetUp { from { transform: translateY(36px); opacity: .3;} to { transform: none; opacity: 1;} }
.sheet.dragging {
  transition: none;
  user-select: none;
  -webkit-user-select: none;
}
.sheet.sheet-closing {
  transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .2s ease;
  pointer-events: none;
}
.sheet-snap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height .3s cubic-bezier(.22,1,.36,1), transform .26s cubic-bezier(.32,.72,0,1);
  will-change: height;
}
.sheet-snap.dragging { transition: none; }
.sheet-snap > .ul-sheet { flex: 1; min-height: 0; }
.sheet-grip {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  height: 30px;
  margin: -12px -20px 7px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.sheet-grip:active { cursor: grabbing; }
.grabber {
  width: 42px; height: 5px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--text) 22%, transparent);
  margin: 0 auto;
  transition: width .2s ease, background .2s ease;
}
.sheet-grip:active .grabber {
  width: 56px;
  background: var(--accent);
}
.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; }

/* ===== 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(--sheen-soft),
    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:
    inset 0 1px 0 var(--edge-light),
    var(--elev-3);
  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;
}
