@import url('reaction-pipes.css');
.cell.hinted:after{content:attr(data-label);position:absolute;left:3px;bottom:1px;font-size:8px;color:#9b7d34;z-index:4;pointer-events:none}
.grid .cell{padding:0}.grid .cell>.molecule-tile,.grid .cell>.factory-tile{width:calc(100% - 14px);height:calc(100% - 14px);margin:7px}.grid .cell>.pipe-tile{border:0;background:none;border-radius:0;padding:0;box-shadow:none;overflow:visible}.pipe-shape{width:100%;height:100%;pointer-events:none;overflow:visible}.pipe-shape path,.terminal-stub path{fill:none;stroke:#a7b4a0;stroke-width:10;stroke-linecap:round;stroke-linejoin:round}.pipe-shape circle,.terminal-stub circle{fill:#a7b4a0}.pipe-shape.fed path,.terminal-stub.fed path{stroke:#4f9684}.pipe-shape.fed circle,.terminal-stub.fed circle{fill:#4f9684}.terminal-stub{position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none}.rotate-mark{position:absolute;right:3px;bottom:1px;font-size:11px;color:#a1ad97;pointer-events:none;opacity:0}.pipe-tile:hover .rotate-mark,.pipe-tile:focus-visible .rotate-mark{opacity:1}.factory-tile.focused{outline:2px solid #9cb48f;outline-offset:1px}.flow-dot{fill:#e5f4c2;stroke:#72a592;stroke-width:1;opacity:.8}.pipes-svg{z-index:3}.outside-target{z-index:4}.input-summary{display:flex;flex-direction:column;align-items:center;gap:4px;font-size:11px;line-height:1.6;color:#6b8064}.input-summary strong{font-size:9px;font-weight:500;text-transform:uppercase;letter-spacing:1px}.input-summary small{font-size:10px;color:var(--green)}.cell.hinted{box-shadow:inset 0 0 0 3px #d1ad57;background:#f5ebbf}.send-quantity{font-size:8px;line-height:1;color:#768568;pointer-events:none}.grid .cell .molecule-tile .molecule{height:50%}.pipe-board.busy .pipe-shape.fed path{stroke:#b99455}.pipe-board.busy .terminal-stub.fed path{stroke:#b99455}@media(max-width:500px){.grid .cell>.molecule-tile,.grid .cell>.factory-tile{width:calc(100% - 7px);height:calc(100% - 7px);margin:3.5px}.pipe-shape path,.terminal-stub path{stroke-width:9}.send-quantity{font-size:6px}.factory-output{font-size:6px}.flow-dot{r:3}.grid .cell .molecule-tile .molecule{height:46%}}@media(prefers-reduced-motion:reduce){.flow-dot{display:none}}

.exit-pipe,.exit-pipe.open{fill:none;stroke-width:2;stroke-dasharray:4 5;stroke-linejoin:round;opacity:.85}.grid .factory-icon{font-size:36px}.factory-tile.ready .factory-icon{color:#50836b}@media(max-width:500px){.grid .factory-icon{font-size:27px}}

.connection-list{align-items:stretch}.input-summary{padding:7px 12px;border:1px solid #d4dfc8;border-radius:8px;background:#eef1e6}.input-summary.selected-supply{border-color:#9cb48f}.reactant-equation{font-size:13px;font-weight:600}

.grid .factory-tile.has-reactants{gap:3px;padding:3px}.grid .factory-tile.has-reactants .factory-icon{font-size:22px}.factory-reactants{display:flex;flex-wrap:wrap;justify-content:center;gap:0 3px;max-width:100%;font-size:11px;font-weight:600;line-height:1.25;pointer-events:none}.reactant-term{white-space:nowrap}@media(max-width:500px){.grid .factory-tile.has-reactants .factory-icon{font-size:16px}.factory-reactants{font-size:9px}.grid .factory-tile.has-reactants{gap:2px;padding:2px}}

/* The board and level controls share one viewport. */
[hidden]{display:none!important}body{height:100dvh;overflow:hidden}.pipes-app{height:100dvh;max-height:100dvh;display:grid;grid-template-rows:44px minmax(0,1fr) 32px 22px 44px 44px;gap:6px;padding:12px 20px calc(10px + env(safe-area-inset-bottom));}.pipes-app header{gap:12px}.pipes-app h1{font-size:25px}.board-stage{min-height:0;display:flex;align-items:center;justify-content:center}.board-stage .pipe-board{flex:none;width:min(100%,calc((100dvh - 242px - env(safe-area-inset-bottom))*1.2));max-width:610px}#feedback{margin:0 4px;min-height:0;align-self:center;font-size:10px;line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.equation{margin:0;min-height:0;align-self:center;font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.controls{margin:0;padding:0;border:0;gap:16px;align-items:center;flex-wrap:nowrap}.controls button{font-size:20px}.controls span{font-size:9px}.level-footer{display:flex;align-items:center;justify-content:space-between;border-top:1px solid #d7dfcc;padding-top:5px;gap:12px}.level-footer #levelNumber{font-size:12px;color:var(--muted);margin-right:auto}.level-arrow,.level-next{border:0;background:none;min-height:36px;padding:6px 10px}.level-arrow{font-size:21px}.level-next{font-size:12px;font-weight:600;color:var(--green)}@media(max-width:500px){.pipes-app{padding:8px 12px calc(8px + env(safe-area-inset-bottom))}.controls{gap:10px}.controls span{font-size:8px}.pipes-app h1{font-size:23px}}@media(max-height:500px){.pipes-app{grid-template-rows:32px minmax(0,1fr) 24px 18px 32px 36px;gap:3px;padding-top:4px;padding-bottom:4px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 176px)*1.2))}.pipes-app h1{font-size:20px}.icon-button{width:30px;height:30px}.controls button{min-height:30px}}

.pipes-app{grid-template-rows:44px minmax(0,1fr) 32px 22px 44px 88px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 286px - env(safe-area-inset-bottom))*1.2))}.pipes-app header h1{flex:1;text-align:center;font:800 23px system-ui;letter-spacing:-.04em}.pipes-app .icon-button{border:0;border-radius:12px;width:40px;height:44px;background:transparent}.level-footer{display:grid;grid-template-columns:36px auto 64px;grid-template-rows:40px 40px;justify-content:center;gap:0 10px;padding:0;border:1px solid #d9dfd1;border-radius:16px;overflow:hidden;background:#fafbf6}.level-footer #levelNumber{margin:0;font-size:12px}.level-footer select{font:inherit;font-size:12px;border:1px solid #d9dfd1;border-radius:8px;background:#fffaf0;color:var(--ink);padding:6px 10px}.level-next{grid-column:1/-1;border-top:1px solid #cfdfc5;background:#4c7d42;color:white;font:600 14px system-ui;min-height:40px}.level-arrow{padding:0}@media(max-height:500px){.pipes-app{grid-template-rows:32px minmax(0,1fr) 24px 18px 32px 72px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 212px)*1.2))}.level-footer{grid-template-rows:34px 34px}.level-next{min-height:34px}}

/* Match the supplied Numero Nesto screen's top bar and single level/next strip. */
body{background:#faf7f0}.pipes-app{grid-template-rows:44px minmax(0,1fr) 32px 22px 44px 42px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 240px - env(safe-area-inset-bottom))*1.2))}.pipes-app header{gap:5px}.pipes-app .icon-button svg,.level-next-arrow{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.pipes-app .icon-button{flex-shrink:0}.pipes-app .icon-button:disabled{opacity:.35}.level-footer{display:flex;justify-content:center;align-items:stretch;border-radius:0 0 19px 19px;border:0;background:transparent;box-shadow:0 3px 12px #20304708}.level-next{width:100%;display:flex;align-items:center;justify-content:center;gap:8px;border-top:1px solid #cfdfc5;border-radius:0 0 19px 19px;padding:5px 12px;background:#4c7d42;color:#fff}.level-footer #levelNumber{color:inherit;font-size:12px;font-weight:600;letter-spacing:.04em}.level-next-arrow{width:22px;height:22px;stroke-width:2}@media(max-width:380px){.pipes-app .icon-button{width:32px}.pipes-app header h1{font-size:19px}}@media(max-height:500px){.pipes-app{grid-template-rows:32px minmax(0,1fr) 24px 18px 32px 36px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 176px)*1.2))}}

/* Keep interaction announcements accessible without text beneath the canvas. */
.pipes-app #feedback.screen-reader-status{position:absolute;width:1px;height:1px;min-height:0;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.pipes-app{grid-template-rows:44px minmax(0,1fr) 44px 42px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 174px - env(safe-area-inset-bottom))*1.2))}@media(max-height:500px){.pipes-app{grid-template-rows:32px minmax(0,1fr) 32px 36px}.board-stage .pipe-board{width:min(100%,calc((100dvh - 128px)*1.2))}}

.cell.reaction-rejected .factory-tile{border-color:#bc6b58!important;background:#fae7df!important;animation:factory-shake .15s linear 3;box-shadow:0 0 0 3px #bc6b5826}.cell.reaction-rejected .factory-icon{color:#bc6b58!important}.reaction-notice{position:absolute;bottom:8px;left:8px;right:calc(100% / 6 + 8px);z-index:5;pointer-events:none;border:1px solid #d6a18e;border-radius:10px;background:#fff5edee;box-shadow:0 4px 16px #53332218;padding:8px 10px;display:flex;flex-direction:column;gap:2px;color:#864b3d;font-size:10px;line-height:1.4}.reaction-notice strong{font-size:11px}@media(max-width:500px){.reaction-notice{font-size:9px;padding:6px 8px}}

/* Machined pipework: shaded sleeves, raised collars and a lit centre coupling. */
.pipe-board .grid{left:var(--frame);top:var(--frame);width:var(--grid-width);height:var(--grid-width);background:linear-gradient(135deg,#edf2ee,#e2e9e2);border:1px solid #b9c8bd;border-radius:14px;box-shadow:0 12px 30px #30453e12,inset 0 1px 0 #fff}
.pipe-shape path,.terminal-stub path{stroke-linecap:round;stroke-linejoin:round}
.pipe-shape .pipe-shadow,.terminal-stub .pipe-shadow{stroke:#334a4625;stroke-width:23;transform:translateY(3px)}
.pipe-shape .pipe-rim,.terminal-stub .pipe-rim{stroke:#657d78;stroke-width:20}
.pipe-shape .pipe-body,.terminal-stub .pipe-body{stroke:#b7cbc4;stroke-width:14}
.pipe-shape .pipe-highlight,.terminal-stub .pipe-highlight{stroke:#eef6f1;stroke-width:4;opacity:.75;transform:translate(-2px,-2px)}
.pipe-shape.fed .pipe-rim,.terminal-stub.fed .pipe-rim{stroke:#327b70}
.pipe-shape.fed .pipe-body,.terminal-stub.fed .pipe-body{stroke:#72b8a2}
.pipe-collar{fill:#95ada4;stroke:#5f7b70;stroke-width:1.5}
.fed .pipe-collar{fill:#afd5b8;stroke:#458679}
.pipe-shape .pipe-hub,.terminal-stub .pipe-hub{fill:#92aca3;stroke:#607c72;stroke-width:2}
.pipe-shape.fed .pipe-hub,.terminal-stub.fed .pipe-hub{fill:#b4dec2;stroke:#478d7b}
.pipe-shape .hub-light,.terminal-stub .hub-light{fill:#eff9f0}
.grid .cell>.terminal-rotate{position:absolute;right:0;bottom:0;margin:0;width:26px;height:26px;min-height:0;border:1px solid #7e9d8d;border-radius:8px;background:#fffdf2;box-shadow:0 2px 4px #30453e20;z-index:4;font-size:19px;line-height:1;color:#456e5f;padding:0}
.grid .cell>.terminal-rotate:hover{background:#dceddf}.grid .cell>.terminal-rotate:focus-visible{outline-offset:1px}
.grid .cell>.factory-tile{background:linear-gradient(135deg,#f4eef8,#e1d6ec);box-shadow:inset 0 1px 0 white,0 3px 7px #71538b20}
.grid .cell>.factory-tile.final{background:linear-gradient(135deg,#fff4cf,#eddb9f)}
.outside-target{transform:translate(-50%,-50%);border-style:solid;border-width:1px;background:linear-gradient(135deg,#fffdf0,#f2e6bc);border-radius:10px;gap:1px;box-shadow:0 3px 10px #8d74321a;padding:3px 2px}
.outside-target small{font-size:6px;letter-spacing:.8px;line-height:1.2;flex:none}
.target-products{display:flex;flex:1;min-height:0;width:100%;justify-content:center;gap:3px}
.target-product{display:flex;flex-direction:column;align-items:center;justify-content:center;min-width:0;flex:1;gap:1px}
.outside-target .target-product .molecule{width:96%;height:70%;min-height:0}
.outside-target .target-product .formula{font-size:8px;line-height:1.1}.outside-target .target-quantity{font-size:8px;line-height:1}
.target-products.multiple{flex-direction:column;gap:1px}.target-products.multiple .target-product{flex-direction:row;gap:2px;min-height:0}
.outside-target .multiple .target-product .molecule{width:30%;height:95%;flex-shrink:0}.outside-target .multiple .formula{font-size:8px}.outside-target .multiple .target-quantity{font-size:7px}
.pipe-board .exit-pipe{stroke:#bba259;stroke-width:8;stroke-dasharray:none;stroke-linecap:round;opacity:1;filter:drop-shadow(0 2px 1px #5a472320)}
.pipe-board .exit-pipe.open{stroke:#65a180}.pipe-board .exit-pipe.failed{stroke:#bc6b58}
.outside-target.failed{border-color:#bc6b58;background:#fae7df}
#failure{text-align:center}#failure h2{color:#994f3e}.loss-symbol{font-size:64px;color:#bc6b58;line-height:1}
.board-stage .pipe-board{width:min(100%,calc(100dvh - 174px - env(safe-area-inset-bottom)));max-width:650px}
.reaction-notice{left:var(--frame);right:var(--frame);bottom:var(--frame)}
@media(max-width:500px){.grid .cell>.terminal-rotate{width:23px;height:23px;font-size:17px;border-radius:6px}.outside-target .target-product .formula{font-size:6px}.outside-target .multiple .formula{font-size:6px}.outside-target .multiple .target-quantity{font-size:6px}.outside-target small{font-size:5px;letter-spacing:.4px}.outside-target .target-quantity{font-size:7px}.grid .cell>.molecule-tile,.grid .cell>.factory-tile{margin:5px;width:calc(100% - 10px);height:calc(100% - 10px)}}
@media(max-height:500px){.board-stage .pipe-board{width:min(100%,calc(100dvh - 128px))}}

/* Smaller one-unit reactants expose the rotating connections around the circle. */
.grid .cell>.molecule-tile{width:62%;height:62%;margin:19%;padding:2px;box-shadow:0 2px 5px #30453e20}
.grid .cell .molecule-tile .molecule{width:96%;height:74%;flex-shrink:0}.grid .cell .molecule-tile .formula{font-size:8px;line-height:1.1}
.delivered-reactor{position:relative;z-index:2;width:calc(100% - 14px);height:calc(100% - 14px);margin:7px;border:2px solid #7da36b;border-radius:12px;background:#e5efdc;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:3px}
.delivered-reactor.incorrect{border-color:#bc6b58;background:#fae7df}.delivered-reactor .factory-icon{font-size:22px;color:#50836b}.factory-products{font-size:12px;font-weight:600;text-align:center;line-height:1.2}
.reaction-notice{display:block;width:max-content;max-width:70%;left:50%;right:auto;bottom:var(--frame);transform:translateX(-50%);text-align:center;font-size:12px;font-weight:600;animation:notice-flash 1.5s ease both}
@keyframes notice-flash{0%{opacity:0}10%,75%{opacity:1}100%{opacity:0}}
@media(max-width:500px){.grid .cell>.molecule-tile{width:62%;height:62%;margin:19%}.grid .cell .molecule-tile .formula{font-size:6px}.delivered-reactor{margin:4px;width:calc(100% - 8px);height:calc(100% - 8px)}.factory-products{font-size:9px}.delivered-reactor .factory-icon{font-size:18px}.reaction-notice{font-size:10px}}

.audio-status{position:fixed;bottom:110px;left:50%;transform:translateX(-50%);z-index:10;background:#fff5ed;border:1px solid #d6a18e;border-radius:9px;padding:8px 12px;font-size:11px;color:#864b3d;white-space:nowrap}

/* Completed reactions remain readable; consumed molecules remain visible but inert. */
.grid .cell>.molecule-tile.spent{opacity:1;filter:none;cursor:default;box-shadow:none;border-style:dashed;border-color:#87998d}
.cell:has(>.spent)>.terminal-stub{opacity:.2;filter:grayscale(1)}
.completed-equation{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:11px;font-weight:650;line-height:1.25;text-align:center;overflow-wrap:anywhere;width:100%}
.completed-equation .equation-arrow{font-size:17px;color:#50836b;line-height:1}
.delivered-reactor{padding:5px;overflow:hidden}.delivered-reactor.correct{border-color:#548a68;background:#e5efdc}
.internal-reaction{position:absolute;inset:5px;z-index:2;border:1px solid #9a83b0;border-radius:10px;background:#f2ecf7;padding:3px 3px 30%;display:flex;align-items:center;justify-content:center}
.internal-reaction .completed-equation{font-size:9px;gap:0}.internal-reaction .equation-arrow{font-size:13px}
.grid .cell>.molecule-tile.reactor-product{position:absolute;z-index:3;width:38%;height:38%;margin:0;bottom:1px;left:31%;background:#fffdf4;border-width:1px}
.grid .cell .reactor-product .molecule{height:52%}.grid .cell .reactor-product .formula{font-size:8px}
.outside-target.open{border:2px solid #458463;background:linear-gradient(135deg,#f0fae8,#d6edce);box-shadow:0 0 0 3px #6caa6c22,0 3px 8px #37684d22}
.outside-target.open small{color:#356647;font-weight:800;letter-spacing:.4px}.output-check{position:absolute;right:-6px;top:-7px;width:19px;height:19px;border-radius:50%;background:#458463;color:white;border:2px solid #faf7f0;display:grid;place-items:center;font-size:12px;font-weight:800}
@media(max-width:500px){.completed-equation{font-size:8px}.completed-equation .equation-arrow{font-size:13px}.internal-reaction{inset:3px}.internal-reaction .completed-equation{font-size:7px}.internal-reaction .equation-arrow{font-size:10px}.grid .cell .reactor-product .formula{font-size:6px}.output-check{width:16px;height:16px;font-size:10px}}

.delivered-reactor.internal-complete{border-color:#9a83b0;background:#f2ecf7}.delivered-reactor.internal-complete .equation-arrow{color:#806398}

.cell.reacting.thermal-unspecified .factory-tile{background:#e8e5f1!important;box-shadow:0 0 20px #9f88b744}

.level-lesson{padding:10px 12px;border-left:3px solid var(--green);background:#edf2e7;border-radius:5px;color:var(--ink)}

.lesson-picker{display:flex;flex-direction:column;gap:6px;font-size:12px;color:var(--ink);margin:12px 0}.lesson-picker select{width:100%;min-height:40px;border:1px solid #cbd7c2;border-radius:8px;background:#fffdf4;color:var(--ink);font:inherit;padding:8px}

/* Use the whole cell for chemistry; fixed pipework stays visible behind the content. */
.grid .cell{container-type:inline-size}
.grid .cell>.factory-tile,.grid .cell>.factory-tile.has-reactants,.grid .cell>.delivered-reactor{width:100%;height:100%;margin:0;padding:3px;border-radius:8px;min-width:0;min-height:0;gap:0;overflow:visible;box-shadow:none}
.grid .cell>.factory-tile{background:#eee5f4c9}.grid .cell>.factory-tile.final{background:#fff1c9c9}
.grid .cell>.delivered-reactor.correct{background:#e5efdce0}.grid .cell>.delivered-reactor.internal-complete{background:#f2ecf7dc}
.cell:has(>.factory-tile)>.terminal-stub,.cell:has(>.delivered-reactor)>.terminal-stub{opacity:.38}
.reactor-supplies{display:grid;grid-template-columns:repeat(var(--supplies),minmax(0,1fr));width:100%;height:100%;gap:2px;min-height:0;pointer-events:none}
.reactor-supply{display:grid;grid-template-rows:minmax(0,1fr) auto;align-items:center;justify-items:center;min-width:0;min-height:0;gap:1px}
.reactor-supply .molecule{width:100%;height:100%;min-height:0;max-width:none;pointer-events:none}
.reactor-supply .formula{font-size:8px;font-size:clamp(6px,12cqi,11px);line-height:1.1;white-space:normal;overflow-wrap:anywhere;text-align:center;max-width:100%}
.completed-equation{height:100%;min-height:0;gap:1px;line-height:1.05;font-size:9px;font-size:clamp(6px,12cqi,11px);font-weight:650;justify-content:center}
.completed-equation.dense{font-size:8px;font-size:clamp(5px,9cqi,9px);gap:0}
.equation-side{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:0 2px;min-width:0;max-width:100%}
.equation-term{min-width:0;max-width:100%;overflow-wrap:anywhere;white-space:normal}.equation-plus{flex:none}
.completed-equation .equation-arrow{font-size:12px;line-height:1;flex:none}
.grid .cell>.molecule-tile{width:100%;height:100%;margin:0;padding:5px 4px;border:0;background:transparent;box-shadow:none;display:grid;grid-template-rows:minmax(0,1fr) auto;gap:0;border-radius:50%}
.grid .cell .molecule-tile .molecule{width:100%;height:100%;min-height:0;flex-shrink:1}
.grid .cell .molecule-tile .formula{font-size:8px;font-size:clamp(6px,12cqi,10px);white-space:normal;overflow-wrap:anywhere;line-height:1.05;max-width:100%;text-align:center}
.grid .cell>.molecule-tile.spent{border:1px dashed #87998d;background:transparent;opacity:1;filter:none}
.cell:has(>.molecule-tile)>.terminal-stub{opacity:.38}.cell:has(>.spent)>.terminal-stub{opacity:.18}
.outside-target .target-product{display:grid;grid-template-rows:minmax(0,1fr) auto;width:100%;height:100%;min-height:0;gap:0}
.outside-target .target-product .molecule{width:100%;height:100%;min-height:0}
.outside-target .target-product .formula{white-space:normal;overflow-wrap:anywhere;max-width:100%;line-height:1.1;font-size:8px}
.detail-equation{overflow-wrap:anywhere;white-space:normal;font-size:16px;line-height:1.5;background:#edf2e7;padding:12px;border-radius:8px}
.detail-products{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.detail-product{display:flex;flex-direction:column;align-items:center;gap:5px;padding:10px;background:#f1f3e9;border-radius:10px;min-width:0;text-align:center}
.detail-product .molecule{width:100%;height:90px}.detail-product strong{overflow-wrap:anywhere;font-size:13px;max-width:100%}.detail-product small{font-size:10px;line-height:1.3;color:var(--muted)}
@media(max-width:500px){.grid .cell>.factory-tile,.grid .cell>.factory-tile.has-reactants,.grid .cell>.delivered-reactor{margin:0;width:100%;height:100%;padding:2px}.grid .cell>.molecule-tile{margin:0;width:100%;height:100%;padding:3px 2px}.outside-target .target-product .formula{font-size:7px}}

/* Chemistry stays above local pipes; neighbouring tile graphics cannot bleed into it. */
.grid .cell{isolation:isolate;overflow:hidden}
.grid .cell>.terminal-stub{z-index:0}
.grid .cell>.molecule-tile,.grid .cell>.factory-tile,.grid .cell>.delivered-reactor{position:relative;z-index:2}
.grid .cell>.molecule-tile{cursor:default}
.molecule-tile .formula,.reactor-supply .formula{position:relative;z-index:3;background:#faf7f0ed;border-radius:3px;padding:1px 2px}
.outside-target .target-product{justify-items:center;text-align:center}
.outside-target .target-product .formula{display:block;width:100%;text-align:center;justify-self:center;align-self:center}

/* Pale blue identifies reactant cells while leaving their feed pipes visible. */
.grid .cell:has(>.molecule-tile){background:linear-gradient(135deg,#e8f3fa,#d7e9f1)}
.grid .cell:has(>.molecule-tile.spent){background:linear-gradient(135deg,#edf3f6,#e1ebef)}
.grid .cell>.molecule-tile .formula{background:#edf6fbee}
.reactor-symbol{position:absolute;top:2px;left:3px;z-index:4;width:14px;height:14px;display:grid;place-items:center;font-size:12px;line-height:1;border-radius:4px;background:#faf7f0f2;color:#806398;pointer-events:none}
.factory-tile.final .reactor-symbol{color:#9b762f}.delivered-reactor.correct .reactor-symbol{color:#458463}
@media(max-width:500px){.reactor-symbol{top:1px;left:2px;width:11px;height:11px;font-size:10px}}

/* Reactors show a centred symbol and formulas; structures belong to reactants. */
.grid .cell>.factory-tile,.grid .cell>.factory-tile.has-reactants,.grid .cell>.delivered-reactor{display:flex;flex-direction:column;border:2px solid #9a83b0!important;padding:3px;gap:2px;background:#f2ecf7e8}
.grid .cell>.factory-tile.final{border-color:#b79748!important;background:#fff1d5e8}
.grid .cell>.delivered-reactor.correct{border-color:#458463!important;background:#e5efdce8}
.grid .cell>.delivered-reactor.incorrect{border-color:#bc6b58!important}
.reactor-symbol{position:static;align-self:center;flex:none;width:auto;height:auto;background:none;border-radius:0;font-size:22px;line-height:1;margin:0;color:#806398}
.factory-tile>.factory-icon{display:none}
.reactor-supplies{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;align-content:center;gap:1px 4px;height:auto;min-height:0;flex:1}
.reactor-supply{display:block;min-width:0;max-width:100%}
.reactor-supply .formula{display:block;text-align:center;font-size:clamp(7px,14cqi,12px);background:none;padding:0}
.delivered-reactor .completed-equation{flex:1;height:auto;min-height:0}
.grid .cell .molecule-tile .formula{font-size:11px;font-size:clamp(8px,17cqi,14px);font-weight:700;line-height:1.15;padding:1px 2px}
@media(max-width:500px){.reactor-symbol{position:static;width:auto;height:auto;font-size:18px}.grid .cell>.factory-tile,.grid .cell>.factory-tile.has-reactants,.grid .cell>.delivered-reactor{padding:2px;gap:1px}.grid .cell .molecule-tile .formula{font-size:clamp(8px,17cqi,12px)}}

/* Reactants have a blue frame; reactor inputs read as a joined chemical expression. */
.grid .cell>.molecule-tile{border:2px solid #72a5bb;border-radius:8px}
.grid .cell>.molecule-tile.spent{border:2px dashed #879eac}
.reactor-input-formula{display:block;flex:1;align-content:center;width:100%;min-width:0;text-align:center;font-size:clamp(8px,15cqi,13px);font-weight:650;line-height:1.2;white-space:normal;overflow-wrap:anywhere;color:var(--ink)}

/* Each formula is an indivisible line; expressions wrap only between chemical terms. */
.formula,.equation-term,.formula-piece,.detail-product strong{white-space:nowrap!important;overflow-wrap:normal!important;word-break:normal;min-width:0;max-width:100%}
.formula-piece{display:inline-block}
.reactor-input-formula{display:flex;align-items:center;justify-content:center;align-content:center;flex-wrap:wrap;gap:0 3px;white-space:normal;overflow-wrap:normal}
.detail-equation{overflow-wrap:normal;word-break:normal}

/* One standard formula size; only labels that fail their own fit check shrink. */
.grid .cell .molecule-tile .formula,.outside-target .target-product .formula,.reactor-input-formula,.equation-term,.formula-piece,.detail-product strong,.detail-equation{font-size:11px}

/* Reactor expressions wrap between terms and fit within the remaining cell height. */
.grid .cell>.factory-tile,.grid .cell>.delivered-reactor{overflow:hidden;min-width:0;min-height:0;box-sizing:border-box}
.reactor-input-formula,.completed-equation{min-height:0;min-width:0;max-width:100%;overflow:hidden}
.completed-equation .equation-side{flex:none;width:100%}
.reactor-input-formula .formula-piece,.completed-equation .equation-term{flex-shrink:0}

.reaction-tutorial{margin:8px auto;padding:12px 16px;background:#edf6fb;border:1px solid #72a5bb;border-radius:12px;max-width:480px;text-align:center}
.reaction-tutorial[hidden]{display:none}.reaction-tutorial p{margin:8px 0;font-size:14px;line-height:1.4}.reaction-tutorial button{padding:7px 12px}
.grid .cell.tutorial-highlight{box-shadow:inset 0 0 0 4px #f3a34a;z-index:3;animation:tutorialGlow 1.2s ease-in-out infinite alternate}
.level-congratulations{text-align:center;color:#377357;font-weight:700;margin:12px 0 4px}.level-congratulations[hidden]{display:none}
.level-next:disabled{opacity:.45;cursor:not-allowed}
.board-stage{position:relative}.reaction-win-effects{position:absolute;inset:0;z-index:20;pointer-events:none;overflow:hidden}
.reaction-confetti{position:absolute;top:-12px;width:7px;height:12px;border-radius:2px;animation:reactionConfetti 1.5s ease-in both}
@keyframes reactionConfetti{to{transform:translate(var(--drift),650px) rotate(540deg);opacity:0}}
@keyframes tutorialGlow{to{box-shadow:inset 0 0 0 4px #ffda72}}
@media(prefers-reduced-motion:reduce){.reaction-confetti{display:none}.grid .cell.tutorial-highlight{animation:none}}

/* Explicit rows keep optional tutorial/status panels from taking the board's row. */
body{overflow-y:auto}
.pipes-app{grid-template-areas:"header" "tutorial" "board" "audio" "controls" "congratulations" "footer";grid-template-rows:44px auto minmax(180px,1fr) auto 44px auto 42px;min-height:560px}
.pipes-app:has(.reaction-tutorial:not([hidden])){min-height:680px}
.pipes-app>header{grid-area:header}
.reaction-tutorial{grid-area:tutorial;align-self:start;width:100%;max-width:540px;margin:0 auto;padding:10px 14px}
.board-stage{grid-area:board;container-type:size;width:100%;height:100%;min-height:0}
.board-stage .pipe-board{width:min(100%,100cqh);max-width:650px;max-height:100%;aspect-ratio:1}
.audio-status{grid-area:audio;margin:0;text-align:center}
.controls{grid-area:controls}
.level-congratulations{grid-area:congratulations;margin:0;font-size:14px}
.level-footer{grid-area:footer}
.reaction-tutorial #tutorialNext{border:0;border-radius:8px;background:var(--green);color:white;font-size:13px;min-height:36px;padding:8px 14px}
@media(max-height:500px){.pipes-app{grid-template-rows:32px auto minmax(180px,1fr) auto 32px auto 36px}}

.reaction-tutorial .tutorial-status{font-size:12px;color:var(--muted);margin:5px 0 8px}
.tutorial-turn .pipe-shape{animation:tutorialPipeTurn .55s ease-in-out}
@keyframes tutorialPipeTurn{from{transform:rotate(-90deg)}to{transform:rotate(0)}}
@media(prefers-reduced-motion:reduce){.tutorial-turn .pipe-shape{animation:none}}

.tutorial-finger{position:absolute;z-index:30;pointer-events:none;font-size:clamp(28px,6vw,44px);line-height:1;transform:translate(-50%,-5%);filter:drop-shadow(0 2px 2px #30453e44);animation:tutorialFingerTap .55s ease-in-out both}
.tutorial-tap-ring{position:absolute;left:50%;top:0;width:28px;height:28px;border:3px solid #f3a34a;border-radius:50%;transform:translate(-50%,-50%);animation:tutorialTapRing .55s ease-out both}
@keyframes tutorialFingerTap{0%,100%{translate:0 10px;opacity:0}30%{translate:0 0;opacity:1}60%{translate:0 -4px;opacity:1}80%{translate:0 0;opacity:1}}
@keyframes tutorialTapRing{0%,30%{scale:.5;opacity:0}55%{scale:1;opacity:1}100%{scale:1.6;opacity:0}}
@media(prefers-reduced-motion:reduce){.tutorial-finger{animation:none}.tutorial-tap-ring{animation:none}}

.feed-outlets{position:absolute;inset:0;width:100%;height:100%;z-index:5;pointer-events:none}
.feed-outlets path{fill:none;stroke:#237669;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;filter:drop-shadow(0 0 1px #fff)}
.feed-outlets.inactive path{stroke:#879eac}
.pipe-lock{position:absolute;right:3px;bottom:3px;font-size:13px;line-height:1;background:#edf6fb;border:1px solid #72a5bb;border-radius:5px;padding:2px;pointer-events:none}
.grid .cell>.pipe-tile:has(.pipe-lock){opacity:1;background:#dfeee733;box-shadow:inset 0 0 0 2px #72a5bb}

.pipes-app .home-button svg{width:22px;height:22px}.pipes-app .home-button{border-radius:10px;transition:background .15s ease,color .15s ease}.pipes-app .home-button:hover{background:rgba(32,48,71,.05)}
