:root {
  --bg: #0f1115;
  --panel: #17191f;
  --bubble-bot: #1f2733;
  --bubble-voice: #2a2032;
  --accent: #4da3ff;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

#header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid #22252c;
  font-weight: 600;
  flex: 0 0 auto;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 4px 8px;
  cursor: pointer;
}

.screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

#chapterList {
  overflow-y: auto;
  padding: 12px;
  gap: 10px;
  display: flex;
}
#chapterList[hidden] { display: none; }

.chapter-card {
  display: flex;
  gap: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  border: 1px solid #22252c;
  align-items: center;
}
.chapter-card:active { background: #1c1f27; }
.chapter-cover {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: #2a2d35 center/cover no-repeat;
  flex: 0 0 auto;
}
.chapter-info { flex: 1 1 auto; min-width: 0; }
.chapter-title { font-weight: 600; font-size: 15px; }
.chapter-meta { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.chapter-lock { font-size: 12px; color: #e0b84d; }

#chat[hidden] { display: none; }

#messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  background: var(--bubble-bot);
  line-height: 1.4;
  font-size: 15px;
  white-space: pre-wrap;
  animation: pop .18s ease-out;
}
.bubble.voice { background: var(--bubble-voice); font-style: italic; }
.bubble.system { align-self: center; background: none; color: var(--text-dim); font-size: 13px; text-align: center; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #05131f; border-bottom-left-radius: var(--radius); border-bottom-right-radius: 4px; }

.bubble-photo { max-width: 82%; border-radius: var(--radius); overflow: hidden; animation: pop .18s ease-out; }
.bubble-photo img { width: 100%; display: block; }
.bubble-photo figcaption { padding: 8px 12px; font-size: 13px; color: var(--text-dim); background: var(--bubble-bot); }

@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.typing { align-self: flex-start; color: var(--text-dim); font-size: 13px; padding: 4px 4px; }

#composer {
  flex: 0 0 auto;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #22252c;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-actions[hidden] { display: none; }

.chip {
  background: #232733;
  color: var(--text);
  border: 1px solid #2d323f;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip:active { background: #2a2f3c; }

.input-bar { display: flex; gap: 8px; }
.input-bar[hidden] { display: none; }

#textInput {
  flex: 1 1 auto;
  background: #1c1f27;
  border: 1px solid #2d323f;
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.primary-btn {
  background: var(--accent);
  color: #05131f;
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary-btn.small { flex: 0 0 auto; width: 46px; padding: 0; height: 46px; }
.primary-btn.secondary { background: #232733; color: var(--text); }

#doneBar { flex-direction: row; }
