:root {
  /* Without this, a browser in dark mode renders the native controls
     (dropdowns, textarea, scrollbars) dark against the white page. */
  color-scheme: light;

  --paper: #ffffff;
  --card: #ffffff;
  --placeholder: #f2f0ec;
  --ink: #24211d;
  --ink-soft: #6d675e;
  --line: #e2ded7;
  --accent: #7a5c3e;
  --danger: #9a3b2c;
  --radius: 4px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 "Iowan Old Style", Georgia, "Times New Roman", serif;
}

h1, h2 { font-weight: 600; line-height: 1.2; }
a { color: var(--accent); }

.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.9rem; }
.hint { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 0.75rem; }
.status { padding: 2rem 1.25rem; color: var(--ink-soft); }

/* ------------------------------------------------------------------ header */

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 5;
}

.home-link {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.header-right {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }

.text-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.text-button.danger { color: var(--danger); }
.back { display: inline-block; margin-bottom: 1rem; }

/* ---------------------------------------------------------------- controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.sort { font-size: 0.9rem; color: var(--ink-soft); }
select {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}
select:hover { border-color: var(--accent); }
.sort select { margin-left: 0.4rem; }

#filter-groups { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; }
.filter-group { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.filter-label { font-size: 0.9rem; color: var(--ink-soft); }
.filter-group select { max-width: 12rem; }

#album-count { margin: 0.9rem 0; font-size: 0.85rem; }

/* -------------------------------------------------------------- album list */

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.album-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}
.album-card:hover { border-color: var(--accent); }

.album-cover {
  aspect-ratio: 4 / 3;
  background: var(--placeholder);
  overflow: hidden;
}
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.album-body { padding: 0.75rem 0.85rem 0.9rem; }
.album-body h2 { margin: 0 0 0.3rem; font-size: 1.02rem; }
.album-body p { margin: 0.15rem 0; font-size: 0.85rem; }

/* -------------------------------------------------------------- album view */

#album-title { margin: 0 0 0.25rem; font-size: 1.6rem; }
#album-meta { margin: 0 0 1.5rem; font-size: 0.9rem; }

.page-group {
  padding: 1.25rem 0;
  border-top: 1px solid var(--line);
}
.page-group h2 {
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  font-weight: 600;
}

.page-scan { margin-bottom: 1rem; }
.page-thumb { display: inline-block; max-width: min(100%, 620px); }
.page-thumb img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 420px;
  aspect-ratio: auto;
  object-fit: contain;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}

.thumb {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 5px;
  line-height: 0;
}
.thumb:hover { border-color: var(--accent); }
.thumb img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }

/* ---------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* display:flex above would otherwise win over the hidden attribute. */
.lightbox[hidden] { display: none; }

.lightbox-inner {
  display: flex;
  gap: 1.5rem;
  width: 100%;
  height: 100%;
  padding: 3rem 3.25rem;
}

.lightbox-image {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.lightbox-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid var(--line);
}

.lightbox-side {
  flex: 0 0 330px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  padding-left: 1.25rem;
}
.lightbox-side h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.09em; }

.comment { padding: 0.6rem 0; border-top: 1px solid var(--line); }
.comment-head { margin: 0 0 0.2rem; font-size: 0.78rem; color: var(--ink-soft); }
.comment-body { margin: 0 0 0.3rem; white-space: pre-wrap; }

#comment-form { margin-top: 1rem; }
#comment-body {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: inherit;
  resize: vertical;
}
#comment-body:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
#comment-submit {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#comment-submit:disabled { opacity: 0.6; cursor: default; }

.lightbox-close, .lightbox-nav {
  position: absolute;
  background: none;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  opacity: 0.55;
  line-height: 1;
}
.lightbox-close:hover, .lightbox-nav:hover { opacity: 1; }
.lightbox-close { top: 0.6rem; right: 1rem; font-size: 2.2rem; }
.lightbox-nav { top: 50%; transform: translateY(-50%); font-size: 3rem; padding: 0 0.5rem; }
.lightbox-nav.prev { left: 0.25rem; }
.lightbox-nav.next { right: 0.25rem; }

/* ------------------------------------------------------------------- login */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  max-width: 380px;
  text-align: center;
}
.login-panel h1 { margin-top: 0; }
.login-panel button {
  font: inherit;
  padding: 0.5rem 1.5rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.login-panel button:disabled { opacity: 0.6; cursor: default; }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 820px) {
  .lightbox-inner { flex-direction: column; padding: 2.5rem 1rem 1rem; gap: 0.75rem; }
  .lightbox-image { flex: 0 0 45%; }
  .lightbox-side {
    flex: 1 1 auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 0.75rem;
    width: 100%;
  }
  .lightbox-nav { font-size: 2.2rem; }
  main { padding: 1rem; }
}
