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

/* ── TOKENS ── */
:root {
  --font: 'IBM Plex Mono', 'Courier New', monospace;
  --fs: 14px;
  --fs-site: 18px;
  --sidebar-w: 250px;
  --content-w: 900px;
  --gap: 25px;
  --tr: 0.2s ease;
  --sidebar-pt: 28px;
  --pad: 28px; /* consistent horizontal padding for toolbar + content */
}

[data-theme="dark"] {
  --bg: #111;
  --fg: #c4c4c4;
  --fg-link: #959595;
  --fg-hover: #5f5f5f;
  --fg-subtle: rgba(196,196,196,0.18);
  --border: rgba(196,196,196,0.1);
  --thumb-bg: #1e1e1e;
}
[data-theme="light"] {
  --bg: #f4f4f2;
  --fg: #111111;
  --fg-link: #717171;
  --fg-hover: #5d5d5d;
  --fg-subtle: rgba(17,17,17,0.2);
  --border: rgba(17,17,17,0.1);
  --thumb-bg: #e2e2e0;
}

/* ── BASE ── */
html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--fs);
  font-weight: 400;
  height: 100%;
  overflow: hidden;
  transition: background var(--tr), color var(--tr);
  text-transform: uppercase;
}

/* ── LAYOUT ── */
#app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: var(--sidebar-pt) 0 24px 28px;
  overflow: hidden;
}

/* ── SITE NAME ── */
#site-name {
  font-size: var(--fs-site);
  font-weight: 400;
  color: var(--fg);
  line-height: 1.4;
  margin-bottom: 32px;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: none;
  padding-right: 16px;
  flex-shrink: 0;
  text-decoration: none;
  display: block;
}

/* ── NAV ── */
#main-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow: hidden; }
#desktop-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow: hidden; min-height: 0; }
.nav-item { display: flex; flex-direction: column; }

.nav-label {
  font-size: var(--fs);
  font-weight: 400;
  color: var(--fg-link);
  cursor: pointer;
  padding: 8px 16px 8px 0;
  user-select: none;
  transition: color var(--tr);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  text-transform: uppercase;
  text-align: left;
  width: 100%;
  display: block;
}
.nav-label:hover { color: var(--fg-hover); }
.nav-label.active { color: var(--fg); }

.sub-nav { display: none; flex-direction: column; padding-left: 12px; margin-bottom: 4px; }
.sub-nav.open { display: flex; }

.sub-label {
  font-size: var(--fs);
  font-weight: 400;
  color: var(--fg-link);
  cursor: pointer;
  padding: 7px 16px 7px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--tr);
  user-select: none;
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  text-transform: uppercase;
  text-align: left;
  width: 100%;
  display: block;
}
.sub-label:hover { color: var(--fg-hover); }
.sub-label.active { color: var(--fg); }

.sub-label-external {
  display: flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  width: 100%;
  margin: 0;
}
.ext-icon {
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  opacity: 0.5;
}

/* ── THEME TOGGLE ── */
#theme-toggle, #theme-toggle-mobile {
  background: none;
  border: none;
  outline: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: var(--fg-link);
  transition: color var(--tr);
  padding: 8px 0;
  -webkit-tap-highlight-color: transparent;
}
#theme-toggle:hover, #theme-toggle-mobile:hover { color: var(--fg-hover); }

/* ── CONTENT (desktop) ── */
#content {
  flex: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-gutter: stable;
  min-width: 0;
}

/* ── TOOLBAR ── */
#toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: var(--pad) var(--pad) 8px;
  padding-top: calc(var(--sidebar-pt) + var(--fs-site) * 1.4 * 3 + 32px - var(--fs));
  max-width: calc(var(--content-w) + var(--pad) * 2);
  width: 100%;
}

#toolbar-project {
  font-size: var(--fs);
  font-weight: 400;
  color: var(--fg);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-align: right;
}

.tool-btn {
  width: 26px; height: 26px;
  background: none; border: none; outline: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-link);
  transition: color var(--tr);
  flex-shrink: 0; padding: 0;
}
.tool-btn:hover { color: var(--fg-hover); }
.tool-btn.gone { display: none; }

