/* ── Typefaces ─────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500&family=DM+Mono:wght@400&display=swap');

/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg:           #f4f2ee;
  --bg2:          #eceae5;
  --surface:      #ffffff;
  --border:       rgba(0,0,0,0.10);
  --text:         #1a1917;
  --text2:        #6b6860;
  --text3:        #a09d98;
  --accent:       #2a52a0;
  --accent-light: #dde5f4;
  --radius:       10px;
  --font:         'DM Sans', system-ui, sans-serif;
  --mono:         'DM Mono', monospace;
  --transition:   0.18s ease;
  --shadow:       0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #18171a;
    --bg2:          #211f24;
    --surface:      #2a2830;
    --border:       rgba(255,255,255,0.09);
    --text:         #eeecea;
    --text2:        #9e9ba0;
    --text3:        #5e5c60;
    --accent:       #7ea8f0;
    --accent-light: #1e2940;
    --shadow:       0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg:    0 8px 32px rgba(0,0,0,0.5);
  }
}

/* ── Reset / base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Views ──────────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── Index view ─────────────────────────────────────────────────────────────── */
#view-index { min-height: 100vh; padding-bottom: 48px; }

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  padding: 18px 24px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}

#album-title {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
  flex: 1;
  min-width: 140px;
}

/* Search bar */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 10px 6px 14px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}
.search-wrap:focus-within { box-shadow: 0 0 0 2px var(--accent); }

#search-input {
  border: none; outline: none; background: transparent;
  font-family: var(--mono); font-size: 13px; color: var(--text); width: 220px;
}
#search-input::placeholder { color: var(--text3); }

#search-btn, #clear-btn {
  background: none; border: none; cursor: pointer; color: var(--text2);
  display: flex; align-items: center; padding: 2px;
  transition: color var(--transition);
}
#search-btn:hover, #clear-btn:hover { color: var(--accent); }
#search-btn svg { width: 16px; height: 16px; }

/* Search result banner */
#search-banner {
  background: var(--accent-light); color: var(--accent);
  font-size: 13px; padding: 10px 24px;
  display: flex; align-items: center; gap: 16px;
}
#back-to-album {
  background: none; border: none; cursor: pointer; color: var(--accent);
  font-size: 13px; font-family: var(--font); text-decoration: underline; padding: 0;
}
#back-to-album:hover { opacity: 0.75; }

/* ── Thumbnail grid ─────────────────────────────────────────────────────────── */
#thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 24px;
}

@media (max-width: 480px) {
  #thumbnail-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px; padding: 16px;
  }
}

.thumb-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow);
}
.thumb-cell:hover  { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.thumb-cell:active { transform: translateY(-1px); }

/* Sub-album tiles get a slightly tinted border to distinguish them */
.thumb-subalbum {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.thumb-img-wrap {
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
}
.thumb-img-wrap img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 0.3s ease;
}
.thumb-url-favicon img {
  width: 64px; height: 64px; object-fit: contain;
}
.thumb-cell:hover .thumb-img-wrap img { transform: scale(1.04); }

.thumb-icon {
  font-size: 40px; opacity: 0.7; user-select: none;
}
.thumb-icon-svg {
  font-size: 0; /* suppress any text */
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
}

.thumb-label {
  padding: 8px 10px 4px;
  font-size: 12px; color: var(--text2);
  white-space: normal; word-break: break-word; overflow-wrap: anywhere;
  line-height: 1.4; font-family: var(--mono);
}

/* Caption snippet shown under filename in grid */
.thumb-caption-snippet {
  padding: 0 10px 8px;
  font-size: 11px; color: var(--text3);
  line-height: 1.4; font-style: italic;
}

/* "Updated mm/dd/yyyy" shown under sub-album tiles */
.thumb-mtime {
  padding: 0 10px 8px;
  font-size: 11px; color: var(--text3);
  line-height: 1.4;
}

.thumb-album {
  padding: 0 10px 8px;
  font-size: 11px; color: var(--text3);
  white-space: normal; word-break: break-word;
  overflow-wrap: anywhere; line-height: 1.4;
}

/* Sub-header HTML block (between search banner and grid) */
#subheader-block {
  padding: 12px 24px 0;
  font-size: 15px; line-height: 1.6; color: var(--text);
}
#subheader-block:empty { display: none; }

/* Footer HTML block (below the grid) */
#footer-block {
  padding: 24px 24px 16px;
  font-size: 13px; line-height: 1.6; color: var(--text2);
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
#footer-block:empty { display: none; }

/* Empty state */
#empty-state {
  text-align: center; padding: 64px 24px;
  color: var(--text3); font-size: 15px;
}

