:root {
  --bg:      hsl(200 60% 5%);
  --surface: hsl(198 55% 11%);
  --card:    hsl(198 58% 12%);
  --border:  hsl(197 40% 20%);
  --text:    hsl(197 55% 94%);
  --muted:   hsl(197 35% 60%);
  --accent:  hsl(197 50% 58%);
  --icy:     hsl(197 51% 76%);
  --arctic:  hsl(194 53% 35%);
  --deep:    hsl(198 72% 16%);
  --best:    #ffc53d;
  --radius:  16px;

  --hero-grad: linear-gradient(135deg, var(--icy) 0%, var(--accent) 55%, var(--arctic) 100%);
  --hero-shadow: 0 0 0 1px hsl(197 50% 58% / .4), 0 6px 32px hsl(197 50% 40% / .45), 0 2px 8px hsl(200 60% 3% / .5);
  --brand-grad: linear-gradient(140deg, var(--text) 0%, var(--icy) 45%, var(--accent) 100%);
  --shadow-lg: 0 10px 28px hsl(200 60% 3% / .55), 0 4px 8px hsl(200 60% 3% / .3);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.015em;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { min-height: 100vh; display: flex; flex-direction: column; }

#screen-home { align-items: center; justify-content: center; text-align: center; padding: 24px; position: relative; overflow: hidden; min-height: 100dvh; height: 100dvh; }

.aurora { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.blob { position: absolute; border-radius: 50%; }
.blob.b1 { top: -20%; left: 50%; width: 700px; height: 500px; background: radial-gradient(ellipse, hsl(197 50% 35% / .55) 0%, transparent 65%); animation: drift1 22s ease-in-out infinite alternate; }
.blob.b2 { bottom: -20%; left: -15%; width: 520px; height: 520px; background: radial-gradient(circle, hsl(194 53% 22% / .45) 0%, transparent 65%); animation: drift2 26s ease-in-out infinite alternate; }
.blob.b3 { bottom: 5%; right: -10%; width: 340px; height: 340px; background: radial-gradient(circle, hsl(39 80% 50% / .08) 0%, transparent 60%); animation: drift3 30s ease-in-out infinite alternate; }
@keyframes drift1 { from { transform: translateX(-50%) translateY(0); } to { transform: translateX(-44%) translateY(28px); } }
@keyframes drift2 { from { transform: translate(0,0); } to { transform: translate(40px,-28px); } }
@keyframes drift3 { from { transform: translate(0,0); } to { transform: translate(-28px,-20px); } }

.photo-stream { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.float-card {
  position: absolute; top: 0; width: var(--w, 110px); aspect-ratio: 3 / 4;
  border-radius: 14px; overflow: hidden;
  background: linear-gradient(160deg, var(--arctic), var(--deep));
  box-shadow: 0 10px 30px hsl(200 60% 3% / .55);
  transform: translateY(115vh);
  animation: riseUp var(--dur, 22s) linear infinite;
  will-change: transform, opacity;
}
.float-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.float-card::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(160deg, hsl(197 55% 45% / .30), hsl(200 60% 6% / .60)); }
@keyframes riseUp {
  0%   { transform: translateY(115vh) rotate(var(--rot, 0deg)); opacity: 0; }
  12%  { opacity: var(--op, .55); }
  88%  { opacity: var(--op, .55); }
  100% { transform: translateY(-70vh) rotate(var(--rot, 0deg)); opacity: 0; }
}
.hero-veil { position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(ellipse 60% 55% at 50% 50%, hsl(200 60% 5% / .78) 0%, hsl(200 60% 5% / .35) 45%, transparent 75%); }

.home-inner { max-width: 380px; width: 100%; position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 26px; }
.hero-head { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.brandmark { font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif; font-size: clamp(54px, 12vw, 132px); font-weight: 700; letter-spacing: -0.04em; line-height: .95; margin: 0;
  background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tagline { color: var(--icy); font-size: clamp(16px, 2.4vw, 22px); line-height: 1.5; margin: 0; text-shadow: 0 2px 16px hsl(200 60% 4% / .7); }
.btn { border: none; border-radius: 10px; font-size: 16px; height: 56px; padding: 0 20px; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .16s ease, box-shadow .16s ease, opacity .16s; }
.btn-primary { background: var(--hero-grad); color: hsl(200 60% 5%); box-shadow: var(--hero-shadow); width: 100%; }
.btn-primary:hover { transform: scale(1.02); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.join-row { display: flex; gap: 8px; width: 100%; }
.input { flex: 1; background: hsl(198 55% 11%); border: 1.5px solid var(--border); color: var(--text); border-radius: 10px; padding: 0 18px; height: 52px; font-size: 15px; text-align: center; outline: none; transition: border-color .2s; }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: hsl(197 30% 50%); }
.home-foot { color: hsl(197 35% 58%); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 500; margin: 6px 0 0; text-shadow: 0 2px 12px hsl(200 60% 4% / .7); }

.room-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid hsl(197 40% 20% / .5); position: sticky; top: 0; background: hsl(200 60% 5% / .6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); z-index: 15; }
.room-title { display: flex; flex-direction: column; min-width: 0; margin-right: 8px; }
#room-name { font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-code { color: var(--muted); font-size: 12.5px; }
.room-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.avatars { display: flex; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; margin-left: -8px; border: 2px solid var(--bg); }
.icon-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; }
.icon-btn:hover { border-color: var(--accent); }
.room-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.leave-btn { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; }
.leave-btn:hover { border-color: var(--accent); color: var(--accent); }

.me-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 12px; cursor: pointer; max-width: 150px; transition: border-color .15s, box-shadow .15s; }
.me-chip:hover { border-color: var(--accent); }
.me-chip.editing { border-color: var(--accent); box-shadow: 0 0 0 3px hsl(197 50% 58% / .18); }
.me-chip .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
#me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-rename { width: 84px; background: transparent; border: none; outline: none; color: var(--text); font: inherit; padding: 0; }

.controls { display: flex; align-items: center; gap: 14px; padding: 12px 16px; }
.control-actions { display: flex; gap: 6px; }
.ctl-btn { height: 38px; padding: 0 12px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: border-color .15s, color .15s; }
.ctl-btn .ctl-ico { font-size: 15px; line-height: 1; }
.ctl-label { display: none; }
.ctl-btn:hover { border-color: var(--accent); color: var(--accent); }
@media (min-width: 600px) { .ctl-label { display: inline; } }
.toggle { position: relative; display: inline-flex; background: var(--surface); border-radius: 11px; padding: 4px; }
.toggle-glide { display: none; }
.toggle-opt { position: relative; z-index: 1; background: transparent; border: 1px solid transparent; color: var(--muted); padding: 8px 20px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background .2s, border-color .2s, color .2s; }
.toggle-opt.active { background: var(--card); border-color: var(--border); box-shadow: var(--shadow-lg); color: var(--text); }
#tab-best.active { color: var(--best); }

.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 14px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: background .2s, color .2s, border-color .2s; }
.chip:hover { background: var(--surface); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px; flex: 1; align-content: start; }
.grid:empty { flex: 0; padding: 0; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.tile { position: relative; aspect-ratio: 1 / 1; overflow: hidden; background: var(--surface); cursor: pointer; border-radius: 6px; animation: tileIn .28s ease both; transition: transform .15s; }
.tile:active { transform: scale(.96); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
@keyframes tileIn { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }
.tile .star { position: absolute; top: 6px; right: 6px; color: var(--best); font-size: 14px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.tile .dup { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.55); backdrop-filter: blur(6px); color: #fff; font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 999px; }

.empty {
  margin: auto;
  max-width: min(560px, 90vw);
  padding: clamp(14px, 3vh, 36px) clamp(20px, 5vw, 48px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted);
}
.empty .empty-icon {
  width: clamp(80px, min(22vw, 20vh), 168px);
  height: clamp(80px, min(22vw, 20vh), 168px);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(40px, min(11vw, 10vh), 76px);
  margin-bottom: clamp(10px, 2vh, 20px);
}
.empty p { margin: 0; }
.empty p:not(.muted) {
  font-size: clamp(20px, 4.6vw, 30px);
  font-weight: 700;
  color: var(--text);
  margin-bottom: clamp(4px, 1vw, 8px);
}
.empty .muted { font-size: clamp(14px, 3.4vw, 18px); line-height: 1.5; }

.toolbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center; padding: 16px; z-index: 15; background: linear-gradient(to top, var(--bg) 35%, transparent); }
.tool-add { width: 100%; max-width: 420px; height: 52px; border: none; border-radius: 12px; background: var(--accent); color: hsl(200 60% 5%); font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: var(--hero-shadow); transition: transform .15s; }
.tool-add:active { transform: scale(.98); }
#screen-room { padding-bottom: 96px; }

body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  opacity: 0; transition: opacity .8s ease;
  background: linear-gradient(
    125deg,
    hsl(200 60% 7%)  0%,
    hsl(198 60% 13%) 20%,
    hsl(197 56% 23%) 38%,
    hsl(191 52% 15%) 55%,
    hsl(198 58% 22%) 73%,
    hsl(200 60% 8%) 100%
  );
  background-size: 300% 300%;
  background-repeat: no-repeat;
  animation: auroraFlow 26s ease-in-out infinite alternate;
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  opacity: 0; transition: opacity .8s ease;
  background:
    radial-gradient(55% 55% at 22% 20%, hsl(197 62% 48% / .20), transparent 60%),
    radial-gradient(50% 50% at 82% 82%, hsl(39 72% 52% / .07), transparent 60%);
  background-size: 165% 165%;
  background-repeat: no-repeat;
  animation: auroraFlow2 34s ease-in-out infinite alternate;
}
body.in-room::before, body.in-room::after { opacity: 1; }
@keyframes auroraFlow {
  from { background-position: 0% 50%; }
  to   { background-position: 100% 50%; }
}
@keyframes auroraFlow2 {
  from { background-position: 10% 0%; }
  to   { background-position: 90% 100%; }
}

.modal { position: fixed; inset: 0; background: hsl(200 60% 3% / .85); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; }
.modal-card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; max-width: 360px; width: 100%; text-align: center; position: relative; box-shadow: var(--shadow-lg); }
.modal-card h2 { margin: 0 0 12px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 12px; width: fit-content; margin: 0 auto 12px; }
.room-code.big { font-size: 22px; letter-spacing: 2px; }

