:root {
  --bg: #120a24;
  --bg2: #1d1038;
  --card: rgba(255, 255, 255, 0.06);
  --card-hi: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6f1ff;
  --muted: #b4a6d6;
  --pink: #ff3d9a;
  --violet: #8b5cff;
  --cyan: #2fe2ff;
  --good: #3ee08f;
  --bad: #ff6b6b;
  --grad: linear-gradient(135deg, var(--pink), var(--violet));
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Outfit', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(120% 60% at 10% -10%, #3b1670 0%, transparent 60%),
              radial-gradient(90% 50% at 110% 10%, #5a0f4a 0%, transparent 55%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.logo { display: inline-flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 500; letter-spacing: .2px; }
.logo b { font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo.small { font-size: 17px; gap: 8px; }
.logo-disc {
  width: 1.4em; height: 1.4em; border-radius: 50%;
  background: radial-gradient(circle, #fff 0 9%, #120a24 10% 18%, transparent 19%), conic-gradient(from 0deg, var(--pink), var(--violet), var(--cyan), var(--pink));
  animation: spin 6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Join */
#join { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.join-card { width: 100%; max-width: 420px; }
.join-card h1 { font-size: 34px; line-height: 1.1; margin: 28px 0 8px; }
.join-card p { margin: 0 0 24px; }
.field { display: block; margin-bottom: 16px; position: relative; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.field input, .field textarea {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; font-size: 17px; outline: none; transition: border-color .15s, background .15s; resize: none;
}
.field input:focus, .field textarea:focus { border-color: var(--violet); background: var(--card-hi); }
#codeInput { font-size: 40px; font-weight: 800; letter-spacing: 18px; text-align: center; padding: 10px 0 10px 18px; }
.counter { position: absolute; right: 10px; bottom: 8px; font-size: 12px; }
.error { color: var(--bad); margin: 0 0 14px; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 700; cursor: pointer;
  background: var(--card-hi); transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--grad); box-shadow: 0 8px 24px -8px rgba(255, 61, 154, .6); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.big { width: 100%; padding: 16px; font-size: 18px; }

/* Party screen */
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 0 10px; position: sticky; top: 0; z-index: 5; background: linear-gradient(var(--bg) 70%, transparent); }
.party-chip { font-size: 14px; color: var(--muted); margin-left: auto; }
.party-chip b { color: var(--text); letter-spacing: 1px; }
.me-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer; max-width: 46vw; }
.me-chip #meName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spots { display: inline-flex; gap: 3px; }
.spots i { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.spots i.used { background: rgba(255, 255, 255, .2); }

.now { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); margin: 4px 0 14px; }
.now-art { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--grad); flex: none; }
.now-info { min-width: 0; flex: 1; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--pink); font-weight: 700; }
.now-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--grad); transition: width 1s linear; }

.tabs { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 14px; position: sticky; top: 56px; z-index: 4; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px 6px; border-radius: 999px; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--grad); color: #fff; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: rgba(255, 255, 255, .18); font-size: 12px; line-height: 20px; }

.searchbox { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 14px; }
.searchbox:focus-within { border-color: var(--violet); }
.searchbox svg { width: 20px; fill: var(--muted); flex: none; }
.searchbox input { flex: 1; border: 0; background: transparent; padding: 14px 0; font-size: 17px; outline: none; min-width: 0; }
.sources { display: flex; gap: 8px; margin-top: 10px; }
.sources button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.sources button.active { border-color: var(--pink); color: var(--text); background: rgba(255, 61, 154, .14); }
.sources button .muted { font-weight: 400; }
.src { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .5px; padding: 1px 5px; border-radius: 5px; margin-right: 5px; vertical-align: 1px; background: rgba(255, 255, 255, .12); color: var(--muted); }
.src.yt { background: rgba(255, 0, 0, .22); color: #ffb3b3; }
.hint { font-size: 13px; margin: 14px 2px 6px; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; }
.small-note { font-size: 14px; margin: 0 2px 10px; }

.tracks { list-style: none; margin: 0; padding: 0; }
.track { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.track img { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--card-hi); flex: none; }
.t-main { min-width: 0; flex: 1; }
.t-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-sub { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-msg { font-size: 13px; color: #ffd2ea; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--grad); font-size: 26px; font-weight: 400; line-height: 1; cursor: pointer; flex: none; }
.add-btn:disabled { background: var(--card-hi); font-size: 16px; }
.pos { width: 22px; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.vote { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 50px; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 700; flex: none; line-height: 1.1; }
.vote span { font-size: 13px; }
.vote.on { background: var(--grad); border-color: transparent; }
.vote:disabled { opacity: .5; cursor: default; }
.mine { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 8px; background: rgba(62, 224, 143, .18); color: var(--good); margin-left: 4px; vertical-align: 2px; }
.cancel { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; padding: 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.spinner { width: 28px; height: 28px; margin: 30px auto; border-radius: 50%; border: 3px solid var(--card-hi); border-top-color: var(--pink); animation: spin .8s linear infinite; }

.photo-form .drop { display: grid; place-items: center; text-align: center; min-height: 240px; border: 2px dashed var(--line); border-radius: var(--radius); margin-bottom: 16px; cursor: pointer; overflow: hidden; background: var(--card); line-height: 1.5; padding: 16px; }
.photo-form .drop img { max-width: 100%; max-height: 360px; border-radius: 10px; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 2, 12, .65); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; background: var(--bg2); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line); padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); animation: rise .2s ease-out; max-height: 92dvh; overflow: auto; }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 14px; }
.sheet-track { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.sheet-track img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--card-hi); }
.sheet-track > div { min-width: 0; }
.attach { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.attach-preview { position: relative; }
.attach-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.attach-preview button { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: #000; font-size: 12px; cursor: pointer; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; padding: 14px; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #fff; color: #120a24; font-weight: 600; padding: 12px 18px; border-radius: 12px; z-index: 30; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: rise .2s; text-align: center; }
.toast.bad { background: var(--bad); color: #fff; }

/* Photo gallery */
#photoAddToggle { margin-bottom: 4px; }
.photo-form { margin-top: 14px; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.gallery button { position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--card-hi); cursor: pointer; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery button span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11px; font-weight: 600; text-align: left; background: linear-gradient(transparent, rgba(0, 0, 0, .75)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 520px) { .gallery { grid-template-columns: repeat(4, 1fr); } }

.lightbox { position: fixed; inset: 0; z-index: 40; background: #05020c; display: flex; flex-direction: column; animation: fade .15s; }
.lightbox img { flex: 1; min-height: 0; width: 100%; object-fit: contain; padding: 56px 8px 8px; touch-action: pan-y; }
.lb-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); font-size: 18px; cursor: pointer; z-index: 2; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; background: rgba(255, 255, 255, .1); font-size: 34px; cursor: pointer; z-index: 2; }
.lb-nav.prev { left: 0; border-radius: 0 12px 12px 0; }
.lb-nav.next { right: 0; border-radius: 12px 0 0 12px; }
.lb-bar { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--bg2); border-top: 1px solid var(--line); }
.lb-info { margin-bottom: 10px; line-height: 1.35; }
.lb-info b { color: var(--pink); margin-right: 6px; }
.lb-info small { display: block; font-size: 12px; }
.lb-actions { display: flex; gap: 10px; }
.lb-actions .btn { flex: 1; padding: 13px; text-decoration: none; }
