:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f9faf7;
  --ink: #1f2528;
  --muted: #677274;
  --line: #dce2dc;
  --line-strong: #c5cec7;
  --blue: #28536b;
  --teal: #0f766e;
  --green: #2f7d4f;
  --amber: #a16207;
  --red: #b8462a;
  --shadow: 0 12px 36px rgba(24, 34, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.92);
  backdrop-filter: blur(16px);
}

.topbar div {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.topbar strong {
  font-size: 18px;
  white-space: nowrap;
}

.topbar span {
  color: var(--muted);
  font-size: 13px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(62px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.mode-tabs button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.mode-tabs button.active {
  color: var(--ink);
  background: #e9eee8;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 18px;
}

.results-column {
  display: grid;
  gap: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title.compact {
  margin: 0 0 12px;
  padding: 18px 18px 0;
}

.section-title h1,
.section-title h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.section-title.compact h2,
.surface > h2 {
  margin: 0;
  font-size: 17px;
}

.section-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  background: var(--panel-soft);
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field span,
.range-head span,
.prompt-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input[type="text"] {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.5;
}

textarea[readonly] {
  color: #394346;
  background: #f3f6f2;
}

input[type="text"]:focus,
textarea:focus,
input[type="range"]:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.persona-flow {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.source-grid button {
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 750;
}

.source-grid button.active {
  border-color: rgba(15, 118, 110, 0.45);
  color: var(--ink);
  background: #e6f1ed;
}

.prompt-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.prompt-card > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.prompt-card strong {
  font-size: 14px;
}

.prompt-card textarea {
  min-height: 148px;
  font-size: 12px;
}

.confirm-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8e7;
  color: #5d4a18;
  font-size: 12px;
  line-height: 1.45;
}

.confirm-row input {
  margin-top: 2px;
  accent-color: var(--teal);
}

.warning-text {
  margin: -2px 0 0;
  padding: 10px 11px;
  border-left: 4px solid var(--red);
  background: #fff1ed;
  color: #773421;
  font-size: 12px;
  line-height: 1.45;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 10px 0 0;
  background: linear-gradient(rgba(255, 255, 255, 0), var(--panel) 34%);
}

.primary,
.secondary,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 750;
  white-space: nowrap;
}

.primary {
  color: #fff;
  background: var(--teal);
}

.secondary {
  color: var(--ink);
  border: 1px solid var(--line-strong);
  background: #eef3ee;
}

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

.range-list {
  display: grid;
  gap: 11px;
  padding: 12px 0 4px;
}

.range-control {
  display: grid;
  gap: 7px;
}

.range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-head output {
  min-width: 46px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.preview-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.preview-box h2 {
  margin: 0 0 7px;
  font-size: 15px;
}

.preview-box p {
  margin: 0 0 10px;
  color: var(--blue);
  font-weight: 700;
  line-height: 1.45;
}

pre {
  max-height: 220px;
  margin: 0;
  overflow: auto;
  color: #263238;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  padding: 12px 16px;
}

.status-strip div {
  display: grid;
  gap: 4px;
}

.status-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-strip strong {
  font-size: 14px;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.metric-tile {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-tile span,
.metric-tile small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-tile strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 27px;
  line-height: 1;
}

.accent-blue {
  border-top-color: var(--blue);
}

.accent-green {
  border-top-color: var(--green);
}

.accent-teal {
  border-top-color: var(--teal);
}

.accent-amber {
  border-top-color: var(--amber);
}

.accent-red {
  border-top-color: var(--red);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.chart-box {
  min-height: 274px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.chart {
  display: block;
  width: 100%;
  height: 230px;
}

.grid-line {
  stroke: #dfe5df;
  stroke-width: 1;
}

.axis-line {
  stroke: #b9c3bc;
  stroke-width: 1.2;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.line {
  fill: none;
  stroke-width: 3;
}

.line-blue {
  stroke: var(--blue);
  background: var(--blue);
}

.line-green {
  stroke: var(--green);
  background: var(--green);
}

.line-teal {
  stroke: var(--teal);
  background: var(--teal);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.network-panel {
  padding: 0 18px 18px;
}

.network-map {
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(40, 83, 107, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(15, 118, 110, 0.05) 1px, transparent 1px),
    #fbfcfa;
  background-size: 26px 26px;
}

.network-edge {
  stroke: #7e8b86;
  stroke-width: 1.5;
}

.network-node {
  stroke: #fff;
  stroke-width: 2;
}

.network-node.high {
  fill: var(--green);
}

.network-node.mid {
  fill: var(--blue);
}

.network-node.low {
  fill: var(--red);
}

.network-node.user {
  fill: var(--amber);
  stroke: #1f2528;
  stroke-width: 2.4;
}

.network-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
  margin-top: 16px;
}

.report-panel,
.competition-panel,
.two-column > .surface {
  padding: 18px;
}

.report-panel h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
}

.report-strategy {
  margin: 10px 0 16px;
  color: var(--blue);
  font-weight: 750;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.report-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.report-grid h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li {
  margin: 6px 0;
  color: #394346;
  line-height: 1.45;
}

.caveat {
  margin: 14px 0 0;
  padding: 12px;
  border-left: 4px solid var(--amber);
  background: #fff8e7;
  color: #5d4a18;
  line-height: 1.5;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 460px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

td {
  font-size: 13px;
  font-weight: 650;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.is-user td {
  color: var(--amber);
}

.benchmark-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.benchmark-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(100px, 0.8fr) 62px;
  gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.benchmark-row strong,
.benchmark-row span {
  display: block;
}

.benchmark-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.benchmark-row b {
  text-align: right;
}

.bar-wrap {
  height: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: #e1e7e1;
}

.bar-wrap i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
}

body[data-mode="experiment"] .competition-panel {
  border-top: 4px solid var(--teal);
}

body[data-mode="competition"] .competition-panel {
  border-top: 4px solid var(--amber);
}

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

  .control-panel {
    position: static;
    max-height: none;
  }

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

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 14px;
  }

  .topbar div {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .app-shell {
    padding: 14px;
  }

  .metric-grid,
  .chart-grid,
  .two-column,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .metric-tile {
    min-height: 92px;
  }

  .status-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .benchmark-row {
    grid-template-columns: 1fr;
  }

  .benchmark-row b {
    text-align: left;
  }
}
