@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Fraunces-var.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Fraunces-var-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Inter-var.woff2") format("woff2");
}

:root {
  --bg: #151018;
  --bg-2: #201a26;
  --surface: #2a2231;
  --ink: #efe8ef;
  --muted: #9c8fa3;
  --accent: #a88be0;
  --accent-deep: #cdb6f0;
  --accent-ink: #241c2e;
  --warm: #d98d66;
  --line: #3a3143;
  --ravenne: var(--warm);
  --ava: var(--accent);
  --radius: 14px;
  --gutter: max(16px, env(safe-area-inset-left));
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.45 "Inter", system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(env(safe-area-inset-top) + 14px) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1, h2 { font-family: "Fraunces", Georgia, serif; font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h1 em, h2 em { font-style: italic; color: var(--accent); font-weight: 400; }
.count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.tools { display: flex; gap: 8px; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  min-width: 0;
}
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; height: 38px; font-size: 16px; }
.search:focus-within { border-color: var(--accent); }
select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  height: 40px;
  font-size: 14px;
  flex: none;
  max-width: 42%;
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chip .n { font-size: 11.5px; opacity: .75; font-variant-numeric: tabular-nums; }
.chip:hover { color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.lock[aria-pressed="false"] { border-style: dashed; }
.chips.secondary .chip { height: 28px; font-size: 12.5px; }

main { padding: 12px var(--gutter) calc(40px + env(safe-area-inset-bottom)); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); } }

.tile {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-2);
  display: block;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 640px) { .tile { border-radius: var(--radius); } }
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity .35s ease, transform .5s ease;
}
.tile img.ready { opacity: 1; transform: none; }
@media (hover: hover) { .tile:hover img.ready { transform: scale(1.035); } }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile .badges {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  pointer-events: none;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(15, 10, 18, .62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.badge.r { color: var(--ravenne); }
.badge.a { color: var(--ava); }
.badge.both { color: #fff; background: linear-gradient(135deg, var(--ravenne), var(--accent)); }
.tile .rank {
  position: absolute;
  top: 6px;
  left: 6px;
  font: italic 600 15px/1 "Fraunces", serif;
  background: rgba(15, 10, 18, .62);
  padding: 4px 8px;
  border-radius: 999px;
}
.tile .lockmark, .tile .play {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(15, 10, 18, .62);
}
.tile .lockmark svg, .tile .play svg { width: 13px; height: 13px; }

.empty { color: var(--muted); text-align: center; padding: 60px 0; font-family: "Fraunces", serif; font-style: italic; font-size: 18px; }

.login {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login form { width: min(360px, 100%); display: grid; gap: 14px; text-align: center; }
.login h2 { font-size: 32px; }
.login p { color: var(--muted); font-size: 14px; }
.login input {
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  padding: 0 14px;
  font-size: 16px;
}
.login button {
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.login-error { color: var(--warm) !important; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #0b080d;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overscroll-behavior: contain;
}
.v-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  z-index: 2;
}
.v-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--ink);
}
.v-btn:hover { background: rgba(255, 255, 255, .08); }
.v-pos { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.v-stage {
  position: relative;
  overflow: hidden;
  touch-action: none;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  min-height: 0;
}
.v-stage img, .v-stage video {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transform-origin: 50% 50%;
  will-change: transform;
}
.v-stage img { transition: opacity .2s; }
.v-stage img.loading { opacity: .35; }
.v-stage.animating img { transition: transform .22s ease, opacity .2s; }
.v-nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: none;
  place-items: center;
  background: rgba(30, 22, 36, .6);
  color: var(--ink);
}
.v-nav.prev { left: 14px; }
.v-nav.next { right: 14px; }
@media (hover: hover) and (pointer: fine) { .v-nav { display: grid; } }

.v-info {
  padding: 12px var(--gutter) calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, #0b080d 70%, transparent);
  max-height: 40dvh;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}
.v-meta { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; display: flex; gap: 6px; flex-wrap: wrap; }
.v-desc { font-family: "Fraunces", Georgia, serif; font-size: 17px; line-height: 1.4; }
.v-desc:empty { display: none; }
.v-file { color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.v-rates { display: grid; gap: 6px; margin-top: 4px; }
.rate { display: flex; align-items: center; gap: 10px; }
.rate .who { width: 66px; font-size: 13px; color: var(--muted); }
.rate .stars { display: inline-flex; }
.rate .star {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: color-mix(in srgb, var(--muted) 45%, transparent);
  font-size: 22px;
  line-height: 1;
}
.rate .star.on { color: var(--ravenne); }
.rate[data-by="ava"] .star.on { color: var(--ava); }
.rate .heart {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 20px;
  filter: grayscale(1) opacity(.35);
  transition: filter .15s, transform .15s;
}
.rate .heart.on { filter: none; }
.rate .heart.pop { transform: scale(1.25); }
.rate.readonly .star { width: 22px; font-size: 16px; cursor: default; }
.rate.readonly .heart { width: 22px; font-size: 15px; }

@media (min-width: 900px) {
  .viewer { grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: auto minmax(0, 1fr); }
  .v-bar { grid-column: 1 / -1; }
  .v-info { grid-column: 2; grid-row: 2; max-height: none; background: #120d15; border-left: 1px solid var(--line); align-content: start; padding-top: 24px; }
}
