:root {
  color-scheme: dark;
  --bg: #101112;
  --panel: #181a1c;
  --panel-2: #202326;
  --panel-3: #292b2d;
  --text: #f3ead9;
  --muted: #b8ae9d;
  --quiet: #82796d;
  --line: #3b3d3d;
  --gold: #d1a24a;
  --red: #bd5044;
  --teal: #3f9d92;
  --green: #73a862;
  --violet: #8f75a8;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 18px;
  align-items: center;
  padding: 14px 18px;
  background: rgba(16, 17, 18, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.brand-meta {
  margin-top: 4px;
  color: var(--quiet);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.search-wrap {
  position: relative;
  flex: 1 1 420px;
  min-width: 220px;
  max-width: 620px;
}

.search-mark {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--quiet);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 34px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

#search-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(209, 162, 74, 0.16);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  min-width: 68px;
  height: 32px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
}

.segmented button.active {
  color: #17130c;
  background: var(--gold);
}

.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: nowrap;
}

.switch-control input {
  accent-color: var(--gold);
}

.layout {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
  padding: 16px 18px 24px;
}

.filters,
.detail-panel {
  position: sticky;
  top: 84px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filters {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.filters select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats-block div {
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-block span {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: var(--gold);
}

.stats-block small {
  color: var(--quiet);
}

.reset-button {
  height: 38px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reset-button:hover {
  border-color: var(--red);
  color: #ffd9d4;
}

.cards-panel {
  min-width: 0;
}

.result-bar {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 10px;
  color: var(--muted);
}

#result-summary {
  font-weight: 700;
  color: var(--text);
}

#data-stamp {
  text-align: right;
  font-size: 12px;
  color: var(--quiet);
  overflow-wrap: anywhere;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(214px, 1fr));
  gap: 12px;
}

.card-item {
  position: relative;
  min-height: 348px;
  display: grid;
  grid-template-rows: 188px auto 1fr;
  overflow: hidden;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
}

.card-item:hover,
.card-item.selected {
  border-color: var(--gold);
}

.card-item.selected {
  box-shadow: 0 0 0 2px rgba(209, 162, 74, 0.26), var(--shadow);
}

.pool-stripe {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--gold);
}

.pool-ironclad .pool-stripe { background: var(--red); }
.pool-silent .pool-stripe { background: var(--green); }
.pool-defect .pool-stripe { background: #4d94c6; }
.pool-necrobinder .pool-stripe { background: var(--violet); }
.pool-regent .pool-stripe { background: var(--teal); }
.pool-colorless .pool-stripe { background: #d6d1c4; }
.pool-curse .pool-stripe { background: #7a5a91; }
.pool-status .pool-stripe { background: #858585; }
.pool-event .pool-stripe { background: #c27b52; }
.pool-quest .pool-stripe { background: #d5b151; }
.pool-token .pool-stripe { background: #89a96b; }

.portrait-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 188px;
  background: var(--panel-3);
  border-bottom: 1px solid var(--line);
}

.portrait-shell img {
  height: 178px;
  width: auto;
  max-width: 100%;
  aspect-ratio: 250 / 351;
  object-fit: contain;
  display: block;
}

.portrait-placeholder {
  width: 126px;
  aspect-ratio: 250 / 351;
  display: grid;
  place-items: center;
  color: var(--quiet);
  border: 1px dashed #56514a;
  border-radius: 6px;
  font-weight: 800;
}

.cost-badge {
  position: absolute;
  top: 8px;
  left: 12px;
  min-width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  color: #18130b;
  background: var(--gold);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  font-weight: 900;
}

.card-main {
  display: grid;
  gap: 8px;
  padding: 11px 12px 8px 16px;
}

.card-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  min-width: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card-id {
  color: var(--quiet);
  font-size: 11px;
  white-space: nowrap;
}

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

.chip {
  max-width: 100%;
  padding: 3px 7px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.card-description {
  padding: 0 12px 14px 16px;
  color: #ddd2bf;
  line-height: 1.45;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.detail-panel {
  min-height: calc(100vh - 108px);
  max-height: calc(100vh - 108px);
  overflow: auto;
}

.detail-empty {
  padding: 18px;
  color: var(--quiet);
}

.detail-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.detail-hero img,
.detail-hero .portrait-placeholder {
  width: 132px;
  height: auto;
  aspect-ratio: 250 / 351;
  object-fit: contain;
}

.detail-title {
  font-size: 22px;
  line-height: 1.22;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.detail-subtitle {
  margin-top: 5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.detail-costs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.detail-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.detail-section h2 {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 14px;
}

.detail-text {
  margin: 0;
  color: #e3d8c7;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.kv-list {
  display: grid;
  gap: 8px;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(86px, 1fr) auto;
  gap: 12px;
  color: var(--muted);
}

.kv-row strong {
  color: var(--text);
  font-weight: 700;
  text-align: right;
}

.empty-results {
  padding: 40px 16px;
  color: var(--quiet);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

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

  .detail-panel {
    position: static;
    grid-column: 1 / -1;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .search-wrap {
    flex-basis: 100%;
    max-width: none;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .filters {
    position: static;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .card-item {
    min-height: 332px;
    grid-template-rows: 168px auto 1fr;
  }

  .portrait-shell {
    min-height: 168px;
  }

  .portrait-shell img {
    height: 158px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 12px;
  }

  .segmented,
  .switch-control {
    flex: 1 1 auto;
  }

  .segmented button {
    min-width: 0;
  }

  .detail-hero {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .detail-hero img,
  .detail-hero .portrait-placeholder {
    width: 96px;
  }
}
