:root {
  --paper: #fdf8f0;
  --ink: #2f2a26;
  --muted: #7d736a;
  --line: #e6dccd;
  --accent: #c8622f;
  --accent-dark: #a94e22;
  --card: #fffdf9;
  --shadow: 0 2px 10px rgba(60, 45, 30, .07);
  --error: #b3341f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 ui-rounded, "Nunito", "Segoe UI", system-ui, sans-serif;
}

/* ------------------------------------------------------------- chrome */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-weight: 800; letter-spacing: -.02em; font-size: 19px;
  background: none; border: none; padding: 0; color: var(--ink); cursor: pointer;
}
.brand:disabled { cursor: default; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-weight: 700; font-size: 15px; }

button {
  font: inherit; font-weight: 700; cursor: pointer;
  border-radius: 999px; border: 1px solid transparent;
  padding: 10px 20px; transition: transform .08s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

.primary { background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.big { padding: 14px 30px; font-size: 17px; }
.small { padding: 7px 14px; font-size: 14px; }

.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }

input[type=text], input[type=password] {
  font: inherit; padding: 13px 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--muted); }
.error { color: var(--error); min-height: 22px; margin: 10px 0 0; font-size: 15px; }

/* -------------------------------------------------------------- views */

.view { display: none; padding: 32px 22px 80px; }
.view.active { display: block; }

.hero { max-width: 560px; margin: 8vh auto 0; text-align: center; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 18px; }
.sub { color: var(--muted); font-size: 18px; margin: 0 0 34px; }

.auth { display: flex; flex-direction: column; gap: 12px; max-width: 340px; margin: 0 auto; }
.auth-buttons { display: flex; gap: 10px; margin-top: 6px; }
.auth-buttons button { flex: 1; }

/* ---------------------------------------------------------- bookshelf */

.shelf-wrap { max-width: 900px; margin: 0 auto; }
.shelf-wrap h2 { font-size: 26px; margin: 0 0 22px; }

.shelf {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.empty { grid-column: 1 / -1; padding: 40px 0; text-align: center; }

.card {
  padding: 0; overflow: hidden; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow); font-weight: 400;
}
.card:hover { border-color: var(--accent); }
.card-img { aspect-ratio: 1; background: var(--paper); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.card-body strong { font-size: 17px; }
.card-body .muted { font-size: 14px; }

.shelf-new { text-align: center; margin-top: 36px; }

/* ---------------------------------------------------------- interview */

.chat-wrap { max-width: 620px; margin: 0 auto; }
.chat { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; min-height: 40vh; }

.bubble {
  max-width: 84%; padding: 13px 18px; border-radius: 20px;
  box-shadow: var(--shadow); animation: rise .25s ease;
}
.bubble.them { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.me { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.typing { color: var(--muted); font-style: italic; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.composer { display: flex; gap: 10px; }

/* ----------------------------------------------------------- portrait */

.portrait-wrap { max-width: 560px; margin: 0 auto; text-align: center; }
.portrait-wrap h2 { font-size: 28px; margin: 0 0 22px; }

.portrait-frame {
  position: relative; aspect-ratio: 1; border-radius: 20px; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.portrait-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }

.loading {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 16px;
  justify-items: center; background: var(--card); color: var(--muted); text-align: center;
  padding: 16px;
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.caption { font-weight: 800; font-size: 20px; margin: 18px 0 4px; }
.portrait-actions { display: flex; gap: 12px; justify-content: center; margin: 20px 0 14px; }
.warn { color: var(--muted); font-size: 14px; max-width: 380px; margin: 0 auto; }

/* -------------------------------------------------------------- story */

.story-wrap { max-width: 720px; margin: 0 auto; }

.story-head { display: flex; gap: 16px; align-items: center; margin-bottom: 22px; }
.story-cover {
  width: 76px; height: 76px; object-fit: cover; border-radius: 16px;
  border: 1px solid var(--line); background: var(--card);
}
.story-head h2 { margin: 0; font-size: 24px; }
.story-head p { margin: 2px 0 0; font-size: 15px; }

.pack { display: flex; gap: 8px; justify-content: center; margin-bottom: 26px; }
.pack img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); opacity: .75;
}

.chapter-title {
  text-align: center; font-size: 26px; font-weight: 800;
  margin: 34px 0 22px; letter-spacing: -.01em;
}
.chapter-title::after {
  content: ''; display: block; width: 48px; height: 3px; border-radius: 2px;
  background: var(--accent); margin: 14px auto 0;
}

.scene {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  overflow: hidden; margin-bottom: 26px; box-shadow: var(--shadow);
  animation: rise .3s ease;
}
.scene-img { position: relative; aspect-ratio: 1; background: var(--paper); }
.scene-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scene-img .loading { background: var(--paper); }
.scene p { margin: 0; padding: 20px 24px 24px; font-size: 18px; }

.next-chapter {
  text-align: center; margin-top: 44px; padding-top: 30px;
  border-top: 1px solid var(--line);
}
.next-chapter h3 { font-size: 21px; margin: 0 0 16px; }
.next-chapter input { max-width: 460px; margin: 0 auto 16px; }
.status { color: var(--muted); font-size: 15px; min-height: 22px; margin: 14px 0 0; }
.status.error { color: var(--error); }

@media (max-width: 560px) {
  .bubble { max-width: 92%; }
  .portrait-actions { flex-direction: column-reverse; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
