:root {
  --cream: #FFF6E8;
  --cream-dark: #F6E7CF;
  --white: #FFFDF8;
  --coral: #FF6B4A;
  --coral-dark: #D94A2B;
  --teal: #1B9AAA;
  --teal-soft: #E0F5F7;
  --abyss: #12233D;
  --yellow: #FFD166;
  --yellow-soft: #FFF1C9;
  --blue: #38BDF8;
  --ink: #1E1B2E;
  --ink-muted: #534D66;
  --border: 3px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--cream);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}

/* Subtle Editorial Cartoon Halftone Paper Grain */
.bg-halftone {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.28;
  background-image: radial-gradient(rgba(30, 27, 46, 0.16) 1.1px, transparent 1.1px);
  background-size: 16px 16px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--cream);
  border-bottom: var(--border);
}

.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.mascot-badge {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: var(--yellow);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: mascotFloat 3.6s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-3px) rotate(1.5deg); }
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

h1, h2, h3 {
  font-family: 'Fredoka', cursive, sans-serif;
  margin: 0;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 1.55rem;
  line-height: 1.1;
}

h2 {
  font-size: 1.16rem;
}

h3 {
  font-size: 1.02rem;
}

.brand-sub {
  margin: 3px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-weight: 600;
}

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

/* Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  font-family: 'Fredoka', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 2px 2px 0 var(--ink);
}

.pill-yellow { background: var(--yellow); }
.pill-cream { background: var(--white); }

.hint-badge {
  font-size: 0.76rem;
  font-weight: 800;
  background: var(--coral);
  color: var(--white);
  padding: 4px 10px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
}

.duration-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--abyss);
  color: var(--yellow);
  padding: 5px 11px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.78rem;
  border-width: 2.5px;
  box-shadow: 2px 2px 0 var(--ink);
}

.btn-cream { background: var(--white); }
.btn-cream:hover:not(:disabled) { background: var(--cream-dark); }
.btn-coral { background: var(--coral); color: var(--white); }
.btn-coral:hover:not(:disabled) { background: var(--coral-dark); }
.btn-yellow { background: var(--yellow); }
.btn-yellow:hover:not(:disabled) { background: #ffc43d; }
.btn-teal { background: var(--teal); color: var(--white); }
.btn-teal:hover:not(:disabled) { background: #158290; }

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2.5px solid var(--ink);
  background: var(--white);
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 0 var(--ink);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #cbd5e1;
  border: 2px solid var(--ink);
}

.status-dot.connected {
  background: #22c55e;
}

/* Workspace Layout */
.workspace {
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 22px 48px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 22px;
  align-items: start;
}

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

.sticky-panel {
  position: sticky;
  top: 94px;
}

/* Cards */
.card {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-yellow-tint { background: var(--yellow-soft); }
.card-teal-tint { background: var(--teal-soft); }
.card-output { background: var(--white); }

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

.card-desc {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.small-note {
  margin: 2px 0 0;
  font-size: 0.77rem;
  color: var(--ink-muted);
}

/* Presets */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preset-btn {
  text-align: left;
  padding: 11px 13px;
  border-radius: 13px;
  border: 2.5px solid var(--ink);
  background: var(--white);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.preset-btn:hover {
  transform: translate(-1px, -1px);
  background: var(--cream);
}

.preset-btn.active {
  background: var(--coral);
  color: var(--white);
}

.preset-btn.active .preset-sub {
  color: #ffe8e2;
}

.preset-title {
  display: block;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.96rem;
  font-weight: 600;
}

.preset-sub {
  display: block;
  font-size: 0.76rem;
  color: var(--ink-muted);
  margin-top: 2px;
  font-weight: 600;
}

/* Idea Row */
.idea-row {
  margin-bottom: 10px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Form Elements */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1.3fr 0.75fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field > span, .field-label {
  font-size: 0.79rem;
  font-weight: 800;
  color: var(--ink);
}

.input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 11px;
  border: 2.5px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.87rem;
  font-weight: 600;
  outline: none;
  transition: box-shadow 0.12s ease, background-color 0.12s ease;
}

.input:focus {
  box-shadow: 3px 3px 0 var(--teal);
  background: #ffffff;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.81rem;
}

.textarea-sm {
  resize: vertical;
  min-height: 62px;
}

/* Palette Selector */
.palette-section {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 2px dashed rgba(30, 27, 46, 0.25);
}

.palette-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

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

.palette-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: var(--cream);
  cursor: pointer;
  text-align: left;
  box-shadow: 2px 2px 0 var(--ink);
}

.palette-card.active {
  background: var(--yellow);
  box-shadow: 3px 3px 0 var(--ink);
}

.palette-name {
  font-weight: 800;
  font-size: 0.8rem;
}

.swatches {
  display: flex;
  gap: 4px;
}

.swatch {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

/* Scenes List */
.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.scene-card {
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 13px;
  box-shadow: 3px 3px 0 var(--ink);
}

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

.scene-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scene-num {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--ink);
  color: var(--yellow);
  padding: 3px 9px;
  border-radius: 999px;
}

.scene-timing {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--white);
  border: 2px solid var(--ink);
  padding: 2px 8px;
  border-radius: 999px;
}

.scene-remove-btn {
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--coral-dark);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
}

