:root {
  --bg: #ececed;
  --surface: #fff;
  --line: rgba(0, 0, 0, .10);
  --ink: #16161a;
  --muted: #74747c;
  --radius: 14px;
  --header: 52px;
  --tap: 44px; /* minimum comfortable touch target */
}

* { box-sizing: border-box; }

/* display:flex/grid below would otherwise beat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.solid { fill: currentColor; stroke: none; }

/* ---------- header ---------- */

header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  height: var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(var(--bg) 60%, transparent);
}

.counter {
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  color: var(--muted);
}
.counter b {
  color: var(--ink);
  font-weight: 600;
}

.toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.toggle button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.toggle button svg {
  width: 15px;
  height: 15px;
}
.toggle button:hover { color: var(--ink); }
.toggle button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
}

/* ---------- single view ---------- */

.full {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--header) + 8px) 16px calc(var(--tap) + 34px);
  overflow: hidden;
}

.full figure {
  margin: 0;
  display: flex;
  min-width: 0;
  min-height: 0;
}

.full img {
  width: auto;
  height: auto;
  max-width: min(100%, 900px);
  max-height: calc(100dvh - var(--header) - var(--tap) - 42px);
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  -webkit-user-drag: none;
  user-select: none;
  transition: filter .18s, opacity .18s;
}
.full img.is-hidden {
  filter: grayscale(1);
  opacity: .38;
}

.nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(6px);
  color: var(--ink);
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s;
}
.nav:hover, .nav:active { opacity: 1; }
.nav svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}
.prev { left: 16px; }
.next { right: 16px; }

/* hide / bring-back control, thumb-reachable at the bottom */
.hide {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  width: 58px;
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(6px);
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.hide svg { width: 20px; height: 20px; }
.hide:hover { border-color: rgba(0, 0, 0, .3); }
.hide[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

/* ---------- grid view ---------- */

.grid {
  padding: calc(var(--header) + 6px) 16px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
}

.tile .open {
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.tile .open:hover {
  border-color: rgba(0, 0, 0, .4);
  transform: translateY(-2px);
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-drag: none;
  transition: filter .18s, opacity .18s;
}

.tile .num {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(22, 22, 26, .78);
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
}

.tile .mark {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(4px);
  color: var(--muted);
  cursor: pointer;
  opacity: .75;
  transition: opacity .15s, background .15s, color .15s;
}
.tile .mark svg { width: 16px; height: 16px; }
.tile .mark:hover { opacity: 1; color: var(--ink); }

/* hidden state */
.tile[data-hidden="true"] img {
  filter: grayscale(1);
  opacity: .3;
}
.tile[data-hidden="true"] .open {
  background: repeating-linear-gradient(
    -45deg,
    transparent 0 9px,
    rgba(0, 0, 0, .045) 9px 18px
  ) var(--surface);
  border-style: dashed;
}
.tile[data-hidden="true"] .num { background: rgba(22, 22, 26, .35); }
.tile[data-hidden="true"] .mark {
  opacity: 1;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

@media (max-width: 640px) {
  .prev { left: 8px; }
  .next { right: 8px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
}
