:root {
  --bg-deep: #0a0a0b;
  --bg-surface: #141416;
  --bg-elevated: #1c1c1f;
  --bg-card: #222226;
  --border-subtle: #2a2a2f;
  --border-accent: #3d3d44;
  --text-primary: #f0f0f2;
  --text-secondary: #9a9aa0;
  --text-muted: #606066;
  --accent-gold: #d4a853;
  --accent-gold-dim: #a68942;
  --accent-red: #c44;
  --accent-cyan: #4ecdc4;
  --grid-color: #1a1a1d;
  --sidebar-width: 520px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Source Serif 4", Georgia, serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── App Layout: sidebar + hero ── */

.app-layout {
  display: grid;
  grid-template-columns: min(var(--sidebar-width), 38vw) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ── */

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  height: 52px;
  display: flex;
  align-items: center;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}
.sidebar-scroll::-webkit-scrollbar-track {
  background: var(--bg-deep);
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border-accent);
  border-radius: 3px;
}

/* ── Main Output (Hero) ── */

.main-output {
  display: flex;
  flex-direction: column;
  padding: 0;
}

.main-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
  height: 52px;
}

.main-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.main-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.image-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
}

.image-hero .image-preview {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  min-height: 50vh;
}

.main-output .prompt-section {
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.main-output .prompt-section .output-content {
  max-height: 200px;
}

.main-output .history-section {
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
}

/* ── Logo & header ── */

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.logo-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  transition: color 0.2s ease;
}
.logo-back:hover {
  color: var(--text-primary);
}
.logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(
    135deg,
    var(--accent-gold) 0%,
    var(--accent-gold-dim) 100%
  );
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Bebas Neue", sans-serif;
  font-size: 15px;
  color: var(--bg-deep);
  letter-spacing: -1px;
  flex-shrink: 0;
}
.logo-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.logo-text h1 {
  font-family: "Bebas Neue", sans-serif;
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--text-primary);
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
}
.logo-text span {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-family: "JetBrains Mono", monospace;
  line-height: 1;
  white-space: nowrap;
}

/* ── Section Cards ── */

.section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: visible;
  transition: border-color 0.3s ease;
}
.section-header {
  border-radius: 7px 7px 0 0;
}
.section-content:last-child {
  border-radius: 0 0 7px 7px;
}
.section:hover {
  border-color: var(--border-accent);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
.section-number {
  font-family: "Bebas Neue", sans-serif;
  font-size: 14px;
  color: var(--accent-gold);
  background: var(--bg-deep);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.section-title {
  font-family: "Bebas Neue", sans-serif;
  font-size: 16px;
  letter-spacing: 1.5px;
  color: var(--text-primary);
  font-weight: 400;
}
.section-content {
  padding: 16px;
}

/* ── Lit leaf components: transparent to CSS grid layout ── */

segment-editor,
scene-sidebar,
logo-sidebar,
website-sidebar,
illustration-sidebar,
music-sidebar,
color-segment,
history-panel,
settings-modal {
  display: contents;
}

/* ── Segment Editor: Textarea ── */

.segment-textarea {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 10px 12px;
  width: 100%;
  resize: vertical;
  min-height: 60px;
  transition: border-color 0.2s ease;
}
.segment-textarea:focus {
  outline: none;
  border-color: var(--accent-gold);
}
.segment-textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Preset Row ── */

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.preset-btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 5px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.preset-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-accent);
  color: var(--text-primary);
}
.preset-btn.selected {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  background: rgba(212, 168, 83, 0.08);
}

/* ── Image Drop Zone ── */

.image-drop-zone {
  margin-top: 10px;
  padding: 16px;
  border: 2px dashed var(--border-subtle);
  border-radius: 6px;
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-muted);
  transition: all 0.2s ease;
  cursor: pointer;
}
.image-drop-zone:hover,
.image-drop-zone.dragover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  background: rgba(78, 205, 196, 0.04);
}

.drop-zone-types {
  display: block;
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Segment Thumbnails ── */

.segment-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.segment-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.segment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.segment-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(10, 10, 11, 0.8);
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.segment-thumb:hover .segment-thumb-remove {
  display: flex;
}
.segment-thumb-remove:hover {
  color: var(--accent-red);
}

/* ── Color Pickers ── */

.color-pickers {
  display: flex;
  gap: 12px;
  padding: 0 16px 16px;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.color-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 52px;
}

.color-input {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  background: var(--bg-card);
  cursor: pointer;
  flex-shrink: 0;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-input::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.color-hex {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

/* ── Add / Remove Instance Buttons ── */

.segment-add-btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--accent-cyan);
  background: transparent;
  border: 1px dashed var(--border-subtle);
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100%;
}
.segment-add-btn:hover {
  border-color: var(--accent-cyan);
  background: rgba(78, 205, 196, 0.04);
}

.segment-remove-btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 4px 12px;
  cursor: pointer;
  transition: color 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  align-self: flex-end;
}
.segment-remove-btn:hover {
  color: var(--accent-red);
}

