:root {
  color-scheme: dark;
  --bg: #1f2430;
  --bg-soft: #242936;
  --panel: #272d3b;
  --panel-hi: #2f3747;
  --text: #cccac2;
  --muted: #8a9199;
  --line: #3a4252;
  --line-strong: #4a5568;
  --blue: #59c2ff;
  --blue-dark: #399ee6;
  --green: #aad94c;
  --yellow: #ffd173;
  --red: #f28779;
  --red-strong: #b3261e;
  --red-contrast: #fff8f6;
  --shadow: rgb(0 0 0 / 22%);
  --tile: #202632;
  --tile-sheen: rgb(89 194 255 / 13%);
  --radius: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="ayu-light"] {
  color-scheme: light;
  --bg: #f8f9fa;
  --bg-soft: #eef2f5;
  --panel: #ffffff;
  --panel-hi: #f2f5f8;
  --text: #5c6773;
  --muted: #8c98a4;
  --line: #d9e0e7;
  --line-strong: #b8c2cc;
  --blue: #36a3d9;
  --blue-dark: #2186b8;
  --green: #86b300;
  --yellow: #f2ae49;
  --red: #f07171;
  --red-strong: #b3261e;
  --red-contrast: #fff8f6;
  --shadow: rgb(27 31 35 / 10%);
  --tile: #f1f5f8;
  --tile-sheen: rgb(54 163 217 / 12%);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(var(--bg-soft), var(--bg) 180px),
    var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
}

a {
  color: var(--blue-dark);
}

code {
  color: var(--blue);
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-strong);
  background: linear-gradient(var(--panel-hi), var(--panel));
  box-shadow: 0 1px 3px var(--shadow);
}

.nav-toggle {
  display: none;
  width: 36px;
  min-width: 36px;
  padding: 5px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-shadow: none;
}

.nav-toggle:hover {
  border-color: var(--line);
  background: var(--bg-soft);
  color: var(--blue);
}

.nav-toggle svg,
.sheet-action svg {
  width: 22px;
  height: 22px;
  display: block;
  fill: currentColor;
}

.brand {
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  text-shadow: 0 1px 0 rgb(0 0 0 / 18%);
}

