:root {
  color-scheme: dark;
  --bg: #1f1e1b;
  --bg-soft: #252421;
  --text: #ece5da;
  --muted: #a39c92;
  --quiet: #736d64;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --accent-strong: #ee9b78;
  --peach: #f2b79e;
  --input: rgba(255, 255, 255, 0.055);
  --focus: #e7a17f;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Spline Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.4, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  overflow-x: hidden;
}

/* Soft vignette + top light */
body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  opacity: 0.5;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.05), transparent 30rem),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02), transparent 18rem);
}

/* Film grain */
body::after {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  content: "";
  opacity: 0.05;
  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.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Slow drifting ambient color */
.ambient {
  position: fixed;
  inset: -22%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(42rem 32rem at 16% 14%, rgba(217, 119, 87, 0.07), transparent 66%),
    radial-gradient(48rem 36rem at 84% 86%, rgba(124, 150, 156, 0.055), transparent 68%);
  animation: ambient-drift 32s ease-in-out infinite alternate;
}

@keyframes ambient-drift {
  from {
    transform: translate3d(-2.5%, -2%, 0) scale(1);
  }

  to {
    transform: translate3d(2.5%, 2%, 0) scale(1.06);
  }
}

/* Light that trails the cursor */
.cursor-glow {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, rgba(217, 119, 87, 0.075), transparent 62%);
  transition:
    transform 480ms var(--ease-out),
    opacity 800ms ease;
}

.cursor-glow.is-awake {
  opacity: 1;
}

/* Progress rail across the top */
.progress-rail {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  height: 2px;
  background: rgba(255, 255, 255, 0.05);
  transition: opacity 900ms ease;
}

.progress-rail.is-complete {
  opacity: 0;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(to right, var(--accent), var(--accent-strong));
  box-shadow: 0 0 12px rgba(217, 119, 87, 0.55);
  transition: width 1100ms var(--ease-out);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  padding: 30px clamp(18px, 4vw, 56px) 56px;
}

/* Entrance choreography for the static intro */
.enter {
  animation: enter-rise 950ms var(--ease-out) both;
}

.enter-1 { animation-delay: 60ms; }
.enter-2 { animation-delay: 320ms; }
.enter-3 { animation-delay: 640ms; }
.enter-4 { animation-delay: 940ms; }

