/* =========================================================
   Side Quest — design tokens
   Palette: void/ink background, violet primary, gold marker
   accent, rose for likes. One display treatment (wordmark),
   everything else quiet.
   ========================================================= */
:root {
  --void: #0b0a14;
  --surface: #15121f;
  --surface-2: #1e1a2c;
  --surface-3: #29233b;
  --hairline: #2c2740;
  --text: #f2eefb;
  --text-dim: #9c93b5;
  --text-faint: #675f80;
  --violet: #7c5cff;
  --violet-dim: #5a3fd6;
  --gold: #f5b942;
  --rose: #ff4d6d;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-lg: 8px;
  --radius-md: 5px;
  --radius-sm: 4px;
  --ease: ease;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

.is-hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------------------------------------------------------
   Buttons / fields
   --------------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--violet); color: #fff; }
.btn-primary:hover { background: var(--violet-dim); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--hairline); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn {
  appearance: none; border: none; background: transparent; color: var(--text-dim);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); }

.field {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; text-align: left;
}
.field span { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.field input, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 15px;
  resize: none;
}
.field input:focus, .field textarea:focus { border-color: var(--violet); outline: none; }

.auth-error {
  color: var(--rose);
  font-size: 13px;
  min-height: 16px;
  margin: -4px 0 10px;
}
.auth-error:empty { margin: 0; min-height: 0; }

/* ---------------------------------------------------------
   Auth screen
   --------------------------------------------------------- */
.screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--void);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 20px;
}

.auth-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 22px;
  border: 1px solid var(--hairline);
}
.auth-tab {
  flex: 1;
  appearance: none; border: none; background: transparent;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.auth-tab.is-active { background: var(--violet); color: #fff; }

.auth-form { text-align: left; }

.avatar-picker {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  appearance: none; background: none; border: none; cursor: pointer;
  margin: 0 auto 18px; color: var(--text-dim); font-size: 12.5px; font-weight: 600;
}
.avatar-picker img {
  width: 76px; height: 76px; border-radius: 50%; object-fit: cover;
  background: var(--surface-3);
  border: 2px dashed var(--hairline);
}
.avatar-picker img[src] { border-style: solid; }

/* ---------------------------------------------------------
   App shell
   --------------------------------------------------------- */
#app-shell { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 16px;
  flex: 0 0 auto;
  background: var(--void);
  border-bottom: 1px solid var(--hairline);
  position: relative; z-index: 5;
}
.topbar-title { font-weight: 700; font-size: 16px; }

.view { display: none; flex: 1 1 auto; min-height: 0; }
.view.is-active { display: flex; flex-direction: column; }

.navbar {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--hairline);
  background: var(--surface);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1;
  appearance: none; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 0 5px;
  color: var(--text-faint);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
}
.nav-btn svg {
  width: 23px; height: 23px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-btn.is-active { color: var(--text); }
.nav-btn.is-active svg { stroke: var(--violet); stroke-width: 2.1; }
/* Upload's icon is a standing gold badge, independent of the active state. */
.nav-btn[data-nav="upload"] svg rect { fill: var(--gold); stroke: none; }
.nav-btn[data-nav="upload"] svg path { stroke: var(--void); stroke-width: 2; }
.nav-btn[data-nav="upload"].is-active svg rect { fill: #ffc766; }

/* ---------------------------------------------------------
   Feed
   --------------------------------------------------------- */
.feed {
  flex: 1 1 auto;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
}
.feed::-webkit-scrollbar { display: none; }

.feed-card {
  position: relative;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: flex-end;
  background: #000;
  overflow: hidden;
}

.feed-card video {
  position: absolute; inset: 0;
  z-index: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}

.feed-card::before {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 45%;
  z-index: 1;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.75) 100%);
  pointer-events: none;
}

.feed-meta {
  position: relative;
  z-index: 2;
  padding: 0 84px 22px 16px;
  width: 100%;
}

