:root {
  --paper: #ffffff;
  --ink: #050505;
  --soft: #6a6a6a;
  --line: #8f8f8f;
  --ghost: #f4f4f4;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.stage {
  position: relative;
  min-height: 100vh;
  background:
    linear-gradient(90deg, transparent 0 49.95%, rgba(0, 0, 0, 0.025) 50%, transparent 50.05%),
    var(--paper);
}

.ready-screen,
.work-screen {
  min-height: 100vh;
  transition:
    opacity 520ms var(--ease),
    transform 760ms var(--ease),
    filter 520ms var(--ease);
}

.ready-screen {
  display: grid;
  place-items: center;
  padding: 24px;
}

.prompt-form {
  position: relative;
  display: grid;
  justify-items: center;
  transform: translateY(-18px);
  animation: floatIn 900ms var(--ease) both;
}

.prompt-form::after {
  content: "";
  position: absolute;
  right: -58px;
  bottom: -34px;
  width: 112px;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  animation: drawLine 900ms var(--ease) 420ms both;
}

.prompt-form h1 {
  margin: 0 0 18px;
  font-size: clamp(2rem, 4vw, 2.65rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}

.prompt-line {
  position: relative;
  width: min(360px, calc(100vw - 48px));
}

.prompt-line input {
  width: 100%;
  min-height: 56px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  text-align: center;
  outline: 0;
  box-shadow: 0 10px 38px rgba(0, 0, 0, 0);
  transition:
    border-color 220ms ease,
    box-shadow 220ms ease,
    transform 220ms ease;
}

.prompt-line input::placeholder {
  color: var(--ink);
  opacity: 1;
}

.prompt-line input:focus {
  border-color: var(--ink);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.prompt-line button {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
}

.work-screen {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 25.4vw);
  opacity: 0;
  pointer-events: none;
  transform: translateY(28px);
}

.research-side {
  position: relative;
  min-height: 100vh;
  padding: 31px 48px 72px 58px;
  overflow: auto;
}

.research-heading {
  display: flex;
  align-items: flex-start;
  gap: 26px;
}

.research-heading h2 {
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 1.9rem);
  font-weight: 400;
  line-height: 1.28;
  letter-spacing: 0;
}

#progress-label {
  min-height: 22px;
  margin: 9px 0 0;
  color: var(--soft);
  font-size: 0.95rem;
  opacity: 0;
  transform: translateX(-10px);
  transition:
    opacity 260ms ease,
    transform 260ms ease;
}

.is-loading #progress-label {
  opacity: 1;
  transform: translateX(0);
}

.report-output {
  width: min(820px, 100%);
  margin-top: clamp(64px, 15vh, 148px);
  font-size: clamp(1rem, 1.65vw, 1.28rem);
  line-height: 1.55;
  white-space: pre-wrap;
}

.report-output h1,
.report-output h2,
.report-output h3,
.report-output p,
.report-output ul,
.report-output ol {
  margin: 0 0 16px;
}

.report-output h1 {
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  font-weight: 400;
}

.report-output h2 {
  margin-top: 26px;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
}

.report-output a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.report-output .cursor {
  display: inline-block;
  width: 10px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--ink);
  animation: blink 850ms steps(2, start) infinite;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  font-size: clamp(1.2rem, 2vw, 1.65rem);
}

.actions button {
  padding: 0 3px;
  font-weight: 400;
  transition:
    transform 180ms ease,
    background-color 180ms ease,
    color 180ms ease;
}

.actions button:hover:not(:disabled),
.actions button:focus-visible:not(:disabled) {
  color: #fff;
  background: var(--ink);
  transform: translateY(-2px);
  outline: 0;
}

.actions button:disabled {
  color: #9b9b9b;
  cursor: not-allowed;
}

.citation-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 26px;
  min-height: 100vh;
  padding: 68px 34px 40px;
  border-left: 1px solid var(--line);
  transform: translateX(34px);
  transition: transform 760ms var(--ease);
  overflow: hidden;
}

.citation-side h2 {
  margin: 0 0 38px;
  font-size: clamp(2.2rem, 4vw, 2.8rem);
  line-height: 1;
  text-align: center;
}

#citations-list {
  display: grid;
  gap: 18px;
  margin: 0;
  padding-left: 24px;
  font-size: 0.98rem;
  line-height: 1.4;
  max-height: calc(100vh - 230px);
  overflow: auto;
}

#citations-list li {
  opacity: 0;
  transform: translateX(18px);
  animation: citationIn 460ms var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * 90ms);
}

#citations-list a {
  color: var(--ink);
  word-break: break-word;
}

.stage[data-state="work"] .ready-screen,
.stage[data-state="loading"] .ready-screen {
  opacity: 0;
  pointer-events: none;
  filter: blur(6px);
  transform: scale(0.98) translateY(-28px);
}

.stage[data-state="work"] .work-screen,
.stage[data-state="loading"] .work-screen {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.stage[data-state="work"] .citation-side,
.stage[data-state="loading"] .citation-side {
  transform: translateX(0);
}

.stage[data-state="ready"] .work-screen {
  visibility: hidden;
}

.stage[data-state="ready"] .ready-screen {
  visibility: visible;
}

.stage[data-state="loading"] .report-output::before {
  content: "";
  display: block;
  width: min(360px, 72vw);
  height: 2px;
  background: linear-gradient(90deg, var(--ink), var(--ghost), var(--ink));
  background-size: 220% 100%;
  animation: loadingLine 1.1s linear infinite;
}

.stage[data-state="loading"] .report-output {
  min-height: 60px;
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(-18px);
  }
}

@keyframes drawLine {
  to {
    transform: scaleX(1);
  }
}

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

@keyframes loadingLine {
  to {
    background-position: -220% 0;
  }
}

@keyframes citationIn {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (max-width: 820px) {
  .work-screen {
    position: absolute;
    grid-template-columns: 1fr;
  }

  .research-side {
    min-height: 58vh;
    padding: 28px 24px 52px;
  }

  .report-output {
    width: 100%;
    margin-top: 46px;
  }

  .actions {
    flex-wrap: wrap;
  }

  .citation-side {
    min-height: 42vh;
    padding: 30px 24px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

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