:root {
  --bg: #0e1014;
  --panel: #14171d;
  --raised: #1b1f27;
  --line: #262b36;
  --text: #e8eaf0;
  --muted: #8d93a3;
  --accent: #8b9dff;
  --accent-ink: #0e1014;
  --danger: #ff8a8a;
  --radius: 10px;
  --side: 264px;
  --head: 64px;    /* height of the top bar; the title block in the left panel matches it */
  --tile: 168px;   /* width of a clip tile at 100% zoom */
  --zoom: 1;       /* set by the - % + control */
  --line-strong: #3a4152;
  --selected: #232a44;
  --selected-text: #ffffff;
  --float: #1b1f27;
  --veil: rgba(14, 16, 20, .5);
  --field-hover: #1a1e26;
  --menu-hover: #2a303c;
  color-scheme: dark;
}

/* light mode (the sun / moon button). Clips opened full size always stay on a dark backdrop. */
:root[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --raised: #eceef3;
  --line: #dde1e8;
  --text: #171a21;
  --muted: #626a79;
  --accent: #4b5fe0;
  --accent-ink: #ffffff;
  --danger: #c43131;
  --line-strong: #bfc5d1;
  --selected: #e2e6ff;
  --selected-text: #171a21;
  --float: #ffffff;
  --veil: rgba(245, 246, 248, .6);
  --field-hover: #f0f2f6;
  --menu-hover: #eef0f5;
  color-scheme: light;
}
.viewer {
  --bg: #0e1014; --panel: #14171d; --raised: #1b1f27; --line: #262b36; --text: #e8eaf0; --muted: #8d93a3;
  --accent: #8b9dff; --accent-ink: #0e1014; --line-strong: #3a4152;
  color: var(--text); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- shared bits ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand em { font-style: normal; font-weight: 400; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--raised); color: var(--text); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); }
.link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--raised); color: var(--text);
}
.icon-btn:hover { border-color: var(--line-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 14px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.login-card .brand { margin-bottom: 6px; font-size: 18px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px;
}
.login-card .btn { height: 40px; margin-top: 2px; }
.login-error { min-height: 18px; margin: -4px 0 0; color: var(--danger); font-size: 13px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100%; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 0 12px 14px; background: var(--panel); border-right: 1px solid var(--line);
}
.side .brand {
  flex: none; height: var(--head); width: calc(100% + 24px); margin: 0 -12px 16px; padding: 0 20px;
  border-bottom: 1px solid var(--line); font-size: 18px;
}
button.brand { background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; color: inherit; text-align: left; cursor: pointer; }
button.brand:hover em { color: var(--text); }

/* drag the right edge of the left panel to resize it */
.side-grip { position: absolute; top: 0; bottom: 0; right: -5px; width: 9px; z-index: 6; cursor: col-resize; touch-action: none; }
.side-grip::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px;
  background: var(--accent); opacity: 0; transition: opacity .15s ease;
}
.side-grip:hover::after { opacity: 1; transition-delay: .12s; }
body.resizing .side-grip::after { opacity: 1; }
body.resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }
body.resizing .main { pointer-events: none; }
.side-label { padding: 0 8px 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tree { flex: 1; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.me {
  display: flex; align-items: center; gap: 10px; padding: 12px 8px 0;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.me b { color: var(--text); font-weight: 600; }
.me > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* folder tree */
.node { display: flex; align-items: center; gap: 2px; border-radius: 7px; }
.node:hover { background: var(--raised); }
.node.on { background: var(--selected); }
.node.on .node-name { color: var(--selected-text); }
.twist {
  flex: none; width: 22px; height: 30px; display: grid; place-items: center;
  background: none; border: 0; color: var(--muted); padding: 0;
}
.twist svg { transition: transform .12s; }
.twist.open svg { transform: rotate(90deg); }
.twist.none { visibility: hidden; }
.node-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 30px;
  background: none; border: 0; padding: 0 8px 0 0; text-align: left;
}
.node-icon { flex: none; display: grid; place-items: center; width: 16px; height: 16px; color: var(--muted); }
.node-icon svg, .twist svg { display: block; }
.node-name { line-height: 16px; }
.node.on .node-icon { color: var(--accent); }
.node-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-count { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.kids { margin-left: 13px; padding-left: 5px; border-left: 1px solid var(--line); }


/* top bar */
.main { --pad: 22px; min-width: 0; padding: 0 var(--pad) 96px; }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  min-height: 64px; margin: 0 calc(var(--pad) * -1); padding: 12px var(--pad);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; flex: 1 1 160px; flex-wrap: wrap; }
.crumbs button { background: none; border: 0; padding: 0; color: var(--muted); font-weight: 500; }
.crumbs button:hover { color: var(--text); }
.crumbs .sep { color: var(--muted); opacity: .6; font-weight: 400; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tools input {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}

/* dropdowns (length, sort) */
.dd { position: relative; }
.dd-btn {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 12px; white-space: nowrap;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  transition: border-color .12s, background .12s;
}
.dd-btn:hover { border-color: var(--line-strong); background: var(--field-hover); }
.dd.open .dd-btn { border-color: var(--accent); }
.dd-btn svg { color: var(--muted); transition: transform .15s; }
.dd.open .dd-btn svg { transform: rotate(180deg); }
.dd-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 12; min-width: max(100%, 172px); padding: 5px;
  background: var(--float); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .32); animation: dd-in .12s ease-out;
}
.dd.right .dd-menu { left: auto; right: 0; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } }
.dd-opt {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 34px; padding: 0 12px 0 8px;
  background: none; border: 0; border-radius: 6px; color: var(--text); text-align: left; white-space: nowrap;
}
.dd-opt.at { background: var(--menu-hover); }
.dd-opt.on { color: var(--accent); font-weight: 600; }
.dd-opt .tick { display: grid; width: 16px; visibility: hidden; }
.dd-opt.on .tick { visibility: visible; }
.tools input { width: clamp(190px, 22vw, 300px); transition: border-color .12s, background .12s; }
.tools input:hover { border-color: var(--line-strong); background: var(--field-hover); }
.tools input:focus { border-color: var(--accent); background: var(--panel); outline: none; }
.sub { display: flex; align-items: center; gap: 14px; padding: 14px 0 12px; color: var(--muted); font-size: 13px; }