@keyframes enter-rise {
  from {
    opacity: 0;
    transform: translateY(18px);
    filter: blur(7px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

.company-context {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
}

.company-context.has-kicker {
  flex-direction: column;
  gap: 12px;
}

.context-kicker {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--quiet);
}

.context-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.company-logo img {
  width: 100%;
  height: 100%;
  padding: 7px;
  box-sizing: border-box;
  object-fit: contain;
  border-radius: inherit;
}

.company-logo .logo-letter {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.company-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    0 10px 30px rgba(0, 0, 0, 0.25);
}

.company-logo svg {
  width: 25px;
  height: 25px;
}

.company-context p {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.42rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.company-context span {
  color: var(--muted);
  font-size: 0.96rem;
}

.conversation {
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 26px;
  width: min(650px, 100%);
  padding-block: 48px;
}

.message-line,
.upload-zone,
.file-line,
.working-block,
.facts,
.action-row,
.cover-area,
.save-area,
.sent-banner {
  opacity: 0;
  transform: translateY(16px);
}

.message-line.is-visible,
.upload-zone.is-visible,
.file-line.is-visible,
.working-block.is-visible,
.facts.is-visible,
.action-row.is-visible,
.cover-area.is-visible,
.save-area.is-visible,
.sent-banner.is-visible {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 780ms ease,
    transform 780ms var(--ease-out);
}

.message-line {
  display: block;
}

p {
  overflow-wrap: anywhere;
}

/* The assistant speaks in a serif voice */
.message-title,
.stream-text {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(1.06rem, 2.2vw, 1.22rem);
  font-weight: 500;
  letter-spacing: 0.002em;
  line-height: 1.55;
}

/* Streamed words fade in individually */
.w {
  display: inline-block;
  opacity: 0;
  transform: translateY(5px);
  filter: blur(4px);
  animation: word-in 380ms var(--ease-out) forwards;
}

@keyframes word-in {
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

/* Live caret while streaming */
.stream-text.is-streaming::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.02em;
  margin-left: 4px;
  vertical-align: -0.16em;
  border-radius: 2px;
  background: var(--accent);
  animation: caret-blink 950ms steps(2, jump-none) infinite;
}

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

.message-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  animation: note-in 550ms ease both;
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Upload zone ---------- */

.upload-zone {
  justify-self: center;
  width: min(340px, 100%);
  margin-block: 2px 12px;
}

.upload-target {
  position: relative;
  display: grid;
  place-items: center;
  gap: 13px;
  min-height: 190px;
  padding: 28px 20px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition:
    border-color 240ms ease,
    background 240ms ease,
    transform 240ms var(--ease-spring);
}

.upload-target:hover {
  border-color: rgba(217, 119, 87, 0.5);
  background: rgba(217, 119, 87, 0.045);
}

.upload-target.is-dragging {
  border-color: var(--accent);
  background: rgba(217, 119, 87, 0.09);
  transform: scale(1.025);
}

.upload-target input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-orbit {
  position: relative;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border-radius: 22px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 18px 50px rgba(0, 0, 0, 0.24);
  transition:
    transform 240ms var(--ease-spring),
    box-shadow 240ms ease;
}

/* Breathing halo behind the icon */
.upload-orbit::before {
  position: absolute;
  inset: -14px;
  content: "";
  border-radius: 30px;
  background: radial-gradient(circle, rgba(217, 119, 87, 0.18), transparent 70%);
  animation: breathe 3.4s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.92);
  }

  50% {
    opacity: 1;
    transform: scale(1.06);
  }
}

.upload-orbit svg {
  position: relative;
  width: 42px;
  height: 42px;
  animation: icon-float 4.2s ease-in-out infinite;
}

@keyframes icon-float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

.upload-target:hover .upload-orbit,
.upload-target.is-dragging .upload-orbit {
  transform: translateY(-3px);
  box-shadow:
    inset 0 0 0 1px rgba(217, 119, 87, 0.45),
    0 20px 55px rgba(0, 0, 0, 0.3);
}

.upload-text {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 550;
}

.upload-hint {
  margin-top: -7px;
  color: var(--quiet);
  font-size: 0.84rem;
}

/* ---------- File + working log ---------- */

.file-line {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 550;
}

.file-icon {
  color: var(--accent);
}

.working-block {
  color: var(--muted);
}

.working-block summary {
  width: fit-content;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.working-block summary::-webkit-details-marker {
  display: none;
}

.working-block summary::after {
  content: "  expand";
  color: var(--quiet);
  font-size: 0.78rem;
  font-weight: 500;
}

.working-block[open] summary::after {
  content: "";
}

.work-list {
  display: grid;
  gap: 9px;
  padding: 13px 0 0;
  margin: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.86rem;
}

.work-step {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  min-height: 24px;
  color: var(--quiet);
  transition: color 400ms ease;
}

.work-step.is-active {
  color: var(--text);
}

.work-step.is-done {
  color: var(--muted);
}

.work-mark {
  display: inline-block;
  color: var(--accent);
}

.work-step.is-done .work-mark {
  animation: mark-pop 320ms var(--ease-spring);
}

@keyframes mark-pop {
  0% {
    transform: scale(0.3);
  }

  70% {
    transform: scale(1.3);
  }

  100% {
    transform: scale(1);
  }
}

.work-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(217, 119, 87, 0.3);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

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

/* ---------- Extracted facts ---------- */

.facts {
  display: grid;
  gap: 18px;
}

.fact-section {
  display: grid;
  gap: 13px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 18px;
}

.fact-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.fact-section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: baseline;
}

.fact-kicker,
.fact-status {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.fact-kicker {
  color: var(--quiet);
}

.fact-status {
  color: #8fae9b;
}

.fact-section-title {
  margin: 3px 0 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 620;
  line-height: 1.16;
}

.fact-section-summary {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.fact-section-body {
  display: grid;
  gap: 8px;
}

.fact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.025);
}

.fact-row.needs-review {
  background: rgba(217, 119, 87, 0.08);
  box-shadow: inset 0 0 0 1px rgba(217, 119, 87, 0.22);
}

.fact-row.needs-review .fact-note {
  color: var(--accent);
}

.fact-value {
  min-width: 0;
}

.fact-value p {
  margin: 0;
  font-weight: 550;
}

.fact-note {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
}

.skill-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.skill-chip {
  width: fit-content;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
}

.skill-edit {
  justify-self: start;
}

.skill-input {
  min-height: 120px;
  resize: vertical;
}

.edit-button,
.ghost-button,
.pill-button,
.text-button,
.file-upload-button {
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 600;
}

.edit-button {
  padding: 0;
  text-underline-offset: 4px;
  transition: color 160ms ease;
}

.edit-button:hover,
.ghost-button:hover,
.text-button:hover {
  color: var(--accent-strong);
}

.edit-button:hover {
  text-decoration: underline;
}

.fact-input {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 9px;
  padding: 6px 10px;
  background: var(--input);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* ---------- Buttons ---------- */

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.answer-row .fact-input {
  width: auto;
  flex: 1 1 240px;
  min-height: 42px;
  padding: 8px 14px;
}

.pill-button {
  min-height: 42px;
  padding: 0 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(217, 119, 87, 0.22), rgba(217, 119, 87, 0.12));
  box-shadow: inset 0 0 0 1px rgba(217, 119, 87, 0.28);
  color: var(--peach);
  transition:
    transform 200ms var(--ease-spring),
    box-shadow 200ms ease,
    background 200ms ease,
    color 200ms ease;
}

.pill-button:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, rgba(217, 119, 87, 0.3), rgba(217, 119, 87, 0.18));
  box-shadow:
    inset 0 0 0 1px rgba(217, 119, 87, 0.5),
    0 10px 28px rgba(217, 119, 87, 0.16);
  color: #ffd9c4;
}

