/* ============================================================
   Design system — Screen Recorder platform
   Single source of truth for tokens + components.
   Light/dark via system preference, overridable with
   <html data-theme="light|dark">.
   ============================================================ */

:root {
  /* Brand */
  --brand-h: 243;
  --accent: hsl(var(--brand-h) 78% 62%);
  --accent-strong: hsl(var(--brand-h) 72% 55%);
  --accent-soft: hsl(var(--brand-h) 78% 62% / 0.12);
  --accent-contrast: #ffffff;

  /* Semantic */
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-soft: rgb(220 38 38 / 0.1);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Consolas, monospace;

  /* Shape & motion */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --transition: 150ms cubic-bezier(0.2, 0, 0, 1);

  /* Light theme surfaces */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --surface-3: #e8eaee;
  --border: #e2e4e9;
  --border-strong: #cdd0d8;
  --text: #16181d;
  --text-2: #5a6072;
  --text-3: #8a90a2;
  --shadow-sm: 0 1px 2px rgb(16 18 24 / 0.06);
  --shadow: 0 2px 8px rgb(16 18 24 / 0.08), 0 1px 2px rgb(16 18 24 / 0.06);
  --shadow-lg: 0 12px 40px rgb(16 18 24 / 0.18);
  --backdrop: rgb(18 20 26 / 0.5);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f13;
    --surface: #16181d;
    --surface-2: #1d2027;
    --surface-3: #262a33;
    --border: #262a33;
    --border-strong: #363b47;
    --text: #eceef2;
    --text-2: #9aa1b3;
    --text-3: #6b7284;
    --accent: hsl(var(--brand-h) 84% 68%);
    --accent-strong: hsl(var(--brand-h) 84% 74%);
    --accent-soft: hsl(var(--brand-h) 84% 68% / 0.16);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow: 0 2px 10px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 16px 48px rgb(0 0 0 / 0.6);
    --backdrop: rgb(0 0 0 / 0.65);
    --danger: #f87171;
    --danger-soft: rgb(248 113 113 / 0.12);
    --success: #4ade80;
    --warning: #fbbf24;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e0f13;
  --surface: #16181d;
  --surface-2: #1d2027;
  --surface-3: #262a33;
  --border: #262a33;
  --border-strong: #363b47;
  --text: #eceef2;
  --text-2: #9aa1b3;
  --text-3: #6b7284;
  --accent: hsl(var(--brand-h) 84% 68%);
  --accent-strong: hsl(var(--brand-h) 84% 74%);
  --accent-soft: hsl(var(--brand-h) 84% 68% / 0.16);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow: 0 2px 10px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 16px 48px rgb(0 0 0 / 0.6);
  --backdrop: rgb(0 0 0 / 0.65);
  --danger: #f87171;
  --danger-soft: rgb(248 113 113 / 0.12);
  --success: #4ade80;
  --warning: #fbbf24;
  color-scheme: dark;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* Re-assert the `hidden` attribute. Author rules like `.auth-view{display:flex}`
   and `.gone-state{display:flex}` otherwise beat the UA `[hidden]{display:none}`
   (equal specificity, author origin wins), which breaks every view toggle —
   leaving the login panel stuck open and share pages showing the "invalid" state. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
img, video, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

/* ---------- Icons ---------- */
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  font-weight: 550; font-size: 14px; cursor: pointer; user-select: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap; min-height: 36px;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-outline { background: transparent; border-color: var(--border-strong); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; min-height: 30px; }
.btn-lg { padding: 11px 20px; font-size: 15px; min-height: 44px; }
.btn-icon { padding: 8px; min-width: 36px; }
.btn-icon.btn-sm { padding: 5px; min-width: 30px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 38px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.field-error { font-size: 12.5px; color: var(--danger); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; gap: 10px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.switch-track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border-strong); transition: background var(--transition); flex: none; position: relative;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--transition);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Segmented control */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-2); padding: 5px 12px;
  border-radius: 5px; cursor: pointer; font-size: 13px; font-weight: 550;
  display: inline-flex; align-items: center; gap: 6px; transition: background var(--transition), color var(--transition);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.badge-success { background: rgb(22 163 74 / 0.12); color: var(--success); border-color: transparent; }
.badge-warning { background: rgb(217 119 6 / 0.12); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--backdrop); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn 140ms ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column; animation: modalIn 160ms cubic-bezier(0.2, 0, 0, 1);
}
.modal-lg { max-width: 640px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-header h2 { font-size: 17px; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 4px 20px 18px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (max-width: 560px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; }
}

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(440px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 11px 14px; font-size: 14px; width: 100%;
  animation: toastIn 200ms cubic-bezier(0.2, 0, 0, 1);
}
.toast .icon { flex: none; }
.toast-success .icon { color: var(--success); }
.toast-error .icon { color: var(--danger); }
.toast-actions { margin-left: auto; display: flex; gap: 6px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Dropdown menu ---------- */
.menu {
  position: absolute; z-index: 90; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 5px; animation: fadeIn 120ms ease;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: 0; background: transparent; color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; text-align: left; text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--surface-2); text-decoration: none; }
.menu .menu-danger { color: var(--danger); }
.menu .menu-danger:hover { background: var(--danger-soft); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }

/* ---------- Skeletons & spinners ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 700ms linear infinite; flex: none;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 56px 24px; text-align: center; color: var(--text-2);
}
.empty-state .icon { width: 40px; height: 40px; color: var(--text-3); stroke-width: 1.5; }
.empty-state h3 { color: var(--text); font-size: 16px; }
.empty-state p { font-size: 14px; max-width: 380px; }

/* ---------- Tooltip (CSS-only, data-tip) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%;
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 500; padding: 4px 9px; border-radius: 6px;
  white-space: nowrap; z-index: 80; pointer-events: none; animation: fadeIn 120ms ease;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; color: var(--text-2); font-weight: 550; font-size: 14px;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 0; }