/* clips */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile) * var(--zoom)), 1fr)); gap: 14px; }

/* folders to choose from, shown instead of clips in a folder that has subfolders */
.folders {
  display: grid; gap: 14px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile) * var(--zoom)), 1fr));
}
.folder-tile {
  display: grid; gap: 8px; align-content: start; justify-items: start; min-width: 0; padding: 16px 14px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); text-align: left;
  transition: border-color .1s, background .1s;
}
.folder-tile:hover { border-color: var(--accent); background: var(--raised); }
.folder-tile svg { color: var(--accent); }
.folder-tile .f-name { font-weight: 600; overflow-wrap: break-word; min-width: 0; max-width: 100%; line-height: 1.3; }
.folder-tile .f-count { color: var(--muted); font-size: 12px; }
.folder-tile.all { border-style: dashed; }
.folder-tile.all svg { color: var(--muted); }

/* - 100% + */
.zoom { display: flex; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.zoom button { background: none; border: 0; padding: 0; height: 100%; }
.zoom button:hover:not(:disabled) { background: var(--raised); }
.zoom button:disabled { opacity: .35; cursor: default; }
#zoom-out, #zoom-in { width: 32px; font-size: 17px; line-height: 1; }
#zoom-level { width: 50px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.card { min-width: 0; user-select: none; -webkit-user-select: none; }
.media {
  position: relative; aspect-ratio: 9 / 16; border-radius: var(--radius); overflow: hidden;
  background: var(--raised); cursor: pointer; outline: 2px solid transparent; outline-offset: 2px;
  transition: outline-color .1s;
}
.card.picked .media { outline-color: var(--accent); }
.media img, .media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media video { opacity: 0; transition: opacity .12s; }
.media video.live { opacity: 1; }
.media::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 34%; pointer-events: none;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.dur {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; padding: 1px 6px; border-radius: 5px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums;
}
.tag {
  position: absolute; left: 8px; bottom: 8px; z-index: 2; padding: 1px 6px; border-radius: 5px;
  background: rgba(139, 157, 255, .92); color: var(--accent-ink); font-size: 11px; font-weight: 600;
}
.tag.warn { background: rgba(255, 196, 107, .95); }
.pick, .dl {
  position: absolute; top: 8px; z-index: 3; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center; background: rgba(14, 16, 20, .72); border: 1px solid rgba(255, 255, 255, .16);
  color: #fff; opacity: 0; transition: opacity .1s; backdrop-filter: blur(6px);
}
.pick { left: 8px; }
.dl { right: 8px; text-decoration: none; }
.media:hover .pick, .media:hover .dl, .card.picked .pick, .picking .pick { opacity: 1; }
.pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.pick svg { opacity: 0; }
.card.picked .pick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card.picked .pick svg { opacity: 1; }
.cap { display: flex; justify-content: space-between; gap: 8px; padding: 7px 2px 0; font-size: 13px; }
.cap .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.cap .what { flex: none; color: var(--muted); font-size: 12px; }
.empty { padding: 60px 0; text-align: center; color: var(--muted); }
.more { height: 1px; }

/* Soft fade at the bottom of the screen while there is more to scroll to. It is taller than the part you
   notice (the bottom ~5%) so that it can ease in from nothing instead of starting at a line. */
.fade {
  position: fixed; left: var(--side); right: 0; bottom: 0; height: 10vh; z-index: 4; pointer-events: none;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  background: var(--veil);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,.015) 12%, rgba(0,0,0,.05) 24%, rgba(0,0,0,.12) 36%, rgba(0,0,0,.23) 48%, rgba(0,0,0,.38) 60%, rgba(0,0,0,.56) 72%, rgba(0,0,0,.76) 84%, rgba(0,0,0,.92) 94%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,.015) 12%, rgba(0,0,0,.05) 24%, rgba(0,0,0,.12) 36%, rgba(0,0,0,.23) 48%, rgba(0,0,0,.38) 60%, rgba(0,0,0,.56) 72%, rgba(0,0,0,.76) 84%, rgba(0,0,0,.92) 94%, #000 100%);
  transition: opacity .2s;
}
.fade.off { opacity: 0; }

