:root {
  color-scheme: light;
  --ink: #252525;
  --muted: #74716d;
  --line: #ded9d1;
  --surface: #ffffff;
  --canvas: #f4f1eb;
  --accent: #d85f3d;
  --accent-dark: #a93f28;
  --accent-soft: #f6ded5;
  --olive: #6e7960;
  --shadow: 0 10px 28px rgba(45, 39, 31, 0.08);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }

.app-shell { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-actions { display: flex; align-items: center; justify-content: end; gap: 8px; }
.admin-toggle.is-active { color: #fff; background: var(--olive); border-color: var(--olive); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  font-size: 25px;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.3;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(20px, 5vw, 26px); line-height: 1.15; }
h2 { margin-bottom: 0; font-size: clamp(25px, 7vw, 34px); line-height: 1.15; }
h3 { margin-bottom: 0; font-size: 17px; line-height: 1.3; }

.main-content { width: min(1120px, 100%); margin: 0 auto; padding: 32px 20px 64px; }
.section-heading, .photo-section-heading, .album-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}
.section-heading { margin-bottom: 22px; }
.count-label { color: var(--muted); font-size: 13px; white-space: nowrap; }

.button, .text-button, .icon-button, .viewer-button {
  border: 0;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.button:active, .text-button:active, .icon-button:active, .viewer-button:active { transform: translateY(1px); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.button-secondary:hover { background: #ece7df; }

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.album-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.album-card:hover { border-color: var(--accent); }
.album-open { display: block; width: 100%; padding: 0; text-align: left; color: inherit; background: transparent; border: 0; }
.card-delete-button, .photo-delete-button {
  color: #b43d2d;
  background: #fff4f0;
  border: 0;
  font-size: 12px;
  font-weight: 700;
}
.card-delete-button { min-height: 36px; border-top: 1px solid #f0d6ce; }
.card-delete-button:hover, .photo-delete-button:hover { background: #f9dfd8; }
.album-cover {
  position: relative;
  aspect-ratio: 1.15;
  overflow: hidden;
  background: #e8e3db;
}
.album-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.album-cover-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #978e82;
  font-size: 34px;
}
.album-card-copy { padding: 12px 13px 14px; }
.album-card-title {
  overflow: hidden;
  margin-bottom: 5px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.album-card-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }

.empty-state, .loading-state { text-align: center; }
.empty-state {
  padding: 64px 18px;
  color: var(--muted);
}
.empty-state.compact { padding: 48px 18px; }
.empty-state h3 { margin: 10px 0 7px; color: var(--ink); }
.empty-state p { margin-bottom: 18px; font-size: 14px; }
.empty-icon { color: var(--accent); font-size: 34px; }
.loading-state { padding: 38px 0; color: var(--muted); font-size: 14px; }

[hidden] { display: none !important; }
.detail-toolbar { margin-bottom: 28px; }
.text-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 5px 0;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
}
.text-button:hover { color: var(--accent-dark); }
.album-heading { align-items: end; margin-bottom: 22px; }
.album-heading .button-danger { flex: 0 0 auto; }
.album-meta { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.button-danger { color: #b43d2d; background: #fff4f0; border: 1px solid #efc8bd; }
.button-danger:hover { background: #f9dfd8; }

.upload-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: center;
  margin-bottom: 34px;
  padding: 14px 18px;
  background: #fffaf4;
  border: 1px solid #e6d8ca;
  border-radius: 8px;
}
.upload-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.upload-collapse-toggle { width: 36px; height: 36px; font-size: 24px; }
.upload-panel.is-collapsed { margin-bottom: 22px; }
#upload-fields { padding-top: 16px; }
.pending-photo-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 12px;
}
.pending-photo-item { position: relative; min-width: 0; overflow: hidden; background: #e8e3db; border-radius: 4px; }
.pending-photo-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.pending-photo-index { position: absolute; top: 4px; left: 4px; display: grid; place-items: center; width: 20px; height: 20px; color: #fff; background: rgba(37, 37, 37, 0.72); border-radius: 50%; font-size: 11px; font-weight: 700; }
.pending-photo-name { overflow: hidden; margin: 0; padding: 5px 5px 6px; color: var(--muted); background: #fff; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.upload-copy p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.upload-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 24px;
  font-weight: 700;
}
.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  color: var(--accent-dark);
  background: #fff;
  border: 1px solid #d9b5a8;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.file-picker:hover { background: var(--accent-soft); }
.file-picker input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.selected-files { grid-column: 1 / -1; color: var(--muted); font-size: 13px; line-height: 1.5; }
.upload-actions { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 12px; }
.status-text { min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; }
.status-text.is-error, .form-error { color: #b43d2d; }

.photo-section-heading { margin-bottom: 14px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
.photo-tile { position: relative; aspect-ratio: 1; overflow: hidden; background: #e8e3db; border-radius: 3px; }
.photo-open { display: block; width: 100%; height: 100%; padding: 0; overflow: hidden; background: transparent; border: 0; }
.photo-tile img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 180ms ease; }
.photo-tile:hover img { transform: scale(1.04); }
.photo-delete-button { position: absolute; top: 5px; right: 5px; z-index: 2; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-size: 20px; line-height: 1; }

.dialog {
  width: min(440px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}
.dialog::backdrop { background: rgba(27, 24, 20, 0.52); }
.dialog-panel, .photo-dialog-panel {
  padding: 22px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 55px rgba(20, 18, 15, 0.2);
}
.dialog-heading, .photo-dialog-toolbar { display: flex; align-items: start; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  font-size: 28px;
  line-height: 1;
}
.icon-button:hover { color: var(--ink); background: #f0ece5; }
.field-label { display: grid; gap: 7px; margin-bottom: 16px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field-label input {
  width: 100%;
  min-height: 45px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
}
.field-label input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { min-height: 20px; margin: 2px 0 14px; font-size: 13px; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; }

.photo-dialog { width: min(900px, calc(100% - 20px)); }
.photo-dialog-panel { padding: 14px; }
.photo-dialog-toolbar { align-items: center; margin: 0 0 10px; }
.photo-dialog-name { max-width: calc(100% - 50px); margin: 0; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.photo-viewer {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(60dvh, 620px);
  background: #1d1c1a;
  border-radius: 5px;
}
.photo-viewer img { display: block; max-width: 100%; max-height: min(68dvh, 700px); object-fit: contain; }
.viewer-loading, .viewer-error { position: absolute; inset: 0; display: grid; place-items: center; color: #d7d1c9; font-size: 14px; }
.viewer-error { color: #f0a18e; }
.viewer-actions { display: flex; align-items: center; gap: 8px; }
.download-photo[aria-disabled="true"] { opacity: 0.48; pointer-events: none; }
.viewer-button {
  position: absolute;
  top: 50%;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 42px;
  height: 54px;
  color: #fff;
  background: rgba(0, 0, 0, 0.42);
  border-radius: 4px;
  font-size: 37px;
  line-height: 1;
  transform: translateY(-50%);
}
.viewer-button:hover { background: rgba(0, 0, 0, 0.7); }
.viewer-prev { left: 8px; }
.viewer-next { right: 8px; }
.photo-dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 12px; }
.viewer-counter { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  z-index: 10;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 10px 14px;
  color: #fff;
  background: #292622;
  border-radius: 5px;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (min-width: 680px) {
  .main-content { padding-top: 50px; }
  .album-grid { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 18px; }
  .photo-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
}

@media (max-width: 560px) {
  .topbar { align-items: flex-start; flex-direction: column; padding-right: 14px; padding-left: 14px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1; }
  .main-content { padding: 28px 14px 48px; }
  .button { min-height: 42px; padding-right: 12px; padding-left: 12px; }
  .pending-photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .album-heading { align-items: flex-start; flex-direction: column; }
  .album-heading .button-danger { width: 100%; }
  .file-picker { width: 100%; }
  .upload-actions { align-items: stretch; flex-direction: column; }
  .upload-actions .button { width: 100%; }
  .photo-viewer { min-height: 52dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
