:root {
  --bg: #0a0b0d;
  --bg-raised: #16171c;
  --line: #26272d;
  --ivory: #f2efe9;
  --ivory-dim: #a9a9a3;
  --brass: #b8935f;
  --radius: 4px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ivory);
  font-family: 'Inter', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* 100vh on mobile is measured against the largest possible viewport
     (address bar hidden); 100svh accounts for the toolbar actually being
     on-screen, so the layout doesn't overflow/jump when it shows or hides */
  min-height: 100svh;
}

/* ---------- Header ---------- */

.site-header {
  padding: 28px 40px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo-wrap {
  display: inline-flex;
  align-items: center;
}

.logo {
  /* was "42x" — invalid CSS unit, silently dropped by the browser,
     which left the logo with no height constraint at all */
  max-height: 42px;
  max-width: 220px;
  object-fit: contain;
}

/* This unconditional display:block was overriding the browser's own
   [hidden]{display:none} default rule (author CSS beats the UA
   stylesheet), so the broken-image icon showed up on top of the
   "Your Logo" fallback text even while the img had hidden="true".
   Scope display:block to only the non-hidden case instead. */
.logo:not([hidden]) {
  display: block;
}

.logo-fallback {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--ivory-dim);
}

/* ---------- Dark mode toggle button ---------- */

.dark-mode-btn {
  flex-shrink: 0;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ivory);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
  position: relative;
  z-index: 100;
}

.dark-mode-btn:hover {
  border-color: var(--brass);
  color: var(--brass);
}

.dark-mode-btn:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------- Carousel ---------- */

.carousel-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  min-height: 0;
  overflow: hidden; /* safety net: never let the carousel push the footer out of view */
}

.carousel {
  position: relative;
  width: 100%;
  min-height: 0; /* without this, flexbox treats the aspect-ratio box's
                    content size as a hard minimum and refuses to shrink,
                    which is what let it grow taller than the space
                    between the header and footer */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.slides {
  position: relative;
  /* Width and height come from fitStage(), so the frame takes the photo's own
     shape and uses the whole stage. These are the fallback before it runs. */
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--bg-raised);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  transition: width 0.35s ease, height 0.35s ease;
  touch-action: pan-y; /* horizontal swipes drive the carousel; vertical scroll still works */
}

.slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.slide.is-active {
  opacity: 1;
  pointer-events: auto;
}

.slide img {
  width: 100%;
  height: 100%;
  /* The frame matches the photo, so contain fills it exactly. It only crops
     for a photo too extreme to give a sane frame, handled by .is-cropped. */
  object-fit: contain;
  display: block;
}

.slides.is-cropped .slide img {
  object-fit: cover;
}

.slide figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--ivory-dim);
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  margin: 0;
}

.loading-msg,
.empty-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ivory-dim);
  font-size: 14px;
  margin: 0;
}

.nav-btn {
  /* Pinned to the stage, not laid out beside the photo: the frame resizes per
     slide, and buttons that stayed adjacent would jump hundreds of pixels. */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--ivory);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.nav-prev {
  left: 4px;
}

.nav-next {
  right: 4px;
}

.nav-btn:hover {
  border-color: var(--brass);
  color: var(--brass);
}

.nav-btn:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.carousel-meta {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 12px;
}

.counter {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 13px;
  color: var(--ivory-dim);
  letter-spacing: 0.04em;
  min-width: 48px;
}

.dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, transform 0.2s ease;
}

.dot.is-active {
  background: var(--brass);
  transform: scale(1.25);
}

.dot:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 40px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.site-footer p {
  margin: 0;
  font-size: 13px;
  color: var(--ivory-dim);
  text-align: center;
}

