:root {
  color-scheme: dark;
  --timeline-h: 72px;
  --bg: #15181d;
  --accent: #e0a800;
  --ink: #fff;
  --header-top: max(3.5vh, env(safe-area-inset-top));
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
a { color: inherit; }

button { font: inherit; }

.hubris-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: calc(var(--header-top) + 62px);
  pointer-events: none;
}

.section-nav {
  position: absolute;
  top: var(--header-top);
  left: 3vw;
  display: flex;
  align-items: center;
  gap: 20px;
  pointer-events: auto;
}

.section-label {
  position: absolute;
  top: calc(var(--header-top) + 63px);
  left: 3vw;
  height: 13px;
  color: rgba(255, 255, 255, .35);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: .32em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 150ms ease;
}

.section-link,
.brand-link,
.step-button,
.image-button,
.gallery-button {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  text-decoration: none;
}

.section-link {
  width: 54px;
  height: 54px;
  opacity: .45;
  transition: opacity 180ms ease;
}

.section-link svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: var(--ink);
  transform: scale(.8);
  transform-origin: center;
}

.section-link .nav-fill,
.section-link .ws-fill,
.section-link .contact-fill,
.section-link .font-letter { fill: var(--ink); }

.section-link .cell-inner,
.section-link .ws-stroke,
.section-link .contact-stroke,
.section-link .font-frame,
.section-link .hubris-stroke {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  stroke-linejoin: round;
  stroke-miterlimit: 10;
}

.section-link .font-letter {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 22px;
  font-weight: 300;
}

.section-link:hover,
.section-link:focus-visible { opacity: 1; }

.section-link:hover svg,
.section-link:focus-visible svg,
.section-link:hover .nav-fill,
.section-link:focus-visible .nav-fill,
.section-link:hover .ws-fill,
.section-link:focus-visible .ws-fill,
.section-link:hover .contact-fill,
.section-link:focus-visible .contact-fill,
.section-link:hover .font-letter,
.section-link:focus-visible .font-letter { fill: var(--accent); }

.section-link:hover .cell-inner,
.section-link:focus-visible .cell-inner,
.section-link:hover .ws-stroke,
.section-link:focus-visible .ws-stroke,
.section-link:hover .contact-stroke,
.section-link:focus-visible .contact-stroke,
.section-link:hover .font-frame,
.section-link:focus-visible .font-frame,
.section-link:hover .hubris-stroke,
.section-link:focus-visible .hubris-stroke { stroke: var(--accent); }

.section-link.is-active { opacity: 1; }
.section-link.is-active svg { fill: var(--accent); }
.section-link.is-active .hubris-stroke { stroke: var(--accent); stroke-width: 1.5; }

.brand-link {
  position: absolute;
  top: var(--header-top);
  left: 50%;
  width: 70px;
  height: 70px;
  opacity: .7;
  transform: translate(-50%, -8px);
  pointer-events: auto;
  transition: opacity 180ms ease;
}

.brand-link:hover,
.brand-link:focus-visible { opacity: 1; }
.brand-link svg { width: 100%; height: 100%; fill: var(--ink); }
.brand-link:hover svg,
.brand-link:focus-visible svg { fill: var(--accent); }

.viewer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  /* v4: no header bar any more, only a small margin around the image. */
  padding: max(3vh, env(safe-area-inset-top)) 9vw calc(max(2vh, env(safe-area-inset-bottom)) + var(--timeline-h));
  background: radial-gradient(circle at 50% 47%, rgba(40, 48, 57, .16), transparent 48%), var(--bg);
  touch-action: pan-y;
  user-select: none;
}

.image-button {
  position: relative;
  z-index: 5;
  display: grid;
  max-width: 100%;
  max-height: 100%;
  place-items: center;
  cursor: pointer;
  will-change: transform;
}

.image-button img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - max(3vh, env(safe-area-inset-top)) - max(2vh, env(safe-area-inset-bottom)) - var(--timeline-h));
  object-fit: contain;
  opacity: 0;
  transform: scale(.995);
  transition: opacity 320ms ease, transform 420ms ease;
}

body.is-ready .image-button img {
  opacity: 1;
  transform: scale(1);
}

.swipe-frame {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  padding: inherit;
  place-items: center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  will-change: transform;
}

.swipe-frame img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer.is-swiping .swipe-frame {
  visibility: visible;
  opacity: 1;
}

.gallery-button { display: none; }

/* v4: link from a Cell99 work in the stream to its place in the space. */
.space-link {
  position: fixed;
  right: 3vw;
  bottom: calc(max(2vh, env(safe-area-inset-bottom)) + var(--timeline-h) + 8px);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, .45);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: .32em;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 180ms ease, opacity 320ms ease;
}

.space-link[hidden] { display: none; }
body:not(.is-ready) .space-link { opacity: 0; }
.space-link svg { width: 26px; height: 26px; fill: currentColor; }
.space-link .cell-inner { fill: none; stroke: currentColor; stroke-width: 1; stroke-linejoin: round; }
.space-link:hover,
.space-link:focus-visible { color: var(--accent); }

.loading-mark {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity 260ms ease;
}

body.is-ready .loading-mark { opacity: 0; }
.loading-mark svg { width: 44px; height: 44px; transform: rotate(-90deg); }
.loading-mark circle {
  fill: none;
  stroke: #263039;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  animation: loading 1100ms ease-in-out infinite;
}

.step-button {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  width: 50vw;
  height: auto;
  overflow: hidden;
  color: rgba(255,255,255,.25);
  cursor: pointer;
  transition: color 180ms ease, opacity 180ms ease;
}

