:root {
  --bg: #140a1f;
  --bg2: #1e1030;
  --card: #251439;
  --card2: #2f1a47;
  --text: #f6ecff;
  --muted: #b39cc9;
  --orange: #ff8c1a;
  --orange2: #ffb347;
  --green: #7cfc8a;
  --red: #ff5e7a;
  --ring: rgba(255, 140, 26, .45);
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -200px, #3a1b5c 0%, var(--bg) 60%);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding: 0 0 max(2rem, env(safe-area-inset-bottom));
  overflow-x: hidden;
}
main { width: min(40rem, 100%); margin: 0 auto; padding: 0 1rem; }
h1 { font-size: clamp(1.6rem, 7vw, 2.2rem); margin: .5rem 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.lead, .muted { color: var(--muted); }
.err { color: var(--red); min-height: 1.5em; margin: .5rem 0 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input[type=text], input[type=password] {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid #4a2d6b;
  border-radius: 12px; padding: .75rem .9rem; width: 100%; min-width: 0; outline: none;
}
input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--ring); }
.primary {
  background: linear-gradient(180deg, var(--orange2), var(--orange)); color: #2a1200; font-weight: 700;
  padding: .75rem 1.1rem; border-radius: 12px; white-space: nowrap; box-shadow: 0 6px 18px rgba(255,140,26,.25);
}
.primary:active { transform: translateY(1px); }
.link { color: var(--orange2); text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.row { display: flex; gap: .5rem; margin-top: .75rem; }

.top { display: flex; align-items: center; justify-content: space-between; width: min(40rem, 100%); margin: 0 auto;
  padding: max(.75rem, env(safe-area-inset-top)) 1rem .5rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.logo { font-size: 1.6rem; filter: drop-shadow(0 0 10px rgba(255,140,26,.6)); }
.who { color: var(--muted); font-size: .9rem; display: flex; gap: .5rem; align-items: center; }
.who #who-name { color: var(--text); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.chip { background: var(--card); border: 1px solid #4a2d6b; border-radius: 999px; padding: .45rem .9rem; font-weight: 600; }
.chip:active { background: var(--card2); }

.banner { border-radius: var(--radius); padding: .7rem 1rem; margin: .25rem 0 .75rem; font-weight: 600;
  background: var(--card); border: 1px solid #4a2d6b; display: none; }
.banner.show { display: block; }
.banner.closed { background: #3a1a2a; border-color: #6b2d4a; }
.banner.reveal { background: linear-gradient(90deg, #4a2a00, #3a1b5c); border-color: var(--orange); }

.tabs { display: flex; gap: .4rem; background: var(--card); padding: .3rem; border-radius: 14px; margin-bottom: .75rem; }
.tabs button { flex: 1; padding: .6rem; border-radius: 11px; font-weight: 700; color: var(--muted); }
.tabs button.active { background: var(--orange); color: #2a1200; }

.progress { position: relative; height: 2rem; background: var(--card); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #7a3bff, var(--orange)); transition: width .4s; }
.progress span { position: relative; display: block; text-align: center; line-height: 2rem; font-weight: 700; font-size: .9rem; }

.card { background: var(--card); border: 1px solid #3b2358; border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.cat-head { display: flex; align-items: baseline; gap: .5rem; }
.cat-head .emoji { font-size: 1.5rem; }
.cat-head h2 { margin: 0; }
.cat-head .done { margin-left: auto; color: var(--green); font-size: .85rem; font-weight: 700; }
.blurb { color: var(--muted); margin: .1rem 0 .75rem; font-size: .92rem; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pk {
  position: relative; background: var(--card2); border: 2px solid transparent; border-radius: 14px;
  padding: 0 0 .4rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .15rem; overflow: hidden;
  transition: transform .08s, border-color .15s, background .15s;
}
.pk:active { transform: scale(.96); }
.ph { display: block; width: 100%; aspect-ratio: 1; background: #1a0f2a; display: grid; place-items: center; font-size: 2rem; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pk .n { position: absolute; top: .3rem; left: .3rem; background: rgba(12,6,20,.8); color: var(--orange2); font-weight: 800; font-size: .8rem; padding: .1rem .45rem; border-radius: 999px; }
.pk .nm { font-size: .7rem; line-height: 1.15; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; max-width: 100%; padding: 0 .3rem; }
.pk .nm b { color: var(--text); }
.pk.sel { border-color: var(--orange); background: #4a2a0a; box-shadow: 0 0 0 3px var(--ring); }
.pk.sel .nm { color: var(--orange2); }
.pk[disabled] { opacity: .55; }
.pk.own::after { content: "yours"; position: absolute; top: .3rem; right: .3rem; background: rgba(12,6,20,.8); color: var(--muted); font-size: .65rem; padding: .1rem .4rem; border-radius: 999px; }

.mine { border-color: #5a3a8a; }
.mine-row { display: flex; gap: .75rem; align-items: center; }
.thumb { width: 4.5rem; height: 4.5rem; border-radius: 12px; background: #1a0f2a; display: grid; place-items: center; font-size: 1.8rem; overflow: hidden; flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.btn { display: inline-flex; align-items: center; gap: .4rem; background: var(--card2); border: 1px solid #5a3a8a; border-radius: 12px; padding: .55rem .9rem; font-weight: 600; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }

.gal { padding: 0; overflow: hidden; }
.gal .big { width: 100%; aspect-ratio: 4 / 3; background: #1a0f2a; display: grid; place-items: center; font-size: 3rem; }
.gal .big img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal .meta { padding: .7rem 1rem; }
.gal .meta b { font-size: 1.05rem; }
.wthumbs { display: flex; gap: .4rem; flex-wrap: wrap; margin: .3rem 0 .5rem; }
.wthumbs img, .wthumbs span { width: 4rem; height: 4rem; border-radius: 10px; object-fit: cover; background: #1a0f2a; display: grid; place-items: center; font-size: 1.6rem; }
.lightbox { position: fixed; inset: 0; background: rgba(5,2,10,.94); z-index: 20; display: grid; place-items: center; padding: 1rem; }
.lightbox img { max-width: 100%; max-height: 85vh; border-radius: 12px; }
.lightbox .cap { position: absolute; bottom: max(1rem, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; font-weight: 700; }

.res-cat { margin-bottom: 1rem; }
.winner { font-size: 1.15rem; font-weight: 800; margin: .25rem 0 .5rem; }
.winner small { color: var(--muted); font-weight: 500; }
.bar { display: grid; grid-template-columns: 2.4rem 1fr 2rem; align-items: center; gap: .5rem; margin: .3rem 0; font-size: .9rem; }
.bar .lbl { font-weight: 700; }
.bar .track { height: .8rem; background: var(--card2); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, #7a3bff, var(--orange)); border-radius: 999px; transition: width .6s; }
.bar.top .fill { background: linear-gradient(90deg, var(--orange), #ffd166); }
.bar .cnt { text-align: right; color: var(--muted); }
.podium { text-align: center; padding: 1rem; background: linear-gradient(180deg, #4a2a00, var(--card)); border-color: var(--orange); }
.podium .big { font-size: 3rem; line-height: 1; }
.toggles { display: grid; gap: .5rem; }
.toggles label { display: flex; gap: .6rem; align-items: center; font-weight: 600; }
.toggles input { width: 1.3rem; height: 1.3rem; accent-color: var(--orange); }
.pk-edit { display: grid; grid-template-columns: 2.4rem 1fr auto auto; gap: .4rem; align-items: center; margin: .4rem 0; }
.pk-edit small { color: var(--muted); }
.pk-edit b { text-align: center; }
.pk-edit input { padding: .5rem .6rem; }
.user-row { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; border-bottom: 1px solid #3b2358; }
.user-row:last-child { border: 0; }
.user-row .x { color: var(--red); font-size: .85rem; }

footer { text-align: center; margin-top: 2rem; opacity: .5; font-size: .85rem; }
.toast { position: fixed; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #0c0614; color: var(--text); border: 1px solid var(--orange); padding: .6rem 1rem; border-radius: 999px;
  font-weight: 600; z-index: 10; max-width: 90vw; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.toast.bad { border-color: var(--red); }

.bats { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.bats span { position: absolute; font-size: 1.4rem; opacity: .35; animation: fly 18s linear infinite; }
.bats span:nth-child(1) { top: 12%; animation-duration: 22s; }
.bats span:nth-child(2) { top: 30%; animation-duration: 17s; animation-delay: -6s; }
.bats span:nth-child(3) { top: 55%; animation-duration: 26s; animation-delay: -12s; }
@keyframes fly { from { left: -5%; transform: translateY(0) } 50% { transform: translateY(-30px) } to { left: 105%; transform: translateY(0) } }
@media (prefers-reduced-motion: reduce) { .bats span { animation: none; display: none; } }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(4, 1fr); } }
