:root {
  --bg: #0d1117;
  --surface: #151b24;
  --surface-2: #1c2430;
  --line: #263041;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .15);
  --danger: #ff6b6b;
  --warn: #f0b429;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 { font-size: 1.35rem; margin: 0 0 .35rem; }
h2 { font-size: 1.05rem; margin: 0; }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 5px; font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.dot { color: var(--muted); margin: 0 .45rem; }
.hidden { display: none !important; }

/* ---- chrome ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 17, 23, .85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand strong { font-weight: 700; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: .7rem;
}
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.page { flex: 1; width: min(1080px, 100%); margin: 0 auto; padding: 1.5rem 1.25rem 3rem; display: grid; gap: 1.25rem; }

.footer {
  border-top: 1px solid var(--line); padding: .8rem 1.25rem;
  color: var(--muted); font-size: .82rem; display: flex; align-items: center;
}

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.count { color: var(--muted); font-weight: 400; margin-left: .3rem; }

/* ---- forms ---- */
textarea, input[type=password] {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .8rem; font: inherit; resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row { display: flex; align-items: center; gap: .8rem; margin-top: .75rem; flex-wrap: wrap; }
.field { display: grid; gap: .35rem; margin: .9rem 0; }
.field span { font-size: .85rem; color: var(--muted); }

.btn {
  border: 1px solid transparent; border-radius: 9px; padding: .55rem 1rem;
  font: inherit; cursor: pointer; background: var(--surface-2); color: var(--text);
  transition: filter .15s ease, border-color .15s ease;
}
.btn:hover { filter: brightness(1.18); }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-block { width: 100%; }
.btn.small { padding: .3rem .65rem; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: progress; }

.alert { margin-top: .9rem; padding: .7rem .85rem; border-radius: 10px; font-size: .9rem; }
.alert-error { background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .35); color: #ffb4b4; }
.alert-warn  { background: rgba(240, 180, 41, .12); border: 1px solid rgba(240, 180, 41, .35); color: #f5d38a; }

.login-wrap { display: grid; place-items: center; min-height: 60vh; }
.login-card { width: min(380px, 100%); }

/* ---- progress bars (used everywhere something takes time) ---- */
.bar { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), #7aa9ff);
  border-radius: 999px; transition: width .35s ease;
}

.jobs { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
.job { background: var(--surface-2); border-radius: 11px; padding: .8rem .9rem; }
.job-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.job-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-percent { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
.job-msg { margin-top: .45rem; font-size: .84rem; color: var(--muted); }
.job.is-error .job-percent { color: var(--danger); }
.job.is-error .bar-fill { background: var(--danger); }
.job.is-done .job-percent { color: #4ade80; }
.job.is-done .bar-fill { background: #4ade80; }

/* ---- library grid ---- */
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem;
        grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile a { text-decoration: none; color: inherit; display: block; }
.thumb {
  position: relative; aspect-ratio: 16/9; border-radius: 11px;
  background: linear-gradient(135deg, #1e2836, #131a24);
  border: 1px solid var(--line);
  display: grid; place-items: center; transition: transform .18s ease, border-color .18s ease;
}
.tile a:hover .thumb { transform: translateY(-3px); border-color: var(--accent); }
.play { font-size: 1.5rem; color: var(--muted); }
.tile a:hover .play { color: var(--accent); }
.badge {
  position: absolute; right: .5rem; bottom: .5rem;
  background: rgba(0,0,0,.72); padding: .1rem .4rem; border-radius: 5px;
  font-size: .75rem; font-variant-numeric: tabular-nums;
}
.tile-body { display: grid; gap: .15rem; margin-top: .55rem; }
.tile-name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { font-size: .78rem; color: var(--muted); }
.empty { text-align: center; padding: 2rem 1rem; }

/* ---- player ---- */
.player-wrap { display: grid; gap: 1.1rem; }
.stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#player { width: 100%; display: block; aspect-ratio: 16/9; background: #000; }

.loader {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .7rem;
  background: rgba(3, 6, 10, .62); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.loader.on { opacity: 1; }
.ring {
  width: 74px; height: 74px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.14); border-top-color: var(--accent);
  display: grid; place-items: center;
  font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums;
  animation: spin 1s linear infinite;
}
.ring span { animation: spin 1s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-label { font-size: .85rem; color: #cbd5e1; }

.meta-row { color: var(--muted); font-size: .88rem; display: flex; align-items: center; flex-wrap: wrap; }
.buffer-block { margin-top: 1.1rem; }
.buffer-head { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .4rem; }
#buffer-percent { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
#cache-note { margin: .55rem 0 0; }

@media (max-width: 560px) {
  .page { padding: 1rem .85rem 2rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ---- settings ---- */
.alert-ok { background: rgba(74, 222, 128, .12); border: 1px solid rgba(74, 222, 128, .35); color: #86efac; }
.pill { font-size: .78rem; padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--line); }
.pill-ok { background: rgba(74, 222, 128, .14); border-color: rgba(74, 222, 128, .4); color: #86efac; }
.pill-off { background: var(--surface-2); color: var(--muted); }
.steps { margin: .9rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .9rem; }
.steps li { margin-bottom: .5rem; }
.copy-row { display: flex; align-items: center; gap: .5rem; margin-top: .4rem; flex-wrap: wrap; }
.copy-row code { word-break: break-all; }
select {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; font: inherit;
}
input[type=text] {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; font: inherit;
}
.or-divider { margin: .2rem 0 0; }
.current-folder { margin: .6rem 0 0; }
.folder-form { margin-top: 1rem; }
