:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191f;
  --muted: #5f6775;
  --border: #dfe3e9;
  --accent: #2563eb;
  --accent-soft: #e5edff;
  --danger: #d92d20;
  --ok: #16a34a;
  --warn-bg: #fdf1d3;
  --warn-text: #8a4b08;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 4px 14px rgb(16 24 40 / 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #20242d;
    --text: #e8eaef;
    --muted: #9aa3b2;
    --border: #2b303b;
    --accent: #5b8cff;
    --accent-soft: #1d2a4a;
    --danger: #f2554a;
    --ok: #34c56b;
    --warn-bg: #3a2c0c;
    --warn-text: #f5c451;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0; padding: 0; margin: -1px;
}

/* Buttons & inputs ------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; line-height: 1;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, filter 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

.link-btn {
  padding: 0; border: 0; background: none;
  color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer;
}

.icon-btn {
  flex: none; width: 36px; height: 36px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input[type="text"], input[type="password"], input[type="search"], input[type="datetime-local"], select {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline-offset: 0; }

.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select { color: var(--text); font-weight: 400; font-size: 15px; }

/* Layout ------------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.inline { display: inline; margin: 0; }

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-size: 17px; font-weight: 700; text-decoration: none;
}
.brand-mark { position: relative; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none; }
.brand-mark::after {
  content: ""; position: absolute; left: 11px; top: 8px;
  border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}

.container { max-width: 1240px; margin: 0 auto; padding: 20px 16px 64px; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar input { max-width: 320px; }

.panel {
  margin-bottom: 20px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 15px; }

/* Library grid ------------------------------------------------------------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 16 / 9;
  padding: 0; border: 0; overflow: hidden; cursor: pointer;
  background: #0c0d10;
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 0.25s; }
.thumb:hover img { transform: scale(1.03); }
.thumb::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 50px; height: 50px; border-radius: 50%;
  background: rgb(0 0 0 / 0.55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5v14l11-7z'/%3E%3C/svg%3E") center / 22px no-repeat;
  opacity: 0.85; transition: opacity 0.2s, transform 0.2s;
}
.thumb:hover::after { opacity: 1; transform: scale(1.06); }
.thumb-placeholder {
  position: absolute; inset: auto 0 12px; text-align: center;
  color: #9aa3b2; font-size: 12px;
}
.duration {
  position: absolute; right: 8px; bottom: 8px;
  padding: 1px 7px; border-radius: 6px;
  background: rgb(0 0 0 / 0.75); color: #fff;
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.card-body { flex: 1; padding: 12px 14px 2px; min-width: 0; }
.card-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { margin-top: 2px; color: var(--muted); font-size: 13px; }
.card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.card-badges:empty { display: none; }
.badge { padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 14px; }
.card-actions .spacer { flex: 1; }

.empty { padding: 64px 16px; text-align: center; border: 2px dashed var(--border); border-radius: var(--radius); }
.empty-title { margin-bottom: 4px; font-size: 18px; font-weight: 600; }

/* Uploads ----------------------------------------------------------------- */