.site-footer a {
  color: var(--ivory-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer a:hover {
  color: var(--brass);
}

/* Hidden easter-egg message: only present at all while dark mode is on;
   even then it's black text on a black chip, readable only when selected */
.secret-msg {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 5vw;
  text-align: center;
  font-size: clamp(48px, 9vw, 180px) !important;
  line-height: 1.05;
  font-family: 'Fraunces', Georgia, serif;
  color: #080808 !important;
  background: #000 !important;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: text;
  z-index: 5; /* stays under the dark-mode button, which is z-index: 100 */
}

body.dark-mode .secret-msg {
  display: flex;
}

.secret-msg::selection {
  color: var(--ivory);
  background: var(--brass);
}

/* ---------- Dark mode (blackout) ---------- */

body.dark-mode {
  background: #000;
}

/* Black out everything except: the toggle button, the real logo image,
   and the text-logo fallback */
body.dark-mode *:not(.dark-mode-btn):not(.dark-mode-btn *):not(#logo):not(.logo-fallback):not(.secret-msg) {
  color: #000 !important;
  background: #000 !important;
  background-image: none !important;
  border-color: #000 !important;
  box-shadow: none !important;
}

/* Carousel photos can't be recolored with `color`, so drop them to black
   via a filter instead, keeping the logo untouched */
body.dark-mode .slide img {
  filter: brightness(0);
}


/* ---------- Chat bubble ---------- */

.chat-bubble {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--ivory-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.chat-bubble:hover,
.chat-bubble:focus-visible {
  border-color: var(--brass);
  color: var(--brass);
  outline: none;
}

.chat-panel {
  position: fixed;
  right: 20px;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  width: min(320px, calc(100vw - 40px));
  max-height: min(420px, calc(100vh - 140px));
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
}

/* Same fix as the logo: an unconditional display:flex here would override
   the browser's own [hidden]{display:none} default (author CSS beats the
   UA stylesheet), showing the panel immediately no matter what. Scope it. */
.chat-panel:not([hidden]) {
  display: flex;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ivory-dim);
}

.chat-close {
  background: none;
  border: none;
  color: var(--ivory-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

.chat-close:hover {
  color: var(--brass);
}

.chat-who {
  color: var(--brass);
}

.chat-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  font-size: 13px;
  color: var(--ivory-dim);
}

.chat-panel-body p {
  margin: 0 0 8px;
}

.chat-panel-body p:last-child {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .chat-bubble {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
  }
  .chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .site-header {
    padding: 16px 20px;
    flex-wrap: wrap;
    row-gap: 12px;
  }
  .dark-mode-btn {
    /* keep the tap target comfortably above the ~44px accessibility minimum */
    padding: 10px 16px;
    font-size: 13px;
  }
  .carousel-stage {
    padding: 8px 8px;
  }
  .carousel {
    gap: 6px;
  }
  .slides {
    border-radius: var(--radius);
  }
  .nav-btn {
    width: 44px;
    height: 44px;
  }
  .carousel-meta {
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .site-footer {
    padding: 14px 16px;
  }
}

@media (max-width: 400px) {
  .logo-wrap {
    max-width: 60%;
  }
  .dark-mode-btn {
    font-size: 12px;
    padding: 8px 12px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .slide { transition: none; }
}

/* ---------- Full size view ---------- */

.slide.is-active img {
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.88);
}

/* Author display:flex beats the user-agent [hidden] rule, so restate it. */
.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Tap to zoom: drop the fit constraints and let the lightbox pan instead.
   margin:auto rather than justify-content:center, because a centred flex item
   that overflows makes the start of the image unreachable. */
.lightbox.is-zoomed {
  align-items: flex-start;
  justify-content: flex-start;
  overflow: auto;
  padding: 0;
}

.lightbox img {
  cursor: zoom-in;
}

.lightbox.is-zoomed img {
  max-width: none;
  max-height: none;
  margin: auto;
  border-radius: 0;
  cursor: zoom-out;
}

/* ---------- Chat composer ---------- */

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ivory);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chat-input:focus {
  outline: none;
  border-color: var(--brass);
}

.chat-input::placeholder {
  color: var(--line);
}

.chat-send {
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--ivory-dim);
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.chat-send:hover {
  color: var(--brass);
  border-color: var(--brass);
}

/* ---------- Version marker ---------- */

/* Author display beats the user-agent [hidden] rule, so restate it. */
.site-footer .footer-marker[hidden] {
  display: none;
}

.site-footer .footer-marker {
  display: inline-block;
  margin: 0;
  padding: 2px 9px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* The full tier can be over a megabyte; without a state the tap looks dead. */
.lightbox.is-loading::after {
  content: "Loading…";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ivory-dim);
}
