:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #23211d;
  --muted: #726b5f;
  --line: #ddd7ca;
  --accent: #1f7a68;
  --accent-ink: #ffffff;
  --warn: #a55322;
  --shadow: 0 18px 48px rgba(42, 35, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px) 20px;
  background: #fffaf0;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.1;
  letter-spacing: 0;
}

.header-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  gap: 10px;
  min-width: 220px;
}

.header-metrics div {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.header-metrics span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.header-metrics small {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 22px;
  padding: 22px clamp(14px, 3vw, 36px) 36px;
}

.filters {
  position: sticky;
  top: 16px;
  align-self: start;
  display: grid;
  gap: 14px;
}

.filter-section,
.stat-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(42, 35, 22, 0.06);
}

.filter-section {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.section-title,
.stat-title {
  color: #4f4638;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
}

label span,
.sorter span {
  color: var(--muted);
  font-size: 13px;
}

select,
input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  background: #fffdf8;
  border: 1px solid #cfc7b8;
  border-radius: 7px;
  color: var(--ink);
}

select:focus,
input:focus,
button:focus-visible {
  outline: 3px solid rgba(31, 122, 104, 0.2);
  border-color: var(--accent);
}

.filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 700;
}

button:first-child {
  background: #fffdf8;
  color: var(--accent);
}

button:hover {
  filter: brightness(0.97);
}

.content {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.summary-row {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(280px, 1fr);
  gap: 14px;
}

.stat-panel {
  padding: 16px;
  min-height: 132px;
}

.stat-bars {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 54px minmax(80px, 1fr) 48px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  background: #ece5d9;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  width: var(--w);
  background: var(--accent);
}

.score-tags,
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.score-tags {
  margin-top: 13px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  background: #eef7f4;
  color: #195e51;
  border: 1px solid #c9e3dc;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.sorter {
  display: grid;
  grid-template-columns: auto 150px;
  align-items: center;
  gap: 8px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 16px;
}

.card {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(42, 35, 22, 0.08);
}

.card-image {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: block;
  object-fit: cover;
  background: #ebe4d8;
  cursor: zoom-in;
}

.card-body {
  display: grid;
  gap: 10px;
  padding: 13px;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hexagram {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
}

.result-pill {
  flex: none;
  min-width: 64px;
  padding: 6px 8px;
  text-align: center;
  border-radius: 7px;
  background: #fff0e4;
  color: var(--warn);
  font-weight: 900;
}

.match {
  font-weight: 800;
  line-height: 1.35;
}

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

.meta-item {
  min-width: 0;
  padding: 8px;
  background: #faf7f0;
  border: 1px solid #eee6da;
  border-radius: 7px;
}

.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.meta-value {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-weight: 700;
}

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

.element-line span {
  padding: 4px 7px;
  background: #f2f7ee;
  border: 1px solid #d6e7cf;
  border-radius: 999px;
  color: #496d38;
  font-size: 12px;
}

.empty-state {
  padding: 42px 18px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.load-more {
  justify-self: center;
  min-width: 180px;
  padding: 0 22px;
}

dialog {
  max-width: min(960px, 94vw);
  max-height: 94vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #111;
  color: white;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

#dialogImage {
  display: block;
  max-width: 94vw;
  max-height: 82vh;
  object-fit: contain;
}

.dialog-caption {
  padding: 10px 14px 14px;
  font-size: 14px;
}

.dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  min-height: 36px;
  border-color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

@media (max-width: 980px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }

  .filter-actions {
    align-self: end;
  }
}

@media (max-width: 720px) {
  .header-metrics,
  .summary-row,
  .filters {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .sorter {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}
