:root {
  --ink:       #1F2A44;
  --ink-soft:  #4A5570;
  --accent:    #9C7C38;
  --accent-soft: #C4A65E;
  --mute:      #6E6E6E;
  --soft:      #D9D2C5;
  --rule:      #C9C0B0;
  --paper:     #FBF7EE;
  --paper-2:   #F7F3EA;
}

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,700;1,400;1,700&display=swap');

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
body { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 18px; line-height: 1.55; }

/* ── Index page ── */
.index-page header { text-align: center; padding: 4rem 2rem 2rem; border-bottom: 1px solid var(--rule); margin-bottom: 2rem; }
.index-page .eyebrow { font-size: 0.75rem; letter-spacing: 0.3em; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.index-page h1 { font-size: 3.5rem; margin: 0.5rem 0; line-height: 1; }
.index-page h1 em { font-style: italic; font-weight: 400; }
.index-page h1 strong { font-weight: 700; }
.index-page .subtitle { font-style: italic; color: var(--ink-soft); font-size: 1.25rem; margin: 0.5rem 0; }
.index-page .byline { font-style: italic; color: var(--mute); margin: 0.5rem 0 2rem; font-size: 1rem; }
.index-grid { max-width: 900px; margin: 0 auto; padding: 0 2rem; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.chapter-card { background: var(--paper-2); border: 1px solid var(--rule); padding: 1.5rem; }
.chapter-card h2 { font-size: 1.5rem; margin: 0 0 0.25rem; }
.chapter-card .principle { color: var(--accent); margin: 0 0 1rem; font-size: 1rem; }
.chapter-card ul.treatments { list-style: none; padding: 0; margin: 0; }
.chapter-card ul.treatments li { margin-bottom: 0.75rem; }
.chapter-card ul.treatments a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--rule); }
.chapter-card ul.treatments a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.chapter-card .t-subtitle { display: block; font-size: 0.85rem; color: var(--mute); font-style: italic; margin-top: 0.15rem; }
.index-page footer { text-align: center; padding: 3rem 2rem; color: var(--mute); font-style: italic; }

/* ── Chapter page layout (with optional chat) ── */
.layout { display: grid; grid-template-columns: 1fr; transition: grid-template-columns 0.3s ease; }
body.chat-open .layout { grid-template-columns: 1fr 420px; }
.chat-pane { display: none; }
body.chat-open .chat-pane { display: flex; }

