:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-strong: #eef2f7;
  --accent: #6bd3b0;
  --accent-strong: #48b892;
  --text: #0f172a;
  --muted: #4b5563;
  --border: #d9e1ec;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  font-family: "Space Grotesk", "Work Sans", sans-serif;
  color: var(--text);
}

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

body {
  margin: 0;
  background: radial-gradient(120% 140% at 10% 10%, rgba(104, 188, 255, 0.18), transparent),
    radial-gradient(90% 130% at 85% 0%, rgba(107, 211, 176, 0.16), transparent),
    var(--bg);
  min-height: 100vh;
}

.app-shell {
  max-width: 1560px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.brand h1 {
  margin: 0;
  font-size: 22px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
}

.brand-logo {
  width: 44px;
  height: 44px;
}

.icon-step {
  vertical-align: middle;
  font-size: 22px;
  margin-right: 6px;
  color: var(--accent-strong);
}

/* status block removed */

input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}

.api-keys {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.9);
}

.api-keys-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-keys-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 420px;
}

.api-keys-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
}

.api-keys-header input {
  background: var(--panel-strong);
}

input,
select {
  width: 100%;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}

textarea {
  width: 100%;
  min-height: 230px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  resize: vertical;
  color: #111827;
}

.shot-edit.editing {
  color: var(--text);
}

.shot-edit.readonly {
  color: rgba(15, 23, 42, 0.65);
}

.warning {
  color: #ffb4b4;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.35);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #0b1b12;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(72, 184, 146, 0.22);
}

button.ghost {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
}

.ghost.danger {
  border-color: rgba(239, 68, 68, 0.6);
  color: #b91c1c;
  background: rgba(255, 255, 255, 0.85);
}

.ghost.danger:hover {
  background: #ef4444;
  color: #fff;
  border-color: #dc2626;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:not(:disabled):active {
  transform: translateY(1px);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
  color: var(--muted);
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-top: 28px;
}

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

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

h2 {
  margin: 4px 0;
  font-size: 20px;
}

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

.small {
  font-size: 13px;
}

.session-pill {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

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

.two-cols {
  grid-template-columns: 2fr 1fr;
}

.three-cols {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.two-cols-tight {
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 14px;
}

.three-wide {
  grid-template-columns: repeat(3, minmax(420px, 1fr));
  gap: 20px;
}

#shot-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 1100px) {
  .shot-grid-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .adder-fab {
    left: -12px;
  }

  .adder-end {
    right: -12px;
  }
}

@media (max-width: 760px) {
  .shot-grid-row {
    grid-template-columns: 1fr;
  }

  .adder-fab {
    left: -10px;
  }

  .adder-end {
    right: -10px;
  }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.style-option {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  color: var(--text);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.style-option:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 16px 36px rgba(72, 184, 146, 0.2);
}

.style-option.selected {
  border: 2px solid rgba(72, 184, 146, 0.95);
  box-shadow: 0 12px 28px rgba(72, 184, 146, 0.28);
  background: linear-gradient(135deg, rgba(124, 231, 198, 0.18), rgba(112, 190, 255, 0.12));
}

.style-option span {
  font-weight: 600;
}

.style-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.style-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gap-lg {
  gap: 20px;
}

.empty-state {
  text-align: left;
}

.card {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}

.scene-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(248, 250, 252, 0.8);
  margin-bottom: 14px;
}

.scene-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.shot-grid-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  grid-auto-rows: auto;
  position: relative;
}

.shot-card-wrap {
  position: relative;
  display: grid;
}

.adder-card {
  border: 1px dashed var(--border);
  background: rgba(248, 250, 252, 0.9);
  color: var(--text);
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 220px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.adder-card:hover {
  border-color: var(--accent);
  background: rgba(107, 211, 176, 0.12);
  transform: translateY(-1px);
}

.adder-fab {
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, opacity 0.12s ease;
  opacity: 0.7;
  z-index: 2;
}

.adder-fab:hover {
  border-color: var(--accent);
  background: rgba(107, 211, 176, 0.22);
  transform: translate(-50%, -50%) scale(1.02);
  opacity: 1;
}

.adder-fab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.adder-fab .adder-plus {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.adder-end {
  position: absolute;
  right: -16px;
  top: 12px;
}

.card h3 {
  margin: 0;
  font-size: 16px;
}

.loading-inline {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.loading-inline::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  animation: bounce-dots 1s infinite ease-in-out;
}

.loading-inline:empty::after {
  content: "";
  box-shadow: none;
  width: 0;
  height: 0;
  animation: none;
}

@keyframes bounce-dots {
  0% {
    transform: translateY(0);
    box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  }
  20% {
    transform: translateY(-6px);
    box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  }
  40% {
    transform: translateY(0);
    box-shadow: 18px -6px 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  }
  60% {
    transform: translateY(0);
    box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px -6px 0 rgba(124, 231, 198, 0.55);
  }
  80% {
    transform: translateY(-3px);
    box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  }
  100% {
    transform: translateY(0);
    box-shadow: 18px 0 0 rgba(124, 231, 198, 0.85), 36px 0 0 rgba(124, 231, 198, 0.55);
  }
}

/* Desktop-only adjustments */
@media (min-width: 1024px) {
  #script-input {
    min-height: 450px;
  }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .api-keys-header {
    min-width: 100%;
    width: 100%;
    gap: 12px;
  }
  .api-keys-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}
.skeleton {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(124, 231, 198, 0.12), rgba(112, 190, 255, 0.12));
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(120%);
  }
}

