:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ece9e3;
  --text: #1d1b22;
  --muted: #6b6775;
  --border: #e0dcd4;
  --accent: #6246c4;
  --accent-soft: #6246c41a;
  --shadow: 0 1px 2px #0000000d, 0 8px 24px #00000014;
  --radius: 12px;
  --topbar-h: 64px;
  --nav-h: 56px;
  --chrome-h: calc(var(--topbar-h) + var(--nav-h));
  --tile: 170px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121118;
    --surface: #1b1a23;
    --surface-2: #262431;
    --text: #ecebf2;
    --muted: #9b98aa;
    --border: #2f2d3b;
    --accent: #a78bfa;
    --accent-soft: #a78bfa24;
    --shadow: 0 1px 2px #0000004d, 0 10px 30px #00000066;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121118;
  --surface: #1b1a23;
  --surface-2: #262431;
  --text: #ecebf2;
  --muted: #9b98aa;
  --border: #2f2d3b;
  --accent: #a78bfa;
  --accent-soft: #a78bfa24;
  --shadow: 0 1px 2px #0000004d, 0 10px 30px #00000066;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Components set their own display (e.g. .icon-btn), which would otherwise override [hidden] */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "PingFang HK", "Noto Sans TC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

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

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  flex: none;
  display: block;
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand h1, .brand .brand-title {
  margin: 0;
  font: 700 22px/1.1 "Cinzel Decorative", Georgia, serif;
  letter-spacing: .02em;
  white-space: nowrap;
}

.search {
  flex: 1;
  max-width: 520px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; }
.search kbd {
  font: 12px ui-monospace, monospace;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
}


.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; }

.filters-toggle { display: none; position: relative; flex: none; }
.search-open, .search-close { display: none; }
.toggle-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
}

/* Desktop: tab on the sidebar's right edge, vertically centred, to hide/show it */
.sidebar-handle {
  position: fixed;
  z-index: 15;
  top: calc(var(--chrome-h) + (100vh - var(--chrome-h)) / 2);
  left: 272px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: color .12s ease, border-color .12s ease;
}
.sidebar-handle:hover { color: var(--accent); border-color: var(--accent); }
.sidebar-handle svg { width: 16px; height: 16px; transition: transform .15s ease; }
.handle-count {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
}

.layout.collapsed { grid-template-columns: minmax(0, 1fr); }
.layout.collapsed .filters { display: none; }
.layout.collapsed .sidebar-handle {
  left: 0;
  border-left: 0;
  border-radius: 0 8px 8px 0;
  transform: translateY(-50%);
}
.layout.collapsed .sidebar-handle svg { transform: rotate(180deg); }

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}

.btn {
  padding: 8px 16px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.filters {
  position: sticky;
  top: var(--chrome-h);
  height: calc(100vh - var(--chrome-h));
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--border);
}

.filters-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.reset-btn {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer;
}
.filters-head h2 { margin: 0; font-size: 15px; }

