:root {
  --ink: #13100d;
  --ink-2: #1b1713;
  --ink-3: #241e18;
  --parchment: #e9dfc8;
  --parchment-dim: #b7ab92;
  --muted: #847a68;
  --gold: #c09a5b;
  --gold-soft: rgba(192, 154, 91, 0.28);
  --gold-faint: rgba(192, 154, 91, 0.12);
  --oxblood: #8a3a2b;
  --line: rgba(233, 223, 200, 0.09);

  --f-display: "IM Fell English SC", "Times New Roman", serif;
  --f-fell: "IM Fell English", "Times New Roman", serif;
  --f-body: "Newsreader", Georgia, serif;
  --f-mono: "Fragment Mono", ui-monospace, monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(ellipse 80% 60% at 70% 20%, #211a13 0%, transparent 60%),
    radial-gradient(ellipse 60% 70% at 0% 100%, #1d1510 0%, transparent 60%),
    var(--ink);
  color: var(--parchment);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection {
  background: var(--gold);
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Atmosphere ---------- */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 50;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.2s steps(4) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1%); }
  50% { transform: translate(1%, -2%); }
  75% { transform: translate(2%, 2%); }
  100% { transform: translate(0, 0); }
}

.rings {
  position: fixed;
  z-index: 0;
  width: 1400px;
  height: 1400px;
  right: -520px;
  top: -420px;
  pointer-events: none;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 69px, rgba(192, 154, 91, 0.05) 69px 70px);
  mask-image: radial-gradient(circle, #000 20%, transparent 68%);
  -webkit-mask-image: radial-gradient(circle, #000 20%, transparent 68%);
}

/* ---------- Layout ---------- */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  height: 100dvh;
}

/* ---------- Colophon ---------- */
.colophon {
  display: flex;
  flex-direction: column;
  gap: 2.2rem;
  padding: 2.6rem 2.2rem 2rem;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(27, 23, 19, 0.6), rgba(19, 16, 13, 0.2));
  overflow-y: auto;
}

.sigil-wrap {
  width: 168px;
  aspect-ratio: 1;
  margin-left: -8px;
  opacity: 0;
  animation: rise 1.4s var(--ease) 0.1s forwards;
}

.sigil {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sigil * {
  fill: none;
  stroke: var(--gold);
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
}

.sigil .ticks {
  stroke-dasharray: 1 4.6;
  stroke-width: 5;
  opacity: 0.6;
}

.sigil .faint {
  opacity: 0.38;
}

.sigil .node {
  fill: var(--gold);
  stroke: none;
}

.sigil-core rect {
  fill: var(--gold-faint);
}

.sigil-outer {
  transform-origin: 100px 100px;
  animation: spin 120s linear infinite;
}

.sigil-inner {
  transform-origin: 100px 100px;
  animation: spin 80s linear infinite reverse;
}

body.thinking .sigil-outer { animation-duration: 9s; }
body.thinking .sigil-inner { animation-duration: 6s; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.brand {
  opacity: 0;
  animation: rise 1.2s var(--ease) 0.3s forwards;
}

.eyebrow,
.empty-kicker,
.ledger dt,
.model-chip,
.head-meta,
.fineprint,
.msg-label {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 0.9rem;
  color: var(--gold);
}

.wordmark {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 2.85rem;
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--parchment);
}

.wordmark span {
  display: inline-block;
  padding-left: 1.1em;
  color: var(--gold);
}

.tagline {
  margin: 1.2rem 0 0;
  max-width: 24ch;
  font-family: var(--f-fell);
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.45;
  color: var(--parchment-dim);
}

.ledger {
  margin: 0;
  display: grid;
  gap: 0.15rem;
  border-top: 1px solid var(--line);
  opacity: 0;
  animation: rise 1.2s var(--ease) 0.5s forwards;
}

.ledger > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.62rem 0;
  border-bottom: 1px solid var(--line);
}

.ledger dt {
  color: var(--muted);
}

.ledger dd {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 0.76rem;
  color: var(--parchment-dim);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 var(--gold-soft);
  animation: pulse 2.4s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(192, 154, 91, 0.45); }
  100% { box-shadow: 0 0 0 9px rgba(192, 154, 91, 0); }
}

.new-inquiry {
  margin-top: auto;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.05rem;
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  background: transparent;
  color: var(--parchment);
  font-family: var(--f-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease), transform 0.15s;
}

