:root {
  --bg: #f4f2ec;
  --panel: #fffdfa;
  --soft: #eef6f4;
  --ink: #172428;
  --muted: #657377;
  --line: #d8d2c6;
  --teal: #007c77;
  --teal-soft: #dff0ee;
  --blue: #315f88;
  --blue-soft: #e3edf5;
  --amber: #b7791f;
  --amber-soft: #f5ead1;
  --red: #b9412e;
  --red-soft: #f4dfda;
  --green: #28795b;
  --green-soft: #dfeee6;
  --shadow: 0 10px 26px rgba(23, 36, 40, 0.1);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  scroll-behavior: smooth;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf6;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(24px, 8vw, 42px);
  line-height: 1.02;
  letter-spacing: 0;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.dnv-logo {
  flex: 0 0 auto;
  width: 96px;
  height: 50px;
  object-fit: contain;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 18px rgba(23, 36, 40, 0.08);
}

.command-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 8px 8px 9px;
  border-bottom: 1px solid rgba(216, 210, 198, 0.85);
  background: rgba(244, 242, 236, 0.96);
  box-shadow: 0 12px 24px rgba(23, 36, 40, 0.12);
  backdrop-filter: blur(9px);
}

.scenario-strip,
.pipe-switch {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.scenario-strip::-webkit-scrollbar,
.pipe-switch::-webkit-scrollbar {
  display: none;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  padding-bottom: 7px;
}

.metric {
  min-width: 0;
  min-height: 66px;
  padding: 7px 6px;
  border: 1px solid #c9d6d5;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,249,249,0.95));
  box-shadow: 0 7px 16px rgba(23, 36, 40, 0.08);
}

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

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

.metric--risk {
  border-color: #b8d8d4;
  background: var(--teal-soft);
}

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

.metric--status.is-safe {
  border-color: #b8d8c5;
  background: var(--green-soft);
}

.metric--status.is-danger {
  border-color: #dda298;
  background: var(--red-soft);
}

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

.case-button,
.scenario-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
}

.case-button.is-active,
.scenario-button.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.scenario-button--action {
  border-color: #a35d1b;
  background: #fff8ec;
}

.scenario-button--quiet {
  background: #f4f7f7;
}

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

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

.card {
  padding: 13px;
}

.stage-card {
  padding: 13px;
  background:
    linear-gradient(135deg, rgba(223, 240, 238, 0.98), rgba(227, 237, 245, 0.95)),
    repeating-linear-gradient(90deg, rgba(0,124,119,0.08) 0 1px, transparent 1px 42px);
}

.stage-card h2,
.card h2 {
  margin: 0;
  font-size: clamp(20px, 6vw, 28px);
  line-height: 1.16;
}

.stage-card p {
  margin: 9px 0 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.stage-flow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 13px 0 0;
  padding: 0;
  list-style: none;
}

.stage-flow li {
  min-height: 42px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.stage-flow li.is-active {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--ink);
}

.stage-flow li.is-danger {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--ink);
}

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

.tag {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.tag--safe {
  border-color: #a8d0ba;
  background: var(--green-soft);
  color: var(--green);
}

.tag--warning {
  border-color: #dfc387;
  background: var(--amber-soft);
  color: #815314;
}

.tag--danger {
  border-color: #dc9b8f;
  background: var(--red-soft);
  color: var(--red);
}

.visual-frame,
.canvas-frame,
.bn-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.physical-frame svg {
  display: block;
  width: 100%;
  height: auto;
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

#gpCanvas {
  cursor: grab;
  touch-action: none;
}

.module-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.svg-label {
  fill: #213238;
  font-size: 18px;
  font-weight: 900;
  paint-order: stroke;
  stroke: rgba(255,255,255,0.75);
  stroke-width: 4px;
}

.svg-small {
  fill: #213238;
  font-size: 14px;
  font-weight: 900;
  paint-order: stroke;
  stroke: rgba(255,255,255,0.75);
  stroke-width: 3px;
}

.svg-alert {
  fill: #b9412e;
  font-size: 15px;
  font-weight: 900;
  paint-order: stroke;
  stroke: rgba(255,255,255,0.82);
  stroke-width: 4px;
}

.wave-line {
  fill: none;
  stroke: #4e97bc;
  stroke-width: 3;
}

.steel-line,
.pipe-link {
  fill: none;
  stroke: #3c4b50;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pipe-link {
  stroke-width: 8;
}

.pipe-outline {
  fill: none;
  stroke: #3e4f54;
  stroke-width: 22;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pipe-inner {
  fill: none;
  stroke: url(#pipeGrad);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pressure-envelope {
  fill: transparent;
  transition: fill 180ms ease;
  pointer-events: none;
}

.pressure-envelope.is-hot {
  fill: rgba(209, 122, 33, 0.18);
}

.pressure-envelope.is-danger {
  fill: rgba(185, 65, 46, 0.24);
}

.limit-line {
  stroke-width: 2;
  stroke-dasharray: 7 7;
}

.limit-line--hipps {
  stroke: #b9412e;
}

.limit-line--pcs {
  stroke: #b7791f;
}

.limit-line--maop {
  stroke: rgba(255,255,255,0.85);
}

.flow-dot {
  fill: #f5ffff;
  opacity: 0.85;
  stroke: #007c77;
  stroke-width: 2;
}

.sensor-probe line,
.sensor-probe circle {
  fill: #dfeaec;
  stroke: #4d5b60;
  stroke-width: 3;
  stroke-linecap: round;
}

.blockage-marker {
  opacity: 0.2;
  transition: opacity 180ms ease, transform 180ms ease;
}

.blockage-marker rect {
  fill: #d96a58;
  stroke: #8f3328;
  stroke-width: 3;
}

.blockage-marker.is-active {
  opacity: 1;
}

.sensor rect {
  fill: #f8ffff;
  stroke: #7aa6b0;
  stroke-width: 3;
}

.sensor text {
  fill: #213238;
  font-size: 16px;
  font-weight: 900;
}

#pipeMain {
  transition: stroke 180ms ease;
}

#pipeMain.is-hot {
  stroke: #d17a21;
}

#pipeMain.is-danger {
  stroke: #b9412e;
}

