:root {
  --bg: #f7f3ea;
  --bg-alt: #ece6d7;
  --card: #fffdf7;
  --ink: #152423;
  --muted: #596867;
  --line: #d6cfbd;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-alt: #d97706;
  --accent-soft: #fde8c8;
  --danger: #b91c1c;
  --shadow: 0 18px 42px rgba(15, 39, 38, 0.11);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(circle at 8% 10%, rgba(15, 118, 110, 0.12), transparent 38%),
    radial-gradient(circle at 88% 6%, rgba(217, 119, 6, 0.12), transparent 28%),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-alt) 100%);
  min-height: 100vh;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(21, 36, 35, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 36, 35, 0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.75), transparent 90%);
}

.site-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 2.8rem 1.2rem 1rem;
  position: relative;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 700;
}

h1,
h2,
h3 {
  font-family: "Fraunces", serif;
  line-height: 1.14;
  margin-top: 0;
}

h1 {
  margin-bottom: 0.4rem;
  font-size: clamp(2rem, 4.4vw, 3.4rem);
}

.subtitle {
  margin: 0;
  max-width: 860px;
  color: var(--muted);
}

.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.2rem 2.2rem;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(430px, 1.1fr);
  gap: 1.45rem;
}

.card {
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--card) 94%, white 6%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.34rem;
  backdrop-filter: blur(3px);
}

.card-head p {
  margin: 0;
  color: var(--muted);
}

.editor-shell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 0.85rem;
  background:
    radial-gradient(circle at 18% 0%, rgba(15, 118, 110, 0.08), transparent 38%),
    linear-gradient(180deg, #fffefb 0%, #f7f2e6 100%);
}

.editor-topbar {
  margin-top: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.editor-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid #b7c9bc;
  background: #effaf4;
  color: #0e5c4e;
  border-radius: 999px;
  padding: 0.18rem 0.62rem;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-small {
  padding: 0.42rem 0.76rem;
  font-size: 0.79rem;
}

.editor-hint {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.arrow-context-grid {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.arrow-context-field {
  display: block;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #fcf8ef;
  padding: 0.5rem;
}

.arrow-context-field span {
  display: block;
  font-size: 0.8rem;
  color: #315451;
  font-weight: 700;
}

.editor-stage {
  min-height: 700px;
}

.editor-frame {
  width: 100%;
  height: 700px;
  border: 0;
  display: block;
  background: #f8f5ed;
}

.editor-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 245, 0.9);
  color: var(--muted);
  font-weight: 600;
  z-index: 3;
}

.details-panel {
  margin-top: 0.85rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  background: #f8f4ea;
}

.details-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent-strong);
}

textarea {
  margin-top: 0.6rem;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: #fffdf8;
  color: var(--ink);
  padding: 0.72rem;
  font-family: inherit;
  resize: vertical;
}

.arrow-context-field textarea {
  margin-top: 0.36rem;
  min-height: 72px;
  background: #fffef9;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.58rem 1rem;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.17s ease, filter 0.17s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(0.99);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
}

.btn-secondary {
  background: #1e3a3a;
  color: #f0fff9;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

.status-line {
  min-height: 1.4rem;
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.status-line.error {
  color: var(--danger);
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 300px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.05), rgba(217, 119, 6, 0.05));
}

.empty-state p {
  max-width: 460px;
  color: var(--muted);
}

.block {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fffdf8;
  padding: 1.18rem;
  margin-bottom: 1.18rem;
  animation: rise 280ms ease both;
  overflow: hidden;
}

.block h3 {
  margin: 1.15rem 0 0.62rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.56rem;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.mode-pill {
  background: var(--accent-soft);
  color: #7c4305;
  border: 1px solid #f2c384;
  border-radius: 999px;
  padding: 0.2rem 0.62rem;
  font-size: 0.82rem;
}

.confidence-grid {
  display: grid;
  grid-template-columns: minmax(122px, 160px) 1fr;
  gap: 0.75rem;
  align-items: center;
}

.score-gauge {
  --score: 0;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto;
  background:
    radial-gradient(closest-side, #fffdf8 74%, transparent 75% 100%),
    conic-gradient(var(--accent) calc(var(--score) * 1%), #d7ddd6 0);
}

.score-gauge span {
  font-family: "Fraunces", serif;
  font-size: 1.9rem;
  font-weight: 600;
}

.formula-label {
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.confidence-help-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.help-dot {
  width: 1.35rem;
  height: 1.35rem;
  border: 1px solid #9ab2a5;
  border-radius: 999px;
  background: #eef7f3;
  color: #104e46;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  margin-top: 0.1rem;
}

.help-popover {
  margin-top: 0.45rem;
  background: #f3efe5;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.62rem;
}

.help-popover p {
  margin: 0 0 0.36rem;
  color: #3a524f;
  font-size: 0.82rem;
}

.formula {
  display: block;
  white-space: normal;
  background: #fcf9f1;
  border: 1px solid #d2cab9;
  border-radius: 0.65rem;
  padding: 0.55rem;
  font-size: 0.79rem;
}

.component-bars {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.metric-row {
  display: grid;
  grid-template-columns: 160px 1fr 46px;
  align-items: center;
  gap: 0.48rem;
  font-size: 0.84rem;
}

.metric-bar {
  height: 9px;
  border-radius: 99px;
  background: #e3e6df;
  overflow: hidden;
}

.metric-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-alt) 100%);
}

.hypothesis {
  margin: 0.34rem 0 1.06rem;
  line-height: 1.56;
}

.fundamental-steps {
  margin: 0.2rem 0 1rem;
  padding-left: 1.25rem;
}

.fundamental-steps li {
  margin: 0 0 0.48rem;
  line-height: 1.48;
}

.tri-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
  align-items: start;
}

.claim-card {
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: #fffcf3;
  padding: 0.62rem;
  margin-bottom: 0.5rem;
}

.claim-card h4 {
  margin: 0 0 0.38rem;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.claim-card p {
  margin: 0;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.claim-meta {
  margin-top: 0.42rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8d4cc;
  border-radius: 999px;
  padding: 0.14rem 0.52rem;
  font-size: 0.75rem;
  background: #f0fbf8;
  color: #0f4b48;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.34;
}

.chip.warn {
  border-color: #f0c58f;
  background: #fff4e6;
  color: #975204;
}

.flat-list {
  padding-left: 1.2rem;
  margin: 0.3rem 0 0;
}

#follow-up {
  display: grid;
  gap: 0.56rem;
}

.follow-item label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.follow-item input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.58rem;
  background: #fffdfa;
  color: var(--ink);
  padding: 0.46rem 0.55rem;
  font-family: inherit;
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.96rem;
  align-items: flex-start;
}

#query-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem;
  margin-top: 1.34rem;
  margin-bottom: 1rem;
}

