/* ---- base ---- */
:root {
  --ink: #2b2b33;
  --muted: #6d6d7a;
  --paper: #faf7f2;
  --card: #ffffff;
  --accent: #4f6df5;
  --accent-ink: #ffffff;
  --line: #e6e1d8;
  --user-bubble: #4f6df5;
  --assistant-bubble: #ffffff;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
main { max-width: 780px; margin: 0 auto; padding: 1rem 1rem 6rem; }
h1, h2 { font-weight: 700; }
img { max-width: 100%; }

/* ---- nav ---- */
.topnav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.nav-links { display: flex; gap: 0.8rem; align-items: center; }
.nav-links a { color: var(--ink); text-decoration: none; }
.inline-form { display: inline; }
.lang-switcher { display: inline-flex; gap: 0.5rem; font-size: 0.85rem; }
.lang-switcher a { color: var(--muted); text-decoration: underline; }
.lang-current { color: var(--ink); font-weight: 600; }

/* ---- buttons ---- */
.btn {
  display: inline-block; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 999px; padding: 0.45rem 1rem;
  font-size: 0.95rem; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-small { padding: 0.25rem 0.7rem; font-size: 0.85rem; }
.btn-large { padding: 0.8rem 1.6rem; font-size: 1.1rem; }

/* ---- chat ---- */
.chat-shell { display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 1rem; }
#chat-log { display: flex; flex-direction: column; gap: 0.6rem; }
.bubble {
  max-width: 85%; padding: 0.7rem 1rem; border-radius: var(--radius);
  line-height: 1.45; white-space: normal; box-shadow: 0 1px 2px rgb(0 0 0 / 6%);
}
.bubble.user { align-self: flex-end; background: var(--user-bubble); color: white; }
.bubble.assistant { align-self: flex-start; background: var(--assistant-bubble); border: 1px solid var(--line); }
.bubble.streaming:empty { display: none; }
.action-chip {
  align-self: center; background: #eef1fb; color: var(--muted);
  border-radius: 999px; padding: 0.25rem 0.9rem; font-size: 0.85rem;
}
.status-line { min-height: 1.2rem; color: var(--muted); font-size: 0.9rem; padding-left: 0.4rem; }
.status-line .stop-turn { margin-left: 0.6rem; }
.status-text::after { content: ""; animation: dots 1.2s infinite; }
@keyframes dots { 0% { content: ""; } 33% { content: "."; } 66% { content: ".."; } 100% { content: "..."; } }

.chat-form {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 0.8rem 1rem;
  background: var(--card); border-top: 1px solid var(--line);
}
.chat-input-row { display: flex; gap: 0.5rem; width: 100%; max-width: 720px; }
.chat-input-row textarea {
  flex: 1;
  padding: 0.6rem 1rem; border: 1px solid var(--line); border-radius: 18px; font-size: 1rem;
  font-family: inherit; line-height: 1.45; resize: none; overflow: hidden;
  min-height: 2.6rem; max-height: 12rem;
}
.chat-input-row button { border-radius: 18px; }

/* ---- quote-to-reply ---- */
#quote-tool {
  position: absolute; z-index: 30;
  background: #2f2f38; color: #fff; border: none; border-radius: 8px;
  padding: 0.4rem 0.9rem; font-size: 0.9rem; cursor: pointer;
  box-shadow: 0 3px 10px rgb(0 0 0 / 25%);
}
.quote-preview {
  display: flex; align-items: flex-start; gap: 0.5rem;
  width: 100%; max-width: 720px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.5rem 0.7rem; font-size: 0.9rem; color: var(--muted);
}
.quote-preview[hidden] { display: none; }
.quote-preview-text {
  flex: 1; border-left: 3px solid var(--accent); padding-left: 0.6rem;
  max-height: 4.6rem; overflow-y: auto; white-space: pre-line;
}
.quote-remove {
  border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 0.1rem 0.3rem;
}
.bubble-quote {
  border-left: 3px solid rgb(255 255 255 / 65%); background: rgb(255 255 255 / 16%);
  border-radius: 6px; padding: 0.35rem 0.6rem; margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

/* ---- redraw-by-reference ---- */
.redraw-preview {
  display: flex; flex-direction: column; gap: 0.4rem;
  width: 100%; max-width: 720px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.5rem 0.7rem;
}
.redraw-preview[hidden] { display: none; }
.redraw-preview-hint { font-size: 0.85rem; color: var(--muted); }
.redraw-preview-items { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.redraw-ref-chip {
  position: relative; margin: 0; width: 64px; text-align: center;
}
.redraw-ref-chip img {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line);
}
.redraw-ref-chip figcaption { font-size: 0.7rem; color: var(--muted); }
.redraw-ref-remove {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0; line-height: 1;
  border: none; border-radius: 50%; cursor: pointer;
  background: #2f2f38; color: #fff; font-size: 0.9rem;
  box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
}
.bubble-refs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.bubble-ref { margin: 0; width: 72px; text-align: center; }
.bubble-ref img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 8px; border: 1px solid rgb(255 255 255 / 45%);
}
.bubble-ref figcaption { font-size: 0.7rem; opacity: 0.85; }

/* ---- widgets ---- */
.widget {
  align-self: stretch; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem;
}
.widget.resolved { opacity: 0.75; }
.widget.cancelled {
  opacity: 0.65; flex-direction: row; flex-wrap: wrap; align-items: baseline;
  gap: 0.3rem 0.8rem; padding: 0.6rem 1rem;
}
.widget.cancelled .widget-title { font-weight: 600; }
.widget-title { font-weight: 700; }
.widget-hint { color: var(--muted); font-size: 0.9rem; }
.widget-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.widget input[type="text"], .widget input[type="number"], .widget textarea, .widget select {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit;
}

.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.6rem; }
.character-option {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem; cursor: pointer;
  background: var(--card);
}
.character-option:has(input:checked) { border-color: var(--accent); background: #eef1fb; }
.character-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.character-avatar.placeholder {
  display: flex; align-items: center; justify-content: center;
  background: #eef1fb; color: var(--accent); font-weight: 700; font-size: 1.4rem;
}
.character-name { font-weight: 600; }
.character-style { color: var(--muted); font-size: 0.8rem; }
.new-character-fields { display: flex; flex-direction: column; gap: 0.5rem; }
.photo-label { color: var(--muted); font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.3rem; }

.page-text-list { display: flex; flex-direction: column; gap: 0.5rem; padding-left: 1.2rem; }
.page-text-list textarea { width: 100%; }

.page-art-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.8rem; }
.page-art-card {
  display: flex; flex-direction: column; gap: 0.4rem;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem;
}
.page-art-card img { border-radius: 8px; aspect-ratio: 1; object-fit: cover; }
.page-art-caption { font-size: 0.85rem; color: var(--muted); }
.missing-art {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: #f0ede6; border-radius: 8px; color: var(--muted);
}

