:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #5b8cff;
  --accent-2: #35d089;
  --danger: #ff5b6a;
  --warn: #ffb84d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar .brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar .right { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; color: var(--muted); font-size: 14px; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

input[type="text"], input[type="password"], input[type="number"], input[type="file"], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #0b0d12;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  margin-top: 18px;
}

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger { background: var(--danger); color: #fff; }

.error {
  background: rgba(255, 91, 106, 0.12);
  border: 1px solid rgba(255, 91, 106, 0.4);
  color: #ff9aa3;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.ready { background: rgba(53, 208, 137, 0.15); color: var(--accent-2); }
.badge.processing { background: rgba(255, 184, 77, 0.15); color: var(--warn); }
.badge.failed { background: rgba(255, 91, 106, 0.15); color: var(--danger); }
.badge.mock { background: rgba(139, 147, 163, 0.15); color: var(--muted); }
.badge.drive { background: rgba(91, 140, 255, 0.15); color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.thumb { width: 80px; height: 45px; object-fit: cover; border-radius: 6px; background: #000; }

.copyfield {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copyfield input {
  flex: 1;
  font-family: monospace;
  font-size: 12px;
}
.copyfield button {
  margin: 0;
  padding: 8px 12px;
}

.notice {
  background: rgba(91, 140, 255, 0.1);
  border: 1px solid rgba(91, 140, 255, 0.35);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
}

.watch-wrap { text-align: center; }
.player-frame {
  /* --vw/--vh: the video's real pixel dimensions, set inline per video
     (falls back to a 16:9 default when dimensions weren't probed).
     Width is capped by 720px/viewport width AND by what fits in 80vh of
     height -- so portrait clips (very common phone-shot content) shrink to
     fit the screen instead of stretching into a fixed 16:9 box. */
  --vw: 16;
  --vh: 9;
  position: relative;
  width: min(720px, 100%, calc(80vh * var(--vw) / var(--vh)));
  aspect-ratio: var(--vw) / var(--vh);
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin: 0 auto 20px;
  border: 1px solid var(--border);
}
.player-frame video { width: 100%; height: 100%; border: 0; }

.unlock-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.muted { color: var(--muted); font-size: 13px; }

.ad-slot {
  max-width: 720px;
  margin: 0 auto 16px;
  text-align: center;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.video-card {
  display: block;
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
/* Higher specificity than the plain .thumb rules (used elsewhere for small
   admin-table thumbnails) so this always wins regardless of viewport. */
.video-card .thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 0;
  display: block;
}
.video-card-title {
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
}

@media (max-width: 640px) {
  .container { padding: 20px 14px 60px; }
  .card { padding: 16px; }
  .table-scroll { margin: 0; padding: 0; overflow-x: visible; }

  /* Below 640px the video table stops being a table at all -- each row
     becomes a self-contained card, stacked vertically. No more sideways
     scrolling to see status/storage/links/delete. This block has to be
     last in the file: td/th's own rules further up set border-bottom and
     padding directly on the element (not inside a media query), and equal-
     specificity rules resolve by source order, not by how "specific" the
     surrounding @media feels -- earlier lost every time regardless of
     which viewport matched. */
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  table { border-collapse: separate; border-spacing: 0; }
  tr {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 14px;
  }
  tr:last-child { margin-bottom: 0; }

  td {
    border: none;
    padding: 0;
  }
  /* Tuck each label tight against its value, but give clear breathing room
     before the next field -- that contrast is what reads as "grouped"
     instead of one undifferentiated block of text. */
  td + td { margin-top: 12px; }

  /* Field name shown above the value, since column headers are hidden. */
  td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 4px;
  }

  /* A full 16:9-width thumbnail ate most of the screen -- this is a
     management list, not a gallery, so cap it short and crop instead. */
  .cell-thumb { margin-bottom: 12px; }
  .thumb { width: 100%; height: 90px; aspect-ratio: auto; object-fit: cover; }
  .cell-title { font-size: 16px; font-weight: 700; }

  /* Status and Storage are two small badges -- full-width stacked blocks
     for each wastes most of a card's height on whitespace. Side by side. */
  .cell-status, .cell-storage {
    display: inline-block;
    width: auto;
    vertical-align: top;
  }
  .cell-status { margin-right: 28px; }
  .cell-storage { margin-top: 0; }

  .cell-delete { margin-top: 14px; }
  .cell-delete button { width: 100%; padding: 10px; }
}