/* selection bar */
.selbar {
  position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 24px;
  background: var(--float); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .35); max-width: calc(100vw - 32px); font-size: 15px;
}
.selbar .btn { height: 44px; padding: 0 20px; font-size: 15px; }
#sel-clear { min-width: 116px; }
#sel-count { font-weight: 550; white-space: nowrap; margin-right: 6px; }

/* back to top, bottom right, once you have scrolled down */
.to-top {
  position: fixed; right: 24px; bottom: 28px; z-index: 19; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--float); color: var(--text);
  border: 1px solid var(--line-strong); box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s, transform .18s, border-color .12s;
}
.to-top.on { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: var(--accent); }

/* one-time tip that points at the sun / moon button: dark frosted glass in both modes */
.tip {
  position: fixed; z-index: 28; width: 236px; padding: 13px 14px 12px; border-radius: 12px;
  color: #f1f3f8; font-size: 13px; line-height: 1.45;
  background: rgba(20, 23, 30, .66); border: 1px solid rgba(255, 255, 255, .14);
  -webkit-backdrop-filter: blur(16px) saturate(1.3); backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .4);
  opacity: 0; transform: translateY(6px); transition: opacity .22s, transform .22s;
}
.tip.on { opacity: 1; transform: none; }
.tip p { margin: 0 0 10px; }
.tip button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: rgba(255, 255, 255, .16);
  color: #fff; font-weight: 600; font-size: 13px;
}
.tip button:hover { background: rgba(255, 255, 255, .26); }
.tip::after {
  content: ""; position: absolute; bottom: -6px; left: var(--arrow, 30px); width: 11px; height: 11px;
  background: rgba(20, 23, 30, .82); border-right: 1px solid rgba(255, 255, 255, .14); border-bottom: 1px solid rgba(255, 255, 255, .14);
  transform: rotate(45deg);
}

/* sun / moon: light and dark mode */
.theme {
  flex: none; width: 28px; height: 28px; margin: -5px 0; display: grid; place-items: center; padding: 0;
  background: none; border: 0; border-radius: 7px; color: var(--muted);
}
.theme:hover { color: var(--text); background: var(--raised); }
.theme svg { overflow: visible; }
.theme .orb, .theme .cut, .theme .rays { transform-box: fill-box; transform-origin: center; transition: transform .45s cubic-bezier(.5, 0, .2, 1), opacity .3s; }
.theme .cut { transform: translate(9px, -9px); }                       /* dark mode: a sun (nothing cut out) */
:root[data-theme="light"] .theme .orb { transform: scale(1.55); }       /* light mode: a crescent moon */
:root[data-theme="light"] .theme .cut { transform: none; }
:root[data-theme="light"] .theme .rays { transform: rotate(60deg) scale(.4); opacity: 0; }

/* one clip, full size */
.viewer {
  position: fixed; inset: 0; z-index: 30; background: rgba(6, 7, 10, .93);
  display: grid; place-items: center; padding: 20px 64px;
}
.v-body { display: flex; gap: 28px; align-items: center; max-width: 100%; max-height: 100%; }
#v-video { height: min(86vh, 900px); max-width: min(52vw, 520px); aspect-ratio: 9 / 16; border-radius: 12px; background: #000; }
.v-info { width: 280px; display: grid; gap: 12px; align-content: start; }
.v-info h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.v-name { margin: -6px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.v-info dl { margin: 4px 0 6px; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.v-info dt { color: var(--muted); }
.v-info dd { margin: 0; overflow-wrap: anywhere; }
.v-close { position: absolute; top: 16px; right: 16px; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%; }
.v-prev { left: 12px; }
.v-next { right: 12px; }

.scrim { display: none; }

/* ---------- narrow screens ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; z-index: 25; left: 0; top: 0; width: min(var(--side), 84vw);
    transform: translateX(-102%); transition: transform .18s;
  }
  .side.open { transform: none; }
  .side.open + .scrim { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(0, 0, 0, .55); }
  .menu { display: inline-grid; }
  .fade { left: 0; }
  .main { --pad: 16px; }
  .side-grip { display: none; }
  .selbar { bottom: 28px; gap: 8px; padding: 10px 10px 10px 16px; }
  .selbar .btn { height: 40px; padding: 0 14px; }
  #sel-clear { min-width: 0; }
  .to-top { right: 16px; bottom: 22px; }
  body.selecting .to-top { bottom: 104px; }
  .tools { width: 100%; }
  .tools input { flex: 1; width: auto; min-width: 0; }
  :root { --tile: 132px; }
  .grid, .folders { gap: 10px; }
  .pick, .dl { opacity: 1; }
  .viewer { padding: 56px 12px 12px; }
  .v-body { flex-direction: column; gap: 14px; overflow: auto; }
  #v-video { height: min(56vh, 620px); width: auto; max-width: 100%; }
  .v-info { width: 100%; }
  .v-nav { top: auto; bottom: 14px; transform: none; }
}
