:root {
  --bg: #e9e7e2;
  --ink: #1a1816;
  --muted: #5c574f;
  --faint: #8a847a;
  --accent: #1f5c57;
  --accent-hover: #267670;
  --accent-dim: rgba(31, 92, 87, 0.12);
  --warm: #a67c52;
  --surface: #f3f1ec;
  --surface-2: #faf9f6;
  --line: rgba(26, 24, 22, 0.12);
  --danger: #b54a4a;
  --danger-dim: rgba(181, 74, 74, 0.1);
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(26, 24, 22, 0.08);
  --font-display: "Fraunces", "Noto Serif TC", serif;
  --font-body: "Noto Sans TC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 8% -10%, rgba(31, 92, 87, 0.12), transparent 60%),
    radial-gradient(700px 420px at 100% 0%, rgba(166, 124, 82, 0.14), transparent 55%),
    var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.top,
.shell {
  position: relative;
  z-index: 1;
}

.top {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.back-link {
  display: inline-block;
  font-size: 0.82rem;
  color: var(--faint);
  text-decoration: none;
  margin-bottom: 0.35rem;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--accent);
}

.page-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-lede {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.15rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--ink);
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(181, 74, 74, 0.25);
}

.btn-danger:hover {
  background: rgba(181, 74, 74, 0.18);
}

.btn-icon {
  font-family: inherit;
  font-size: 1.1rem;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--ink);
}

.status-bar {
  margin-bottom: 1rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(181, 74, 74, 0.2);
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 4rem 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-icon {
  font-size: 2.5rem;
  color: var(--faint);
  margin-bottom: 0.75rem;
}

.empty-state h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.empty-state p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.cell-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.cell-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}

.cell-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 36px rgba(26, 24, 22, 0.12);
  border-color: rgba(31, 92, 87, 0.25);
}

.cell-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell-cover {
  aspect-ratio: 4 / 3;
  background: var(--surface);
  overflow: hidden;
  position: relative;
}

.cell-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cell-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--faint);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(31, 92, 87, 0.06) 100%);
}

.cell-badge {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(26, 24, 22, 0.65);
  color: #fff;
}

.cell-body {
  padding: 0.85rem 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cell-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cell-title.is-empty {
  color: var(--faint);
  font-style: italic;
  font-weight: 500;
}

.cell-excerpt {
  font-size: 0.82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cell-meta {
  font-size: 0.72rem;
  color: var(--faint);
  margin-top: auto;
  padding-top: 0.35rem;
}

/* Dialog */
.cell-dialog {
  border: none;
  padding: 0;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: calc(100% - 1.5rem);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 24px 64px rgba(26, 24, 22, 0.2);
  margin: auto;
  position: fixed;
  inset: 0;
  height: fit-content;
  max-height: min(90vh, 720px);
  overflow: hidden;
}

.cell-dialog[open] {
  display: flex;
  flex-direction: column;
}

.cell-dialog::backdrop {
  background: rgba(26, 24, 22, 0.45);
  backdrop-filter: blur(4px);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-height: min(90vh, 720px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.15rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}

.dialog-body {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dialog-body > * {
  flex-shrink: 0;
}

.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.15rem 1rem;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.dialog-foot-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}

.input,
.textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.textarea {
  resize: vertical;
  min-height: 120px;
}

.xhs-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  flex-shrink: 0;
  width: 100%;
}

.xhs-panel[open] {
  border-color: rgba(255, 36, 66, 0.22);
  background: linear-gradient(180deg, rgba(255, 36, 66, 0.04) 0%, var(--surface) 100%);
}

.xhs-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  line-height: 1.4;
}

.xhs-summary::-webkit-details-marker {
  display: none;
}

.xhs-summary-main {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.xhs-chevron {
  font-size: 0.85rem;
  color: var(--faint);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.xhs-panel[open] .xhs-chevron {
  transform: rotate(90deg);
}

.xhs-summary-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.xhs-panel[open] .xhs-summary-label {
  color: #c41e3a;
}

.meta-pill.has-content {
  color: #c41e3a;
  background: rgba(255, 36, 66, 0.1);
  flex-shrink: 0;
}

.xhs-body {
  padding: 0 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.xhs-textarea {
  width: 100%;
  min-height: 160px;
  font-size: 0.9rem;
  line-height: 1.65;
  resize: vertical;
}

.xhs-hint {
  font-size: 0.75rem;
  color: var(--faint);
}

.cell-xhs-tag {
  align-self: flex-start;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  color: #c41e3a;
  background: rgba(255, 36, 66, 0.1);
  border: 1px solid rgba(255, 36, 66, 0.18);
}

.images-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.images-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dropzone-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.dropzone-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.5rem;
}

.image-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-thumb.is-uploading {
  opacity: 0.55;
}

.image-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 1.5rem;
  height: 1.5rem;
  border: none;
  border-radius: 50%;
  background: rgba(26, 24, 22, 0.7);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.image-thumb:hover .image-remove,
.image-remove:focus-visible {
  opacity: 1;
}

.upload-status {
  font-size: 0.82rem;
  color: var(--muted);
}

.upload-status.is-error {
  color: var(--danger);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}

.toast.is-error {
  background: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (max-width: 600px) {
  .top {
    flex-direction: column;
    align-items: stretch;
  }

  .top .btn-primary {
    width: 100%;
    text-align: center;
  }

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

  .dialog-foot-right {
    width: 100%;
    margin-left: 0;
  }

  .dialog-foot-right .btn {
    flex: 1;
  }
}