.query-chip {
  border-radius: 0.68rem;
  padding: 0.36rem 0.58rem;
  display: block;
  max-width: none;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.32;
}

.source-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffcf5;
  padding: 0.78rem;
  margin-bottom: 0.92rem;
  overflow-wrap: anywhere;
}

.source-card h4 {
  margin: 0;
  font-size: 0.92rem;
}

.source-card a {
  color: var(--accent-strong);
  text-decoration: none;
}

.source-card a:hover {
  text-decoration: underline;
}

.source-meta {
  color: var(--muted);
  margin: 0.35rem 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

.source-abstract {
  margin: 0;
  font-size: 0.84rem;
}

.synthesis-figure {
  margin-top: 0.45rem;
  width: 100%;
  height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #fffef9;
}

.synthesis-card {
  background: #fffdfa;
}

.synthesis-redraw {
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: transparent;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 1.3fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
}

.synth-side {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
  align-items: center;
}

.skeletal-box {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  text-align: center;
  min-width: 0;
}

.skeletal-canvas-wrap {
  min-height: 230px;
  width: 100%;
  overflow: hidden;
}

.skeletal-canvas {
  width: 100%;
  height: 230px;
  display: block;
  background: transparent;
}

.skeletal-empty {
  min-height: 230px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed #d8d0bd;
  border-radius: 0.62rem;
  color: #5a6f6b;
  font-size: 0.82rem;
  padding: 0.6rem;
}

.synth-struct-label {
  margin: 0.16rem 0 0;
  font-size: 0.76rem;
  color: #32524f;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.synth-arrow-zone {
  text-align: center;
  min-width: 0;
}

.synth-arrow-line {
  margin: 0.24rem 0;
  font-size: 0.86rem;
  color: #32524f;
  overflow-wrap: anywhere;
  line-height: 1.32;
  min-width: 0;
}

.synth-arrow {
  height: 0;
  border-top: 2px solid #135f59;
  position: relative;
  margin: 0.34rem 0;
}

.synth-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -6px;
  border-left: 9px solid #135f59;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.synthesis-figure-wrap {
  border: 1px solid var(--line);
  border-radius: 0.62rem;
  background: #fbfaf4;
  padding: 0.45rem;
}

.synthesis-figure-fallback {
  min-height: 120px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0.8rem;
  color: var(--muted);
  font-size: 0.84rem;
  border: 1px dashed var(--line);
  border-radius: 0.52rem;
}

.table-scroll {
  overflow-x: auto;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--line);
  padding: 0.54rem;
  text-align: left;
  vertical-align: top;
  font-size: 0.84rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.matrix-table th {
  background: #f4efe1;
}

.site-footer {
  max-width: 1240px;
  margin: 0 auto;
  color: var(--muted);
  padding: 0.4rem 1.2rem 1.8rem;
  font-size: 0.85rem;
}

.list-status {
  margin: 0.5rem 0 0.78rem;
}

.breakdown-list {
  margin: 0.45rem 0 1.24rem;
  padding-left: 1.35rem;
}

.breakdown-list li {
  margin-bottom: 0.52rem;
  line-height: 1.45;
}

#literature-load-more,
#synthesis-load-more {
  margin-top: 0.45rem;
  margin-bottom: 0.75rem;
}

@media (max-width: 1450px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .tri-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .editor-stage {
    min-height: 580px;
  }

  .editor-frame {
    height: 580px;
  }

  .synthesis-redraw {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .arrow-context-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .tri-grid {
    grid-template-columns: 1fr;
  }

  #query-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .metric-row {
    grid-template-columns: 110px 1fr 40px;
    font-size: 0.78rem;
  }

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

  .score-gauge {
    width: 112px;
    height: 112px;
  }

  .score-gauge span {
    font-size: 1.45rem;
  }

  .editor-stage {
    min-height: 500px;
  }

  .editor-frame {
    height: 500px;
  }

  .action-row {
    width: 100%;
  }

  .action-row .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }
}
