:root {
  --bg: #0b0b0f;
  --panel: #16161d;
  --panel-2: #1e1e27;
  --line: #2a2a35;
  --text: #ecedf2;
  --muted: #9a9aab;
  --accent: #7c8cff;
  --danger: #ff6b6b;
  --fav: #ff4d6d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* Several elements below set display explicitly, which would otherwise beat
   the UA rule for [hidden]. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

.screen[hidden] { display: none !important; }

/* ---------------------------------------------------------------- lock */

#lock {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
}

.lock-inner {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.lock-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--accent);
}

.lock-title {
  margin: 0 0 22px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  height: 14px;
  margin-bottom: 12px;
}

.pin-dots i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  animation: pop 160ms ease-out;
}

@keyframes pop { from { transform: scale(0.4); opacity: 0; } }

.lock-message {
  min-height: 20px;
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--danger);
}

.lock-inner.shake { animation: shake 380ms cubic-bezier(.36,.07,.19,.97); }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.keypad button {
  aspect-ratio: 1.55;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 22px;
  font-weight: 500;
  display: grid;
  place-items: center;
  transition: background 120ms, transform 80ms;
}

.keypad button:active { background: var(--panel-2); transform: scale(0.97); }
.keypad button.ghost { background: transparent; border-color: transparent; color: var(--muted); font-size: 17px; }

.submit {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--accent);
  color: #0b0b12;
  font-weight: 650;
  transition: opacity 120ms;
}

.submit:disabled { opacity: 0.45; }

.lock-hint { margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.linkish { color: var(--accent); text-decoration: underline; padding: 0; font-size: inherit; }

.text-pin { display: flex; gap: 8px; margin-top: 14px; }
.text-pin input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
}
.text-pin button {
  padding: 0 18px;
  border-radius: 12px;
  background: var(--accent);
  color: #0b0b12;
  font-weight: 600;
}

.busy .keypad, .busy .submit, .busy .text-pin { pointer-events: none; opacity: 0.5; }

/* ---------------------------------------------------------------- gallery */

#gallery { padding-bottom: calc(var(--safe-bottom) + 24px); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) 10px calc(var(--safe-left) + 16px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 640;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--text);
  transition: background 120ms;
}

.icon-btn:active { background: var(--panel-2); }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 12px calc(var(--safe-right) + 16px) 4px calc(var(--safe-left) + 16px);
}

.filters::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  white-space: nowrap;
}

.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #0b0b12; font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 3px;
  padding: 10px calc(var(--safe-right) + 3px) 0 calc(var(--safe-left) + 3px);
}

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; padding-left: 12px; padding-right: 12px; }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel-2);
  padding: 0;
  display: block;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 220ms ease;
}

.tile img.ready { opacity: 1; }

.tile .heart {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 15px;
  height: 15px;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
  pointer-events: none;
}

.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14.5px; }
.grid-footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 22px 16px 6px; }

/* ---------------------------------------------------------------- sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] { display: none; }

.sheet-panel {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
  animation: rise 200ms ease-out;
}

@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 20px; }
}

@keyframes rise { from { transform: translateY(18px); opacity: 0; } }

.sheet-panel h2 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; }
.sheet-panel h2:first-child { margin-top: 0; }
.sheet-note { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }

.sheet-btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 15px;
  margin-bottom: 4px;
}

.sheet-btn.ghost { background: transparent; color: var(--muted); }
.sheet-btn:disabled { opacity: .5; }

.progress { height: 5px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: 10px 0 4px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 160ms linear; }

/* ---------------------------------------------------------------- viewer */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.viewer[hidden] { display: none; }

.viewer-track {
  position: absolute;
  inset: 0;
  display: flex;
  will-change: transform;
}

.slide {
  position: relative;
  flex: 0 0 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

/* The <img> box always fills the slide; object-fit letterboxes the pixels
   inside it. That keeps the gesture maths in one coordinate space — the
   slide — instead of chasing a box that resizes with each photo. */
.slide img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  will-change: transform;
  transform-origin: 0 0;
  -webkit-user-drag: none;
}

.viewer-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 200ms ease;
}

.viewer-chrome.hidden { opacity: 0; }

.viewer-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 10px) 24px calc(var(--safe-left) + 10px);
  background: linear-gradient(rgba(0,0,0,.62), transparent);
}

.viewer-top .icon-btn { pointer-events: auto; color: #fff; }

.viewer-counter { flex: 1; text-align: center; font-size: 13.5px; color: rgba(255,255,255,.82); font-variant-numeric: tabular-nums; }

#btn-fav.on { color: var(--fav); }
#btn-fav.on svg { fill: var(--fav); }

.viewer-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 30px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 16px);
  background: linear-gradient(transparent, rgba(0,0,0,.62));
}

.viewer-caption { font-size: 12.5px; color: rgba(255,255,255,.75); text-align: center; }
.viewer-caption b { display: block; font-weight: 550; color: rgba(255,255,255,.95); font-size: 13.5px; margin-bottom: 2px; word-break: break-all; }

/* ---------------------------------------------------------------- session */

.session-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 14px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 10px 10px 10px 16px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
  font-size: 13px;
  color: var(--muted);
}

.session-bar button {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b0b12;
  font-size: 13px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- shade */

#privacy-shade {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: none;
}

body.shaded #privacy-shade { display: block; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
