:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfbfe;
  --border: #e8eaf0;
  --border-strong: #d8dbe6;
  --text: #1d2030;
  --muted: #6b7288;
  --purple: #6d4aff;
  --purple-dark: #5736e0;
  --purple-soft: #f0edff;
  --red: #ff3b5c;
  --red-dark: #e82446;
  --red-soft: #ffeef2;
  --green: #22c55e;
  --green-soft: #e8f9ef;
  --amber: #f59e0b;
  --amber-soft: #fff4e0;
  --blue: #3b82f6;
  --blue-soft: #eaf2ff;
  --pink: #ec4899;
  --pink-soft: #fdeef6;
  --shadow-sm: 0 1px 2px rgba(23, 26, 41, 0.05), 0 1px 3px rgba(23, 26, 41, 0.06);
  --shadow-md: 0 6px 24px rgba(23, 26, 41, 0.08);
  --shadow-lg: 0 16px 48px rgba(23, 26, 41, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--purple) 0%, var(--pink) 100%);
  color: #fff;
  font-size: 15px;
  padding-left: 2px;
  box-shadow: 0 4px 12px rgba(109, 74, 255, 0.35);
}

.brand-text h1 {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.2px;
  color: var(--text);
}

.tagline {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Mode toggle ---------- */
.mode-toggle {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.mode-btn:hover {
  color: var(--text);
  background: var(--surface);
}

.mode-btn.active {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 2px 8px rgba(109, 74, 255, 0.3);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rec-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0.15; }
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  min-width: 50px;
  text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  width: 100%;
  box-shadow: var(--shadow-sm);
}

.btn:hover { background: var(--surface-2); border-color: var(--purple); box-shadow: var(--shadow-sm), 0 0 0 3px var(--purple-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(109, 74, 255, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #7b5cff 0%, #5f3fe8 100%);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(109, 74, 255, 0.4);
}

.btn-primary:disabled {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  opacity: 0.5;
}

.btn-record {
  background: var(--red);
  border-color: transparent;
  color: #fff;
  width: auto;
  min-width: 128px;
  box-shadow: 0 4px 14px rgba(255, 59, 92, 0.35);
}

.btn-record:hover {
  background: var(--red-dark);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(255, 59, 92, 0.45);
}

.btn-record.recording {
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: var(--red);
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
}

.btn-ghost:hover { color: var(--purple); border-color: var(--border); background: var(--surface); }

.btn-float {
  width: auto;
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--red-soft);
  border-color: transparent;
  color: var(--red);
  box-shadow: none;
}

.btn-danger:hover { background: #ffdde5; border-color: transparent; }

.btn-small {
  width: auto;
  padding: 7px 13px;
  font-size: 13px;
  flex: 0 0 auto;
}

/* ---------- Main layout ---------- */
main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background:
    radial-gradient(1200px 600px at 20% 0%, #f1edff 0%, transparent 55%),
    radial-gradient(1000px 500px at 90% 100%, #ffeef2 0%, transparent 55%),
    var(--bg);
  overflow: hidden;
}

#stage {
  aspect-ratio: 9 / 16;
  height: min(80vh, 980px);
  max-width: 100%;
  background: #000;
  border-radius: 20px;
  border: 6px solid var(--surface);
  box-shadow: var(--shadow-lg);
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: aspect-ratio 0.3s ease;
}

#stage.mode-desktop {
  aspect-ratio: 16 / 9;
  height: min(70vh, 680px);
}

#stage.dragging { cursor: grabbing; }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  max-width: 460px;
  line-height: 1.5;
}

.hint b { color: var(--purple); font-weight: 700; }

/* ---------- Controls ---------- */
.controls {
  flex: 0 0 340px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.1px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 15px;
}

.chip-red { background: var(--red-soft); }
.chip-purple { background: var(--purple-soft); }
.chip-amber { background: var(--amber-soft); }
.chip-green { background: var(--green-soft); }
.chip-blue { background: var(--blue-soft); }
.chip-pink { background: var(--pink-soft); }

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.row span:first-child { min-width: 96px; }

.row.check { gap: 8px; }

.row.check input { width: 16px; height: 16px; accent-color: var(--purple); }

.row select {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
}

.row input[type="range"] {
  flex: 1;
  accent-color: var(--purple);
  min-width: 60px;
}

.val {
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.val.muted { color: var(--muted); }

/* ---------- Image list ---------- */
.img-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.img-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.img-item:hover { border-color: var(--border-strong); }

.img-item.selected {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-soft);
}

.img-item img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}

