:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef3f4;
  --ink: #172126;
  --muted: #607079;
  --line: #d9e0e3;
  --teal: #087f8c;
  --green: #3b8b5f;
  --coral: #d85545;
  --gold: #d79b28;
  --violet: #6e5aa8;
  --shadow: 0 18px 50px rgba(23, 33, 38, 0.11);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(8, 127, 140, 0.12), transparent 28%),
    linear-gradient(315deg, rgba(216, 85, 69, 0.10), transparent 28%),
    var(--bg);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 16px;
  max-width: 1500px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand > div:last-child {
  min-width: 0;
}

.brand h1,
.brand p,
.stage-header h2,
.composer-panel h2,
.atlas-panel h2,
.feed h3 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.05;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.brand-mark span:nth-child(1) {
  translate: -11px -9px;
  background: var(--teal);
}

.brand-mark span:nth-child(2) {
  translate: 12px -1px;
  background: var(--coral);
}

.brand-mark span:nth-child(3) {
  translate: -1px 13px;
  background: var(--gold);
}

.top-actions,
.composer-actions,
.form-actions,
.stage-meta,
.reflection-metrics {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(290px, 360px);
  gap: 16px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}

.composer-panel,
.probe-stage,
.atlas-panel,
.reflection-band {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.composer-panel,
.atlas-panel {
  padding: 16px;
}

.probe-stage {
  padding: 18px;
  min-width: 0;
}

.panel-kicker {
  margin-bottom: 6px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.composer-panel h2,
.atlas-panel h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

.field-group {
  padding: 0;
  margin: 18px 0 14px;
  border: 0;
}

.field-group legend,
.input-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.mechanism-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mechanism-button {
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.mechanism-button:hover {
  transform: translateY(-1px);
  border-color: rgba(8, 127, 140, 0.55);
}

.mechanism-button.is-selected {
  border-color: var(--teal);
  background: #e9f6f7;
}

.mechanism-button span,
.mechanism-button small {
  display: block;
}

.mechanism-button span {
  font-weight: 800;
}

.mechanism-button small {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.25;
}

select,
textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

select,
input[type="text"],
input[type="number"] {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
  min-height: 106px;
  padding: 11px;
  line-height: 1.45;
}

.composer-actions {
  margin-top: 12px;
  align-items: stretch;
}

.composer-actions button {
  flex: 1 1 0;
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 40px;
  border-radius: var(--radius);
  font-weight: 800;
}

.primary-button {
  border: 1px solid #066b76;
  background: var(--teal);
  color: #ffffff;
  box-shadow: 0 10px 28px rgba(8, 127, 140, 0.24);
}

.primary-button:hover {
  background: #066b76;
}

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

.ghost-button:hover,
.text-button:hover {
  border-color: rgba(216, 85, 69, 0.65);
  color: var(--coral);
}

.text-button {
  min-height: 32px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 4px;
}

.consent-rail {
  margin-top: 16px;
  padding: 13px;
  border-left: 4px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: #edf7f1;
}

.consent-rail strong {
  display: block;
  margin-bottom: 5px;
}

.consent-rail p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.stage-header h2 {
  max-width: 72ch;
  font-size: clamp(1.35rem, 2.3vw, 2.35rem);
  line-height: 1.1;
}

.stage-meta {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stage-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.stimulus-area {
  display: grid;
  gap: 12px;
  min-height: 210px;
  margin-bottom: 14px;
}

.stimulus-box,
.response-panel,
.insight-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stimulus-box {
  padding: 16px;
}

.stimulus-box strong {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.stimulus-box p {
  margin: 0;
  line-height: 1.55;
  font-size: 1rem;
}

.stimulus-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.option-box {
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.option-box b {
  display: block;
  margin-bottom: 8px;
  color: var(--coral);
}

.response-panel {
  padding: 16px;
}

.response-fields {
  display: grid;
  gap: 14px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(130px, 190px) minmax(0, 1fr) 54px;
  gap: 12px;
  align-items: center;
}

.range-row label {
  color: var(--muted);
  font-weight: 800;
}

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

.range-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  text-align: right;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.choice-tile {
  display: block;
  min-height: 118px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.choice-tile:has(input:checked) {
  border-color: var(--teal);
  background: #e9f6f7;
}

.choice-tile input {
  margin-right: 7px;
}

.choice-tile span {
  font-weight: 900;
}

.choice-tile p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.consent-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 0.92rem;
}

.consent-toggle input {
  margin-top: 3px;
  accent-color: var(--green);
}

.form-actions {
  margin-top: 15px;
  flex-wrap: wrap;
}

.atlas-canvas-wrap {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101719;
  overflow: hidden;
  aspect-ratio: 1.45;
}

#atlasCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.metric {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span,
.metric small {
  display: block;
}

.metric span {
  font-size: 1.38rem;
  font-weight: 950;
  line-height: 1.05;
}

.metric small {
  margin-top: 5px;
  color: var(--muted);
  font-weight: 750;
}

.mechanism-bars {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.feed {
  margin-top: 16px;
}

.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.feed h3 {
  font-size: 0.95rem;
}

.feed-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.feed-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.feed-item b {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.feed-item span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.reflection-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1500px;
  margin: 16px auto 0;
  padding: 14px 16px;
}

.reflection-band p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.reflection-metrics {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.reflection-metrics span {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 850;
  white-space: nowrap;
}

.insight-box {
  padding: 12px;
  border-color: rgba(215, 155, 40, 0.55);
  background: #fff8e8;
  color: #5f4511;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

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

  .atlas-panel {
    grid-column: 1 / -1;
  }

  .atlas-panel {
    display: grid;
    grid-template-columns: minmax(280px, 440px) minmax(0, 1fr);
    gap: 14px;
  }

  .atlas-panel > .panel-kicker,
  .atlas-panel > h2 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 800px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .stage-header,
  .reflection-band {
    align-items: stretch;
    flex-direction: column;
  }

  .brand {
    align-items: flex-start;
  }

  .brand p {
    max-width: 26ch;
  }

  .top-actions,
  .stage-meta,
  .reflection-metrics {
    justify-content: flex-start;
  }

  .workspace,
  .atlas-panel {
    grid-template-columns: 1fr;
  }

  .mechanism-grid,
  .choice-grid,
  .stimulus-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .range-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .range-value {
    text-align: left;
  }

  .composer-actions,
  .form-actions {
    flex-direction: column;
  }

  .composer-actions button,
  .form-actions button {
    width: 100%;
  }
}
