:root {
  --ink: #12212b;
  --ink-2: #2b3d48;
  --paper: #f6f1e7;
  --card: #fffdf8;
  --line: #e3dccd;
  --amber: #e0a43a;
  --amber-soft: #f7e6c4;
  --teal: #2e8b85;
  --teal-soft: #d6ece9;
  --red: #b4432f;
  --muted: #6c7a83;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(18 33 43 / 6%), 0 8px 24px rgb(18 33 43 / 8%);
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.6 var(--sans); color: var(--ink); background: var(--paper); min-height: 100vh; }
a { color: var(--teal); }
button, select, textarea, input { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Slow drifting light behind the page: alive, but never in the way. */
.backdrop {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40vmax 40vmax at 15% 10%, rgb(224 164 58 / 16%), transparent 60%),
    radial-gradient(35vmax 35vmax at 90% 30%, rgb(46 139 133 / 14%), transparent 60%),
    radial-gradient(30vmax 30vmax at 50% 100%, rgb(18 33 43 / 6%), transparent 60%);
  animation: drift 24s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(-3%, 2%, 0) scale(1.05); } }

.top { display: flex; align-items: center; justify-content: space-between; padding: 20px clamp(16px, 4vw, 48px); }
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); }
.brand strong { display: block; font: 700 1.35rem/1 var(--serif); letter-spacing: .01em; }
.brand small { color: var(--muted); font-size: .8rem; }
.top nav { display: flex; gap: 20px; }
.top nav a { color: var(--ink-2); text-decoration: none; font-weight: 500; }
.top nav a:hover { color: var(--teal); }

.banner { margin: 0 clamp(16px, 4vw, 48px) 8px; padding: 10px 16px; border-radius: 10px; background: var(--amber-soft); border: 1px solid #ecd29d; font-size: .92rem; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: clamp(20px, 3vw, 40px); padding: 12px clamp(16px, 4vw, 48px) 40px; max-width: 1280px; margin: 0 auto; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

h1 { font: 700 clamp(2rem, 4.2vw, 3.1rem)/1.12 var(--serif); margin: 18px 0 22px; letter-spacing: -.01em; }
h1 span { color: var(--teal); }
h2 { font: 700 1.05rem/1.3 var(--sans); margin: 0; }

.ask-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 10px; transition: border-color .2s, box-shadow .2s; }
.ask-box:focus-within { border-color: var(--teal); box-shadow: 0 0 0 4px rgb(46 139 133 / 15%), var(--shadow); }
.ask-box textarea { width: 100%; border: 0; resize: none; outline: none; background: transparent; font-size: 1.15rem; line-height: 1.5; padding: 4px 4px 8px; }
.ask-row { display: flex; align-items: center; gap: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.ask-row .muted { margin-left: auto; font-size: .8rem; font-variant-numeric: tabular-nums; }
.provider { display: flex; gap: 8px; align-items: center; font-size: .85rem; color: var(--muted); }
.provider select { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); padding: 4px 8px; color: var(--ink); }
#ask-button { border: 0; border-radius: 10px; padding: 9px 18px; background: var(--ink); color: var(--paper); font-weight: 600; cursor: pointer; transition: transform .15s, background .2s; }
#ask-button:hover { background: var(--teal); }
#ask-button:active { transform: scale(.97); }
#ask-button:disabled { opacity: .55; cursor: progress; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 26px; }
.examples button { border: 1px solid var(--line); background: rgb(255 253 248 / 70%); border-radius: 999px; padding: 5px 12px; font-size: .86rem; cursor: pointer; transition: background .2s, border-color .2s, transform .2s; }
.examples button:hover { background: var(--teal-soft); border-color: var(--teal); transform: translateY(-1px); }