.topnav {
  position: sticky; top: 0; background: var(--paper); z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.75rem 2rem; border-bottom: 1px solid var(--rule); font-size: 0.9rem;
}
.topnav .home { color: var(--ink-soft); text-decoration: none; }
.topnav .variant-switch { display: flex; gap: 0.25rem; }
.topnav .variant-switch a {
  padding: 0.25rem 0.75rem; border: 1px solid var(--rule);
  color: var(--ink-soft); text-decoration: none; font-weight: 700; font-size: 0.85rem;
}
.topnav .variant-switch a.active { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.topnav .treatment-name { color: var(--mute); font-style: italic; }
.topnav .chat-toggle {
  margin-left: auto; padding: 0.4rem 1rem;
  background: var(--paper); border: 1px solid var(--accent); color: var(--accent);
  font-family: inherit; font-size: 0.9rem; cursor: pointer;
}
.topnav .chat-toggle:hover { background: var(--accent); color: var(--paper); }

.chapter { max-width: 760px; margin: 0 auto; padding: 3rem 2rem 6rem; font-size: 19px; line-height: 1.65; }
.chapter h1 { font-size: 3rem; line-height: 1; margin: 1rem 0 0.5rem; font-weight: 700; }
.chapter h1 + h1 { margin-top: 0; }
.chapter h2 { font-size: 1.25rem; font-style: italic; color: var(--mute); font-weight: 400; margin: 0.5rem 0 2rem; }
.chapter h3 { text-align: center; font-size: 0.9rem; letter-spacing: 0.3em; color: var(--accent); font-weight: 700; text-transform: uppercase; margin: 3rem 0 1.5rem; }
.chapter h4 { text-align: center; font-style: italic; color: var(--accent); font-size: 1.1rem; margin: 2rem 0 1rem; }
.chapter p { margin: 0 0 1.2rem; }
.chapter strong { font-weight: 700; }
.chapter em { font-style: italic; }
.chapter hr { border: none; border-top: 1px solid var(--rule); margin: 2rem auto; width: 60%; }

/* Spell box — boxed callout per spec § 5 */
.chapter .spell {
  background: var(--paper-2);
  border: 1px solid var(--soft);
  border-left: 4px solid var(--accent);
  padding: 1.5rem 2rem;
  margin: 2.5rem 0;
  display: block;
}
.chapter .spell p:first-child {
  font-size: 0.85rem; letter-spacing: 0.2em; color: var(--accent);
  font-weight: 700; text-transform: uppercase; margin-bottom: 1rem;
}
.chapter .spell p:first-child strong { color: var(--accent); }
.chapter .spell p:nth-child(2) strong {
  font-style: italic; font-size: 1.5rem; line-height: 1.2;
  color: var(--ink); font-weight: 700; display: block; margin-bottom: 0.5rem;
}
.chapter .spell p { margin-bottom: 0.75rem; }
.chapter .spell p:last-child { margin-bottom: 0; }

/* Pullquote — bold inline phrase set off as italic quote */
.chapter blockquote {
  border-left: none;
  text-align: center;
  font-style: italic;
  font-size: 1.5rem;
  line-height: 1.3;
  color: var(--ink);
  margin: 2rem auto;
  max-width: 80%;
  padding: 1rem 0;
  border-top: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
}

/* Photos */
.chapter figure { margin: 1.5rem 0; }
.chapter figure img { width: 100%; height: auto; display: block; border: 1px solid var(--ink-soft); }
.chapter figcaption { font-style: italic; font-size: 0.9rem; color: var(--mute); margin-top: 0.5rem; text-align: left; }
.chapter .hero { margin: 0 0 2.5rem; }
.chapter .hero img { border: none; }
.chapter .photo-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 2rem 0; }
.chapter .photo-pair figure { margin: 0; }
.chapter .inflow { float: right; width: 45%; margin: 0 0 1rem 1.5rem; }
.chapter .inflow:nth-of-type(even) { float: left; margin: 0 1.5rem 1rem 0; }