.new-inquiry svg {
  width: 12px;
  height: 12px;
  stroke: var(--gold);
  stroke-width: 1.4;
}

.new-inquiry:hover {
  background: var(--gold-faint);
  border-color: var(--gold);
}

.new-inquiry:active {
  transform: translateY(1px);
}

/* ---------- Chamber ---------- */
.chamber {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}

.chamber-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem clamp(1.25rem, 4vw, 3.5rem);
  border-bottom: 1px solid var(--line);
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.38rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--parchment-dim);
}

.model-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7d9a6a;
}

.head-meta {
  color: var(--muted);
}

.thread {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem clamp(1.25rem, 6vw, 5.5rem) 2rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-3) transparent;
}

.thread > * {
  max-width: 760px;
}

/* ---------- Empty state ---------- */
.empty {
  padding-top: clamp(1rem, 7vh, 5rem);
}

.empty > * {
  opacity: 0;
  animation: rise 1.1s var(--ease) forwards;
}

.empty > :nth-child(1) { animation-delay: 0.35s; }
.empty > :nth-child(2) { animation-delay: 0.45s; }
.empty > :nth-child(3) { animation-delay: 0.6s; }
.empty > :nth-child(4) { animation-delay: 0.75s; }

.empty-kicker {
  margin: 0 0 1rem;
  color: var(--gold);
}

.empty-title {
  margin: 0;
  font-family: var(--f-fell);
  font-weight: 400;
  font-size: clamp(2.8rem, 6.5vw, 5.2rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
}

.empty-title em {
  display: inline-block;
  padding-left: clamp(1.5rem, 6vw, 5rem);
  color: var(--gold);
}

.empty-copy {
  margin: 1.6rem 0 2.4rem;
  max-width: 52ch;
  color: var(--parchment-dim);
  font-weight: 300;
}

.suggestions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}

.suggestions li:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.suggestions button {
  width: 100%;
  height: 100%;
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  padding: 1.05rem 1.1rem 1.05rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--parchment);
  font-family: var(--f-body);
  font-size: 0.98rem;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: color 0.25s, background 0.25s, padding 0.35s var(--ease);
}

.suggestions li:nth-child(even) button {
  padding-left: 1.1rem;
}

.suggestions button span {
  flex: none;
  width: 2.2em;
  font-family: var(--f-fell);
  font-style: italic;
  color: var(--gold);
}

.suggestions button:hover {
  background: linear-gradient(90deg, var(--gold-faint), transparent);
  padding-left: 0.7rem;
}

.suggestions li:nth-child(even) button:hover {
  padding-left: 1.8rem;
}

/* ---------- Messages ---------- */
.msg {
  margin: 0 0 2.4rem;
  animation: rise 0.7s var(--ease) both;
}

.msg-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
  color: var(--muted);
}

.msg-label svg {
  width: 16px;
  height: 16px;
}

.msg-label svg * {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.2;
}

.msg.user {
  margin-left: auto;
  max-width: min(560px, 88%);
}

.msg.user .msg-label {
  justify-content: flex-end;
}

.msg.user .msg-body {
  padding: 0.95rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(36, 30, 24, 0.7);
  color: var(--parchment);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.archivist .msg-label {
  color: var(--gold);
}

.msg.archivist .msg-body {
  padding-left: 1.5rem;
  border-left: 1px solid var(--gold-soft);
  overflow-wrap: anywhere;
}

.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }

.msg.archivist .msg-body > p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.12em 0 0;
  font-family: var(--f-fell);
  font-size: 3.3em;
  line-height: 0.82;
  color: var(--gold);
}

.msg-body p { margin: 0 0 0.95em; }

