:root {
  --edge: 16px;  /* gap between the + button and the screen's right and bottom edges */
  --plus: 56px;  /* the + button */
  --btn: 38px;   /* like / dislike / comment / share */
  --bg: #000;
  --fg: #f2f2f2;
  --dim: #8a8a8a;
  --line: rgba(255, 255, 255, 0.14);
  --glass: rgba(20, 20, 20, 0.6);
  --red: #ff3b4e;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.top {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.logo { font-weight: 700; letter-spacing: -0.02em; font-size: 18px; }

.icon-btn {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
/* Icons are PNG cutouts used as masks, so their color follows the button state. */
.ico {
  display: block; width: 22px; height: 22px; background: var(--fg);
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.i-sound { --icon: url(/icons/sound-off.png); width: 24px; height: 24px; }
.sound-on .i-sound { --icon: url(/icons/sound-on.png); }
.i-groups { --icon: url(/icons/groups.svg); width: 24px; height: 24px; }
.i-chat { --icon: url(/icons/comment.png); width: 24px; height: 24px; }
.i-arrow { --icon: url(/icons/chevron.png); width: 16px; height: 16px; }
.flip-r { transform: scaleX(-1); }

.pill {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
a.pill { color: inherit; text-decoration: none; }
.pill.danger { color: var(--red); border-color: rgba(255, 59, 78, .5); }
#postBtn { margin-left: auto; }
.pill.solid { background: var(--fg); color: #000; border-color: var(--fg); font-weight: 600; }
.pill.wide { width: 100%; padding: 14px; cursor: pointer; }

/* Feed: one slide on screen; the next ones wait below and slide up. */
.feed { position: absolute; inset: 0; overflow: hidden; touch-action: none; }

.slide {
  position: absolute; inset: 0; transform: translateY(100%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  display: flex; justify-content: center; align-items: center; background: var(--bg); overflow: hidden;
}
.slide.current { transform: none; }
.slide.out { transform: translateY(-100%); }
/* Centered 9:16 column, black bars either side on wide screens. */
.frame {
  position: relative; height: 100%; aspect-ratio: 9 / 16; max-width: 100%;
  background: #0b0b0b; overflow: hidden;
}
.frame video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.frame video.tall { object-fit: cover; }
/* A video's first frame, over it until it's playing (no black flash) */
.frame .cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.frame .cover.tall { object-fit: cover; }
.frame .cover.off { display: none; }
.frame .pic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* Dead feed: next in line to be deleted. */
.frame::after {
  content: ""; position: absolute; inset: 0; border: 4px solid #ff2d2d; border-radius: inherit;
  pointer-events: none; display: none; z-index: 4;
}
.slide.dead .frame::after, .slide.disliked .frame::after { display: block; } /* and any post you've thumbed down */

/* Phones: the video fills the screen, so sit just under the logo instead of on it. */
@media (min-width: 700px) {
  .slide { padding: 12px 0; }
  .frame { border-radius: 14px; }
}

/* Side buttons: a tight column hugging the right edge, above the + button. */
.side {
  position: absolute; right: calc(6px + env(safe-area-inset-right));
  bottom: calc(var(--edge) + var(--plus) + 12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 0;
}
.side .count { line-height: 1.25; }
.vote {
  width: var(--btn); height: var(--btn); border-radius: 50%; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform .08s ease;
}
.vote:active { transform: scale(0.9); }
.vote .ico { --icon: url(/icons/thumb.png); width: 19px; height: 19px; }
.dislike .ico { transform: scaleY(-1); } /* same sprite, flipped */
.vote.on { background: var(--fg); }
.vote.on .ico { background: #000; }
.side .dislike, .side .talk, .side .share { margin-top: 3px; }
.count { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.dim { color: var(--dim); }

.create {
  position: fixed; z-index: 20;
  right: calc(var(--edge) + env(safe-area-inset-right)); bottom: calc(var(--edge) + env(safe-area-inset-bottom));
  width: var(--plus); height: var(--plus); border-radius: 50%;
  background: var(--fg); color: #000; font-size: 30px; line-height: 1; font-weight: 300;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

.sheet-title { font-weight: 600; }

/* Make something: full-screen page */
.sheet {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: grid; grid-template-columns: 100%; place-items: center; padding: 16px;
}
.sheet-head { min-height: 44px; }

/* Picture crop: the picture moves behind a fixed phone-screen frame; outside it is dimmed. */
.sheet { overflow: hidden; }
#reviewImg {
  position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
}
#reviewImg:active { cursor: grabbing; }
.sheet.picture .stage { overflow: visible; touch-action: none; border-color: transparent; background: #000; }
.crop-frame {
  position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit;
  border: 2px solid #fff; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .72);
}
.sheet.picture .sheet-head, .sheet.picture .controls, .zoom-row, .hint { position: relative; z-index: 3; }
.sheet:not(.picture) .pic-only, .sheet:not(.picture) .crop-frame { display: none; }
.zoom-row {
  display: flex; align-items: center; gap: 10px; width: min(100%, calc(62dvh * 9 / 16)); margin: 0 auto;
  color: var(--dim); font-size: 18px;
}
.zoom-row input { flex: 1; accent-color: #fff; }
.hint { margin: 0; text-align: center; font-size: 12px; color: var(--dim); }
.sheet:not(.picture) #reviewImg,
.sheet.picture #review, .sheet.picture .trim, .sheet.picture .trim-play { display: none; }
.sheet-inner {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.x { font-size: 28px; width: 40px; height: 40px; color: var(--dim); }

.stage {
  position: relative; aspect-ratio: 9 / 16; width: min(100%, calc(62dvh * 9 / 16));
  margin: 0 auto; border-radius: 18px; overflow: hidden; background: #0b0b0b; border: 1px solid var(--line);
}
.stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 14px;
  background: #0b0b0b; pointer-events: none;
}
.sheet.loading .trim, .sheet.loading .trim-play { opacity: .3; pointer-events: none; }
/* Play / pause icon in the middle of a video (feed and trim screen). */
.center-icon {
  position: absolute; left: 50%; top: 50%; width: 76px; height: 76px; margin: -38px 0 0 -38px;
  display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, .5);
  opacity: 0; transition: opacity .3s ease; pointer-events: none; z-index: 3;
}
.center-icon svg { grid-area: 1 / 1; width: 36px; height: 36px; fill: #fff; }
.center-icon .i-pause, .center-icon.flash .i-play { display: none; }
.center-icon.flash .i-pause { display: block; }
.center-icon.paused, .center-icon.flash { opacity: 1; }
.center-icon.flash { transition: none; }
.trim-play { pointer-events: auto; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 76px; }
.controls .pill { min-width: 84px; }

/* Trimmer */
.trim { display: flex; flex-direction: column; gap: 8px; width: min(100%, calc(62dvh * 9 / 16)); margin: 0 auto; }
.trim-track {
  position: relative; height: 44px; border-radius: 10px; background: #161616; border: 1px solid var(--line);
  touch-action: none;
}
.trim-sel {
  position: absolute; top: -1px; bottom: -1px; border: 2px solid var(--fg); border-radius: 10px;
  background: rgba(255, 255, 255, 0.12); cursor: grab;
}
.trim-sel:active { cursor: grabbing; }
/* Where the video is right now. */
.trim-head {
  position: absolute; top: -8px; bottom: -8px; width: 3px; margin-left: -1.5px; z-index: 2;
  background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.6); pointer-events: none;
}
.trim-head::before {
  content: ""; position: absolute; top: -4px; left: 50%; width: 11px; height: 11px; margin-left: -5.5px;
  border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6);
}
.trim-handle {
  position: absolute; top: 50%; width: 18px; height: 52px; margin: -26px 0 0 -9px;
  border-radius: 6px; background: var(--fg); cursor: ew-resize; touch-action: none; z-index: 3;
}
.trim-handle::after {
  content: ""; position: absolute; inset: 16px 7px; border-left: 2px solid #000; border-right: 2px solid #000; opacity: .35;
}
.trim-info {
  display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums;
}
.trim-now { color: var(--fg); font-weight: 600; }

.rules { margin: 0; text-align: center; font-size: 12px; color: var(--dim); line-height: 1.5; }

.toast {
  position: fixed; z-index: 40; left: 50%; bottom: 96px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: #1c1c1c; border: 1px solid var(--line); font-size: 14px; text-align: center;
}
.vote.small { width: 34px; height: 34px; }
.vote.small .ico { width: 16px; height: 16px; }
.answering { display: block; font-size: 12px; color: var(--dim); margin-bottom: 2px; overflow-wrap: anywhere; }
.thread-toggle { display: block; margin: -2px 0 6px 46px; padding: 4px 0; font-size: 12px; font-weight: 600; color: var(--dim); }
.thread-toggle::before { content: ""; display: inline-block; width: 20px; height: 1px; margin-right: 8px; vertical-align: middle; background: var(--dim); }
.cv { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 34px; }
.cv .count { font-size: 11px; }
.vote.small.talk .ico { --icon: url(/icons/comment.png); width: 18px; height: 18px; }
.x.small { width: 28px; height: 28px; font-size: 20px; }

/* Share button */
.vote.share .ico { --icon: url(/icons/share.png); width: 19px; height: 19px; }

/* Small popup in the middle (e.g. a shared post that's been deleted) */
.notice {
  position: fixed; z-index: 50; left: 50%; top: 45%; transform: translate(-50%, -50%);
  max-width: calc(100% - 48px); padding: 16px 22px; border-radius: 16px; text-align: center;
  background: #1c1c1c; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.6);
  font-size: 15px; font-weight: 600; opacity: 1; transition: opacity .5s ease;
}
.notice.fade { opacity: 0; } /* same arrow, mirrored */
/* Computers get side arrows on hover; phones swipe. */
@media (hover: hover) and (pointer: fine) {
  .frame:hover .nav { display: grid; }
}
/* Between items: nothing to trim or frame */
.sheet.empty #review, .sheet.empty #reviewImg, .sheet.empty .trim, .sheet.empty .pic-only,
.sheet.empty .trim-play, .sheet.empty .crop-frame { display: none !important; }
.sheet.empty .stage { background: #0b0b0b; border-color: var(--line); }

/* The hidden player that prepares videos for upload */
video.worker { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

/* A post on its way up */
.upload-bar {
  position: fixed; z-index: 45; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 120px); padding: 8px 14px;
  border-radius: 999px; overflow: hidden; background: #1c1c1c; border: 1px solid var(--line);
  font-size: 13px; white-space: nowrap; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.upload-bar #uploadText { overflow: hidden; text-overflow: ellipsis; }
.upload-bar button { color: var(--fg); font-weight: 600; }
.upload-bar.failed { border-color: rgba(255, 59, 78, .5); }
.upload-fill { position: absolute; left: 0; bottom: 0; height: 2px; width: 0; background: var(--fg); transition: width .2s ease; }
.upload-bar.failed .upload-fill { display: none; }

/* --- The three screens: groups, videos, chat ------------------------------- */
.pager {
  position: fixed; inset: 0; width: 300vw; display: flex; transform: translateX(-100vw);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1); touch-action: pan-y;
}
.screen { position: relative; flex: 0 0 100vw; height: 100dvh; overflow: hidden; background: var(--bg); }
.side-screen { display: flex; flex-direction: column; padding: max(10px, env(safe-area-inset-top)) 12px 0; }
/* These sat against the page; now they sit on the center screen and move with it. */
.center .top, .center .create { position: absolute; }
.center .top { justify-content: flex-start; gap: 8px; }
.group-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 4px rgba(0, 0, 0, .7); }
.small { font-size: 12px; }
.icon-btn { position: relative; flex: none; }
.icon-btn.small { width: 40px; height: 40px; }
/* Something new on another screen */
.dot { position: absolute; top: 2px; right: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px #000; }
.screen-head { display: flex; align-items: center; gap: 10px; min-height: 48px; padding-bottom: 10px; }
.screen-title { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#groupsScreen .screen-title { flex: none; }
#groupsScreen #toFeedL { margin-left: auto; }
#groupsScreen #adminLink { margin-left: auto; }
body.admin #groupsScreen #adminLink + #toFeedL { margin-left: 0; }

/* A post's code */
.post-code {
  position: absolute; z-index: 5; left: calc(10px + env(safe-area-inset-left)); bottom: calc(26px + env(safe-area-inset-bottom));
  padding: 3px 8px; border-radius: 999px; background: var(--glass); font: 12px ui-monospace, Menlo, monospace; color: var(--fg);
}
.side .share { margin-top: 3px; }
.frame .del, .group-row .del { background: rgba(255, 59, 78, .85); border-color: transparent; }
.vote.del .ico { --icon: url(/icons/delete.svg); }
.side .del { margin-top: 10px; }

/* Only for admins */
.admin-only { display: none !important; }
body.admin .admin-only { display: grid !important; }
body.admin a.admin-only { display: inline-flex !important; }

/* --- Groups --------------------------------------------------------------- */
#newGroupBtn { flex: none; margin-bottom: 10px; }
.group-list { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; padding-bottom: env(safe-area-inset-bottom); }
.group-row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 12px; cursor: pointer; }
.group-row:hover { background: rgba(255, 255, 255, .05); }
.group-row.on { background: rgba(255, 255, 255, .1); }
.group-icon {
  width: 40px; height: 40px; flex: none; border-radius: 10px; overflow: hidden; display: grid; place-items: center;
  background: #1c1c1c; border: 1px solid var(--line); font-weight: 700; text-transform: uppercase;
}
.group-icon img { width: 100%; height: 100%; object-fit: cover; }
.group-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.group-row-name, .group-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row-name { font-weight: 600; }
.group-desc:empty { display: none; }

/* --- Chat ------------------------------------------------------------------ */
.chat-title { flex: 1; min-width: 0; }
/* Pops up for a few seconds in the top corner of the feed and chat. */
.post-notes {
  position: fixed; z-index: 15; right: 10px; top: calc(max(14px, env(safe-area-inset-top)) + 58px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none;
}
body.on-groups .post-notes { display: none; }
.post-note {
  pointer-events: auto; padding: 6px 10px; border-radius: 10px; font-size: 13px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: note-in .2s ease; transition: opacity .4s ease;
}
.post-note.fade { opacity: 0; }
@keyframes note-in { from { opacity: 0; transform: translateY(-6px); } }
.code-link { padding: 0; font: 12px ui-monospace, Menlo, monospace; color: #7fb6ff; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
/* A few messages sit at the bottom by the message box; older ones climb up. */
.chat-list > :first-child { margin-top: auto; }
.msg { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding: 6px 10px; border-radius: 10px; font-size: 15px; line-height: 1.35; }
.msg { align-self: flex-start; max-width: 85%; background: rgba(255, 255, 255, .06); }
/* Your own messages are on the right. */
.msg.mine { align-self: flex-end; background: rgba(255, 255, 255, .14); }
.msg.mine .sender, .msg.mine .small { margin-left: auto; }
.msg.private { background: rgba(127, 182, 255, .12); }
.msg.system { color: var(--dim); font-size: 13px; padding: 2px 8px; background: none; }
.sender { padding: 0; font: 600 12px ui-monospace, Menlo, monospace; color: var(--dim); }
.sender.is-admin { color: var(--red); }
.msg-body { flex: 1 1 100%; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
/* Five lines on screen, however wide the phone. Tapping shows the rest of a long one. */
.msg-body.clamped:not(.open) { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden; }
body.admin .msg:not(.system) { padding-right: 28px; }
.msg-del { position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; place-items: center; color: var(--red); font-size: 18px; line-height: 1; }
/* Command auto-fill, above the message box */
.cmd-list { display: flex; flex-direction: column; margin-bottom: 6px; border-radius: 12px; overflow: hidden; background: #161616; border: 1px solid var(--line); }
.cmd { display: flex; align-items: baseline; gap: 10px; padding: 8px 12px; text-align: left; width: 100%; }
.cmd.on { background: rgba(255, 255, 255, .12); }
.cmd b { font: 600 13px ui-monospace, Menlo, monospace; flex: none; }
.cmd span { min-width: 0; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-form { flex: none; padding: 6px 0 max(10px, env(safe-area-inset-bottom)); }
.chat-bar { display: flex; align-items: flex-end; gap: 8px; }
.chat-bar textarea {
  flex: 1; min-width: 0; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 18px; outline: 0;
  background: #161616; border: 1px solid var(--line); color: var(--fg); font-size: 16px; line-height: 1.3; font-family: inherit; /* 16px stops phones zooming in */
}
.falling { position: fixed; z-index: 95; pointer-events: none; will-change: transform; white-space: pre; color: var(--fg); }
.falling-pic { object-fit: contain; }

/* --- Dialogs and the warning ------------------------------------------------ */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .6); }
.modal-box { width: min(100%, 440px); display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 16px; background: #111; border: 1px solid var(--line); }
.modal-box p { margin: 0; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.new-group-body { display: flex; gap: 10px; }
.icon-pick { width: 76px; height: 76px; flex: none; border-radius: 16px; overflow: hidden; display: grid; place-items: center; background: #1c1c1c; border: 1px dashed rgba(255, 255, 255, .3); font-size: 26px; font-weight: 700; text-transform: uppercase; }
.icon-pick img { width: 100%; height: 100%; object-fit: cover; }
.fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.fields textarea { width: 100%; resize: none; padding: 9px 12px; border-radius: 10px; outline: 0; background: #161616; border: 1px solid var(--line); color: var(--fg); font-size: 16px; font-family: inherit; }
.gate { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; background: #000; }
/* Nothing chosen yet in the creator */
.sheet.empty #review, .sheet.empty #reviewImg, .sheet.empty .trim, .sheet.empty .pic-only, .sheet.empty .trim-play, .sheet.empty .crop-frame { display: none !important; }
.sheet.empty .stage { background: #0b0b0b; border-color: var(--line); }
.sheet.empty .stage { cursor: pointer; }
.pill:disabled { opacity: .35; cursor: default; }
