:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #141820;
  --panel-hover: #191e28;
  --border: #292f3b;
  --text: #f1f3f6;
  --muted: #969eab;
  --accent: #8ea8ff;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  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 {
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
}

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

.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: 9px;
}

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

.category-button[aria-selected="true"] {
  color: white;
  background: #20283a;
  border-color: var(--accent);
}

.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);
}

.search-field {
  flex: 1;
}

.search-field input,
.sort-control select {
  min-height: 38px;
  color: var(--text);
  background: #0d1016;
  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;
}

.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);
}

.gallery-card:hover {
  border-color: #3b4352;
}

.image-button {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: #090b0f;
  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(24, 31, 48, 0.86);
  border: 1px solid rgba(142, 168, 255, 0.5);
  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: #0d1016;
  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: #c9ced7;
  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: #0d1016;
  border-radius: 5px;
  font-size: 10px;
}

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

.skeleton-card div,
.skeleton-card span {
  display: block;
  background: #1e232d;
  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: var(--text);
  background: rgba(5, 6, 9, 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 var(--border);
}

.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: var(--muted);
}

.lightbox-actions a {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.icon-button,
.nav-button {
  display: grid;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  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: var(--muted);
  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: #c9ced7;
  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 var(--border);
  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: #ff9a9a;
  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;
  }

  .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;
  }
}