.msg-body h1,
.msg-body h2,
.msg-body h3,
.msg-body h4 {
  margin: 1.5em 0 0.5em;
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.msg-body strong {
  font-weight: 600;
  color: #f3ead6;
}

.msg-body em {
  font-style: italic;
}

.msg-body ul,
.msg-body ol {
  margin: 0 0 1em;
  padding-left: 1.3em;
}

.msg-body li {
  margin: 0.3em 0;
  padding-left: 0.3em;
}

.msg-body ul li::marker {
  content: "✦  ";
  color: var(--gold);
  font-size: 0.7em;
}

.msg-body ol li::marker {
  font-family: var(--f-fell);
  font-style: italic;
  color: var(--gold);
}

.msg-body code {
  font-family: var(--f-mono);
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  background: var(--ink-3);
  border-radius: 2px;
}

.msg-body pre {
  padding: 1rem;
  background: var(--ink-2);
  border: 1px solid var(--line);
  overflow-x: auto;
}

.msg-body pre code {
  padding: 0;
  background: none;
}

.msg-body blockquote {
  margin: 0 0 1em;
  padding: 0.2em 0 0.2em 1em;
  border-left: 2px solid var(--oxblood);
  font-family: var(--f-fell);
  font-style: italic;
  color: var(--parchment-dim);
}

.msg-body hr {
  border: 0;
  height: 1px;
  margin: 1.6em 0;
  background: linear-gradient(90deg, var(--gold-soft), transparent);
}

.cursor {
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--gold);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Loading */
.consulting {
  display: grid;
  gap: 0.9rem;
}

.consulting-status {
  font-family: var(--f-fell);
  font-style: italic;
  color: var(--parchment-dim);
}

.consulting-status::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.4s steps(4) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.skeleton {
  height: 0.7rem;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--ink-3) 0%, #33291f 40%, var(--ink-3) 80%);
  background-size: 300% 100%;
  animation: shimmer 1.8s linear infinite;
}

.skeleton:nth-child(2) { width: 92%; }
.skeleton:nth-child(3) { width: 78%; }
.skeleton:nth-child(4) { width: 54%; }

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -200% 0; }
}

.msg-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  color: #d9a091;
  font-style: italic;
}

.msg-error button {
  padding: 0.35rem 0.8rem;
  border: 1px solid rgba(217, 160, 145, 0.4);
  background: transparent;
  color: var(--parchment);
  font-family: var(--f-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.msg-error button:hover {
  background: rgba(138, 58, 43, 0.25);
}

/* ---------- Composer ---------- */
.composer {
  padding: 0.6rem clamp(1.25rem, 6vw, 5.5rem) max(1.2rem, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--ink) 35%);
}

.composer-box {
  max-width: 760px;
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.55rem 0.55rem 0.55rem 1.15rem;
  border: 1px solid var(--gold-soft);
  border-radius: 3px;
  background: rgba(27, 23, 19, 0.92);
  box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(233, 223, 200, 0.04);
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

.composer-box:focus-within {
  border-color: var(--gold);
  box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.8), 0 0 0 3px var(--gold-faint);
}

.composer textarea {
  flex: 1;
  min-height: 2.6rem;
  max-height: 12rem;
  padding: 0.55rem 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--parchment);
  font-family: var(--f-body);
  font-size: 1.05rem;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: var(--muted);
  font-style: italic;
}

.send {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border: 0;
  border-radius: 2px;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}

.send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send:hover { background: #d4b077; }
.send:active { transform: scale(0.95); }
.send:disabled { opacity: 0.35; cursor: default; }

body.thinking .send .i-send { display: none; }
body.thinking .send .i-stop { display: block; }
body.thinking .send { background: var(--parchment-dim); opacity: 1; cursor: pointer; }

.fineprint {
  max-width: 760px;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.6rem;
}

/* ---------- Motion ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .sigil-outer,
  .sigil-inner,
  .grain { animation: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .colophon {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .sigil-wrap {
    width: 46px;
    margin: 0;
  }

  .eyebrow,
  .tagline,
  .ledger {
    display: none;
  }

  .wordmark {
    font-size: 1.35rem;
    line-height: 1;
  }

  .wordmark br { display: none; }
  .wordmark span { padding-left: 0.25em; }

  .new-inquiry {
    margin: 0 0 0 auto;
    align-self: center;
    padding: 0.55rem 0.75rem;
    font-size: 0.64rem;
  }

  .chamber {
    height: auto;
    min-height: 0;
  }

  .chamber-head {
    display: none;
  }

  .thread {
    padding-top: 1.6rem;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .suggestions li:nth-child(odd) {
    border-right: 0;
  }

  .suggestions li:nth-child(even) button {
    padding-left: 0;
  }

  .suggestions li:nth-child(even) button:hover {
    padding-left: 0.7rem;
  }

  .fineprint span:first-child {
    display: none;
  }
}

@media (max-width: 480px) {
  .new-inquiry {
    font-size: 0;
    gap: 0;
    padding: 0.6rem;
  }

  .new-inquiry svg {
    width: 14px;
    height: 14px;
  }

  .msg.user {
    max-width: 94%;
  }

  .msg.archivist .msg-body {
    padding-left: 1rem;
  }
}
