:root {
  color-scheme: light;
  --bg: #f7f3ee;
  --ink: #201b17;
  --muted: #746960;
  --line: #ddd1c7;
  --paper: #fffaf5;
  --accent: #7f4f35;
  --accent-dark: #4f2f23;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 11px 16px;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

.page {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0 72px;
}

.narrow {
  max-width: 860px;
}

.hero {
  min-height: 100vh;
  display: grid;
  align-items: end;
  background: linear-gradient(130deg, #2a211c, #86654d);
  background-size: cover;
  background-position: center;
  position: relative;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.56));
}

.hero-inner {
  position: relative;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 54px;
  color: #fff;
}

.hero p {
  margin: 0 0 12px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 15px;
}

.hero h1 {
  margin: 0;
  max-width: 860px;
  font-size: clamp(44px, 9vw, 120px);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero p {
  display: block;
  max-width: 620px;
  margin-top: 18px;
  color: rgba(255, 255, 255, 0.84);
  font-size: clamp(18px, 2vw, 24px);
}

.category-nav {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 12px max(16px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 238, 0.92);
  backdrop-filter: blur(10px);
}

.category-nav a {
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
}

.category {
  padding-top: 28px;
}

.category h2 {
  margin: 0 0 18px;
  font-size: 30px;
}

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

.media-card {
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: #e4dbd3;
  border-radius: 8px;
  position: relative;
}

.media-open {
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.media-open:hover {
  background: transparent;
}

.media-thumb,
.gallery-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.22s ease;
}

.media-card:hover .media-thumb,
.media-card:focus-within .media-thumb,
.gallery-card:hover img {
  transform: scale(1.035);
}

.media-tools {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.media-card:hover .media-tools,
.media-card:focus-within .media-tools {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.media-tool {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  padding: 0;
  text-align: center;
  text-decoration: none;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  line-height: 1;
  flex: 0 0 auto;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.media-tool:hover,
.media-tool.is-active {
  background: transparent;
  color: #fff;
  transform: translateY(-1px);
}

.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.gallery-card {
  min-height: 280px;
  display: grid;
  align-content: end;
  gap: 4px;
  overflow: hidden;
  position: relative;
  text-decoration: none;
  border-radius: 8px;
  background: #ddd1c7;
  padding: 18px;
}

.gallery-card img {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.gallery-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.62));
}

.gallery-card span,
.gallery-card small {
  position: relative;
  z-index: 1;
  color: #fff;
}

.gallery-card span {
  font-size: 24px;
  font-weight: 800;
}

.gallery-card small {
  color: rgba(255, 255, 255, 0.8);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  background: rgba(20, 16, 13, 0.92);
}

.lightbox[hidden] {
  display: none;
}

.lightbox-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  gap: 8px;
}

.lightbox-action {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  backdrop-filter: blur(10px);
}

.lightbox-action:hover,
.lightbox-action.is-active {
  background: transparent;
  color: #fff;
  transform: translateY(-1px);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  transform: translateY(-50%);
}

.lightbox-nav:hover {
  background: transparent;
  color: #fff;
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

.lightbox [data-lightbox-body] {
  min-height: 0;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox img,
.lightbox video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-video {
  width: 100%;
  height: 100%;
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 92px);
  object-fit: contain;
}

.lightbox p {
  margin: 0;
  color: #fff;
  text-align: center;
}

.no-scroll {
  overflow: hidden;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form,
.panel {
  width: min(100%, 560px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 22px;
}

.login h1,
.admin h1,
.panel h2 {
  margin: 0 0 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.admin {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 70px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  background: #f3eee8;
}

.admin-menu {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-right: 1px solid var(--line);
  background: #fffaf5;
  padding: 22px 16px;
}

.admin-menu strong {
  display: block;
  margin-bottom: 18px;
  font-size: 18px;
}

.admin-menu a,
.preview-link {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  font-weight: 700;
}

.admin-menu a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.admin-menu form {
  margin-top: auto;
}

.admin-content {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 70px;
  display: grid;
  gap: 16px;
}

.admin-content > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-content .panel {
  width: 100%;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.admin-list {
  margin-top: 16px;
}

.panel-head,
.category-admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.cover-preview {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e4dbd3;
  aspect-ratio: 16 / 9;
}

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

.cover-actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
}

.file-action {
  width: auto;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
}

.file-action input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost:hover {
  background: #f1e8df;
}

.admin > header,
.admin > .panel:last-child {
  grid-column: 1 / -1;
}

.admin > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.category-admin {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  margin-top: 14px;
}

.category-admin.is-hidden {
  opacity: 0.68;
}

.category-title-form {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.category-actions {
  display: flex;
  gap: 8px;
}

.category-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-top: 14px;
}

.media-admin-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.media-admin-item {
  display: grid;
  grid-template-columns: 24px 78px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.media-admin-item.is-dragging {
  opacity: 0.45;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-weight: 900;
  letter-spacing: -4px;
}

.media-admin-item.is-hidden {
  opacity: 0.62;
}

.media-admin-preview {
  width: 78px;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: #e4dbd3;
}

.media-admin-preview img,
.media-admin-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-admin-item strong,
.media-admin-item small {
  display: block;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.media-actions form {
  display: inline;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.danger {
  color: #8f1d1d;
}

.admin-card strong,
.admin-card small {
  display: block;
}

.admin-card small {
  color: var(--muted);
  word-break: break-all;
}

details {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

code {
  border-radius: 6px;
  background: #eee5dd;
  padding: 2px 6px;
}

@media (max-width: 820px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-menu {
    position: static;
    height: auto;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .category-admin-head,
  .category-actions,
  .cover-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .category-title-form,
  .category-upload {
    grid-template-columns: 1fr;
  }

  .media-admin-item {
    grid-template-columns: 22px 64px minmax(0, 1fr);
  }

  .media-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .media-tools {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .lightbox-actions {
    top: auto;
    right: 50%;
    bottom: 16px;
    transform: translateX(50%);
  }

  .lightbox-prev {
    left: 10px;
  }

  .lightbox-next {
    right: 10px;
  }

  .hero {
    min-height: 100vh;
  }
}