#hippsValve.is-closed rect {
  fill: #f4dfda;
  stroke: #b9412e;
}

#hippsValve.is-closed circle {
  fill: #f4dfda;
  stroke: #b9412e;
}

.bn-panel {
  overflow-x: auto;
}

.bn-panel svg {
  display: block;
  width: max(760px, 100%);
  height: auto;
}

.bn-group {
  fill: rgba(227,237,245,0.6);
  stroke: #7aa1c2;
  stroke-width: 1.5;
  stroke-dasharray: 7 5;
}

.bn-group--safety {
  fill: rgba(245,234,209,0.65);
  stroke: #cf9637;
}

.bn-group--struct {
  fill: rgba(223,238,230,0.72);
  stroke: #66a889;
}

.bn-group-title {
  fill: #24404a;
  font-size: 13px;
  font-weight: 900;
}

.bn-edge path {
  fill: none;
  stroke: #7a898d;
  stroke-width: 2;
  marker-end: url(#bnArrow);
}

.bn-node rect {
  fill: #fff;
  stroke: #90a2a6;
  stroke-width: 2;
}

.bn-node--model rect {
  fill: #e3edf5;
  stroke: #315f88;
}

.bn-node--safety rect {
  fill: #fff7e7;
  stroke: #b7791f;
}

.bn-node--event rect {
  fill: #fff8ef;
  stroke: #9b6930;
}

.bn-node--danger rect {
  fill: #fff1ec;
  stroke: #b9412e;
}

.bn-node--burst rect {
  fill: #e5f6f5;
  stroke: #007c77;
}

.bn-node.is-active rect {
  stroke-width: 4;
}

.bn-node.is-danger rect {
  fill: var(--red-soft);
  stroke: var(--red);
}

.bn-node text {
  fill: #213238;
  font-size: 12px;
  font-weight: 900;
  text-anchor: middle;
}

.bn-node text + text {
  fill: #637176;
  font-size: 11px;
  font-weight: 800;
}

.risk-card {
  background:
    linear-gradient(135deg, rgba(251,250,246,1), rgba(223,240,238,0.92));
}

.risk-grid {
  display: grid;
  gap: 10px;
}

.risk-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.78);
}

.risk-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.risk-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.45;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.legend i {
  width: 18px;
  height: 4px;
  border-radius: 999px;
}

.legend-risk {
  background: var(--red);
}

.legend-pressure {
  background: var(--blue);
}

.legend-flow {
  background: var(--teal);
}

.legend-hipps {
  background: var(--amber);
}

.settings-card {
  display: grid;
  gap: 12px;
}

.slider {
  display: grid;
  gap: 8px;
}

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

.slider b {
  color: var(--ink);
}

.slider input {
  width: 100%;
  accent-color: var(--teal);
}

.explanation-card ul {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
}

@media (min-width: 720px) {
  .command-bar {
    padding-inline: 14px;
  }

  .control-strip {
    grid-template-columns: auto 1fr;
    align-items: center;
  }

  .metrics-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .metric {
    flex-basis: auto;
  }

  .app-shell {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .stage-card,
  .primary-card,
  .risk-card,
  .settings-card,
  .explanation-card {
    grid-column: 1 / -1;
  }

  .primary-card:nth-of-type(2),
  .primary-card:nth-of-type(3),
  .primary-card:nth-of-type(4),
  .primary-card:nth-of-type(5) {
    grid-column: span 1;
  }

  .risk-grid {
    grid-template-columns: 0.75fr 1.25fr;
  }
}

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

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

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

  .card {
    padding: 16px;
  }

  .metric strong {
    font-size: 21px;
  }
}

@media (max-width: 410px) {
  .app-header {
    align-items: flex-start;
  }

  .dnv-logo {
    width: 76px;
    height: 42px;
    padding: 6px 7px;
  }

  .metric {
    min-height: 62px;
    padding: 6px 5px;
  }

  .metric strong {
    font-size: 13px;
  }

  .metric span,
  .metric small {
    font-size: 8px;
  }

  .stage-flow {
    grid-template-columns: 1fr;
  }
}
