:root {
  --bg: #0b0b0d;
  --panel: #151518;
  --panel-2: #1c1c21;
  --line: #2a2a31;
  --text: #f2f2f4;
  --muted: #9a9aa6;
  --accent: #14b8a6;
  --accent-2: #0d9488;
  --up: #22c55e;
  --down: #ef4444;
  --gold: #facc15;
  --radius: 14px;
  --tabbar-h: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.up { color: var(--up); }
.down { color: var(--down); }
.accent { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(20px, calc((100vw - 1400px) / 2));
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(11, 11, 13, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; white-space: nowrap; }
.brand b { color: var(--accent); }
.topnav { display: flex; gap: 6px; }
.topnav a { padding: 7px 12px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--accent); background: rgba(20, 184, 166, .1); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.chip {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; font-weight: 600; font-size: 13.5px;
}
select.chip { appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.chip .accent { margin-left: 4px; }

.tabbar { display: none; }

main { max-width: 1400px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------- generic ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: #3a3a44; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #031a17; }
.btn.primary:hover { background: #2dd4bf; }
.btn.danger { color: var(--down); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center;
  background: transparent; border: 1.5px solid var(--accent); color: var(--accent); font-size: 18px; line-height: 1; padding: 0;
}
.icon-btn:hover { background: rgba(20, 184, 166, .15); }
.input, select.input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
.input:focus { border-color: var(--accent); }
.search-box { display: flex; gap: 10px; }
.search-box .input { padding-left: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%239a9aa6' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5.5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 13px 50%; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 13px; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--bg); color: var(--accent); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); }
.badge.grade { background: #3b2f05; border-color: #6b5410; color: var(--gold); }
.badge.var { color: var(--accent); }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px; }
.section-title h2 { font-size: 19px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- card grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.grid.compact { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.tile {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: #3a3a44; }
.tile .img { position: relative; aspect-ratio: 63 / 88; border-radius: 9px; overflow: hidden; background: var(--panel-2); }
.tile .img img { width: 100%; height: 100%; object-fit: cover; }
.tile .img .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; }
.tile .name { font-weight: 700; font-size: 15px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.tile .meta a { text-decoration: underline; text-underline-offset: 2px; }
.tile .price { font-weight: 800; font-size: 16px; }
.tile .foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; margin-top: auto; }
.tile .qty-badge {
  position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px;
  background: var(--accent); color: #031a17; font-weight: 800; font-size: 13px; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.tile.missing .img img { filter: grayscale(1) brightness(.45); }
.tile.missing .name { color: var(--muted); }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.tile .check {
  position: absolute; top: 16px; left: 16px; width: 24px; height: 24px; border-radius: 7px; z-index: 2;
  border: 2px solid #fff; background: rgba(0, 0, 0, .45); display: grid; place-items: center; font-size: 15px; font-weight: 900;
}
.tile.selected .check { background: var(--accent); border-color: var(--accent); color: #031a17; }
.grid.compact .tile { padding: 7px; gap: 5px; }
.grid.compact .tile .name { font-size: 13px; }
.grid.compact .tile .price { font-size: 13.5px; }
.grid.compact .icon-btn { width: 28px; height: 28px; font-size: 16px; }

/* list view */
.list { display: flex; flex-direction: column; gap: 6px; }
.list .tile { flex-direction: row; align-items: center; padding: 8px 12px; gap: 12px; }
.list .tile .img { width: 46px; flex: none; border-radius: 5px; }
.list .tile .body { flex: 1; min-width: 0; }
.list .tile .foot { margin: 0; flex-direction: column; align-items: flex-end; }
.list .tile .check { top: 50%; left: 6px; transform: translateY(-50%); }
.list .tile .qty-badge { position: static; }

/* ---------- portfolio ---------- */
.pf-head { display: grid; grid-template-columns: 1fr 340px; gap: 18px; }
.pf-value .label { color: var(--muted); font-weight: 600; }
.pf-value .total { font-size: 38px; font-weight: 800; letter-spacing: -.5px; margin: 4px 0; }
.pf-chart { margin-top: 10px; }
.pf-chart svg { width: 100%; height: auto; display: block; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 19px; font-weight: 800; }
.stat .k { color: var(--muted); font-size: 12.5px; }
.top-list { display: flex; flex-direction: column; }
.top-list .it { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.top-list .it:last-child { border: 0; }
.pf-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.pf-tab { flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; text-align: left; }
.pf-tab .n { font-weight: 700; }
.pf-tab .s { font-size: 12px; color: var(--muted); }
.pf-tab.on { border-color: var(--accent); background: rgba(20, 184, 166, .08); }
.pf-tab.on .n { color: var(--accent); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.toolbar .input { width: auto; flex: 1; min-width: 180px; }
.selbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; gap: 8px; align-items: center; background: #202026; border: 1px solid #3a3a44; border-radius: 16px;
  padding: 10px 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, .6); max-width: calc(100vw - 20px); flex-wrap: wrap; justify-content: center;
}
.selbar .count { font-weight: 800; padding: 0 6px; }

/* ---------- sets ---------- */
.series { margin-bottom: 26px; }
.series h2 { font-size: 18px; margin-bottom: 10px; display: flex; gap: 10px; align-items: center; }
.sets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.set-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.set-tile:hover { border-color: #3a3a44; }
.set-tile .logo { height: 70px; display: grid; place-items: center; }
.set-tile .logo img { max-height: 70px; max-width: 100%; object-fit: contain; }
.set-tile .logo .txt { font-weight: 800; font-size: 18px; text-align: center; }
.set-tile .nm { font-weight: 700; font-size: 14px; }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.set-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.set-head .logo img { max-height: 80px; max-width: 220px; }
.set-head .info { flex: 1; min-width: 220px; }
.set-head .pct { font-size: 30px; font-weight: 800; }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .7); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow-y: auto;
}
.modal { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; width: min(980px, 100%); padding: 22px; }
.modal.narrow { width: min(460px, 100%); }
.modal .close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); font-size: 18px; }
.modal h2 { font-size: 22px; margin-bottom: 6px; padding-right: 40px; }
.card-detail { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.card-detail .big-img { width: 100%; border-radius: 14px; aspect-ratio: 63/88; object-fit: cover; background: var(--panel-2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
table.prices { width: 100%; border-collapse: collapse; font-size: 14px; }
table.prices th, table.prices td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.prices th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
table.prices td.num { text-align: right; font-variant-numeric: tabular-nums; }
.box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.box h3 { font-size: 15px; margin-bottom: 10px; }
.hold-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hold-row:last-child { border: 0; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line); background: transparent; font-size: 17px; line-height: 1; padding: 0; }
.stepper button.plus { border-color: var(--accent); color: var(--accent); }
.stepper input { width: 52px; text-align: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #26262d; border: 1px solid #3a3a44; padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 60;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 30px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .pf-head { grid-template-columns: 1fr; }
  .card-detail { grid-template-columns: 1fr; }
  .card-detail .big-img { max-width: 300px; margin: 0 auto; }
}
@media (max-width: 760px) {
  :root { --tabbar-h: 62px; }
  .topbar { gap: 10px; padding-left: 14px; padding-right: 14px; }
  .topnav { display: none; }
  .brand span { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(17, 17, 20, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--muted); gap: 2px; }
  .tabbar a .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a.active .ti { filter: none; opacity: 1; }
  main { padding: 14px 12px 40px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid.compact { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .tile { padding: 8px; }
  .pf-value .total { font-size: 30px; }
  .sets-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .set-tile { padding: 10px; }
  .set-tile .logo { height: 50px; }
  .set-tile .logo img { max-height: 50px; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; padding: 18px 14px 40px; padding-top: max(18px, env(safe-area-inset-top)); }
  .form-grid { grid-template-columns: 1fr; }
  .search-box .btn { display: none; }
}

/* ---------- sets page (album tiles) ---------- */
.sets-top { text-align: center; margin-bottom: 22px; }
.sets-top h1 { font-size: 30px; margin-bottom: 16px; }
.sets-controls { justify-content: center; }
.sets-controls .search-box .input { min-width: 220px; }
.sets-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 10px; }
.set-card { display: flex; flex-direction: column; gap: 8px; text-align: center; border-radius: 10px; }
.set-logo {
  position: relative; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #6b6b74, #44444b); display: grid; place-items: center; padding: 14px;
  transition: transform .15s, box-shadow .15s;
}
.set-card:hover .set-logo { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.set-logo img { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.set-logo .txt { font-weight: 800; font-size: 18px; }
.set-logo .date { position: absolute; top: 6px; right: 6px; background: rgba(20,20,24,.75); color: #d4d4d8; font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px; }
.set-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 15px; background: rgba(255,255,255,.75); }
.set-bar i { display: block; height: 100%; background: var(--accent); color: #fff; font-style: normal; font-size: 10px; font-weight: 800; text-align: left; padding-left: 6px; line-height: 15px; }
.set-info .nm { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.set-info .small b { font-weight: 700; }
@media (max-width: 760px) {
  .sets-grid { grid-template-columns: repeat(2, 1fr); gap: 12px 8px; }
  .sets-top h1 { font-size: 24px; }
  .set-logo { padding: 10px; }
  .set-info .nm { font-size: 13.5px; }
}
