/* ================= gallery =================
   One screen, solid background, same pixel-border language as the nav and buttons.
   Page   = tiles (one per place).
   Click  = a file-explorer window. Click a photo = the viewer, which plays. */

/* the animated dots are switched off on this page (app.js adds .on-gallery) */
html.on-gallery #bg-root { display: none !important; }

#gallery-section.section { position: fixed; inset: 0; z-index: 1; max-width: none; min-height: 0; margin: 0; padding: var(--nav-h) 0 0; overflow: hidden; background: var(--bg); }
.g-ico { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: miter; }
.g-ico.fill { fill: currentColor; stroke: none; }
img.in { opacity: 1 !important; }
.g-miss { background: repeating-linear-gradient(135deg, transparent 0 8px, color-mix(in srgb, var(--ink) 10%, transparent) 8px 10px); }
.g-miss::after { content: 'image not found'; position: absolute; left: 10px; bottom: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); }

/* ---------- the page ---------- */
.g-page { height: 100%; max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; padding: clamp(12px, 3vh, 32px) var(--pad) clamp(14px, 3vh, 30px); }
.g-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 6px 24px; }
#gallery-section .g-head h2 { margin: 0; font-size: clamp(34px, 6vh, 58px); line-height: 1.1; }
.g-sub { margin: 2px 0 0; color: var(--ink-dim); font-size: 20px; }
.g-meta { display: flex; gap: 18px; margin: 0 0 6px; font-family: var(--font-mono); font-size: 12px; letter-spacing: .04em; color: var(--ink-dim); }
.g-empty { padding: 40px 0; font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim); }

/* tiles: they share the screen height, so the page never scrolls */
.g-tiles { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); grid-auto-rows: minmax(200px, 560px); align-content: center; gap: 46px clamp(18px, 3vw, 36px); overflow-y: auto; padding: 36px 8px 10px 3px; }
.g-tile { position: relative; display: flex; flex-direction: column; min-height: 0; padding: 10px; background: var(--bg); border: 2px solid var(--ink); box-shadow: 6px 6px 0 rgba(0,0,0,.14);
  transition: transform .1s steps(2, end), box-shadow .1s steps(2, end); }
.g-tile:hover, .g-tile:focus-visible { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 rgba(0,0,0,.2); }
.g-tile:active { transform: translate(1px, 1px); box-shadow: 2px 2px 0 rgba(0,0,0,.12); }
/* the little folder tab on top of every tile */
.g-tab { position: absolute; left: -2px; bottom: calc(100% - 2px); z-index: 2; display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 14px 2px 10px; background: var(--bg); border: 2px solid var(--ink); border-bottom: 0;
  font-family: var(--font-ui); font-size: 12px; font-weight: 700; text-transform: lowercase; white-space: nowrap; transition: background .1s steps(2), color .1s steps(2); }
.g-tile:hover .g-tab, .g-tile:focus-visible .g-tab { background: var(--ink); color: var(--bg); }
.g-dot { width: 7px; height: 7px; background: currentColor; animation: g-blink 1.2s steps(2, jump-none) infinite; }
@keyframes g-blink { 0% { opacity: 1; } 100% { opacity: .15; } }
.g-tile-pic { position: relative; flex: 1; min-height: 0; overflow: hidden; background: color-mix(in srgb, var(--ink) 9%, var(--bg)); border: 2px solid var(--ink); }
.g-tile-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .4s steps(6), transform .5s ease; }
.g-tile:hover .g-tile-pic img { transform: scale(1.04); }
.g-tile-info { display: block; padding: 12px 2px 2px; }
.g-tile-info h3 { margin: 0 0 4px; font-style: italic; font-weight: 400; font-size: clamp(26px, 3.2vw, 36px); line-height: 1.1; }
.g-line { display: block; font-family: var(--font-mono); font-size: 12px; letter-spacing: .03em; line-height: 1.7; color: var(--ink-dim); }

