:root {
  color-scheme: light;
  --font-sans: "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: Georgia, "Iowan Old Style", "Times New Roman", serif;

  /* 3-step body typography scale (plus architectural h1 & brand wordmark) */
  --text-lg: 1.25rem;
  --text-md: 0.9375rem;
  --text-sm: 0.8125rem;

  /* Architectural daylight tokens */
  --paper: #f6f5f0;
  --surface: #ffffff;
  --surface-tint: #eef2ec;
  --ink: #132220;
  --muted: #4f615c;
  --line: #dde1d8;
  --accent: #0a6657;
  --accent-hover: #085246;
  --accent-soft: #dff2ec;
  --rec: #d93829;
  --rec-hover: #b82b1e;
  --warn: #a45b0b;
  --warn-soft: #fdf2e3;

  /* Dark studio tokens */
  --st-bg: #0d1413;
  --st-panel: #141e1c;
  --st-elevated: #1c2825;
  --st-line: #283834;
  --st-ink: #f3f6f2;
  --st-muted: #9eb0aa;
  --st-accent: #6de0cc;
  --st-accent-ink: #0a1f1c;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

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

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
a { color: var(--accent); }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.tabular { font-variant-numeric: tabular-nums; }

/* Accessible visually-hidden utility (modern-web-guidance) */
.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link:focus-visible {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

/* Brand mark */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand-word small {
  display: block;
  margin-top: 4px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}

.brand.compact .brand-word small { display: none; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--ink);
  color: #7ce3d0;
  font-family: var(--font-sans);
  font-size: 1.35rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  position: relative;
  flex: none;
}

.brand-mark > span { transform: translate(-2px, 1px); }
.brand-mark > i {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e5483a;
}

.brand.compact .brand-mark { width: 34px; height: 34px; font-size: 1.15rem; border-radius: 9px; }

/* Buttons & inputs */
.btn, .btn-primary, .btn-secondary, .btn-danger, .btn-record, .icon-btn, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-block-size: 38px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  background: transparent;
  transition-property: background-color, border-color, color, transform, opacity;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}

.btn-primary {
  background: var(--ink);
  color: #f8f9f5;
  border-color: var(--ink);
}
.btn-primary:hover:not(:disabled) { background: #243b37; }

.btn-record {
  background: var(--rec);
  color: #ffffff;
  border-color: var(--rec);
}
.btn-record:hover:not(:disabled) { background: var(--rec-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-tint); border-color: #b7c3b8; }

.btn-danger {
  background: #fff2f0;
  color: #a92418;
  border-color: #f0c2bc;
}
.btn-danger:hover:not(:disabled) { background: #ffe3df; }

.btn-ghost {
  color: var(--accent);
  padding: 0 10px;
}
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }

.icon-btn {
  min-inline-size: 36px;
  min-block-size: 36px;
  padding: 0 8px;
  color: inherit;
}
.icon-btn:hover:not(:disabled) { background: rgba(127, 148, 140, 0.16); }

.btn-sm { min-block-size: 32px; padding: 0 11px; font-size: var(--text-sm); }

/* Segmented controls (non-button clusters for modes/filters) */
.segmented {
  display: inline-flex;
  background: var(--surface-tint);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 6px 11px;
  min-block-size: 30px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition-property: background-color, color;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}

.segmented button[aria-pressed="true"],
.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 28, 25, 0.08);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
}

.field .hint {
  font-weight: 400;
  color: var(--muted);
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea) {
  width: 100%;
  min-width: 0;
  min-block-size: 40px;
  padding: 8px 12px;
  border: 1px solid #cbd2c6;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  transition-property: border-color, background-color;
  transition-duration: 140ms;
}

textarea { min-block-size: 84px; resize: vertical; line-height: 1.5; }
input[type="color"] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: transparent; cursor: pointer; }

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}
.check-row input[type="checkbox"] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

