:root {
  --bg: #0b0b0d;
  --surface: #161619;
  --surface-2: #1e1e22;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .2);
  --text: #f5f3ee;
  --muted: #8e8b84;
  --accent: #d6ab62;
  --accent-ink: #1a1408;
  --danger: #ef7a6a;
  --ok: #8fd19e;
  --radius: 16px;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
img { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
h1, h2 { font-family: var(--sans); font-weight: 700; letter-spacing: -.03em; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 24px;
  border: 0; border-radius: 999px;
  font-size: 17px; font-weight: 700;
  text-decoration: none; cursor: pointer;
  transition: transform .15s ease, background .2s ease, color .2s ease, box-shadow .2s ease;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }
.btn-primary.is-done { background: var(--surface-2); color: var(--ok); }
.btn-ghost { background: rgba(255,255,255,.1); color: var(--text); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.btn-ghost.is-picked { background: var(--accent); color: var(--accent-ink); }
.icon-btn {
  width: 44px; height: 44px; padding: 11px; margin-right: -10px;
  border: 0; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- flash ---------- */
.flash-wrap { position: fixed; top: 12px; left: 16px; right: 16px; z-index: 50; display: grid; gap: 8px; max-width: 440px; margin: 0 auto; }
.flash { padding: 14px 18px; border-radius: 14px; font-size: 15px; font-weight: 500; background: var(--surface-2); animation: drop .35s ease both; }
.flash-error { background: #3a1814; color: #ffd6cf; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- login ---------- */
.login {
  min-height: 100dvh; max-width: 420px; margin: 0 auto;
  padding: 48px 24px calc(40px + var(--safe-b));
  display: flex; flex-direction: column; justify-content: center; gap: 40px;
}
.login-glow {
  position: fixed; inset: -25% -40% auto; height: 70vh; pointer-events: none; z-index: -1;
  background: radial-gradient(closest-side, rgba(214, 171, 98, .14), transparent 70%);
}
.login h1 { font-size: clamp(42px, 13vw, 56px); line-height: 1; }
.login-form { display: grid; gap: 12px; }
.login-form input {
  width: 100%; height: 58px; padding: 0 20px;
  background: var(--surface); color: var(--text);
  border: 1px solid transparent; border-radius: 16px;
  font-size: 17px; outline: none; transition: border-color .2s, background .2s;
}
.login-form input::placeholder { color: var(--muted); }
.login-form input:focus { border-color: var(--accent); background: var(--surface-2); }
.code-input { letter-spacing: .14em; text-transform: uppercase; }
.code-input::placeholder { letter-spacing: normal; text-transform: none; }
.login-form .btn { margin-top: 12px; }

/* ---------- gallery ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1100px; margin: 0 auto;
  padding: 20px 16px 16px; padding-top: max(20px, env(safe-area-inset-top));
  background: linear-gradient(var(--bg) 75%, rgba(11, 11, 13, 0));
}
.topbar h1 {
  font-size: clamp(32px, 9.5vw, 48px); line-height: 1.05;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar form { margin: 0; }
.gallery-main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 0; }

.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 12px; } }
@media (min-width: 980px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 16px; } }

.card {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); aspect-ratio: 4 / 5;
  transition: box-shadow .25s ease;
  animation: rise .5s ease both; animation-delay: calc(var(--i, 0) * 40ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.card-open { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .5s ease, filter .3s ease; }
@media (hover: hover) { .card:hover img { transform: scale(1.03); } }
.card-pick {
  position: absolute; right: 6px; top: 6px;
  width: 44px; height: 44px; padding: 9px; border: 0; background: none; cursor: pointer;
}
.card-pick::before {
  content: ""; position: absolute; inset: 9px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85); background: rgba(0,0,0,.25);
  transition: background .2s, border-color .2s, transform .2s;
}
.card-pick svg { position: relative; width: 100%; height: 100%; fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(.6); transition: .2s; }
.card.is-picked { box-shadow: 0 0 0 3px var(--accent); }
.card.is-picked .card-pick::before { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.card.is-picked .card-pick svg { opacity: 1; transform: none; }
.grid.has-pick .card:not(.is-picked) img { filter: brightness(.6) saturate(.8); }

.none-option {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  margin-top: 12px; padding: 18px;
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; transition: border-color .2s, color .2s, background .2s;
}
.none-option strong { font-weight: 700; }
.radio { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-strong); transition: .2s; }
.none-option.is-picked { border-color: var(--accent); color: var(--text); background: var(--surface); }
.none-option.is-picked .radio { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 4px var(--surface); }

.dock-spacer { height: calc(104px + var(--safe-b)); }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 16px 16px calc(16px + var(--safe-b));
  background: linear-gradient(rgba(11, 11, 13, 0), var(--bg) 40%);
}
.dock .btn { max-width: 440px; margin: 0 auto; display: flex; }

/* ---------- lightbox ---------- */
.lb { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; animation: fade .2s ease both; }
.lb[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px; padding-top: max(8px, env(safe-area-inset-top));
}
.lb-close, .lb-spacer { width: 48px; height: 48px; }
.lb-close { border: 0; background: none; padding: 12px; cursor: pointer; }
.lb-close svg, .lb-arrow svg { width: 100%; height: 100%; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lb-count { font-size: 15px; font-weight: 700; color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; }
.lb-track {
  flex: 1; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior: contain; scrollbar-width: none;
}
.lb-track::-webkit-scrollbar { display: none; }
.lb-slide {
  flex: 0 0 100%; height: 100%; margin: 0; scroll-snap-align: center; scroll-snap-stop: always;
  display: grid; place-items: center; padding: 64px 0 calc(100px + var(--safe-b));
}
.lb-slide img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.lb-arrow {
  display: none; position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 52px; height: 52px; padding: 13px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.1);
}
.lb-arrow:hover { background: rgba(255,255,255,.2); }
.lb-prev { left: 20px; } .lb-next { right: 20px; }
@media (hover: hover) and (min-width: 768px) { .lb-arrow { display: block; } }
.lb-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 16px 16px calc(16px + var(--safe-b));
}
.lb-bottom .btn { max-width: 400px; margin: 0 auto; display: flex; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 12px 20px; border-radius: 999px; max-width: calc(100% - 32px); white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 15px; font-weight: 700;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); color: #1b0703; white-space: normal; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 64px 8px 80px; max-width: 420px; margin: 0 auto; }
.empty h2 { font-size: 28px; margin-top: 36px; }
.empty-art { position: relative; height: 150px; }
.empty-art span {
  position: absolute; left: 50%; top: 10px; width: 100px; height: 125px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line-strong);
}
.empty-art span:nth-child(1) { transform: translateX(-90%) rotate(-10deg); }
.empty-art span:nth-child(2) { transform: translateX(-10%) rotate(9deg); }
.empty-art span:nth-child(3) { transform: translateX(-50%); border-color: rgba(214, 171, 98, .5); animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateX(-50%) translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
