:root {
  --bg: #121218;
  --surface: #1c1c26;
  --surface-2: #262633;
  --border: #343444;
  --text: #ececf1;
  --text-dim: #9b9bad;
  --accent: #8c52ff;
  --accent-hover: #9d6bff;
  --red: #e5484d;
  --amber: #f5a524;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.logo-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

.logo-text {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.author-info {
  margin-left: auto;
  color: #82828f;
  font-size: 12px;
  font-weight: 400;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 48px;
}

.screen { display: none; width: 100%; max-width: 1100px; text-align: center; }
.screen.active { display: block; }

h1 { font-size: 26px; font-weight: 700; margin: 8px 0 26px; }

.hidden { display: none !important; }

/* ---------- Banner ---------- */
.banner {
  background: #3b1d20;
  border: 1px solid var(--red);
  color: #ffd2d4;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
  text-align: left;
}

.subtitle {
  color: var(--text-dim);
  font-size: 15px;
  margin: -14px auto 26px;
  max-width: 560px;
}

/* ---------- Setup panel ---------- */
.setup-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.device-row {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.device-row label {
  flex: 0 0 150px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.device-row select {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  min-width: 0;
}

.device-toggle-label input { accent-color: var(--accent); width: 16px; height: 16px; }

.device-row select:disabled { opacity: 0.45; }

/* Setup-screen mockup: a 16:9 "screen" with the live camera bubble on it. */
#setupStage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background:
    radial-gradient(ellipse at 30% 20%, rgba(140, 82, 255, 0.10), transparent 60%),
    linear-gradient(160deg, #15151d, #1b1b27);
  overflow: hidden;
}

.setup-stage-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 14px;
  user-select: none;
  pointer-events: none;
}

.setup-stage-hint .hint-icon { font-size: 30px; }

#setupBubble {
  position: absolute;
  cursor: move;
  touch-action: none;
}

#setupBubble .bubble-clip {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

#setupBubble video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

.hint { color: var(--text-dim); font-size: 13px; margin: 0; text-align: left; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover:not(:disabled) { background: #303040; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.danger:hover:not(:disabled) { background: #f25b60; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 16px; padding: 13px 26px; border-radius: 12px; }
.btn.muted { background: #3b1d20; border-color: var(--red); }

.rec-glyph {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  display: inline-block;
}

/* ---------- Record screen ---------- */
.stage-area { display: flex; justify-content: center; }

#stageWrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

#stage {
  display: block;
  max-width: 100%;
  max-height: 68vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  background: #000;
  border: 1px solid var(--border);
}

/* Camera bubble interaction overlay */
#bubbleOverlay {
  position: absolute;
  border: 2px dashed transparent;
  cursor: move;
  touch-action: none;
  transition: border-color 0.15s;
}

#bubbleOverlay:hover { border-color: var(--accent); }

.bubble-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 1.5px solid #fff;
  cursor: nwse-resize;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

#bubbleOverlay:hover .bubble-handle { opacity: 1; }

#setupBubble .bubble-handle { opacity: 0.7; }
#setupBubble:hover .bubble-handle { opacity: 1; }

/* Countdown */
#countdownOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(10, 10, 16, 0.55);
  backdrop-filter: blur(3px);
  border-radius: 12px;
  line-height: 1.2;
}

#countdownNum {
  font-size: 120px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.6);
}

#countdownNum.pop { animation: pop 0.9s ease-out; }

@keyframes pop {
  0% { transform: scale(1.6); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.85; }
}

/* Controls bar */
.controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 16px;
  flex-wrap: wrap;
  justify-content: center;
}

#timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  min-width: 52px;
  text-align: left;
}

.divider { width: 1px; height: 24px; background: var(--border); }

.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.2s ease-in-out infinite;
}

.rec-dot.paused { background: var(--amber); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- Preview ---------- */
#previewVideo {
  width: 100%;
  max-width: 920px;
  max-height: 60vh;
  border-radius: 12px;
  background: #000;
  border: 1px solid var(--border);
}

.meta { color: var(--text-dim); font-size: 14px; margin: 14px 0 22px; }

.export-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.export-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.export-row-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 76px;
  text-align: right;
}

.res-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.res-chip input { display: none; }

.res-chip span {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.res-chip span strong { color: inherit; }

.res-chip input:checked + span {
  border-color: var(--accent);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(140, 82, 255, 0.25);
}

.preview-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.export-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
}

.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

#exportBarFill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s linear;
}

#exportStatus {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.export-hint { text-align: center; }
.export-hint a { color: var(--accent); }
