:root{
  /* QueenCharleen Palette */
  --qc-royal-plum: #6A0DAD;
  --qc-blush-rose: #E8A0B0;
  --qc-steel-gray: #4A4A4A;
  --qc-moonlight-silver: #D8D8D8;
  --qc-electric-violet: #8A2BE2;

  /* App Mapping */
  --bg:#0f0a18;
  --bg-soft:#161022;

  --text:#F3ECFF;
  --text-muted:#C9C2E0;

  --panel:#1a1328;
  --border:rgba(216,216,216,.18);

  --accent:var(--qc-electric-violet);
  --accent-soft:rgba(138,43,226,.25);
  --accent-secondary:var(--qc-blush-rose);

  --shadow:0 14px 40px rgba(0,0,0,.55);
  --radius:16px;

  /* Modal bar safety height */
  --modal-bar-min:88px;
}

*{ box-sizing:border-box; }
html,body{ height:auto; }

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 600px at 15% 10%, rgba(138,43,226,.18) 0%, transparent 60%),
    radial-gradient(900px 600px at 85% 20%, rgba(232,160,176,.18) 0%, transparent 60%),
    linear-gradient(180deg, #0c0814 0%, #140e22 100%);
  color:var(--text);
}

a{ color:inherit; text-decoration:none; }
.muted{ color:var(--text-muted); }

.container{ max-width:1400px; margin:0 auto; padding:20px; }

/* HEADER */
.topbar{
  position:sticky;
  top:0;
  z-index:50;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 18px;
  background: rgba(26,19,40,.85);
  backdrop-filter: blur(10px);
  border-bottom:1px solid var(--border);
}

.topbar-left{ display:flex; align-items:center; gap:12px; }

.logo{
  font-weight:800;
  letter-spacing:.3px;
  color:var(--qc-blush-rose);
}

.userpill{
  padding:8px 10px;
  border:1px solid rgba(138,43,226,.30);
  background: rgba(138,43,226,.15);
  border-radius:999px;
  font-size:13px;
  color:var(--text-muted);
}
.userpill span{ color:var(--text); }

.topbar-right{ display:flex; align-items:center; gap:14px; flex-wrap:wrap; }

/* NAV */
.sortnav{
  display:flex;
  gap:8px;
  padding:6px;
  border:1px solid var(--border);
  border-radius:999px;
  background: rgba(138,43,226,.12);
}
.sortnav a{
  padding:8px 10px;
  border-radius:999px;
  font-size:13px;
  color:var(--text-muted);
}
.sortnav a.active{
  color:white;
  background: rgba(138,43,226,.45);
  border:1px solid rgba(138,43,226,.6);
}

/* BUTTONS */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:10px 14px;
  border-radius:12px;
  border:1px solid rgba(138,43,226,.35);
  background: linear-gradient(180deg, rgba(138,43,226,.30), rgba(106,13,173,.22));
  color:white;
  font-weight:700;
  font-size:13px;
  cursor:pointer;
  transition:all .18s ease;
}
.btn:hover{
  background: linear-gradient(180deg, rgba(138,43,226,.55), rgba(106,13,173,.40));
  transform: translateY(-1px);
}

.upload{ display:flex; align-items:center; gap:10px; }
.upload input[type="file"]{ max-width:260px; color:var(--text-muted); }

/* GRID */
.grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap:14px;
  padding-top:8px;
}

/* CARDS */
.card{
  border:1px solid var(--border);
  background: linear-gradient(180deg, rgba(138,43,226,.18), rgba(106,13,173,.12));
  border-radius: var(--radius);
  overflow:hidden;
  box-shadow: var(--shadow);
}

.thumb{ width:100%; border:0; background:transparent; cursor:pointer; display:block; }

.thumb img,
.thumb-video{
  width:100%;
  height:240px;
  object-fit:cover;
  display:block;
  transition: transform .2s ease;
}
.card:hover .thumb img,
.card:hover .thumb-video{ transform: scale(1.05); }

.cardmeta{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:12px;
}

.score{
  font-weight:800;
  font-size:13px;
  color:var(--qc-moonlight-silver);
}

.stars{ display:flex; gap:6px; }

.star{
  border:0;
  background:transparent;
  color:var(--qc-blush-rose);
  font-size:20px;
  cursor:pointer;
  transition:all .15s ease;
}
.star:hover{
  color:var(--qc-electric-violet);
  transform: scale(1.2);
  text-shadow:0 0 10px rgba(138,43,226,.6);
}

