:root {
    --bg: hsl(0 0% 100%);
    --fg: hsl(0 0% 7%);
    --muted: hsl(0 0% 45%);
    --muted-bg: hsl(0 0% 96%);
    --border: hsl(0 0% 92%);
    --card: hsl(0 0% 100%);
    --destructive: hsl(0 84% 60%);

    --rarity-common:    hsl(0 0% 55%);
    --rarity-uncommon:  hsl(142 65% 42%);
    --rarity-rare:      hsl(217 91% 55%);
    --rarity-legendary: hsl(0 78% 55%);
    --rarity-godly:     hsl(330 80% 60%);
    --rarity-ancient:   hsl(270 70% 55%);
    --rarity-vintage:   hsl(42 90% 50%);
    --rarity-unique:    hsl(38 55% 65%);
    --rarity-christmas: hsl(0 70% 45%);

    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    line-height: 1.4;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

.font-mono, .brand-sub, .counts, .group-label, .chip, .qty, .type, .rarity, .panel-sub, .panel-count, .footer { font-family: var(--mono); }
.text-fg { color: var(--fg); }
.text-muted { color: var(--muted); }

.topbar {
    position: sticky; top: 0; z-index: 20;
    background: hsl(0 0% 100% / 0.85);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar .inner {
    max-width: 1600px; margin: 0 auto;
    padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.avatar {
    width: 36px; height: 36px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--muted-bg); object-fit: cover;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.brand:hover .brand-title { text-decoration: underline; }
.brand-sub { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 2px; }

.counts { display: flex; align-items: center; gap: 14px; font-size: 11px; color: var(--muted); }
.counts b { color: var(--fg); font-weight: 500; }
.counts .sep { width: 1px; height: 12px; background: var(--border); }
@media (max-width: 640px) { .counts { display: none; } }

.container { max-width: 1600px; margin: 0 auto; padding: 24px; }
.error {
    margin-bottom: 16px;
    border: 1px solid hsl(0 84% 60% / 0.3);
    background: hsl(0 84% 60% / 0.05);
    color: var(--destructive);
    padding: 8px 12px; border-radius: 6px; font-family: var(--mono); font-size: 12px;
}
.layout {
    display: grid; gap: 16px;
    grid-template-columns: 260px 1fr 1fr;
}
@media (max-width: 1024px) { .layout { grid-template-columns: 1fr; } }

.sidebar { position: sticky; top: 80px; align-self: start; }
@media (max-width: 1024px) { .sidebar { position: static; } }

.filters {
    display: flex; flex-direction: column; gap: 12px;
    background: var(--card); border: 1px solid var(--border); border-radius: 6px;
    padding: 12px;
}
.search input {
    width: 100%; height: 36px;
    border: 1px solid var(--border); border-radius: 6px;
    padding: 0 12px;
    font-family: var(--sans); font-size: 13px; color: var(--fg); background: var(--bg);
    outline: none; transition: border-color 150ms;
}
.search input:focus { border-color: var(--fg); }
.group { display: flex; flex-direction: column; gap: 8px; }
.group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    border: 1px solid var(--border); color: var(--muted);
    padding: 4px 8px; border-radius: 4px; font-size: 11px;
    cursor: pointer; transition: all 150ms;
}
.chip:hover { color: var(--fg); border-color: hsl(0 0% 7% / 0.4); }
.chip.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.submit {
    margin-top: 4px; height: 32px; border-radius: 6px; border: 1px solid var(--fg);
    background: var(--fg); color: var(--bg); cursor: pointer; font-family: var(--mono); font-size: 12px;
}

.panel {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--card); border: 1px solid var(--border); border-radius: 6px;
}
.panel-head {
    display: flex; align-items: baseline; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.01em; display: inline; }
.panel-sub { margin-left: 8px; font-size: 11px; color: var(--muted); }
.panel-count { font-size: 11px; color: var(--muted); }

.grid {
    display: grid; gap: 8px; padding: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px)  { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.empty {
    grid-column: 1 / -1;
    min-height: 200px; display: flex; align-items: center; justify-content: center;
    font-family: var(--mono); font-size: 12px; color: var(--muted);
}

.tile {
    position: relative; display: flex; flex-direction: column;
    border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
    background: var(--card); transition: transform 150ms, border-color 150ms;
}
.tile:hover { border-color: hsl(0 0% 7% / 0.3); transform: translateY(-2px); }
.qty {
    position: absolute; right: 6px; top: 6px; z-index: 1;
    background: var(--fg); color: var(--bg);
    padding: 2px 6px; border-radius: 3px;
    font-family: var(--mono); font-size: 10px; font-weight: 500; line-height: 1;
}
.thumb {
    aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
    background: hsl(0 0% 96% / 0.6); padding: 12px;
}
.thumb img { max-height: 100%; max-width: 100%; object-fit: contain; }
.meta { display: flex; flex-direction: column; gap: 2px; padding: 8px 8px 10px; }
.type { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.name {
    font-size: 13px; font-weight: 500; line-height: 1.2; color: var(--fg);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rarity { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }

.r-uncommon  { color: var(--rarity-uncommon); }
.r-rare      { color: var(--rarity-rare); }
.r-legendary { color: var(--rarity-legendary); }
.r-godly     { color: var(--rarity-godly); }
.r-ancient   { color: var(--rarity-ancient); }
.r-vintage   { color: var(--rarity-vintage); }
.r-unique    { color: var(--rarity-unique); }
.r-christmas { color: var(--rarity-christmas); }

.bar { height: 4px; width: 100%; }
.bar-common      { background: var(--rarity-common); }
.bar-uncommon    { background: var(--rarity-uncommon); }
.bar-rare        { background: var(--rarity-rare); }
.bar-legendary   { background: var(--rarity-legendary); }
.bar-godly       { background: var(--rarity-godly); }
.bar-ancient     { background: var(--rarity-ancient); }
.bar-vintage     { background: var(--rarity-vintage); }
.bar-unique      { background: var(--rarity-unique); }
.bar-christmas   { background: var(--rarity-christmas); }
.bar-chroma {
    background: linear-gradient(90deg,
        #ff0040, #ff8a00, #ffd500, #2bd16b,
        #00b4ff, #6a5cff, #d500ff, #ff0040);
    background-size: 200% 100%;
    animation: chroma-slide 3s linear infinite;
}
@keyframes chroma-slide {
    0%   { background-position: 0% 0%; }
    100% { background-position: 200% 0%; }
}

.footer {
    margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.footer a:hover { color: var(--fg); }
