:root {
  color-scheme: dark;
  --bg: #121413;
  --panel: #1d201e;
  --panel-2: #252923;
  --ink: #f3f0e8;
  --muted: #b8b0a3;
  --line: #3a3f38;
  --accent: #77c8a4;
  --accent-2: #e8b468;
  --danger: #ef7d73;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 13px 22px 16px;
  background: var(--panel);
}

.sidebar-footer a {
  color: var(--accent);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.eyebrow,
.counter,
.meta,
.empty-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.75rem;
}

h2 {
  margin-bottom: 3px;
  font-size: 1.35rem;
}

.admin-link,
button {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--panel-2);
  text-decoration: none;
  cursor: pointer;
}

.admin-link {
  padding: 9px 12px;
  white-space: nowrap;
}

button {
  min-height: 40px;
  padding: 9px 13px;
}

.admin-link:hover,
button:hover {
  border-color: var(--accent);
}

.search {
  display: grid;
  gap: 7px;
  padding: 0 22px 18px;
}

label span {
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  color: var(--ink);
  background: #101210;
}

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

.image-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding: 0 14px 16px;
}

.image-group {
  margin: 0 0 10px;
}

.image-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #171a17;
  cursor: pointer;
  list-style: none;
}

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

.image-group summary::before {
  content: ">";
  flex: 0 0 auto;
  width: 14px;
  color: var(--accent);
}

.image-group[open] summary::before {
  content: "v";
}

.image-group summary span {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-group summary small {
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  background: #101210;
}

.image-group-items {
  padding-top: 8px;
}

.image-button {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  width: 100%;
  margin: 0 0 8px;
  padding: 8px;
  text-align: left;
}

.image-button.active {
  border-color: var(--accent);
  background: #26342f;
}

.image-button img,
.admin-item img {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px;
  background: #0b0c0b;
}

.image-button span {
  min-width: 0;
}

.image-button strong,
.image-button small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-button small {
  margin-top: 4px;
  color: var(--muted);
}

.image-button em {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  color: var(--accent-2);
  font-size: 0.82rem;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
  min-height: 100vh;
  overflow: hidden;
}

.viewer-header {
  position: sticky;
  top: 0;
  z-index: 25;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #171917;
}

.viewer-header > div:first-child {
  min-width: 0;
}

.viewer-header h2 {
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.toolbar button,
.viewer-delete-form button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 1.35rem;
}

.viewer-delete-form {
  display: flex;
}

.viewer-delete-form button {
  width: auto;
  min-width: 84px;
  padding: 0 12px;
  border-color: #69413d;
  color: #ffe7e4;
  background: #3b201e;
  font-size: 0.95rem;
}

.viewer-comment {
  max-width: 72ch;
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-line;
}

.viewer {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #080908;
}

.viewer .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  padding: 32px;
}

.viewer .empty a {
  color: var(--accent);
}

.admin-page {
  background: #141614;
}

.admin-shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.admin-header {
  margin-bottom: 22px;
}

.admin-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.notice {
  border: 1px solid #456556;
  border-radius: 7px;
  padding: 12px 14px;
  background: #20352b;
}

.notice.error {
  border-color: #7e3e3b;
  background: #39201f;
}

.login-form,
.upload-panel,
.admin-list {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
}

.login-form,
.upload-panel form:first-child {
  display: grid;
  gap: 14px;
}

.dropzone {
  display: grid;
  gap: 10px;
  min-height: 140px;
  align-content: center;
  border: 1px dashed #647063;
  border-radius: 8px;
  padding: 22px;
  background: #171a17;
}

input[type="file"] {
  color: var(--muted);
}

.logout-form {
  margin-top: 12px;
}

.admin-list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.delete-all-form {
  margin: 0;
}

.delete-all-form button {
  border-color: #69413d;
  color: #ffe7e4;
  background: #3b201e;
  white-space: nowrap;
}

.admin-list h2 {
  margin-bottom: 14px;
}

.admin-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.admin-item:first-of-type {
  border-top: 0;
}

.admin-item img {
  width: 88px;
  height: 62px;
}

.admin-item h3 {
  margin-bottom: 3px;
  font-size: 1rem;
}

.admin-edit-form {
  display: grid;
  gap: 10px;
}

.admin-edit-form label {
  display: grid;
  gap: 6px;
}

.admin-edit-form .save-button {
  justify-self: start;
  border-color: #3c6857;
  color: #e7fff3;
  background: #1f3a30;
}

.admin-item p {
  margin: 2px 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.admin-file-meta {
  font-size: 0.9rem;
}

.admin-item-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.admin-item-actions .admin-link {
  min-height: 40px;
  text-align: center;
}

.admin-item-actions .delete-form {
  margin: 0;
}

.admin-item-actions button {
  width: 100%;
}

.delete-form button,
.viewer-delete-form button {
  border-color: #69413d;
  color: #ffe7e4;
  background: #3b201e;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 1fr);
    height: auto;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    max-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .image-list {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .stage {
    height: auto;
    min-height: 560px;
  }

  .viewer {
    min-height: 560px;
  }

  .viewer-header,
  .topbar,
  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    flex-wrap: wrap;
  }

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

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

  .admin-list-header {
    flex-direction: column;
  }
}
