:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f0f0f7;
  --border: #e3e3ee;
  --text: #17172b;
  --muted: #6b6b85;
  --brand: #5b4cf0;
  --brand-hover: #4a3bdb;
  --brand-soft: #ecebff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --success: #1f9d55;
  --rec: #f2414b;
  --shadow: 0 1px 2px rgb(20 20 50 / 6%), 0 8px 24px rgb(20 20 50 / 6%);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f17;
    --surface: #181824;
    --surface-2: #222232;
    --border: #2d2d40;
    --text: #ececf5;
    --muted: #9a9ab5;
    --brand: #7c70ff;
    --brand-hover: #9187ff;
    --brand-soft: #25224a;
    --danger-soft: #3a1a1d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #fff 0 28%, transparent 29%), var(--brand);
}
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
button.user-chip { border: 0; background: transparent; font: inherit; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
button.user-chip:hover { background: var(--surface-2); color: var(--text); }
dialog input[type=password] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  background: var(--brand-soft); color: var(--brand);
  display: inline-grid; place-items: center; font-weight: 600; font-size: 13px;
}

/* Layout */
.container { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-rec { background: var(--rec); border-color: var(--rec); color: #fff; }
.btn-rec:hover { background: color-mix(in srgb, var(--rec) 88%, #000); }
.btn-lg { padding: 13px 22px; font-size: 16px; border-radius: 12px; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; }

input[type=text], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input[type=text]:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); border: 0; cursor: default;
}
.pill.public { background: var(--brand-soft); color: var(--brand); }
button.pill { cursor: pointer; font-family: inherit; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }

.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* Toasts */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Landing */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.landing .card { width: min(420px, 100%); padding: 36px; text-align: center; }
.landing input[type=email], .landing input[type=password] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; width: 100%; }
.landing input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.landing h1 { font-size: 30px; margin: 18px 0 6px; }
.landing .logo { justify-content: center; font-size: 20px; }
.landing .stack { display: grid; gap: 12px; margin-top: 28px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.google-btn svg { width: 18px; height: 18px; }

/* Dashboard */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.video-card { overflow: hidden; display: flex; flex-direction: column; }
.thumb {
  position: relative; display: block; aspect-ratio: 16 / 9; background: var(--surface-2);
  background-size: cover; background-position: center;
}
.thumb .duration {
  position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 70%); color: #fff;
  font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 6px;
}
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 32px; }
.video-card .body { padding: 12px 14px 14px; display: grid; gap: 8px; }
.title-input {
  border: 1px solid transparent !important; background: transparent !important;
  padding: 4px 6px !important; margin: -4px -6px; font-weight: 600 !important; width: calc(100% + 12px) !important;
  border-radius: 6px !important; text-overflow: ellipsis;
}
.title-input:hover { border-color: var(--border) !important; }
.title-input:focus { background: var(--surface) !important; border-color: var(--brand) !important; }
.meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { text-align: center; padding: 64px 24px; }
.empty .icon { font-size: 44px; }

/* Recorder */
.recorder { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .recorder { grid-template-columns: 1fr; } }
.stage {
  position: relative; aspect-ratio: 16 / 9; background: #0b0b12; border-radius: var(--radius);
  overflow: hidden; display: grid; place-items: center; color: #b9b9d0;
}
.stage canvas, .stage video { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage canvas.grab { cursor: grab; }
.stage canvas.grabbing { cursor: grabbing; }
.stage .hint { text-align: center; padding: 24px; }
.stage .hint .big { font-size: 40px; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / 55%);
  color: #fff; font-size: 120px; font-weight: 800;
}
.panel { padding: 20px; display: grid; gap: 16px; }
.panel h2 { margin: 0; }
.camera-preview {
  width: 120px; height: 120px; border-radius: 50%; overflow: hidden; margin: 0 auto;
  background: var(--surface-2); border: 3px solid var(--surface); box-shadow: var(--shadow);
}
.camera-preview video { width: 100%; height: 100%; object-fit: cover; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--success); transition: width .08s; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--brand); }

.rec-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-top: 16px;
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); animation: pulse 1.2s infinite; }
.rec-dot.paused { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: .3; } }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; min-width: 64px; }
.rec-bar .spacer { flex: 1; }

.preview video { width: 100%; border-radius: var(--radius); background: #000; display: block; max-height: 70vh; }

/* Watch page */
.watch { max-width: 1040px; }
.player { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); display: block; }
.watch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-top: 20px; flex-wrap: wrap; }
.watch-title { font-size: 24px; font-weight: 700; }
.watch-title.title-input { font-size: 24px !important; }
.byline { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.unavailable { text-align: center; padding: 80px 24px; }

/* Document Picture-in-Picture controls */
body.pip { min-height: 0; display: grid; place-items: center; height: 100vh; }
body.pip .rec-bar { margin: 0; box-shadow: none; border: 0; background: transparent; }

/* Library layout */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 59px); }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .sidebar { border-right: 0; border-bottom: 1px solid var(--border); } }
.sidebar { border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 16px; }
.sidebar .space { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  color: var(--text); font-size: 14px; cursor: pointer; user-select: none; min-width: 0;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.space-root { font-weight: 600; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .gear { color: var(--muted); font-size: 13px; padding: 0 4px; border-radius: 4px; }
.nav-item .gear:hover { color: var(--text); background: var(--border); text-decoration: none; }
.nav-item .role { font-size: 11px; color: var(--muted); font-weight: 500; }
.drop-target.drag-over { outline: 2px dashed var(--brand); outline-offset: -2px; background: var(--brand-soft); }
.content { padding: 28px 32px 64px; min-width: 0; }
@media (max-width: 800px) { .content { padding: 20px 16px 48px; } }

.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 10px; }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 28px; }
.folder-card {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; cursor: pointer;
  border-radius: 10px; box-shadow: none;
}
.folder-card:hover { border-color: var(--brand); }
.folder-card .name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-card .icon { font-size: 20px; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px;
  width: 28px; height: 28px; display: inline-grid; place-items: center; font-size: 14px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.video-card[draggable=true], .folder-card[draggable=true] { cursor: grab; }
.dragging { opacity: .45; }
.title-input[readonly] { cursor: default; }
.title-input[readonly]:hover { border-color: transparent !important; }

/* Dialog */
dialog.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
dialog.dialog::backdrop { background: rgb(10 10 25 / 45%); }
.dialog-head { padding: 18px 20px 6px; }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 8px 12px; max-height: 50vh; overflow: auto; display: grid; gap: 2px; }
.dialog-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.pick { border: 0; background: transparent; font: inherit; text-align: left; width: 100%; }
.pick:disabled { opacity: .45; cursor: not-allowed; }
.pick.selected { background: var(--brand); color: #fff; }

/* Account settings */
.settings { max-width: 760px; display: grid; gap: 20px; }
.settings .card { padding: 22px; display: grid; gap: 14px; }
.settings h2 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input[type=text], .row > input[type=email] { flex: 1; min-width: 200px; }
input[type=email] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
select.inline { width: auto; }
.members { display: grid; }
.member { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.member:first-child { border-top: 0; }
.member .who { flex: 1; min-width: 0; }
.member .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .email { font-size: 13px; color: var(--muted); }
.help { font-size: 13px; color: var(--muted); margin: 0; }
