:root {
  color-scheme: light;
  --bg: #fff8f2;
  --panel: rgba(255, 253, 250, 0.94);
  --panel-hover: #fff3ee;
  --border: #e9c9ca;
  --text: #5b4147;
  --muted: #9a7479;
  --accent: #d9788e;
  --accent-soft: #f9dbe1;
  --mint: #bcd9c4;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12px 12px, rgba(231, 168, 180, 0.2) 0 2px, transparent 2.5px),
    radial-gradient(circle at 36px 36px, rgba(174, 207, 184, 0.18) 0 2px, transparent 2.5px),
    linear-gradient(135deg, rgba(255, 236, 226, 0.72), transparent 42%);
  background-size: 48px 48px, 48px 48px, 100% 100%;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header,
.gallery-app {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
}

.app-header {
  position: relative;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
}

.app-header::after {
  position: absolute;
  right: 190px;
  bottom: -11px;
  padding: 0 8px;
  color: #d99aaa;
  background: var(--bg);
  content: "✿";
  font-size: 16px;
}

.app-header h1,
.app-header p {
  margin: 0;
}

.app-header .eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.app-header .header-note {
  margin-top: 7px;
  font-size: 12px;
}

.admin-entry {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 7px;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  color: #754f58;
  background: linear-gradient(#fffdfa, #fff1ed);
  border: 1px solid #deaeb6;
  border-radius: 999px;
  box-shadow: inset 0 0 0 3px #fff, 0 5px 15px rgba(155, 100, 112, 0.12);
  font-size: 12px;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.admin-entry:hover {
  box-shadow: inset 0 0 0 3px #fff, 0 8px 20px rgba(155, 100, 112, 0.18);
  transform: translateY(-2px);
}

.app-header h1 {
  font-size: 22px;
  line-height: 1.3;
}

.app-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.gallery-app {
  padding: 24px 0 64px;
}

.gallery-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.category-sidebar {
  position: sticky;
  top: 20px;
}

.sidebar-label {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.category-tabs {
  display: grid;
  gap: 8px;
}

.category-button {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.78), 0 4px 12px rgba(145, 98, 108, 0.05);
  transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.category-button:hover {
  color: var(--text);
  background: var(--panel-hover);
  transform: translateX(3px);
}

.category-button[aria-selected="true"] {
  color: #704851;
  background: linear-gradient(135deg, #ffe8ea, #fff5ee);
  border-color: var(--accent);
}

.category-button[aria-selected="true"]::before {
  color: var(--accent);
  content: "✿";
  font-size: 12px;
}

.category-icon {
  display: none;
}

.category-label strong,
.category-label span {
  display: block;
  font-size: 12px;
}

.category-label {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.category-label strong {
  font-weight: 600;
}

.category-label span {
  color: var(--muted);
  font-size: 10px;
}

.toolbar {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 9px 24px rgba(141, 95, 105, 0.07);
}

.search-field {
  flex: 1;
}

.search-field input,
.sort-control select {
  min-height: 38px;
  color: var(--text);
  background: #fffaf7;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.search-field input {
  width: 100%;
  padding: 8px 11px;
}

.search-field input:focus,
.sort-control select:focus {
  border-color: var(--accent);
}

.sort-control {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.sort-control select {
  padding: 6px 30px 6px 10px;
}

.gallery-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  color: var(--muted);
  font-size: 12px;
}

.gallery-status p {
  margin: 0;
}

.gallery-status span {
  padding: 3px 8px;
  background: var(--panel);
  border-radius: 999px;
  border: 1px solid #efd7d8;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.gallery-card,
.skeleton-card {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 9px 25px rgba(131, 84, 96, 0.08);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.gallery-card:hover {
  border-color: #dca7b0;
  box-shadow: 0 14px 32px rgba(131, 84, 96, 0.14);
  transform: translateY(-3px);
}

.image-button {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: #f4e7e2;
  border: 0;
  aspect-ratio: 16 / 10;
}

.image-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 160ms ease;
}

.image-button img[data-loading="true"] {
  opacity: 0;
}

.view-mark {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  width: 30px;
  height: 30px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  opacity: 0;
  place-items: center;
}

.card-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 5px;
}

.card-badges span {
  padding: 3px 7px;
  color: #fff;
  background: rgba(117, 71, 82, 0.82);
  border: 1px solid rgba(255, 230, 234, 0.75);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.image-button:hover .view-mark,
.image-button:focus-visible .view-mark {
  opacity: 1;
}

.image-error {
  position: absolute;
  inset: 0;
  display: none;
  align-content: center;
  padding: 20px;
  color: var(--muted);
  background: #fff6f2;
  font-size: 12px;
  text-align: center;
  place-items: center;
}

.image-error span {
  display: none;
}

.image-button.has-error .image-error {
  display: grid;
}

.card-body {
  padding: 12px;
}

.card-category {
  color: var(--accent);
  font-size: 11px;
}

.card-time {
  margin: 5px 0 3px;
  font-size: 14px;
  font-weight: 600;
}

.card-file {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-comment {
  display: -webkit-box;
  margin: 9px 0 0;
  overflow: hidden;
  color: #7f6268;
  font-size: 12px;
  line-height: 1.6;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.tag-list span {
  padding: 2px 6px;
  color: var(--muted);
  background: #fff0ec;
  border: 1px solid #f0d8d6;
  border-radius: 5px;
  font-size: 10px;
}

.skeleton-card {
  padding-bottom: 18px;
}

.skeleton-card div,
.skeleton-card span {
  display: block;
  background: #f2dedc;
  animation: pulse 1.2s ease-in-out infinite alternate;
}

.skeleton-card div {
  width: 100%;
  aspect-ratio: 16 / 10;
}

.skeleton-card span {
  width: 48%;
  height: 10px;
  margin: 14px 12px 0;
  border-radius: 4px;
}

.empty-state {
  padding: 60px 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 16px;
}

.empty-state p {
  margin: 0;
  font-size: 12px;
}

.lightbox {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  padding: 0;
  margin: 0;
  color: #fffaf7;
  background: rgba(62, 42, 49, 0.96);
  border: 0;
}

.lightbox::backdrop {
  background: transparent;
}

.lightbox-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.lightbox-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.18);
}

.lightbox-topbar > div,
.lightbox-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lightbox-topbar span,
.lightbox-topbar strong,
.lightbox-actions a {
  font-size: 12px;
}

.lightbox-topbar span {
  color: #dfc6cc;
}

.lightbox-actions a {
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,0.26);
  border-radius: 7px;
}

.icon-button,
.nav-button {
  display: grid;
  color: #fff;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.22);
  place-items: center;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 22px;
}

.lightbox-stage {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 12px;
  align-items: center;
  min-height: 0;
  padding: 16px;
  touch-action: pan-y;
}

.lightbox-stage figure {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  min-width: 0;
  height: 100%;
  margin: 0;
}

.lightbox-stage img {
  align-self: center;
  max-width: 100%;
  max-height: calc(100vh - 125px);
  object-fit: contain;
  opacity: 1;
  transition: opacity 140ms ease;
}

.lightbox-stage img.is-loading {
  opacity: 0;
}

.lightbox-stage figcaption {
  display: grid;
  gap: 5px;
  justify-items: center;
  min-height: 38px;
  padding-top: 9px;
  color: #dfc6cc;
  font-size: 11px;
}

.lightbox-stage figcaption > div {
  display: flex;
  gap: 10px;
}

.lightbox-stage figcaption p {
  margin: 0;
}

.lightbox-stage figcaption span {
  color: var(--accent);
}

.lightbox-comment {
  max-width: 720px;
  color: #f0dde1;
  line-height: 1.55;
  text-align: center;
}

.nav-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 28px;
}

.nav-button:disabled {
  cursor: default;
  opacity: 0.25;
}

.image-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: spin 0.8s linear infinite;
}

.image-loader.is-visible {
  opacity: 1;
}

.noscript {
  padding: 20px;
  color: #a34f62;
  text-align: center;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

@keyframes pulse {
  to { opacity: 0.45; }
}

@media (max-width: 820px) {
  .gallery-layout {
    grid-template-columns: 174px minmax(0, 1fr);
    gap: 16px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-header,
  .gallery-app {
    width: min(100% - 24px, 1200px);
  }

  .app-header {
    padding-top: 20px;
  }

  .app-header {
    gap: 14px;
    align-items: flex-start;
  }

  .app-header .header-note,
  .app-header::after {
    display: none;
  }

  .admin-entry {
    padding: 7px 10px;
    font-size: 11px;
  }

  .gallery-layout {
    display: block;
  }

  .category-sidebar {
    position: static;
    margin-bottom: 14px;
  }

  .sidebar-label {
    display: none;
  }

  .category-tabs {
    display: flex;
    flex-wrap: nowrap;
    padding-bottom: 5px;
    overflow-x: auto;
  }

  .category-button {
    flex: 0 0 auto;
    width: auto;
  }

  .category-label span { margin-left: 8px; }

  .toolbar {
    display: grid;
  }

  .sort-control {
    justify-content: space-between;
  }

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

  .lightbox-topbar {
    padding: 9px 10px;
  }

  .lightbox-topbar strong {
    display: none;
  }

  .lightbox-stage {
    display: block;
    padding: 10px;
  }

  .lightbox-stage figure {
    justify-content: center;
  }

  .nav-button {
    position: absolute;
    top: 50%;
    z-index: 2;
    background: rgba(20, 24, 32, 0.88);
    transform: translateY(-50%);
  }

  .nav-button.prev { left: 10px; }
  .nav-button.next { right: 10px; }
}

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