.modal.loupe { flex-direction: column; background: hsl(200 60% 3% / .95); }
.loupe-img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 8px; }
.loupe-nav { position: absolute; top: 50%; transform: translateY(-50%); background: hsl(198 58% 12% / .7); backdrop-filter: blur(8px); color: #fff; border: 1px solid var(--border); font-size: 28px; width: 46px; height: 62px; cursor: pointer; border-radius: 12px; }
.loupe-nav.prev { left: 10px; } .loupe-nav.next { right: 10px; }
.loupe-info { position: absolute; bottom: 22px; display: flex; gap: 10px; align-items: center; }
#loupe-owner { color: #fff; display: flex; align-items: center; gap: 8px; }
#loupe-download { color: #fff; }
#loupe-delete { color: #ffb1b1; }
.modal.loupe.playing .loupe-nav { display: none; }
.modal.loupe.playing .loupe-info { opacity: .5; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.08); } }
.modal.loupe.playing .loupe-img { animation: kenburns 3s ease-in-out infinite alternate; }

.selfie-video { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; background: #000; margin: 16px auto; display: block; border: 3px solid var(--accent); box-shadow: 0 0 0 6px hsl(197 50% 58% / .15), 0 0 30px hsl(197 50% 58% / .25); transform: scaleX(-1); }

.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); background: var(--card); color: var(--text); padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); z-index: 50; font-size: 14px; }