.fgroup { border-bottom: 1px solid var(--border); }
.fgroup:last-child { border-bottom: 0; }
.fgroup summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.fgroup summary::-webkit-details-marker { display: none; }
.fgroup summary:hover { color: var(--text); }
.fgroup summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin: 0 4px 3px auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform .15s ease;
}
.fgroup:not([open]) summary::after { transform: rotate(-45deg); margin-bottom: 0; }
.fcount {
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.fbody { padding: 0 0 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.ink-logo { display: block; flex: none; width: auto; height: 20px; }
.chip .ink-logo { margin-left: -4px; }
.chip.ink[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--text); }

.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.set-tile {
  position: relative;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #16151d;
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.set-tile img { display: block; width: 100%; height: 100%; object-fit: contain; }
.set-tile:hover:not(:disabled) { transform: translateY(-2px); }
.set-tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.set-tile:disabled { opacity: .35; filter: grayscale(1); cursor: not-allowed; }
.set-num {
  position: absolute;
  left: 5px;
  bottom: 5px;
  padding: 0 6px;
  border-radius: 5px;
  background: #000000b3;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
}
.set-tile[aria-pressed="true"] .set-num { background: var(--accent); }

.chips-cost .chip {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}

.seg {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}
.chip .en { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 4px; }
.chip[aria-pressed="true"] .en { color: inherit; opacity: .75; }

.seg button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
  padding: 5px 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 13px;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }
.seg .en { font-size: 10px; opacity: .7; }

.scrim { display: none; }

main { padding: 16px 24px 48px; min-width: 0; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}
.active-filters[hidden] { display: none; }
.af-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 13px;
}
.af-chip .ink-logo { height: 16px; margin-left: -4px; }
.af-label { color: var(--muted); font-size: 12px; }
.af-remove {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.af-remove:hover { background: var(--accent); color: #fff; }
.af-clear { margin-left: 4px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar p { margin: 0; color: var(--muted); font-size: 14px; }
.toolbar p strong { color: var(--text); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.sort select { width: auto; padding: 6px 8px; color: var(--text); }
.density { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-left: 8px; }
.density svg { width: 16px; height: 16px; fill: currentColor; }
.density input { width: 90px; accent-color: var(--accent); }

/* ---------- Grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--tile), 100%), 1fr));
  gap: 18px 14px;
}

.tile {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tile-open {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.tile-img {
  display: block;
  width: 100%;
  aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 1px 2px #00000026;
  transition: transform .15s ease, box-shadow .15s ease;
}
.tile-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile-open:hover .tile-img, .tile-open:focus-visible .tile-img { transform: translateY(-4px); box-shadow: var(--shadow); }
.tile-open:focus-visible { outline: none; }
.tile-open:focus-visible .tile-img { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ink-dots { display: inline-flex; gap: 2px; }
.ink-dots .ink-logo { height: 16px; }

.empty { text-align: center; padding: 64px 16px; color: var(--muted); }
.empty code {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
}

/* ---------- Detail dialog ---------- */

dialog {
  width: min(1000px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
/* Keep the card list behind the detail view still while it's open */
html:has(dialog[open]) { overflow: hidden; }
html { scrollbar-gutter: stable; }
.detail-inner { overscroll-behavior: contain; }

dialog::backdrop { background: #0b0a12b3; backdrop-filter: blur(4px); }

.detail-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.detail-bar span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.close-btn { margin-left: auto; }

.detail-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 28px;
  padding: 24px;
  overflow-y: auto;
}

.detail-img { margin: 0; }
.detail-img img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%;
  background: var(--surface-2) center / cover no-repeat;
  box-shadow: var(--shadow);
}

.detail-body { min-width: 0; }
.eyebrow { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.detail-body h2 { margin: 0; font-size: 26px; line-height: 1.15; }
.detail-body h2 small { display: block; margin-top: 4px; font-size: 16px; font-weight: 500; color: var(--muted); }

.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 18px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
}
.pill .ink-logo { height: 18px; margin-left: -4px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}
.stat {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}
.stat dt { font-size: 11px; color: var(--muted); }
.stat dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: center; justify-content: center; gap: 4px; }
.stat dd .ic { font-size: 16px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.tag {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  font-size: 12px;
  cursor: pointer;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }

.card-text {
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}
.card-text p { margin: 0 0 8px; }
.card-text { position: relative; }
.card-text[lang="zh-Hant"] { line-height: 1.7; }
.card-text[lang="zh-Hant"] .reminder { font-style: normal; }
.lang-toggle {
  float: right;
  display: flex;
  gap: 2px;
  margin: -4px -6px 6px 12px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}
.lang-toggle button {
  padding: 2px 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.lang-toggle button[aria-checked="true"] { background: var(--accent); color: #fff; }
.card-text p:last-child { margin-bottom: 0; }
.card-text .ability { letter-spacing: .02em; display: block; margin-bottom: 2px; }
.card-text .reminder { font-style: italic; color: var(--muted); }

.flavor {
  margin: 14px 0 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
}

.section-label { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 18px 0 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.meta a { color: var(--accent); }

.ic {
  display: inline-flex;
  width: 1.05em;
  height: 1.05em;
  vertical-align: -.15em;
}
.ic svg { width: 100%; height: 100%; fill: currentColor; }
.ic-i { color: #c99a2e; }
.ic-s { color: #d1283a; }
.ic-w { color: #1a8fd0; }
.ic-l { color: #7c4d9f; }
.ic-e, .ic-inkwell { color: var(--text); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  :root { --topbar-h: 60px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .brand { flex: none; }
  .search { min-width: 0; margin-left: 0; }
  .search kbd { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filters-toggle { display: inline-grid; }
  .sidebar-handle { display: none; }
  .layout.collapsed .filters { display: block; }

  .filters {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(320px, 86vw);
    height: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .filters.open { transform: none; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: #0b0a1280; }
  .scrim[hidden] { display: none; }

  main { padding: 14px 16px 40px; }
  .density input { width: 70px; }

  .detail-inner { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 16px; }
  .detail-img img { max-width: 360px; margin: 0 auto; }
  dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
}

@media (max-width: 480px) {
    .density { display: none; }
    .toolbar .cols-btn { display: inline-flex; }
    .grid { grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 14px 10px; }
    /* Narrow tiles (3–4 per row): tighter labels and deck controls */
    :root[data-cols="3"] .grid, :root[data-cols="4"] .grid { gap: 12px 6px; }
    :root[data-cols="4"] .tile-meta { font-size: 10px; gap: 3px; }
    :root[data-cols="4"] .tile-meta .ink-logo { height: 12px; }
    :root[data-cols="3"] .deck-ctl .qty-btn, :root[data-cols="4"] .deck-ctl .qty-btn { width: 22px; height: 22px; font-size: 14px; }
    :root[data-cols="4"] .deck-ctl b { font-size: 10px; }
}

/* ---------- Related cards (detail view) ---------- */

.related {
  grid-column: 1 / -1;
  min-width: 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.related-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.related-head h3 { margin: 0; font-size: 17px; }
.related-hint { margin: 4px 0 4px; font-size: 12px; color: var(--muted); }
.rel-section {
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.rel-group { margin-bottom: 16px; min-width: 0; }
.rel-group-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.rel-group-head .n {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
}
.rel-group-head .link-btn { margin-left: auto; font-size: 12px; white-space: nowrap; }
.rel-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.rel-card {
  flex: 0 0 104px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
}
.rel-card > img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%;
  background: var(--surface-2);
  box-shadow: 0 1px 2px #00000026;
  transition: transform .12s ease;
}
.rel-card:hover > img, .rel-card:focus-visible > img { transform: translateY(-3px); }
.rel-card:focus-visible { outline: none; }
.rel-card:focus-visible > img { outline: 2px solid var(--accent); outline-offset: 2px; }
.rel-card.off { opacity: .45; }
.rel-inks { display: flex; align-items: center; gap: 4px; margin-top: 5px; }
.rel-inks .ink-logo { height: 14px; }
.rel-name {
  display: -webkit-box;
  margin-top: 2px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.rel-name small { display: block; color: var(--muted); font-size: 11px; }
.rel-empty { color: var(--muted); font-size: 13px; }
.back-btn { width: auto; padding: 0 12px; font-size: 13px; white-space: nowrap; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 900px) {
  .rel-card { flex-basis: 88px; }
}

/* ---------- Page navigation ---------- */

.pagenav {
  position: sticky;
  top: var(--topbar-h);
  z-index: 19;
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: var(--nav-h);
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.pagenav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.pagenav-link:hover { color: var(--text); }
/* Plain link to the crawlable static card list */
.filters-link {
  display: block;
  margin: 16px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}
.filters-link:hover { text-decoration: underline; }
.cols-btn { display: none; width: auto; gap: 4px; padding: 0 9px; font-size: 13px; }
.cols-btn svg { width: 15px; height: 15px; fill: currentColor; }

.pagenav-list {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  text-decoration: none;
}
.pagenav-list small { font-size: 11px; }
.pagenav-list:hover { color: var(--text); }
.nav-label { font-size: 15px; line-height: 1.25; text-align: center; }
.pagenav-link[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.nav-count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}
.pagenav-link[aria-current="page"] .nav-count { background: var(--accent); color: #fff; }

/* ---------- Deck Builder ---------- */

.deck-panel, .deck-ctl, .deck-fab { display: none; }

body.page-deck .layout { grid-template-columns: 272px minmax(0, 1fr) 360px; }
body.page-deck .layout.collapsed { grid-template-columns: minmax(0, 1fr) 360px; }

body.page-deck .deck-panel {
  position: sticky;
  top: var(--chrome-h);
  height: calc(100vh - var(--chrome-h));
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border-left: 1px solid var(--border);
  background: var(--bg);
}

.deck-head { display: flex; gap: 8px; }
.deck-head select { flex: 1; min-width: 0; font-weight: 600; }
.deck-close { display: none; }
.deck-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.link-btn.danger { color: #e5484d; }

.deck-summary { padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.deck-count { font-size: 14px; color: var(--muted); }
.deck-count b { font-size: 28px; color: var(--text); font-variant-numeric: tabular-nums; }
.deck-inks { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 10px; font-size: 13px; }
.deck-inks span { display: inline-flex; align-items: center; gap: 4px; }
.deck-inks .ink-logo { height: 18px; }
.deck-inks .muted { color: var(--muted); }
.deck-bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.deck-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }

.deck-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.deck-checks li { display: flex; align-items: baseline; gap: 8px; }
.deck-checks span {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.deck-checks .ok span { background: #2a8a4333; color: #3fb95f; }
.deck-checks .bad span { background: #e5484d26; color: #e5484d; }
.deck-filter { width: 100%; font-size: 13px; }

.deck-label { margin: 6px 0 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.curve { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; height: 96px; align-items: end; }
.curve-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 2px; }
.curve-bar { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--accent); opacity: .85; }
.curve-n, .curve-cost { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.deck-meta { margin: 0; font-size: 12px; color: var(--muted); }

.deck-group { margin-top: 6px; }
.deck-group-head {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.deck-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.deck-cost {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.deck-row .ink-dots {
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 16px;
}
.deck-row .ink-dots .ink-logo { height: 16px; }
.deck-row .ink-dots .ink-logo:nth-child(2) { margin-top: -1px; }
.deck-name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.25;
  cursor: pointer;
}
.deck-name:hover { color: var(--accent); }
/* Small crop of the card art, enough to recognise the card at a glance */
.deck-art {
  position: relative;
  flex: none;
  width: 52px;
  height: 36px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border);
}
.deck-art img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; }
/* Location cards are printed sideways: turn the image so the art reads landscape */
.deck-art.loc img {
  position: absolute;
  left: 8px;
  top: -8px;
  width: 36px;
  height: 52px;
  object-position: center;
  transform: rotate(90deg);
}
.deck-name:hover .deck-art { box-shadow: 0 0 0 2px var(--accent); }
.deck-name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-name small { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.deck-empty { color: var(--muted); font-size: 13px; }

.qty { flex: none; display: inline-flex; align-items: center; gap: 6px; }
.qty b { min-width: 16px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.qty-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.qty-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.qty-btn:disabled { opacity: .35; cursor: not-allowed; }

/* +/− under each card, Deck Builder only */
body.page-deck .deck-ctl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}
.deck-ctl b { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile.in-deck .deck-ctl { border-color: var(--accent); background: var(--accent-soft); }
.tile.in-deck .deck-ctl b { color: var(--text); font-weight: 700; }
body.page-deck .tile.cant-add .tile-img { opacity: .4; }

.detail-deck {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
}
.detail-deck .qty { margin-left: auto; }
.detail-deck small { width: 100%; color: var(--muted); }

.deck-io { width: min(560px, calc(100vw - 32px)); }
.deck-io form { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.deck-io h3 { margin: 0; }
.deck-io-hint, .deck-io-msg { margin: 0; font-size: 13px; color: var(--muted); }
.deck-io textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
.deck-io-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }

/* Edge tab on the deck panel, vertically centred, to widen it into a card-image view */
.deck-handle { display: none; }
body.page-deck .deck-handle {
  position: fixed;
  z-index: 15;
  top: calc(var(--chrome-h) + (100vh - var(--chrome-h)) / 2);
  right: 360px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow);
  cursor: pointer;
  transform: translate(50%, -50%);
}
body.page-deck .deck-handle:hover { color: var(--accent); border-color: var(--accent); }
.deck-handle svg { width: 16px; height: 16px; transition: transform .15s ease; }

.deck-visual { display: none; }

/* Expanded: the deck panel takes the whole width; summary on the left, cards on the right */
body.page-deck.deck-expanded .layout,
body.page-deck.deck-expanded .layout.collapsed { grid-template-columns: minmax(0, 1fr); }
body.page-deck.deck-expanded .filters,
body.page-deck.deck-expanded main,
body.page-deck.deck-expanded .sidebar-handle { display: none; }
body.page-deck.deck-expanded .deck-handle { right: auto; left: 0; transform: translateY(-50%); border-left: 0; border-radius: 0 8px 8px 0; }
body.page-deck.deck-expanded .deck-handle svg { transform: rotate(180deg); }
body.page-deck.deck-expanded .deck-panel { padding: 20px 28px; border-left: 0; }
body.page-deck.deck-expanded #deckBody {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
body.page-deck.deck-expanded .deck-side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
body.page-deck.deck-expanded .deck-list { display: none; }
body.page-deck.deck-expanded .deck-visual { display: block; }
.deck-side { display: flex; flex-direction: column; gap: 10px; }
.deck-vgroup { margin-bottom: 18px; }
.deck-vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
.deck-card { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.deck-card-img {
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.deck-card-img img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%;
  background: var(--surface-2);
  box-shadow: 0 1px 2px #00000026;
  transition: transform .12s ease;
}
.deck-card-img:hover img { transform: translateY(-3px); }
.deck-card-n {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #000000c0;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .pagenav { padding: 0 8px; }
  .pagenav-link { padding: 0 10px; }
  body.page-deck .layout, body.page-deck .layout.collapsed { grid-template-columns: minmax(0, 1fr); }
  body.page-deck .deck-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(380px, 92vw);
    height: auto;
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  body.page-deck .deck-panel.open { transform: none; }
  .deck-close { display: inline-grid; }
  body.page-deck .deck-handle { display: none; }
  body.page-deck.deck-expanded .layout { grid-template-columns: minmax(0, 1fr); }
  body.page-deck.deck-expanded main { display: block; }
  body.page-deck.deck-expanded .filters { display: block; }
  body.page-deck.deck-expanded .deck-list { display: block; }
  body.page-deck.deck-expanded .deck-visual { display: none; }
  body.page-deck.deck-expanded #deckBody { display: block; }
  body.page-deck.deck-expanded .deck-panel { padding: 16px; }
  body.page-deck .deck-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 35;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 14px;
    cursor: pointer;
  }
}

/* ---------- Scan ---------- */

.scan-btn { display: none; flex: none; }

dialog.scan {
  width: min(520px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  flex-direction: column;
}
dialog.scan[open] { display: flex; }
.scan-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.scan-bar h3 { margin: 0; font-size: 16px; }
.scan-bar small { color: var(--muted); font-weight: 500; }
.scan-stage {
  position: relative;
  flex: none;
  height: min(58vh, 520px);
  overflow: hidden;
  background: #000;
}
.scan-stage video, .scan-stage img { position: absolute; inset: 0; width: 100%; height: 100%; }
.scan-stage video { object-fit: cover; }
.scan-stage img { object-fit: contain; }
.scan-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 86%;
  aspect-ratio: 800 / 1116;
  max-width: 86%;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 4.5% / 3.2%;
  box-shadow: 0 0 0 100vmax #00000080;
  pointer-events: none;
}
.scan-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: #cfcfd8; font-size: 14px; }
.scan-hint { margin: 10px 14px 0; font-size: 12px; color: var(--muted); }
.scan-actions { display: flex; justify-content: center; padding: 10px 14px; }
.scan-photo-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 160px; cursor: pointer; }
.scan-results { display: flex; flex-direction: column; gap: 8px; padding: 0 14px 14px; overflow-y: auto; }
.scan-note { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.scan-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.scan-result:hover { border-color: var(--accent); }
.scan-result.best { border-color: var(--accent); background: var(--accent-soft); }
.scan-result img { flex: none; width: 52px; height: auto; aspect-ratio: 800 / 1116; border-radius: 4px; }
.scan-result-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 14px; }
.scan-result-text small { color: var(--muted); font-size: 12px; }
.scan-result-text em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--accent); }

@media (max-width: 900px) {
  .scan-btn { display: inline-grid; }
}

/* ---------- Hover preview ---------- */

.hover-preview {
  position: fixed;
  z-index: 60;
  pointer-events: none;
}
.hover-preview img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%;
  background: var(--surface-2) center / cover no-repeat;
  box-shadow: 0 12px 28px #000000a0;
}

/* Copyright / source notice under the card list */
.app-foot { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.6; }
.app-foot p { margin: 0 0 6px; }

/* Live scan stopped on a recognised card */
.scan-stage.locked .scan-guide { border-color: var(--accent); box-shadow: 0 0 0 100vmax #000000a0, 0 0 0 4px var(--accent); }
.scan-again { align-self: center; margin-top: 4px; }

/* ---------- Deck Guide (新手牌組設計) ---------- */

.guide-page { display: none; }
body.page-guide .layout, body.page-guide .sidebar-handle { display: none; }
body.page-guide .guide-page { display: block; max-width: 1240px; margin: 0 auto; padding: 20px 24px 48px; }


.g-head h2 { margin: 0 0 6px; font-size: 24px; }
.g-head p { margin: 0 0 16px; color: var(--muted); line-height: 1.7; }
.g-head .ink-logo, .g-ink-title .ink-logo { display: inline-block; height: 18px; vertical-align: -3px; margin-right: 2px; }
.g-sets { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.g-set { flex: 0 0 105px; } /* 30% smaller than the sidebar tiles */
@media (max-width: 900px) { .g-sets { gap: 8px; } .g-set { flex: 1 1 calc(35% - 4px); max-width: calc(35% - 4px); } }

.g-grid { display: grid; gap: 18px 14px; }
.g-showcase { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.g-recs { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.g-card { display: flex; flex-direction: column; gap: 5px; min-width: 0; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.g-card > img { display: block; width: 100%; height: auto; aspect-ratio: 800 / 1116; border-radius: 4.5% / 3.2%; background: var(--surface-2); box-shadow: 0 2px 6px #00000040; transition: transform .15s ease, box-shadow .15s ease; }
.g-showcase .g-card:hover > img { transform: translateY(-5px) scale(1.02); box-shadow: 0 14px 30px #00000070; }
.g-recs .g-card:hover > img { transform: translateY(-3px); }
.g-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.g-name small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.g-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.g-meta .ink-logo { height: 15px; }
.g-reasons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.g-reasons em { padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-style: normal; }

.g-split { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; }
.g-theme { position: sticky; top: calc(var(--chrome-h) + 16px); }
.g-theme > img { display: block; width: 100%; height: auto; border-radius: 4.5% / 3.2%; box-shadow: 0 12px 30px #00000060; }
.g-theme-name { margin: 10px 0 2px; font-size: 18px; font-weight: 700; }
.g-theme-name small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.g-theme-meta { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.g-theme-meta .ink-logo { height: 18px; }

.g-inks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.g-ink {
  display: flex; gap: 14px; align-items: center; padding: 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 12px; background: var(--surface);
  transition: transform .15s ease, border-color .15s ease;
}
.g-ink:hover { transform: translateY(-3px); border-color: var(--c); }
.g-ink > img { flex: none; width: 84px; height: auto; aspect-ratio: 800 / 1116; border-radius: 4.5% / 3.2%; }
.g-ink-body { display: flex; flex-direction: column; gap: 4px; }
.g-ink-title { font-size: 16px; font-weight: 700; }
.g-ink-style { color: var(--muted); font-size: 13px; line-height: 1.5; }
.g-ink-count { font-size: 13px; }
.g-ink-count b, .g-count b { color: var(--accent); }

.g-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 18px; }
.g-hint { color: var(--muted); font-size: 12px; }

@media (max-width: 900px) {
  body.page-guide .guide-page { padding: 14px 16px 40px; }
  .g-split { grid-template-columns: minmax(0, 1fr); }
  .g-theme { position: static; display: grid; grid-template-columns: 110px 1fr; gap: 4px 14px; align-items: start; }
  .g-theme > img { grid-row: span 3; }
  .g-theme-name { margin-top: 0; }
  .g-showcase { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .g-recs { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

/* Deck Guide as one scrolling page */
.g-nav {
  position: sticky; top: var(--chrome-h); z-index: 12;
  display: flex; gap: 6px; margin: 0 -24px 8px; padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.g-nav button {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.g-nav button b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); font-size: 11px; }
.g-nav button.on { color: var(--text); border-color: var(--accent); }
.g-nav button.on b { background: var(--accent); color: #fff; }
.g-nav button:disabled { opacity: .45; cursor: default; }

.g-hero {
  overflow-x: clip; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 24px; align-items: center;
  padding: 58px 0 74px; /* +60px breathing room */
}
.g-hero-text .g-eyebrow, .g-eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: .08em; }
.g-hero-title { margin: 0 0 14px; font-size: clamp(28px, 4vw, 44px); line-height: 1.15; }
.g-hero-text p { color: var(--muted); font-size: 16px; line-height: 1.8; max-width: 34em; }
.g-hero .btn { margin-top: 12px; padding: 12px 22px; font-size: 15px; }
.g-hero-fan { position: relative; height: 300px; margin-bottom: 40px; }
.g-hero-fan img {
  position: absolute; left: 50%; bottom: 0; width: 170px; height: auto; aspect-ratio: 800 / 1116;
  border-radius: 4.5% / 3.2%; box-shadow: 0 16px 36px #00000080;
  transform-origin: 50% 120%;
  transform: translateX(calc(-50% + var(--i) * 34px)) rotate(calc(var(--i) * 7.3deg)) translateY(calc(var(--i) * var(--i) * 4px));
  transition: transform .3s ease;
}
@media (hover: hover) and (pointer: fine) {
  .g-hero-fan:hover img { transform: translateX(calc(-50% + var(--i) * 42px)) rotate(calc(var(--i) * 9deg)) translateY(calc(var(--i) * var(--i) * 5px - 12px)); }
}

.g-sec { padding: 36px 0 12px; border-top: 1px solid var(--border); scroll-margin-top: calc(var(--chrome-h) + 60px); }
.g-num { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .1em; }
.g-filters { position: relative; display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.g-franchise { padding-top: 22px; scroll-margin-top: calc(var(--chrome-h) + 60px); }
.g-franchise h3 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; font-size: 18px; }
.g-franchise h3 small { color: var(--muted); font-size: 12px; font-weight: 400; }
.g-showcase { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.g-card.picked > img { outline: 3px solid var(--accent); outline-offset: 3px; }
.g-ink.picked { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.g-cta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
  margin: 28px 0 8px; padding: 18px 20px; border: 1px solid var(--accent); border-radius: 14px; background: var(--accent-soft);
}
.g-cta p { margin: 0; color: var(--muted); }
.g-cta p b { color: var(--text); }
.g-cta .btn { padding: 12px 24px; font-size: 15px; }

@media (max-width: 900px) {
  .g-nav { margin: 0 -16px 8px; padding: 8px 16px; overflow-x: auto; }
  .g-nav button { flex: none; }
  .g-hero { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .g-hero-fan { height: 200px; margin: 0 0 56px; order: -1; }
  .g-hero-fan img { width: 110px; transform: translateX(calc(-50% + var(--i) * 18px)) rotate(calc(var(--i) * 7.3deg)) translateY(calc(var(--i) * var(--i) * 3px)); }
  .g-showcase { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); }
}
/* The last step fills the screen so it can scroll up under the step bar */
.g-sec:last-child { min-height: calc(100vh - var(--chrome-h) - 60px); }

/* Deck Guide step 1: game-style character select */
.g-select { position: relative; z-index: 1; overflow-x: clip; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; margin: 8px 0 18px; padding: 30px 0; /* +60px breathing room */ }
.g-arrow {
  display: grid; place-items: center; width: 52px; height: 52px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%; background: var(--surface);
  color: var(--text); font-size: 30px; line-height: 1; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease, color .12s ease;
}
.g-arrow:hover { transform: scale(1.08); border-color: var(--accent); color: var(--accent); }
.g-select-main { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.g-select-title { margin: 0; text-align: center; font-size: 24px; font-weight: 700; }
.g-select-title small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; font-weight: 400; }
.g-fan { position: relative; width: 100%; height: 390px; margin-top: 4px; }
.g-fan-card {
  position: absolute; left: 50%; bottom: 40px; width: 220px; padding: 0; border: 0; background: none; cursor: pointer;
  transform-origin: 50% 130%;
  /* Spread sideways as well as rotating, so each card has its own area to hover */
  transform: translateX(calc(-50% + var(--i) * 70px)) rotate(calc(var(--i) * 8deg)) translateY(calc(var(--i) * var(--i) * 4px));
}
/* The lift happens on the image only: the button's hover area never moves, so no flicker */
.g-fan-card img {
  display: block; width: 100%; height: auto; aspect-ratio: 800 / 1116; pointer-events: none;
  border-radius: 4.5% / 3.2%; box-shadow: 0 16px 36px #00000080;
  transition: transform .25s ease, box-shadow .25s ease;
}
.g-fan-card:focus-visible { z-index: 20 !important; }
.g-fan-card:focus-visible img { transform: rotate(calc(var(--i) * -8deg)) translateY(-28px) scale(1.07); }
/* Lift on hover only with a real mouse: on phones a tap left the card stuck enlarged */
@media (hover: hover) and (pointer: fine) {
  .g-fan-card:hover { z-index: 20 !important; }
  .g-fan-card:hover img { transform: rotate(calc(var(--i) * -8deg)) translateY(-28px) scale(1.07); box-shadow: 0 24px 50px #000000a0; }
}
.g-fan-card.picked img { outline: 3px solid var(--accent); outline-offset: 3px; }
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 13px; cursor: pointer;
}

/* Step 2: overlapping strip of the franchise's other characters */
.g-strip { margin-bottom: 18px; }
.g-strip-title { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.g-strip-title small { margin-left: 8px; color: var(--muted); font-size: 12px; font-weight: 400; }
.g-strip-cards { display: flex; padding: 14px 0 6px 6px; overflow-x: auto; scrollbar-width: thin; }
.g-strip-card {
  flex: 0 0 104px; margin-left: -30px; padding: 0; border: 0; background: none; cursor: pointer;
  transform: rotate(calc((var(--k) - 4) * 1.5deg)); transition: transform .2s ease;
}
.g-strip-card:first-child { margin-left: 0; }
.g-strip-card img { display: block; width: 100%; height: auto; aspect-ratio: 800 / 1116; border-radius: 4.5% / 3.2%; box-shadow: 0 6px 16px #00000070; }
@media (hover: hover) and (pointer: fine) { .g-strip-card:hover { position: relative; z-index: 3; transform: translateY(-12px) scale(1.08); } }

@media (max-width: 900px) {
  .g-select { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 4px; }
  .g-arrow { width: 40px; height: 40px; font-size: 24px; }
  .g-fan { height: 275px; }
  .g-fan-card { width: 143px; transform: translateX(calc(-50% + var(--i) * 20px)) rotate(calc(var(--i) * 8deg)) translateY(calc(var(--i) * var(--i) * 3px)); }
  .g-select-title { font-size: 19px; }
  .g-strip-card { flex-basis: 84px; margin-left: -26px; }
}

/* Franchise dropdown under the fan */
.g-picker { position: relative; z-index: 25; display: flex; justify-content: center; width: 100%; margin: 0 0 4px; }
.g-picker-btn {
  display: flex; align-items: center; gap: 12px; min-width: min(360px, 100%); padding: 8px 16px 8px 8px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow);
  text-align: left; cursor: pointer; transition: border-color .15s ease;
}
.g-picker-btn:hover, .g-picker-btn[aria-expanded="true"] { border-color: var(--accent); }
.g-picker-btn img { flex: none; width: 36px; height: 50px; object-fit: cover; border-radius: 4px; }
.g-picker-btn span { flex: 1; min-width: 0; font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-picker-btn span small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.g-picker-btn em { color: var(--muted); font-size: 12px; font-style: normal; font-variant-numeric: tabular-nums; }
.g-picker-btn svg { flex: none; width: 18px; height: 18px; color: var(--muted); transition: transform .15s ease; }
.g-picker-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.g-picker-panel {
  position: absolute; top: calc(100% + 8px); left: 50%; z-index: 30; transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px)); padding: 12px;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: 0 20px 50px #00000080;
}
.g-picker-panel[hidden] { display: none; }
.g-picker-search {
  width: 100%; margin-bottom: 10px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
.g-picker-search:focus { outline: none; border-color: var(--accent); }
.g-picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-height: 360px; overflow-y: auto; overscroll-behavior: contain; }
.g-picker-item {
  display: flex; align-items: center; gap: 10px; padding: 6px; border: 1px solid transparent; border-radius: 10px;
  background: none; text-align: left; cursor: pointer;
}
.g-picker-item[hidden] { display: none; }
.g-picker-item:hover { background: var(--surface-2); }
.g-picker-item[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.g-picker-item img { flex: none; width: 32px; height: 44px; object-fit: cover; border-radius: 4px; }
.g-picker-item span { min-width: 0; font-size: 13px; font-weight: 600; line-height: 1.3; }
.g-picker-item span small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.g-picker-empty { margin: 8px 0 2px; color: var(--muted); font-size: 13px; text-align: center; }
.g-picker-count { display: none; font-weight: 400; }
@media (max-width: 900px) {
  .g-picker-btn { min-width: 0; width: 100%; }
  .g-picker-btn em { display: none; }
  .g-picker-count { display: inline; }
  .g-picker-btn span { font-size: 17px; line-height: 1.25; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .g-picker-btn span small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .g-picker-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); max-height: 50vh; }
}

/* Rotation: sets too old for deck building */
.deck-legal { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
body.page-deck .set-tile.rotated { opacity: .35; filter: grayscale(1); cursor: not-allowed; }
body.page-deck .set-tile.rotated::after {
  content: "已輪替"; position: absolute; right: 5px; top: 5px; padding: 0 6px; border-radius: 5px;
  background: #000000b3; color: #fff; font-size: 10px; line-height: 16px;
}
.g-hero-text .g-legal { margin-top: 4px; font-size: 13px; }

/* "Change theme" button under the chosen character */
.g-change {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 4px; padding: 10px 14px;
  border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s ease, color .15s ease;
}
.g-change:hover { background: var(--accent); color: #fff; }
.g-change svg { width: 16px; height: 16px; }
@media (max-width: 900px) { .g-change { width: auto; justify-self: start; } }

/* Recommendations grouped for beginners */
.g-rec-group { margin-top: 26px; }
.g-rec-group h3 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 4px; font-size: 18px; }
.g-rec-group h3 small { color: var(--muted); font-size: 12px; font-weight: 400; }
.g-rec-desc { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

/* Step 3: recommendations with a deck play-style panel on the right */
.g-recs-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.g-traits {
  position: sticky; top: calc(var(--chrome-h) + 70px); display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100vh - var(--chrome-h) - 86px); overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
}
.g-traits-title { margin: 0; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .1em; }
.g-traits-summary { margin: 0; font-size: 15px; line-height: 1.6; }
.g-traits-summary b { color: var(--accent); }
.g-trait-list { display: flex; flex-direction: column; gap: 8px; }
.g-trait {
  display: flex; flex-direction: column; gap: 5px; padding: 10px 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); transition: border-color .15s ease;
}
.g-trait:hover, .g-trait[aria-pressed="true"] { border-color: var(--accent); }
.g-trait[aria-pressed="true"] { background: var(--accent-soft); }
.g-trait-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.g-trait-head b { font-size: 15px; }
.g-trait-head small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.g-trait-bar { height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.g-trait-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.g-trait-desc { color: var(--muted); font-size: 12px; line-height: 1.5; }
.g-traits-hint { margin: 0; color: var(--muted); font-size: 11px; }
.g-traits .g-cta { flex-direction: column; align-items: stretch; margin: 4px 0 0; padding: 14px; }
.g-traits .g-cta p { font-size: 12px; }
.g-recs-layout.filtering .g-rec { opacity: .25; transition: opacity .2s ease; }
.g-recs-layout.filtering .g-rec.match { opacity: 1; }
@media (max-width: 1000px) {
  .g-recs-layout { grid-template-columns: minmax(0, 1fr); }
  .g-traits { position: static; order: -1; max-height: none; }
}


/* Site language switch */
.lang-btn {
  flex: none; height: 36px; min-width: 40px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 700; cursor: pointer;
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Tapped / picked card pops out on its own; the rest of the fan stays put */
.g-hero-fan img { cursor: pointer; }
.g-hero-fan img.pop { z-index: 10; transform: translateX(calc(-50% + var(--i) * 34px)) rotate(0deg) translateY(-26px) scale(1.07); }
.g-fan-card.picked { z-index: 20 !important; }
.g-fan-card.picked img { transform: rotate(calc(var(--i) * -8deg)) translateY(-28px) scale(1.07); box-shadow: 0 24px 50px #000000a0; }
@media (max-width: 900px) {
  .g-hero-fan img.pop { transform: translateX(calc(-50% + var(--i) * 18px)) rotate(0deg) translateY(-18px) scale(1.08); }
}

/* Written summary under a pre-rendered guide page (guides/<key>/) */
.guide-about { display: none; }
body.page-guide .guide-about:not([hidden]) {
  display: block; max-width: 1240px; margin: 0 auto; padding: 8px 24px 48px;
  color: var(--muted); font-size: 14px; line-height: 1.7;
}
.guide-about h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }
.guide-about h3 { color: var(--text); font-size: 15px; margin: 20px 0 6px; }
.guide-about h4 { color: var(--text); font-size: 14px; margin: 14px 0 2px; }
.guide-about p, .guide-about ul { margin: 0 0 8px; }
.guide-about ul { padding-left: 20px; }
.guide-about a { color: var(--accent); }
@media (max-width: 720px) { body.page-guide .guide-about:not([hidden]) { padding: 4px 16px 40px; } }
@media (hover: hover) and (pointer: fine) { .reset-btn:hover { border-color: var(--accent); color: var(--accent); } }

/* Phones: search opens from an icon and then fills the top bar */
@media (max-width: 640px) {
  .search { display: none; }
  .search-open { display: inline-grid; flex: none; margin-left: auto; }
  /* The name fits again now the search box is folded away */
  .topbar { gap: 8px; }
  .brand { gap: 8px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand h1, .brand .brand-title { font-size: 18px; }
  .topbar.searching > :not(.search):not(.search-close) { display: none; }
  .topbar.searching .search { display: flex; max-width: none; }
  .topbar.searching .search-close {
    display: block; flex: none; padding: 0 2px; border: 0; background: none;
    color: var(--accent); font-size: 15px; cursor: pointer;
  }
}
@media (max-width: 340px) { .brand div { display: none; } }
