:root {
  font-family: 'Manrope', sans-serif;
  color-scheme: dark;
  --bg: #0a0b11;
  --panel: #111827;
  --panel-2: #0f172a;
  --card: #121a2a;
  --border: #243350;
  --text: #e6eefc;
  --muted: #9fb0cc;
  --accent: #4b7bff;
  --accent-2: #27d9a5;
  --danger: #ff3b6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% 10%, #122042 0%, #0a0b11 60%) no-repeat;
  color: var(--text);
}

a { color: #9ad1ff; text-decoration: none; }

.shell { max-width: 1400px; margin: 0 auto; padding: 24px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(10px);
}

.brand {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.nav { display: flex; gap: 12px; flex-wrap: wrap; }
.nav a { font-size: 13px; color: var(--muted); }
.nav a:hover { color: var(--text); }
.nav .danger-link { color: #ff93ad; }

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 22px 4px 18px;
  gap: 16px;
}

h1 {
  margin: 6px 0 4px;
  font-size: 32px;
  font-family: 'Space Grotesk', sans-serif;
}

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

.small { font-size: 12px; color: var(--muted); }
.status-ok { color: #9ff3d7; }
.status-error { color: #ffb3c2; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}
.main { min-width: 0; }

.sidebar {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  margin-bottom: 4px;
}
.generate-form { display: flex; flex-direction: column; gap: 4px; }
.generate-form .rowinline { flex-wrap: wrap; }
.generate-form select,
.generate-form input { min-width: 120px; }
.form-status { font-size: 11px; color: var(--muted); }
.form-status.error { color: #ffb3c2; }
.generate-form .actions { justify-content: space-between; align-items: center; }
.generate-form .actions .rowinline { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: linear-gradient(180deg, #121a2a 0%, #0f1526 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.35);
  min-width: 0;
}

.timeline { display: flex; flex-direction: column; gap: 14px; }

.itemhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: grab; flex-wrap: wrap; }
.title { font-weight: 700; min-width: 0; flex: 1 1 auto; word-break: break-word; }
.item-actions { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid #2b3b5a;
  border-radius: 999px;
  margin-left: 8px;
  opacity: 0.9;
}

.token { font-size: 11px; }

input, textarea, select {
  width: 100%;
  background: #0e1522;
  color: var(--text);
  border: 1px solid #273550;
  border-radius: 12px;
  padding: 10px;
  margin: 6px 0 10px;
}

button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button.danger { background: var(--danger); }
button.ghost {
  background: transparent;
  border: 1px solid #2b3b5a;
  color: var(--muted);
}

.rowinline { display: flex; gap: 8px; }
.actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.actions .autosave-status { margin-left: 10px; font-size: 11px; color: var(--muted); align-self: center; }
.color-picker {
  width: 100%;
  margin: 6px 0 10px;
  border: 1px solid #273550;
  border-radius: 12px;
  background: #0e1522;
  padding: 8px;
}
.color-picker summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
.color-picker summary::-webkit-details-marker { display: none; }
.color-preview {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid #3b4b66;
  background: var(--swatch-color, #ffffff);
}
.color-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.color-palette-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 4px;
}
.color-swatch {
  aspect-ratio: 1 / 1;
  width: 100%;
  min-width: 0;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: var(--swatch-color, #ffffff);
  padding: 0;
}
.color-swatch:hover { transform: translateY(-1px); }
.color-swatch.selected {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

.timelineviz { margin-top: 8px; }
.timeline-controls { display: flex; gap: 12px; flex-wrap: wrap; }

.track { margin-top: 10px; }
.track-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.track-bar {
  position: relative;
  height: 22px;
  border-radius: 999px;
  background: #0e1522;
  border: 1px solid #243450;
  overflow: hidden;
}
.visual-bar { height: 84px; }
.audio-fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #2c7bff, #5aa3ff); }

.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  white-space: nowrap;
  padding: 6px 2px;
  max-width: 100%;
}
.strip-item {
  flex: 0 0 auto;
  min-width: 64px;
  display: inline-flex;
  flex-direction: column;
  background: #0f172a;
  border: 1px solid #243450;
  border-radius: 12px;
  overflow: hidden;
  cursor: grab;
  position: relative;
}
.strip-item img {
  width: 100%;
  height: 72px;
  object-fit: cover;
  display: block;
}
.strip-title {
  font-size: 10px;
  padding: 6px 8px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-item:hover::after {
  content: attr(data-duration-label);
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 44px;
  padding: 4px 6px;
  font-size: 10px;
  color: white;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 8px;
  text-align: center;
  pointer-events: none;
}

.segment {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border-radius: 12px;
  overflow: hidden;
  background: #1d2b44;
  border: 1px solid rgba(255,255,255,0.08);
}

.segment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}

.segment-label {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 10px;
  background: rgba(10, 11, 17, 0.7);
  padding: 2px 6px;
  border-radius: 8px;
}

.missing-warning { margin-top: 10px; font-size: 12px; }
.missing-warning.warn { color: #ffb3c2; }

.preview {
  position: relative;
  margin: 10px 0;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #22314b;
  background: #0b111d;
  width: min(420px, 100%);
  aspect-ratio: var(--output-ratio, 9 / 16);
}

.preview-media {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  background: #0b111d;
}
.preview .overlay {
  position: absolute;
  left: 60px;
  top: 120px;
  font-family: "DejaVu Sans", "Arial", sans-serif;
  font-weight: 400;
  text-shadow: none;
  pointer-events: none;
  white-space: pre-line;
}

.thumb { width: 100%; border-radius: 12px; margin-top: 10px; border: 1px solid #22314b; }
.render-player {
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid #22314b;
  background: #0b111d;
}

.error { white-space: pre-wrap; background:#0e1522; border:1px solid #3d1a24; color:#ffb3c2; padding:10px; border-radius:10px; overflow:auto; }

details { margin-top: 6px; }
summary { cursor: pointer; }
.hidden { display: none; }
.settings-panel { display: none; }
.settings-panel.is-open { display: block; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .page-title { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 720px) {
  .rowinline { flex-direction: column; }
  .visual-bar { height: 120px; }
  .timeline-controls { flex-direction: column; }
}