/* Fallback for browsers without accent-color (brand-consistent-forms guide) */
@supports not (accent-color: auto) {
  .check-row { position: relative; padding-left: 26px; }
  .check-row input[type="checkbox"] {
    position: absolute;
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  .check-row input[type="checkbox"] + span::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 17px;
    height: 17px;
    border: 2px solid var(--muted);
    border-radius: 4px;
    background: var(--surface);
  }
  .check-row input[type="checkbox"]:checked + span::before {
    background: var(--accent);
    border-color: var(--accent);
  }
  .check-row input[type="checkbox"]:focus-visible + span::before {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

/* Native Range Sliders (modern-web-guidance: slider) */
input[type="range"] {
  --slider-track-size: 6px;
  --slider-thumb-size: 16px;
  --slider-track-radius: 999px;
  --slider-thumb-radius: 50%;
  --slider-track-color: #c8d2cb;
  --slider-fill-color: var(--accent);
  --slider-thumb-color: var(--accent);
  --slider-direction: to right;
  --attr-min: attr(min type(<number>), 0);
  --attr-max: attr(max type(<number>), 100);
  --control-value: attr(value type(<number>), 50);
  --slider-progress: calc(progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%);

  appearance: none;
  -webkit-appearance: none;
  inline-size: 100%;
  block-size: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

@supports not (opacity: progress(1, 0, 100)) {
  input[type="range"] {
    --slider-progress: calc((var(--control-value) - var(--attr-min)) / max(0.0001, (var(--attr-max) - var(--attr-min))) * 100%);
  }
}

/* Separate WebKit and Firefox blocks (never comma-combined) */
input[type="range"]::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc((var(--slider-track-size) - var(--slider-thumb-size)) / 2);
  border: 0;
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
}

input[type="range"]::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: var(--slider-track-color);
}

input[type="range"]::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--slider-track-radius);
  background: var(--slider-fill-color);
}

input[type="range"]::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 0;
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--slider-fill-color);
  outline-offset: 4px;
}

/* Native Modal <dialog> with @starting-style + allow-discrete (modern-web-guidance) */
dialog.toma-dialog {
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  max-height: 86dvh;
  overflow: auto;
  box-shadow: 0 24px 64px rgba(10, 24, 21, 0.28);
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 210ms;
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.toma-dialog { transform: translateY(10px) scale(0.97); }
}

dialog.toma-dialog[open]:where(:not([data-closing])) {
  opacity: 1;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) {
    transform: translateY(0) scale(1);
    @starting-style { transform: translateY(10px) scale(0.97); }
  }
}

dialog.toma-dialog::backdrop {
  background: rgba(12, 24, 21, 0);
  backdrop-filter: blur(2px);
  transition-property: background-color, display, overlay;
  transition-duration: 210ms;
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
}