/* ---- proposal & display widgets ---- */
.proposal-summary { font-size: 0.95rem; }
.proposal-new-title { font-weight: 600; }
.proposal-pages li { display: flex; flex-direction: column; gap: 0.3rem; }
.proposal-badge {
  align-self: flex-start; font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; border-radius: 999px; padding: 0.1rem 0.55rem;
}
.badge-new { background: #dcf3e3; color: #1f7a3f; }
.badge-edited { background: #fdeeda; color: #a06514; }
.badge-removed { background: #fdeaea; color: #a02020; }
.proposal-old-text { color: var(--muted); font-size: 0.9rem; }
.proposal-delete { list-style: none; }
.proposal-scene-note { color: var(--muted); font-size: 0.8rem; font-style: italic; }

.illus-plan-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.illus-plan-page { font-weight: 600; }
.illus-plan-feedback { font-size: 0.9rem; }
.illus-plan-refs { color: var(--muted); font-size: 0.85rem; font-style: italic; }

.preview-story-title { font-weight: 600; font-size: 1.05rem; }
.preview-page-list { display: flex; flex-direction: column; gap: 0.6rem; }
.preview-page {
  display: flex; align-items: flex-start; gap: 0.7rem;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem;
}
.preview-page img { width: 96px; border-radius: 8px; aspect-ratio: 1; object-fit: cover; flex-shrink: 0; }
.preview-page-text { display: flex; gap: 0.5rem; }
.preview-page-number { font-weight: 700; color: var(--muted); }

.showcase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
.showcase-card {
  display: flex; flex-direction: column; gap: 0.3rem;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem;
}
.showcase-card img { border-radius: 8px; aspect-ratio: 1; object-fit: cover; }
.showcase-name { font-weight: 600; }
.showcase-age { color: var(--muted); font-size: 0.85rem; }
.showcase-description { font-size: 0.85rem; color: var(--muted); }

.book-card {
  align-self: stretch; background: linear-gradient(135deg, #eef1fb, #fdf3e3);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem;
  display: flex; flex-direction: column; gap: 0.8rem;
}
.book-card-title { font-weight: 700; font-size: 1.1rem; }
.book-card-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ---- home & library ---- */
.hero { text-align: center; padding: 3rem 1rem 2rem; }
.hero p { color: var(--muted); max-width: 34rem; margin: 0.8rem auto 1.4rem; }
.story-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.story-row {
  display: flex; align-items: center; gap: 0.8rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 1rem;
}
.story-title { font-weight: 600; flex: 1; }
.story-actions { display: flex; gap: 0.4rem; }
.status-chip { font-size: 0.75rem; border-radius: 999px; padding: 0.15rem 0.6rem; background: #eee; color: var(--muted); }
.status-assembled { background: #dcf3e3; color: #1f7a3f; }
.status-illustration_review, .status-text_review { background: #fdeeda; color: #a06514; }
.empty-note { color: var(--muted); }

/* ---- auth ---- */
.auth-card {
  max-width: 420px; margin: 3rem auto; padding: 2rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 1rem;
}
.auth-card h1 { margin: 0; font-size: 1.4rem; }
.auth-card form { display: flex; flex-direction: column; gap: 0.9rem; }
.auth-card label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.auth-card input {
  padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.field-hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.auth-error { background: #fdeaea; color: #a02020; border-radius: 8px; padding: 0.6rem 0.9rem; font-size: 0.9rem; margin: 0; }
.auth-alt { color: var(--muted); font-size: 0.9rem; text-align: center; margin: 0; }
.auth-alt a { color: var(--accent); }

.verify-banner {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  background: #fff8e1; color: #7a5b00; padding: 0.6rem 1rem; font-size: 0.9rem;
}
.btn-link {
  background: none; border: none; padding: 0; font: inherit; color: var(--accent);
  text-decoration: underline; cursor: pointer;
}

/* ---- invite links ---- */
.invite-form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.8rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1.5rem;
}
.invite-form label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.invite-form input {
  padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.invite-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.invite-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 1rem;
}
.invite-url { flex: 1; min-width: 240px; word-break: break-all; font-size: 0.85rem; }
.invite-status { font-size: 0.75rem; border-radius: 999px; padding: 0.15rem 0.6rem; background: #eee; color: var(--muted); }
.invite-expiry, .invite-note { color: var(--muted); font-size: 0.85rem; }

/* ---- reader ---- */
.reader {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 1rem;
  height: calc(100vh - 8rem);
}
.reader-page {
  flex: 0 0 100%; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem;
}
.reader-page img { max-height: 60%; border-radius: var(--radius); }
.reader-text { font-size: 1.5rem; text-align: center; max-width: 34rem; line-height: 1.5; }
.reader-page.cover h1 { font-size: 2.2rem; text-align: center; }
.swipe-hint { color: var(--muted); }