/* ---------- the explorer window ---------- */
.g-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; padding: 2vh 2vw; background: color-mix(in srgb, var(--bg) 88%, transparent); animation: g-in .18s steps(4, end); }
@keyframes g-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.g-overlay[hidden], .g-lb[hidden] { display: none; }
html.g-lock { overflow: hidden; }
html.g-open .controls { opacity: 0; pointer-events: none; }
.g-win { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; width: min(1120px, 100%); height: min(720px, 100%); background: var(--bg); color: var(--ink); border: 2px solid var(--ink); box-shadow: 8px 8px 0 rgba(0,0,0,.28); outline: none; }
.g-titlebar { display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 12px; padding-top: calc(5px + env(safe-area-inset-top, 0px)); background: var(--ink); color: var(--bg); font-family: var(--font-ui); font-size: 13px; font-weight: 700; text-transform: lowercase; }
.g-tb-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-x { width: 28px; height: 24px; display: grid; place-items: center; padding: 0; background: var(--bg); color: var(--ink); border: 2px solid var(--bg); font-family: var(--font-ui); font-size: 16px; line-height: 1; }
.g-x:hover { background: var(--ink); color: var(--bg); }
.g-addr { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 2px solid var(--ink); }
.g-up, .g-playall { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 30px; padding: 0 12px; background: var(--bg); color: var(--ink); border: 2px solid var(--ink); box-shadow: 2px 2px 0 rgba(0,0,0,.12);
  font-family: var(--font-ui); font-size: 13px; font-weight: 700; text-transform: lowercase; line-height: 1; }
.g-up:hover, .g-playall:hover { background: var(--ink); color: var(--bg); }
.g-path { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border: 2px solid var(--ink); font-family: var(--font-ui); font-size: 13px; font-weight: 700; text-transform: lowercase; white-space: nowrap; overflow: hidden; }
.g-path a:hover { text-decoration: underline; }
.g-path i { font-style: normal; opacity: .55; }
.g-path b { overflow: hidden; text-overflow: ellipsis; }

.g-wbody { display: grid; grid-template-columns: 190px minmax(0, 1fr) 290px; min-height: 0; }
.g-side { padding: 12px 0; overflow: auto; border-right: 2px solid var(--ink); }
.g-side-h { margin: 0; padding: 0 14px 8px; font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; color: var(--ink-dim); }
.g-side-item { display: flex; align-items: center; gap: 9px; padding: 7px 14px; font-family: var(--font-ui); font-size: 13px; font-weight: 700; text-transform: lowercase; }
.g-side-item small { margin-left: auto; font-family: var(--font-mono); font-size: 11px; font-weight: 400; opacity: .7; }
.g-side-item:hover, .g-side-item.on { background: var(--ink); color: var(--bg); }

.g-files { overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; align-content: start; }
.g-file { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; box-sizing: border-box; margin: 0; padding: 6px; background: none; border: 2px solid transparent; text-align: left; cursor: pointer; }
.g-thumb { position: relative; display: block; width: 100%; box-sizing: border-box; aspect-ratio: 4 / 3; overflow: hidden; background: color-mix(in srgb, var(--ink) 9%, var(--bg)); border: 2px solid var(--ink); }
.g-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .35s steps(6); }
.g-fname { display: block; padding: 1px 3px; font-style: italic; font-size: 17px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-fmeta { display: block; padding: 0 3px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); }
.g-file:hover, .g-file:focus-visible { border-color: var(--ink); }
.g-file:hover .g-fname, .g-file:focus-visible .g-fname { background: var(--ink); color: var(--bg); }

.g-info { padding: 16px 16px 22px; overflow: auto; border-left: 2px solid var(--ink); }
.g-info h3 { margin: 0 0 8px; font-style: italic; font-weight: 400; font-size: 27px; line-height: 1.15; }
.g-i-text { margin: 0 0 4px; color: var(--ink-dim); font-size: 18px; line-height: 1.5; }
.g-info dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; margin: 16px 0 0; font-size: 17px; line-height: 1.35; }
.g-info dt { padding-top: 3px; font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em; color: var(--ink-dim); }
.g-info dd { margin: 0; overflow-wrap: anywhere; }
.g-status { display: flex; justify-content: space-between; gap: 12px; padding: 5px 12px; padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px)); border-top: 2px solid var(--ink); font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); }

