:root {
  --paper: #f6f2ea;
  --surface: #fffdf8;
  --ink: #241f1a;
  --soft: #756d61;
  --faint: #a89f92;
  --line: #e8dfce;
  --line-soft: #f0e9db;
  --accent: #b8543a;
  --accent-press: #a2452e;
  --accent-soft: #f3e2da;
  --sage: #5c7a63;
  --user: #ece3d3;
  --shadow: 0 10px 34px rgba(70, 50, 32, .10);
  --shadow-soft: 0 4px 16px rgba(70, 50, 32, .07);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 18px 10px; }
.brand { font-family: var(--serif); font-size: 27px; font-weight: 600; letter-spacing: -.01em; line-height: 1; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--soft); border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 500; cursor: pointer; max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { color: var(--ink); }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: none; background: transparent; color: var(--soft); border-radius: 12px; cursor: pointer; }
.icon-btn:hover { background: var(--surface); color: var(--ink); }

/* ---------- feed ---------- */
.feed { flex: 1; overflow-y: auto; padding: 8px 16px 18px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.feed::-webkit-scrollbar { width: 0; }

.greeting { margin: auto 0; padding: 24px 6px; text-align: left; }
.greeting h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; line-height: 1.18; letter-spacing: -.015em; margin: 0 0 14px; color: var(--ink); }
.greeting h1 em { font-style: italic; color: var(--accent); }
.greeting p { color: var(--soft); font-size: 16px; margin: 0 0 20px; max-width: 30em; }
.eg-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin-bottom: 8px; }
.eg { display: flex; flex-direction: column; gap: 8px; }
.eg button { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-family: inherit; font-size: 14.5px; color: var(--ink); cursor: pointer; line-height: 1.45; box-shadow: var(--shadow-soft); }
.eg button:hover { border-color: var(--accent); }
.eg button span { color: var(--faint); }