.feed-creator {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 8px;
  background: none; border: none; padding: 0; cursor: pointer;
}
.feed-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  object-fit: cover; border: 1.5px solid rgba(255,255,255,.5);
  background: var(--surface-3);
  flex: 0 0 auto;
}
.feed-username { font-weight: 700; font-size: 14.5px; color: #fff; }
.feed-handle { font-weight: 500; font-size: 12px; color: rgba(255,255,255,.7); margin-left: 6px; }

.feed-pause-icon {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s var(--ease);
}
.feed-card.is-paused .feed-pause-icon { opacity: 1; }
.feed-pause-icon svg {
  width: 64px; height: 64px;
  fill: rgba(255,255,255,.85);
  filter: drop-shadow(0 4px 16px rgba(0,0,0,.5));
}

.feed-caption {
  font-size: 14px;
  color: rgba(255,255,255,.92);
  line-height: 1.4;
  margin: 0 0 4px;
  max-width: 88%;
}

.feed-rail {
  position: absolute;
  right: 10px;
  bottom: 20px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.rail-btn {
  appearance: none; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; color: #fff;
  padding: 0;
}
.rail-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55);
}
.rail-icon svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.rail-count { font-size: 11.5px; font-weight: 700; color: #fff; }

.rail-btn[data-action="like"].is-active .rail-icon svg { fill: var(--rose); stroke: var(--rose); }
.rail-btn[data-action="save"].is-active .rail-icon svg { fill: var(--gold); stroke: var(--gold); }

.rail-follow {
  appearance: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--violet);
  border: 2px solid var(--void);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 17px; font-weight: 800; line-height: 1;
  cursor: pointer; margin-top: -8px;
}
.rail-follow.is-following { background: var(--surface-3); color: var(--text-dim); font-size: 13px; }
.rail-follow.is-self { display: none; }

.feed-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; padding: 40px 30px; color: var(--text-dim);
}
.feed-empty h2 { color: var(--text); font-size: 18px; margin: 0; }
.feed-empty p { margin: 0 0 14px; font-size: 14px; }

/* ---------------------------------------------------------
   Upload
   --------------------------------------------------------- */
.upload-wrap { padding: 4px 18px 18px; max-width: 460px; margin: 0 auto; width: 100%; overflow-y: auto; }
.upload-wrap h2 { font-size: 19px; margin: 4px 0 16px; }

.upload-drop {
  display: block;
  position: relative;
  aspect-ratio: 9 / 13;
  max-height: 46vh;
  border-radius: var(--radius-lg);
  border: 1.5px dashed var(--hairline);
  background: var(--surface);
  cursor: pointer;
  margin-bottom: 16px;
  overflow: hidden;
}
.upload-drop-copy {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--text-dim); font-size: 13.5px; font-weight: 600; text-align: center; padding: 20px;
}
.upload-drop-icon {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--gold); font-weight: 700;
}
.upload-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------------------------------------------------------
   Profile
   --------------------------------------------------------- */
.profile-wrap { padding: 4px 18px 18px; max-width: 520px; margin: 0 auto; width: 100%; overflow-y: auto; }

.profile-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 0 18px; }
.profile-avatar-btn {
  appearance: none; border: none; background: none; cursor: pointer; padding: 0;
  border-radius: 50%;
  margin-bottom: 10px;
}
.profile-avatar-btn img {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  background: var(--surface-3); border: 2px solid var(--hairline);
}
#profile-username { font-size: 18px; margin: 0 0 2px; }
#profile-handle { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; }
#profile-edit-btn, #profile-mod-role-btn, #profile-mod-delete-btn, #profile-self-delete-btn { font-size: 12.5px; padding: 6px 14px; margin-bottom: 10px; }
#profile-mod-delete-btn, #profile-self-delete-btn { color: var(--rose); border-color: var(--rose); }

.profile-stats { display: flex; gap: 28px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat strong { font-size: 16px; }
.stat span { font-size: 11.5px; color: var(--text-dim); }

#profile-follow-btn { margin-bottom: 8px; min-width: 140px; }
#profile-logout-btn { font-size: 13px; padding: 8px 18px; }

.profile-tabs {
  display: flex;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 14px;
}
.profile-tab {
  flex: 1; appearance: none; border: none; background: none; cursor: pointer;
  padding: 11px 0; color: var(--text-faint); font-size: 13px; font-weight: 700;
  border-bottom: 2px solid transparent;
}
.profile-tab.is-active { color: var(--text); border-bottom-color: var(--gold); }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.profile-grid-item {
  position: relative;
  aspect-ratio: 9 / 14;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  border: none;
  padding: 0;
}
.profile-grid-item video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.grid-delete {
  position: absolute; top: 4px; right: 4px; z-index: 1;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.65); color: #fff; font-size: 15px; line-height: 1;
}
.grid-delete:hover { background: var(--rose); }
.grid-empty { text-align: center; color: var(--text-dim); font-size: 13.5px; padding: 30px 0; }

