:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --ink: #121826;
  --muted: #5c6376;
  --line: #dfe3ec;
  --accent: #0f9ed5;
  --accent-strong: #0b7fad;
  --radius: 12px;
  --canvas-aspect: 16 / 9;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(15, 158, 213, 0.08), transparent 32%), var(--bg);
  color: var(--ink);
}

.page {
  width: 96%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.back-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 8px 18px -14px rgba(10, 18, 40, 0.4);
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
}

.tab-bar {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 28px -24px rgba(10, 18, 40, 0.4);
  margin-bottom: 14px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 158, 213, 0.22);
}

.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 10px 22px -18px rgba(15, 158, 213, 0.9);
}

.tab-panels {
  display: block;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.lede {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--muted);
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.panel-controls {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 28px -24px rgba(10, 18, 40, 0.45);
}

.panel-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.actions {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

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

.actions-right {
  display: inline-flex;
}

.token-row input {
  min-width: 260px;
}

.field.inline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
}

.aspect-toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: #f1f4f9;
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: 10px;
}

.aspect-toggle label {
  display: inline-flex;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}

.aspect-toggle input {
  display: none;
}

.aspect-toggle span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.aspect-toggle input:checked + span {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 0 0 1px var(--line);
}

.field label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
  resize: none;
  width: 100%;
  min-height: 100px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 158, 213, 0.18);
}

.primary {
  width: fit-content;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 32px -24px rgba(15, 158, 213, 0.9);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 42px -22px rgba(15, 158, 213, 0.95);
}

.secondary {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.1s ease, color 0.1s ease;
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.settings-grid {
  display: grid;
  gap: 14px;
}

.scene-controls .scene-bar {
  display: flex;
  align-items: center;
}

.scene-controls .scene-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-output video {
  max-width: 100%;
  max-height: 65vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px -24px rgba(10, 18, 40, 0.35);
}

.production-wrapper {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  outline: none;
  display: flex;
  justify-content: center;
}

.production-wrapper #productionOutput {
  min-height: auto;
  width: 100%;
}

.export-output {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.export-output:has(.generating-text) {
  align-items: center;
  justify-content: center;
}

.scene-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.scene-form-actions {
  display: flex;
  justify-content: flex-end;
}

.scene-list {
  display: grid;
  gap: 12px;
}

.scene-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 12px 28px -22px rgba(10, 18, 40, 0.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.scene-title {
  margin: 2px 0 4px;
}

.scene-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-line;
}

.scenes-breakdown {
  display: grid;
  gap: 10px;
}

.scene-breakdown-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.breakdown-title {
  font-weight: 600;
  color: var(--ink);
}

.breakdown-count {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.timeline {
  margin-top: 18px;
}

.panel-list {
  display: grid;
  gap: 12px;
  position: relative;
}

.panel-list:not(.empty-state) {
  align-items: start;
}

.panel-list.empty-state {
  grid-template-columns: 1fr;
  justify-items: center;
  align-items: center;
  place-items: center;
}

.panel-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 28px -22px rgba(10, 18, 40, 0.35);
  position: relative;
  overflow: hidden;
}

.panel-card .card-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 50;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius);
}

.panel-card .card-overlay.active {
  display: flex;
}

.panel-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.25);
}

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

.panel-media {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}

.panel-media .canvas-wrap,
.panel-media .image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

.draw-frame {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
}

.draw-frame canvas {
  display: block;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.6);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.overlay-text {
  margin: 0;
  color: #fff;
  font-weight: 700;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(18, 24, 38, 0.3);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
}

.box-icon {
  display: inline-block;
  margin-right: 8px;
}

.generating-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
}

.panel-card.dragging {
  opacity: 0.9;
  box-shadow: 0 20px 40px -18px rgba(10, 18, 40, 0.45);
}

.drag-image {
  opacity: 1;
  box-shadow: 0 20px 40px -18px rgba(10, 18, 40, 0.45);
  border-radius: var(--radius);
}

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

.panel-head:active {
  cursor: grabbing;
}

.head-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-card--draw .head-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "convert convert"
    "duplicate remove";
  width: 100%;
  max-width: 220px;
  justify-items: stretch;
  align-items: stretch;
}

.panel-card--draw .head-actions [data-convert] {
  grid-area: convert;
  width: 100%;
}

.panel-card--draw .head-actions [data-duplicate] {
  grid-area: duplicate;
  width: 100%;
}

.panel-card--draw .head-actions [data-remove] {
  grid-area: remove;
  width: 100%;
  justify-self: end;
}

body[data-aspect="9:16"] .head-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  max-width: 192px;
  justify-content: end;
}

.insert-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 6px 14px -10px rgba(10, 18, 40, 0.35);
  font-size: 16px;
}