.nav {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.nav a,
.link-button,
.theme-toggle {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.nav a,
.link-button,
.theme-toggle {
  justify-content: center;
}

.nav a:hover,
.link-button:hover,
.theme-toggle:hover {
  border-color: var(--line);
  background: var(--bg-soft);
  color: var(--blue);
}

.inline-form {
  display: inline;
  margin: 0;
}

.shell {
  width: min(1220px, calc(100% - 28px));
  margin: 14px auto 36px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 3px var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  line-height: 1.15;
}

h1 {
  font-size: clamp(24px, 4vw, 42px);
}

.muted {
  color: var(--muted);
}

.status-card {
  min-width: 220px;
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.status-card span:last-child {
  color: var(--muted);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--yellow);
}

.status-dot.ok {
  background: var(--green);
}

.mosaic {
  display: grid;
  grid-auto-flow: dense;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  grid-auto-rows: 132px;
  gap: 10px;
  margin: 14px 0;
}

.tile {
  display: grid;
  place-items: end start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(135deg, var(--tile-sheen), transparent 54%),
    var(--tile);
}

.tile span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(0 0 0 / 20%);
  font-weight: 700;
}

.tile.tall {
  grid-row: span 2;
}

.tile.wide {
  grid-column: span 2;
}

.details {
  padding: 14px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 9px;
  padding: 10px;
  margin-bottom: 12px;
  background: linear-gradient(var(--panel-hi), var(--panel));
}

.filters label,
.download-form label,
.stack label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.check-label {
  display: inline-flex !important;
  grid-auto-flow: column;
  align-items: center;
  min-height: 30px;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.check-label input {
  min-height: auto;
}

input,
select,
button,
.button {
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  background: linear-gradient(#6ecbff, var(--blue-dark));
  border-color: var(--blue-dark);
  color: #071923;
  font-weight: 700;
  text-shadow: 0 1px 0 rgb(255 255 255 / 24%);
}

.button.secondary {
  background: linear-gradient(var(--panel-hi), var(--bg-soft));
  color: var(--text);
  border-color: var(--line);
}

button.danger {
  background: linear-gradient(#ff9d91, var(--red));
  border-color: var(--red);
  color: #2a0905;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.auth-card {
  position: relative;
  width: min(360px, 100%);
  padding: 18px;
}

.auth-theme-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
}

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

.alert {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.alert.error {
  color: var(--red);
}

.alert.ok {
  color: var(--green);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: 10px;
  align-items: start;
  transition: opacity 160ms ease, transform 160ms ease;
}

.gallery-grid.is-swapping {
  opacity: 0.35;
  transform: translateY(4px);
}

.gallery-grid.is-entering .media-card {
  opacity: 0;
  transform: translateY(8px);
}

.gallery-grid.is-entered .media-card {
  opacity: 1;
  transform: translateY(0);
}

.media-card {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(110deg, transparent 0%, var(--tile-sheen) 38%, transparent 72%),
    var(--tile);
  background-size: 220% 100%, auto;
  text-decoration: none;
  box-shadow: 0 1px 2px var(--shadow);
  transition: opacity 180ms ease, transform 180ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.media-link {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.media-link:focus-visible {
  outline: 0;
}

.media-card:focus-within {
  border-color: var(--blue);
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 5px rgb(89 194 255 / 55%);
}

.media-card:hover {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgb(89 194 255 / 18%);
}

.media-card.is-favorite {
  border-color: color-mix(in srgb, var(--blue) 64%, var(--line));
}

.media-card .media-asset {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: saturate(0.86);
  transition: opacity 180ms ease, filter 180ms ease;
}

.media-card .media-asset.is-loaded {
  opacity: 1;
  filter: saturate(1);
}

.media-card.video::before {
  content: "▶";
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgb(255 255 255 / 72%);
  font-size: 38px;
  text-shadow: 0 1px 5px rgb(0 0 0 / 70%);
  pointer-events: none;
}

.media-meta {
  position: absolute;
  z-index: 2;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: var(--radius);
  background: rgb(0 0 0 / 56%);
  color: #f8f9fa;
  font-size: 11px;
}

.media-meta em {
  color: rgb(255 255 255 / 72%);
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-overlay,
.viewer-overlay {
  position: absolute;
  z-index: 3;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.media-card:hover .media-overlay,
.media-card:focus-within .media-overlay,
.viewer:hover .viewer-overlay,
.viewer:focus-within .viewer-overlay {
  opacity: 1;
  transform: translateY(0);
}

.icon-button {
  min-width: 32px;
  min-height: 30px;
  padding: 4px 7px;
  border-color: rgb(255 255 255 / 18%);
  background: rgb(17 23 34 / 82%);
  color: #f8f9fa;
  text-shadow: none;
  backdrop-filter: blur(4px);
}

.icon-button.secondary {
  color: var(--yellow);
}

.icon-button.danger {
  color: #fff;
  background: rgb(242 135 121 / 88%);
  border-color: var(--red);
}

.detail-nav {
  position: absolute;
  z-index: 3;
  top: 50%;
  min-width: 42px;
  min-height: 58px;
  padding: 0;
  border-color: rgb(255 255 255 / 14%);
  background: rgb(17 23 34 / 58%);
  color: #f8f9fa;
  font-size: 34px;
  line-height: 1;
  text-shadow: none;
  transform: translateY(-50%);
}

.detail-exit {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: 10px;
  min-height: 34px;
  padding: 6px 10px;
  border-color: rgb(255 255 255 / 18%);
  background: rgb(17 23 34 / 68%);
  color: #f8f9fa;
  text-shadow: none;
  backdrop-filter: blur(4px);
}

.detail-exit:hover,
.detail-exit:focus-visible {
  border-color: var(--blue);
  background: rgb(17 23 34 / 82%);
  color: #fff;
}

.detail-nav.prev {
  left: 8px;
}

.detail-nav.next {
  right: 8px;
}

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

.detail-sheet-bar {
  display: none;
}

.sheet-action {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: var(--line);
  background: var(--bg-soft);
  color: var(--text);
  text-shadow: none;
}

.sheet-action.is-favorite,
.sheet-action.secondary {
  color: var(--yellow);
}

.sheet-action.danger {
  border-color: color-mix(in srgb, var(--red-strong) 78%, black);
  background: linear-gradient(color-mix(in srgb, var(--red-strong) 84%, white), var(--red-strong));
  color: var(--red-contrast);
  box-shadow: 0 4px 14px rgb(179 38 30 / 22%);
}

.sheet-action.danger:hover,
.sheet-action.danger:focus-visible {
  color: #fff;
  border-color: color-mix(in srgb, var(--red-strong) 64%, white);
  background: linear-gradient(color-mix(in srgb, var(--red-strong) 74%, white), color-mix(in srgb, var(--red-strong) 86%, black));
}

.sheet-toggle svg {
  transition: transform 160ms ease;
}

.detail-sheet.is-expanded .sheet-toggle svg {
  transform: rotate(180deg);
}

[data-favorite-star] {
  min-width: 0.85em;
  display: inline-block;
  color: var(--yellow);
}

.detail-favorite-star {
  min-width: 30px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--yellow);
  font-size: 18px;
}

.confirm-modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgb(0 0 0 / 58%);
  backdrop-filter: blur(3px);
}

.confirm-modal.is-open {
  display: flex;
}

.confirm-modal-card {
  width: min(380px, 100%);
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 6px);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 18px 48px rgb(0 0 0 / 34%);
}

.confirm-modal-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.confirm-modal-card p {
  margin: 0;
  color: var(--muted);
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

body.is-modal-open {
  overflow: hidden;
}

.detail-favorite-star.is-on {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--yellow) 22%, transparent);
}

.pager {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.empty {
  padding: 22px;
  color: var(--muted);
}

.detail-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  gap: 12px;
  width: min(1220px, calc(100% - 28px));
  height: auto;
  margin: 14px auto 36px;
  padding-bottom: 0;
}

.viewer {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 70vh;
  height: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at center, color-mix(in srgb, var(--panel-hi) 76%, var(--bg)) 0%, var(--panel) 62%),
    var(--panel);
  box-shadow: 0 1px 3px var(--shadow);
}

:root[data-theme="ayu-light"] .viewer {
  background:
    radial-gradient(circle at center, color-mix(in srgb, var(--panel-hi) 70%, var(--bg)) 0%, var(--bg-soft) 68%),
    var(--bg-soft);
}

.viewer img,
.viewer video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 78vh;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px var(--shadow);
}

.viewer-loader {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--blue);
  pointer-events: none;
}

.viewer-loader svg {
  width: 42px;
  height: 42px;
  fill: currentColor;
  opacity: 0.8;
  animation: spin 900ms linear infinite;
}

.viewer.is-loaded .viewer-loader {
  display: none;
}

.viewer .viewer-asset {
  position: relative;
  z-index: 2;
}

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

.detail-sheet {
  position: static;
  max-height: none;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: visible;
}

.detail-sheet-bar {
  display: none;
}

.detail-sheet-bar form,
.detail-sheet-bar button {
  justify-self: center;
}

.detail-sheet-content {
  display: block;
  max-height: none;
  overflow: visible;
  padding: 0;
}

.detail-sheet.is-expanded .detail-sheet-content {
  display: block;
}

.detail-sheet .action-row {
  display: flex;
}

.action-row,
.tag-form,
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 9px 0;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  text-decoration: none;
}