/* ── Chat pane ── */
.chat-pane {
  flex-direction: column;
  position: sticky; top: 49px; align-self: start;
  height: calc(100vh - 49px);
  background: var(--paper-2);
  border-left: 1px solid var(--rule);
}
.chat-pane header {
  padding: 1.5rem 1.5rem 1rem; border-bottom: 1px solid var(--rule);
}
.chat-pane .chat-eyebrow {
  font-size: 0.7rem; letter-spacing: 0.25em; color: var(--accent);
  font-weight: 700; text-transform: uppercase; margin: 0 0 0.25rem;
}
.chat-pane header h3 {
  font-size: 1.2rem; font-style: italic; margin: 0; color: var(--ink);
  font-weight: 400;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.chat-messages .msg { padding: 0.75rem 1rem; font-size: 0.95rem; line-height: 1.5; }
.chat-messages .msg p { margin: 0 0 0.5rem; }
.chat-messages .msg p:last-child { margin-bottom: 0; }
.chat-messages .msg.user {
  background: var(--paper); border: 1px solid var(--rule);
  align-self: flex-end; max-width: 85%; border-radius: 2px;
}
.chat-messages .msg.model {
  align-self: flex-start; max-width: 95%;
  border-left: 3px solid var(--accent); padding-left: 0.75rem;
}
.chat-messages .msg.thinking { color: var(--mute); font-style: italic; }
.chat-messages .msg.error { color: #a33; font-style: italic; }

.chat-input {
  display: flex; gap: 0.5rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--rule);
}
.chat-input textarea {
  flex: 1; font-family: inherit; font-size: 0.95rem;
  border: 1px solid var(--rule); padding: 0.5rem; background: var(--paper);
  resize: vertical; color: var(--ink);
}
.chat-input button {
  background: var(--accent); color: var(--paper);
  border: none; padding: 0.5rem 1rem; font-family: inherit;
  font-size: 0.9rem; cursor: pointer; font-weight: 700;
}
.chat-input button:hover { background: var(--ink); }

/* Responsive */
@media (max-width: 1100px) {
  body.chat-open .layout { grid-template-columns: 1fr; }
  .chat-pane { position: fixed; top: 0; right: 0; width: 100%; max-width: 420px; z-index: 100; box-shadow: -4px 0 12px rgba(0,0,0,0.1); }
}
@media (max-width: 720px) {
  .index-grid { grid-template-columns: 1fr; }
  .chapter .photo-pair { grid-template-columns: 1fr; }
  .chapter .inflow { float: none; width: 100%; margin: 1.5rem 0; }
  .chapter { padding: 2rem 1.25rem 4rem; }
}
/* Full-width vignette (centered, no float) */
.chapter .inflow-full { margin: 2.5rem 0; clear: both; }
.chapter .inflow-full img { width: 100%; height: auto; display: block; border: 1px solid var(--ink-soft); }
.chapter .inflow-full figcaption { font-style: italic; font-size: 0.9rem; color: var(--mute); margin-top: 0.5rem; text-align: left; }

/* Left-floated vignette */
.chapter .inflow-left { float: left; width: 45%; margin: 0 1.5rem 1rem 0; }

/* ── Image upload (chat) ── */
.chat-input .input-row {
  display: flex; gap: 0.5rem; align-items: stretch;
}
.chat-input .img-button {
  display: flex; align-items: center; justify-content: center;
  width: 38px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  flex-shrink: 0;
}
.chat-input .img-button:hover { color: var(--accent); border-color: var(--accent); }
.img-preview {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.5rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.img-preview img {
  max-height: 60px;
  max-width: 120px;
  border: 1px solid var(--rule);
}
.img-preview #imgClear {
  margin-left: 0.5rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  width: 24px; height: 24px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--ink-soft);
  font-family: inherit;
}
.img-preview #imgClear:hover { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.chat-messages .msg.user .msg-img,
.chat-messages .msg.model .msg-img {
  max-width: 100%;
  max-height: 200px;
  margin-bottom: 0.5rem;
  display: block;
  border: 1px solid var(--rule);
}

/* ── Toast notification ── */
.toast {
  position: fixed; top: 4rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 0.5rem 1.25rem; font-size: 0.9rem; font-style: italic;
  z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  letter-spacing: 0.05em;
  animation: toastFade 2.4s ease-out;
}
@keyframes toastFade {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}
/* ── Drag-and-drop affordance (subtle, scoped to chat pane) ── */
body.dragging-file .chat-pane {
  position: relative;
}
body.dragging-file .chat-pane::after {
  content: '';
  position: absolute; inset: 8px;
  border: 3px dashed var(--accent);
  pointer-events: none;
  animation: dropPulse 1.4s ease-in-out infinite;
}
body.dragging-file .chat-input .img-button {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
body.dragging-file .chat-input textarea {
  border-color: var(--accent);
}
@keyframes dropPulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* ── Save chat buttons (chat header) ── */
.chat-pane header { position: relative; }
.chat-save-actions {
  position: absolute; top: 1rem; right: 1rem;
  display: flex; gap: 0.4rem;
}
.save-chat-btn {
  background: var(--paper); border: 1px solid var(--accent); color: var(--accent);
  font-family: inherit; font-size: 0.78rem; padding: 0.3rem 0.65rem;
  cursor: pointer; border-radius: 2px; white-space: nowrap;
}
.save-chat-btn:hover:not(:disabled) { background: var(--accent); color: var(--paper); }
.save-chat-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Create a Spell tool (above chat input) ── */
.chat-tools {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0 1.5rem 0.5rem;
}
.spell-btn {
  background: var(--accent); color: var(--paper);
  border: 1px solid var(--accent);
  font-family: inherit; font-size: 0.85rem; font-weight: 700;
  padding: 0.35rem 0.85rem; cursor: pointer; border-radius: 2px;
  white-space: nowrap;
}
.spell-btn:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); }
.spell-btn:disabled { opacity: 0.6; cursor: default; }
.spell-hint {
  font-size: 0.78rem; font-style: italic; color: var(--mute); line-height: 1.2;
}
@media (max-width: 720px) { .spell-hint { display: none; } }

