/* Architecture Simulator section (#lab). Uses the site's tokens from styles.css. */
.sim { --ok: #6fbf8f; --warn: #d8a24a; --bad: #d9706a; --rep: #a89bd0; margin-top: 14px; padding: 30px 28px 18px; }
.exp + .tabs { margin-top: 14px; }
.sim h3 { font: 600 17px/1.3 var(--head); color: var(--hd); margin: 0 0 12px; }
.sim .ic { width: 22px; height: 22px; }
.sim select, .sim button, .sim input { font-family: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.sim-grid { display: grid; grid-template-columns: minmax(0, 1fr) clamp(280px, 32%, 380px); gap: 14px; margin-top: 24px; }
.sim-box { min-width: 0; border: 1px solid var(--line); border-radius: 4px; background: rgba(0, 0, 0, .18); }

/* diagram panel */
.sim-diagram { display: flex; flex-direction: column; padding: 12px 14px 14px; }
.sim-diagram #sim-v-diagram:not([hidden]) { flex: 1; display: flex; flex-direction: column; justify-content: center; border-radius: 4px; }
.sim-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.sim-tools { display: flex; gap: 8px; }
.field { display: block; }
.field > span { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--mut); }
.sim select { appearance: none; width: 100%; padding: 9px 34px 9px 12px; font-size: 14px; color: #e6e1d8; border: 1px solid var(--line); border-radius: 4px; cursor: pointer;
  background: rgba(255, 255, 255, .03) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%239a948a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1.5 1.5 4.5 4.5 4.5-4.5'/%3E%3C/svg%3E") right 12px center / 12px 8px no-repeat; }
.sim select option { background: #1b1a17; color: #e6e1d8; }
.sim select:hover { border-color: rgba(217, 163, 91, .4); }
.tpl { min-width: 190px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: rgba(255, 255, 255, .03); }
/* all:unset beats the site's global [role="tab"] styles, which apply once JS adds the role */
.sim .seg button { all: unset; box-sizing: border-box; cursor: pointer; padding: 9px 16px; font: 600 14px/1.2 var(--body); color: var(--mut); transition: color .15s, background .15s; }
.sim .seg button:hover { color: var(--hd); }
.sim .seg button[aria-selected="true"] { color: var(--hd); background: rgba(217, 163, 91, .12); box-shadow: inset 0 -2px 0 var(--accent); }
.sim .seg button:focus-visible, .sim .fs:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fs { all: unset; box-sizing: border-box; display: grid; place-items: center; width: 38px; height: 38px; cursor: pointer; color: var(--mut); border: 1px solid var(--line); border-radius: 4px; background: rgba(255, 255, 255, .03); }
.fs:hover { color: var(--hd); border-color: rgba(217, 163, 91, .4); }
.view[hidden] { display: none; }
.stage-scroll { overflow-x: auto; border-radius: 4px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent; }
.stage-scroll { --fl: 0px; --fr: 0px; -webkit-mask-image: linear-gradient(90deg, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent); mask-image: linear-gradient(90deg, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent); }
.stage-scroll.more-l { --fl: 26px; } .stage-scroll.more-r { --fr: 26px; }
.stage { position: relative; container-type: inline-size; min-width: 600px; aspect-ratio: 640 / 560; }
.edges { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; overflow: visible; }
.edge { transition: opacity .35s; }
.edge[data-on="0"] { opacity: 0; }
.eb { fill: none; stroke: #7a766c; stroke-width: 1.4; stroke-dasharray: 4 4; opacity: .85; }
.ef { fill: none; stroke: #e8c28a; stroke-width: 3; stroke-linecap: round; animation: sim-flow linear infinite; display: none; }
.edge[data-c="warm"] .eb { stroke: var(--warn); } .edge[data-c="warm"] .ef { stroke: #fcd34d; }
.edge[data-c="hot"] .eb { stroke: var(--bad); } .edge[data-c="hot"] .ef { stroke: #fca5a5; }
.edge[data-c="rep"] .eb { stroke: var(--rep); } .edge[data-c="rep"] .ef { stroke: #c4b5fd; }
.edge[data-l="1"] .ef { display: block; stroke-dasharray: .1 20; --pl: -20; }
.edge[data-l="2"] .ef { display: block; stroke-dasharray: .1 12; --pl: -12; }
.edge[data-l="3"] .ef { display: block; stroke-dasharray: .1 7; --pl: -7; }
@keyframes sim-flow { to { stroke-dashoffset: -20; } }
.edge[data-l="2"] .ef { animation-name: sim-flow2; } .edge[data-l="3"] .ef { animation-name: sim-flow3; }
@keyframes sim-flow2 { to { stroke-dashoffset: -12; } }
@keyframes sim-flow3 { to { stroke-dashoffset: -7; } }

.sn { --stk: 0 0 0 0 #0000; position: absolute; z-index: 1; display: flex; align-items: center; gap: .55em; padding: 0 .65em; font-size: clamp(11px, 1.75cqw, 14.5px); color: var(--hd);
  border: 1.5px solid color-mix(in srgb, var(--nc) 75%, transparent); border-radius: 4px;
  background: color-mix(in srgb, var(--nc) 8%, #1b1a17);
  box-shadow: var(--stk); transition: opacity .3s, border-color .3s, box-shadow .3s; }
.sn .sn-ic { position: relative; flex: none; display: grid; color: var(--nc); }
.sn .ic { width: 1.9em; height: 1.9em; }
.sn-t { min-width: 0; line-height: 1.2; }
.sn-t b { display: block; font: 700 1.08em/1.15 var(--body); }
.sn-t i { display: block; margin-top: .15em; font: normal 400 .88em/1.2 var(--body); color: var(--mut); }
.sn .sw { position: absolute; top: .5em; right: .55em; }
.sn .chip { position: absolute; right: .6em; bottom: -.82em; padding: .34em .65em; border: 1px solid color-mix(in srgb, var(--nc) 55%, transparent); border-radius: 4px; background: #1b1a17; font: 600 .78em/1 var(--body); color: #e6e1d8; white-space: nowrap; }
.sn[data-n="api"] { --stk: 4px 4px 0 -1px #1b1a17, 4px 4px 0 0 rgba(134, 165, 196, .5); }
.sn[data-stack="1"] { --stk: 0 0 0 0 #0000; }
.sn[data-stack="3"] { --stk: 4px 4px 0 -1px #1b1a17, 4px 4px 0 0 rgba(134, 165, 196, .5), 8px 8px 0 -1px #1b1a17, 8px 8px 0 0 rgba(134, 165, 196, .32); }
.sn[data-s="warm"] { border-color: var(--warn); } .sn[data-s="warm"] .chip { border-color: var(--warn); color: #fcd34d; }
.sn[data-s="hot"] { border-color: var(--bad); } .sn[data-s="hot"] .chip { border-color: var(--bad); color: #fca5a5; }
.sn[data-s="down"] { border-color: var(--bad); } .sn[data-s="down"] .sn-ic { color: var(--bad); }
.sn[data-s="down"] .sn-ic::after { content: ""; position: absolute; left: 8%; right: 8%; top: 50%; border-top: 2px solid var(--bad); transform: rotate(-40deg); }
.sn[data-s="down"] .chip { background: var(--bad); border-color: var(--bad); color: #1b0a0a; font-weight: 700; letter-spacing: .06em; }
.sn.off { border-style: dashed; border-color: rgba(154, 148, 138, .45); background: rgba(20, 19, 17, .55); opacity: .6; --nc: var(--mut); }
.sn.off .chip { color: #e6e1d8; border-style: dashed; }
.sn.gone { opacity: 0; visibility: hidden; }
.sn.bn::after { content: ""; position: absolute; inset: -6px; border: 2px solid var(--ring, var(--accent)); border-radius: 8px; pointer-events: none; animation: sim-pulse 1.8s ease-out infinite; }
.sn.bn[data-s="warm"] { --ring: var(--warn); } .sn.bn[data-s="hot"], .sn.bn[data-s="down"] { --ring: var(--bad); }
@keyframes sim-pulse { 0% { opacity: .9; transform: scale(.985); } 100% { opacity: 0; transform: scale(1.06); } }
.pill { position: absolute; left: 2.8%; top: 5.6%; z-index: 1; display: flex; align-items: center; gap: .5em; margin: 0; padding: .45em .8em; font-size: clamp(10px, 1.7cqw, 13px); color: var(--mut); border: 1px solid var(--line); border-radius: 4px; background: rgba(20, 19, 17, .7); }
.pill .ic { width: 1.4em; height: 1.4em; } .pill b { font-weight: 600; color: #e6e1d8; }
.legend { position: absolute; left: 2.8%; top: 29.6%; z-index: 1; display: grid; gap: .4em; font-size: clamp(10px, 1.7cqw, 12.5px); color: var(--mut); }
.legend li { display: flex; align-items: center; gap: .6em; }
.legend li::before { content: ""; width: .9em; height: .9em; border: 1.5px solid #86a5c4; border-radius: .25em; }
.legend [data-s="warm"]::before { border-color: var(--warn); } .legend [data-s="hot"]::before { border-color: var(--bad); background: rgba(217, 112, 106, .3); }
.legend [data-s="down"]::before { border-color: var(--bad); background: var(--bad); }

/* infrastructure view */
.tbl-wrap { overflow-x: auto; border-radius: 4px; }
.infra { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 14px; }
.infra th, .infra td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.infra td:nth-child(n+3), .infra thead th { white-space: nowrap; }
.infra thead th { font: 600 12.5px/1 var(--body); color: var(--mut); }
.infra tbody th { white-space: nowrap; color: var(--hd); font-weight: 600; }
.infra .n { text-align: right; font-variant-numeric: tabular-nums; }
.infra td { color: var(--txt); }
.infra tfoot th, .infra tfoot td { color: var(--hd); font-weight: 700; border-bottom: 0; border-top: 1px solid rgba(255, 255, 255, .18); }
.ub { display: inline-block; vertical-align: middle; width: 96px; height: 6px; border-radius: 4px; background: rgba(255, 255, 255, .09); overflow: hidden; }
.ub i { display: block; height: 100%; border-radius: 4px; background: #86a5c4; }
.ub[data-s="warm"] i { background: var(--warn); } .ub[data-s="hot"] i { background: var(--bad); }
.up { display: inline-block; margin-left: 10px; min-width: 3.2em; font-variant-numeric: tabular-nums; }
.mut { color: var(--mut); }

/* configuration panel */
.sim-config { padding: 16px 18px 18px; }
.sim-config h3 { font-size: 18px; margin-bottom: 8px; }
.opt { display: flex; gap: 12px; padding: 9px 0; }
.opt > .ic { margin-top: 2px; color: var(--mut); }
.opt-body { flex: 1; min-width: 0; }
.opt-body.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt-t { display: block; min-width: 0; }
.opt-t b { display: block; font: 600 14.5px/1.3 var(--body); color: var(--hd); }
.opt-t i { display: block; font: normal 400 12.5px/1.35 var(--body); color: var(--mut); }
.vol-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
#sim-rps-val { font: 600 18px/1 var(--body); color: var(--hd); white-space: nowrap; }
.sim input[type="range"] { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 22px; margin: 6px 0 0; background: transparent; cursor: pointer; --p: 50%; }
.sim input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 4px; background: linear-gradient(var(--accent), var(--accent)) 0 / var(--p) 100% no-repeat, rgba(255, 255, 255, .11); }
.sim input[type="range"]::-moz-range-track { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, .11); }
.sim input[type="range"]::-moz-range-progress { height: 6px; border-radius: 4px; background: var(--accent); }
.sim input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; border: 2px solid #e6e1d8; background: var(--accent); }
.sim input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #e6e1d8; background: var(--accent); }
.sim input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.ticks { position: relative; height: 18px; margin-top: 2px; font-size: 12px; color: var(--mut); }
.ticks span { position: absolute; top: 0; left: calc(9px + (100% - 18px) * var(--t)); transform: translateX(-50%); }
.step { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: rgba(255, 255, 255, .03); }
.step button { all: unset; box-sizing: border-box; display: grid; place-items: center; width: 34px; height: 34px; font-size: 18px; color: #e6e1d8; cursor: pointer; }
.step button:hover:not(:disabled) { background: rgba(217, 163, 91, .12); color: var(--hd); }
.step button:disabled { opacity: .35; cursor: default; }
.step button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.step output { min-width: 34px; text-align: center; font: 700 15px/1 var(--body); color: var(--hd); }
.opts { margin: 4px 0 0; padding-top: 4px; border-top: 1px solid var(--line); }
.two { display: grid; gap: 12px; padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--line); }
.sw { appearance: none; position: relative; flex: none; width: 2.4em; height: 1.3em; margin: 0; padding: 0; border: 0; border-radius: 4px; background: #3a3832; cursor: pointer; font-size: 16px; transition: background .2s; }
.sw::after { content: ""; position: absolute; left: .15em; top: .15em; width: 1em; height: 1em; border-radius: 50%; background: var(--hd); transition: transform .2s; }
.sw[aria-checked="true"] { background: var(--accent); } .sw[aria-checked="true"]::after { transform: translateX(1.1em); }
.sw-r[aria-checked="true"] { background: var(--bad); }
.sw-s { font-size: inherit; }
.sw-s::before { content: ""; position: absolute; inset: -7px; }
.chaos { margin: 12px 0 14px; padding: 4px 14px 6px; min-width: 0; border: 1px dashed rgba(217, 112, 106, .4); border-radius: 4px; }
.chaos legend { display: flex; align-items: center; gap: 7px; padding: 0 8px; font: 600 12.5px/1 var(--body); color: var(--bad); }
.chaos legend .ic { width: 16px; height: 16px; }
.crow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; line-height: 1.3; color: #e6e1d8; }
.crow em { display: block; font-style: normal; font-size: 12px; color: var(--mut); }
.run { all: unset; box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 13px 16px; border-radius: 4px; cursor: pointer; font: 700 15px/1 var(--body); color: #1a1305; background: var(--accent); transition: filter .15s; }
.run .ic { width: 16px; height: 16px; }
.run:hover:not(:disabled) { filter: brightness(1.1); }
.run:disabled { opacity: .7; cursor: progress; }
.run:focus-visible { outline: 2px solid var(--hd); outline-offset: 3px; }

/* results, status, qualities */
.sim-row2 { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 32%, 380px); gap: 14px; margin-top: 14px; }
.results, .status { padding: 16px 18px 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { min-width: 0; padding: 0 14px; border-left: 1px solid var(--line); }
.kpi:first-child { padding-left: 0; border-left: 0; } .kpi:last-child { padding-right: 0; }
.kh { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mut); white-space: nowrap; }
.kpi .kh { font-size: 12.5px; gap: 6px; } .kpi .kh span { overflow: hidden; text-overflow: ellipsis; }
.kh .ic { width: 20px; height: 20px; }
.kpi[data-kpi="lat"] .ic { color: #86a5c4; } .kpi[data-kpi="thr"] .ic { color: var(--ok); } .kpi[data-kpi="cpu"] .ic { color: var(--rep); } .kpi[data-kpi="db"] .ic { color: var(--warn); }
.kn { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 8px; margin-top: 8px; }
.kv { font: 700 22px/1.25 var(--body); color: var(--hd); white-space: nowrap; }
.dl { font-size: 12.5px; font-weight: 600; color: var(--mut); white-space: nowrap; }
.dl.good { color: var(--ok); } .dl.bad { color: var(--bad); }
.ks { display: block; font-size: 12px; line-height: 1.4; color: var(--mut); }
.spark { display: block; width: 100%; height: 34px; margin-top: 8px; overflow: visible; }
.status { --sc: var(--ok); }
.status[data-s="degraded"] { --sc: var(--warn); } .status[data-s="overloaded"] { --sc: #f97316; } .status[data-s="outage"] { --sc: var(--bad); }
.st-top { display: flex; align-items: center; gap: 10px; }
.st-top b { font: 700 24px/1.2 var(--body); color: var(--hd); }
.st-dot { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--sc); transition: background .3s; }
.st-dot .ic { width: 16px; height: 16px; color: #1a1305; stroke-width: 2.6; }
.st-msg { margin: 6px 0 12px; font-size: 14px; line-height: 1.5; min-height: 3em; }
.hbar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.hbar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); transition: width .5s, background .3s; }
.hbar i[data-c="a"] { background: var(--warn); } .hbar i[data-c="r"] { background: var(--bad); }
.st-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin-top: 8px; font-size: 12.5px; color: var(--mut); }
.sim-q { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.qc { padding: 13px 16px 14px; border: 1px solid var(--line); border-radius: 4px; background: rgba(255, 255, 255, .025); }
.qc b { display: block; margin: 8px 0 2px; font: 700 22px/1.25 var(--body); color: var(--hd); }
.qc b.sm { font-size: 16px; line-height: 1.6; margin-bottom: 6px; }
.qc .kh .ic { color: var(--accent); }
.meter { display: flex; gap: 3px; } .meter i { flex: 1; height: 8px; border-radius: 2px; background: rgba(255, 255, 255, .1); }
.meter i.on { background: #86a5c4; } .meter i.on:nth-child(n+5) { background: var(--warn); } .meter i.on:nth-child(n+8) { background: var(--bad); }

/* analysis */
.sim-row3 { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 34%, 400px); gap: 14px; margin-top: 14px; }
.analysis { display: flex; gap: 16px; padding: 18px 20px; }
.analysis .big { width: 34px; height: 34px; margin-top: 1px; color: var(--warn); }
.recs { display: grid; gap: 7px; }
.recs li { position: relative; padding-left: 16px; font-size: 14.5px; line-height: 1.5; }
.recs li::before { content: ""; position: absolute; left: 0; top: .6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.trades { padding: 18px 20px; }
.trades h3 { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.trades h3 .ic { color: var(--mut); }
.checks { display: grid; gap: 7px; }
.checks li { position: relative; padding-left: 22px; font-size: 14px; line-height: 1.45; }
.checks li::before { content: "✓"; position: absolute; left: 0; top: 0; font-weight: 700; color: var(--ok); }
.checks b { color: var(--hd); font-weight: 600; }
.sim-note { margin: 16px 6px 0; font-size: 13px; color: var(--mut); text-align: center; }

.sim:fullscreen { overflow: auto; margin: 0; border-radius: 0; padding: 28px; background: var(--bg); }
.sim.paused .ef, .sim.paused .sn.bn::after { animation-play-state: paused; }

@media (min-width: 1040px) { .sim { padding: 32px 28px 18px; } }
@media (max-width: 899px) {
  .sim-grid, .sim-row2, .sim-row3 { grid-template-columns: minmax(0, 1fr); }
  .sim-q { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .sim { padding: 24px 16px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 0; }
  .kpi:nth-child(3) { padding-left: 0; border-left: 0; } .kpi:nth-child(2) { padding-right: 0; }
  .sim-diagram, .sim-config, .results, .status, .analysis, .trades { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 479px) { .sim-q { grid-template-columns: minmax(0, 1fr); } }
@media (prefers-reduced-motion: reduce) {
  .ef { animation: none; display: none !important; }
  .sn.bn::after { animation: none; opacity: .9; }
}
