:root {
  --bg: #ffffff;
  --ink: #11151c;
  --ink-soft: #525b67;
  --ink-faint: #8b94a0;
  --line: #e8eaee;
  --line-soft: #f1f2f5;
  --accent: #3b4cca;
  --accent-soft: #eef0ff;
  --good: #1f9d57;
  --gold: #b8860b;
  --shadow: 0 1px 2px rgba(16, 21, 28, 0.04), 0 8px 28px rgba(16, 21, 28, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 480px at 50% -8%, #f7f8ff 0%, rgba(255, 255, 255, 0) 60%),
    var(--bg);
  min-height: 100vh;
}

.shell {
  max-width: 940px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* ---------- Masthead ---------- */
.masthead { text-align: center; margin-bottom: 38px; }
.mark { display: inline-flex; margin-bottom: 14px; }
.mark svg { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mark circle { fill: var(--accent-soft); }
h1 {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 44px;
  letter-spacing: -0.5px;
  margin: 0 0 10px;
}
.tagline {
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.55;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.input-card { padding: 26px; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 7px;
}
textarea, input[type="number"], input[type="password"], input[type="text"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%238b94a0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.field-sm { width: 120px; flex: none; margin-bottom: 16px; }
.field-provider { width: 170px; flex: none; margin-bottom: 16px; }
.field-key { flex: 1; min-width: 220px; margin-bottom: 16px; }

.primary {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 15.5px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.05s, background 0.15s, opacity 0.15s;
}
.primary:hover { background: #3140b5; }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.55; cursor: progress; }
.primary.running { background: var(--ink); }

.hint { font-size: 13px; color: var(--ink-faint); margin: 10px 2px 0; min-height: 16px; }
.hint.error { color: #c0392b; }

/* ---------- Phases ---------- */
.process { margin-top: 30px; }
.phases {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.phase {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fff;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.phase.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.phase.done { background: #fbfdfb; }
.phase-name {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.phase.active .phase-name { color: var(--accent); }
.phase-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.phase.active .phase-dot { background: var(--accent); animation: pulse 1.3s infinite; }
.phase.done .phase-dot { background: var(--good); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.agent { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 14px; color: var(--ink-soft); }
.agent .a-dot {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); background: #fff; transition: all 0.2s;
}
.agent.run .a-dot { border-color: var(--accent); border-right-color: transparent; animation: spin 0.7s linear infinite; }
.agent.done .a-dot { border-color: var(--good); background: var(--good); }
.agent.done { color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panes ---------- */
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pane { padding: 18px 20px; min-height: 220px; }
.pane-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-faint); margin: 0 0 14px;
}

.timeline { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.timeline li {
  position: relative; padding: 0 0 13px 18px; font-size: 13.5px; line-height: 1.45; color: var(--ink-soft);
  border-left: 2px solid var(--line-soft); margin-left: 3px;
}
.timeline li::before {
  content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.timeline li b { color: var(--ink); font-weight: 600; }
.timeline li.err::before { background: #c0392b; }

.leaderboard { list-style: none; margin: 0 0 14px; padding: 0; counter-reset: lb; }
.leaderboard li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  font-size: 14px; margin-bottom: 4px; background: var(--line-soft); transition: background 0.25s;
}
.leaderboard li.empty { color: var(--ink-faint); background: transparent; font-size: 13px; }
.leaderboard li .lb-rank {
  width: 22px; height: 22px; border-radius: 6px; background: #fff; border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--ink-soft); flex: none;
}
.leaderboard li.top .lb-rank { background: var(--accent); color: #fff; border-color: var(--accent); }
.leaderboard li .lb-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li .lb-elo { font-variant-numeric: tabular-nums; color: var(--ink-faint); font-size: 12.5px; font-weight: 600; }

.matches { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; }
.matches li { font-size: 12.5px; color: var(--ink-faint); padding: 5px 0; border-top: 1px solid var(--line-soft); line-height: 1.4; }
.matches li b { color: var(--ink-soft); }

/* ---------- Results ---------- */
.results { margin-top: 34px; }
.results-head { text-align: center; margin-bottom: 22px; }
.results-head h2 {
  font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 30px; margin: 0 0 12px;
}
.synthesis {
  color: var(--ink-soft); font-size: 14.5px; line-height: 1.6; max-width: 640px; margin: 0 auto;
  background: var(--accent-soft); border-radius: 12px; padding: 14px 18px; text-align: left;
}

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; justify-content: center; }
.tab {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 16px;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-soft); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; transition: all 0.15s;
}
.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab .tab-elo { font-size: 11px; opacity: 0.75; font-variant-numeric: tabular-nums; }

.paper {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 64px 52px 44px; position: relative;
}
.paper-actions {
  position: absolute; top: 18px; right: 18px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
}
.act {
  border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 7px 13px;
  font: inherit; font-size: 12.5px; font-weight: 500; color: var(--ink-soft); cursor: pointer;
  transition: all 0.15s;
}
.act:hover { border-color: var(--accent); color: var(--accent); }
.act-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.act-primary:hover { background: #3140b5; color: #fff; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg-btn {
  border: none; background: #fff; padding: 7px 13px; font: inherit; font-size: 12.5px;
  font-weight: 500; color: var(--ink-soft); cursor: pointer; transition: all 0.15s;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { color: var(--accent); }
.seg-btn.on { background: var(--accent); color: #fff; }

.writing { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--accent); font-weight: 500; }
.mini-spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-right-color: var(--accent); animation: spin 0.7s linear infinite;
}

.paper table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; }
.paper th, .paper td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.paper thead { background: var(--line-soft); }
.paper th { font-weight: 600; color: var(--ink); }

/* Markdown */
.paper h1 { font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 30px; line-height: 1.2; margin: 4px 0 18px; letter-spacing: -0.3px; }
.paper h2 { font-size: 19px; margin: 30px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line-soft); }
.paper h3 { font-size: 16px; margin: 22px 0 8px; }
.paper p, .paper li { font-size: 15px; line-height: 1.72; color: #28303b; }
.paper ul, .paper ol { padding-left: 22px; }
.paper li { margin: 4px 0; }
.paper strong { color: var(--ink); font-weight: 600; }
.paper em { color: var(--ink-soft); }
.paper code {
  background: var(--line-soft); padding: 2px 6px; border-radius: 5px; font-size: 13.5px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.paper hr { border: none; border-top: 1px solid var(--line); margin: 26px 0; }
.paper a { color: var(--accent); text-decoration: none; }
.paper a:hover { text-decoration: underline; }
.paper .pending { color: var(--ink-faint); font-style: italic; }

.spinner-line { display: inline-flex; align-items: center; gap: 9px; color: var(--ink-faint); font-size: 14px; }
.spinner-line::before {
  content: ""; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line); border-right-color: var(--accent); animation: spin 0.7s linear infinite;
}

/* ---------- Footer ---------- */
.foot { text-align: center; margin-top: 50px; color: var(--ink-faint); font-size: 12.5px; }
.foot .privacy { display: block; margin-top: 8px; max-width: 560px; margin-left: auto; margin-right: auto; line-height: 1.5; }

@media (max-width: 760px) {
  .phases { grid-template-columns: 1fr; }
  .panes { grid-template-columns: 1fr; }
  .paper { padding: 30px 24px; }
  h1 { font-size: 36px; }
}