.img-item .name {
  flex: 1;
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.img-item .dim {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover { color: var(--text); border-color: var(--muted); background: var(--surface-2); }
.icon-btn.off { opacity: 0.4; }
.icon-btn.del:hover { color: var(--red); border-color: var(--red); background: var(--red-soft); }

/* ---------- Screen crop ---------- */
.crop-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.crop-preset {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.crop-preset:hover {
  border-color: var(--purple);
  color: var(--purple);
}

.crop-preset.active {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}

/* ---------- Shot list ---------- */
.panel-shots {
  border: 2px solid var(--purple-soft);
}

.shot-actions {
  display: flex;
  gap: 8px;
}

.shot-actions .btn { flex: 1; }

.shot-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
}

.shot-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.shot-item:hover { border-color: var(--border-strong); }

.shot-item.active {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-soft);
}

.shot-item.recorded {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green-soft);
}

.shot-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shot-num {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--purple-soft);
  color: var(--purple);
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.shot-num.done {
  background: var(--green-soft);
  color: var(--green);
}

.shot-name-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  padding: 2px 0;
  min-width: 0;
}

.shot-name-input::placeholder { color: var(--muted); }

.shot-duration {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.shot-duration input {
  width: 38px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 4px;
  font-size: 11px;
  text-align: center;
  background: var(--surface);
}

.shot-script {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 48px;
  max-height: 120px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.shot-script:focus { border-color: var(--purple); }
.shot-script::placeholder { color: var(--muted); }

.shot-footer {
  display: flex;
  align-items: center;
  gap: 6px;
}

.shot-record-btn {
  appearance: none;
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.shot-record-btn:hover {
  background: var(--red);
  color: #fff;
}

.shot-record-btn.recording {
  background: var(--red);
  color: #fff;
  animation: blink 1s steps(1) infinite;
}

.shot-record-btn.recorded {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
}

.shot-status {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}

.shot-status.ok { color: var(--green); font-weight: 600; }

.shot-delete {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
}

.shot-delete:hover { color: var(--red); }

.shot-drag {
  cursor: grab;
  color: var(--muted);
  font-size: 14px;
  user-select: none;
}

.shot-drag:active { cursor: grabbing; }

.shot-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  padding: 16px 0;
}

/* ---------- Editor modal ---------- */
.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 34, 0.5);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.editor-overlay[hidden] {
  display: none !important;
}

.pip-status {
  color: var(--green);
  font-weight: 600;
}

.editor {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: min(680px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.2px;
}

.editor-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#editorVideo {
  width: 100%;
  max-height: 46vh;
  background: #0d0f18;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-row input[type="range"] {
  flex: 1;
  accent-color: var(--purple);
}

.trim-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.trim-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.trim-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.trim-line span { min-width: 34px; }

.trim-line input[type="range"] {
  flex: 1;
  accent-color: var(--amber);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-row select {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
}

.render-msg {
  color: var(--purple);
  font-weight: 700;
}

.editor-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.editor-actions .btn { flex: 1; min-width: 150px; }

/* ---------- Status toast ---------- */
.status {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #191c2c;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  max-width: 80vw;
  text-align: center;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(23, 26, 41, 0.25);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.show { opacity: 1; }

.status.error {
  background: var(--red);
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 20px;
  max-width: 72vw;
  line-height: 1.45;
  white-space: normal;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d3d7e2; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #b9bfce; }

@media (max-width: 900px) {
  main { flex-direction: column; overflow-y: auto; }
  body { overflow: auto; }
  .controls { flex: none; width: auto; border-left: none; border-top: 1px solid var(--border); }
  #stage { height: auto; width: min(86vw, 480px); }
  #stage.mode-desktop { width: min(90vw, 700px); }
  .header-actions { gap: 8px; }
  .btn-float { display: none; }
  .editor { padding: 16px; }
  .mode-toggle { font-size: 12px; }
}
