:root {
  --bg: #0e0f13;
  --bg-elev: #171922;
  --bg-elev2: #1e212c;
  --line: #2a2e3a;
  --text: #e7e9ee;
  --muted: #9aa0ad;
  --accent: #6c8cff;
  --accent-2: #57d9a3;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(14,15,19,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .3px;
  color: var(--text);
}
.brand span { color: var(--accent); }
.header-spacer { flex: 1; }
.header-nav { display: flex; align-items: center; gap: 8px; }
.header-nav .who { color: var(--muted); font-size: 13px; margin-right: 6px; }

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

/* buttons + inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0d16; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: #4a2a30; background: #241a1e; }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-ghost { background: transparent; }

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }

/* centered auth card */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 6px; }
.error-box {
  background: #2a1a1e; border: 1px solid #4a2a30; color: #ffb4b4;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.ok-box {
  background: #16261f; border: 1px solid #204a3a; color: #a9f0cf;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}

/* toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .count { color: var(--muted); font-size: 14px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.search { max-width: 420px; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--muted); font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #0b0d16; font-weight: 600; }

/* gallery grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: .15s;
  display: flex;
  flex-direction: column;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0a0b0f center/cover no-repeat;
  display: block;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(0,0,0,.7);
  color: #fff;
}
.badge.dur { bottom: 8px; right: 8px; }
.badge.fmt { top: 8px; left: 8px; background: rgba(108,140,255,.85); color: #0b0d16; }
.badge.cc { top: 8px; right: 8px; background: rgba(87,217,163,.85); color: #06120d; }
.badge.watched { bottom: 8px; left: 8px; background: rgba(87,217,163,.9); color: #06120d; }
.pbar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.card-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-size: 13.5px; line-height: 1.35; word-break: break-word; }
.card-meta { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.card-actions { display: flex; gap: 8px; margin-top: auto; }
.card-actions .btn { flex: 1; justify-content: center; }

.empty { text-align: center; color: var(--muted); padding: 80px 20px; }
.empty h2 { color: var(--text); }

/* player */
.player-shell { max-width: 1100px; margin: 0 auto; }
.player-box { background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
video { width: 100%; display: block; max-height: 78vh; background: #000; }
.prep {
  aspect-ratio: 16/9; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 20px;
}
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.prep-bar { width: min(320px, 80%); height: 6px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; }
.prep-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.player-head { display: flex; align-items: flex-start; gap: 14px; margin: 16px 2px; }
.player-head h1 { font-size: 20px; margin: 0; flex: 1; word-break: break-word; }

/* admin */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 22px; flex-wrap: wrap; }
.tab { padding: 10px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }
.section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.section-card h3 { margin: 0 0 14px; font-size: 15px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tag { padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; }
.tag.admin { background: rgba(108,140,255,.2); color: var(--accent); }
.tag.on { background: rgba(87,217,163,.18); color: var(--accent-2); }
.tag.off { background: rgba(255,107,107,.18); color: var(--danger); }
.inline-form { display: inline; }
.row-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row-inline .field { margin-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-reveal { background: #0b1020; border: 1px dashed var(--accent); padding: 12px 14px; border-radius: 10px; font-family: ui-monospace, monospace; word-break: break-all; }
.muted { color: var(--muted); }
.browser { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.browser-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-elev2); font-size: 13px; }
.browser-list { max-height: 300px; overflow: auto; }
.browser-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-top: 1px solid var(--line); font-size: 13.5px; }
.browser-row:hover { background: var(--bg-elev2); }
.crumb { cursor: pointer; color: var(--accent); }

/* ---- iteration 2 ---- */
.sortsel { width: auto; min-width: 140px; }
.tagpill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  background: rgba(108,140,255,.16); color: #aebdff; border: 1px solid transparent; }
.tagline { display: flex; flex-wrap: wrap; gap: 5px; }
.card-meta .stat { color: var(--muted); white-space: nowrap; }

/* select mode */
.thumb-wrap { position: relative; }
.sel-check { position: absolute; top: 8px; left: 8px; z-index: 3; width: 22px; height: 22px;
  display: none; accent-color: var(--accent); cursor: pointer; }
body.selecting .sel-check { display: block; }
body.selecting .thumb { cursor: pointer; }
.card.picked { outline: 2px solid var(--accent); outline-offset: -2px; }
.selbar { position: fixed; left: 50%; bottom: -80px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--bg-elev2);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 30;
  transition: bottom .2s; }
.selbar.show { bottom: 20px; }
#selectToggle.active { background: var(--accent); border-color: var(--accent); color: #0b0d16; }

/* player extras */
.player-topnav { display: flex; align-items: center; gap: 8px; margin: 0 2px 12px; }
.player-topnav .spacer { flex: 1; }
.live-seek { display: flex; align-items: center; gap: 12px; margin: 10px 2px 0; }
.live-seek input[type=range] { flex: 1; accent-color: var(--accent); }
.like-btn { gap: 8px; }
.like-btn .heart { color: var(--muted); font-size: 16px; }
.like-btn.liked { border-color: var(--danger); }
.like-btn.liked .heart { color: var(--danger); }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; min-height: 8px; }
.tagpill.removable { cursor: pointer; }
.tagpill.removable b { opacity: .6; }
.tagpill.removable:hover { background: rgba(255,107,107,.18); color: #ffb4b4; }
.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.comment-head .muted { font-size: 12px; }
.comment-head .cdel { margin-left: auto; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; line-height: 1; }
.comment-head .cdel:hover { color: var(--danger); }
.comment-body { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
textarea { resize: vertical; }

/* download queue */
.qrow { gap: 12px; }
.qname { flex: 1; word-break: break-word; }
.qstatus { color: var(--muted); font-size: 12.5px; white-space: nowrap; min-width: 90px; text-align: right; }
.qbar { width: 120px; height: 6px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; }
.qbar > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

@media (max-width: 640px) {
  .container { padding: 16px 14px 50px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .player-head { flex-direction: column; }
  .qbar { display: none; }
}

/* ---- iteration 3: sidebar layout, selection, player, activity ---- */

/* custom select (kills the white native arrow box on hover) */
select.sortsel {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  width: auto; min-width: 150px; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%239aa0ad' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
select.sortsel::-ms-expand { display: none; }

/* layout with sidebar */
.layout { display: flex; gap: 20px; max-width: 1500px; margin: 0 auto; padding: 20px; align-items: flex-start; }
.sidebar { width: 250px; flex-shrink: 0; position: sticky; top: 66px; max-height: calc(100vh - 86px);
  overflow-y: auto; padding-right: 4px; }
.main { flex: 1; min-width: 0; }
.side-section { margin-bottom: 22px; }
.side-head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.clearlink { font-size: 11px; text-transform: none; }
.side-links { display: flex; flex-direction: column; gap: 2px; }
.side-link { padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 13.5px; }
.side-link:hover { background: var(--bg-elev); text-decoration: none; }
.side-link.active { background: var(--bg-elev2); color: var(--accent); font-weight: 600; }
.side-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* folder tree */
.tree, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-children { margin-left: 14px; border-left: 1px solid var(--line); padding-left: 4px; }
.tree-children.collapsed { display: none; }
.tree-row { display: flex; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 8px; }
.tree-row:hover { background: var(--bg-elev); }
.tree-row.active { background: var(--bg-elev2); }
.tree-row.active .tree-link { color: var(--accent); font-weight: 600; }
.tree-link { flex: 1; color: var(--text); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-link:hover { text-decoration: none; }
.tree-count { color: var(--muted); font-size: 11px; }
.tree-toggle { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px;
  width: 14px; padding: 0; transition: transform .15s; }
.tree-toggle.collapsed { transform: rotate(-90deg); }
.tree-space { width: 14px; display: inline-block; }
.sidebar-toggle { display: none; }

/* selection mode */
.selbanner { display: none; margin-bottom: 16px; padding: 10px 14px; border-radius: 10px;
  background: rgba(108,140,255,.12); border: 1px solid rgba(108,140,255,.4); color: #c3cfff; font-size: 13.5px; }
.selbanner.show { display: block; }
.sel-box { position: absolute; top: 8px; left: 8px; z-index: 3; width: 24px; height: 24px; display: none;
  border-radius: 6px; border: 2px solid #fff; background: rgba(0,0,0,.45); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
body.selecting .sel-box { display: block; }
body.selecting .thumb { cursor: pointer; }
body.selecting .card { cursor: pointer; }
.card.picked .sel-box { background: var(--accent); border-color: var(--accent); }
.card.picked .sel-box::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: #08122e; font-size: 15px; font-weight: 800; }
.card.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.card.picked .thumb img { opacity: .82; }
#selectToggle.active { background: var(--accent); border-color: var(--accent); color: #0b0d16; }
.selbar-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
#selbar #bulkTag { width: 150px; }
.iconbtn { padding: 6px 10px; }
.iconbtn svg { display: block; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px;
  border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* player: single fixed-size stage */
.player-box { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line); }
.player-box video { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none;
  object-fit: contain; background: #000; }
.player-box .prep { position: absolute; inset: 0; aspect-ratio: auto; display: flex; z-index: 2; }
.suboverlay { position: absolute; left: 0; right: 0; bottom: 64px; z-index: 3; text-align: center;
  padding: 0 8%; pointer-events: none; }
.suboverlay:empty { display: none; }
.suboverlay { color: #fff; font-size: clamp(15px, 2.4vw, 24px); line-height: 1.3; }
.suboverlay :is(br) { }
.suboverlay { text-shadow: 0 2px 4px #000, 0 0 6px #000; }
.player-box.live:hover .controls, .player-box.live .controls:focus-within { opacity: 1; }
.controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; align-items: center;
  gap: 10px; padding: 10px 14px; background: linear-gradient(transparent, rgba(0,0,0,.75)); opacity: .96;
  transition: opacity .2s; }
.ctrl-btn { background: rgba(255,255,255,.12); border: none; color: #fff; width: 34px; height: 34px;
  border-radius: 8px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.ctrl-btn:hover { background: rgba(255,255,255,.22); }
.ctrl-btn.on { background: var(--accent); color: #0b0d16; }
.controls .seek { flex: 1; accent-color: var(--accent); cursor: pointer; }
.ctime { color: #fff; font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 42px; text-align: center; }

.quick-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.quick-tags .addtag { cursor: pointer; opacity: .8; }
.quick-tags .addtag:hover { opacity: 1; background: rgba(87,217,163,.18); color: var(--accent-2); }

/* my activity */
.act-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; align-items: start; }
.act-list { display: flex; flex-direction: column; }
.act-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.act-name { word-break: break-word; }
.act-time { white-space: nowrap; font-size: 12px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; width: 270px; max-height: none;
    background: var(--bg-elev); border-right: 1px solid var(--line); padding: 70px 14px 20px;
    transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .sidebar-toggle { display: inline-flex; }
  .layout { padding: 14px; }
}
