:root {
  --bg: #09080c;
  --surface: #121017;
  --surface-2: #18141e;
  --surface-3: #211b27;
  --line: #2b2431;
  --line-strong: #43364a;
  --ink: #f3ebdf;
  --muted: #a69ba5;
  --faint: #70677a;
  --gold: #d7a74e;
  --gold-hi: #f0cf8e;
  --radius: 10px;
  --header-h: 68px;
  --sidebar-w: 292px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); overflow-x: hidden;
  background: radial-gradient(900px 420px at 70% -180px, rgba(111, 61, 117, .2), transparent 70%), var(--bg);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid rgba(240, 207, 142, .65); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.appbar { position: sticky; top: 0; z-index: 30; border-bottom: 1px solid var(--line); background: rgba(10, 9, 13, .9); backdrop-filter: blur(18px); }
.appbar-inner { max-width: 1760px; height: var(--header-h); margin: 0 auto; padding: 0 24px; display: grid; grid-template-columns: var(--sidebar-w) minmax(260px, 680px) 1fr; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; color: inherit; text-decoration: none; }
.brand-mark { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid #765b2d; border-radius: 9px; color: var(--gold-hi); background: linear-gradient(145deg, #34271a, #15111a); font: 800 12px/1 system-ui, sans-serif; }
.brand-copy { display: grid; gap: 3px; min-width: 0; }
.brand-copy strong { font-size: 17px; letter-spacing: .04em; white-space: nowrap; }
.brand-copy small { color: var(--faint); font-size: 11px; white-space: nowrap; }
.search { height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: #0e0c12; transition: border-color .16s, box-shadow .16s; }
.search:focus-within { border-color: #9a7238; box-shadow: 0 0 0 3px rgba(215, 167, 78, .1); }
.search svg { flex: none; width: 18px; height: 18px; fill: none; stroke: #8b7f8d; stroke-width: 1.8; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 14px; }
.search input::placeholder { color: #6f6675; }
.search kbd { min-width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--faint); font: 11px system-ui; }
.library-total { justify-self: end; display: flex; align-items: baseline; gap: 5px; color: var(--faint); font-size: 12px; white-space: nowrap; }
.library-total b { color: var(--gold-hi); font: 700 18px system-ui, sans-serif; }

.shell { max-width: 1760px; margin: 0 auto; padding: 20px 24px 60px; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 24px; align-items: start; }
.sidebar { position: sticky; top: calc(var(--header-h) + 20px); display: grid; gap: 12px; max-height: calc(100vh - var(--header-h) - 40px); overflow: auto; scrollbar-width: thin; }
.category-panel, .filter-panel { border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(180deg, rgba(25, 20, 30, .94), rgba(16, 13, 20, .96)); }
.category-panel { padding: 14px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.panel-title small { color: var(--faint); font-size: 10px; font-weight: 400; letter-spacing: 0; }
.category-nav { display: grid; gap: 4px; }
.category-item { position: relative; width: 100%; min-height: 52px; display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid transparent; border-radius: 9px; background: transparent; text-align: left; cursor: pointer; transition: background .15s, border-color .15s; }
.category-item:hover { background: rgba(255,255,255,.035); }
.category-item.active { border-color: color-mix(in srgb, var(--accent) 52%, transparent); background: color-mix(in srgb, var(--accent) 12%, #16111a); }
.category-item.active::before { content: ''; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.category-item:disabled { opacity: .38; cursor: not-allowed; }
.category-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.category-text { display: grid; gap: 3px; min-width: 0; }
.category-text b { overflow: hidden; color: #eee3d6; font-size: 14px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.category-text small { overflow: hidden; color: var(--faint); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.category-item em { color: var(--muted); font: 600 12px system-ui, sans-serif; font-style: normal; }
.category-item.active em { color: var(--gold-hi); }

.filter-panel { padding: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: -2px 2px 12px; }
.sheet-head h2 { margin: 0; font-size: 15px; }
.sheet-grabber, .sheet-foot { display: none; }
.filter-section + .filter-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.tier-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tier-chip { min-width: 0; height: 48px; display: grid; place-content: center; gap: 2px; border: 1px solid var(--line); border-radius: 8px; background: #0f0d13; cursor: pointer; transition: .15s; }
.tier-chip b { color: #e5d9cd; font: 700 14px system-ui, sans-serif; }
.tier-chip i { margin-left: 1px; color: var(--gold); font-size: 10px; font-style: normal; }
.tier-chip small { color: var(--faint); font-size: 10px; }
.tier-chip:hover:not(:disabled), .tribe-chip:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-3); }
.tier-chip.active { border-color: #e1b866; background: linear-gradient(180deg, #e1b866, #c78c38); }
.tier-chip.active b, .tier-chip.active i, .tier-chip.active small { color: #1b1207; }
.tier-chip:disabled, .tribe-chip:disabled { opacity: .3; cursor: not-allowed; }
.tribe-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.tribe-chip { min-width: 0; height: 36px; display: grid; grid-template-columns: 7px 1fr auto; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: #0f0d13; cursor: pointer; text-align: left; transition: .15s; }
.tribe-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--tribe-color); }
.tribe-chip span { overflow: hidden; color: #d8cdc4; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.tribe-chip b { color: var(--faint); font: 500 10px system-ui, sans-serif; }
.tribe-chip.active { border-color: color-mix(in srgb, var(--tribe-color) 64%, #5a4730); background: color-mix(in srgb, var(--tribe-color) 15%, #15111a); }
.tribe-chip.active span { color: #fff2dc; }
.tribe-chip.active b { color: #d8c4a7; }

.content { min-width: 0; }
.result-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 4px 2px 18px; border-bottom: 1px solid var(--line); }
.result-heading p { margin: 0 0 5px; color: var(--faint); font-size: 12px; }
.result-heading h1 { display: flex; align-items: baseline; gap: 8px; margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: .02em; }
.result-heading h1 b { color: var(--gold-hi); font: 700 22px system-ui, sans-serif; }
.result-heading h1 small { color: var(--muted); font-size: 13px; font-weight: 400; }
.result-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.filter-trigger { display: none; height: 38px; align-items: center; gap: 7px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.filter-trigger svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.filter-trigger span { min-width: 18px; height: 18px; display: grid; place-items: center; border-radius: 9px; color: #1b1207; background: var(--gold); font-size: 11px; font-weight: 700; }
.segmented { height: 38px; display: flex; padding: 3px; border: 1px solid var(--line-strong); border-radius: 9px; background: #0f0d13; }
.segmented[hidden], .tier-grid[hidden], .filter-section[hidden] { display: none; }
.segmented button { min-width: 52px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.segmented button.active { color: #1b1207; background: var(--gold); }
.select-control { height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 0 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: #0f0d13; color: var(--faint); font-size: 12px; }
.select-control select { height: 100%; min-width: 88px; padding: 0 30px 0 0; border: 0; outline: 0; appearance: none; background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%23a69ba5' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 11px center; color: #e8ddd1; font-size: 13px; cursor: pointer; }
.select-control option { background: #17131b; }
.active-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px 0; }
.active-row[hidden] { display: none; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.active-chip { height: 30px; display: inline-flex; align-items: center; gap: 7px; padding: 0 9px 0 11px; border: 1px solid #6b5230; border-radius: 15px; background: rgba(215, 167, 78, .1); color: #f2d9ac; font-size: 12px; cursor: pointer; }
.active-chip b { color: #a98d69; font-size: 15px; line-height: 1; }
.text-button { flex: none; padding: 6px 4px; border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.text-button:hover { color: var(--gold-hi); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: 14px 10px; align-items: start; padding-top: 18px; }
.card-grid[hidden] { display: none; }
.group-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; min-height: 34px; margin-top: 10px; }
.group-head:first-child { margin-top: 0; }
.group-head span { color: var(--gold-hi); font-size: 15px; font-weight: 700; white-space: nowrap; }
.group-head small { color: var(--faint); font-size: 12px; white-space: nowrap; }
.group-head i { flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }
.card { min-width: 0; display: block; padding: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #121017; text-align: left; cursor: pointer; transition: transform .16s, border-color .16s, box-shadow .16s; content-visibility: auto; contain-intrinsic-size: auto 260px; }
.card:hover { transform: translateY(-2px); border-color: #7a5a2e; box-shadow: 0 12px 28px rgba(0,0,0,.4); }
.card-art { position: relative; aspect-ratio: 512 / 672; overflow: hidden; background: #0d0b10; }
.card-art img { width: 100%; height: 100%; display: block; object-fit: contain; }
.card-badge { position: absolute; top: 6px; left: 6px; padding: 3px 6px; border-radius: 4px; color: #120d08; background: var(--accent); font-size: 10px; font-weight: 700; box-shadow: 0 3px 10px rgba(0,0,0,.35); }
.card-info { min-height: 48px; padding: 7px 8px 8px; border-top: 1px solid var(--line); background: #17131b; }
.card-name { overflow: hidden; color: #f1e7da; font-size: 13px; line-height: 1.35; white-space: nowrap; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 4px; min-width: 0; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 11px; white-space: nowrap; }
.card-meta span:last-child { overflow: hidden; text-overflow: ellipsis; }
.card-tier { color: var(--gold); font-weight: 700; }
.card-dot { color: #574c5e; }
.empty { display: grid; place-items: center; margin-top: 20px; padding: 80px 16px; border: 1px dashed var(--line-strong); border-radius: 12px; text-align: center; }
.empty[hidden] { display: none; }
.empty-mark { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--gold); font: 700 20px system-ui; }
.empty h2 { margin: 14px 0 6px; font-size: 18px; }
.empty p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.primary-button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 9px; color: #1b1207; background: linear-gradient(180deg, #e7c06f, #c98d39); font-weight: 700; cursor: pointer; }

.site-foot { max-width: 1760px; margin: 0 auto; padding: 18px 24px 28px; display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); color: #625a68; font-size: 11px; }
.dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px; background: rgba(5,4,8,.82); backdrop-filter: blur(9px); }
.dialog-panel { position: relative; display: grid; grid-template-columns: minmax(210px, 320px) 1fr; gap: 26px; width: min(840px, 100%); max-height: 92vh; overflow: auto; padding: 24px; border: 1px solid var(--line-strong); border-radius: 14px; background: linear-gradient(145deg, #1d1723, #0e0c12 78%); box-shadow: 0 28px 80px rgba(0,0,0,.7); }
.dialog-panel img { width: 100%; height: auto; display: block; }
.dialog-copy { align-self: center; min-width: 0; }
.dialog-kicker { margin-bottom: 10px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.dialog-copy h2 { margin: 0 0 12px; font-size: 26px; }
.dialog-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.dialog-tags span { padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--muted); font-size: 12px; }
.dialog-text { margin: 0 0 18px; color: #ddd2c9; font-size: 14px; line-height: 1.8; white-space: pre-wrap; }
.dialog-statline { display: flex; gap: 8px; }
.dialog-statline div { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #15111a; }
.dialog-statline strong { display: block; font: 700 20px system-ui; }
.dialog-statline small { color: var(--faint); font-size: 11px; }
.dialog-close { position: absolute; top: 8px; right: 9px; width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }

@media (max-width: 1120px) {
  :root { --sidebar-w: 248px; }
  .appbar-inner { grid-template-columns: var(--sidebar-w) minmax(220px, 1fr) auto; gap: 18px; }
  .tribe-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  :root { --header-h: 116px; }
  .appbar-inner { height: auto; padding: 12px 14px; grid-template-columns: 1fr auto; gap: 12px; }
  .search { grid-column: 1 / -1; grid-row: 2; height: 44px; }
  .search kbd { display: none; }
  .library-total { grid-row: 1; grid-column: 2; }
  .shell { display: block; padding: 0 14px 44px; }
  .sidebar { position: sticky; top: var(--header-h); z-index: 20; display: block; max-height: none; overflow: visible; margin: 0 -14px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: rgba(9, 8, 12, .94); backdrop-filter: blur(16px); }
  .category-panel { padding: 0; border: 0; background: transparent; }
  .category-panel > .panel-title { display: none; }
  .category-nav { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
  .category-nav::-webkit-scrollbar { display: none; }
  .category-item { flex: 0 0 auto; width: auto; min-height: 38px; grid-template-columns: 7px auto auto; gap: 7px; padding: 0 12px; border-color: var(--line); background: var(--surface); scroll-snap-align: start; }
  .category-item.active::before { display: none; }
  .category-text small { display: none; }
  .category-text b { font-size: 13px; }
  .filter-trigger { display: inline-flex; }
  .filter-panel { position: fixed; z-index: 80; left: 0; right: 0; bottom: 0; max-height: min(78vh, 680px); overflow: auto; padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .22s ease; box-shadow: 0 -24px 60px rgba(0,0,0,.55); }
  .sheet-open .filter-panel { transform: translateY(0); }
  .sheet-backdrop { position: fixed; z-index: 70; inset: 0; background: rgba(0,0,0,.58); }
  .sheet-backdrop[hidden] { display: none; }
  .sheet-head { position: sticky; top: -8px; z-index: 1; min-height: 52px; margin: -8px -16px 12px; padding: 12px 16px 6px; background: #17131b; }
  .sheet-grabber { display: block; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; border-radius: 2px; background: #4a3e50; transform: translateX(-50%); }
  .sheet-foot { position: sticky; bottom: calc(-14px - env(safe-area-inset-bottom)); display: block; margin: 18px -16px calc(-14px - env(safe-area-inset-bottom)); padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #17131b; }
  .sheet-foot .primary-button { width: 100%; }
  .tribe-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .result-header { align-items: flex-start; flex-direction: column; min-height: 0; padding: 18px 0 14px; }
  .result-heading h1 { font-size: 23px; }
  .result-actions { width: 100%; justify-content: flex-start; }
  .select-control { margin-left: auto; }
}

@media (max-width: 560px) {
  :root { --header-h: 112px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-copy strong { font-size: 16px; }
  .brand-copy small { font-size: 10px; }
  .library-total span { display: none; }
  .search { height: 42px; }
  .result-actions { gap: 6px; }
  .filter-trigger, .segmented, .select-control { height: 36px; }
  .segmented button { min-width: 44px; font-size: 12px; }
  .select-control { padding-left: 10px; }
  .select-control span { display: none; }
  .select-control select { min-width: 74px; font-size: 12px; }
  .tier-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tribe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 7px; }
  .card-info { min-height: 42px; padding: 6px; }
  .card-name { font-size: 11px; }
  .card-meta { font-size: 9px; }
  .group-head span { font-size: 14px; }
  .dialog-panel { grid-template-columns: 1fr; gap: 14px; padding: 16px; }
  .dialog-panel img { width: min(220px, 70%); margin: 0 auto; }
  .site-foot { flex-direction: column; padding-inline: 14px; }
}

@media (max-width: 360px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segmented { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}

.type-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-bottom: 12px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #0d0b10; }
.type-tab { min-width: 0; height: 42px; display: grid; place-content: center; gap: 1px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.type-tab span { font-size: 13px; font-weight: 600; }
.type-tab b { color: var(--faint); font: 500 10px system-ui, sans-serif; }
.type-tab.active { color: #1b1207; background: linear-gradient(180deg, #e3bb69, #c98d39); }
.type-tab.active b { color: rgba(27,18,7,.7); }
.category-group + .category-group { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.category-group { display: grid; gap: 4px; }
.category-group-title { display: flex; align-items: baseline; justify-content: space-between; padding: 0 3px 4px; }
.category-group-title span { color: #ded2c5; font-size: 12px; font-weight: 700; }
.category-group-title small { color: var(--faint); font-size: 10px; }
.card.is-spell .card-art { background: radial-gradient(circle at 50% 42%, rgba(88,167,214,.12), transparent 66%), #0d0b10; }
.dialog-art { display: grid; gap: 12px; }
.dialog-art-switch { justify-self: center; }
@media (max-width: 860px) {
  .category-panel { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; }
  .type-switch { width: 174px; margin: 0; }
  .type-tab { height: 38px; }
  .type-tab b { display: none; }
  .category-nav { min-width: 0; }
  .category-group { display: contents; }
  .category-group-title { display: none; }
  .category-group + .category-group { margin: 0; padding: 0; border: 0; }
}
@media (max-width: 560px) {
  .category-panel { grid-template-columns: 1fr; }
  .type-switch { width: 100%; }
}

@media (max-width: 860px) {
  .sidebar { backdrop-filter: none; background: #0b0a0e; }
}

.filter-trigger span[hidden] { display: none; }
