:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --surface-strong: #fffaf0;
  --line: #d8c7ae;
  --text: #2f2418;
  --muted: #73614c;
  --accent: #a94f2d;
  --accent-soft: #f3d9c8;
  --shadow: 0 18px 40px rgba(58, 39, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #fff7e5 0, transparent 28%),
    linear-gradient(180deg, #f7f1e8 0%, #efe5d5 100%);
}

.app {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  margin-bottom: 24px;
}

.page-links {
  margin-top: 18px;
}

.page-link {
  display: inline-flex;
  align-items: center;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  border: 1px solid rgba(169, 79, 45, 0.18);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.subtitle {
  margin: 12px 0 0;
  color: var(--muted);
  max-width: 640px;
}

.search-panel,
.results-card,
.preview-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 20px;
  margin-bottom: 24px;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 12px;
}

input,
button,
.gallery-select {
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
}

input {
  padding: 14px 16px;
  background: #fff;
}

.gallery-select {
  padding: 14px 16px;
  background: #fff;
}

button {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.status {
  margin: 12px 0 0;
  color: var(--muted);
}

.results-layout {
  display: grid;
  grid-template-columns: minmax(320px, 430px) 1fr;
  gap: 24px;
}

.results-card,
.preview-card {
  padding: 20px;
  min-height: 560px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.results-list {
  display: grid;
  gap: 12px;
  max-height: 680px;
  overflow: auto;
  padding-right: 4px;
}

.result-item {
  width: 100%;
  text-align: left;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 14px;
}

.result-item.active {
  border-color: var(--accent);
  background: #fff1e7;
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.result-meta {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.45;
}

.preview-empty {
  display: grid;
  place-items: center;
  min-height: 460px;
  border-radius: 18px;
  background: var(--surface-strong);
  color: var(--muted);
  border: 1px dashed var(--line);
}

.preview-panel.hidden {
  display: none;
}

.preview-panel {
  display: grid;
  gap: 16px;
}

#previewImage {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: 18px;
  background: #f7f1e6;
  border: 1px solid var(--line);
}

.preview-meta {
  display: grid;
  gap: 8px;
}

.preview-meta p {
  margin: 0;
  line-height: 1.45;
}

.gallery-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.gallery-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 240px 140px;
  gap: 14px;
  align-items: end;
}

.gallery-field {
  min-width: 0;
}

.gallery-field-small {
  max-width: 240px;
}

.gallery-actions {
  display: flex;
  align-items: end;
}

.gallery-actions button {
  width: 100%;
  min-height: 52px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.gallery-card {
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: 0 10px 24px rgba(58, 39, 24, 0.08);
}

.gallery-image {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #f2eadb;
}

.zoomable-image {
  cursor: zoom-in;
}

.gallery-card-body {
  padding: 14px;
}

.gallery-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.gallery-card-title {
  font-size: 1.05rem;
  font-weight: 800;
  word-break: break-word;
}

.gallery-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.gallery-meta {
  display: grid;
  gap: 6px;
}

.gallery-meta p {
  margin: 0;
  line-height: 1.45;
  font-size: 0.94rem;
}

.gallery-edit-wrap {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.gallery-edit-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--muted);
}

.gallery-edit-row {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.gallery-edit-input {
  width: 100%;
}

.gallery-save-button {
  min-height: 52px;
}

.gallery-save-status {
  margin-top: 8px;
  min-height: 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(23, 16, 10, 0.82);
  z-index: 9999;
}

.lightbox-overlay.open {
  display: flex;
}

.lightbox-content {
  position: relative;
  width: min(1100px, 100%);
  max-height: 100%;
}

.lightbox-image {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  object-fit: contain;
  border-radius: 18px;
  background: #f7f1e6;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: none;
  background: rgba(23, 16, 10, 0.72);
  color: #fff;
  font-size: 1.7rem;
  line-height: 1;
  z-index: 1;
}

@media (max-width: 900px) {
  .results-layout {
    grid-template-columns: 1fr;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .gallery-toolbar {
    grid-template-columns: 1fr;
  }

  .gallery-field-small {
    max-width: none;
  }

  .gallery-edit-row {
    grid-template-columns: 1fr;
  }
}