@keyframes pulse {
  0% {
    opacity: 0.55;
    transform: scale(0.98);
  }
  50% {
    opacity: 1;
    transform: scale(1.01);
  }
  100% {
    opacity: 0.55;
    transform: scale(0.98);
  }
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(107, 125, 146, 0.12);
  color: var(--muted);
  font-size: 12px;
}

.image-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  position: relative;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(107, 211, 176, 0.18), rgba(104, 188, 255, 0.16));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.image-frame.loading {
  background: linear-gradient(135deg, rgba(107, 211, 176, 0.28), rgba(104, 188, 255, 0.24));
  border-color: rgba(72, 184, 146, 0.65);
}

.image-frame.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: shimmer 0.9s ease-in-out infinite;
}

.image-frame.loading::before {
  content: "Generating…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #0b1b12;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-shadow: 0 2px 8px rgba(255, 255, 255, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
}

.image-frame.portrait {
  aspect-ratio: 9 / 16;
}

.image-frame.shot-lg {
  aspect-ratio: 16 / 9;
  min-height: 0;
}

.image-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.image-wrapper {
  position: relative;
}

.image-wrapper:hover .image-actions {
  opacity: 1;
}

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.icon-btn:hover {
  background: linear-gradient(135deg, rgba(186, 123, 255, 0.9), rgba(124, 231, 198, 0.9));
  color: #041012;
  box-shadow: 0 8px 18px rgba(186, 123, 255, 0.25);
  transform: translateY(-1px);
}

.glyph {
  line-height: 1;
}

.image-frame:hover {
  cursor: pointer;
}

.tooltip {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(130deg, rgba(186, 123, 255, 0.9), rgba(107, 211, 176, 0.9));
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: #0b1b12;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(186, 123, 255, 0.3);
}

.image-wrapper:hover .tooltip {
  opacity: 1;
}

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

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(720px, 90vw);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-backdrop.show {
  display: flex;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
}

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

.card pre {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  max-height: 220px;
  overflow: auto;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor textarea {
  min-height: 90px;
}

.footer {
  margin-top: 32px;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.toast.error {
  border-color: rgba(255, 107, 107, 0.4);
  color: #ffb4b4;
}

.toast.hidden {
  display: none;
}

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}

.lightbox-backdrop.show {
  display: flex;
}

.lightbox {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
}

.lightbox img {
  width: 100%;
  height: auto;
  max-height: 92vh;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: block;
}

.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  background: rgba(0, 0, 0, 0.7);
}

.lightbox-close:hover {
  background: linear-gradient(135deg, rgba(186, 123, 255, 0.9), rgba(124, 231, 198, 0.9));
}

@media (max-width: 820px) {
  .two-cols {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
  }
}
/* Better circular connector button */
.adder-fab {
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  opacity: 0.9;
  z-index: 2;

  /* override previous layout stuff */
  display: inline-block;
  padding: 0;

  /* small visual improvement */
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

/* perfectly centered plus, drawn as two bars */
.adder-fab::before,
.adder-fab::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent-strong);
  border-radius: 999px;
}

.adder-fab::before {
  width: 14px;
  height: 2px;
}

.adder-fab::after {
  width: 2px;
  height: 14px;
}

/* hover state, still scaling from center */
.adder-fab:hover {
  border-color: var(--accent);
  background: rgba(107, 211, 176, 0.12);
  transform: translate(-50%, -50%) scale(1.05);
  opacity: 1;
}

/* hide the text "+" but keep it for screen readers */
.adder-fab .adder-plus {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
