:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #171717;
  --line: #232323;
  --line-strong: #2e2e2e;
  --text: #f5f5f5;
  --text-dim: #a3a3a3;
  --text-faint: #6b6b6b;
  --radius: 14px;
  --maxw: 760px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}

.display {
  font-family: 'Instrument Serif', serif;
  font-weight: 400; letter-spacing: -0.02em; line-height: 1.02;
}
.display em { font-style: italic; color: var(--text-dim); }

/* NAV */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(10,10,10,0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  height: 60px; display: flex; align-items: center; gap: 24px;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none; color: var(--text); font-weight: 500;
  font-size: 15px; letter-spacing: 0.02em;
}
.brand-mark { font-size: 18px; }
.brand-name { letter-spacing: 0.04em; }
.nav-links { display: flex; gap: 4px; margin-left: 12px; }
.nav-link {
  background: transparent; border: 0; color: var(--text-dim);
  font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 8px;
  cursor: pointer; text-decoration: none; transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.is-active { color: var(--text); }

/* VIEWS */
.view { display: none; flex: 1; }
.view.active { display: flex; flex-direction: column; }

/* CHAT */
.chat-shell {
  flex: 1; display: flex; flex-direction: column;
  max-width: var(--maxw); width: 100%; margin: 0 auto; padding: 0 20px;
  min-height: calc(100vh - 60px);
}
.chat-stream { flex: 1; padding: 48px 0 24px; overflow-y: auto; }
.empty-state { padding: 40px 0 24px; text-align: left; max-width: 620px; }
.empty-state .display { font-size: clamp(2.2rem, 6vw, 3.6rem); margin-bottom: 14px; }
.lede { color: var(--text-dim); font-size: 15px; max-width: 52ch; margin-bottom: 32px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.suggestion {
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-dim); font: inherit; font-size: 13.5px;
  text-align: left; padding: 14px 16px; border-radius: 10px; cursor: pointer;
  transition: all .18s;
}
.suggestion:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }

.messages { display: flex; flex-direction: column; gap: 26px; }
.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg .avatar {
  flex-shrink: 0; width: 28px; height: 28px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 500; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-dim); letter-spacing: 0.02em;
}
.msg-bot .avatar { color: var(--text); font-size: 15px; }
.msg .bubble {
  flex: 1; min-width: 0; padding-top: 2px;
  white-space: pre-wrap; word-wrap: break-word;
  font-size: 15px; line-height: 1.7; color: var(--text);
}
.msg-user .bubble { font-weight: 450; }
.msg .bubble.error { color: #ff8a8a; }
.msg-sources { margin-top: 10px; font-size: 12.5px; color: var(--text-faint); letter-spacing: 0.02em; }

/* Markdown-rendered content inside bubbles */
.msg .bubble h3,
.msg .bubble h4 {
  font-family: 'Instrument Serif', serif;
  font-weight: 400; letter-spacing: -0.01em;
  margin: 16px 0 8px; line-height: 1.25;
}
.msg .bubble h3 { font-size: 1.25rem; }
.msg .bubble h4 { font-size: 1.1rem; }
.msg .bubble strong { color: var(--text); font-weight: 600; }
.msg .bubble em { font-style: italic; color: var(--text-dim); }
.msg .bubble code {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 5px;
  font-size: 0.9em; font-family: 'Menlo', 'Consolas', monospace;
}
.msg .bubble br { content: ''; display: block; margin: 6px 0; }

.thinking { display: inline-flex; gap: 4px; align-items: center; padding: 8px 0; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: pulse 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: .25; transform: scale(.85); }
  40% { opacity: 1; transform: scale(1); }
}

.composer-wrap {
  position: sticky; bottom: 0; padding: 14px 0 22px;
  background: linear-gradient(180deg, transparent, var(--bg) 26%);
}
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 8px 8px 8px 16px;
  transition: border-color .18s, box-shadow .18s;
}
.composer:focus-within { border-color: #4a4a4a; box-shadow: 0 0 0 3px rgba(255,255,255,0.04); }
.composer textarea {
  flex: 1; background: transparent; border: 0; outline: none;
  color: var(--text); font: inherit; font-size: 15px;
  resize: none; padding: 9px 0; max-height: 200px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--text-faint); }
