:root {
  color-scheme: light dark;
  --bg: Canvas;
  --bg-elevated: Canvas;
  --bg-elevated2: Canvas;
  --panel: Canvas;
  --panel-soft: color-mix(in srgb, Canvas 90%, CanvasText 10%);
  --border: ButtonBorder;
  --accent: AccentColor;
  --accent-soft: color-mix(in srgb, AccentColor 20%, Canvas 80%);
  --accent-strong: AccentColor;
  --text: CanvasText;
  --muted: GrayText;
  --input-bg: Field;
  --input-border: ButtonBorder;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 24px;
}

#app {
  width: 100%;
  margin: 0 auto;
  background: var(--bg-elevated);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px color-mix(in srgb, CanvasText 15%, transparent);
  padding: 20px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.controls-bar {
  grid-column: 1 / -1;
  grid-row: 2 / 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: 0 10px 30px color-mix(in srgb, CanvasText 12%, transparent);
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.controls-left {
  flex: 1;
}

.controls-right {
  margin-left: auto;
  justify-content: flex-end;
}

.toolbar-project-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.audio-sync {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  min-width: 180px;
}

.audio-sync label {
  font-size: 11px;
  color: var(--muted);
}

.audio-sync-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#audioOffsetInput {
  width: 90px;
  background: var(--input-bg);
  border-radius: 999px;
  border: 1px solid var(--input-border);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

#audioOffsetInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.capture-hint {
  font-size: 11px;
  color: var(--muted);
}

.audio-sync-right {
  width: 100%;
  margin-top: 4px;
}

.audio-sync-standalone {
  margin-top: 10px;
}

/* Left: clip list */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  order: 2;
}

.capture-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 12px 12px 14px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px color-mix(in srgb, CanvasText 15%, transparent);
  display: none;
}

.capture-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.capture-header h2 {
  margin: 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.capture-header h2 span.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  box-shadow: none;
  font-size: 14px;
}

.capture-subtitle {
  font-size: 11px;
  color: var(--muted);
}

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

button {
  font: inherit;
}

button span.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: none;
}

button.small {
  padding: 4px 8px;
  font-size: 11px;
}

button.round {
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.capture-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.status-pill {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  background: var(--panel-soft);
}

.status-dot-idle,
.status-dot-live,
.status-dot-recording {
  width: 7px;
  height: 7px;
  border-radius: 999px;
}

.status-dot-idle {
  background: GrayText;
  box-shadow: none;
}

.status-dot-live {
  background: AccentColor;
  box-shadow: none;
}

.status-dot-recording {
  background: color-mix(in srgb, AccentColor 75%, CanvasText 25%);
  box-shadow: none;
}

.hint {
  font-size: 11px;
  color: var(--muted);
}

.preview-wrapper {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated2);
  box-shadow: 0 12px 28px color-mix(in srgb, CanvasText 15%, transparent);
  margin-top: 6px;
}

#preview {
  width: 100%;
  
  display: block;
  background: var(--panel-soft);
}

#webcamPiP {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-100%, -100%);
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 10px;
  pointer-events: none;
  background: linear-gradient(
    to top,
    color-mix(in srgb, Canvas 80%, transparent) 0%,
    transparent 55%
  );
}

.preview-overlay-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview-badge {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel-soft);
}

.preview-title {
  font-size: 12px;
  color: var(--text);
}

.preview-overlay-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill-soft {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  font-size: 11px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  box-shadow: none;
}

.pill-soft .tiny-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: none;
}

/* Right: preview + export */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  order: 1;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 10px 11px 11px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px color-mix(in srgb, CanvasText 15%, transparent);
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-header h2 span {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel-soft);
}

.panel-header small {
  font-size: 11px;
  color: var(--muted);
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 10px;
  color: var(--muted);
}

.chip {
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

#clipList {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  padding-right: 3px;
}

.clip-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  box-shadow: 0 10px 22px color-mix(in srgb, CanvasText 15%, transparent);
}

.clip-item.dragging {
  opacity: 0.6;
}

.clip-item.drag-over {
  background: color-mix(in srgb, var(--panel) 85%, var(--accent-soft) 15%);
}

.clip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 2px;
}

.clip-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.clip-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.clip-title-input {
  flex: 1;
  min-width: 0;
  background: var(--input-bg);
  border-radius: 999px;
  border: 1px solid var(--input-border);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.clip-title-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.index-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel-soft);
}

.btn-group {
  display: flex;
  gap: 4px;
}

.clip-thumbnail {
  position: relative;
  padding-bottom: 22px; /* make room for the custom timeline below the video */
}

.clip-thumbnail video {
  width: 100%;
  height:300px;
  border-radius: 7px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

.trim-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  height: 22px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px 2px;
}

.trim-overlay .trim-bar {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: 6px;
  background: color-mix(in srgb, #3b82f6 20%, Canvas 80%);
  border: 1px solid color-mix(in srgb, #3b82f6 45%, Canvas 55%);
  pointer-events: auto;
}

.trim-overlay .trim-fill {
  position: absolute;
  top: 1px;
  bottom: 1px;
  background: color-mix(in srgb, var(--accent) 65%, Canvas 35%);
  border-radius: 6px;
}

.trim-overlay .trim-handle {
  position: absolute;
  top: -4px;
  width: 10px;
  height: 16px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, Canvas 50%);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--accent) 30%, transparent);
  transform: translateX(-50%);
  cursor: ew-resize;
}