/* ---------------------------------------------------------
   Comments sheet
   --------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 5, 12, .55);
  display: flex; align-items: flex-end;
}
.comments-sheet {
  width: 100%;
  max-height: 72vh;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  border-radius: 0;
  display: flex; flex-direction: column;
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.comments-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 8px 12px 18px;
  border-bottom: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.comments-head h3 { font-size: 15px; margin: 0; }
#comments-count { color: var(--text-dim); font-weight: 500; }

.comments-list { flex: 1 1 auto; overflow-y: auto; padding: 8px 18px; }
.comment-row { display: flex; gap: 10px; padding: 10px 0; }
.comment-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex: 0 0 auto; }
.comment-body { flex: 1; min-width: 0; }
.comment-user { font-size: 13px; font-weight: 700; margin-right: 6px; }
.comment-text { font-size: 13.5px; color: var(--text); word-wrap: break-word; }
.comment-time { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.comment-delete {
  appearance: none; border: none; background: none; color: var(--text-faint);
  font-size: 12px; cursor: pointer; padding: 4px; align-self: flex-start;
}
.comment-delete:hover { color: var(--rose); }
.comments-empty { text-align: center; color: var(--text-dim); font-size: 13.5px; padding: 30px 0; }

.comment-form {
  display: flex; gap: 10px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.comment-form input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); padding: 11px 16px; font-size: 14px;
}
.comment-form input:focus { outline: none; border-color: var(--violet); }
.comment-form .btn { padding: 10px 18px; font-size: 13.5px; }

/* ---------------------------------------------------------
   Toast
   --------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%; bottom: 90px;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  transition: opacity .15s linear;
  pointer-events: none;
  white-space: nowrap;
}
.toast.is-visible { opacity: 1; }

/* ---------------------------------------------------------
   Responsive: desktop
   --------------------------------------------------------- */
@media (min-width: 720px) and (max-width: 899px) {
  .screen { padding: 40px; }

  #app-shell { align-items: center; }
  .topbar, .view, .navbar { width: 100%; max-width: 460px; }
  #app-shell {
    max-height: 900px;
    height: 92vh;
    margin: auto;
    border: 1px solid var(--hairline);
    overflow: hidden;
  }
  body { display: flex; }
}

/* Wide desktop: stop pretending to be a phone floating in a void.
   The nav becomes a left rail (like a real desktop app), and the
   whole shell scales up to use the space instead of sitting in a
   tiny fixed-width card. */
@media (min-width: 900px) {
  .screen { padding: 28px; }
  body { display: flex; }

  #app-shell {
    flex-direction: row;
    align-items: stretch;
    width: min(94vw, 1180px);
    height: 92vh;
    max-height: 1040px;
    margin: auto;
    border: 1px solid var(--hairline);
    overflow: hidden;
  }

  .topbar { display: none; }

  .navbar {
    order: -1;
    flex-direction: column;
    justify-content: center;
    gap: 30px;
    width: 104px;
    height: 100%;
    border-top: none;
    border-right: 1px solid var(--hairline);
    padding: 0;
  }
  .nav-btn { flex: 0 0 auto; padding: 10px 0; }
  .nav-btn:hover { color: var(--text); }
  .nav-btn svg { width: 26px; height: 26px; }

  .view { flex: 1 1 auto; width: auto; max-width: none; height: 100%; }

  .feed { scroll-snap-type: y mandatory; }
  .feed-card {
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
    border-radius: 0;
  }

  .upload-wrap, .profile-wrap { max-width: 460px; margin: 0 auto; padding-top: 24px; }

  /* Mouse-friendly hover feedback the touch version doesn't need */
  .rail-btn:hover .rail-icon { background: rgba(0, 0, 0, .8); }
  .profile-tab:hover, .auth-tab:hover { color: var(--text); }
}