.scene-remove-btn:hover {
  background: #ffe2dc;
}

.scene-meta-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.65fr 1fr;
  gap: 9px;
}

.scene-card .field {
  margin-bottom: 9px;
}

.scene-card .field:last-child {
  margin-bottom: 0;
}

/* Output Panel */
.output-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.output-sub {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.tabs-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 7px 5px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.1s ease, background-color 0.12s ease;
}

.tab-btn:hover {
  transform: translateY(-1px);
}

.tab-btn.active {
  background: var(--coral);
  color: var(--white);
}

.tab-btn.tab-tts.active {
  background: var(--teal);
  color: var(--white);
}

.tab-btn.completed {
  border-color: #15803d;
}

.tab-step {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  border: 2px solid var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.72rem;
}

.tab-btn.completed .tab-step {
  background: #4ade80;
}

.stage-banner {
  background: var(--yellow-soft);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.81rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.code-shell {
  border: var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--abyss);
  box-shadow: 3px 3px 0 var(--ink);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: #0c192d;
  border-bottom: 2.5px solid var(--ink);
  flex-wrap: wrap;
}

.code-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cmd-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--yellow);
  color: var(--ink);
  padding: 3px 8px;
  border-radius: 7px;
  border: 2px solid var(--ink);
}

.char-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: #94a3b8;
}

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

.done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #e2e8f0;
  cursor: pointer;
}

.done-toggle input {
  accent-color: #4ade80;
  width: 15px;
  height: 15px;
}

.code-output {
  margin: 0;
  padding: 14px;
  max-height: 490px;
  overflow: auto;
  color: #f8fafc;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.workflow-tip {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--teal-soft);
  border: 2px solid var(--ink);
  font-size: 0.79rem;
  font-weight: 600;
}

/* TTS Panel */
.tts-box {
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 13px;
  padding: 12px;
  margin-bottom: 11px;
}

.tts-box-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.tts-script-preview {
  margin: 0;
  padding: 11px 12px;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 280px;
  overflow: auto;
}

.tts-checklist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--yellow-soft);
  border: 2.5px solid var(--ink);
  font-size: 0.79rem;
}

.tts-checklist-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tts-checklist code {
  background: var(--white);
  padding: 1px 5px;
  border-radius: 5px;
  border: 1.5px solid var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 35, 61, 0.62);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  overflow: auto;
  background: var(--cream);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 18px;
}

.modal-sm {
  max-width: 480px;
}

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

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 12px 0;
}

.library-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--white);
  border: 2.5px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.library-item-meta strong {
  display: block;
  font-size: 0.9rem;
}

.library-item-meta span {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.library-item-actions {
  display: flex;
  gap: 6px;
}

/* Toast */
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  background: var(--abyss);
  color: var(--yellow);
  border: var(--border);
  border-radius: 13px;
  padding: 10px 16px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sticky-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .form-grid-2, .form-grid-3, .scene-meta-grid, .preset-grid, .palette-grid {
    grid-template-columns: 1fr;
  }
  .tabs-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
