:root {
  color: #102f49;
  background: #b9ddfa;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #b9ddfa;
  overscroll-behavior: none;
}

button, input { font: inherit; }
button { cursor: pointer; }

main { min-height: 100vh; min-height: 100dvh; }

.unlock {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  opacity: 1;
  transition: opacity 900ms ease;
}

.unlock.is-opening { opacity: 0; pointer-events: none; }

.unlock form {
  width: min(100%, 20rem);
  padding: 2.25rem 2rem;
  border: 0;
  border-radius: 1.1rem;
  background: rgba(255, 255, 255, .26);
  box-shadow: 0 1.5rem 4rem rgba(30, 79, 119, .12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

h1 { margin: 0 0 2.25rem; font-size: 1.6rem; font-weight: 500; letter-spacing: -.03em; text-align: center; }
label { display: block; margin-bottom: .35rem; color: #315b7b; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
input, .unlock button {
  width: 100%;
  min-height: 2.75rem;
}
input {
  -webkit-appearance: none;
  appearance: none;
  padding: .55rem 0;
  border: 0;
  border-bottom: 1px solid #527fa2;
  border-radius: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  color: #102f49;
  caret-color: #174f79;
}
input:focus { border-bottom-color: #123f62; box-shadow: 0 1px 0 #123f62; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: #102f49;
  -webkit-box-shadow: 0 0 0 1000px #c8e5fa inset;
  border-bottom: 1px solid #527fa2;
  transition: background-color 9999s ease-out 0s;
}
.unlock button {
  margin-top: 1.35rem;
  border: 1px solid #315f84;
  border-radius: 999px;
  background: transparent;
  color: #173f5f;
}
.unlock button:hover { background: rgba(255, 255, 255, .2); }
.unlock button:disabled { cursor: wait; opacity: .65; }
.message { min-height: 1.25rem; margin: .75rem 0 0; color: #8a2634; font-size: .9rem; text-align: center; }

.gallery {
  position: relative;
  width: min(74rem, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  padding: clamp(1rem, 4vw, 3.5rem) clamp(1rem, 4vw, 3.5rem) 7rem;
  align-content: center;
}

.gallery:not([hidden]) { display: grid; }
.slide { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.5rem, 5vw, 4.5rem); align-items: center; }
.slide.is-even .image-frame { order: 2; }
.slide.is-even #slide-text { order: 1; }
.image-frame { display: grid; min-height: 18rem; place-items: center; }
.image-frame img { display: block; width: 100%; max-height: 72vh; border-radius: .85rem; clip-path: inset(0 round .85rem); opacity: 0; object-fit: contain; transition: opacity 1100ms ease-in-out; will-change: opacity; }
.image-frame img.is-visible { opacity: 1; }
#slide-text { margin: 0; white-space: pre-wrap; opacity: 1; font-size: clamp(1.05rem, 2vw, 1.35rem); line-height: 1.75; transition: opacity 850ms ease; }
#slide-text.is-clearing { opacity: 0; }
.caption-letter { opacity: 0; transition: opacity 480ms ease; }
.caption-letter.is-visible { opacity: 1; }
.controls {
  position: absolute;
  bottom: clamp(1.5rem, 4vh, 3rem);
  left: 50%;
  display: grid;
  grid-template-columns: 2.8rem auto 2.8rem;
  gap: .85rem;
  align-items: center;
  padding: .45rem .55rem;
  border: 1px solid rgba(36, 77, 109, .18);
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  box-shadow: 0 .75rem 2.5rem rgba(25, 72, 108, .1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateX(-50%);
}
.controls button {
  display: grid;
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(36, 77, 109, .28);
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #173f5f;
  font-size: 1.2rem;
  line-height: 1;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}
.controls button:hover:not(:disabled) { border-color: rgba(23, 63, 95, .55); background: rgba(255, 255, 255, .38); transform: translateY(-1px); }
.controls button:first-child { justify-self: end; }
.controls button:last-child { justify-self: start; }
.controls button:disabled { cursor: default; opacity: .3; }
#counter { min-width: 3.25rem; color: #456984; opacity: 0; font-size: .78rem; font-variant-numeric: tabular-nums; letter-spacing: .08em; text-align: center; transition: opacity 650ms ease; }
#counter.is-visible { opacity: 1; }

button:focus-visible { outline: 3px solid #1c527c; outline-offset: 2px; }
noscript { display: block; padding: 2rem; text-align: center; }

@media (max-width: 43rem) {
  .unlock {
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  }
  .unlock form { padding: 1.75rem 1.4rem; }
  .unlock input { font-size: 1rem; }

  .gallery {
    min-height: 100svh;
    padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    align-content: stretch;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }
  .slide {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(12rem, 52svh) minmax(4.5rem, auto);
    gap: clamp(.8rem, 2.5vh, 1.25rem);
    align-content: start;
  }
  .slide.is-even .image-frame, .slide.is-even #slide-text { order: initial; }
  .image-frame { min-width: 0; min-height: 0; height: 100%; }
  .image-frame img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
  #slide-text {
    min-height: 4.5rem;
    max-height: 18svh;
    overflow-y: auto;
    font-size: 1rem;
    line-height: 1.55;
    text-align: center;
    -webkit-overflow-scrolling: touch;
  }
  .controls {
    position: static;
    left: auto;
    width: fit-content;
    min-height: 0;
    margin-top: .45rem;
    padding: .4rem .5rem;
    box-shadow: none;
    justify-self: center;
    transform: none;
  }
  .controls button { width: 2.65rem; min-width: 2.65rem; height: 2.65rem; min-height: 2.65rem; }
}

@media (max-width: 43rem) and (orientation: landscape) {
  .gallery { overflow: auto; }
  .slide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .slide.is-even .image-frame { order: 2; }
  .slide.is-even #slide-text { order: 1; }
  .image-frame { min-height: 65svh; }
  #slide-text { max-height: 65svh; align-self: center; }
}

@media (prefers-reduced-motion: no-preference) {
  .gallery { animation: gallery-in 500ms ease both; }
}

@media (prefers-reduced-motion: reduce) {
  .unlock, .image-frame img, #slide-text, .caption-letter, #counter { transition-duration: 0.01ms; }
}

@keyframes gallery-in { from { opacity: 0; } to { opacity: 1; } }