.trim-overlay .trim-handle-start {
  background: #16a34a;
  border-color: #15803d;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.35);
}

.trim-overlay .trim-handle-end {
  background: #ef4444;
  border-color: #b91c1c;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.35);
}

.trim-overlay .trim-playhead {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 2px;
  background: #facc15;
  border-radius: 2px;
  pointer-events: auto;
  cursor: grab;
  transform: translateX(-50%);
  box-shadow:
    0 0 0 1px rgba(250, 204, 21, 0.7),
    0 0 8px rgba(250, 204, 21, 0.6);
}

.trim-overlay .trim-playhead::after {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #facc15;
  border: 1px solid rgba(217, 119, 6, 0.6);
  box-shadow:
    0 0 10px rgba(250, 204, 21, 0.6),
    0 2px 6px rgba(217, 119, 6, 0.4);
  transform: translate(-50%, 0);
}

.trim-overlay .trim-playhead:active {
  cursor: grabbing;
}

.trim-overlay.disabled {
  opacity: 0.4;
}

.stop-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, CanvasText 35%, transparent);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.stop-overlay-btn {
  padding: 32px 48px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.02em;
  border-radius: 18px;
  background: var(--accent-strong);
  color: ButtonText;
  border: 3px solid ButtonBorder;
  cursor: pointer;
  box-shadow: 0 24px 50px color-mix(in srgb, CanvasText 20%, transparent);
}

.render-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: color-mix(in srgb, CanvasText 40%, transparent);
  backdrop-filter: blur(6px);
  z-index: 10000;
}

.render-overlay.active {
  display: flex;
}

.render-modal {
  width: min(940px, 96vw);
  max-height: 92vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 64px color-mix(in srgb, CanvasText 30%, transparent);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.render-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.render-title {
  font-weight: 700;
  font-size: 16px;
}

.render-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.render-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.render-progress meter {
  width: 100%;
  height: 12px;

}



.render-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.render-preview {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.render-preview-label {
  font-size: 12px;
  color: var(--muted);
}

.render-preview-frame {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
  min-height: 240px;
  max-height: 60vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, CanvasText 6%, transparent);
}

.render-preview-frame canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: var(--panel-soft);
}

.render-preview-placeholder {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

body.rendering-active {
  overflow: hidden;
}

.clip-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
}

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

.clip-meta .label {
  color: var(--muted);
}

.clip-meta .value {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
}

.clip-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  font-size: 11px;
}

.clip-controls label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--muted);
}

.clip-controls input {
  background: var(--input-bg);
  border-radius: 999px;
  border: 1px solid var(--input-border);
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.clip-controls input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.title-preview {
  position: relative;
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-soft);
}

.title-preview-img {
  width: 100%;
  height: 100%;
  max-height:300px;
  object-fit: contain;
  display: block;
}

.title-preview-text {
  width: 100%;
  padding: 14px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 2px 12px color-mix(in srgb, CanvasText 45%, transparent);
  box-sizing: border-box;
}


.title-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 11px;
}

.title-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
}

.title-controls textarea,
.title-controls input,
.title-controls select {
  background: var(--input-bg);
  border-radius: 8px;
  border: 1px solid var(--input-border);
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  resize: vertical;
}

.title-controls textarea:focus,
.title-controls input:focus,
.title-controls select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.title-text-settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  align-items: flex-end;
}

.title-textarea-wrap textarea {
  width: 100%;
  min-height: 90px;
}

.title-duration-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.title-bg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* Export panel */
.export-panel {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 9px 10px 10px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 24px color-mix(in srgb, CanvasText 15%, transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.export-top-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.export-top-left strong {
  font-size: 13px;
  color: var(--text);
}

.export-top-left small {
  font-size: 11px;
  color: var(--muted);
}

.export-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.export-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

#downloadLink {
  font-size: 12px;
  color: LinkText;
  text-decoration: none;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 15%, transparent);
  box-shadow:
    0 12px 24px color-mix(in srgb, currentColor 20%, transparent),
    0 0 0 1px color-mix(in srgb, currentColor 10%, Canvas 90%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#downloadLink:hover {
  text-decoration: none;
}

#status {
  font-size: 11px;
  color: var(--muted);
}

.project-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
}

.project-actions-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.project-actions-left small {
  color: var(--muted);
  font-size: 11px;
}

.project-actions-right {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.repo-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-top: 4px;
}

.project-repo-link {
  font-size: 15px;
  font-weight: 600;
  color: LinkText;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.project-repo-link:hover {
  text-decoration: underline;
}

@media (max-width: 960px) {
  #app {
    padding: 16px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 10px;
  }
  #app {
    padding: 12px;
  }
  .project-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .clip-item {
    grid-template-columns: 1fr;
  }
  .clip-header {
    flex-direction: column;
    align-items: stretch;
  }
  .clip-header-right {
    width: 100%;
    justify-content: flex-start;
    flex: 1 1 100%;
  }
  .clip-thumbnail video {
    max-height: 140px;
  }
  .preview-overlay {
    padding: 8px;
  }
}
