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

:root {
  --sidebar-width: 260px;
  --bg: #1a1a1a;
  --sidebar-bg: #111;
  --chat-bg: #1a1a1a;
  --user-msg-bg: #2a2a2a;
  --ai-msg-bg: #1e1e1e;
  --system-msg-bg: #1c1c2e;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #7c8aff;
  --border: #333;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  height: 100%;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow-y: auto;
}

#sidebar h1 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

#chapter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-link {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.chapter-link:hover {
  background: #2a2a2a;
}

.chapter-link.active {
  background: #2a2a2a;
  color: var(--accent);
}

.chapter-link.new {
  animation: flash 0.6s ease-out 2;
}

@keyframes flash {
  0%, 100% { background: transparent; }
  50% { background: rgba(124, 138, 255, 0.2); }
}

/* Chat area */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.5rem 0;
}

#messages {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0 1rem;
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.message .role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.message .bubble {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  line-height: 1.55;
  font-size: 0.9375rem;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--user-msg-bg);
}

.message.ai .bubble {
  background: var(--ai-msg-bg);
  border: 1px solid var(--border);
}

.message.system .bubble {
  background: var(--system-msg-bg);
  border: 1px solid #2a2a40;
  font-style: italic;
}

/* Asset attachments */
.asset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.asset-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  background: #252530;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.asset-chip:hover {
  background: #303040;
}

.asset-chip::before {
  content: "📎";
  font-size: 0.85rem;
}

.asset-image {
  max-width: 100%;
  border-radius: 6px;
  margin-top: 0.4rem;
  border: 1px solid var(--border);
}

/* Scroll anchor (invisible) */
#scroll-anchor {
  height: 1px;
  width: 100%;
}
