:root {
  --bg: #0d0d10;
  --bg-side: #0a0a0d;
  --panel: #16161b;
  --line: #24242c;
  --line-soft: #1c1c23;
  --fg: #ececed;
  --fg-dim: #9a9aa5;
  --fg-faint: #6b6b76;
  --accent: #c3aeea;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 16px;
  background: var(--fg);
  color: var(--bg);
  z-index: 100;
  border-radius: 0 0 6px 0;
}

.skip:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- sidebar ---------- */

#sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.sidebar-inner {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 40px 22px 32px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.brand h1 {
  font-size: 19px;
  font-weight: 640;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 5px;
}

.brand .count {
  font-size: 13px;
  color: var(--fg-faint);
  margin: 0;
}

.sort-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 9px;
}

.sort-buttons {
  display: flex;
  gap: 6px;
}

.sort-buttons button {
  flex: 1;
  font: inherit;
  font-size: 12.5px;
  padding: 6px 4px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg-dim);
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}

.sort-buttons button:hover { color: var(--fg); }

.sort-buttons button[aria-pressed="true"] {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

#nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--line);
}

#nav a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0 7px 13px;
  margin-left: -1px;
  border-left: 1px solid transparent;
  font-size: 13.5px;
  color: var(--fg-dim);
  text-decoration: none;
  transition: color 0.12s, border-color 0.12s;
}

#nav a:hover { color: var(--fg); }

#nav a[aria-current="true"] {
  color: var(--fg);
  border-left-color: var(--accent);
  font-weight: 550;
}

#nav .n {
  font-size: 11.5px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- owner tools ---------- */

.tools {
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.tools[hidden] { display: none; }

.tools-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 9px;
}

.tools button {
  width: 100%;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
}

.tools button:hover:not(:disabled) { border-color: var(--accent); }
.tools button:disabled { opacity: 0.55; cursor: default; }
.tools button[hidden] { display: none; }

.tools-note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--fg-faint);
  margin: 9px 0 0;
}

.tools-out {
  display: block;
  margin-top: 9px;
  padding: 8px;
  border-radius: 6px;
  background: #000;
  border: 1px solid var(--line);
  color: var(--accent);
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  user-select: all;
}

.tools-out[hidden] { display: none; }

/* ---------- cards ---------- */

#list {
  padding: 40px 36px 100px;
  max-width: 1200px;
  outline: none;
}

#list section {
  scroll-margin-top: 28px;
}

#list section + section {
  margin-top: 52px;
  padding-top: 40px;
  border-top: 1px solid var(--line-soft);
}

#list h2 {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.01em;
  margin: 0 0 3px;
}

#list .section-meta {
  font-size: 13px;
  color: var(--fg-faint);
  margin: 0 0 20px;
}

#list h2 + .grid { margin-top: 20px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 26px 20px;
}

.card {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: zoom-in;
}

.card img {
  width: 100%;
  aspect-ratio: 0.716;
  object-fit: cover;
  object-position: top center;
  display: block;
  border-radius: 8px;
  background: var(--panel);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover img,
.card:focus-visible img {
  transform: translateY(-4px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

.card .name {
  font-size: 13px;
  font-weight: 560;
  margin-top: 10px;
  line-height: 1.35;
}

.card .meta {
  font-size: 12px;
  color: var(--fg-faint);
  line-height: 1.4;
}

/* ---------- viewer ---------- */

dialog#viewer {
  /* Stay out of normal flow, otherwise showModal() scrolls the page to
     reach the dialog. Also makes it the containing block for .viewer-close. */
  position: fixed;
  inset: 0;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--fg);
  max-width: min(720px, 92vw);
  max-height: 92vh;
  overflow: visible;
}

dialog#viewer::backdrop { background: rgba(4, 4, 6, 0.84); }

.viewer-inner {
  display: flex;
  gap: 26px;
  padding: 26px;
  align-items: center;
  max-height: 92vh;
  overflow-y: auto;
}

#viewer img {
  flex: 0 0 244px;
  width: 244px;
  border-radius: 9px;
  display: block;
}


.viewer-text .name {
  font-size: 19px;
  font-weight: 620;
  margin: 0 0 4px;
}

.viewer-text .meta {
  font-size: 13.5px;
  color: var(--fg-dim);
  margin: 0 0 12px;
}

.viewer-text .note {
  font-size: 14px;
  color: var(--fg-dim);
  margin: 0 0 20px;
  max-width: 40ch;
}

.viewer-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.viewer-links a {
  font-size: 13.5px;
  font-weight: 550;
  text-decoration: none;
  padding: 8px 15px;
  border-radius: 7px;
}

.viewer-links .tcg {
  color: var(--bg);
  background: var(--accent);
}

.viewer-links .pc {
  color: var(--fg-dim);
  border: 1px solid var(--line);
}

.viewer-links .tcg:hover { filter: brightness(1.08); }
.viewer-links .pc:hover { color: var(--fg); border-color: var(--fg-faint); }
.viewer-links a[hidden] { display: none; }

.viewer-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  font: inherit;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  background: none;
  border: 0;
  color: var(--fg-faint);
  cursor: pointer;
  border-radius: 6px;
}

.viewer-close:hover { color: var(--fg); }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }

  #sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .sidebar-inner {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 22px 20px 14px;
    gap: 18px;
    background: var(--bg-side);
  }

  .sort { display: flex; align-items: center; gap: 12px; }
  .sort-label { margin-bottom: 0; }
  .sort-buttons { flex: 0 0 auto; }
  .sort-buttons button { padding: 6px 14px; }

  #nav ul {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-left: 0;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  #nav ul::-webkit-scrollbar { display: none; }

  #nav li { flex: 0 0 auto; }

  #nav a {
    padding: 5px 12px;
    margin-left: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
  }

  #nav a[aria-current="true"] {
    background: var(--panel);
    border-color: var(--accent);
  }

  #nav .n { display: none; }

  .tools { padding-top: 14px; }
  .tools button { width: auto; }

  #list { padding: 30px 20px 80px; }
  #list section { scroll-margin-top: 130px; }

  .viewer-inner { flex-direction: column; align-items: center; gap: 18px; }
  #viewer img { flex: none; width: min(230px, 60vw); }
  .viewer-text { text-align: center; }
  .viewer-links { justify-content: center; }
  .viewer-text .note { max-width: none; }
}

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 20px 14px; }
  .brand h1 { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card img { transition: none; }
  .card:hover img, .card:focus-visible img { transform: none; }
}