/* ── Viewer view ─────────────────────────────────────────────────────────────── */
#view-viewer {
  position: fixed; inset: 0;
  background: #0e0d0d;
  display: none; align-items: center; justify-content: center;
  overflow: hidden;
}
#view-viewer.active { display: flex; }

#viewer-bg { position: absolute; inset: 0; background: #0e0d0d; }

/* Navigation zones */
.nav-zone { position: absolute; z-index: 20; cursor: pointer; }
#zone-prev { left: 0; top: 0; bottom: 0; width: 33%; cursor: w-resize; }
#zone-next { right: 0; top: 0; bottom: 0; width: 33%; cursor: e-resize; }
#zone-up   { left: 33%; right: 33%; top: 0; height: 72px; cursor: n-resize; }

/* Hint arrows */
.nav-hint {
  position: absolute; z-index: 30;
  color: rgba(255,255,255,0.82); font-size: 48px; line-height: 1;
  pointer-events: none; opacity: 0;
  transition: opacity 0.4s ease;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  user-select: none;
}
#view-viewer.hints-visible .nav-hint { opacity: 1; }
#hint-prev { left: 20px;  top: 50%; transform: translateY(-50%); }
#hint-next { right: 20px; top: 50%; transform: translateY(-50%); }
#hint-up   { top: 18px;   left: 50%; transform: translateX(-50%); font-size: 28px; }

/* Main content */
#viewer-content {
  position: relative; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  padding: 0 0 80px; /* leave room for taller caption bar */
}

#viewer-content img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  user-select: none; -webkit-user-drag: none;
}

.viewer-embed { width: 100%; height: 100%; border: none; border-radius: 6px; }
.viewer-video { max-width: 100%; max-height: 100%; outline: none; border-radius: 4px; }

/* Audio in viewer */
.viewer-audio-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 24px;
  color: rgba(255,255,255,0.5);
}
.viewer-audio-wrap .thumb-icon-svg svg { width: 80px; height: 80px; }
.viewer-audio { width: 320px; max-width: 90vw; }

.viewer-text {
  background: rgba(255,255,255,0.07); border-radius: 8px; padding: 24px;
  color: rgba(255,255,255,0.88); font-family: var(--mono); font-size: 13px;
  line-height: 1.7; white-space: pre-wrap;
  max-width: 680px; max-height: 70vh; overflow-y: auto;
}

.viewer-fallback, .viewer-url {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: rgba(255,255,255,0.8); text-align: center;
}
.fallback-icon, .url-icon { font-size: 64px; opacity: 0.6; }
.viewer-fallback p, .viewer-url p {
  font-size: 14px; color: rgba(255,255,255,0.55);
  font-family: var(--mono); word-break: break-all; max-width: 400px;
}

.open-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 99px; color: #fff;
  font-family: var(--font); font-size: 13px; text-decoration: none;
  transition: background var(--transition);
}
.open-btn:hover { background: rgba(255,255,255,0.22); }

/* ── Caption bar ────────────────────────────────────────────────────────────── */
#viewer-caption {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 25;
  padding: 20px 96px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
}

#caption-meta {
  display: flex; align-items: baseline; gap: 10px;
}
#caption-name {
  font-family: var(--mono); font-size: 12px;
  color: rgba(255,255,255,0.75);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
#caption-exif {
  font-size: 11px; color: rgba(255,255,255,0.4);
  white-space: nowrap; flex-shrink: 0;
}

/* Sidecar caption text */
#caption-text {
  font-size: 13px; color: rgba(255,255,255,0.82);
  line-height: 1.5; font-style: italic;
  max-width: 72ch;
}
#caption-text:empty, #caption-text[hidden] { display: none; }

#caption-controls {
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: auto;
}
#caption-pos {
  font-size: 12px; color: rgba(255,255,255,0.4); white-space: nowrap;
}

/* Slideshow button */
#slideshow-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 99px;
  color: rgba(255,255,255,0.8);
  font-size: 13px; padding: 4px 12px;
  cursor: pointer; transition: background var(--transition);
  line-height: 1.6;
}
#slideshow-btn:hover { background: rgba(255,255,255,0.22); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header { padding: 12px 16px; }
  #search-input { width: 150px; }
  #viewer-content { padding: 0 0 96px; }
  #viewer-caption { padding: 16px 16px 12px; }
  #hint-prev { left: 10px; font-size: 36px; }
  #hint-next { right: 10px; font-size: 36px; }
}

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#back-to-parent,
#back-to-parent:visited {
    color: hotpink;
}