.step-button:hover,
.step-button:focus-visible { color: var(--accent); }
.step-button:disabled { opacity: .08; cursor: default; }
.step-button svg { width: 48px; height: 48px; }
.step-button path { fill: none; stroke: currentColor; stroke-width: 1.25; }
/* v4: older on the left, newer on the right. */
.step-older { left: 0; justify-content: center; }
.step-newer { right: 0; justify-content: center; }

dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border: 0;
  color: var(--ink);
  background: rgba(21, 24, 29, .985);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.is-archive-open {
  overflow-y: auto;
}

body.is-archive-open .hubris-header {
  position: relative;
  inset: auto;
}

body.is-archive-open .viewer {
  display: none;
}

body.is-archive-open dialog {
  position: relative;
  inset: auto;
  min-height: 100vh;
  height: auto;
  overflow: visible;
}

body.is-archive-open .archive-grid {
  padding-top: 30px;
}

.archive-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.4vw;
  width: min(88vw, 1480px);
  margin: 0 auto;
  padding: calc(var(--header-top) + 86px) 0 max(6vh, env(safe-area-inset-bottom));
}

.archive-item {
  appearance: none;
  position: relative;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #0e1013;
  cursor: pointer;
  aspect-ratio: 1;
}

.archive-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  transition: border-color 180ms ease;
}

.archive-item:hover::after,
.archive-item:focus-visible::after,
.archive-item.is-current::after { border-color: var(--accent); }
.archive-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* v4: Cell99 works in the archive carry a small corner mark. */
.archive-item.is-cell::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  width: 9px;
  height: 9px;
  border-top: 1px solid var(--accent);
  border-left: 1px solid var(--accent);
}

@keyframes loading {
  from { stroke-dashoffset: 100; opacity: .4; }
  75% { stroke-dashoffset: 0; opacity: 1; }
  to { stroke-dashoffset: 0; opacity: 0; }
}

@media (max-width: 820px), (pointer: coarse) {
  :root { --header-top: max(2.5vh, env(safe-area-inset-top)); }

  .hubris-header { height: calc(var(--header-top) + 52px); }
  .section-nav { left: 4vw; gap: 8px; }
  .section-label { display: none; }
  .section-link { width: 42px; height: 42px; }
  .desktop-only, .hubris-link { display: none; }

  body.is-empty .cell-link { display: block; }

  .brand-link {
    width: 52px;
    height: 52px;
    transform: translate(-50%, -5px);
  }

  .viewer {
    padding: calc(var(--header-top) + 62px) 0 calc(max(58px, calc(env(safe-area-inset-bottom) + 44px)) + var(--timeline-h));
    touch-action: pan-y;
  }

  .image-button { width: 100%; cursor: default; }
  .image-button img {
    max-height: calc(100vh - var(--header-top) - 126px - env(safe-area-inset-bottom) - var(--timeline-h));
    width: 100%;
  }

  .gallery-button {
    position: fixed;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 50%;
    z-index: 8;
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    color: rgba(255, 255, 255, .42);
    transform: translateX(-50%);
  }

  .gallery-button svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
  }

  .space-link {
    bottom: max(10px, env(safe-area-inset-bottom));
    right: 4vw;
    height: 42px;
  }

  .space-link span { display: none; }

  .gallery-button:active,
  .gallery-button:focus-visible { color: var(--accent); }

  .archive-grid {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px;
    padding: calc(var(--header-top) + 66px) 0 max(4vh, env(safe-area-inset-bottom));
  }

  body.is-archive-open .archive-grid { padding-top: 12px; }

}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 1ms !important; animation: none !important; }
}

/* ---------------------------------------------------------------- v4 time axis */

.timeline {
  position: fixed;
  right: 0;
  bottom: max(2vh, env(safe-area-inset-bottom));
  left: 0;
  z-index: 9;
  height: var(--timeline-h);
  user-select: none;
}

.timeline[hidden],
body.is-archive-open .timeline { display: none; }

.timeline__track {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

.timeline__track:active { cursor: grabbing; }

/* The colour band is drawn into a canvas (v4/timeline.js). */
.timeline__band {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Hover preview above the band (mouse only). */
.timeline__peek {
  position: absolute;
  bottom: calc(50% + 14px);
  left: 0;
  width: 96px;
  height: 120px;
  margin-left: -48px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  pointer-events: none;
}

.timeline__peek[hidden] { display: none; }

@media (max-width: 820px), (pointer: coarse) {
  :root { --timeline-h: 64px; }

  .timeline { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 44px); }
}

/* ---------------------------------------------------------------- v4 editing tools (signed in only) */

.edit-bar {
  position: fixed;
  top: max(2.4vh, env(safe-area-inset-top));
  right: max(2.4vw, env(safe-area-inset-right));
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 6px;
}

.edit-bar[hidden] { display: none; }
.edit-bar.is-busy { opacity: .55; pointer-events: none; }

.edit-bar__button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  min-width: 34px;
  height: 34px;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid rgba(224, 168, 0, .55);
  border-radius: 17px;
  color: var(--accent);
  background: rgba(21, 24, 29, .72);
  font: inherit;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: .24em;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.edit-bar__button[hidden] { display: none; }
.edit-bar__button:hover,
.edit-bar__button:focus-visible { color: #15181d; background: var(--accent); }

.edit-bar__message {
  max-width: 34vw;
  color: rgba(255, 255, 255, .6);
  font-size: 11px;
}

.edit-bar__button--add { padding: 0; font-size: 18px; letter-spacing: 0; }