.answer { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--amber); border-radius: var(--radius); padding: 18px 22px; box-shadow: var(--shadow); animation: rise .35s ease-out; }
.answer-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; font-size: .82rem; }
.pill { background: var(--amber-soft); color: #7a5410; border-radius: 999px; padding: 2px 10px; font-weight: 600; }
.pill.ok { background: var(--teal-soft); color: #1d5e59; }
.pill.none { background: #ece7dc; color: var(--ink-2); }
.pill.err { background: #f5d9d3; color: var(--red); }
.answer-text { font-size: 1.07rem; white-space: normal; overflow-wrap: anywhere; }
.answer-text p { margin: 0 0 .6em; }
.answer-text ul { margin: 0 0 .6em; padding-left: 1.2em; }
.answer-text.streaming::after { content: ""; display: inline-block; width: .55em; height: 1.05em; margin-left: 2px; vertical-align: -2px; background: var(--amber); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cite { border: 0; background: var(--teal); color: #fff; border-radius: 6px; font-size: .72rem; font-weight: 700; padding: 1px 6px; margin: 0 1px; vertical-align: 2px; cursor: pointer; }
.cite:hover { background: var(--ink); }

.sources { margin-top: 26px; }
.sources h2 { margin-bottom: 10px; }
.sources ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.source { background: rgb(255 253 248 / 80%); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; animation: rise .3s ease-out both; transition: border-color .2s, box-shadow .2s, opacity .2s; }
.source.unused { opacity: .62; }
.source.flash { border-color: var(--teal); box-shadow: 0 0 0 4px rgb(46 139 133 / 18%); }
.source header { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: .86rem; }
.source .no { flex: none; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--ink); color: var(--paper); font-weight: 700; font-size: .78rem; }
.source.used .no { background: var(--teal); }
.source .where { color: var(--muted); }
.source p { margin: 8px 0 0; font-size: .92rem; color: var(--ink-2); max-height: 7.5em; overflow: hidden; mask-image: linear-gradient(#000 70%, transparent); }
.source.open p { max-height: none; mask-image: none; }
.source button.more { border: 0; background: none; color: var(--teal); padding: 0; font-size: .82rem; cursor: pointer; margin-top: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.library { background: rgb(255 253 248 / 75%); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; align-self: start; position: sticky; top: 16px; backdrop-filter: blur(6px); }
.library-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.dropzone { position: relative; border: 1.5px dashed #cdbf9f; border-radius: 12px; padding: 14px; text-align: center; transition: background .2s, border-color .2s; }
.dropzone.over { background: var(--amber-soft); border-color: var(--amber); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone label b { display: block; }
.dropzone label span { font-size: .8rem; color: var(--muted); }
#admin-key { position: relative; z-index: 1; margin-top: 10px; width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--card); }
.docs { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.docs li { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 10px; }
.docs li:hover { background: rgb(18 33 43 / 4%); }
.docs .icon { width: 28px; height: 34px; border-radius: 4px; display: grid; place-items: center; font-size: .6rem; font-weight: 800; color: #fff; background: var(--ink-2); }
.docs .icon.pdf { background: var(--red); }
.docs .icon.docx { background: #2f5f9e; }
.docs .icon.md, .docs .icon.txt { background: var(--teal); }
.docs .name { text-decoration: none; color: var(--ink); font-size: .9rem; line-height: 1.3; overflow-wrap: anywhere; }
.docs .name small { display: block; color: var(--muted); font-size: .75rem; }
.docs .status { font-size: .72rem; border-radius: 999px; padding: 1px 8px; background: #ece7dc; }
.docs .status.Ready { background: var(--teal-soft); color: #1d5e59; }
.docs .status.Processing, .docs .status.Pending { background: var(--amber-soft); animation: pulse 1.4s ease-in-out infinite; }
.docs .status.Failed { background: #f5d9d3; color: var(--red); }
.docs .del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0 4px; }
@keyframes pulse { 50% { opacity: .5; } }
.privacy { margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--ink-2); }

.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 10px 16px 30px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.source:nth-child(2) { animation-delay: 60ms; } .source:nth-child(3) { animation-delay: 120ms; }
.source:nth-child(4) { animation-delay: 180ms; } .source:nth-child(5) { animation-delay: 240ms; }
.source:nth-child(n+6) { animation-delay: 300ms; }
