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

:root {
  --bg: #ffffff;
  --surface: #f0f0f0;
  --text: #111;
  --text-dim: #999;
  --gap: 16px;
  --margin-x: 80px;
  --margin-top: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --surface: #141414;
    --text: #f0f0f0;
    --text-dim: #888;
  }
}

@media (max-width: 640px) {
  :root {
    --gap: 1px;
    --margin-x: 0px;
    --margin-top: 0px;
  }
}

html { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
body { min-height: 100dvh; touch-action: manipulation; }

/* --- Header --- */
.site-header {
  max-width: calc(900px + var(--margin-x) * 2);
  margin: 0 auto;
  padding: calc(var(--margin-top)) var(--margin-x) 24px;
}

.site-header-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 60px;
}

.site-header-links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.site-header-link {
  color: var(--text-dim);
  transition: color 0.2s ease;
  display: flex;
}

.site-header-link:hover {
  color: var(--text);
}

.site-header-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
  color: var(--text);
  filter: url(#textDistortion);
}

@media (max-width: 640px) {
  .site-header {
    padding: 32px 16px 20px;
  }
}

/* --- Grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  padding: 0 var(--margin-x);
  max-width: calc(900px + var(--margin-x) * 2);
  margin: 0 auto;
}

.grid-item {
  position: relative;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  transition: opacity 0.4s ease;
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.grid-item img.hires {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.grid-item::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: black;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
@media (hover: hover) {
  .grid-item:hover::after { opacity: 0.12; }
}
.grid-item:active::after { opacity: 0.12; }

.grid-item img.loaded { opacity: 1; }

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.lightbox::before {
  content: "";
  position: absolute;
  top: calc(-1 * env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  height: env(safe-area-inset-top, 0px);
  background: inherit;
}

.lightbox.open { display: flex; }

.lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 20px;
  height: calc(100dvh - 96px);
  width: calc((100dvh - 96px) * 9 / 16);
  max-width: calc(100vw - 200px);
}

.lightbox img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

#lb-placeholder, #lb-img {
  position: absolute;
  inset: 0;
}

#lb-placeholder {
  filter: blur(6px) saturate(0.85);
  opacity: 1;
  pointer-events: none;
  z-index: 0;
  transition: filter 0.4s ease;
}

#lb-placeholder.hidden { opacity: 0; transition: opacity 0.25s ease; }
#lb-placeholder.clean { filter: none; }

#lb-noise {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.08;
  filter: url(#grain);
  background: white;
  transition: opacity 0.3s ease;
}

#lb-noise.hidden { opacity: 0; }

#lb-img {
  z-index: 2;
  opacity: 0;
  transition: opacity 0.35s ease;
}

#lb-img.loaded {
  opacity: 1;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 120;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.lightbox-close:hover { opacity: 1; }

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 24px 28px;
  opacity: 0.4;
  transition: opacity 0.2s;
  z-index: 103;
}
.lightbox-nav svg { pointer-events: none; }
.lightbox-nav:hover { opacity: 1; }
.lightbox-prev { left: 0; }
.lightbox-next { right: 0; }

/* Desktop: nav zones at window edges (120px strips where arrows are) */
.lightbox-tap {
  display: block;
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 102;
  cursor: pointer;
}
.lightbox-tap-left { left: 0; width: 120px; }
.lightbox-tap-right { right: 0; width: 120px; }

.lightbox-meta {
  position: fixed;
  pointer-events: none;
  font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
  line-height: 1.6;
  z-index: 102;
  text-align: left;
  white-space: pre;
}
.meta-location { color: rgba(255, 255, 255, 0.85); }
.meta-date { color: rgba(255, 255, 255, 0.5); display: block; }

@media (max-width: 999px) and (min-width: 641px) {
  .lightbox-meta {
    position: fixed;
    bottom: 8px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
  }
  .meta-date { display: inline; }
}

/* tap zone gradient only on mobile */

@media (max-width: 640px) {
  .lightbox {
    background: black;
    flex-direction: column;
    justify-content: flex-start;
  }

  .lightbox-content {
    position: relative;
    width: 100%;
    height: calc(100dvh - 52px);
    max-height: none;
    max-width: none;
    aspect-ratio: auto;
    overflow: hidden;
    border-radius: 24px;
  }

  .lightbox img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  #lb-placeholder {
    filter: blur(8px) saturate(0.85);
  }

  .lightbox-nav { display: none; }

  .lightbox-close {
    position: fixed;
    z-index: 120;
    top: env(safe-area-inset-top, 8px);
    right: 8px;
    padding-top: 8px;
    opacity: 0.85;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
  }
  .lightbox-close:hover { opacity: 1; }

  .lightbox-tap {
    z-index: 110;
    transition: opacity 0.05s;
    touch-action: none;
  }
  .lightbox-tap-left {
    width: 40%;
    background: linear-gradient(to right, rgba(0,0,0,0.4), transparent);
    opacity: 0;
  }
  .lightbox-tap-right {
    width: 40%;
    background: linear-gradient(to left, rgba(0,0,0,0.4), transparent);
    opacity: 0;
  }
  .lightbox-tap.pressing { opacity: 1; }

  .lightbox-meta {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    white-space: nowrap;
    text-align: center;
    transform: none;
  }
  .meta-date { display: inline; }
}

