:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --border-subtle: #21262d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #f0c060;
  --accent-dim: #2d1f00;
  --accent-text: #f0a030;
  --green: #56d364;
  --green-dim: #1f3f1f;
  --red: #f85149;
  --sidebar-w: 260px;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* Layout */
#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-logo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

#session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  flex-shrink: 0;
}

#main {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Session cards in sidebar */
.session-card {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.session-card:hover { background: var(--surface2); }
.session-card.active { background: var(--surface2); border-color: var(--accent); }
.session-card .session-title { font-weight: 600; font-size: 0.88rem; }
.session-card .session-meta { font-size: 0.73rem; color: var(--text-secondary); margin-top: 2px; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border: none;
  padding: 7px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}

/* Forms */
input, textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label { font-size: 0.78rem; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.form-group { margin-bottom: 12px; }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }

/* Session workspace */
.workspace-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  flex-shrink: 0;
}
.workspace-header h2 { font-size: 1rem; font-weight: 700; }
.genre-badge {
  font-size: 0.72rem;
  background: var(--accent-dim);
  color: var(--accent-text);
  padding: 2px 8px;
  border-radius: 10px;
}
.workspace-header .meta { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab {
  padding: 10px 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { padding: 16px 20px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.card-title { font-weight: 600; font-size: 0.88rem; }
.card-meta { font-size: 0.73rem; color: var(--text-secondary); margin-top: 3px; }
.card-body { font-size: 0.8rem; color: var(--text-secondary); margin-top: 6px; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }

/* Traits */
.traits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.trait {
  background: var(--surface2);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
}

/* Context pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  color: var(--accent-text);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  margin: 2px;
}
.pill .remove { cursor: pointer; opacity: 0.6; font-size: 0.9em; }
.pill .remove:hover { opacity: 1; }
.pills-container { display: flex; flex-wrap: wrap; margin-bottom: 10px; }

/* Plot hooks */
.hook-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.85rem;
}
.hook-card:hover { border-color: var(--accent); background: var(--surface2); }
.hook-num { font-weight: 700; color: var(--accent-text); margin-right: 4px; }

/* Story streaming display */
.story-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.88rem;
  line-height: 1.75;
  color: #c9d1d9;
  max-height: 50vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  vertical-align: middle;
  animation: blink 0.8s infinite;
}
.stream-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}
.dot-live { width: 8px; height: 8px; background: var(--green); border-radius: 50%; animation: pulse 1s infinite; }
.word-count { color: var(--text-muted); margin-left: auto; }

/* Paragraph-based story display */
.story-display-paras { white-space: normal; }
.story-paragraphs { display: flex; flex-direction: column; gap: 0; }

.story-para {
  position: relative;
  padding: 4px 4px 4px 22px;
  border-radius: 4px;
  margin-bottom: 0.9em;
  line-height: 1.75;
  transition: background 0.15s;
}
.story-para:last-child { margin-bottom: 0; }

.para-play-btn {
  position: absolute;
  left: 2px;
  top: 5px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.65rem;
  padding: 2px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  line-height: 1;
}
.story-para:hover .para-play-btn { opacity: 0.5; }
.para-play-btn:hover { opacity: 1 !important; color: var(--accent); }

.para-active {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
  padding-left: 20px;
}
.para-active .para-play-btn { opacity: 0.4; }

/* Toast notifications */
.tts-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.82rem;
  color: var(--text);
  z-index: 9999;
  transition: opacity 0.4s;
  max-width: 80vw;
  text-align: center;
  pointer-events: none;
}
.tts-toast-error { border-color: var(--red); color: var(--red); }

/* Audio player */
.audio-player {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
}
.audio-controls { display: flex; align-items: center; gap: 12px; }
.play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #0d1117;
  transition: opacity 0.15s;
}
.play-btn:hover { opacity: 0.85; }
.play-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.scrubber-wrap { flex: 1; }
.scrubber {
  position: relative;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
  margin-bottom: 5px;
}
.scrubber-fill { height: 100%; background: var(--accent); border-radius: 2px; pointer-events: none; }
.scrubber-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
}
.time-display { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-muted); }
.voice-selector { margin-bottom: 10px; }

/* Welcome screen */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-secondary);
}
#welcome-screen h2 { color: var(--text); }

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#modal-overlay.hidden { display: none; }
#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
#modal h3 { margin-bottom: 16px; }

/* Word count slider */
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type=range] {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0;
  accent-color: var(--accent);
}
.slider-row input[type=number] { width: 80px; flex: none; text-align: center; }

/* Workspace layout (main area) */
.workspace { display: flex; flex-direction: column; height: 100%; }
.workspace-body { flex: 1; overflow-y: auto; }

/* Utility */
.hidden { display: none !important; }
.flex-row { display: flex; gap: 8px; align-items: center; }
.flex-end { justify-content: flex-end; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.text-muted { color: var(--text-muted); font-size: 0.8rem; }
.section-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 32px 16px; font-size: 0.85rem; }

/* Animations */
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Mobile */
@media (max-width: 640px) {
  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #app { flex-direction: column; }
  #main { height: auto; overflow-y: visible; }
  body { overflow-y: auto; }
}