#nav-controls { display: flex; align-items: center; gap: 4px; }
#nav-controls.gone { display: none; }

#photo-counter {
  font-size: var(--fs); color: var(--fg-link);
  min-width: 52px; text-align: center; letter-spacing: 0.02em;
}

#counter-hint {
  font-size: 11px; color: var(--fg-subtle);
  white-space: nowrap; font-weight: 300;
  letter-spacing: 0.04em; margin-left: 10px; display: none;
}

/* ── VIEWER (desktop) ── */
#viewer { width: 100%; display: block; position: relative; }

/* ── SLIDESHOW ── uses fixed so it fills viewport even inside scrolling #content */
#slideshow { position: fixed; top: 0; left: var(--sidebar-w); right: 0; bottom: 0; overflow: hidden; display: none; pointer-events: none; }

.slide-card {
  position: absolute; cursor: grab; user-select: none;
  opacity: 0; transition: opacity 0.9s ease;
  filter: drop-shadow(0 8px 32px rgba(0,0,0,0.5));
}
.slide-card.visible { opacity: 1; pointer-events: auto; }
.slide-card.dragging { cursor: grabbing; transition: none; }
.slide-card img { width: 100%; height: auto; display: block; pointer-events: none; }

/* ── SINGLE VIEW (desktop) ── */
#single-view {
  width: 100%;
  display: none; flex-direction: column; align-items: flex-start;
  padding: 0 var(--pad) 40px;
}
#single-view.active { display: flex; }

#main-photo {
  max-width: min(var(--content-w), 100%);
  width: auto; height: auto;
  display: block; object-fit: contain;
  transition: opacity 0.25s ease;
  flex-shrink: 0;
}
#main-photo.fade { opacity: 0; }

/* ── PAIRS LAYOUT ── */
#photo-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: min(var(--content-w), 100%);
  width: 100%;
}
#photo-pair img {
  width: 100%; height: auto;
  display: block; object-fit: contain;
  transition: opacity 0.25s ease;
}
#photo-pair img.fade { opacity: 0; }

#photo-desc {
  max-width: min(var(--content-w), 100%);
  font-size: var(--fs); font-weight: 300;
  color: var(--fg-link); line-height: 1.7;
  text-transform: none; letter-spacing: 0.01em;
  margin-top: 14px;
  white-space: pre-line;
}

/* ── GRID VIEW ── */
#grid-view { display: none; width: 100%; padding: 0 var(--pad) 40px; }
#grid-view.active { display: block; }

#grid-inner {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: var(--gap); max-width: var(--content-w);
}

.thumb { aspect-ratio: 3/2; overflow: hidden; background: var(--thumb-bg); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity 0.2s ease; }
.thumb:hover img { opacity: 0.6; }

/* ── PANEL VIEW ── */
#panel-view { display: none; width: 100%; padding: 0 var(--pad) 40px; }
#panel-view.active { display: block; }

/* ── INFO ── */
.info-layout { display: grid; grid-template-columns: 1fr 320px; gap: 52px; max-width: var(--content-w); align-items: start; }
.info-text { font-size: var(--fs); font-weight: 400; color: var(--fg); line-height: 1.8; text-transform: none; letter-spacing: 0.01em; }
.info-text p { margin-bottom: 20px; }
.info-text a { color: var(--fg-link); text-decoration: none; border-bottom: 1px solid var(--border); transition: color var(--tr); }
.info-text a:hover { color: var(--fg-hover); }
.info-portrait { width: 100%; display: block; object-fit: cover; background: var(--thumb-bg); min-height: 400px; }

.info-copyright {
  font-size: var(--fs);
  font-weight: 400;
  color: var(--fg-link);
  line-height: 1.8;
  text-transform: none;
  letter-spacing: 0.01em;
  margin-top: 32px;
}