.secondary.small {
  padding: 7px 10px;
  font-weight: 600;
}

.secondary.small.square {
  padding: 7px;
  min-width: 32px;
  text-align: center;
}

.panel-head h3 {
  margin: 0;
  letter-spacing: -0.2px;
}

.meta {
  margin: 0;
  color: var(--muted);
}

.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(180deg, #fdfdff 0%, #f5f7fb 100%);
  display: grid;
  gap: 8px;
}

.canvas-wrap.image-mode {
  gap: 8px;
}

.image-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: var(--canvas-aspect);
  display: grid;
  place-items: center;
}

.toolbar-spacer {
  height: 34px;
}

.image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.toolbar > .brush-range {
  margin-right: auto;
}

.toolbar > .clear {
  margin-left: auto;
}

.title-input,
.notes-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.title-input:focus,
.notes-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 158, 213, 0.18);
}

.notes-input {
  resize: none;
  min-height: 80px;
}

.panel-scene-select {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.panel-scene-select label {
  min-width: 50px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}

.scene-select-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.scene-select-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 158, 213, 0.18);
}

.panel-time-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.panel-time-slider label {
  min-width: 90px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}

.time-slider-input {
  flex: 0 0 50%;
  height: 6px;
  border: none;
  border-radius: 3px;
  background: linear-gradient(to right, var(--line), var(--accent));
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.time-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.time-slider-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.color-picker-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #cdd3df;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.color-swatch:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.color-picker-popup {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 10px 28px -18px rgba(10, 18, 40, 0.4);
  z-index: 100;
  min-width: 220px;
}

.color-picker-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.color-slider {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-slider label {
  min-width: 20px;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
}

.color-slider-input {
  flex: 1;
  height: 6px;
  border: none;
  border-radius: 3px;
  background: linear-gradient(to right, #ddd, #999);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.color-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.color-slider-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.color-slider span {
  min-width: 32px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.clear {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

.clear:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.brush-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

canvas {
  width: 100%;
  height: auto;
  aspect-ratio: var(--canvas-aspect);
  min-height: 140px;
  max-height: 520px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  touch-action: none;
}

.remove {
  background: transparent;
  border: 1px solid #f0c7c7;
  color: #b14848;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 600;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: none;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

#productionOutput.empty-state,
#charactersOutput.empty-state {
  border: none;
  background: transparent;
  min-height: auto;
}

.empty-copy {
  margin: 0;
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
  }
}

body[data-aspect="16:9"] {
  --canvas-aspect: 16 / 9;
}

body[data-aspect="9:16"] {
  --canvas-aspect: 9 / 16;
}

body[data-aspect="16:9"] .panel-list:not(.empty-state) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

body[data-aspect="9:16"] .panel-list:not(.empty-state) {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

@media (max-width: 1280px) {
  .panel-list {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
  }

  .panel-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal__dialog {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  max-width: 520px;
  width: min(520px, 100%);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 20px 60px -28px rgba(6, 10, 30, 0.55);
}

.modal__dialog h3 {
  margin: 0 0 12px;
}

.modal__lede {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
}

.modal__textarea {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  margin-top: 6px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
}

.tutorial-steps-dialog {
  max-width: 720px !important;
  width: min(720px, 100%) !important;
  padding: 21.6px !important;
  min-height: auto;
}

.tutorial-step {
  flex: 1;
}

.gap-controls {
  position: absolute;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.gap-controls.active {
  display: flex;
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1.02);
}


.home .page { width: 96%; max-width: 1600px; }

.home-hero { margin-bottom: 16px; }

.project-section { margin-top: 18px; }

.project-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.project-card { position: relative; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 12px 28px -22px rgba(10, 18, 40, 0.35); cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease; }

.project-card:hover { transform: translateY(-2px); box-shadow: 0 16px 36px -22px rgba(10, 18, 40, 0.4); }

.project-thumb { aspect-ratio: 16 / 9; background-size: cover; background-position: center; background-repeat: no-repeat; background-color: #f5f7fb; }
.project-divider { height: 1px; background: var(--line); }

.project-body { padding: 12px; }

.project-title { font-weight: 700; margin: 0 0 4px; }

.project-meta { margin: 0; color: var(--muted); font-size: 13px; }

.delete-project { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #f0c7c7; background: #fff; color: #b14848; font-weight: 700; cursor: pointer; }


.hero-actions { margin-top: 10px; }


.home-bar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 12px 28px -22px rgba(10, 18, 40, 0.35);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.home-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.shopping-section {
  margin-bottom: 16px;
}

.shopping-section:last-child {
  margin-bottom: 0;
}

.shopping-section-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 8px 0;
  color: var(--ink);
}

.shopping-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.shopping-list li {
  padding: 6px 0;
  color: var(--ink);
  font-size: 14px;
}