.upload-list { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.upload-head { display: flex; align-items: center; gap: 10px; }
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.upload-size { color: var(--muted); font-size: 13px; }
.progress { height: 8px; margin: 6px 0 4px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.2s linear; }
.upload-foot { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.upload-item.done .progress-bar { background: var(--ok); }
.upload-item.error .progress-bar { background: var(--danger); }
.upload-item.error .upload-status { color: var(--danger); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drop-overlay div { padding: 14px 22px; border-radius: 12px; background: var(--surface); font-weight: 700; box-shadow: var(--shadow); }
body.dragging .drop-overlay { display: grid; }

/* Dialogs ----------------------------------------------------------------- */

dialog.dialog {
  width: min(580px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.35);
}
dialog.dialog-wide { width: min(1100px, calc(100vw - 24px)); }
dialog.dialog-narrow { width: min(420px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.dialog-inner { display: block; padding: 18px; }
.dialog-inner > h2 { font-size: 18px; margin-bottom: 8px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { font-size: 18px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }

#player-video { display: block; width: 100%; max-height: 75dvh; border-radius: 10px; background: #000; }

.share-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 18px; }
.share-form .full { grid-column: 1 / -1; }
.share-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.share-item { padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.share-item.expired .share-url { text-decoration: line-through; opacity: 0.6; }
.share-link-row { display: flex; gap: 6px; }
.share-link-row input.share-url {
  min-height: 32px; padding: 4px 10px; border-radius: 8px;
  font: 12.5px/1.4 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.share-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.share-meta .label { color: var(--text); font-weight: 600; }
.status-expired { color: var(--danger); font-weight: 600; }
.note { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); color: var(--muted); overflow-wrap: anywhere; }

/* Settings menu (⋮) ----------------------------------------------------- */

.menu-wrap { position: relative; }
.menu-btn { display: grid; place-items: center; position: relative; }
.menu-btn svg { fill: currentColor; }
.menu-busy {
  position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface);
}
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 20;
  width: min(300px, calc(100vw - 24px)); padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}
.menu-item {
  display: grid; gap: 2px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item-title { font-weight: 600; font-size: 14px; }
.menu-item-sub { color: var(--muted); font-size: 12.5px; }

/* Move to a new PC ------------------------------------------------------------ */

.banner { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-weight: 600; font-size: 14px; }
.move-section { display: grid; gap: 14px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.import-progress { display: grid; gap: 6px; }
.import-headline { font-weight: 600; }
.import-failed { margin: 4px 0 0; padding-left: 18px; color: var(--danger); font-size: 13px; }
.import-failed:empty { display: none; }
.import-progress.done .progress-bar { background: var(--ok); }
.import-progress.failed .progress-bar { background: var(--danger); }

/* Toast (uses the popover top layer so it shows above open dialogs) ------- */

.toast {
  position: fixed; inset: auto auto 24px 50%; z-index: 100;
  max-width: calc(100vw - 32px); margin: 0; padding: 10px 16px;
  border: 0; border-radius: 10px;
  background: #111827; color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  transform: translateX(-50%);
}
.toast { display: none; }
.toast.show { display: block; }
.toast.error { background: var(--danger); }
.offscreen { position: fixed; top: -1000px; left: 0; opacity: 0; }

/* Login -------------------------------------------------------------------- */

.auth { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.auth-card {
  display: grid; gap: 14px; width: min(380px, 100%); padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 6px; font-size: 21px; }
.alert {
  padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 14px;
}

/* Public share page -------------------------------------------------------- */

body.watch { min-height: 100dvh; background: #0b0c0f; color: #e8eaef; color-scheme: dark; }
.watch-main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.watch-player { overflow: hidden; border-radius: 14px; background: #000; }
.watch-player video { display: block; width: 100%; height: auto; max-height: 82dvh; background: #000; }
.watch-info { padding: 16px 2px; }
.watch-info h1 { font-size: 21px; overflow-wrap: anywhere; }
.watch-info p { margin-top: 4px; color: #9aa3b2; font-size: 14px; }
.watch-info a { color: #8fb0ff; }
.watch-missing { display: grid; place-items: center; min-height: 100dvh; padding: 16px; text-align: center; }
.watch-missing h1 { margin: 6px 0 8px; font-size: 22px; }
.watch-missing p { color: #9aa3b2; }
.watch .eyebrow { color: #9aa3b2; }

/* Small screens ------------------------------------------------------------ */

@media (max-width: 640px) {
  .toolbar { flex-direction: column; align-items: stretch; gap: 6px; }
  .toolbar input { max-width: none; }
  .share-form { grid-template-columns: 1fr; }
  .card-actions .btn { flex: 1; }
  .card-actions .spacer { display: none; }
  .dialog-inner { padding: 14px; }
  .watch-main { padding: 0 0 32px; }
  .watch-player { border-radius: 0; }
  .watch-info { padding: 14px 16px; }
}
@media (max-width: 380px) {
  .brand span:last-child { display: none; }
}
