:root {
  --bg-deep: #0c1118;
  --bg-panel: #141b24;
  --bg-lift: #1a2430;
  --line: rgba(168, 198, 220, 0.14);
  --text: #e8eef4;
  --muted: #8fa3b8;
  --accent: #3dd6c6;
  --accent-dim: rgba(61, 214, 198, 0.16);
  --danger: #ff7b72;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font: "Outfit", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
  line-height: 1.4;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(61, 214, 198, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 45% at 90% 0%, rgba(72, 120, 180, 0.18), transparent 50%),
    linear-gradient(180deg, #101722 0%, var(--bg-deep) 40%, #0a0e14 100%);
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 1.25rem;
}

.brand-mark {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.brand-sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.refresh {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-lift);
  color: var(--text);
  font: 500 0.95rem var(--font);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.refresh:hover {
  border-color: rgba(61, 214, 198, 0.45);
  background: var(--accent-dim);
}

.refresh:active {
  transform: translateY(1px);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 3rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, border-color 0.25s ease;
}

.card:hover .thumb-wrap,
.card:focus-visible .thumb-wrap {
  transform: translateY(-3px);
  border-color: rgba(61, 214, 198, 0.4);
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.card:hover .thumb-wrap img {
  transform: scale(1.04);
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.meta-name {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-info {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mini-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-lift);
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.mini-download:hover {
  background: var(--accent-dim);
  border-color: rgba(61, 214, 198, 0.45);
}

.empty,
.error {
  margin: 3rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
}

.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.viewer {
  border: 0;
  padding: 0;
  width: min(96vw, 1200px);
  max-height: 92vh;
  background: transparent;
  color: var(--text);
}

.viewer::backdrop {
  background: rgba(5, 8, 12, 0.78);
  backdrop-filter: blur(8px);
}

.viewer-shell {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 92vh;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

.viewer-name {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-lift);
  color: var(--text);
  text-decoration: none;
  font: 500 0.9rem var(--font);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.btn:hover {
  border-color: rgba(61, 214, 198, 0.45);
  background: var(--accent-dim);
}

.btn-download {
  background: var(--accent);
  color: #06221f;
  border-color: transparent;
  font-weight: 600;
}

.btn-download:hover {
  background: #67e6d8;
  border-color: transparent;
}

.viewer-stage {
  display: grid;
  place-items: center;
  padding: 0.75rem 1rem 1.1rem;
  overflow: auto;
  min-height: 40vh;
}

.viewer-stage img {
  max-width: 100%;
  max-height: calc(92vh - 5.5rem);
  object-fit: contain;
  border-radius: 8px;
}

@media (max-width: 640px) {
  .top {
    flex-direction: column;
    align-items: flex-start;
  }

  .viewer-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .viewer-actions {
    width: 100%;
  }

  .viewer-actions .btn {
    flex: 1;
    text-align: center;
  }
}
