/* Palette adopted from bs-coolscan (dark, layered grays + blue accents). */
:root {
  --bg: #1a1d21;
  --surface: #23262c;
  --surface-2: #1e2228;
  --tile: #2b2f36;
  --hover: #2c313a;
  --border: #2a2e34;
  --border-strong: #383d44;
  --fg: #e6e6e6;
  --fg-bright: #f2f4f8;
  --fg-dim: #8a8f95;
  --label: #cdd6e0;
  --accent: #7fb4f0;
  --accent-fill: #37495f;
  --accent-fill-hi: #3f5168;
  --accent-bd: #4a6080;
  --danger: #e07a7a;
  --radius: 8px;
  --radius-sm: 6px;

  color-scheme: dark;
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
}

a {
  color: var(--accent);
}

h1 {
  color: var(--fg-bright);
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  margin: 0 0 0.15rem;
}

button {
  font: inherit;
  cursor: pointer;
}

.error {
  color: var(--danger);
}

/* --- Top bar --------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: 52px;
  background: var(--surface-2);
}

.topbar > a {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg-bright);
  flex: none;
}

.topbar-auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-email {
  color: var(--fg-dim);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 22ch;
}

.topbar-loading {
  color: var(--fg-dim);
  font-size: 0.85rem;
}

.topbar-signin {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 0.9rem;
  border: 1px solid var(--accent-bd);
  border-radius: var(--radius-sm);
  background: var(--accent-fill);
  color: var(--fg-bright) !important;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-signin:hover {
  background: var(--accent-fill-hi);
}

.container {
  max-width: 64rem;
  margin: 1rem auto 4rem;
  padding: 0 1rem;
}

/* --- Auth ------------------------------------------------------------------ */
.signin {
  padding: 3rem 0;
  text-align: center;
  color: var(--fg-dim);
}

.logout {
  height: 34px;
  padding: 0 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-dim);
  font-size: 0.85rem;
}

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

/* --- Album list (home) ----------------------------------------------------- */
.album-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.album-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.album-card:hover,
.album-card:active {
  border-color: var(--accent-bd);
  transform: translateY(-2px);
}

.album-cover {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 4;
  object-fit: cover;
  background: var(--tile);
}

.album-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.6rem 0.8rem;
}

.album-title {
  font-weight: 600;
  color: var(--label);
}

.album-count {
  color: var(--fg-dim);
  font-size: 0.85rem;
}

/* --- Album header ---------------------------------------------------------- */
.album-header {
  margin-top: 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.album-headtext {
  min-width: 0;
}

.album-sub {
  margin: 0 0 0.45rem;
  color: var(--fg-dim);
  font-size: 0.9rem;
}

/* The opaque album id, demoted to a small monospace chip (tap to copy link). */
.id-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  padding: 0.2rem 0.55rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--fg-dim);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.id-chip:hover {
  color: var(--label);
  border-color: var(--accent-bd);
}

.id-chip:active {
  background: var(--hover);
}

.download-all {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--accent-bd);
  border-radius: var(--radius-sm);
  background: var(--accent-fill);
  color: var(--fg-bright);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.download-all:hover {
  background: var(--accent-fill-hi);
}

/* --- Image grid ------------------------------------------------------------ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.6rem;
  margin-top: 1rem;
}

.thumb {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--tile);
  aspect-ratio: 5 / 4;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.thumb:hover img {
  transform: scale(1.04);
}

.thumb:active {
  border-color: var(--accent-bd);
}

.badge {
  position: absolute;
  bottom: 0.4rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--fg-bright);
  background: rgba(20, 22, 26, 0.78);
  border-radius: 0.35rem;
  pointer-events: none;
}

.badge-format {
  left: 0.4rem;
  letter-spacing: 0.03em;
}

.badge-size {
  right: 0.4rem;
}

/* --- Lightbox -------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  cursor: zoom-out;
  z-index: 100;
}

.lightbox-img {
  max-width: 94vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.lightbox-actions {
  position: fixed;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  left: 1.25rem;
  right: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
}

.lightbox-close {
  pointer-events: all;
  width: 44px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 26, 0.75);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--fg-bright);
  font-size: 1.1rem;
  backdrop-filter: blur(6px);
}

.lightbox-close:hover {
  background: rgba(30, 34, 40, 0.9);
  border-color: var(--danger);
  color: var(--danger);
}

.lightbox-download {
  pointer-events: all;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1.15rem;
  background: var(--accent-fill);
  color: var(--fg-bright);
  border: 1px solid var(--accent-bd);
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  backdrop-filter: blur(6px);
}

.lightbox-download:hover {
  background: var(--accent-fill-hi);
}

.download-all-bottom {
  display: none;
}

/* --- Mobile ---------------------------------------------------------------- */
@media (max-width: 640px) {
  .container {
    margin-top: 0.5rem;
  }

  .album-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .download-all {
    width: 100%;
  }

  .album-list {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .download-all-bottom {
    display: inline-flex;
    width: 100%;
    margin-top: 0.75rem;
  }
}
