/* ===========================================================================
   Academica — clinical design system
   =========================================================================== */
:root {
  --teal: #0e7c7b;
  --teal-dark: #0a5e5d;
  --teal-50: #e6f3f3;
  --ink: #1c2630;
  --ink-soft: #44525f;
  --muted: #6b7a89;
  --line: #e2e8ee;
  --line-soft: #eef2f6;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f9fbfc;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --shadow-sm: 0 1px 2px rgba(20, 40, 60, .06);
  --shadow: 0 4px 16px rgba(20, 40, 60, .10);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  /* motion */
  --ease-spring: cubic-bezier(.16, 1, .3, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --shadow-glow: 0 10px 40px -8px rgba(14, 124, 123, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.55;
}
[hidden] { display: none !important; }
a { color: var(--teal); }

/* ---- Loading splash ---- */
.app-loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 100;
}
.spinner {
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.big { width: 34px; height: 34px; border-width: 3px; color: var(--teal); }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border: 2px solid #fff; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ---- Buttons ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: none;
  border-radius: var(--radius-sm); padding: 10px 16px; transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--teal); color: #fff; width: 100%; padding: 12px; }
.btn-primary:hover { background: var(--teal-dark); }
.btn:disabled { opacity: .6; cursor: default; }

/* ===========================================================================
   Landing view
   =========================================================================== */
.landing { height: 100%; overflow-y: auto; background: var(--bg); }
.lp-nav {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.lp-nav .brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.lp-nav-cta { display: flex; gap: 8px; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-primary-sm { background: var(--teal); color: #fff; padding: 9px 16px; }
.btn-primary-sm:hover { background: var(--teal-dark); }

.lp-hero {
  max-width: 760px; margin: 0 auto; text-align: center; padding: 64px 24px 40px;
}
.lp-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.lp-logo svg { border-radius: 16px; box-shadow: 0 8px 30px rgba(14,124,123,.28); }
.lp-badge {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--teal-dark); background: var(--teal-50); border: 1px solid #cfe6e5; padding: 5px 12px; border-radius: 20px; margin-bottom: 18px;
}
.lp-hero h1 { font-size: 44px; line-height: 1.1; letter-spacing: -1px; margin: 0 0 18px; }
.grad { background: linear-gradient(100deg, var(--teal), #1aa39c); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lp-sub { font-size: 17px; color: var(--ink-soft); max-width: 620px; margin: 0 auto 28px; line-height: 1.6; }
.lp-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.lp-cta.center { margin-top: 26px; }
.lp-cta .btn-primary { width: auto; padding: 13px 26px; font-size: 15px; }
.lp-cta .btn-ghost { padding: 13px 22px; font-size: 15px; }
.lp-fineprint { font-size: 12.5px; color: var(--muted); margin-top: 20px; }

.lp-features {
  max-width: 1040px; margin: 0 auto; padding: 24px 24px 16px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.lp-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.lp-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #cfe6e5; }
.lp-ico {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px;
  border-radius: 11px; background: var(--teal-50); color: var(--teal-dark); margin-bottom: 14px;
}
.lp-card h3 { font-size: 16px; margin: 0 0 6px; }
.lp-card p { font-size: 13.5px; color: var(--ink-soft); margin: 0; line-height: 1.55; }

.lp-why { max-width: 880px; margin: 0 auto; padding: 48px 24px 24px; text-align: center; }
.lp-why h2 { font-size: 28px; letter-spacing: -.5px; margin: 0 0 28px; }
.lp-why-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; text-align: left; }
.lp-why-item { font-size: 14px; color: var(--ink-soft); line-height: 1.6; padding: 18px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--line-soft); }
.lp-why-item b { color: var(--ink); }
.lp-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 40px 24px; border-top: 1px solid var(--line-soft); margin-top: 32px; }

.auth-back {
  position: absolute; top: 14px; left: 14px; background: none; border: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px;
}
.auth-back:hover { color: var(--ink); background: var(--surface-2); }

@media (max-width: 880px) {
  .lp-features, .lp-why-grid { grid-template-columns: 1fr; }
  .lp-hero h1 { font-size: 34px; }
  .lp-hero { padding-top: 44px; }
}

/* ===========================================================================
   Auth view
   =========================================================================== */
.auth-view {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--teal-50), var(--bg));
}
.auth-card {
  position: relative;
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo { font-size: 40px; }
.auth-brand h1 { margin: 6px 0 2px; font-size: 24px; letter-spacing: -.4px; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.auth-form input {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink);
}
.auth-form input:focus { outline: none; border-color: var(--teal); background: #fff; box-shadow: 0 0 0 3px var(--teal-50); }
.auth-hint, .auth-note { font-size: 12.5px; color: var(--muted); margin: -4px 0 0; }
.auth-note { color: var(--ink-soft); }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.auth-error {
  background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c9c9;
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 14px;
}
.auth-foot { font-size: 12px; color: var(--muted); text-align: center; max-width: 380px; }

/* ===========================================================================
   App layout
   =========================================================================== */
.app-view { display: grid; grid-template-columns: 280px 1fr; height: 100%; }

/* ---- Sidebar ---- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar-head { padding: 14px; border-bottom: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 12px; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; letter-spacing: -.3px; }
.brand-logo { font-size: 18px; }
.btn-new {
  background: var(--teal-50); color: var(--teal-dark); border: 1px solid #cfe6e5;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-size: 14px;
}
.btn-new:hover { background: #d8edec; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-empty { color: var(--muted); font-size: 13px; padding: 16px; text-align: center; }
.conv-item {
  display: flex; align-items: center; border-radius: var(--radius-sm); margin-bottom: 2px;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--teal-50); }
.conv-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  background: none; border: none; cursor: pointer; text-align: left; padding: 9px 10px; font: inherit;
}
.conv-title { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { font-size: 11px; color: var(--muted); }
.conv-actions { display: none; gap: 2px; padding-right: 6px; }
.conv-item:hover .conv-actions, .conv-item.active .conv-actions { display: flex; }
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px;
  width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }
.sidebar-foot {
  border-top: 1px solid var(--line-soft); padding: 10px 12px; display: flex; align-items: center; gap: 8px;
}
.user-chip { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--teal); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-email { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Chat column ---- */
.chat { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.sidebar-toggle { display: none; }
.chat-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-wrap { display: flex; align-items: center; gap: 6px; }
.mode-label { font-size: 12px; color: var(--muted); }
.mode-select {
  font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--surface-2); color: var(--ink-soft);
}

/* ---- Messages ---- */
.messages { flex: 1; overflow-y: auto; padding: 24px 0; scroll-behavior: smooth; }
.loading-conv { text-align: center; color: var(--muted); padding: 40px; }
.error-banner { margin: 20px auto; max-width: 720px; background: var(--danger-soft); color: var(--danger); padding: 12px 16px; border-radius: var(--radius-sm); }

.msg { display: flex; gap: 14px; max-width: 820px; margin: 0 auto 22px; padding: 0 24px; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
}
.msg-avatar.user { background: var(--ink); color: #fff; }
.msg-avatar.assistant { background: none; }
.ico { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.brand-mark, .msg-avatar svg, .welcome-logo svg, .auth-logo svg { display: block; }
.msg-bubble { min-width: 0; flex: 1; padding-top: 3px; }
.msg-user .msg-content { color: var(--ink); white-space: pre-wrap; }
.msg-status { color: var(--muted); font-size: 13.5px; display: flex; flex-direction: column; gap: 4px; }
.msg-status .plan { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.msg-rich { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.error-inline { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; margin-top: 8px; }

/* ---- Welcome ---- */
.welcome { max-width: 640px; margin: 6vh auto; text-align: center; padding: 0 24px; }
.welcome-logo { display: flex; justify-content: center; }
.auth-logo { display: inline-flex; }
.welcome h1 { font-size: 28px; margin: 8px 0 6px; letter-spacing: -.6px; }
.welcome-sub { color: var(--muted); max-width: 460px; margin: 0 auto 26px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestion {
  font: inherit; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; color: var(--ink-soft);
  font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
.suggestion:hover { border-color: var(--teal); box-shadow: var(--shadow-sm); color: var(--ink); }

/* ---- Markdown content ---- */
.markdown { font-size: 15px; color: var(--ink); }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { line-height: 1.3; margin: 18px 0 8px; }
.markdown h3 { font-size: 16px; color: var(--teal-dark); }
.markdown h2 { font-size: 18px; }
.markdown p { margin: 0 0 12px; }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown code { font-family: var(--mono); font-size: .88em; background: var(--line-soft); padding: 1px 5px; border-radius: 4px; }
.markdown pre { background: #0f1b24; color: #e6edf3; padding: 14px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; color: inherit; }
.markdown blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--teal); color: var(--ink-soft); }
.markdown table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 13.5px; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--surface-2); }
.markdown a { text-decoration: underline; }

/* ---- Composer ---- */
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 14px 24px 10px; }
.composer-inner {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  padding: 8px 8px 8px 14px; transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-50); background: #fff; }
.composer-input {
  flex: 1; border: none; background: none; resize: none; font: inherit; font-size: 15px;
  color: var(--ink); max-height: 200px; padding: 6px 0; line-height: 1.5;
}
.composer-input:focus { outline: none; }
.btn-send, .btn-stop {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 9px; padding: 0;
  display: grid; place-items: center; font-size: 16px;
}
.btn-send { background: var(--teal); color: #fff; }
.btn-send:hover { background: var(--teal-dark); }
.btn-stop { background: var(--danger); color: #fff; }
.composer-disclaimer { max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--muted); }

/* ===========================================================================
   Rich blocks (knowledge cards, concept map, sources)
   =========================================================================== */
.rich-block { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.rich-head {
  width: 100%; display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: none; cursor: pointer; padding: 10px 14px; font: inherit; font-weight: 600; font-size: 13.5px; color: var(--ink-soft);
}
.rich-head:hover { background: var(--line-soft); }
.rich-caret { color: var(--muted); font-size: 11px; width: 12px; }
.rich-title { flex: 1; text-align: left; }
.rich-count { background: var(--teal-50); color: var(--teal-dark); font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 20px; }
.rich-body { display: none; }
.rich-block.open .rich-body { display: block; }
.rich-body > * { padding: 12px 14px; border-top: 1px solid var(--line-soft); }
@media (prefers-reduced-motion: no-preference) {
  .rich-block.open .rich-body > * { animation: revealDown .34s var(--ease-out); }
}
@keyframes revealDown { from { opacity: 0; transform: translateY(-7px); } to { opacity: 1; transform: none; } }

/* Knowledge cards */
.kc-list { display: flex; flex-direction: column; gap: 8px; }
.kc { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.kc > summary { list-style: none; cursor: pointer; padding: 10px 12px; }
.kc > summary::-webkit-details-marker { display: none; }
.kc-head { display: flex; align-items: center; gap: 8px; }
.kc-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.kc-title { font-weight: 600; font-size: 14px; }
.kc-cat { font-size: 11px; text-transform: capitalize; font-weight: 600; }
.kc-score { margin-left: auto; font-size: 11px; color: var(--muted); background: #fff; border: 1px solid var(--line); padding: 1px 7px; border-radius: 20px; }
.kc-detail { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.kc-scope { margin: 0; font-size: 13px; color: var(--ink-soft); }
.kc-codes { display: flex; flex-wrap: wrap; gap: 6px; }
.code-chip { font-size: 11px; font-family: var(--mono); background: #fff; border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px; color: var(--ink-soft); }
.code-chip b { color: var(--teal-dark); font-weight: 700; }
.kc-rels { display: flex; flex-direction: column; gap: 6px; }
.kc-rel { display: grid; grid-template-columns: 130px 1fr auto; gap: 8px; font-size: 12.5px; align-items: start; }
.kc-rel-label { font-weight: 600; color: var(--ink-soft); }
.kc-rel-label.critical { color: var(--danger); }
.kc-rel-targets { color: var(--ink); }
.kc-rel-src { color: var(--muted); font-size: 11px; }
.kc-onto { font-size: 11px; color: var(--muted); }
.kc-insights { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.kc-insights-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.kc-insight { font-size: 12.5px; color: var(--ink-soft); padding: 2px 0; }

/* Concept map */
.cm-wrap { display: flex; flex-direction: column; gap: 8px; }
.concept-map { width: 100%; height: auto; background: var(--surface-2); border-radius: var(--radius-sm); }
.cm-label { font-size: 11px; font-family: var(--font); pointer-events: none; }
.cm-node { cursor: default; }
.cm-node:hover circle { stroke: var(--ink); stroke-width: 1.5; }
.cm-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-soft); }
.cm-legend-item { display: flex; align-items: center; gap: 5px; text-transform: capitalize; }
.cm-legend-dot { width: 9px; height: 9px; border-radius: 50%; }

/* Sources */
.src-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.src-item { display: flex; gap: 10px; }
.src-idx { width: 20px; height: 20px; flex-shrink: 0; background: var(--teal-50); color: var(--teal-dark); border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.src-body { min-width: 0; }
.src-title { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.src-meta { font-size: 12px; color: var(--muted); }

/* Figures */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.img-cell { display: flex; flex-direction: column; gap: 4px; text-decoration: none; }
.img-cell img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); }
.img-cap { font-size: 11px; color: var(--muted); }

/* Follow-ups */
.followups { margin-top: 4px; }
.followups-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
.followups-list { display: flex; flex-direction: column; gap: 6px; }
.followup {
  font: inherit; font-size: 13px; text-align: left; cursor: pointer; color: var(--teal-dark);
  background: var(--teal-50); border: 1px solid #cfe6e5; border-radius: 8px; padding: 8px 12px;
}
.followup:hover { background: #d8edec; }

/* ===========================================================================
   Responsive
   =========================================================================== */
@media (max-width: 760px) {
  .app-view { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: grid; }
  .suggestions { grid-template-columns: 1fr; }
  .kc-rel { grid-template-columns: 1fr; gap: 2px; }
  .msg { padding: 0 16px; }
}

/* ===========================================================================
   Premium layer — motion, depth, polish (Apple-vibe)
   =========================================================================== */

/* Global smoothing */
html { scroll-behavior: smooth; }
::selection { background: rgba(14, 124, 123, .18); }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

/* Refined scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(100, 120, 140, .35) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: rgba(100, 120, 140, .32); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(100, 120, 140, .55); border: 3px solid transparent; background-clip: content-box; }

/* Buttons — spring hover, gradient primaries, glow */
.btn { transition: transform .25s var(--ease-spring), box-shadow .25s var(--ease-out), background .2s, opacity .2s, border-color .2s; will-change: transform; }
.btn-primary, .lp-cta .btn-primary { background: linear-gradient(135deg, #129b98, #0a5e5d); box-shadow: var(--shadow-glow); }
.btn-primary:hover, .lp-cta .btn-primary:hover { background: linear-gradient(135deg, #14a8a4, #0a5e5d); box-shadow: 0 14px 40px -8px rgba(14,124,123,.5); transform: translateY(-2px); }
.btn-primary-sm { background: linear-gradient(135deg, #129b98, #0a5e5d); box-shadow: 0 4px 14px rgba(14,124,123,.3); }
.btn-primary-sm:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(14,124,123,.42); }
.btn-send { transition: transform .25s var(--ease-spring), background .2s; }
.btn-send:hover { transform: translateY(-1px) scale(1.05); }
.btn:active { transform: translateY(0) scale(.96); transition-duration: .08s; }
.btn-ghost { transition: background .2s, border-color .2s, transform .25s var(--ease-spring); }
.btn-ghost:hover { transform: translateY(-1px); }
.btn-new:hover { transform: translateY(-1px); }

/* Icon buttons + conversation rows */
.icon-btn { transition: background .18s, color .18s, transform .2s var(--ease-spring); }
.icon-btn:active { transform: scale(.9); }
.conv-item { transition: background .2s var(--ease-out); }
.conv-open, .suggestion, .followup, .src-item, .lp-card, .mode-select { transition: all .25s var(--ease-out); }

/* Inputs — smooth focus */
.auth-form input, .composer-inner, .mode-select { transition: border-color .2s var(--ease-out), box-shadow .25s var(--ease-out), background .2s; }

/* Frosted, layered surfaces */
.auth-card { box-shadow: 0 1px 1px rgba(20,40,60,.04), 0 12px 40px -12px rgba(20,40,60,.22); }
.chat-head { backdrop-filter: saturate(1.4) blur(6px); background: rgba(255,255,255,.82); }

/* Animated thinking spinner → softer */
.msg-status .spinner { color: var(--teal); }

/* ---- Keyframes ---- */
@keyframes viewIn { from { opacity: 0; transform: translateY(10px) scale(.994); } to { opacity: 1; transform: none; } }
@keyframes floatIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes nodePulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.18); opacity: .8; } }
@keyframes meshDrift { 0% { transform: translate(0,0) scale(1); } 50% { transform: translate(4%, 3%) scale(1.12); } 100% { transform: translate(0,0) scale(1); } }
@keyframes sheen { from { background-position: -150% 0; } to { background-position: 250% 0; } }

/* Hero ambient gradient mesh */
.lp-hero { position: relative; isolation: isolate; }
.lp-hero::before {
  content: ''; position: absolute; z-index: -1; top: -180px; left: 50%; width: 900px; height: 700px;
  transform: translateX(-50%);
  background:
    radial-gradient(420px 320px at 38% 30%, rgba(20,168,160,.30), transparent 70%),
    radial-gradient(420px 360px at 66% 42%, rgba(59,108,183,.20), transparent 70%),
    radial-gradient(360px 300px at 52% 12%, rgba(14,124,123,.22), transparent 70%);
  filter: blur(34px); pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  /* View transitions (re-fire on display:none -> visible) */
  #landing-view:not([hidden]), #auth-view:not([hidden]), #app-view:not([hidden]) { animation: viewIn .55s var(--ease-spring) both; }

  /* Landing hero staggered reveal */
  .lp-logo   { animation: floatIn .7s var(--ease-spring) both; }
  .lp-badge  { animation: floatIn .7s var(--ease-spring) .08s both; }
  .lp-hero h1{ animation: floatIn .8s var(--ease-spring) .15s both; }
  .lp-sub    { animation: floatIn .8s var(--ease-spring) .24s both; }
  .lp-hero .lp-cta { animation: floatIn .8s var(--ease-spring) .33s both; }
  .lp-fineprint    { animation: floatIn .8s var(--ease-spring) .42s both; }

  /* Living logo (hero only) */
  .lp-logo .brand-mark { animation: floatIn .7s var(--ease-spring) both, logoFloat 6s var(--ease-in-out) 1s infinite; }
  .lp-logo .brand-mark circle { transform-box: fill-box; transform-origin: center; animation: nodePulse 3.2s var(--ease-in-out) infinite; }
  .lp-logo .brand-mark circle:nth-of-type(1) { animation-delay: 0s; }
  .lp-logo .brand-mark circle:nth-of-type(2) { animation-delay: .35s; }
  .lp-logo .brand-mark circle:nth-of-type(3) { animation-delay: .7s; }
  .lp-logo .brand-mark circle:nth-of-type(4) { animation-delay: 1.05s; }

  /* Ambient mesh drift */
  .lp-hero::before { animation: meshDrift 16s var(--ease-in-out) infinite; }

  /* Hero primary CTA sheen */
  .lp-hero .lp-cta .btn-primary { position: relative; overflow: hidden; }
  .lp-hero .lp-cta .btn-primary::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.35) 50%, transparent 65%);
    background-size: 250% 100%; animation: sheen 5.5s ease-in-out 2s infinite;
  }

  /* Messages + welcome + rich blocks entrance */
  .msg { animation: msgIn .5s var(--ease-out) both; }
  .welcome { animation: viewIn .6s var(--ease-spring) both; }
  .msg-rich .rich-block { animation: popIn .4s var(--ease-out) both; }

  /* Scroll-reveal (class added by JS) */
  .reveal { opacity: 0; transform: translateY(28px); transition: opacity .8s var(--ease-out), transform .8s var(--ease-spring); }
  .reveal.in { opacity: 1; transform: none; }
}

/* Card hover refined */
.lp-card:hover { transform: translateY(-5px); box-shadow: 0 20px 45px -18px rgba(20,40,60,.30); border-color: #bfe0df; }
.lp-card .lp-ico { transition: transform .3s var(--ease-spring), background .25s; }
.lp-card:hover .lp-ico { transform: scale(1.08) rotate(-3deg); background: #d6ecec; }
.suggestion:hover { transform: translateY(-2px); }
.followup:hover { transform: translateX(2px); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ===========================================================================
   View modes (reading-area layout) — set via data-view on .chat
   =========================================================================== */

/* Wide — reclaim the side margins */
.chat[data-view="wide"] .msg,
.chat[data-view="wide"] .composer-inner,
.chat[data-view="wide"] .composer-disclaimer { max-width: 1180px; }

/* ---- Glass 3D — experimental layered translucent panels ---- */
.chat[data-view="glass"] { position: relative; overflow: hidden; }
.chat[data-view="glass"]::before {
  content: ''; position: absolute; inset: -10%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(700px 520px at 16% 0%, rgba(20,168,160,.20), transparent 60%),
    radial-gradient(680px 560px at 92% 22%, rgba(59,108,183,.18), transparent 60%),
    radial-gradient(620px 520px at 60% 108%, rgba(125,60,181,.14), transparent 60%),
    radial-gradient(520px 420px at 38% 60%, rgba(14,124,123,.12), transparent 60%);
  filter: blur(8px);
}
.chat[data-view="glass"] .chat-head { position: relative; z-index: 3; background: rgba(255,255,255,.7); }
.chat[data-view="glass"] .messages {
  position: relative; z-index: 1; background: transparent;
  perspective: 1700px; perspective-origin: 50% 22%;
}
.chat[data-view="glass"] .composer {
  position: relative; z-index: 3;
  background: rgba(255,255,255,.62); backdrop-filter: blur(14px) saturate(1.4);
}

.chat[data-view="glass"] .msg { max-width: 1040px; transform-style: preserve-3d; }
.chat[data-view="glass"] .msg-avatar {
  transition: transform .45s var(--ease-spring), box-shadow .45s;
  box-shadow: 0 10px 24px -10px rgba(20,40,60,.5);
}
.chat[data-view="glass"] .msg-bubble {
  padding: 18px 24px; border-radius: 20px;
  background: rgba(255,255,255,.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  border: 1px solid rgba(255,255,255,.65);
  box-shadow: 0 26px 60px -26px rgba(20,40,60,.5), inset 0 1px 0 rgba(255,255,255,.75);
  transform: rotateX(1.4deg) translateZ(0);
  transform-style: preserve-3d;
  transition: transform .5s var(--ease-spring), box-shadow .5s var(--ease-out);
}
.chat[data-view="glass"] .msg:hover .msg-bubble {
  transform: rotateX(0deg) translateZ(46px);
  box-shadow: 0 44px 96px -30px rgba(20,40,60,.55), inset 0 1px 0 rgba(255,255,255,.85);
}
.chat[data-view="glass"] .msg:hover .msg-avatar { transform: translateZ(60px); }
/* User panels = solid teal glass; assistant = clear glass */
.chat[data-view="glass"] .msg-user .msg-bubble {
  background: linear-gradient(135deg, rgba(16,138,136,.85), rgba(10,94,93,.85));
  border-color: rgba(255,255,255,.28);
}
.chat[data-view="glass"] .msg-user .msg-content { color: #fff; }
/* Rich blocks become translucent too, so layers read as glass-on-glass */
.chat[data-view="glass"] .rich-block { background: rgba(255,255,255,.5); border-color: rgba(255,255,255,.6); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.chat[data-view="glass"] .rich-head { background: rgba(255,255,255,.35); }
.chat[data-view="glass"] .kc, .chat[data-view="glass"] .concept-map, .chat[data-view="glass"] .lp-card { background: rgba(255,255,255,.45); }

@media (prefers-reduced-motion: no-preference) {
  .chat[data-view="glass"]::before { animation: meshDrift 18s var(--ease-in-out) infinite; }
  /* gentle entrance for the layered panels */
  .chat[data-view="glass"] .msg-bubble { animation: glassIn .6s var(--ease-spring) both; }
}
@keyframes glassIn { from { opacity: 0; transform: rotateX(8deg) translateZ(-40px); } to { opacity: 1; transform: rotateX(1.4deg) translateZ(0); } }

/* Header can hold two selects — let it wrap gracefully on narrow screens */
@media (max-width: 620px) {
  .chat-head { flex-wrap: wrap; row-gap: 6px; }
  .chat-head .chat-title { flex-basis: 100%; order: -1; }
}

/* ===========================================================================
   Deck view — swipeable stack of page-cards
   =========================================================================== */
.deck-layer { display: none; flex: 1; position: relative; overflow: hidden; min-height: 0; }
.chat[data-view="deck"] .messages { display: none; }
.chat[data-view="deck"] .deck-layer { display: flex; align-items: center; justify-content: center; }
.chat[data-view="deck"] .deck-layer {
  background:
    radial-gradient(680px 480px at 18% 0%, rgba(20,168,160,.10), transparent 60%),
    radial-gradient(640px 520px at 92% 30%, rgba(59,108,183,.10), transparent 60%);
}

.deck-empty { color: var(--muted); font-size: 14px; }

.deck-stackwrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.deck-stack { position: relative; width: min(720px, 90%); height: min(78%, 660px); }

/* Table of contents rail (left margin) */
.deck-toc {
  display: none; position: absolute; left: 22px; top: 50%; transform: translateY(-50%); z-index: 55;
  flex-direction: column; gap: 2px; width: 152px; max-height: 80%; overflow-y: auto; padding: 6px;
}
.deck-toc-item {
  display: flex; align-items: center; gap: 9px; width: 100%; cursor: pointer; text-align: left;
  font: inherit; color: var(--muted); background: none; border: none; padding: 7px 10px; border-radius: 9px;
  transition: background .18s, color .18s;
}
.deck-toc-item:hover { background: rgba(255, 255, 255, .7); color: var(--ink-soft); }
.deck-toc-item.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.deck-toc-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.deck-toc-dot.crit { background: var(--danger); }
.deck-toc-dot.ess { background: var(--teal); }
.deck-toc-dot.act { background: #3b6cb7; }
.deck-toc-dot.det { background: #7d3cb5; }
.deck-toc-dot.note, .deck-toc-dot.ref { background: #6b7a89; }
.deck-toc-dot.q { background: var(--ink); }
.deck-toc-item.active .deck-toc-dot { box-shadow: 0 0 0 3px rgba(14, 124, 123, .18); }
.deck-toc-txt { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Bottom nav bar (prev · counter · next) */
.deck-navbar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .85); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 24px; padding: 5px 8px; box-shadow: var(--shadow-sm);
}
.deck-navbar .deck-nav { position: static; transform: none; width: 34px; height: 34px; border: none; background: transparent; box-shadow: none; }
.deck-navbar .deck-nav:hover { transform: none; background: var(--surface-2); }
.deck-navbar .deck-counter { position: static; transform: none; border: none; background: none; box-shadow: none; padding: 0 4px; min-width: 42px; text-align: center; }

@media (min-width: 1180px) {
  .chat[data-view="deck"] .deck-toc { display: flex; }
  .chat[data-view="deck"] .deck-stackwrap { padding-left: 165px; }
}

.deck-card {
  position: absolute; inset: 0; overflow: auto; box-sizing: border-box;
  /* background + blur driven by the see-through slider (--deck-glass: 0..1) */
  background: rgba(255, 255, 255, calc(1 - var(--deck-glass, 0) * 0.74));
  -webkit-backdrop-filter: blur(calc(var(--deck-glass, 0) * 16px)) saturate(1.3);
  backdrop-filter: blur(calc(var(--deck-glass, 0) * 16px)) saturate(1.3);
  border: 1px solid rgba(170, 188, 200, calc(0.35 + var(--deck-glass, 0) * 0.4));
  border-radius: 22px;
  padding: 50px 38px 34px; box-shadow: 0 34px 80px -28px rgba(20, 40, 60, .42), 0 2px 6px rgba(20,40,60,.06);
  transform-origin: center bottom; will-change: transform, opacity;
  touch-action: pan-y; cursor: grab; -webkit-user-select: none; user-select: none;
}
/* the top (focused) card in priority mode gets a subtle accent rail */
.deck-card:has(.deck-tier.crit) { box-shadow: 0 34px 80px -28px rgba(214,69,69,.3), inset 3px 0 0 var(--danger); }
.deck-card:has(.deck-tier.ess) { box-shadow: 0 34px 80px -28px rgba(14,124,123,.3), inset 3px 0 0 var(--teal); }

/* Importance tier pill */
.deck-tier {
  position: absolute; top: 18px; left: 24px; z-index: 2;
  font-size: 10px; font-weight: 800; letter-spacing: .7px; text-transform: uppercase;
  padding: 3px 10px; border-radius: 20px;
}
.deck-tier.crit { background: var(--danger-soft); color: var(--danger); }
.deck-tier.ess  { background: var(--teal-50); color: var(--teal-dark); }
.deck-tier.act  { background: #e7eefb; color: #3b6cb7; }
.deck-tier.note { background: #eef2f6; color: #6b7a89; }
.deck-tier.det  { background: #f3eef8; color: #7d3cb5; }
.deck-tier.ref  { background: #eef2f6; color: #6b7a89; }
.deck-tier.q    { background: #e9edf0; color: var(--ink); }

/* Order toggle (Priority / Reading) */
.deck-order {
  position: absolute; top: 12px; left: 16px; z-index: 60;
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.85); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 20px; padding: 4px 6px 4px 12px; box-shadow: var(--shadow-sm);
}
.deck-order-label { font-size: 11px; font-weight: 700; color: var(--muted); }
.deck-order-btn {
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; border: none;
  background: transparent; color: var(--ink-soft); padding: 4px 10px; border-radius: 14px;
  transition: background .2s, color .2s;
}
.deck-order-btn.on { background: var(--teal); color: #fff; }
.deck-order-btn:not(.on):hover { background: var(--surface-2); }
.deck-card:active { cursor: grabbing; }
.deck-card::-webkit-scrollbar { width: 8px; }

.deck-page-no {
  position: absolute; top: 16px; right: 20px; font-size: 12px; font-weight: 700;
  color: var(--teal); opacity: .5;
}
.deck-card-body { font-size: 16px; line-height: 1.62; }
.deck-card-body > *:first-child { margin-top: 0; }
.deck-q { font-weight: 700; color: var(--teal-dark); font-size: 19px; line-height: 1.35; margin-bottom: 4px; letter-spacing: -.2px; }
.deck-card-body .rich-block { margin-top: 12px; }

.deck-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 60;
  width: 46px; height: 46px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px); color: var(--ink-soft); font-size: 24px; line-height: 1;
  box-shadow: var(--shadow-sm); transition: transform .2s var(--ease-spring), background .2s;
}
.deck-nav:hover { background: #fff; transform: translateY(-50%) scale(1.08); color: var(--teal-dark); }
.deck-nav:active { transform: translateY(-50%) scale(.94); }
.deck-nav.prev { left: 10px; }
.deck-nav.next { right: 10px; }

.deck-counter {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 60;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: rgba(255, 255, 255, .85); padding: 4px 12px; border-radius: 20px; border: 1px solid var(--line);
}
.deck-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60;
  font-size: 11px; color: var(--muted); letter-spacing: .2px;
}
.deck-glass-ctrl {
  position: absolute; top: 12px; right: 16px; z-index: 60;
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: rgba(255, 255, 255, .85); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px;
  font-size: 11px; font-weight: 600; color: var(--muted); box-shadow: var(--shadow-sm);
}
.deck-glass-ctrl input[type="range"] { width: 96px; accent-color: var(--teal); cursor: pointer; }

@media (max-width: 620px) { .deck-card { padding: 26px 24px; } .deck-glass-ctrl { top: 8px; right: 8px; } }
