:root {
  color-scheme: light;
  --paper: #efe7da;
  --ink: #1f1b16;
  --ink-soft: rgba(31, 27, 22, 0.66);
  --tile-size: 196px;
  --tile-size-current: 196px;
  --tile-gap: 10px;
  --label-opacity: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.78), transparent 36%),
    linear-gradient(180deg, #f6f0e7 0%, var(--paper) 100%);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  overscroll-behavior: none;
}

.viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.45), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0)),
    linear-gradient(145deg, rgba(251, 244, 233, 0.92), rgba(228, 213, 189, 0.86));
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

.viewport:active,
.viewport.is-dragging {
  cursor: grabbing;
}

.zoom-meter {
  position: absolute;
  top: 50%;
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  width: 22px;
  height: min(188px, 36vh);
  opacity: 0;
  transform: translateY(-50%) scale(0.96);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.zoom-meter.is-visible {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.zoom-meter-track {
  position: absolute;
  inset: 0;
}

.zoom-meter-track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: rgba(255, 250, 244, 0.34);
  box-shadow: 0 0 0 1px rgba(28, 23, 18, 0.08);
}

.zoom-meter-stop {
  position: absolute;
  left: 50%;
  width: 10px;
  height: 2px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: rgba(255, 250, 244, 0.78);
}

.zoom-meter-thumb {
  position: absolute;
  left: 50%;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: #1f1b16;
  box-shadow:
    0 0 0 1px rgba(255, 251, 244, 0.92),
    0 4px 12px rgba(31, 27, 22, 0.24);
}

.wall {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.tile {
  position: absolute;
  min-width: 0;
  overflow: hidden;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.2);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.8),
    0 14px 28px rgba(52, 39, 27, 0.14);
  cursor: pointer;
  outline: none;
}

.tile-figure {
  width: 100%;
  height: 100%;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #d8c8b0;
  -webkit-user-drag: none;
  user-select: none;
}

.tile-meta {
  position: absolute;
  inset: auto 0 0 0;
  display: grid;
  gap: 5px;
  padding: 40px 14px 14px;
  background: linear-gradient(180deg, transparent 0%, rgba(12, 10, 8, 0.74) 100%);
  opacity: var(--label-opacity);
  transition: opacity 180ms ease;
  pointer-events: none;
}

.tile-date,
.tile-title {
  min-width: 0;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.tile-date {
  font-family: "SF Mono", "Monaco", "Cascadia Mono", "Roboto Mono", monospace;
  font-size: 0.72rem;
  color: rgba(255, 248, 238, 0.82);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tile-title {
  color: #fffaf4;
  font-size: clamp(0.64rem, calc(0.46rem + var(--tile-size-current) * 0.002), 1rem);
  line-height: 1.06;
}

.tile:focus-visible {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.86),
    0 0 0 2px rgba(27, 23, 19, 0.42),
    0 14px 28px rgba(52, 39, 27, 0.14);
}

.no-script {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.no-script {
  margin: 0 18px 18px;
}

.viewer {
  --viewer-backdrop-opacity: 0.98;
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, var(--viewer-backdrop-opacity));
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, background-color 120ms linear;
  touch-action: none;
}

.viewer.is-open {
  opacity: 1;
  pointer-events: auto;
}

.viewer-stage {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.viewer-frame {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  will-change: transform, opacity;
}

.viewer img {
  display: block;
  width: 100vw;
  height: 100vh;
  object-position: center center;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.viewer-meta {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 31;
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.viewer-meta::before {
  content: "";
  position: absolute;
  inset: -64px -16px -16px;
  z-index: -1;
  border-radius: 28px;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.74) 58%, rgba(0, 0, 0, 0.9) 100%);
}

.viewer-date,
.viewer-title {
  min-width: 0;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.viewer-date {
  font-family: "SF Mono", "Monaco", "Cascadia Mono", "Roboto Mono", monospace;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 247, 236, 0.78);
}

.viewer-title {
  color: #fffaf4;
  font-size: clamp(1.05rem, 2.5vw, 1.55rem);
  line-height: 1.08;
}

@media (max-width: 840px) {
  :root {
    --tile-size: 172px;
    --tile-gap: 12px;
  }
}

@media (max-width: 580px) {
  :root {
    --tile-size: 156px;
    --tile-gap: 10px;
  }

  .zoom-meter {
    width: 18px;
    height: min(148px, 30vh);
  }

  .tile {
    border-radius: 14px;
  }
}