/* ── NEWSLETTER ── */
.nl-wrap { max-width: var(--content-w); width: 100%; }
.nl-section-title { font-size: var(--fs); font-weight: 400; color: var(--fg); letter-spacing: 0.06em; margin-bottom: 16px; }
.nl-embed-wrap { margin-bottom: 44px; width: 100%; }
.nl-archive-title { font-size: var(--fs); font-weight: 400; color: var(--fg); letter-spacing: 0.06em; margin-bottom: 12px; }
.nl-list { list-style: none; display: flex; flex-direction: column; }
.nl-list li { font-size: var(--fs); font-weight: 400; color: var(--fg-link); padding: 8px 0; text-transform: none; letter-spacing: 0.01em; line-height: 1.4; }
.nl-list li a { color: var(--fg-link); text-decoration: none; transition: color var(--tr); }
.nl-list li a:hover { color: var(--fg-hover); }
.nl-date { color: var(--fg-subtle); margin-right: 6px; font-variant-numeric: tabular-nums; }
.nl-loading { font-size: var(--fs); color: var(--fg-subtle); padding: 12px 0; letter-spacing: 0.06em; }

/* ── MOBILE HEADER ── */
#mobile-header { display: none; }

/* ── SKIP LINK ── */
.skip-link {
  position: absolute; top: -100%; left: 0;
  background: var(--bg); color: var(--fg);
  padding: 8px 16px; font-size: var(--fs);
  z-index: 1000; text-decoration: none; text-transform: uppercase;
}
.skip-link:focus { top: 0; }

/* ── FOCUS ── */
:focus-visible { outline: 2px solid var(--fg-link); outline-offset: 2px; }

/* ────────────────────────────────────────
   MOBILE
   Simple approach: the whole page scrolls.
   No flex height tricks. No overflow games.
   ──────────────────────────────────────── */
@media (max-width: 700px) {
  /* Reset base overflow so the page can scroll */
  html, body { height: 100%; overflow: auto; }

  #app {
    flex-direction: column;
    min-height: 100%;
    height: auto;
    overflow: visible;
  }

  /* Sidebar: static, full width, sits at top, scrolls with page */
  #sidebar {
    width: 100%; height: auto !important;
    flex-direction: column;
    padding: 16px 20px 0;
    overflow: visible !important;
    flex-shrink: 0;
    position: relative !important;
    z-index: 200;
    background: var(--bg);
  }
  /* Mobile slideshow: behind the nav */
  #slideshow { position: fixed; inset: 0; left: 0; top: 0; z-index: 1; }
  #mobile-header { display: flex; align-items: center; justify-content: space-between; width: 100%; }
  #site-name { display: none; }
  #theme-toggle { display: none; }
  #mobile-nav-wrap { display: block; padding: 8px 0 12px; width: 100%; }

  /* Content: natural height, no overflow constraints */
  #content { flex: 1; height: auto; overflow: visible; min-width: 0; }
  #viewer { display: block; height: auto; overflow: visible; position: static; }

  /* Toolbar: simple bar showing project name */
  #toolbar {
    padding: 12px 16px; align-items: center;
    max-width: 100%; width: 100%;
  }
  #btn-grid, #nav-controls { display: none !important; }
  #toolbar-project { margin-left: 0; max-width: 100%; text-align: left; }

  /* Slideshow on mobile fills the content area below sidebar */
  .slide-card { max-width: 40%; }

  /* Single view: images stack vertically, 20px gap */
  #single-view {
    display: none;
    flex-direction: column; align-items: stretch;
    width: 100%; height: auto;
    overflow: visible;
    padding: 0;
  }
  #single-view.active { display: flex; }
  #main-photo { display: none; }
  #photo-desc { display: none; }
  #mobile-scroll {
    display: flex; flex-direction: column;
    width: 100%; gap: 20px;
    padding: 16px 16px 80px;
  }
  #mobile-scroll img { width: 100%; height: auto; display: block; }

  /* Grid hidden on mobile */
  #grid-view { display: none !important; }

  /* Panels */
  #panel-view { display: none; width: 100%; height: auto; overflow: visible; padding: 16px 20px 80px; }
  #panel-view.active { display: block; }

  .info-layout { grid-template-columns: 1fr; gap: 24px; }
  .info-portrait { min-height: 260px; }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--fg-subtle); border-radius: 2px; }

/* ── MOBILE SITE NAME LINK ── */
#site-name-mobile {
  font-size: 18px; font-weight: 400; letter-spacing: 0.02em;
  cursor: pointer; color: var(--fg); line-height: 1.4;
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
