:root {
  --bg: #000000;
  --bg-elevated: rgba(28, 28, 30, 0.55);
  --glass: rgba(255, 255, 255, 0.10);
  --glass-strong: rgba(255, 255, 255, 0.16);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-border-strong: rgba(255, 255, 255, 0.28);
  --text: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --accent: #0a84ff;
  --accent-glow: rgba(10, 132, 255, 0.45);
  --danger: #ff453a;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  --shadow-float: 0 40px 90px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  --transition: 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --transition-bounce: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em;
}

/* Ambient orbs for liquid glass refraction */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}

.orb-1 {
  width: 55vw;
  height: 55vw;
  background: radial-gradient(circle, rgba(10,132,255,0.55), rgba(10,132,255,0.0) 70%);
  top: -15vh;
  left: -10vw;
}

.orb-2 {
  width: 45vw;
  height: 45vw;
  background: radial-gradient(circle, rgba(175,82,222,0.45), rgba(175,82,222,0.0) 70%);
  bottom: -10vh;
  right: -8vw;
  animation-delay: -6s;
}

.orb-3 {
  width: 35vw;
  height: 35vw;
  background: radial-gradient(circle, rgba(48,209,88,0.35), rgba(48,209,88,0.0) 70%);
  top: 40vh;
  left: 35vw;
  animation-delay: -12s;
}

@keyframes drift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(4vw, 3vh) scale(1.08); }
}

/* Topbar */
.topbar {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  height: 54px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.08));
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 22px;
  height: 22px;
  color: var(--text);
}

.app-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 0 rgba(255,255,255,0.08) inset;
}

.tb-btn:hover {
  background: rgba(255,255,255,0.16);
  transform: translateY(-1px);
}

.tb-btn:active { transform: translateY(0) scale(0.98); }

.tb-btn svg { width: 16px; height: 16px; }

/* Desktop */
.desktop {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

/* Window */
.win {
  position: absolute;
  min-width: 320px;
  min-height: 220px;
  width: 640px;
  height: 400px;
  border-radius: var(--radius-lg);
  z-index: 10;
  user-select: none;
  transition: box-shadow var(--transition), transform var(--transition);
  will-change: transform, width, height, left, top;
}

.win.active { z-index: 100; }

.win-glass {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.07) 45%, rgba(255,255,255,0.12) 100%);
  backdrop-filter: blur(28px) saturate(200%);
  -webkit-backdrop-filter: blur(28px) saturate(200%);
  border: 1px solid var(--glass-border-strong);
  box-shadow: var(--shadow-float), inset 0 1px 0 rgba(255,255,255,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.win.active .win-glass {
  box-shadow: var(--shadow-float), 0 0 0 1px rgba(255,255,255,0.32) inset, 0 0 40px rgba(10,132,255,0.12);
}

/* Titlebar */
.win-titlebar {
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  cursor: grab;
}

.win-titlebar:active { cursor: grabbing; }

.win-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.win-icon { width: 16px; height: 16px; opacity: 0.9; }

.win-actions { display: flex; align-items: center; gap: 6px; }

.win-act {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.07);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.win-act:hover { background: rgba(255,255,255,0.18); transform: scale(1.05); }
.win-act:active { transform: scale(0.95); }
.win-act svg { width: 14px; height: 14px; }

.win-act.close:hover { background: rgba(255,69,58,0.85); color: #fff; }

.win-act.settings,
.win-act.source,
.win-act.close {
  position: relative;
  z-index: 50;
  pointer-events: auto;
}

.win-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.win-titlebar {
  pointer-events: auto;
}

/* Make sure the titlebar and actions are above the stage */
.win-titlebar,
.win-controls {
  position: relative;
  z-index: 25;
}

/* Body */
.win-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1;
  position: relative;
  background: #000;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin: 0 8px 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 2;
}

.empty-state svg { width: 42px; height: 42px; opacity: 0.7; }

.stage.has-source .empty-state { opacity: 0; }

/* Settings panel */
.settings-panel {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 22, 0.78);
  backdrop-filter: blur(34px) saturate(160%);
  -webkit-backdrop-filter: blur(34px) saturate(160%);
  padding: 16px;
  overflow-y: auto;
  transform: translateY(-101%);
  transition: transform var(--transition-bounce);
  z-index: 20;
  pointer-events: auto;
}

.settings-panel.open { transform: translateY(0); }

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-row label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-row input[type="text"],
.field-row input[type="file"],
.field-row textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.field-row input[type="text"]:focus,
.field-row textarea:focus {
  border-color: var(--accent);
  background: rgba(0,0,0,0.45);
  box-shadow: 0 0 0 3px rgba(10,132,255,0.18);
}

.field-row textarea { resize: vertical; min-height: 48px; }

.file-row input[type="file"] { padding: 7px; font-size: 12px; }

.actions-row { margin-top: 4px; }

.btn-apply {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-apply:hover { background: #1a91ff; transform: translateY(-1px); }
.btn-apply:active { transform: translateY(0); }

/* DRM panel */
.drm-panel {
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
  margin-bottom: 12px;
}

.drm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.drm-body {
  padding: 12px;
  display: none;
}

.drm-panel.enabled .drm-body { display: block; }

.drm-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.drm-tab {
  flex: 1;
  min-width: 70px;
  padding: 7px 8px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.drm-tab:hover { background: rgba(255,255,255,0.12); color: var(--text); }
.drm-tab.active { background: rgba(10,132,255,0.22); color: #fff; }

.drm-tab-body.hidden { display: none; }

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: rgba(255,255,255,0.18);
  cursor: pointer;
  transition: background var(--transition);
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform var(--transition-bounce);
}

.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Controls */
.win-controls {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.12);
  position: relative;
  z-index: 5;
}

.ctl {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 9px;
  background: rgba(255,255,255,0.07);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), color var(--transition);
  position: relative;
  z-index: 6;
}

.ctl:hover { background: rgba(255,255,255,0.18); transform: scale(1.06); }
.ctl:active { transform: scale(0.96); }
.ctl svg { width: 16px; height: 16px; }

.time {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 92px;
  text-align: center;
}

.progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.16);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  transition: transform var(--transition);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.volume-wrap { width: 90px; display: flex; align-items: center; }

.hidden { display: none !important; }

/* Resize handles */
.resize-handle {
  position: absolute;
  z-index: 30;
}

.resize-handle.n { top: -4px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.resize-handle.s { bottom: -4px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.resize-handle.e { right: -4px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.resize-handle.w { left: -4px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.resize-handle.ne { top: -4px; right: -4px; width: 12px; height: 12px; cursor: nesw-resize; }
.resize-handle.nw { top: -4px; left: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
.resize-handle.se { bottom: -4px; right: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; width: 12px; height: 12px; cursor: nesw-resize; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(40,40,42,0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition-bounce);
  z-index: 2000;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Responsive */
@media (max-width: 640px) {
  .topbar { height: 48px; }
  .tb-btn span { display: none; }
  .tb-btn { padding: 0 8px; }
  .win { min-width: 280px; min-height: 200px; }
}
