:root {
  --bg: #181818;
  --line: #222;
  --text: #ececec;
  --muted: #8a8a8a;
  --purple: #a855f7;
  --purple-dim: #7c3aed;
  --purple-border-dark: #4a1d7e;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Consolas", monospace;
  --frame: 3px solid #222;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* html must be filled too — color-scheme: dark otherwise uses a #000 canvas */
html {
  height: 100%;
  color-scheme: dark;
  background-color: #181818 !important;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background-color: #181818 !important;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.site-header,
.layout,
.site-footer {
  position: relative;
}

.site-header {
  padding: clamp(1rem, 3vw, 1.5rem) clamp(1rem, 4vw, 2rem) 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  max-width: 720px;
  margin: 0 auto;
  min-width: 0;
}

.logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.8vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.75rem clamp(1rem, 4vw, 2rem) 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--bg);
  border: var(--frame);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel.result-panel {
  overflow: visible;
}

.upload-panel {
  outline: none;
  transition: border-color 0.25s ease, transform 0.25s ease;
}

.upload-panel:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.upload-panel.dragover {
  border-color: var(--purple);
  transform: scale(1.005);
}

.drop-inner {
  padding: clamp(1.75rem, 5vw, 2.5rem) 1.25rem;
  text-align: center;
}

.drop-icon {
  color: var(--purple);
  margin-bottom: 0.65rem;
  display: flex;
  justify-content: center;
}

.drop-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
}

.drop-hint {
  margin: 0;
  color: var(--muted);
}

.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--purple);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.linkish:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.drop-meta {
  margin: 0.85rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.progress {
  height: 3px;
  background: var(--line);
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--purple);
  transition: width 0.2s ease;
}

.result-panel {
  padding: 1.1rem 1.1rem 1.25rem;
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.result-panel.result-panel--leaving {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  pointer-events: none;
  transition:
    opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1),
    transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes uploadPop {
  0% {
    transform: scale(1);
    border-color: var(--line);
  }
  35% {
    transform: scale(1.012);
    border-color: var(--purple);
  }
  100% {
    transform: scale(1);
    border-color: var(--line);
  }
}

.upload-panel.upload-panel--pop {
  animation: uploadPop 0.7s cubic-bezier(0.25, 1, 0.5, 1);
}

.result-heading {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.result-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.result-card {
  border: var(--frame);
  border-radius: var(--radius-sm);
  padding: 1rem;
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  will-change: opacity, transform;
}

.result-card.result-card--animate {
  animation: cardEnter 0.52s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--enter-delay, 0ms);
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.result-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.result-card-head .result-card-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.result-card-title {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  word-break: break-word;
}

.result-card-status {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.result-card-status--error {
  color: var(--danger);
  font-weight: 600;
}

.preview-wrap--skel {
  min-height: 140px;
  max-height: 180px;
  background: #141414;
  position: relative;
  overflow: hidden;
}

.skel-shine {
  position: absolute;
  top: 0;
  left: 0;
  width: 45%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(168, 85, 247, 0.18) 50%,
    transparent 100%
  );
  transform: translate3d(-100%, 0, 0);
  animation: skelSweep 1.25s ease-in-out infinite;
}

@keyframes skelSweep {
  0% {
    transform: translate3d(-100%, 0, 0);
  }
  100% {
    transform: translate3d(280%, 0, 0);
  }
}

.skel-lines {
  margin-top: 0.75rem;
}

.skel-line {
  height: 10px;
  border-radius: 4px;
  background: #252525;
  margin-bottom: 0.5rem;
  animation: skelPulse 0.9s ease-in-out infinite alternate;
}

.skel-line--short {
  width: 58%;
}

@keyframes skelPulse {
  from {
    opacity: 0.45;
  }
  to {
    opacity: 0.95;
  }
}

.result-card--done .preview-wrap img {
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.result-card--done .preview-wrap img.img-ready {
  opacity: 1;
  transform: scale(1);
}

.ox-section--card {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 3px solid #222;
}

.ox-global {
  margin-top: 1.15rem;
  padding-top: 1.15rem;
  border-top: 3px solid #222;
}

@media (prefers-reduced-motion: reduce) {
  .upload-panel,
  .progress-bar {
    transition: none;
  }

  .upload-panel.dragover {
    transform: none;
  }

  .result-panel.result-panel--leaving {
    transition: none !important;
    opacity: 0;
  }

  .upload-panel.upload-panel--pop {
    animation: none !important;
  }

  .result-card,
  .result-card.result-card--animate,
  .result-card--done .preview-wrap img,
  .skel-shine,
  .skel-line {
    animation: none !important;
    transition: none !important;
  }

  .result-card {
    opacity: 1 !important;
    transform: none !important;
    will-change: auto;
  }

  .result-card--done .preview-wrap img {
    opacity: 1 !important;
    transform: none !important;
  }
}

.preview-wrap {
  border: var(--frame);
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 0.9rem;
  max-height: min(52vh, 420px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-wrap img {
  max-width: 100%;
  max-height: min(52vh, 420px);
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.ox-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 3px solid #222;
}

.ox-hint {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.ox-hint code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--purple);
}

.url-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.url-row-tall {
  align-items: stretch;
}

.url-row-tall .btn {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.url-input {
  flex: 1 1 200px;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.55rem 0.65rem;
  border: var(--frame);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}

.url-input:focus {
  outline: none;
  border-color: var(--purple);
}

.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  border: var(--frame);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

.btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--purple-dim);
  color: #fff;
  border: 3px solid var(--purple-border-dark);
}

.btn.primary:hover {
  background: var(--purple);
}

.btn.ghost:hover {
  border-color: var(--muted);
}

#reset-btn {
  margin-top: 0.85rem;
  width: 100%;
}

.toast {
  min-height: 1.2rem;
  margin: 0.55rem 0 0;
  font-size: 0.88rem;
  color: var(--purple);
}

.error {
  margin: 0;
  padding: 0.75rem 0.9rem;
  border: var(--frame);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--danger);
  font-weight: 500;
}

.site-footer {
  padding: 0.75rem clamp(1rem, 4vw, 2rem) 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer .dot {
  margin: 0 0.3rem;
}

@media (max-width: 480px) {
  .url-row {
    flex-direction: column;
  }

  .btn.primary {
    width: 100%;
  }

}

.layout--wide {
  max-width: min(960px, 100%);
}

.server-setup-panel,
.library-panel {
  padding: 1rem 1.1rem 1.15rem;
}

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 3px solid #222;
}

.library-toolbar-main {
  min-width: 0;
}

.library-total {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.library-total-num {
  font-variant-numeric: tabular-nums;
  color: var(--purple);
}

.library-total-label {
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.25rem;
}

.library-slug-line {
  margin: 0.35rem 0 0;
}

.library-slug {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--purple);
  word-break: break-all;
}

.library-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.library-share-hint {
  margin: 0.5rem 0 0;
  max-width: 36rem;
  line-height: 1.45;
}

.library-share-hint a {
  color: var(--purple);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.library-share-hint a:hover {
  color: var(--text);
}

.library-share-hint a:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 2px;
}

.library-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 0.65rem;
  max-height: min(52vh, 480px);
  overflow-y: auto;
  padding: 0.15rem 0 0;
}