dialog.toma-dialog[open]:where(:not([data-closing]))::backdrop {
  background: rgba(12, 24, 21, 0.48);
  @starting-style { background: rgba(12, 24, 21, 0); }
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.dialog-body {
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 6px;
}

/* Boot shell & Toast */
.boot-shell {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  max-width: min(92vw, 460px);
  background: var(--ink);
  color: #f6f8f4;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
  transition-property: opacity, transform;
  transition-duration: 180ms;
  transition-timing-function: var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ======================== LOGIN ======================== */
.login-layout {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  min-height: 100dvh;
}

.login-stage {
  background: var(--st-bg);
  color: var(--st-ink);
  padding: clamp(28px, 5vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.login-stage .brand-word small { color: var(--st-muted); }
.login-stage .brand-mark { background: #1e332f; }

.login-preview-frame {
  margin: auto 0;
  border-radius: 18px;
  padding: 20px;
  background: linear-gradient(135deg, #0d5044 0%, #152b2a 55%, #2b1d28 100%);
  border: 1px solid rgba(124, 227, 208, 0.18);
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.42);
}

.login-preview-screen {
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  background: #f6f5f0;
  color: var(--ink);
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-preview-bars {
  display: flex;
  gap: 6px;
}
.login-preview-bars span { width: 9px; height: 9px; border-radius: 50%; background: #d5dbd2; }
.login-preview-lines { display: grid; gap: 8px; margin-top: 12px; max-width: 62%; }
.login-preview-lines i { display: block; height: 8px; border-radius: 4px; background: #dde4dc; }
.login-preview-lines i:first-child { height: 14px; background: #132220; width: 78%; }
.login-preview-lines i:last-child { width: 52%; }

.login-preview-bubble {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7ce3d0, #0a6657 72%);
  border: 3px solid #ffffff;
  box-shadow: 0 10px 24px rgba(10, 26, 23, 0.32);
}

.login-stage-note {
  color: var(--st-muted);
  font-size: var(--text-sm);
  margin: 24px 0 0;
  max-width: 46ch;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: clamp(24px, 5vw, 56px);
  background: var(--paper);
}

.login-form {
  width: min(100%, 390px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.4rem, 4.5vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
}

.login-form p { margin: 0 0 8px; color: var(--muted); font-size: var(--text-md); }
.form-error { color: #b42318; font-size: var(--text-sm); font-weight: 500; margin: 0; min-height: 1.2em; }
.login-divider { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }

/* ======================== WORKSPACE SHELL (LIBRARY & STORAGE) ======================== */
.workspace-layout {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  background: var(--surface-tint);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 24px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar .brand { padding: 0 6px; }
.sidebar-cta { width: 100%; }

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 9px;
  padding: 10px 12px;
  min-block-size: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  transition-property: background-color, color;
  transition-duration: 140ms;
}

.nav-item:hover { background: #e1eae0; }
.nav-item[aria-current="page"] { background: #d4ebe2; color: #084d41; }

.sidebar-folders {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sidebar-section-label {
  padding: 4px 12px 6px;
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.quota-mini {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: var(--text-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}

.quota-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-tint);
  overflow: hidden;
}
.quota-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.quota-bar.warn > i { background: var(--rec); }

.workspace-main {
  padding: clamp(22px, 3.6vw, 48px);
  max-width: 1520px;
  width: 100%;
  margin-inline: auto;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.1rem, 4vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 0 20px;
  border-top: 1px solid var(--line);
}

.search-wrap {
  position: relative;
  width: min(100%, 340px);
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-wrap input[type="search"] { padding-left: 40px; }

/* Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
  gap: 22px 20px;
}

.video-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition-property: border-color, transform, box-shadow;
  transition-duration: 180ms;
  transition-timing-function: var(--ease);
}

.video-card:hover {
  border-color: #88a79d;
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(19, 34, 32, 0.07);
}

.video-thumb-link {
  display: block;
  position: relative;
  aspect-ratio: 16 / 9;
  background: #162422;
  overflow: hidden;
  text-decoration: none;
}

.video-thumb-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-thumb-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #163732 0%, #101b1a 100%);
  color: #7ce3d0;
}

.video-duration {
  position: absolute;
  right: 9px;
  bottom: 9px;
  background: rgba(10, 17, 16, 0.86);
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.video-card-body {
  padding: 14px 16px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.video-card-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card-meta {
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-variant-numeric: tabular-nums;
}

.video-card-actions {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid #eef0ea;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed #b9c4b8;
  border-radius: var(--radius-lg);
  padding: 52px 24px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.7rem;
  color: var(--ink);
}
.empty-state p { margin: 0; max-width: 46ch; }

/* Storage Center */
.storage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.storage-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.storage-panel h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
}

.storage-metric {
  font-family: var(--font-display);
  font-size: 2rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.storage-split {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 22px;
  align-items: start;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}

.data-table th { color: var(--muted); font-weight: 600; }

/* ======================== DARK CINEMA STUDIO (component-specific-light-dark-theme) ======================== */
.studio-shell {
  color-scheme: only dark;
  background: var(--st-bg);
  color: var(--st-ink);
  accent-color: var(--st-accent);
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.studio-shell :where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--st-accent);
  outline-offset: 2px;
}

.studio-shell input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
.studio-shell select,
.studio-shell textarea {
  background: #101817;
  color: var(--st-ink);
  border-color: var(--st-line);
}

.studio-shell input[type="range"] {
  --slider-track-color: #2c3e3a;
  --slider-fill-color: var(--st-accent);
  --slider-thumb-color: #ffffff;
}

.studio-shell .btn-secondary {
  background: var(--st-elevated);
  color: var(--st-ink);
  border-color: var(--st-line);
}
.studio-shell .btn-secondary:hover:not(:disabled) {
  background: #253632;
  border-color: #3a524c;
}

.studio-shell .btn-primary {
  background: var(--st-accent);
  color: var(--st-accent-ink);
  border-color: var(--st-accent);
}
.studio-shell .btn-primary:hover:not(:disabled) { background: #89ebda; }

.studio-shell .segmented {
  background: #0f1716;
  border-color: var(--st-line);
}
.studio-shell .segmented button { color: var(--st-muted); }
.studio-shell .segmented button[aria-pressed="true"],
.studio-shell .segmented button[aria-selected="true"] {
  background: #22322e;
  color: var(--st-ink);
}

.studio-head {
  background: var(--st-panel);
  border-bottom: 1px solid var(--st-line);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.studio-head-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}

.studio-title-input {
  max-width: 300px;
  min-block-size: 34px !important;
  padding: 4px 10px !important;
  font-weight: 600;
  background: transparent !important;
  border-color: transparent !important;
}
.studio-title-input:hover, .studio-title-input:focus {
  background: #101817 !important;
  border-color: var(--st-line) !important;
}

.studio-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.studio-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 326px;
  min-height: 0;
}

.studio-stage-col {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 18px 22px 12px;
  min-height: 300px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(109, 224, 204, 0.06), transparent 62%),
    var(--st-bg);
}

.stage-canvas {
  max-width: 100%;
  max-height: calc(100dvh - 300px);
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  background: #080d0c;
  display: block;
}

.stage-canvas.pick-zoom { cursor: crosshair; }

/* Teleprompter overlay (never baked into canvas!) */
.teleprompter-overlay {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 620px);
  max-height: 155px;
  overflow: hidden;
  background: rgba(9, 15, 14, 0.84);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(109, 224, 204, 0.28);
  border-radius: 12px;
  padding: 12px 18px;
  z-index: 6;
  color: #f6f8f5;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}

.teleprompter-track {
  overflow-y: auto;
  max-height: 110px;
  line-height: 1.45;
  white-space: pre-wrap;
  scrollbar-width: none;
}
.teleprompter-track::-webkit-scrollbar { display: none; }

.teleprompter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  color: var(--st-muted);
}

/* Countdown overlay */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 12, 11, 0.62);
  z-index: 12;
  font-family: var(--font-display);
  font-size: clamp(5rem, 12vw, 9rem);
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

/* Recording floating dock on canvas */
.record-dock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--st-panel);
  border-top: 1px solid var(--st-line);
}

.rec-timer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--text-md);
  min-width: 78px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rec);
}

.vu-meter {
  width: 74px;
  height: 8px;
  border-radius: 999px;
  background: #23322f;
  overflow: hidden;
}
.vu-meter > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #52d6b6, #e8c547, #e5483a);
  transition-property: width;
  transition-duration: 60ms;
}

/* Timeline tray */
.timeline-tray {
  background: #111918;
  border-top: 1px solid var(--st-line);
  padding: 12px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timeline-transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.timeline-transport-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.timecode {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--st-muted);
  min-width: 112px;
}

.clips-strip {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 6px;
}

.clip-block {
  flex: none;
  min-width: 144px;
  max-width: 240px;
  border-radius: 10px;
  border: 1px solid var(--st-line);
  background: var(--st-elevated);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  color: var(--st-ink);
  transition-property: border-color, background-color;
  transition-duration: 140ms;
}

.clip-block[aria-selected="true"] {
  border-color: var(--st-accent);
  background: #203430;
}

.clip-block-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
}

.clip-block-sub {
  font-size: var(--text-sm);
  color: var(--st-muted);
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

/* Studio right inspector */
.studio-inspector {
  background: var(--st-panel);
  border-left: 1px solid var(--st-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--st-line);
  padding: 6px;
  gap: 4px;
}

.inspector-tabs button {
  border: 0;
  background: transparent;
  color: var(--st-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 7px;
  min-block-size: 36px;
}

.inspector-tabs button[aria-selected="true"] {
  background: var(--st-elevated);
  color: var(--st-accent);
}

.inspector-scroll {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.panel-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--st-line);
}
.panel-group:last-child { border-bottom: 0; padding-bottom: 0; }

.panel-group h3 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--st-ink);
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.layout-opt {
  border: 1px solid var(--st-line);
  border-radius: 9px;
  background: #101817;
  color: var(--st-muted);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: var(--text-sm);
  font-weight: 600;
}

.layout-opt[aria-pressed="true"] {
  border-color: var(--st-accent);
  background: #1d312d;
  color: var(--st-ink);
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0;
  min-block-size: 34px;
}
.swatch[aria-pressed="true"] { border-color: #ffffff; transform: scale(1.06); }

.range-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.range-row-head {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--st-muted);
  font-variant-numeric: tabular-nums;
}

.zoom-item, .cue-item {
  border: 1px solid var(--st-line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #101817;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-sm);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-gap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ======================== WATCH & EMBED PAGE ======================== */
.watch-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px clamp(16px, 4vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.watch-main {
  max-width: 1360px;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px) clamp(16px, 4vw, 40px) 56px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: start;
}

.watch-player-wrap {
  color-scheme: only dark;
  background: #0c1211;
  color: #f4f6f2;
  accent-color: #6de0cc;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(13, 24, 21, 0.16);
}

.watch-video-box {
  position: relative;
  background: #070b0a;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
}
.watch-video-box.aspect-9-16 { aspect-ratio: 9 / 16; max-height: 76dvh; margin-inline: auto; }
.watch-video-box.aspect-1-1 { aspect-ratio: 1 / 1; max-height: 74dvh; margin-inline: auto; }

.watch-video-box video,
.watch-video-box iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #000;
}

.player-controls {
  padding: 10px 14px 12px;
  background: #121a19;
  border-top: 1px solid #22302d;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-controls input[type="range"] {
  --slider-track-color: #2f423e;
  --slider-fill-color: #6de0cc;
  --slider-thumb-color: #ffffff;
}

.player-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.watch-info {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.watch-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.watch-title-row h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.watch-cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 10px;
  color: #ffffff;
  font-weight: 700;
  font-size: var(--text-md);
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(10, 40, 35, 0.18);
  transition-property: transform, opacity;
  transition-duration: 150ms;
}
.watch-cta-btn:hover { transform: translateY(-1px); opacity: 0.94; }

.reactions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.react-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  min-block-size: 36px;
  font-size: var(--text-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.react-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.watch-aside {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.aside-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--surface-tint);
}

.aside-tabs button {
  border: 0;
  background: transparent;
  padding: 11px 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.aside-tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.aside-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 68dvh;
  overflow-y: auto;
}

.chapter-btn, .transcript-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--text-sm);
}
.chapter-btn:hover, .transcript-btn:hover { background: var(--surface-tint); }
.transcript-btn.active { background: var(--accent-soft); border-color: #a9d9cb; }

.ts-pill {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.comment-item {
  border-bottom: 1px solid #eef0ea;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-sm);
}
.comment-item:last-child { border-bottom: 0; }

/* Embed mode */
html[data-embed="1"] body { background: #000; overflow: hidden; }
.embed-shell {
  width: 100vw;
  height: 100dvh;
  background: #000;
  display: grid;
  place-items: center;
  position: relative;
}
.embed-shell video, .embed-shell iframe { width: 100%; height: 100%; border: 0; }

/* Progress bar */
progress.toma-progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  accent-color: var(--accent);
}

/* ======================== RESPONSIVE & COARSE POINTERS ======================== */
@media (pointer: coarse) {
  .btn, .btn-primary, .btn-secondary, .btn-record, .icon-btn, .nav-item {
    min-block-size: 44px;
  }
}

@media (max-width: 1020px) {
  .studio-body { grid-template-columns: 1fr; }
  .studio-inspector {
    border-left: 0;
    border-top: 1px solid var(--st-line);
    max-height: none;
  }
  .stage-canvas { max-height: 46dvh; }
  .watch-main { grid-template-columns: 1fr; }
  .storage-grid { grid-template-columns: 1fr; }
  .storage-split { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-stage { min-height: 260px; padding: 24px 20px; }
  .login-preview-frame { margin-top: 20px; }
  .workspace-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    gap: 10px;
  }
  .sidebar-cta { display: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-item { width: auto; flex: 1; justify-content: center; }
  .sidebar-folders, .quota-mini { display: none; }
  .sidebar-foot { flex-direction: row; margin-top: 0; padding-top: 8px; }
  .studio-shell { grid-template-rows: auto minmax(0, 1fr); }
  .studio-head {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 10px 12px;
    align-items: center;
  }
  .studio-head-left {
    display: contents;
  }
  .studio-head-left > .brand { grid-column: 1; grid-row: 1; }
  .studio-head-right {
    grid-column: 2;
    grid-row: 1;
    justify-content: flex-end;
    gap: 6px;
  }
  .studio-head-left > .studio-title-input {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
    background: #101817 !important;
    border-color: var(--st-line) !important;
  }
  .studio-head-left > .segmented {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
  }
  .studio-head-left > .segmented > button { flex: 1; justify-content: center; }
  .studio-head-right .btn-label-hide { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.toma-dialog, dialog.toma-dialog::backdrop { transition-duration: 80ms; }
  *, *::before, *::after { animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
