/* Randomstudio Video Server: true-black, flat style that matches the black-and-white mark.
   Surfaces are separated by tone steps, not lines or shadows. One accent colour (orange)
   only marks data in motion (upload progress, drop target); controls stay neutral. */

@font-face {
  font-family: "Geist";
  src: url("fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  /* tone steps, darkest to lightest */
  --bg: #000;
  --surface: #0e0e0e;
  --raised: #171717;
  --hover: #202020;
  --line: #2a2a2a;          /* form fields and table rules only */
  --text: #f2f2f2;
  --muted: #9b9b9b;         /* ≥ 6:1 on every surface above */
  --accent: #ff8a3d;
  --ok: #7ee2a8;
  --ok-tint: rgba(126, 226, 168, 0.12);
  --warn: #f3cf6b;
  --warn-tint: rgba(243, 207, 107, 0.12);
  --bad: #ff8a80;
  --bad-tint: rgba(255, 138, 128, 0.12);

  --radius: 10px;
  --radius-sm: 8px;
  --gutter: 24px;

  /* Motion is feedback only: presses, moves the user caused, things they opened. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --press: 160ms;
  --fast: 200ms;
  --base: 260ms;

  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
/* Type sizes cluster on 12 / 14 / 18 / 24. */
h1 { font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h3 { font-size: 14px; font-weight: 600; margin: 0; }
a { color: var(--text); }
code { background: var(--raised); padding: 2px 6px; border-radius: 4px; font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.sub { color: var(--muted); margin: 4px 0 0; }
.empty { color: var(--muted); margin: 0; }
.num, .meta, .seen, .count, .dur { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ shell */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); padding: 20px 12px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-logo { height: 32px; width: auto; flex: none; }
.brand-name { display: flex; flex-direction: column; font-size: 14px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.brand-name small { font-size: 12px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
nav { display: flex; flex-direction: column; gap: 2px; position: relative; }
nav a { position: relative; z-index: 1; color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 500; transition: color var(--fast) var(--ease-out); }
nav a.active { color: var(--text); }
/* Neutral active state: one tone step that slides to the chosen section. */
.nav-indicator { position: absolute; top: 0; left: 0; border-radius: var(--radius-sm); background: var(--hover); pointer-events: none; opacity: 0; }
.nav-indicator.ready { opacity: 1; transition: transform var(--base) var(--ease-out), width var(--base) var(--ease-out), height var(--base) var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  nav a:hover { color: var(--text); }
}
.sidebar-foot { margin-top: auto; color: var(--muted); display: flex; justify-content: space-between; align-items: center; padding: 0 8px; }

main { padding: 32px 40px 80px; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: var(--gutter); flex-wrap: wrap; }

/* --------------------------------------------------------------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  background: var(--raised); color: var(--text); border: 0; border-radius: var(--radius-sm); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: transform var(--press) var(--ease-out), background-color var(--fast) var(--ease-out); }
a.btn { text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(0.97); }
/* The one primary action per view: near-white on black. */
.btn.primary { background: var(--text); color: #000; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .35; cursor: default; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { background: var(--hover); }
  .btn.primary:hover:not(:disabled) { background: #fff; }
}
.btn:focus-visible, nav a:focus-visible, .link:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 3px; padding: 0; }

input, select { height: 40px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 12px; font: inherit; width: 100%; }
input::placeholder { color: #8a8a8a; }
input:focus, select:focus { outline: none; border-color: var(--text); }
input[type=checkbox], input[type=range] { height: auto; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; margin: 12px 0 0; font-weight: 400; }
label.check input { width: auto; margin-top: 3px; accent-color: var(--text); }
.inline-form { display: flex; gap: 8px; }
.inline-form input { width: 240px; }

.panel { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.panel.narrow { max-width: 420px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.panel.narrow label { align-self: stretch; }

/* ----------------------------------------------------------------- videos */
.dropzone { display: block; border-radius: var(--radius); padding: 32px; text-align: center; cursor: pointer; color: var(--text); background: var(--surface); font-weight: 400;
  outline: 1.5px dashed transparent; outline-offset: -1.5px;
  transition: background-color var(--fast) var(--ease-out), outline-color var(--fast) var(--ease-out); }
.dropzone.over { background: var(--raised); outline-color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  .dropzone:hover { background: var(--raised); }
}
.dropzone .sub { display: block; margin-top: 4px; }
#optimize-wrap { color: var(--muted); }
#uploads:not(:empty) { margin-top: 16px; }
.upload-row { display: grid; grid-template-columns: 1fr 200px 52px; gap: 12px; align-items: center; padding: 8px 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 4px; background: var(--raised); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform var(--fast) var(--ease-out); }
.upload-row.done { transition: opacity var(--fast) var(--ease-out); opacity: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 16px; margin-top: var(--gutter); align-items: stretch; }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: background-color var(--fast) var(--ease-out); }
.thumb { aspect-ratio: 16/9; background: var(--raised); position: relative; display: grid; place-items: center; color: var(--muted); cursor: pointer; overflow: hidden; }
.thumb-img { position: absolute; inset: 0; background: center/cover no-repeat; transition: transform 400ms var(--ease-out); }
.thumb > :not(.thumb-img) { position: relative; }
.thumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.72); color: #fff; padding: 1px 6px; border-radius: 4px; font-size: 12px; }
@media (hover: hover) and (pointer: fine) {
  .card:hover { background: var(--raised); }
  .thumb:hover .thumb-img { transform: scale(1.03); }
}
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card-actions { display: flex; gap: 6px; margin-top: auto; }
/* Status: pale tint, readable text, one per item. */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 99px; background: var(--raised); color: var(--muted); }
.badge.ok { color: var(--ok); background: var(--ok-tint); }
.badge.warn { color: var(--warn); background: var(--warn-tint); }
.badge.bad { color: var(--bad); background: var(--bad-tint); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.spin { width: 18px; height: 18px; border: 2px solid var(--hover); border-top-color: var(--text); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Loading: flat blocks at real size, no shimmer, so nothing jumps when data arrives. */
.placeholder { background: var(--surface); border-radius: var(--radius); aspect-ratio: 232 / 228; }

/* -------------------------------------------------------------- playlists */
.split { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.list { list-style: none; margin: 0; padding: 6px; background: var(--surface); border-radius: var(--radius); }
.list li { padding: 0 12px; height: 40px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; transition: background-color var(--fast) var(--ease-out); }
.list li.empty { cursor: default; }
.list li.active { background: var(--hover); }
@media (hover: hover) and (pointer: fine) {
  .list li:not(.empty):not(.active):hover { background: var(--raised); }
}
.list li .count { color: var(--muted); font-size: 12px; }
.editor-head { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.editor-head input { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.items { list-style: none; padding: 0; margin: 0 0 16px; }
/* A real ordered list: the number is the play position. */
.items { counter-reset: item; }
.items li { display: grid; grid-template-columns: 24px 64px 1fr auto; gap: 12px; align-items: center; padding: 6px 8px; border-radius: var(--radius-sm); margin-bottom: 4px; background: var(--raised); }
.items li.dragging { opacity: .4; }
.items li.drop-target { background: var(--hover); }
.items li::before { counter-increment: item; content: counter(item); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.items .mini { width: 64px; aspect-ratio: 16/9; background: #000 center/cover; border-radius: 4px; cursor: grab; }
.items .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .name .sub { font-size: 12px; font-variant-numeric: tabular-nums; }
.items .btns { display: flex; gap: 4px; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row select { flex: 1; min-width: 160px; width: auto; }
#playlist-editor > .sub { margin-top: 14px; }

/* ---------------------------------------------------------------- screens */
.new-screen { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; margin-bottom: 16px; }
.screens { display: grid; gap: 12px; }
.screen { background: var(--surface); border-radius: var(--radius); padding: 20px; display: grid; grid-template-columns: 1fr auto; gap: 20px; }
.screen-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.screen-head h3 { font-size: 18px; letter-spacing: -0.01em; }
.screen-head code { color: var(--muted); }
.urls { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.url { display: flex; align-items: center; gap: 8px; }
.url .sub { flex: none; }
.url code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 6px 8px; }
/* Two dropdowns, then the on/off settings, on one line. */
.screen-fields { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) repeat(3, auto); gap: 12px 20px; margin-top: 16px; align-items: end; }
.screen-fields label.check { margin: 0; align-items: center; height: 40px; }
.screen-side { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 168px; }
.screen-side .btn.danger { margin-top: auto; }
.seen { color: var(--muted); font-size: 12px; margin-top: 14px; overflow-wrap: anywhere; }

/* --------------------------------------------------------------- settings */
/* A label column beside each settings panel. */
.setting { display: grid; grid-template-columns: 240px 1fr; gap: 24px; padding: 24px 0; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting-label .sub { max-width: 30ch; }
.help h2 { font-size: 14px; margin: 16px 0 4px; }
.help h2:first-of-type { margin-top: 12px; }
.help p { line-height: 1.6; color: var(--muted); margin: 0 0 8px; max-width: 72ch; }
.help ol { padding-left: 20px; line-height: 1.7; color: var(--muted); margin: 0; max-width: 72ch; }

.wm { display: grid; grid-template-columns: minmax(240px, 420px) 1fr; gap: 24px; align-items: start; }
.wm-preview { position: relative; aspect-ratio: 16/9; border-radius: var(--radius-sm); overflow: hidden; background: var(--raised); }
.wm-video { position: absolute; inset: 0; background: var(--raised) center/cover no-repeat; }
.wm-preview img { position: absolute; right: 2%; bottom: 3%; height: auto; pointer-events: none; }
.wm-controls { display: flex; flex-direction: column; gap: 16px; }
.wm-controls label.check { margin: 0; }
.wm-controls input[type=range] { padding: 0; accent-color: var(--text); border: 0; }
.wm-controls label span { color: var(--text); font-variant-numeric: tabular-nums; }

/* Address field with the site shown in front of it. */
.affix { display: flex; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.affix:focus-within { border-color: var(--text); }
.affix input { border: 0; border-radius: 0; min-width: 0; flex: 1; }
.affix input:focus { border: 0; }
#slug-prefix { color: var(--muted); padding-left: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; flex: none; }
.affix #slug-prefix + input { padding-left: 1px; }

/* ------------------------------------------------------- floating layers */
.toast { position: fixed; bottom: 20px; left: 50%; background: var(--raised); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: 0 12px 32px rgba(0,0,0,.6); z-index: 10;
  opacity: 0; transform: translate(-50%, 12px) scale(0.98); pointer-events: none;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out); }
.toast[data-open] { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; transition-duration: var(--base); }
.toast.err { color: var(--bad); }

dialog { background: #000; border: 0; border-radius: var(--radius); padding: 0; max-width: 90vw; box-shadow: 0 24px 64px rgba(0,0,0,.7); }
dialog video, dialog img.preview { display: block; max-width: 90vw; max-height: 80vh; }
dialog::backdrop { background: rgba(0,0,0,.82); }
dialog[open] { animation: pop-in var(--base) var(--ease-out); }
dialog[open]::backdrop { animation: fade-in var(--base) var(--ease-out); }
dialog.closing { animation: pop-out 150ms var(--ease-out) forwards; }
dialog.closing::backdrop { animation: fade-out 150ms var(--ease-out) forwards; }
/* QR window: the code sits on white with a quiet zone so any camera can read it. */
dialog.qr-dialog { background: var(--surface); }
.qr-card { padding: 24px; width: min(360px, 86vw); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.qr-card .sub { margin: 0; }
.qr-frame { background: #fff; border-radius: var(--radius-sm); padding: 12px; margin-top: 4px; }
.qr-img { display: block; width: min(280px, 70vw); height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.qr-url { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-card label.check { margin: 0; text-align: left; font-size: 12px; }
.qr-actions { display: flex; gap: 8px; margin-top: 4px; }

@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes pop-out { to { opacity: 0; transform: scale(0.96); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ------------------------------------------------------------------ login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { padding: 0; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; }
.login-card .btn { margin-top: 6px; height: 40px; }
.error { color: var(--bad); margin: 0; }
.hint { color: var(--muted); margin: 0; }

/* Grid and flex items won't shrink below their content by default, so one long file name or
   address would widen the whole page on a phone. Let them shrink; long text ends in "…". */
.layout > *, .split > *, .screen > *, .screen-fields > *, .setting > *, .wm > *, .new-screen > *,
.page-head > *, .editor-head > *, .add-row > *, .inline-form > *, .card, .card-body, .items li > *,
.screen-head > *, .url > * { min-width: 0; }
select { max-width: 100%; }
.screen-head h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ phone */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .brand { padding: 0; }
  nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; }
  nav a { padding: 0 14px; height: 44px; display: inline-flex; align-items: center; }
  .sidebar-foot { margin: 0 0 0 auto; gap: 12px; padding: 0; }
  main { padding: 24px 16px 64px; }
  .split, .new-screen, .screen, .screen-fields, .setting, .wm { grid-template-columns: 1fr; }
  .setting { gap: 12px; }
  .inline-form { width: 100%; }
  .inline-form input { width: 100%; }
  .upload-row { grid-template-columns: 1fr 80px 44px; }
  /* Touch targets: at least 44px tall. */
  .btn, input, select { height: 44px; }
  .btn.small { height: 44px; min-width: 44px; font-size: 14px; }
  .screen-side { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  /* Playlist items: name gets the full width, reorder buttons sit underneath. */
  .items li { grid-template-columns: 20px 64px minmax(0, 1fr); row-gap: 6px; }
  .add-row select { min-width: 0; }
  .url .btn.small { flex: none; }
  /* Address label above, address and its buttons below, so the address gets the full width. */
  .url { flex-wrap: wrap; row-gap: 4px; }
  .url > .sub { width: 100% !important; }
  .url code { padding: 12px 10px; }
  .items .btns { grid-column: 2 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