.send-btn {
  flex-shrink: 0; width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  border: 0; border-radius: 9px; cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.send-btn:hover { opacity: .9; }
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.composer-note { text-align: center; font-size: 11.5px; color: var(--text-faint); margin-top: 10px; letter-spacing: 0.01em; }

/* Upgrade card */
.upgrade-card {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.upgrade-card h4 {
  font-family: 'Instrument Serif', serif; font-weight: 400;
  font-size: 1.3rem; letter-spacing: -0.01em;
}
.upgrade-card p { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.upgrade-btn {
  display: inline-block; text-align: center;
  background: var(--text); color: var(--bg);
  padding: 11px 20px; border-radius: 9px;
  text-decoration: none; font-size: 13.5px; font-weight: 500;
  transition: opacity .15s;
}
.upgrade-btn:hover { opacity: .9; }
.upgrade-hint { font-size: 11.5px; color: var(--text-faint); }
.pro-input {
  width: 100%; background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 9px 12px; color: var(--text);
  font: inherit; font-size: 13.5px; outline: none;
}
.pro-input:focus { border-color: #4a4a4a; }
.pro-apply {
  background: transparent; color: var(--text);
  border: 1px solid var(--line-strong);
  padding: 9px 18px; border-radius: 8px;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.pro-apply:hover { background: var(--surface-2); }

/* UPLOAD */
.upload-shell { max-width: 880px; width: 100%; margin: 0 auto; padding: 56px 20px 80px; }
.upload-head { margin-bottom: 40px; max-width: 640px; }
.upload-head .display { font-size: clamp(2rem, 5vw, 3.2rem); margin-bottom: 14px; }

.upload-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
  display: flex; flex-direction: column; gap: 18px;
}
.upload-card-wide { width: 100%; }
.upload-card-head { display: flex; flex-direction: column; gap: 8px; }
.upload-card h2 {
  font-family: 'Instrument Serif', serif; font-weight: 400;
  font-size: 1.6rem; letter-spacing: -0.01em;
}
.tag {
  display: inline-block; width: fit-content;
  font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--bg);
  background: var(--text); padding: 3px 8px; border-radius: 4px;
  font-weight: 600;
}
.card-desc { color: var(--text-dim); font-size: 13.5px; line-height: 1.55; }

.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: 10px; padding: 44px 20px;
  text-align: center; cursor: pointer;
  transition: all .18s; background: var(--bg);
}
.dropzone:hover, .dropzone.drag { border-color: #4a4a4a; background: var(--surface-2); }
.dropzone svg { color: var(--text-dim); margin-bottom: 12px; }
.dropzone p { font-size: 14px; color: var(--text-dim); }
.dropzone p strong { color: var(--text); font-weight: 500; }
.dz-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px;
}
.file-kind {
  font-size: 9.5px; letter-spacing: 0.1em;
  padding: 2px 6px; border-radius: 3px;
  background: var(--surface-2); color: var(--text-dim);
  flex-shrink: 0;
}
.file-name { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-faint); flex-shrink: 0; }

.upload-actions { display: flex; justify-content: flex-end; }
.btn-primary {
  background: var(--text); color: var(--bg);
  border: 0; border-radius: 9px;
  padding: 11px 22px;
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: opacity .15s, transform .1s;
}
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-primary:active:not(:disabled) { transform: scale(.99); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }
.upload-status { font-size: 13px; color: var(--text-dim); text-align: center; min-height: 20px; }

.upload-info {
  margin-top: 44px;
  display: grid; grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 20px;
}
.info-item {
  display: flex; gap: 14px; align-items: flex-start;
  padding-top: 20px; border-top: 1px solid var(--line);
}
.info-num {
  font-family: 'Instrument Serif', serif;
  font-size: 1.3rem; color: var(--text-faint);
  line-height: 1;
}
.info-item h3 { font-size: 13.5px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.info-item p { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }

/* ABOUT */
.about { border-top: 1px solid var(--line); padding: 80px 20px; }
.about-inner { max-width: 680px; margin: 0 auto; }
.about .display { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-bottom: 18px; }
.about p { color: var(--text-dim); font-size: 15px; line-height: 1.7; max-width: 56ch; }

/* FOOTER */
.footer { border-top: 1px solid var(--line); padding: 24px 20px; }
.footer-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  font-size: 12.5px; color: var(--text-faint);
}
.footer-dim { margin-left: auto; }

/* RESPONSIVE */
@media (max-width: 720px) {
  .nav-inner { gap: 12px; padding: 0 16px; height: 56px; }
  .nav-links { margin-left: 4px; }
  .nav-link { padding: 6px 9px; font-size: 13px; }
  .brand-name { font-size: 14px; }
  .chat-shell { padding: 0 16px; }
  .chat-stream { padding: 28px 0 16px; }
  .empty-state { padding: 20px 0 12px; }
  .suggestions { grid-template-columns: 1fr; }
  .upload-shell { padding: 32px 16px 56px; }
  .upload-info { grid-template-columns: 1fr; gap: 0; }
  .upload-actions { justify-content: stretch; }
  .btn-primary { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}