button.tag-pill {
  cursor: pointer;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.user-row,
.job-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.user-row {
  grid-template-columns: minmax(120px, 1fr) auto auto auto;
}

.download-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 100px 160px 100px auto auto auto;
  gap: 8px;
  align-items: end;
}

.log-tail {
  max-height: 60vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111722;
  color: #d8dee9;
  white-space: pre-wrap;
}

dl {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
}

dl div {
  display: grid;
  grid-template-columns: minmax(100px, 150px) 1fr;
  gap: 12px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

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

  .media-card .media-asset {
    opacity: 1;
    filter: none;
  }
}

@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  html:has(#app.detail-shell),
  body:has(#app.detail-shell) {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
  }

  .topbar,
  .hero,
  dl div,
  .detail-shell {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: sticky;
    align-items: stretch;
    min-height: 46px;
    padding: 8px 12px;
  }

  .brand {
    display: inline-flex;
    align-items: center;
  }

  .nav-toggle {
    display: inline-flex;
    position: absolute;
    top: 7px;
    right: 10px;
    z-index: 22;
  }

  .nav {
    position: absolute;
    top: calc(100% + 6px);
    right: 10px;
    z-index: 21;
    min-width: min(260px, calc(100vw - 20px));
    display: grid;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 8px 24px rgb(0 0 0 / 34%);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 140ms ease, transform 140ms ease;
  }

  .topbar.is-open .nav {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .nav a,
  .link-button,
  .theme-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .inline-form {
    display: block;
  }

  .tile.wide {
    grid-column: span 1;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  }

  .download-form,
  .job-row,
  .user-row {
    grid-template-columns: 1fr;
  }

  #app.detail-shell {
    width: 100%;
    height: calc(100dvh - 47px);
    margin: 0;
    padding-bottom: 70px;
    gap: 0;
    overflow: hidden;
  }

  .detail-exit {
    top: 8px;
    left: 8px;
    min-width: 44px;
    min-height: 40px;
  }

  .detail-shell .viewer {
    min-height: 0;
    height: calc(100dvh - 47px - 70px);
    padding: 0;
    border: 0;
    border-radius: 0;
    background:
      radial-gradient(circle at center, color-mix(in srgb, var(--panel-hi) 70%, var(--bg)) 0%, var(--bg) 72%),
      var(--bg);
    box-shadow: none;
    overflow: hidden;
    touch-action: none;
  }

  .detail-shell .viewer img,
  .detail-shell .viewer video {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: contain;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(var(--swipe-y, 0)) rotate(var(--swipe-tilt, 0deg));
    transition: transform 190ms cubic-bezier(0.22, 1, 0.36, 1), opacity 190ms ease;
    will-change: transform;
  }

  .detail-shell .viewer.is-swiping img,
  .detail-shell .viewer.is-swiping video {
    transition: none;
  }

  .detail-shell .viewer.is-swipe-committing img,
  .detail-shell .viewer.is-swipe-committing video,
  .detail-shell .viewer.is-swipe-reverting img,
  .detail-shell .viewer.is-swipe-reverting video,
  .detail-shell .viewer.is-swipe-entering img,
  .detail-shell .viewer.is-swipe-entering video {
    transition: transform 210ms cubic-bezier(0.22, 1, 0.36, 1), opacity 190ms ease;
  }

  .detail-shell .detail-nav {
    display: none;
  }

  .detail-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    max-height: 74dvh;
    padding: 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 14px 14px 0 0;
    overflow: hidden;
  }

  .detail-sheet-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: linear-gradient(var(--panel-hi), var(--panel));
  }

  .detail-sheet-bar form,
  .detail-sheet-bar button {
    justify-self: center;
  }

  .detail-sheet-content {
    display: none;
    max-height: calc(74dvh - 64px);
    overflow: auto;
    padding: 0 14px 16px;
  }

  .detail-sheet.is-expanded .detail-sheet-content {
    display: block;
  }

  .detail-sheet .action-row {
    display: none;
  }

  .media-overlay {
    opacity: 1;
    transform: none;
  }
}
