:root {
  --bg: #0b0d16;
  --panel: #141826;
  --panel-2: #1b2032;
  --border: #2a3145;
  --text: #e8ecf5;
  --muted: #8a93a8;
  --accent: #ffb43c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14px;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: 260px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); padding: 18px 16px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand-mark {
  font-size: 26px; color: var(--accent);
  background: rgba(255,180,60,.12); width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 900; letter-spacing: 1px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.sidebar-label { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 1px; margin: 20px 0 10px; }

.series-list { display: flex; flex-direction: column; gap: 10px; }
.series-card {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px;
  cursor: pointer; border: 1px solid var(--border); background: var(--panel-2);
  transition: transform .12s, border-color .12s;
}
.series-card:hover { transform: translateY(-1px); }
.series-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.series-emoji { font-size: 24px; width: 46px; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.series-name { font-weight: 700; }
.series-count { color: var(--muted); font-size: 12px; }

.saved-list { display: flex; flex-direction: column; gap: 8px; }
.saved-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.saved-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.saved-actions { display: flex; gap: 6px; }
.saved-actions button { font-size: 11px; padding: 4px 10px; }
.empty-note { color: var(--muted); font-size: 12px; font-style: italic; }
.side-editor {
  margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,.03);
}
.side-editor summary, .content-editor summary {
  cursor: pointer; color: var(--text); font-size: 13px; font-weight: 700;
}
.compact-field { margin-top: 10px; margin-bottom: 10px; }
.full-btn { width: 100%; }

/* Main */
#main { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.series-title { font-size: 18px; font-weight: 800; }
.ui-lang { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

#workspace { display: grid; grid-template-columns: 320px 1fr; gap: 18px; padding: 18px 24px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.panel h3 { margin: 0 0 16px; font-size: 15px; }
.panel h4 { margin: 0 0 12px; font-size: 13px; color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field span { font-weight: 600; }
select, input[type=text], input[type=url], input[type=password], textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; font-family: inherit; width: 100%;
}
textarea { resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }
output { color: var(--accent); font-weight: 700; }

.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; cursor: pointer; font-weight: 700; }
.segmented button.active { background: var(--accent); color: #241400; border-color: var(--accent); }

.content-editor, .ai-config { margin-bottom: 14px; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: rgba(255,255,255,.02); }
.model-custom { margin-top: 8px; }
.story-suggestions { display: grid; gap: 8px; margin: -2px 0 12px; }
.story-suggestions .btn { text-align: left; padding: 8px 10px; font-size: 12px; }
.worker-note { margin: 10px 0 2px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.hidden { display: none; }

button.btn, button.btn-primary {
  border: none; border-radius: 10px; cursor: pointer; font-weight: 700; font-family: inherit;
}
.btn-primary {
  width: 100%; padding: 13px; font-size: 15px;
  background: linear-gradient(45deg, #ff8c00, var(--accent)); color: #241400;
  box-shadow: 0 8px 26px rgba(255,160,0,.35);
}
.btn-primary:hover { filter: brightness(1.05); }
.html-primary { margin-top: 10px; background: linear-gradient(45deg, #38bdf8, #7dd3fc); color: #082f49; box-shadow: 0 8px 26px rgba(56,189,248,.25); }
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); padding: 10px 14px; font-size: 13px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.gen-status { margin-top: 10px; font-size: 13px; color: var(--accent); min-height: 18px; text-align: center; }

/* Stage */
.stage-wrap {
  position: relative; margin: 0 auto; background: #050505; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
}
.stage-wrap.aspect-16-9 { width: 100%; aspect-ratio: 16/9; }
.stage-wrap.aspect-9-16 { width: auto; height: 60vh; aspect-ratio: 9/16; }
canvas#renderStage { width: 100%; height: 100%; display: block; }
.stage-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--muted); }
.stage-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* Script view */
#script-panel { margin: 0 24px 24px; }
.script-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.script-head h3 { margin: 0; }
.script-meta { color: var(--muted); font-size: 12px; }
.script-view { display: flex; flex-direction: column; gap: 10px; }
.scene-row { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.scene-row.playing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.scene-name { font-weight: 700; color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.scene-narration { font-size: 13px; line-height: 1.5; }
.scene-tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; background: rgba(255,255,255,.06); padding: 2px 8px; border-radius: 20px; color: var(--muted); }

.playhead { margin-top: 8px; height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.playhead > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

@media (max-width: 900px) {
  #workspace { grid-template-columns: 1fr; }
  #sidebar { width: 210px; }
}