/* ---------- the viewer: always a dark room, so the photograph is judged on black ---------- */
.g-lb { position: fixed; inset: 0; z-index: 3000; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #070707; color: #f4f4f4; outline: none; animation: g-in .18s steps(4, end); }
.g-lb-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
.g-lb-count { font-family: var(--font-mono); font-size: 12px; letter-spacing: .05em; color: rgba(255,255,255,.62); }
.g-lb-ctl { display: flex; gap: 10px; }
.g-lbtn { height: 36px; min-width: 36px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: rgba(0,0,0,.6); color: #fff; border: 2px solid #fff; font-family: var(--font-ui); font-size: 13px; font-weight: 700; text-transform: lowercase; line-height: 1; cursor: pointer; transition: background .1s steps(2), color .1s steps(2); }
.g-lbtn:hover { background: #fff; color: #000; }
.g-lbtn:focus-visible { outline: 2px dashed #fff; outline-offset: 3px; }
.g-lb-stage { position: relative; min-height: 0; }
.g-lb-scroll { position: absolute; inset: 0; display: flex; padding: 6px 14px; overflow: auto; }
.g-lb-scroll img { margin: auto; display: block; flex: none; max-width: 100%; max-height: 100%; width: auto; height: auto; opacity: 0; transition: opacity .3s steps(6); cursor: zoom-in; }
.g-lb.zoom .g-lb-scroll img { max-width: none; max-height: none; cursor: zoom-out; }
.g-lb-prev, .g-lb-next { position: absolute; top: 50%; transform: translateY(-50%); z-index: 6; width: 40px; padding: 0; font-size: 26px; }
.g-lb-prev { left: 14px; } .g-lb-next { right: 14px; }
.g-lb.zoom .g-lb-prev, .g-lb.zoom .g-lb-next { opacity: .35; }
.g-lb-bar { position: relative; display: grid; gap: 3px; padding: 14px 20px; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 2px solid rgba(255,255,255,.85); background: #0d0d0d; }
.g-lb-prog { position: absolute; left: 0; top: -2px; width: 100%; height: 2px; background: #fff; transform: scaleX(0); transform-origin: left; }
.g-lb-prog.run { animation: g-prog var(--sec, 4s) linear forwards; }
.g-lb.zoom .g-lb-prog { animation-play-state: paused; }
@keyframes g-prog { to { transform: scaleX(1); } }
.g-lb-cap { margin: 0; font-style: italic; font-size: 23px; line-height: 1.25; }
.g-lb-story { margin: 0 0 3px; max-width: 80ch; font-size: 17px; line-height: 1.45; color: rgba(255,255,255,.72); }
.g-lb-story:empty, .g-lb-info:empty { display: none; }
.g-lb-info { margin: 0; font-family: var(--font-mono); font-size: 12px; letter-spacing: .03em; color: rgba(255,255,255,.62); }

/* ---------- smaller screens ---------- */
@media (max-width: 900px) {
  .g-wbody { grid-template-columns: minmax(0, 1fr) 250px; }
  .g-side { display: none; }
}
@media (max-width: 700px) {
  .g-page { padding-bottom: 14px; }
  .g-sub { font-size: 18px; }
  .g-tiles { gap: 44px 0; padding-right: 6px; }
  .g-tile-info { padding-right: 70px; }          /* keep the text clear of the floating language / theme buttons */
  .g-overlay { padding: 0; display: block; }
  .g-win { width: 100%; height: 100%; border: 0; box-shadow: none; }
  .g-wbody { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .g-files { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
  .g-info { border-left: 0; border-top: 2px solid var(--ink); max-height: 34vh; padding: 12px 14px 16px; }
  .g-info h3 { font-size: 23px; }
  .g-info dl { margin-top: 10px; font-size: 16px; }
  #g-hint { display: none; }
  .g-lb-prev { left: 6px; } .g-lb-next { right: 6px; }
  .g-lb-scroll { padding: 4px 6px; }
  .g-lb-cap { font-size: 20px; }
}
@media (max-height: 560px) { .g-tile-info .g-line:nth-of-type(3) { display: none; } }

/* ================= touch + small screens ================= */
/* scrolling inside the album / viewer never drags the page or triggers pull-to-refresh */
.g-tiles, .g-files, .g-info, .g-side, .g-lb-scroll { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
html.g-lock, html.g-lock body { overscroll-behavior: none; }

/* no "stuck hover" after a tap */
@media (hover: none) {
  #g-hint { display: none; }
  .g-tile:hover { transform: none; box-shadow: 6px 6px 0 rgba(0,0,0,.14); }
  .g-tile:hover .g-tab { background: var(--bg); color: var(--ink); }
  .g-tile:hover .g-tile-pic img { transform: none; }
  .g-tile:active { transform: translate(1px, 1px); box-shadow: 2px 2px 0 rgba(0,0,0,.12); }
  .g-up:hover, .g-playall:hover, .g-x:hover { background: var(--bg); color: var(--ink); }
  .g-file:hover { border-color: transparent; }
  .g-file:hover .g-fname { background: none; color: inherit; }
  .g-side-item:hover:not(.on) { background: none; color: inherit; }
  .g-lbtn:hover { background: rgba(0,0,0,.6); color: #fff; }
}

/* the gallery page on a phone: tiles are a normal scrolling list with a 4:3 cover */
@media (max-width: 700px) {
  .g-page { padding-left: max(var(--pad), env(safe-area-inset-left, 0px)); padding-right: max(var(--pad), env(safe-area-inset-right, 0px)); }
  .g-tiles { grid-template-columns: minmax(0, 1fr); grid-auto-rows: max-content; align-content: start; padding: 36px 6px calc(96px + env(safe-area-inset-bottom, 0px)) 3px; }
  .g-tile { display: block; }
  .g-tile-pic { display: block; aspect-ratio: 4 / 3; }
  .g-tile-info { padding-right: 2px; }
}

/* the explorer on a phone (or a phone turned sideways): full screen, big thumbnails grid,
   no details pane (you cannot hover on a touch screen; tap a photo to open it) */
@media (max-width: 700px), (max-height: 520px) and (pointer: coarse) {
  .g-overlay { padding: 0; display: block; background: var(--bg); }
  .g-win { width: 100%; height: 100%; border: 0; box-shadow: none; padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .g-wbody { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .g-side, .g-info, #g-hint { display: none; }
  .g-titlebar { padding-top: calc(4px + env(safe-area-inset-top, 0px)); }
  .g-x { width: 44px; height: 36px; font-size: 22px; }
  .g-addr { gap: 8px; padding: 8px 10px; }
  .g-up, .g-playall, .g-path { height: 40px; }
  .g-up { min-width: 44px; }
  .g-files { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; padding: 10px; }
  .g-file { padding: 3px; gap: 4px; }
  .g-fname { font-size: 14px; }
  .g-fmeta { display: none; }
  .g-status { padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 700px) { .g-files { padding: 10px; } }

/* the viewer on touch screens: thumb-sized buttons, safe areas */
@media (max-width: 700px), (pointer: coarse) {
  .g-lb { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .g-lbtn { height: 44px; min-width: 44px; font-size: 14px; }
  .g-lb-top { padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
  .g-lb-prev, .g-lb-next { width: 44px; height: 56px; background: rgba(0,0,0,.5); }
  .g-lb-cap { font-size: 20px; }
}
/* phone sideways: very little height, so keep the caption bar slim */
@media (max-height: 520px) and (pointer: coarse) {
  .g-lb { grid-template-rows: minmax(0, 1fr) auto; }
  .g-lb-top { position: absolute; top: 0; left: 0; right: 0; z-index: 8; padding-top: calc(4px + env(safe-area-inset-top, 0px)); padding-bottom: 14px; background: linear-gradient(rgba(0,0,0,.65), transparent); pointer-events: none; }
  .g-lb-top > * { pointer-events: auto; }
  .g-lbtn { height: 38px; }
  .g-lb-scroll { padding-top: 4px; }
  .g-lb-bar { padding: 8px 20px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .g-lb-story, #g-lb-gear { display: none; }
  .g-lb-cap { font-size: 17px; }
  .g-tiles { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); grid-auto-rows: max-content; align-content: start; }
  .g-tile { display: block; }
  .g-tile-pic { display: block; aspect-ratio: 16 / 9; }
  .g-page { padding-left: max(var(--pad), env(safe-area-inset-left, 0px)); padding-right: max(var(--pad), env(safe-area-inset-right, 0px)); }
}