.pill-button:active {
  transform: translateY(0) scale(0.97);
}

.pill-button.is-selected {
  background: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  color: #241410;
}

.file-upload-button {
  position: relative;
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  color: var(--muted);
  cursor: pointer;
  transition:
    transform 200ms var(--ease-spring),
    background 200ms ease,
    color 200ms ease;
}

.file-upload-button:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.file-upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.ghost-button {
  min-height: 42px;
  padding: 0 10px;
  color: var(--muted);
  transition: color 160ms ease;
}

/* ---------- Cover letter ---------- */

.cover-area {
  display: grid;
  gap: 14px;
}

.cover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.cover-editor {
  min-height: 180px;
  width: 100%;
  resize: vertical;
  border: 0;
  border-radius: 15px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
  transition: box-shadow 220ms ease;
}

.cover-editor:focus {
  box-shadow: inset 0 0 0 1px rgba(217, 119, 87, 0.45);
}

.cover-editor::placeholder {
  color: var(--quiet);
}

.cover-file-status {
  min-height: 1.35em;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

/* ---------- Sent banner + save ---------- */

.sent-banner {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding-top: 6px;
}

.sent-check {
  width: 46px;
  height: 46px;
  color: var(--accent);
}

.sent-check circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-dasharray: 152;
  stroke-dashoffset: 152;
  animation: draw-stroke 700ms 150ms var(--ease-out) forwards;
}

.sent-check path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: draw-stroke 450ms 750ms var(--ease-out) forwards;
}

@keyframes draw-stroke {
  to {
    stroke-dashoffset: 0;
  }
}

.sent-banner p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sent-banner span {
  color: var(--muted);
  font-size: 0.95rem;
}

.save-area {
  display: grid;
  gap: 14px;
}

.save-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  color: var(--muted);
  list-style: none;
}

.save-list li {
  animation: note-in 550ms ease both;
}

.save-list li:nth-child(1) { animation-delay: 120ms; }
.save-list li:nth-child(2) { animation-delay: 240ms; }
.save-list li:nth-child(3) { animation-delay: 360ms; }
.save-list li:nth-child(4) { animation-delay: 480ms; }

.save-list li::before {
  content: "✓ ";
  color: var(--accent);
}

/* ---------- Confetti ---------- */

.confetti {
  position: fixed;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -5vh;
  left: var(--x);
  width: 8px;
  height: 13px;
  opacity: 0;
  animation: confetti-fall var(--d) var(--delay) cubic-bezier(0.22, 0.4, 0.62, 0.98) forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(var(--s));
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--sway), 108vh, 0) rotate(var(--r)) scale(var(--s));
  }
}

.is-hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .app {
    padding: 22px 18px 40px;
  }

  .conversation {
    align-self: start;
    padding-top: 54px;
  }

  .company-logo {
    width: 42px;
    height: 42px;
  }

  .company-context p {
    font-size: 1.22rem;
  }

  .fact-section-head,
  .fact-row {
    grid-template-columns: 1fr;
  }

  .edit-button {
    justify-self: start;
  }

  .cursor-glow {
    display: none;
  }
}

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

  .cursor-glow,
  .confetti {
    display: none;
  }
}