.library-images-status {
  grid-column: 1 / -1;
  margin: 0;
}

.library-thumb-card {
  border: var(--frame);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.library-thumb-link {
  display: block;
  aspect-ratio: 1;
  background: #111;
}

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

.library-thumb-name {
  margin: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.68rem;
  line-height: 1.25;
  color: var(--muted);
  overflow: hidden;
}

.library-thumb-name code {
  font-family: var(--mono);
  font-size: 0.66rem;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.folder-intro {
  margin: 0 0 1rem;
}

.folder-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.folder-card {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-bottom: 3px solid #222;
}

.folder-card:last-child {
  border-bottom: none;
}

.folder-card-preview {
  flex-shrink: 0;
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: var(--frame);
}

.folder-card-preview img {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: cover;
  background: var(--bg);
}

.folder-card-body {
  flex: 1 1 200px;
  min-width: 0;
}

.folder-card-name {
  margin: 0 0 0.4rem;
  font-size: 0.88rem;
}

.folder-card-name code {
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
}

.folder-card-url-row {
  margin: 0;
}

.folder-footer-code {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--purple);
  word-break: break-all;
}

.server-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.85rem;
}

.server-meta-line {
  flex: 1 1 auto;
  margin: 0;
  font-size: 0.95rem;
  min-width: 0;
}

.server-meta-line code {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--purple);
  word-break: break-all;
}

.server-meta-sep {
  margin: 0 0.35rem;
  color: var(--muted);
}

#server-image-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.server-create {
  margin-bottom: 0;
}

.server-actions {
  margin-bottom: 0.5rem;
}

.btn.danger {
  color: var(--danger);
  border-color: #5c2a2a;
}

.btn.danger:hover {
  border-color: var(--danger);
}

.btn-sm {
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
}

.admin-auth-panel {
  padding: 1rem 1.1rem 1.25rem;
}

.admin-dashboard {
  padding: 1rem 1.1rem 1.25rem;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.admin-toolbar .result-heading {
  margin: 0;
  flex: 1 1 auto;
}

.admin-images-heading {
  margin: 1.25rem 0 0.65rem;
}

.table-wrap {
  overflow-x: auto;
  border: var(--frame);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 3px solid #222;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tr:last-child td {
  border-bottom: none;
}

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

.data-table .actions {
  text-align: right;
  white-space: nowrap;
}

.admin-pagination {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--text);
}

.site-footer a:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 2px;
}

.admin-error {
  margin-top: 0.75rem;
}