/* ── Output Sections ── */

.output-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
}
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
.output-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.output-header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.output-title {
  font-family: "Bebas Neue", sans-serif;
  font-size: 16px;
  letter-spacing: 1.5px;
  color: var(--text-primary);
}
.output-badge {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--accent-gold);
  background: rgba(212, 168, 83, 0.15);
  padding: 3px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

/* ── Buttons ── */

.copy-btn,
.download-btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.copy-btn:hover,
.download-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-accent);
  color: var(--text-primary);
}
.copy-btn.copied {
  background: rgba(78, 205, 196, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.copy-btn svg {
  display: inline-block;
  vertical-align: -2px;
  margin-right: 4px;
}
.hidden {
  display: none;
}

.generate-btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--bg-deep);
  background: var(--accent-gold);
  border: 1px solid var(--accent-gold);
  padding: 8px 24px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
}
.generate-btn:hover {
  background: var(--accent-gold-dim);
  border-color: var(--accent-gold-dim);
}
.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.generate-btn svg {
  display: inline-block;
  vertical-align: -2px;
  margin-right: 4px;
}

/* ── Image ── */

.image-preview {
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}
.image-empty {
  text-align: center;
  color: var(--text-muted);
}
.image-empty p {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}
.image-result {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

/* Loading indicator */
.generating-indicator {
  text-align: center;
  color: var(--accent-cyan);
}
.generating-indicator p {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  margin-top: 16px;
}
.generating-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Status */
.image-status {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.image-status.status-error {
  color: var(--accent-red);
}
.image-status.status-generating {
  color: var(--accent-cyan);
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
.image-status.status-generating::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent-cyan);
  border-radius: 50%;
  margin-left: 8px;
  vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}

/* ── History ── */

.history-grid {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.history-card {
  position: relative;
  flex: 0 0 140px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  scroll-snap-align: start;
}
.history-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-2px);
}
.history-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}
.history-meta {
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
}
.history-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(10, 10, 11, 0.7);
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.history-card:hover .history-delete {
  display: flex;
}
.history-delete:hover {
  color: var(--accent-red);
  background: rgba(10, 10, 11, 0.9);
}

/* ── Param fields (settings modal) ── */

.param-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.param-field label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.param-field input,
.param-field select {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: var(--text-primary);
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 12px;
  transition: border-color 0.2s ease;
  width: 100%;
}
.param-field input:focus,
.param-field select:focus {
  outline: none;
  border-color: var(--accent-gold);
}
.param-field select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239a9aa0' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.output-content {
  padding: 20px;
  max-height: 400px;
  overflow-y: auto;
}
.output-content pre {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Modal ── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.is-open {
  display: flex;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  width: 100%;
  max-width: 440px;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
  font-family: "Bebas Neue", sans-serif;
  font-size: 18px;
  letter-spacing: 1.5px;
  color: var(--text-primary);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text-primary);
}
.modal-body {
  padding: 20px;
}
.modal-body .param-field {
  margin-bottom: 16px;
}
.modal-warning {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: rgba(212, 168, 83, 0.08);
  border-left: 2px solid var(--accent-gold-dim);
  border-radius: 0 4px 4px 0;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-top: 20px;
}

/* ── Settings key display ── */

.settings-key-display {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}

/* ── Animations ── */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.section {
  animation: fadeIn 0.4s ease backwards;
}
.section:nth-child(1) {
  animation-delay: 0.05s;
}
.section:nth-child(2) {
  animation-delay: 0.1s;
}
.section:nth-child(3) {
  animation-delay: 0.15s;
}
.section:nth-child(4) {
  animation-delay: 0.2s;
}
.section:nth-child(5) {
  animation-delay: 0.25s;
}

/* ── Responsive: stack on mobile ── */

@media (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .sidebar-scroll {
    max-height: none;
    overflow-y: visible;
  }
  .main-toolbar {
    padding: 16px 20px;
  }
  .image-hero .image-preview {
    padding: 24px;
    min-height: 300px;
  }
}

@media (max-width: 768px) {
  .main-toolbar {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .history-card {
    flex: 0 0 120px;
  }
  .history-thumb {
    height: 80px;
  }
}

@media (max-width: 600px) {
  .modal {
    margin: 16px;
  }
  .logo-text span {
    display: none;
  }
}
