:root {
  --ink: #1e2118;
  --muted: #656d59;
  --paper: #f8f3e7;
  --panel: rgba(255, 252, 244, 0.9);
  --line: #d8cdb4;
  --accent: #9b3f1f;
  --accent-2: #1f6f62;
  --gold: #c08a2e;
  --shadow: 0 18px 45px rgba(64, 48, 23, 0.16);
}

@font-face {
  font-family: "ZKingJinwen";
  src: url("./fonts/ZKing.ttf") format("truetype");
  font-display: swap;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
  background:
    radial-gradient(circle at top left, rgba(192, 138, 46, 0.28), transparent 34rem),
    radial-gradient(circle at right 20%, rgba(31, 111, 98, 0.18), transparent 28rem),
    linear-gradient(135deg, #f5ead4 0%, #fbf7ee 48%, #ebe1cc 100%);
}

.shell {
  width: min(1360px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 34px 0 44px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(28px, 5vw, 76px);
  min-height: 134px;
  margin-bottom: 26px;
}

.hero-copy {
  display: flex;
  align-items: flex-end;
  gap: clamp(16px, 2.2vw, 28px);
  min-width: 0;
}

.site-logo {
  display: block;
  width: clamp(66px, 7vw, 98px);
  max-height: 120px;
  object-fit: contain;
  opacity: 0.88;
  filter: drop-shadow(0 14px 20px rgba(58, 41, 20, 0.14)) contrast(1.24);
  flex: 0 0 auto;
}

.hero-text {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: #8f321c;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  color: #25251d;
  font-size: clamp(34px, 4.2vw, 56px);
  line-height: 1.06;
  letter-spacing: 0;
  white-space: nowrap;
  text-wrap: nowrap;
}

.byline {
  max-width: 860px;
  margin: -2px 0 8px;
  color: #5a5447;
  font-size: clamp(13px, 1vw, 15px);
  line-height: 1.55;
}

.subtitle {
  max-width: 760px;
  margin-bottom: 0;
  color: #4b4b3f;
  font-size: clamp(15px, 1.25vw, 18px);
  line-height: 1.45;
}

.brand-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(18px, 2.8vw, 34px);
  min-width: 360px;
}

.brand-logo {
  display: block;
  width: clamp(96px, 8vw, 136px);
  max-width: 100%;
  height: auto;
  opacity: 0.72;
  filter: drop-shadow(0 10px 18px rgba(58, 41, 20, 0.18)) contrast(1.2);
  pointer-events: none;
}

.stats {
  min-width: 260px;
  padding: 17px 28px;
  border: 1px solid rgba(190, 158, 104, 0.48);
  border-radius: 20px;
  background: rgba(255, 252, 245, 0.68);
  box-shadow: 0 18px 42px rgba(88, 62, 24, 0.1);
  color: var(--accent-2);
  font-size: clamp(18px, 1.45vw, 22px);
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.search-panel,
.results-card,
.detail-card {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.search-panel {
  padding: 22px;
  margin-bottom: 22px;
}

.search-panel > label {
  display: block;
  margin-bottom: 10px;
  color: var(--accent);
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.scope-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px 14px;
  margin: 16px 0 0;
  padding: 15px 16px 14px;
  border: 1px solid #d8c6a6;
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.72);
}

.scope-panel legend {
  padding: 0 8px;
  color: var(--accent);
  font-weight: 700;
}

.scope-panel label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.scope-panel input {
  width: auto;
  padding: 0;
  accent-color: var(--accent-2);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid #cdbf9f;
  border-radius: 16px;
  background: #fffaf0;
  color: var(--ink);
  outline: none;
}

input {
  padding: 17px 18px;
  font-size: 19px;
}

select {
  padding: 11px 12px;
  font-family: "ZKingJinwen", "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
}

input:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(31, 111, 98, 0.12);
}

button {
  border: 0;
  border-radius: 16px;
  padding: 0 20px;
  background: var(--ink);
  color: #fff9ef;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.filters label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.search-notice {
  margin-top: 16px;
  padding: 14px 16px 0;
  border-top: 1px dashed rgba(155, 63, 31, 0.24);
  color: #5c564b;
  font-size: 14px;
  line-height: 1.65;
}

.search-notice p {
  margin: 0;
}

.search-notice p + p {
  margin-top: 6px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.78fr) minmax(480px, 1.22fr);
  gap: 22px;
  align-items: start;
}

