:root {
  --bg: #0b0b0c;
  --bg-2: #141416;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f1ee;
  --muted: rgba(242, 241, 238, 0.5);
  --great: #e8c36a;
  --ok: #8fb3d9;
  --bad: #e07a6b;
  --radius: 14px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { -webkit-font-smoothing: antialiased; min-height: 100dvh; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(232, 195, 106, 0.08), transparent 60%),
    var(--bg);
}
.login-card { width: min(340px, 100%); text-align: center; animation: rise .6s ease both; }
.brand { font-family: var(--serif); font-size: 64px; font-weight: 400; letter-spacing: -0.02em; line-height: 1; }
.brand-sub { margin-top: 10px; font-size: 12px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--muted); }
.field {
  margin-top: 44px; display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg-2);
  padding: 6px 6px 6px 20px; transition: border-color .2s;
}
.field:focus-within { border-color: rgba(255, 255, 255, 0.25); }
.field input {
  flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text);
  font: inherit; font-size: 16px; letter-spacing: 0.04em;
}
.field input::placeholder { color: var(--muted); letter-spacing: 0.02em; }
.field button {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--text); color: var(--bg); transition: transform .15s;
}
.field button:active { transform: scale(.94); }
.login-err { min-height: 20px; margin: 14px 0 0; font-size: 13px; color: var(--bad); }
.shake { animation: shake .4s; }

/* ---------- Gallery ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--sat)) clamp(16px, 4vw, 40px) 10px;
  background: linear-gradient(var(--bg) 70%, rgba(11, 11, 12, 0));
}
.title { display: flex; align-items: baseline; gap: 12px; }
.brand-sm { font-family: var(--serif); font-size: 28px; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; }
.actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--muted); transition: color .2s, background .2s;
}
.icon-btn:hover { color: var(--text); background: var(--bg-2); }
.icon-btn svg { width: 20px; height: 20px; }

.filters {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 6px clamp(16px, 4vw, 40px) 18px;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); font-size: 13px;
  transition: all .2s;
}
.chip .n { font-variant-numeric: tabular-nums; opacity: .7; }
.chip .dot, .rate .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip:hover { color: var(--text); }
.chip[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip[data-f="great"] .dot { background: var(--great); }
.chip[data-f="ok"] .dot { background: var(--ok); }
.chip[data-f="bad"] .dot { background: var(--bad); }
.chip[data-f="none"] .dot { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }

.grid {
  display: grid; gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  padding: 0 clamp(4px, 4vw, 40px) calc(40px + var(--sab));
}
@media (min-width: 900px) { .grid { gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }
.tile {
  position: relative; aspect-ratio: 2 / 3; overflow: hidden; border-radius: 4px;
  background: var(--bg-2); cursor: pointer; padding: 0; display: block; width: 100%;
}
@media (min-width: 900px) { .tile { border-radius: 8px; } }
.tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transform: scale(1.02); transition: opacity .5s ease, transform .6s ease;
}
.tile img.loaded { opacity: 1; transform: none; }
@media (hover: hover) { .tile:hover img.loaded { transform: scale(1.03); } }
.tile .badge {
  position: absolute; right: 8px; bottom: 8px; width: 10px; height: 10px; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); transform: scale(0); transition: transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.tile[data-r] .badge { transform: scale(1); }
.tile[data-r="great"] .badge { background: var(--great); }
.tile[data-r="ok"] .badge { background: var(--ok); }
.tile[data-r="bad"] .badge { background: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 80px 20px; font-size: 14px; }

/* ---------- Viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; animation: fade .25s ease both; overscroll-behavior: contain; }
.track {
  position: absolute; inset: 0; display: flex;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  scrollbar-width: none; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.track::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%; height: 100%; scroll-snap-align: center; scroll-snap-stop: always;
  display: grid; place-items: center; position: relative;
}
.slide img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  user-select: none; -webkit-user-drag: none; -webkit-touch-callout: none;
  opacity: 0; transition: opacity .35s ease;
}
.slide img.loaded { opacity: 1; }
.slide .spinner {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .15); border-top-color: rgba(255, 255, 255, .6);
  animation: spin .8s linear infinite;
}
.slide img.loaded + .spinner { display: none; }

.ui { transition: opacity .25s ease, transform .3s ease; }
.viewer.ui-hidden .ui { opacity: 0; pointer-events: none; }
.viewer.ui-hidden .v-bottom { transform: translate(-50%, 16px); }
.viewer.ui-hidden .v-top { transform: translateY(-12px); }

.glass {
  background: rgba(20, 20, 22, 0.55);
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.v-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--sat)) 14px 12px; pointer-events: none;
}
.v-top > * { pointer-events: auto; }
.glass-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(20, 20, 22, 0.45); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08); transition: background .2s, color .2s, opacity .2s;
}
.glass-btn:active { background: rgba(60, 60, 64, .6); }
#autoBtn[aria-pressed="false"] { color: var(--muted); }
#autoBtn[aria-pressed="false"] svg { opacity: .5; }
.counter {
  height: 32px; padding: 0 14px; border-radius: 999px; display: grid; place-items: center;
  font-size: 13px; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; color: rgba(255, 255, 255, .85);
}

.nav-btn {
  position: absolute; top: 50%; z-index: 2; width: 52px; height: 52px; margin-top: -26px;
  border-radius: 50%; display: none; place-items: center; color: rgba(255, 255, 255, .7);
  transition: opacity .25s, background .2s, color .2s;
}
.nav-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-btn svg { width: 28px; height: 28px; stroke-width: 1.4; }
.nav-btn.prev { left: 16px; }
.nav-btn.next { right: 16px; }
.nav-btn:disabled { opacity: 0 !important; pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .nav-btn { display: grid; } }

.v-bottom {
  position: absolute; left: 50%; bottom: calc(20px + var(--sab)); z-index: 2;
  transform: translateX(-50%); width: min(420px, calc(100% - 28px));
}
.rate-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px; border-radius: 999px; }
.rate {
  height: 52px; border-radius: 999px; display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 15px; font-weight: 500; letter-spacing: 0.01em; color: rgba(255, 255, 255, .82);
  transition: background .2s, color .2s, transform .12s;
}
.rate:active { transform: scale(.95); }
.rate[data-rating="great"] .dot { background: var(--great); }
.rate[data-rating="ok"] .dot { background: var(--ok); }
.rate[data-rating="bad"] .dot { background: var(--bad); }
@media (hover: hover) { .rate:hover { background: rgba(255, 255, 255, .07); } }
.rate.active { color: #111; }
.rate.active .dot { background: rgba(0, 0, 0, .55) !important; }
.rate.active[data-rating="great"] { background: var(--great); }
.rate.active[data-rating="ok"] { background: var(--ok); }
.rate.active[data-rating="bad"] { background: var(--bad); }
.rate.pop { animation: pop .35s cubic-bezier(.3, 1.6, .5, 1); }

.toast {
  position: absolute; left: 50%; top: calc(70px + var(--sat)); z-index: 3;
  transform: translate(-50%, -6px); opacity: 0; pointer-events: none;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  background: rgba(20, 20, 22, .7); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.locked { overflow: hidden; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 50% { transform: scale(1.06); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
