:root {
  --bg: #fff;
  --fg: #111;
  --muted: #555;
  --sidebar-w: 250px;
  --gutter: 44px;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  padding: 40px 0 30px var(--gutter);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.brand {
  font-size: 21px;
  line-height: 1.2;
  text-decoration: none;
  margin-bottom: 40px;
}

.nav { display: flex; flex-direction: column; gap: 12px; }
.nav a {
  font-size: 15px;
  text-decoration: none;
  color: var(--muted);
  transition: color .2s;
}
.nav a:hover { color: var(--fg); }
.nav a.active { color: var(--fg); font-weight: 600; }
.nav a.gallery-link { font-weight: 700; }

.menu-toggle { display: none; font-size: 15px; text-decoration: underline; }

.copyright {
  margin-top: auto;
  font-size: 12px;
  line-height: 1.4;
}

/* ---------- Main ---------- */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 var(--gutter) 30px 0;
}

.toolbar {
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-bottom: 12px;
}

.pager, .grid-title { font-size: 14px; }
.pager a { text-decoration: underline; }
.pager a:hover { text-decoration: none; }
.counter { margin-left: 14px; color: var(--muted); }
.grid-title { font-weight: 600; }

.view-toggle { width: 28px; height: 28px; display: grid; place-items: center; }
.icon-grid {
  width: 15px; height: 15px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
}
.icon-grid i { background: var(--fg); }
.icon-close { display: none; font-size: 30px; line-height: 1; font-weight: 300; }
body.grid-mode .icon-grid { display: none; }
body.grid-mode .icon-close { display: block; }
body.page-mode .view-toggle,
body.page-mode .pager { visibility: hidden; }

/* ---------- Slideshow ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.slide {
  margin: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.slide img {
  /* Leave room underneath for the title; width/height stay in proportion. */
  flex: none;
  max-width: 100%;
  max-height: calc(100% - 34px);
  width: auto;
  height: auto;
  display: block;
  opacity: 0;
  transition: opacity .45s ease;
}
.slide img.loaded { opacity: 1; }

/* Image title: under the photo, lined up with its left edge.
   script.js sets its width to match the photo. */
.slide figcaption {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
  min-height: 1em;
  text-align: left;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity .45s ease;
}
.slide img.loaded + figcaption { opacity: 1; }

/* Invisible click zones: left half = previous, right half = next */
.hit {
  position: absolute;
  top: 0; bottom: 0;
  width: 50%;
}
.hit-prev { left: 0;  cursor: w-resize; }
.hit-next { right: 0; cursor: e-resize; }

/* ---------- Thumbnail grid ---------- */
.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 36px 40px;
  align-items: center;
  justify-items: center;
  padding: 10px 0 40px;
  animation: fade .4s ease;
}
.grid[hidden] { display: none; }

.thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: opacity .2s;
}
.thumb:hover img { opacity: .7; }
.thumb.current img { outline: 1px solid var(--fg); outline-offset: 4px; }

/* ---------- Text pages ---------- */
.page {
  max-width: 600px;
  font-size: 16px;
  line-height: 1.6;
  animation: fade .4s ease;
}
.page h1 { font-size: 22px; font-weight: 400; margin: 0 0 18px; }
.page form { display: grid; gap: 12px; margin-top: 24px; }
.page label { display: grid; gap: 6px; font-size: 14px; }
.page input, .page textarea {
  font: inherit;
  border: 1px solid #ccc;
  padding: 8px;
  border-radius: 0;
}
.page button[type="submit"] {
  justify-self: start;
  border: 1px solid var(--fg);
  padding: 9px 22px;
  font-size: 15px;
}
.page .note { color: var(--muted); font-size: 14px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

[hidden] { display: none !important; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --gutter: 16px; }

  .sidebar {
    position: static;
    width: auto;
    padding: 20px var(--gutter) 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
  }
  .brand { margin-bottom: 0; }
  .menu-toggle { display: block; }
  .nav { display: none; width: 100%; padding: 18px 0 4px; gap: 12px; }
  .nav a { font-size: 17px; }
  .sidebar.open .nav { display: flex; }
  .copyright { display: none; }

  .main { margin-left: 0; height: auto; min-height: calc(100vh - 70px); padding: 0 var(--gutter) 24px; }
  .toolbar { height: 56px; }
  .pager, .grid-title { font-size: 15px; }
  .stage { height: calc(100vh - 150px); flex: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 20px; overflow: visible; }
}
