:root {
  --ink: #17241f;
  --muted: #627069;
  --paper: #f6f4ee;
  --surface: #fffefa;
  --line: #d9ddd5;
  --moss: #315f4b;
  --moss-dark: #234638;
  --sage: #dfe8de;
  --ochre: #c88b3a;
  --shadow: 0 22px 60px rgba(31, 47, 39, 0.09);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.55;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 4%, rgba(223, 232, 222, 0.8), transparent 28rem),
    linear-gradient(180deg, #faf9f4 0, var(--paper) 42rem);
}

button,
textarea,
select {
  font: inherit;
}

.site-header {
  display: flex;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 28px;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  color: var(--ink);
  text-decoration: none;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: block;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(49, 95, 75, 0.18);
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(22, 42, 34, 0.14);
  object-fit: cover;
  object-position: center;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: -0.02em;
}

.brand small {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.corpus-status {
  display: flex;
  color: var(--muted);
  font-size: 0.83rem;
  align-items: center;
  gap: 8px;
}

.corpus-status i {
  width: 8px;
  height: 8px;
  background: #4e8a63;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(78, 138, 99, 0.13);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 78px 28px 100px;
}

.hero {
  max-width: 810px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--moss);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

h1 {
  max-width: 700px;
  margin: 0;
  font-size: clamp(2.8rem, 7vw, 5.2rem);
  letter-spacing: -0.055em;
  line-height: 0.98;
}

.lede {
  max-width: 610px;
  margin: 26px 0 12px;
  color: var(--muted);
  font-size: 1.08rem;
}

.runtime-note {
  margin: 0 0 38px;
  color: var(--ochre);
  font-size: 0.88rem;
  font-weight: 700;
}

.question-card,
.progress-panel,
.answer-card,
.sources-card {
  border: 1px solid rgba(49, 95, 75, 0.13);
  background: rgba(255, 254, 250, 0.96);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.question-card {
  padding: 18px;
}

.question-card > label {
  display: block;
  margin: 2px 4px 10px;
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  min-height: 132px;
  padding: 14px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.32rem;
  line-height: 1.45;
  outline: none;
  resize: vertical;
}

textarea::placeholder {
  color: #9aa29c;
}

textarea:focus {
  background: #fbfcf8;
  box-shadow: inset 0 0 0 2px var(--sage);
}

.form-footer {
  display: flex;
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  align-items: center;
  justify-content: space-between;
}

.form-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.select-control {
  color: var(--muted);
  font-size: 0.85rem;
}

select {
  margin-left: 8px;
  padding: 8px 28px 8px 10px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

button,
.download-button {
  display: inline-flex;
  padding: 12px 18px;
  color: white;
  background: var(--moss);
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  align-items: center;
  gap: 28px;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

button:hover,
.download-button:hover {
  background: var(--moss-dark);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.error-message {
  margin: 14px 4px 0;
  color: #9c342e;
}

.progress-panel {
  max-width: 810px;
  margin: 32px auto 0;
  padding: 28px;
}

.progress-heading,
.result-header,
.sources-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.progress-heading h2,
.result-header h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  line-height: 1.15;
}

.progress-actions {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 10px;
}

#progress-percent {
  color: var(--moss);
  font-family: Georgia, serif;
  font-size: 1.6rem;
}

.cancel-button {
  padding: 8px 14px;
  color: #9c342e;
  background: transparent;
  border: 1px solid rgba(156, 52, 46, 0.45);
}

.cancel-button:hover {
  color: white;
  background: #9c342e;
}

.cancel-button:disabled {
  cursor: wait;
}

.progress-track {
  height: 7px;
  margin: 24px 0 22px;
  overflow: hidden;
  background: var(--sage);
  border-radius: 99px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--moss), #70917e);
  border-radius: inherit;
  transition: width 320ms ease;
}

.progress-track.indeterminate span {
  width: 35%;
  animation: progress-sweep 1.4s ease-in-out infinite;
}

@keyframes progress-sweep {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(310%);
  }
}

.progress-steps {
  display: grid;
  margin: 0;
  padding: 0;
  grid-template-columns: repeat(4, 1fr);
  list-style: none;
}

.progress-steps li {
  position: relative;
  padding-top: 20px;
  color: #929a95;
  font-size: 0.76rem;
}

.progress-steps li::before {
  position: absolute;
  top: 3px;
  left: 0;
  width: 9px;
  height: 9px;
  background: #cbd1cc;
  border-radius: 50%;
  content: "";
}

.progress-steps li.active,
.progress-steps li.done {
  color: var(--ink);
}

.progress-steps li.active::before,
.progress-steps li.done::before {
  background: var(--ochre);
}

.progress-detail {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.results {
  margin-top: 82px;
}

.result-header {
  margin-bottom: 24px;
  align-items: end;
}

.result-header h2 {
  max-width: 700px;
}

.download-button {
  flex: none;
  background: transparent;
  border: 1px solid var(--moss);
  color: var(--moss);
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(260px, 0.8fr);
  gap: 22px;
  align-items: start;
}

.answer-card,
.sources-card {
  padding: clamp(24px, 5vw, 44px);
}

.answer {
  color: #29352f;
}

.answer h1,
.answer h2,
.answer h3 {
  margin: 1.6em 0 0.55em;
  letter-spacing: -0.025em;
}

.answer h1:first-child,
.answer h2:first-child,
.answer h3:first-child {
  margin-top: 0;
}

.answer p {
  margin: 0 0 1em;
}

.answer li {
  margin-bottom: 0.45em;
}

.sources-card {
  position: sticky;
  top: 20px;
  padding: 26px;
}

.sources-heading {
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.sources-heading h3 {
  margin: 0;
  font-size: 1.35rem;
}

#source-count {
  display: grid;
  width: 30px;
  height: 30px;
  color: var(--moss);
  background: var(--sage);
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 750;
  place-items: center;
}

.sources-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources-list li {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.sources-list li:last-child {
  border-bottom: 0;
}

.source-number {
  color: var(--ochre);
  font-size: 0.72rem;
  font-weight: 800;
}

.source-title {
  display: block;
  margin: 4px 0;
  font-family: Georgia, serif;
  font-size: 1rem;
  line-height: 1.3;
}

a.source-title {
  color: var(--ink);
  text-decoration-color: var(--ochre);
  text-underline-offset: 3px;
}

a.source-title:hover {
  color: var(--moss);
}

.source-reference {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 30px 28px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  main {
    padding-top: 48px;
  }

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

  .sources-card {
    position: static;
  }

  .progress-steps {
    grid-template-columns: 1fr 1fr;
    row-gap: 12px;
  }

  .result-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .site-header,
  main {
    padding-right: 18px;
    padding-left: 18px;
  }

  .corpus-status {
    display: none;
  }

  .form-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  button {
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
