:root {
  --bg: #0f0d10;
  --surface: #1a171c;
  --surface-2: #241f27;
  --text: #f3eef6;
  --muted: #9b8fa6;
  --accent: #e8743b;
  --gold: #f0c060;
  --green: #4caf7d;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #1a171c, rgba(26,23,28,0.9));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #2a2530;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 0.5px; }
.disc {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at center, #f3eef6 0 14%, #19161b 15% 28%, #2a2530 29% 100%);
  box-shadow: 0 0 0 2px #19161b inset;
  animation: spin 4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stat {
  font-size: 12px; color: var(--muted);
  background: var(--surface-2); padding: 5px 10px; border-radius: 999px;
}

.tabs { display: flex; gap: 8px; padding: 12px 16px 4px; }
.tab {
  flex: 1; padding: 9px 0; border: none; border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--accent); color: #fff; }

.controls { display: flex; gap: 8px; padding: 10px 16px 6px; }
#search {
  flex: 1; padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid #2a2530; background: var(--surface); color: var(--text);
  font-size: 15px;
}
#search::placeholder { color: #6f6577; }
#sort {
  padding: 0 10px; border-radius: var(--radius);
  border: 1px solid #2a2530; background: var(--surface); color: var(--text);
  font-size: 13px;
}

.list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 12px 16px 40px;
}
@media (min-width: 620px) { .list { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .list { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
  border: 1px solid #241f27; text-decoration: none; color: inherit;
}
.card:active { transform: scale(0.98); }
.cover { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: rgba(0,0,0,0.6); color: #fff; backdrop-filter: blur(4px);
}
.badge.deal { background: var(--gold); color: #2a1c00; }
.badge.new { background: var(--green); color: #04150d; }
.badge.pre { background: #6c8cff; color: #04102e; }
.discount-tag {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 8px;
  background: var(--accent); color: #fff;
}

.card-body { padding: 10px 11px 12px; display: flex; flex-direction: column; gap: 3px; }
.card-title { font-size: 14px; font-weight: 700; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-artist { font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }
.price { font-size: 15px; font-weight: 800; color: var(--gold); }
.orig { font-size: 12px; color: var(--muted); text-decoration: line-through; }
.card-foot { font-size: 11px; color: #6f6577; margin-top: 4px;
  display: flex; justify-content: space-between; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 30px; }
.card { cursor: pointer; }

/* detail modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(3px);
  display: none; align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(28px + env(safe-area-inset-bottom));
  position: relative; animation: slideup .22s ease;
}
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--surface-2); color: var(--text); font-size: 15px; cursor: pointer;
}
.sheet-hero { width: 100%; aspect-ratio: 1.4; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); margin-bottom: 14px; display: flex; align-items: center; justify-content: center; }
.sheet-hero img { width: 100%; height: 100%; object-fit: contain; }
.sheet-title { font-size: 18px; margin: 0 0 8px; line-height: 1.3; }
.sheet-price { margin-bottom: 6px; }
.price.big { font-size: 22px; }
.sheet-source { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.d-sub { font-size: 13px; color: var(--gold); font-weight: 700; margin: 16px 0 6px; }
.d-table { display: flex; flex-direction: column; gap: 1px; background: #2a2530; border-radius: 10px; overflow: hidden; }
.d-row { display: flex; gap: 10px; padding: 9px 12px; background: var(--surface); font-size: 13px; }
.d-k { color: var(--muted); flex: 0 0 38%; }
.d-v { color: var(--text); flex: 1; word-break: break-word; }
.buy-btn {
  display: block; text-align: center; margin-top: 18px; padding: 13px;
  background: var(--accent); color: #fff; text-decoration: none;
  border-radius: 12px; font-weight: 700; font-size: 15px;
}
.muted { color: var(--muted); }

.empty, .loading { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px; }
.spinner {
  width: 26px; height: 26px; border: 3px solid #2a2530; border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 14px; animation: spin 0.8s linear infinite;
}