.year-header {
  grid-column: 1 / -1;
  padding: 56px 0 6px;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  filter: url(#yearDistortion);
}

.grid-item.faded {
  opacity: 0.2;
  transition: opacity 0.4s ease;
}

@media (max-width: 640px) {
  .year-header {
    padding: 36px 16px 4px;
  }
}

/* --- Navigator --- */
.navigator {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}
.nav-selector { position: relative; }
.nav-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(255,255,255,0.55);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: #111;
  font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border: 0.5px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 6px 6px 6px 12px;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s;
  white-space: nowrap;
  filter: url(#chipDistortion);
}
#nav-city-btn { color: rgba(0,0,0,0.65); }
@media (hover: hover) {
  .nav-chip:hover { background: rgba(0,0,0,0.03); }
}
@media (prefers-color-scheme: dark) {
  .nav-chip {
    background: rgba(30,30,30,0.55);
    color: #f0f0f0;
    border-color: rgba(255,255,255,0.12);
  }
  #nav-city-btn { color: rgba(240,240,240,0.65); }
}
@media (hover: hover) and (prefers-color-scheme: dark) {
  .nav-chip:hover { background: rgba(255,255,255,0.06); }
}
.nav-dropdown {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: rgba(255,255,255,0.7);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 0.5px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  box-shadow: none;
  padding: 6px 0;
  max-height: 320px;
  overflow-y: auto;
  min-width: 100%;
}
.nav-dropdown.open { display: block; }
.nav-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  color: rgba(0,0,0,0.65);
}
.nav-dropdown button.current { font-weight: 500; color: #111; }
.nav-dropdown button:hover { background: rgba(0,0,0,0.05); }
.nav-dropdown .nav-date {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 10px;
  font-weight: 400;
  color: rgba(0,0,0,0.35);
  margin-left: 10px;
}
.nav-year-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 400;
  color: rgba(0,0,0,0.3);
  pointer-events: none;
}
.nav-year-heading:first-child { padding-top: 6px; }
.nav-year-heading hr {
  flex: 1;
  border: none;
  border-top: 1px solid rgba(0,0,0,0.1);
}
@media (prefers-color-scheme: dark) {
  .nav-dropdown {
    background: rgba(30,30,30,0.7);
    border-color: rgba(255,255,255,0.12);
  }
  .nav-dropdown button { color: rgba(240,240,240,0.65); }
  .nav-dropdown button.current { color: #f0f0f0; }
  .nav-dropdown button:hover { background: rgba(255,255,255,0.08); }
  .nav-dropdown .nav-date { color: rgba(255,255,255,0.35); }
  .nav-year-heading { color: rgba(255,255,255,0.3); }
  .nav-year-heading hr { border-top-color: rgba(255,255,255,0.1); }
}
@media (max-width: 640px) {
  .navigator {
    bottom: auto;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .navigator.mobile-visible { opacity: 1; pointer-events: auto; }
  .nav-chip { font-size: 10px; padding: 5px 5px 5px 10px; border-radius: 7px; filter: none; }
  .nav-dropdown { bottom: auto; top: calc(100% + 8px); }
  .nav-dropdown button { font-size: 12px; padding: 6px 12px; }
}

/* --- Edit Mode --- */
.edit-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  background: rgba(255,255,255,0.55);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: #111;
  font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border: 0.5px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  display: none;
  transition: background 0.15s;
}
.edit-toggle.visible { display: block; }
.edit-toggle:hover { background: rgba(255,255,255,0.7); }
.edit-toggle.active { background: rgba(0,122,255,0.85); color: #fff; border-color: rgba(0,122,255,0.9); -webkit-backdrop-filter: none; backdrop-filter: none; }
.edit-toggle.active:hover { background: rgba(0,122,255,1); }
@media (prefers-color-scheme: dark) {
  .edit-toggle { background: rgba(30,30,30,0.55); color: #f0f0f0; border-color: rgba(255,255,255,0.12); }
  .edit-toggle:hover { background: rgba(30,30,30,0.7); }
  .edit-toggle.active { background: rgba(0,122,255,0.85); color: #fff; border-color: rgba(0,122,255,0.9); }
}
@media (max-width: 640px) {
  .edit-toggle { bottom: 16px; right: 16px; font-size: 10px; padding: 5px 10px; border-radius: 7px; }
}

body.edit-mode .grid-item { cursor: grab; }
body.edit-mode .grid-item:active { cursor: grabbing; }
body.edit-mode .grid-item.dragging { opacity: 0.3; transform: scale(0.95); }
body.edit-mode .grid-item.drag-over { box-shadow: inset 0 0 0 3px rgba(0,122,255,0.7); }

body.edit-mode .grid-item .edit-hide-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
body.edit-mode .grid-item:hover .edit-hide-btn { opacity: 1; }
body.edit-mode .grid-item .edit-hide-btn:hover { background: rgba(220,40,40,0.8); }

body.edit-mode .edit-color-swatch {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.4);
  pointer-events: none;
}

.edit-toast {
  position: fixed;
  bottom: 64px;
  right: 24px;
  z-index: 55;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.edit-toast.visible { opacity: 1; }
@media (max-width: 640px) {
  .edit-toast { bottom: 52px; right: 16px; font-size: 12px; }
}

/* --- Loader --- */
.loader {
  text-align: center;
  padding: 40px 0;
  color: var(--text-dim);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--text-dim);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 120px 20px;
  color: var(--text-dim);
}
.empty-state p { font-size: 15px; }

@media (max-width: 480px) {
  .lightbox-nav { padding: 20px 12px; }
}