/* ── Spell idea cards (in chat) ── */
.spell-cards {
  margin: 0.25rem 0 0.5rem; padding-left: 0.75rem;
  border-left: 3px solid var(--accent);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.spell-cards-lead { font-size: 0.82rem; font-style: italic; color: var(--mute); margin: 0 0 0.25rem; }
.spell-card { background: var(--paper-2); border: 1px solid var(--soft); padding: 0.6rem 0.75rem; }
.spell-card-title { font-weight: 700; font-style: italic; font-size: 1.05rem; color: var(--ink); margin: 0 0 0.3rem; }
.spell-card-body { font-size: 0.92rem; line-height: 1.45; margin: 0 0 0.55rem; color: var(--ink); }
.spell-use-btn {
  background: var(--paper); border: 1px solid var(--accent); color: var(--accent);
  font-family: inherit; font-size: 0.8rem; font-weight: 700; padding: 0.28rem 0.7rem; cursor: pointer; border-radius: 2px;
}
.spell-use-btn:hover:not(:disabled) { background: var(--accent); color: var(--paper); }
.spell-use-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Pending (just-applied) spell highlight in the chapter ── */
.chapter .spell.spell-pending {
  background: #FBF1D8;
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: spellPulse 1.1s ease-in-out 2;
}
@keyframes spellPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-soft); }
  50%      { box-shadow: 0 0 0 7px var(--accent); }
}

/* ── Keep / Undo bar ── */
.spell-approve-bar {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; display: none; gap: 0.75rem; align-items: center;
  z-index: 1500; box-shadow: 0 4px 16px rgba(0,0,0,0.22); font-size: 0.9rem; border-radius: 3px;
}
.spell-approve-bar button {
  font-family: inherit; font-size: 0.85rem; padding: 0.3rem 0.85rem; cursor: pointer;
  border: 1px solid var(--paper); background: transparent; color: var(--paper); border-radius: 2px;
}
.spell-approve-bar #spellKeep { background: var(--accent); border-color: var(--accent); }
.spell-approve-bar #spellKeep:hover { background: var(--accent-soft); }

/* ── Tool button cluster (Create a Spell · Through the Lens · Voice Check) ── */
.chat-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
  padding: 0 1.5rem 0.15rem;
}
.chat-tools-hint {
  margin: 0 0 0.5rem; padding: 0 1.5rem;
  font-size: 0.76rem; font-style: italic; color: var(--mute);
}
.tool-btn {
  background: var(--paper); border: 1px solid var(--accent); color: var(--accent);
  font-family: inherit; font-size: 0.8rem; font-weight: 700;
  padding: 0.32rem 0.7rem; cursor: pointer; border-radius: 2px; white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { background: var(--accent); color: var(--paper); }
.tool-btn:disabled { opacity: 0.6; cursor: default; }
.tool-btn-primary { background: var(--accent); color: var(--paper); }
.tool-btn-primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); }
@media (max-width: 720px) { .chat-tools-hint { display: none; } }