/* messages */
.msg { max-width: 86%; padding: 12px 15px; border-radius: 18px; font-size: 15.5px; line-height: 1.5; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow-soft); }
.msg.ai .answer { white-space: pre-wrap; }
.msg.ai b { font-weight: 600; }
.msg.thinking { color: var(--faint); font-style: italic; }
.dots span { display: inline-block; width: 5px; height: 5px; margin: 0 1px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.dots span:nth-child(2){ animation-delay: .2s; } .dots span:nth-child(3){ animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{ opacity:.25; } 30%{ opacity:1; } }

/* added-summary card */
.added { align-self: flex-start; max-width: 88%; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; border-bottom-left-radius: 6px; padding: 13px 15px; box-shadow: var(--shadow-soft); }
.added-head { font-size: 13px; color: var(--sage); font-weight: 600; margin-bottom: 9px; display: flex; align-items: center; gap: 6px; }
.added-lines { display: flex; flex-direction: column; gap: 5px; margin-bottom: 6px; }
.added-line { font-size: 14.5px; line-height: 1.45; }
.added-line .r { color: var(--accent); font-weight: 500; }
.added-nodes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ntag { display: inline-flex; align-items: center; gap: 5px; background: var(--accent-soft); color: #7a3a28; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 500; }
.added-foot { margin-top: 10px; display: flex; gap: 10px; align-items: center; }
.added-foot button { background: none; border: none; color: var(--soft); font-family: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.added-foot .insight { color: var(--accent); font-weight: 500; text-decoration: none; }

/* ---------- composer ---------- */
.composer { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--paper) 24%); }
.mode-toggle { position: relative; display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin: 0 auto 10px; box-shadow: var(--shadow-soft); }
.mode-btn { position: relative; z-index: 1; border: none; background: transparent; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--soft); padding: 7px 22px; border-radius: 999px; cursor: pointer; transition: color .2s; }
.mode-btn.active { color: #fff; }
.mode-slider { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); background: var(--accent); border-radius: 999px; transition: transform .24s cubic-bezier(.4,1.2,.4,1); }
.mode-toggle.ask .mode-slider { transform: translateX(100%); background: var(--sage); }
.input-row { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); }
.input-row:focus-within { border-color: var(--accent); }
#composer { flex: 1; border: none; background: transparent; resize: none; font-family: inherit; font-size: 16px; line-height: 1.45; color: var(--ink); outline: none; max-height: 40vh; padding: 8px 0; }
#composer::placeholder { color: var(--faint); }
.mic-btn, .send-btn { flex: none; width: 42px; height: 42px; border-radius: 50%; border: none; display: grid; place-items: center; cursor: pointer; }
.mic-btn { background: var(--paper); color: var(--soft); }
.mic-btn:hover { color: var(--ink); }
.mic-btn.recording { background: var(--accent); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(184,84,58,.4);} 50%{ box-shadow: 0 0 0 10px rgba(184,84,58,0);} }
.send-btn { background: var(--accent); color: #fff; }
.send-btn:hover { background: var(--accent-press); }
.send-btn:disabled { opacity: .4; cursor: default; }
body.ask-mode .send-btn { background: var(--sage); }
body.ask-mode .input-row:focus-within { border-color: var(--sage); }
body.ask-mode .mic-btn.recording { background: var(--sage); }

/* ---------- graph overlay ---------- */
.overlay { position: fixed; inset: 0; background: var(--paper); z-index: 40; display: none; flex-direction: column; }
.overlay.open { display: flex; }
.overlay-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.overlay-title { font-family: var(--serif); font-size: 20px; font-weight: 500; }
.overlay-head .icon-btn { margin-left: auto; }
#graph { flex: 1; width: 100%; display: block; touch-action: none; cursor: grab; }
.node-card { position: absolute; left: 14px; right: 14px; bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 15px 16px; box-shadow: var(--shadow); display: none; max-height: 52dvh; overflow-y: auto; }
.node-card.open { display: block; }
.nc-name { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.nc-kind { color: var(--faint); font-size: 13px; margin-bottom: 8px; }
.nc-line { font-size: 14.5px; line-height: 1.5; padding: 6px 0; border-top: 1px solid var(--line-soft); }
.nc-line:first-of-type { border-top: none; }
.nc-line .r { color: var(--accent); }

/* ---------- settings sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(40,30,20,.28); backdrop-filter: blur(2px); z-index: 50; display: none; align-items: flex-end; justify-content: center; }
.sheet-bg.open { display: flex; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--paper); border-radius: 26px 26px 0 0; padding: 8px 20px calc(24px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 40px rgba(40,30,20,.2); }
.sheet-grip { width: 42px; height: 4px; background: var(--line); border-radius: 3px; margin: 8px auto 6px; }
.sheet h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 6px 0 16px; }
.set-block { margin-bottom: 20px; }
.set-label { font-size: 13px; font-weight: 600; color: var(--soft); margin-bottom: 8px; }
.set-hint { font-size: 12.5px; color: var(--faint); margin-top: 7px; line-height: 1.5; }
.set-hint code { background: var(--surface); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
.set-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.manual { display: flex; flex-direction: column; gap: 8px; }
.field { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; font-family: inherit; font-size: 15px; color: var(--ink); outline: none; margin-bottom: 8px; }
.field:last-child { margin-bottom: 0; }
.field:focus { border-color: var(--accent); }
select.field { -webkit-appearance: none; appearance: none; }

.btn { font-family: inherit; font-size: 15px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 11px 16px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-press); }
.btn.ghost { background: transparent; font-weight: 500; font-size: 14px; padding: 9px 13px; }
.btn.danger { color: var(--accent); }
.btn.wide { width: 100%; margin-top: 6px; }

/* ---------- toast ---------- */
#toast { position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(14px); background: var(--ink); color: var(--paper); padding: 11px 17px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .22s; z-index: 90; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) { .greeting h1 { font-size: 34px; } }