/* MODAL */
.modal.hidden{ display:none; }
body.modal-open{ overflow:hidden; }

.modal{
  position:fixed;
  inset:0;
  z-index:1000;
  display:flex;
  align-items:center;
  justify-content:center;
}

.modal-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.75);
}

.modal-shell{
  position:relative;
  width:min(1600px, calc(100vw - 24px));
  height:min(92vh, 980px);
  border-radius:22px;
  background: linear-gradient(180deg, rgba(26,19,40,.95), rgba(18,12,28,.96));
  border:1px solid rgba(138,43,226,.25);
  box-shadow:0 0 40px rgba(138,43,226,.25), 0 10px 30px rgba(0,0,0,.6);
  overflow:hidden;
  display:flex;
}

/* HARD SPLIT MODAL */
.modal-content{
  width:100%;
  height:100%;
  display:grid;
  grid-template-rows: 1fr auto;
  min-height:0;
}

/* MEDIA */
.modal-media{
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:12px;
  overflow:hidden;
}

.modal-media-inner{
  width:100%;
  height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
}

.modal-media-inner img,
.modal-media-inner video{
  width:100%;
  height:100%;
  object-fit:contain;
  border-radius:12px;
}

/* BAR ALWAYS VISIBLE */
.modal-bar{
  min-height:var(--modal-bar-min);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 12px;
  border-top:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
}

.modal-score{ font-weight:800; font-size:13px; }
.modal-stars{ display:flex; gap:8px; }
.modal-hint{ font-size:12px; color:var(--text-muted); }

/* NAV BUTTONS */
.iconbtn{
  position:absolute;
  z-index: 9000;
  top:12px;
  right:12px;
  width:40px;
  height:40px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color:white;
  cursor:pointer;
}

.navbtn{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  width:56px;
  height:140px;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color:white;
  font-size:42px;
  cursor:pointer;
}
#prev{ left:12px; }
#next{ right:12px; }

/* MOBILE */
@media (max-width:820px){
  .grid{ grid-template-columns: repeat(2, 1fr); }
  .thumb img,.thumb-video{ height:160px; }

  .modal-shell{
    width:100vw;
    height:100vh;
    border-radius:0;
  }
  @supports(height:100dvh){ .modal-shell{ height:100dvh; } }

  .modal-content{
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-bar{
    flex-direction:column;
    align-items:flex-start;
    gap:8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .navbtn{
    top:auto;
    bottom: calc(var(--modal-bar-min) + env(safe-area-inset-bottom));
    transform:none;
    width:52px;
    height:52px;
    font-size:34px;
  }
}

@media (max-width:420px){
  .grid{ grid-template-columns: 1fr; }
}

/* ===== LOGIN / AUTH SCREEN CENTER FIX ===== */

body.authonly{
  min-height:100dvh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
}

.authwrap{
  width:100%;
  max-width:520px;
  display:flex;
  align-items:center;
  justify-content:center;
}

.authcard{
  width:100%;
  text-align:center;

  padding:42px 32px;
  border-radius:20px;

  border:1px solid rgba(216,216,216,.18);
  background: linear-gradient(
    180deg,
    rgba(138,43,226,.18),
    rgba(106,13,173,.12)
  );

  box-shadow:
    0 0 40px rgba(138,43,226,.18),
    0 18px 45px rgba(0,0,0,.55);

  backdrop-filter: blur(12px);
}

/* Logo / title */
.authcard .brand{
  font-size:28px;
  font-weight:800;
  margin-bottom:12px;
  color:#E8A0B0;
}

/* Description */
.authcard .desc{
  font-size:15px;
  color:#C9C2E0;
  margin-bottom:26px;
}

/* Buttons stack centered */
.authbuttons{
  display:flex;
  flex-direction:column;
  gap:12px;
  align-items:center;
}

.authbuttons .btn{
  width:100%;
  max-width:280px;
  justify-content:center;
}

/* Fine print */
.fineprint{
  margin-top:22px;
  font-size:12px;
  color:#9a92b8;
}

/* Mobile polish */
@media (max-width:600px){
  .authcard{
    padding:32px 22px;
  }

  .authcard .brand{
    font-size:24px;
  }
}
