:root {
  --bg: #0f1117; --surface: #181b24; --surface-2: #222634; --border: #2e3344;
  --text: #e8eaf0; --muted: #9097a8; --accent: #ff5c8a; --accent-2: #7c5cff; --gold: #ffc94d;
  --ok: #3ecf8e; --err: #ff6b6b; --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f6fa; --surface: #fff; --surface-2: #eef0f6; --border: #dde0ea; --text: #1b1e27; --muted: #5f6678; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
code { font-family: ui-monospace, monospace; font-size: .9em; }
.muted { color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.stats { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { max-width: 1400px; margin: 0 auto; padding: 20px; }

.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent-2); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; font-weight: 600; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.search { flex: 1 1 240px; min-width: 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.search:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 8px; text-decoration: none; }
.tile-media { position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
  box-shadow: 0 4px 14px rgb(0 0 0 / .25); transition: transform .18s ease, box-shadow .18s ease; }
.tile:hover .tile-media, .tile:focus-visible .tile-media { transform: translateY(-4px); box-shadow: 0 10px 24px rgb(0 0 0 / .35); }
.cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback, .hero-cover.cover-fallback { display: grid; place-items: center; font-size: 42px; font-weight: 800; color: #fff;
  background: linear-gradient(145deg, var(--ph), color-mix(in srgb, var(--ph) 40%, #000)); }
.ph-0 { --ph: #e85d75; } .ph-1 { --ph: #7c5cff; } .ph-2 { --ph: #2bb3a3; }
.ph-3 { --ph: #f2a541; } .ph-4 { --ph: #3d8bfd; } .ph-5 { --ph: #c065d6; }
.count-badge { position: absolute; bottom: 8px; right: 8px; background: rgb(0 0 0 / .75); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; }
.tile-title { font-size: 14px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.fav { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(0 0 0 / .55); color: #ffffff80; font-size: 17px; line-height: 1; }
.fav[aria-pressed="true"] { color: var(--gold); }
.fav-inline { position: static; width: 28px; height: 28px; background: transparent; color: var(--muted); margin-left: auto; }

.hero { display: flex; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
.hero-cover { width: 160px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / .35); flex-shrink: 0; }
.hero h1 { margin: 6px 0 4px; font-size: clamp(22px, 4vw, 34px); line-height: 1.15; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { --ed: var(--muted); background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--ed); border-radius: var(--radius); padding: 12px 14px; }
.ed-1 { --ed: #8a93a6; } .ed-2 { --ed: #3ecf8e; } .ed-3 { --ed: #3d8bfd; } .ed-4 { --ed: #c065d6; }
.ed-5 { --ed: #f2a541; } .ed-6 { --ed: #ff5c8a; } .ed-7 { --ed: #2bb3a3; } .ed-8 { --ed: #ffc94d; }
.card-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.print { font-size: 18px; }
.edition { color: var(--ed); font-size: 14px; }
.card-name { margin: 6px 0 2px; font-size: 16px; }
.quality { color: var(--gold); letter-spacing: 2px; font-size: 14px; }
.card-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 10px 0 6px; font-size: 13px; }
.card-meta dt { color: var(--muted); }
.card-meta dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--surface-2); border-radius: 999px; padding: 2px 8px; }

.loading, .empty, .error { text-align: center; color: var(--muted); padding: 48px 0; }
.sentinel { height: 1px; }

.dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); max-width: 460px; width: calc(100% - 32px); padding: 22px; }
.dialog::backdrop { background: rgb(0 0 0 / .6); }
.dialog h2 { margin-top: 0; }
.dialog label { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 14px; }
.dialog input { padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.upload-result { min-height: 1.4em; font-size: 14px; }
.upload-result.ok { color: var(--ok); } .upload-result.err { color: var(--err); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .stats { order: 3; flex-basis: 100%; }
  .view { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
  .hero { gap: 14px; }
  .hero-cover { width: 100px; }
  .cards { grid-template-columns: 1fr; }
}
