:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-hover: #1c212a;
  --line: #262c37;
  --text: #e7eaf0;
  --dim: #8b94a5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --green: #3ecf8e;
  --amber: #f0b429;
  --red: #f2545b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
code { background: var(--bg-soft); padding: 2px 6px; border-radius: 6px; font-size: 0.9em; }
.dim { color: var(--dim); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; }

.warp {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.warp:hover { background: var(--bg-soft); color: var(--text); }
.warp:disabled { opacity: 0.6; cursor: default; }

.warp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4a5261;
  flex-shrink: 0;
}
.warp.is-on { border-color: rgba(62, 207, 142, 0.35); color: #7de3b4; }
.warp.is-on .warp-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.16); }

.tab {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--bg-soft); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: #a9c6ff; }

/* ---------- layout ---------- */

.wrap { max-width: 900px; margin: 0 auto; padding: 32px 24px 80px; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0; color: var(--dim); font-weight: 600; }
.sub { margin: 0; color: var(--dim); font-size: 14px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-actions { display: flex; align-items: center; gap: 12px; }
.summary { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- home ---------- */

.hero { text-align: center; padding: 48px 0 32px; }
.hero h1 { font-size: 32px; margin-bottom: 8px; }

.url-form {
  display: flex;
  gap: 10px;
  margin: 28px auto 10px;
  max-width: 620px;
}

.url-form input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.url-form input::placeholder { color: #5c6577; }
.url-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.url-form button {
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: filter 0.15s;
}
.url-form button:hover { filter: brightness(1.1); }
.url-form button:disabled { opacity: 0.6; cursor: default; }

.hint { color: var(--dim); font-size: 13px; margin: 0; }

.panel { margin-top: 40px; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.link { color: var(--accent); text-decoration: none; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ---------- buttons ---------- */

.btn {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.tiny { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--dim);
  filter: none;
}
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.danger { background: transparent; border-color: rgba(242, 84, 91, 0.4); color: #ff8b90; filter: none; }
.btn.danger:hover { background: rgba(242, 84, 91, 0.12); }

/* ---------- download cards ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-top { display: flex; align-items: flex-start; gap: 12px; }
.card-main { flex: 1; min-width: 0; }
.icon { font-size: 17px; line-height: 1.4; flex-shrink: 0; }

.card-title {
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-url {
  color: var(--dim);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--bg-hover);
  color: var(--dim);
}
.badge-downloading { background: var(--accent-soft); color: #a9c6ff; }
.badge-completed { background: rgba(62, 207, 142, 0.14); color: #7de3b4; }
.badge-paused { background: rgba(240, 180, 41, 0.14); color: #f5cd6e; }
.badge-failed { background: rgba(242, 84, 91, 0.14); color: #ff8b90; }

.bar {
  height: 5px;
  margin: 12px 0 10px;
  border-radius: 99px;
  background: var(--bg-hover);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease-out;
}
.card[data-status="completed"] .bar-fill { background: var(--green); }
.card[data-status="paused"] .bar-fill { background: var(--amber); }
.card[data-status="failed"] .bar-fill { background: var(--red); }
.card[data-status="cancelled"] .bar-fill { background: #3a4150; }

.bar-fill.indeterminate {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: slide 1.4s infinite linear;
}
@keyframes slide {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.meta { color: var(--dim); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; }

/* ---------- file table ---------- */

.breadcrumb { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13.5px; }
.crumb { color: var(--accent); text-decoration: none; }
.crumb:hover { text-decoration: underline; }
.crumb.current { color: var(--dim); }
.crumb-sep { color: #3a4150; }

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--bg-soft);
}

/* Fixed layout keeps the action buttons on screen: without it a long file name
   widens the table until Save/Delete are pushed out of the container. */
table.files { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 600px; }

table.files th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dim);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  background: #12151b;
}
.col-size { width: 100px; }
.col-date { width: 130px; }
.col-act { width: 205px; }

table.files td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(38, 44, 55, 0.6);
  font-size: 14px;
  vertical-align: middle;
}
table.files tr:last-child td { border-bottom: 0; }
.row:hover td { background: var(--bg-hover); }
.row.up { cursor: pointer; color: var(--dim); }

.cell-name { overflow: hidden; }
.name-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-name .name {
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-name .name:hover { color: var(--accent); }
.cell-size, .cell-date { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-act { text-align: right; white-space: nowrap; }
.cell-act .btn + .btn, .cell-act a + button { margin-left: 6px; }

.empty { color: var(--dim); text-align: center; padding: 32px 0; font-size: 14px; }

/* ---------- player ---------- */

.watch-head { margin-bottom: 14px; }
.watch-title {
  font-size: 19px;
  margin: 8px 0 4px;
  overflow-wrap: anywhere;
}
.watch-hint { margin-top: 12px; text-align: center; }

.player {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  outline: none;
}
.player:fullscreen { border-radius: 0; aspect-ratio: auto; height: 100vh; }
.player.idle { cursor: none; }
.player.idle .controls { opacity: 0; pointer-events: none; }

.player video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}
.player video::cue { font-size: 1.05em; background: rgba(0, 0, 0, 0.65); }

.spinner {
  position: absolute;
  top: 50%; left: 50%;
  width: 42px; height: 42px;
  margin: -21px 0 0 -21px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.flash, .osd {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  color: #fff;
}
.flash {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 76px; height: 76px;
  display: grid;
  place-items: center;
  font-size: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
}
.flash.show { animation: flash 0.5s ease-out; }
@keyframes flash {
  from { opacity: 1; transform: translate(-50%, -50%) scale(0.85); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
}

.osd {
  top: 18px; left: 18px;
  padding: 7px 13px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  font-size: 13.5px;
  font-weight: 600;
  transition: opacity 0.2s;
}
.osd.show { opacity: 1; }

.player-error {
  position: absolute;
  inset: auto 24px 90px 24px;
  padding: 16px 18px;
  border-radius: 10px;
  background: rgba(20, 22, 28, 0.94);
  border: 1px solid rgba(242, 84, 91, 0.4);
  color: #ffb3b6;
  font-size: 13.5px;
}
.player-error p { margin: 0 0 12px; line-height: 1.55; }
.error-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.watch-actions { display: flex; gap: 8px; margin-top: 10px; }

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 26px 14px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  transition: opacity 0.25s;
}

.seek { position: relative; padding: 7px 0; cursor: pointer; }
.seek-track { height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.24); }
.seek-fill { height: 100%; width: 0; border-radius: 99px; background: var(--accent); }
.seek-head {
  position: absolute;
  top: 50%; left: 0;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  transition: opacity 0.15s;
}
.seek:hover .seek-head { opacity: 1; }
.seek:hover .seek-track { height: 6px; margin-top: -1px; }
.seek-tip {
  position: absolute;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.control-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.control-row .spacer { flex: 1; }

.ctl {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  line-height: 1;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s;
}
.ctl:hover { background: rgba(255, 255, 255, 0.14); }
.ctl.labelled {
  font-size: 12.5px;
  font-weight: 600;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.volume { display: flex; align-items: center; gap: 4px; }
.volume input[type="range"] {
  width: 86px;
  accent-color: var(--accent);
  cursor: pointer;
}

.time {
  color: #e7eaf0;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  padding-left: 6px;
  white-space: nowrap;
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  max-height: 320px;
  overflow-y: auto;
  padding: 5px;
  border-radius: 10px;
  background: rgba(22, 26, 33, 0.97);
  border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  z-index: 5;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item.is-active { color: #a9c6ff; font-weight: 600; }

@media (max-width: 640px) {
  .volume input[type="range"] { width: 60px; }
  .ctl.labelled { max-width: 96px; }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  border-radius: 10px;
  background: #232935;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: min(90vw, 460px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(242, 84, 91, 0.5); color: #ffb3b6; }

@media (max-width: 640px) {
  .wrap { padding: 24px 16px 64px; }
  .hero { padding: 28px 0 16px; }
  .hero h1 { font-size: 26px; }
  .url-form { flex-direction: column; }
  .col-date, .cell-date { display: none; }
  .col-size { width: 90px; }
}
