:root {
  --bg: #f4f2ec;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #172428;
  --muted: #5e6d71;
  --line: #d8d2c6;
  --teal: #007c77;
  --teal-dark: #005f5b;
  --teal-soft: #dff0ee;
  --blue: #315f88;
  --blue-soft: #e3edf5;
  --amber: #a96616;
  --amber-soft: #f7ead0;
  --red: #b43b2a;
  --red-soft: #f5dfda;
  --green: #247252;
  --green-soft: #deeee5;
  --violet: #725a9b;
  --violet-soft: #eee7f6;
  --shadow: 0 10px 26px rgba(23, 36, 40, 0.1);
  --radius: 10px;
  --touch: 48px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color-scheme: light;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(0, 124, 119, 0.3);
  outline-offset: 3px;
}

a {
  color: inherit;
}

sub {
  line-height: 0;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 14px 13px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at 90% 12%, rgba(0, 124, 119, 0.12), transparent 30%),
    #fbfaf6;
}

.header-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.app-header h1 {
  margin: 0;
  max-width: 780px;
  font-size: clamp(28px, 9vw, 46px);
  line-height: 0.98;
  letter-spacing: -0.035em;
}

.subtitle {
  margin: 9px 0 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.target-badge {
  flex: 0 0 auto;
  width: 112px;
  padding: 10px 9px;
  border: 1px solid #a9ccc8;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #ffffff, var(--teal-soft));
  box-shadow: 0 7px 18px rgba(23, 36, 40, 0.08);
  text-align: center;
}

.target-badge span,
.target-badge small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.target-badge strong {
  display: block;
  margin: 5px 0;
  color: var(--teal-dark);
  font-size: 15px;
  line-height: 1.1;
}

.command-dock {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 8px 8px 7px;
  border-bottom: 1px solid rgba(216, 210, 198, 0.86);
  background: rgba(244, 242, 236, 0.96);
  box-shadow: 0 10px 22px rgba(23, 36, 40, 0.13);
  backdrop-filter: blur(10px);
}

.metric-grid {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.metric-grid::-webkit-scrollbar {
  display: none;
}

.metric {
  flex: 0 0 148px;
  min-width: 0;
  min-height: 68px;
  padding: 8px 9px;
  border: 1px solid #ccd6d4;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #f8faf9);
  box-shadow: 0 5px 13px rgba(23, 36, 40, 0.07);
}

.metric > span,
.metric > small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.metric > small {
  display: none;
}

.metric > strong {
  display: block;
  margin: 4px 0 3px;
  font-size: 15px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric--state {
  border-color: #e1c07e;
  background: var(--amber-soft);
}

.metric--state.is-safe {
  border-color: #9cc8ae;
  background: var(--green-soft);
}

.metric--state.is-unsafe {
  border-color: #dda094;
  background: var(--red-soft);
}

.command-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  margin-top: 7px;
}

.quick-action,
.reset-action {
  min-height: var(--touch);
  border-radius: var(--radius);
  font-weight: 900;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--teal-dark);
  background: var(--teal);
  color: #fff;
  text-align: left;
}

.quick-action:disabled,
.primary-action:disabled {
  cursor: default;
  opacity: 0.62;
}

.quick-action__icon {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 21px;
}

.quick-action > span:last-child {
  min-width: 0;
}

.quick-action b,
.quick-action small {
  display: block;
}

.quick-action b {
  font-size: 14px;
}

.quick-action small {
  margin-top: 2px;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reset-action {
  min-width: 72px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.jump-nav {
  display: flex;
  gap: 7px;
  margin-top: 7px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.jump-nav::-webkit-scrollbar {
  display: none;
}

.jump-nav a {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.jump-nav span {
  color: var(--teal-dark);
}

.app-shell {
  display: grid;
  width: min(100% - 16px, 1180px);
  margin: 12px auto 38px;
  gap: 12px;
}

.card,
.story-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.story-card {
  padding: 15px;
  background:
    linear-gradient(140deg, rgba(223, 240, 238, 0.72), rgba(255, 253, 250, 0.96) 45%),
    var(--panel);
}

.section-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-kicker span,
.section-kicker b {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.section-kicker span {
  color: var(--teal-dark);
}

.section-kicker b {
  color: var(--muted);
}

.story-card h2,
.evidence-card h2 {
  margin: 10px 0 8px;
  font-size: clamp(22px, 6.4vw, 31px);
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.story-card > p,
.evidence-card > p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.58;
}

.story-flow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.story-flow li {
  position: relative;
  min-height: 86px;
  padding: 11px 10px 9px 43px;
  border: 1px solid #cddedb;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.84);
}

.story-flow li > span {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.story-flow b,
.story-flow small {
  display: block;
}

.story-flow b {
  font-size: 15px;
}

.story-flow small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.target-note {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 11px 12px;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--teal-soft);
}

.target-note strong {
  font-size: 14px;
}

.target-note span {
  color: #40575b;
  font-size: 13px;
  line-height: 1.45;
}

.card {
  padding: 13px;
  scroll-margin-top: 246px;
}

.card-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
}

.module-number {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
}

.card-header p {
  margin: 0 0 3px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.card-header h2 {
  margin: 0;
  font-size: clamp(20px, 5.8vw, 28px);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.module-tag {
  align-self: start;
  padding: 5px 7px;
  border: 1px solid #b8d3d0;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
}

.decision-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.decision-summary > div {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #faf9f5;
}

.decision-summary span,
.decision-summary strong {
  display: block;
}

.decision-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.decision-summary strong {
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.35;
}

.experiment-grid {
  display: grid;
  gap: 8px;
}

.experiment-button {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.experiment-button.is-selected {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
  background: var(--teal-soft);
}

.experiment-button.is-recommended::after {
  content: "BEST VALUE";
  position: absolute;
  top: -7px;
  right: 8px;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--teal-dark);
  color: #fff;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.03em;
  opacity: 1;
}

.experiment-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 20px;
  font-weight: 900;
}

.experiment-button[data-experiment="fe"] .experiment-icon {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.experiment-button[data-experiment="lab"] .experiment-icon {
  background: var(--violet-soft);
  color: var(--violet);
}

.experiment-button b,
.experiment-button small {
  display: block;
}

.experiment-button b {
  font-size: 14px;
}

.experiment-button small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.experiment-button em {
  max-width: 68px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  line-height: 1.2;
  text-align: right;
}

.primary-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  margin-top: 9px;
  padding: 8px 13px;
  border: 1px solid var(--teal-dark);
  border-radius: var(--radius);
  background: var(--teal);
  color: #fff;
  text-align: left;
}

.primary-action > span:first-child {
  font-size: 17px;
}

.primary-action b,
.primary-action small {
  display: block;
}

.primary-action b {
  font-size: 14px;
}

.primary-action small {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
}

.reliability-panel {
  margin-top: 10px;
  padding: 11px;
  border: 1px solid #cad9d8;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfefd, #f2f8f7);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading span {
  display: block;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.panel-heading h3 {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.25;
}

.panel-heading > b {
  display: grid;
  flex: 0 0 auto;
  min-width: 42px;
  min-height: 36px;
  place-items: center;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
}

#reliabilityCanvas {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 7px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 13px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

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

.chart-legend span[hidden] {
  display: none;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--teal);
}

.legend-line--before {
  border-top: 2px dashed #72878d;
}

.legend-line--target {
  border-top: 2px dashed var(--red);
}

.reliability-panel.is-uncertain .legend-line--after {
  border-color: var(--amber);
}

.reliability-panel.is-safe .legend-line--after {
  border-color: var(--green);
}

.reliability-panel.is-unsafe .legend-line--after {
  border-color: var(--red);
}

.sr-chart-summary {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.impact-card {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #e1c584;
  border-radius: var(--radius);
  background: var(--amber-soft);
}

.impact-card > span {
  color: #73521d;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.impact-card > strong {
  font-size: 15px;
  line-height: 1.3;
}

.impact-card > small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.impact-card.is-safe {
  border-color: #9cc8ae;
  background: var(--green-soft);
}

.impact-card.is-unsafe {
  border-color: #dda094;
  background: var(--red-soft);
}

.state-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.state-card {
  padding: 9px 10px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  opacity: 0.76;
}

.state-card.is-active {
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(23, 36, 40, 0.12);
}

.state-card--safe.is-active {
  border-color: var(--green);
  background: var(--green-soft);
}

.state-card--uncertain.is-active {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.state-card--unsafe.is-active {
  border-color: var(--red);
  background: var(--red-soft);
}

.state-card header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.state-card header span {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
}

.state-card header b {
  font-size: 13px;
}

.state-card svg {
  display: block;
  width: 100%;
  height: 62px;
}

.mini-axis {
  stroke: #91a0a3;
  stroke-width: 1;
}

.mini-target {
  stroke: var(--red);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.mini-density {
  fill: rgba(0, 124, 119, 0.12);
  stroke: var(--teal);
  stroke-width: 2.3;
}

.state-card > small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.pipe-stage {
  overflow: hidden;
  border: 1px solid #bfcdd0;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 42%, rgba(63, 113, 133, 0.33), transparent 42%),
    linear-gradient(180deg, #152a34, #09151b);
}

.pipe-stage__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px 0;
  color: #d8e9ee;
}

.pipe-stage__head span,
.pipe-stage__head small {
  font-size: 11px;
  font-weight: 800;
}

.pipe-stage__head small {
  color: #a8c1ca;
  text-align: right;
}

#pipeCanvas {
  display: block;
  width: 100%;
  height: 255px;
  touch-action: pan-y;
}

.pipe-callout {
  display: grid;
  gap: 2px;
  margin: 0 10px 10px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 170, 104, 0.5);
  border-radius: 8px;
  background: rgba(15, 24, 28, 0.88);
  color: #fff;
}

.pipe-callout b {
  color: #ffc08b;
  font-size: 13px;
}

.pipe-callout span {
  color: #cddde2;
  font-size: 12px;
}

.sync-bridge {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin: 9px 0;
}

.sync-bridge > div {
  min-width: 0;
  min-height: 65px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.sync-bridge span,
.sync-bridge b {
  display: block;
}

.sync-bridge span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.sync-bridge b {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.sync-bridge > i {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #c6d8d6;
}

.sync-bridge > i::after {
  content: "→";
  position: absolute;
  top: 50%;
  right: -3px;
  color: var(--teal-dark);
  font-size: 17px;
  font-style: normal;
  font-weight: 900;
  transform: translateY(-55%);
}

.sync-bridge em {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(0, 124, 119, 0.15);
  transform: translateY(-50%);
}

.sync-bridge.is-updating em {
  animation: syncPulse 1.15s ease-in-out infinite;
}

@keyframes syncPulse {
  0% { left: 2px; }
  100% { left: calc(100% - 14px); }
}

.virtual-card {
  padding: 11px;
  border: 1px solid #b9d1cf;
  border-radius: var(--radius);
  background: linear-gradient(150deg, #f7fcfb, var(--teal-soft));
}

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

.virtual-card__head span,
.virtual-card__head b {
  font-size: 11px;
  font-weight: 900;
}

.virtual-card__head span {
  color: var(--teal-dark);
}

.virtual-card__head b {
  padding: 4px 7px;
  border-radius: 999px;
  background: #fff;
  color: var(--teal-dark);
}

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

.virtual-grid article {
  min-width: 0;
  padding: 9px;
  border: 1px solid rgba(127, 166, 163, 0.5);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.virtual-grid span,
.virtual-grid b,
.virtual-grid small {
  display: block;
}

.virtual-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.virtual-grid b {
  margin: 5px 0 3px;
  font-size: 15px;
}

.virtual-grid small {
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
}

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

.network-toolbar button {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 8px 12px;
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  background: #fff;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
}

.network-toolbar button[aria-pressed="true"] {
  background: var(--teal);
  color: #fff;
}

.network-toolbar span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-align: right;
}

.bayes-canvas {
  position: relative;
  width: 100%;
  height: 550px;
  overflow: hidden;
  border: 1px solid #becdd0;
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(49, 95, 136, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(49, 95, 136, 0.05) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, #f7fbfc, #edf4f5);
  background-size: 24px 24px, 24px 24px, auto;
  touch-action: pan-y;
}

.bayes-canvas.is-arranging {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 2px rgba(0, 124, 119, 0.15);
}

.bayes-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.bayes-lines line {
  stroke: #80959b;
  stroke-width: 1.7;
  marker-end: url(#bayesArrow);
  transition: stroke 180ms ease, stroke-width 180ms ease;
}

.bayes-lines line.is-active {
  stroke: var(--teal);
  stroke-width: 3.6;
  stroke-dasharray: 7 5;
  animation: pathFlow 0.75s linear infinite;
}

@keyframes pathFlow {
  to { stroke-dashoffset: -12; }
}

.bayes-node {
  position: absolute;
  z-index: 2;
  display: grid;
  width: 66px;
  min-height: 54px;
  padding: 5px 4px;
  place-content: center;
  border: 1px solid #6f8a92;
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 5px 13px rgba(23, 36, 40, 0.12);
  text-align: center;
  touch-action: pan-y;
  transform: translate(-50%, -50%);
  user-select: none;
}

.bayes-canvas.is-arranging .bayes-node {
  cursor: grab;
  touch-action: none;
}

.bayes-canvas.is-arranging .bayes-node.is-dragging {
  z-index: 4;
  cursor: grabbing;
  box-shadow: 0 8px 22px rgba(0, 124, 119, 0.28);
}

.bayes-node--epistemic {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.bayes-node--major {
  border-width: 2px;
}

.bayes-node--decision {
  border-color: var(--violet);
  background: var(--violet-soft);
}

.bayes-node--result {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.bayes-node.is-active {
  border-color: var(--teal);
  background: #c8ece7;
  box-shadow: 0 0 0 4px rgba(0, 124, 119, 0.13), 0 7px 18px rgba(0, 124, 119, 0.2);
}

.bayes-node b,
.bayes-node small {
  display: block;
  pointer-events: none;
}

.bayes-node b {
  font-size: 14px;
  line-height: 1.05;
}

.bayes-node small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.05;
}

.network-legend {
  position: absolute;
  right: 8px;
  bottom: 8px;
  left: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
}

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

.network-legend i {
  width: 12px;
  height: 12px;
  border: 1px solid #6f8a92;
  border-radius: 4px;
  background: #fff;
}

.network-legend span:last-child i {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.active-path,
.node-explanation {
  margin-top: 8px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.active-path span,
.active-path strong,
.node-explanation b,
.node-explanation span {
  display: block;
}

.active-path span {
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.active-path strong {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
}

.node-explanation {
  background: #f7f8f6;
}

.node-explanation b {
  font-size: 13px;
}

.node-explanation span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.model-flow {
  display: grid;
  gap: 8px;
}

.model-flow article {
  position: relative;
  min-width: 0;
  padding: 13px 12px 12px 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.flow-number {
  position: absolute;
  top: 12px;
  left: 11px;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.model-flow h3 {
  margin: 0;
  font-size: 16px;
}

.model-flow p {
  margin: 6px 0 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.48;
}

.formula {
  padding: 8px 9px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #244a6b;
  font-family: "Cambria Math", Cambria, Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.model-flow article > strong {
  display: block;
  margin-top: 8px;
  color: var(--teal-dark);
  font-size: 14px;
  text-align: center;
}

.uncertainty-block {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.uncertainty-block + .uncertainty-block {
  margin-top: 8px;
}

.uncertainty-block--epistemic {
  border-color: #e0bf7c;
  background: #fffaf0;
}

.uncertainty-block--aleatory {
  border-color: #b9cbd9;
  background: #f2f7fb;
}

.uncertainty-head {
  display: grid;
  gap: 5px;
  margin-bottom: 11px;
}

.uncertainty-head span {
  display: block;
  color: var(--amber);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.uncertainty-block--aleatory .uncertainty-head span {
  color: var(--blue);
}

.uncertainty-head h3 {
  margin: 2px 0 0;
  font-size: 17px;
}

.uncertainty-head small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.uncertainty-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 38px;
  align-items: center;
  gap: 7px;
  min-height: 48px;
  padding: 6px 0;
  border-top: 1px solid rgba(175, 145, 85, 0.25);
}

.uncertainty-row > span {
  min-width: 0;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
}

.uncertainty-row > i {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadfca;
}

.uncertainty-row em {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e2a13a, var(--amber));
  transition: width 260ms ease;
}

.uncertainty-row > strong {
  font-size: 12px;
  text-align: right;
}

.uncertainty-block--aleatory > p {
  margin: 0;
  color: #405762;
  font-size: 13px;
  line-height: 1.5;
}

.cycle-flow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cycle-flow li {
  position: relative;
  min-height: 108px;
  padding: 11px 9px 9px 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.cycle-flow li.is-active {
  border-color: var(--teal);
  background: var(--teal-soft);
  transform: translateY(-2px);
}

.cycle-flow li > span {
  position: absolute;
  top: 10px;
  left: 9px;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.cycle-flow b,
.cycle-flow small {
  display: block;
}

.cycle-flow b {
  font-size: 13px;
}

.cycle-flow small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.history-panel {
  margin-top: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  background: #f7f7f3;
}

.history-head span,
.history-head b {
  display: block;
}

.history-head span {
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.history-head b {
  margin-top: 3px;
  font-size: 13px;
}

.history-head button {
  min-width: 64px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.history-list {
  display: grid;
  max-height: 330px;
  overflow-y: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  padding: 11px;
  border-top: 1px solid #ece8df;
}

.history-item:first-child {
  border-top: 0;
}

.history-item > span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.history-item b,
.history-item small,
.history-item em {
  display: block;
}

.history-item b {
  font-size: 13px;
}

.history-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.history-item em {
  margin-top: 5px;
  color: var(--teal-dark);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.empty-history {
  margin: 0;
  padding: 16px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.evidence-card {
  padding: 15px;
}

.evidence-card .disclaimer {
  margin-top: 10px;
  padding: 10px 11px;
  border-left: 4px solid var(--amber);
  border-radius: 7px;
  background: var(--amber-soft);
  color: #544833;
  font-size: 12px;
}

.paper-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--touch);
  margin-top: 11px;
  padding: 9px 13px;
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  background: #fff;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: #ebe8df;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.app-footer a {
  flex: 0 0 auto;
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  color: var(--teal-dark);
  text-decoration: none;
}

.toast {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 100;
  display: grid;
  gap: 3px;
  max-width: 520px;
  margin-inline: auto;
  padding: 12px 14px;
  border: 1px solid #82b7b1;
  border-radius: var(--radius);
  background: #102e31;
  color: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast b {
  font-size: 13px;
}

.toast span {
  color: #c5dcda;
  font-size: 11px;
  line-height: 1.35;
}

.noscript {
  position: fixed;
  inset: auto 8px 8px;
  z-index: 200;
  padding: 12px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: var(--red-soft);
  color: #5a241d;
  font-size: 13px;
}

@media (min-width: 720px) {
  .app-header {
    padding-inline: 20px;
  }

  .command-dock {
    padding-inline: 14px;
  }

  .metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
  }

  .metric {
    min-height: 72px;
  }

  .metric > small {
    display: block;
  }

  .command-actions {
    grid-template-columns: minmax(260px, 420px) auto;
  }

  .story-flow,
  .cycle-flow {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .experiment-grid,
  .state-grid,
  .model-flow {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .experiment-button {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .experiment-button em {
    grid-column: 1 / -1;
    max-width: none;
    text-align: left;
  }

  .twin-card {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 10px;
  }

  .twin-card .card-header,
  .twin-card .sync-bridge {
    grid-column: 1 / -1;
  }

  .virtual-card {
    align-self: stretch;
  }

  .bayes-canvas {
    height: 590px;
  }

  .bayes-node {
    width: 78px;
    min-height: 60px;
  }

  .uncertainty-head {
    grid-template-columns: 0.7fr 1.3fr;
    align-items: end;
  }

  .uncertainty-head small {
    text-align: right;
  }

  .card {
    scroll-margin-top: 156px;
  }
}

@media (min-width: 1024px) {
  .app-header {
    padding-inline: 28px;
  }

  .command-dock {
    padding-inline: 28px;
  }

  .app-shell {
    width: min(100% - 56px, 1280px);
  }

  .card,
  .story-card,
  .evidence-card {
    padding: 17px;
  }

  .decision-card,
  .bayes-card {
    padding: 20px;
  }

  #reliabilityCanvas {
    height: 270px;
  }
}

@media (max-width: 410px) {
  .app-header {
    gap: 8px;
    padding-inline: 12px;
  }

  .app-header h1 {
    font-size: clamp(27px, 8.8vw, 36px);
  }

  .subtitle {
    font-size: 13px;
  }

  .target-badge {
    width: 96px;
    padding-inline: 6px;
  }

  .target-badge strong {
    font-size: 13px;
  }

  .metric {
    min-height: 70px;
    padding: 7px 8px;
  }

  .metric > strong {
    font-size: 14px;
  }

  .card-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .module-tag {
    display: none;
  }

  .experiment-button em {
    display: none;
  }

  .experiment-button {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .sync-bridge {
    grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1fr);
    gap: 5px;
  }

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

  .network-toolbar {
    align-items: flex-start;
  }

  .network-toolbar span {
    max-width: 145px;
  }

  .bayes-canvas {
    height: 520px;
  }

  .bayes-node {
    width: 60px;
    min-height: 52px;
  }

  .uncertainty-row {
    grid-template-columns: minmax(0, 1fr) 56px 34px;
  }
}

@media (max-width: 340px) {
  .target-badge {
    display: none;
  }

  .reset-action {
    min-height: 44px;
  }

  .network-toolbar {
    display: grid;
  }

  .network-toolbar span {
    max-width: none;
    text-align: left;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .command-dock {
    position: relative;
  }

  .app-header h1 {
    font-size: 30px;
  }

  #reliabilityCanvas {
    height: 190px;
  }

  .bayes-canvas {
    height: 470px;
  }

  .card {
    scroll-margin-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