.results-card,
.detail-card {
  min-height: 540px;
  overflow: hidden;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.card-heading h2 {
  margin: 0;
  font-size: 20px;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.ghost-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(31, 111, 98, 0.22);
  background: rgba(31, 111, 98, 0.08);
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.ghost-button:hover:not(:disabled) {
  background: var(--accent-2);
  color: #fff9ef;
}

#resultSummary {
  color: var(--muted);
  font-size: 14px;
}

.results {
  max-height: 620px;
  overflow: auto;
  padding: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid rgba(216, 205, 180, 0.75);
  background: rgba(255, 250, 240, 0.62);
}

.page-numbers {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.page-button {
  min-width: 40px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(155, 63, 31, 0.22);
  border-radius: 13px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.page-button:hover:not(:disabled),
.page-button.active {
  border-color: rgba(155, 63, 31, 0.42);
  background: var(--accent);
  color: #fff9ef;
}

.page-button:disabled {
  background: rgba(255, 250, 240, 0.55);
  color: var(--muted);
}

.page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  color: var(--muted);
  font-weight: 800;
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.page-jump input {
  width: 76px;
  padding: 8px 9px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
}

.result-item {
  width: 100%;
  display: block;
  margin: 0 0 8px;
  padding: 14px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.result-item:hover,
.result-item.active {
  border-color: rgba(155, 63, 31, 0.35);
  background: #fff5df;
}

.result-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 17px;
  font-weight: 800;
}

.jinwen-text {
  font-family: "ZKingJinwen", "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
}

.result-title span:last-child {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.result-meta {
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.result-snippet {
  display: block;
  margin-top: 8px;
  color: #4c493f;
  font-family: "ZKingJinwen", "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
  font-size: 13px;
  line-height: 1.55;
}

.detail {
  padding: 22px;
}

.detail.empty {
  color: var(--muted);
  line-height: 1.8;
}

.detail-title {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--line);
}

.detail-title h3 {
  margin: 0 0 8px;
  font-size: 30px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(31, 111, 98, 0.12);
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
}

.detail-section {
  margin-top: 18px;
}

.detail-section h4 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 16px;
  letter-spacing: 0.04em;
}

.fields {
  display: grid;
  gap: 13px;
}

.field {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(216, 205, 180, 0.72);
}

.field dt {
  color: var(--accent);
  font-weight: 800;
}

.field dd {
  margin: 0;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}

.readable-field {
  padding: 14px;
  border: 1px solid rgba(31, 111, 98, 0.16);
  border-radius: 18px;
  background: rgba(31, 111, 98, 0.06);
}

.readable-field dd {
  font-family: "ZKingJinwen", "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
}

.readable-field dt {
  font-family: "Microsoft YaHei", "Noto Serif SC", "Songti SC", serif;
}

.mingtu-section {
  padding: 14px;
  border: 1px solid rgba(155, 63, 31, 0.18);
  border-radius: 20px;
  background: rgba(255, 245, 223, 0.72);
}

.mingtu-gallery {
  display: grid;
  gap: 14px;
}

.mingtu-card {
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(216, 205, 180, 0.88);
  border-radius: 18px;
  background: #fffdfa;
}

.mingtu-card a {
  position: relative;
  display: block;
  background: #f3ead8;
  cursor: zoom-in;
}

.mingtu-card a::after {
  content: "點擊放大";
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  background: rgba(38, 35, 26, 0.72);
  color: #fffaf0;
  font-size: 12px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.mingtu-card a:hover::after {
  opacity: 1;
  transform: translateY(0);
}

.mingtu-card img {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
}

.mingtu-card figcaption {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  word-break: break-all;
}

.image-hint {
  color: var(--accent);
  font-weight: 700;
}

.viewer-open {
  overflow: hidden;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  color: #fff8e8;
}

.image-viewer.is-open {
  display: block;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 18, 0.78);
  backdrop-filter: blur(6px);
}

.image-viewer-panel {
  position: absolute;
  inset: 22px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(230, 213, 177, 0.42);
  border-radius: 26px;
  background: linear-gradient(135deg, rgba(39, 35, 25, 0.96), rgba(18, 17, 13, 0.95));
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.38);
}

.image-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(230, 213, 177, 0.24);
}

.image-viewer-title {
  min-width: 0;
  overflow: hidden;
  color: #fff3cf;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-viewer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.image-viewer-actions button,
.image-viewer-original {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(230, 213, 177, 0.36);
  border-radius: 999px;
  background: rgba(255, 250, 238, 0.1);
  color: #fff8e8;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.image-viewer-actions button:hover,
.image-viewer-original:hover {
  background: rgba(255, 250, 238, 0.18);
}

.image-viewer-scale {
  min-width: 54px;
  color: #dac99d;
  font-weight: 700;
  text-align: center;
}

.image-viewer-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  background:
    radial-gradient(circle at center, rgba(255, 249, 234, 0.08), transparent 45%),
    #15130f;
  cursor: grab;
  touch-action: none;
}

.image-viewer-stage.is-dragging {
  cursor: grabbing;
}

.image-viewer-img {
  display: block;
  max-width: 94%;
  max-height: 94%;
  object-fit: contain;
  transform-origin: center center;
  transition: opacity 0.18s ease, transform 0.08s ease-out;
  user-select: none;
  will-change: transform;
}

.image-viewer-img.is-loading {
  opacity: 0.42;
}

.image-viewer-help {
  padding: 10px 16px;
  border-top: 1px solid rgba(230, 213, 177, 0.18);
  color: rgba(255, 248, 232, 0.68);
  font-size: 12px;
  text-align: center;
}

.notice {
  padding: 22px;
  color: var(--muted);
  line-height: 1.8;
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 24px, 760px);
    padding-top: 20px;
  }

  .hero,
  .content-grid,
  .search-row,
  .filters {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero {
    min-height: 0;
    gap: 18px;
  }

  .hero-copy {
    align-items: flex-end;
  }

  .site-logo {
    width: clamp(62px, 13vw, 86px);
    max-height: 104px;
  }

  .stats {
    min-width: 0;
    text-align: left;
  }

  .brand-panel {
    justify-content: space-between;
    min-width: 0;
  }

  .brand-logo {
    width: min(118px, 26vw);
  }

  .field {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .card-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .result-actions {
    width: 100%;
    justify-content: space-between;
  }

  .pagination {
    flex-wrap: wrap;
  }

  .page-numbers {
    order: 3;
    flex-basis: 100%;
  }

  .page-jump {
    order: 4;
    flex-basis: 100%;
    justify-content: center;
  }
}

@media (max-width: 560px) {
  body {
    background:
      radial-gradient(circle at top left, rgba(192, 138, 46, 0.2), transparent 22rem),
      linear-gradient(135deg, #f7ecd7 0%, #fbf7ee 58%, #eee2ca 100%);
  }

  .shell {
    width: calc(100vw - 18px);
    padding: 14px 0 28px;
  }

  .hero {
    gap: 12px;
    margin-bottom: 14px;
  }

  .hero-copy {
    align-items: flex-end;
    gap: 12px;
  }

  .site-logo {
    width: 48px;
    max-height: 72px;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 11px;
  }

  h1 {
    margin-bottom: 0;
    font-size: clamp(22px, 7.2vw, 34px);
    line-height: 1.08;
    letter-spacing: 0;
    white-space: nowrap;
    text-wrap: nowrap;
  }

  .stats {
    min-width: 0;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
  }

  .brand-panel {
    gap: 10px;
  }

  .brand-logo {
    width: min(86px, 24vw);
    opacity: 0.68;
  }

  .search-panel,
  .results-card,
  .detail-card {
    border-radius: 18px;
  }

  .search-panel {
    padding: 14px;
    margin-bottom: 14px;
  }

  input {
    padding: 14px 15px;
    font-size: 16px;
  }

  button {
    min-height: 44px;
    padding: 0 16px;
  }

  .scope-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    border-radius: 15px;
    font-size: 14px;
  }

  .scope-panel label {
    white-space: normal;
  }

  .filters {
    gap: 10px;
    margin-top: 12px;
  }

  .card-heading {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 14px;
  }

  .results-card,
  .detail-card {
    min-height: 0;
  }

  .results {
    max-height: none;
    padding: 7px;
  }

  .result-item {
    padding: 12px;
    border-radius: 15px;
  }

  .result-title {
    gap: 8px;
    font-size: 16px;
  }

  .result-meta,
  .result-snippet {
    font-size: 13px;
  }

  .detail-body {
    padding: 14px;
  }

  .detail-title {
    gap: 8px;
  }

  .detail-title h2 {
    font-size: 24px;
  }

  .image-viewer-panel {
    inset: 8px;
    border-radius: 18px;
  }

  .image-viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .image-viewer-title {
    width: 100%;
  }

  .image-viewer-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .image-viewer-actions button,
  .image-viewer-original {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .image-viewer-help {
    padding: 8px 10px;
  }

  .section-block {
    padding: 14px;
    border-radius: 16px;
  }
}

@media (max-width: 380px) {
  .scope-panel {
    grid-template-columns: 1fr;
  }
}
