.lab-page {
  background: radial-gradient(ellipse at 87% 6%, #e0faff, transparent 35rem),
    radial-gradient(ellipse at 10% 20%, #f8edff, transparent 35rem), #f5fcf9;
  color: #193647;
}
.lab-page [hidden] { display: none !important; }
.lab-page button { font: inherit; cursor: pointer; }
.lab-page button:disabled { cursor: default; }
.lab-page :focus-visible { outline: 3px solid #6236ad; outline-offset: 2px; }
.lab-page .lab-main { width: min(1560px, calc(100% - 28px)); padding-block: 8px 20px; }
.lab-intro { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 3px 0 8px; }
.lab-intro h1 { margin: 0; font-size: clamp(1.5rem, 3.25vw, 2.65rem); line-height: 1.08; letter-spacing: -.05em; }
.lab-intro .lab-button { min-height: 34px; white-space: nowrap; }
.lab-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; }
.lab-settings, .lab-cabinet { border: 1px solid #a9d2c4; border-radius: 21px; box-shadow: 0 9px 27px #183c4e14; }
.lab-settings { display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: 9px 14px; padding: 7px 10px; background: #fff; border-radius: 13px; }
.lab-chapter h2 { margin: 0; font-size: .94rem; line-height: 1.15; }
.lab-chapter p { color: #365965; font-size: .69rem; line-height: 1.3; }
.lab-difficulty { display: flex; align-items: center; gap: 5px; }
.lab-settings label { font-size: .73rem; font-weight: 850; }
.lab-settings select { width: 100%; min-height: 37px; border: 1px solid #9bbab6; border-radius: 8px; padding-inline: 5px; background: #f4fbff; color: #16364b; font: inherit; font-size: .82rem; font-weight: 800; }
.lab-missions { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.lab-missions button {
  display: flex; justify-content: center; align-items: center; gap: 5px;
  min-width: 0; min-height: 38px; padding: 3px; border: 1px solid #c4ddd3; border-radius: 9px;
  color: #213e54; background: #f7fbfa; text-align: left;
}
.lab-missions button:is(:hover, [aria-pressed="true"]) { border-color: #429f82; background: #e4f9ef; }
.lab-missions button[aria-pressed="true"] { box-shadow: inset 3px 0 #188571; }
.lab-missions button[data-cleared="true"] b { color: #14644b; text-decoration: underline; text-decoration-thickness: 2px; }
.lab-missions b { font-size: .78rem; }
.lab-mission-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; color: #fff; background: var(--cargo-color); }
.lab-mission-icon svg { width: 15px; height: 15px; }

.lab-cabinet { display: grid; grid-template-rows: auto auto; min-width: 0; overflow: hidden; background: #f7fcff; }
.lab-board {
  position: relative; isolation: isolate; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  height: clamp(300px, 49vh, 565px); padding: 10px; background: #b9e7e6;
}
.lab-board::before { content: ""; position: absolute; z-index: -1; inset: 0; background: url("schoolyard.webp") center / cover; transition: transform .65s ease-out; }
.lab-board[data-phase="running"]::before { transform: scale(1.045); }
.lab-board-top { z-index: 1; display: flex; align-items: start; justify-content: space-between; gap: 6px; }
.lab-stage-title { min-width: 0; padding: 5px 11px 7px; border: 1px solid #fff; border-radius: 12px; background: #fffdf2ee; box-shadow: 0 3px 14px #27414a25; }
.lab-stage-title p { color: #205e62; font-size: .7rem; line-height: 1.2; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.lab-stage-title h2 { margin: 1px 0 0; font-size: clamp(1rem, 2.8vw, 1.7rem); line-height: 1.08; letter-spacing: -.035em; }
.lab-display-controls { display: flex; flex: 0 0 auto; gap: 6px; }
.lab-display-controls button {
  display: grid; place-items: center; width: 43px; height: 43px; padding: 0; border: 1px solid #ffffffbd; border-radius: 12px;
  background: #12384cce; color: #fff; box-shadow: 0 3px 13px #12354a41;
}
.lab-display-controls button:hover { background: #12384cf2; }
.lab-display-controls button:focus-visible { outline-color: white; }
.lab-display-controls svg, .lab-button svg { width: 19px; height: 19px; flex: 0 0 auto; }
.lab-world { position: relative; min-height: 0; align-self: stretch; overflow: hidden; pointer-events: none; }
.lab-machine {
  position: absolute; left: 50%; bottom: 0; display: block; width: min(86%, 880px); height: 100%;
  transform: translateX(-50%); filter: drop-shadow(0 3px 3px #32575a30);
}
.lab-character { position: absolute; bottom: 4px; display: grid; justify-items: center; width: 17%; max-width: 172px; }
.lab-character img { width: 100%; height: auto; max-height: 210px; object-fit: contain; filter: drop-shadow(0 4px 4px #123e5350); }
.lab-character span { margin-top: -4px; padding: 1px 7px; border: 1px solid #fff; border-radius: 15px; background: #fff9e6; color: #214254; font-size: .68rem; font-weight: 850; }
.lab-paxa { left: 0; }
.lab-host { right: 0; }
.lab-board[data-phase="success"] .lab-character img { animation: lab-cheer .55s cubic-bezier(.2,.7,.32,1) 2; }
.lab-board-bottom { display: grid; align-items: center; justify-items: center; gap: 4px; min-height: 25px; z-index: 1; }
.lab-objective {
  margin: 0; max-width: 100%; padding: 4px 9px; border-radius: 8px;
  color: #173948; background: #fffff3f2; font-weight: 750; font-size: .79rem; line-height: 1.25; text-align: center;
}
.lab-timeline { display: flex; gap: 4px; width: min(58%, 390px); padding: 4px; border: 1px solid #fff; border-radius: 20px; background: #173b53d9; }
.lab-timeline span { flex: 1; height: 7px; overflow: hidden; border-radius: 8px; background: #ffffff4f; }
.lab-timeline span::after { display: block; content: ""; width: var(--run-progress, 0%); height: 100%; background: linear-gradient(90deg, #54dcb9, #e7fa7a); }
.lab-timeline span[data-outcome="force"]::after, .lab-timeline span[data-outcome="travel"]::after { background: #ffb591; }
.lab-timeline span[data-outcome="force"] { outline: 1px solid #ffb591; }
.lab-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lab-confetti i {
  position: absolute; left: var(--start); top: 3%; width: 9px; height: 15px; border-radius: 2px; background: var(--confetti);
  animation: lab-confetti 1.2s var(--wait) ease-in both;
}
.lab-finish-mark { position: absolute; inset: 18% auto auto 50%; display: grid; place-items: center; width: clamp(35px, 8vw, 77px); aspect-ratio: 1; border: 3px solid #fff4cb; border-radius: 50%; color: #fff; background: var(--mission-color); box-shadow: 0 0 0 10px #fff5bc68, 0 8px 22px #163f4b40; animation: lab-finish 1.65s cubic-bezier(.2,.7,.28,1) both; }
.lab-finish-mark svg { width: 61%; height: 61%; }
@keyframes lab-cheer { 50% { transform: translateY(-12px) rotate(-5deg); } }
@keyframes lab-confetti { from { opacity: 0; transform: translateY(-14px) rotate(0); } 20% { opacity: 1; } to { opacity: 0; transform: translateY(225px) rotate(285deg); } }
@keyframes lab-finish { 0% { opacity: 0; transform: translate(-50%, 22px) scale(.45); } 27%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -35px) scale(1.1); } }

.lab-console { display: grid; gap: 8px; align-content: start; padding: 10px 12px 12px; background: linear-gradient(120deg, #f6fffd, #eff8ff); }
.lab-route-row, .lab-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.lab-route { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.lab-route button {
  display: inline-flex; align-items: center; gap: 4px; min-height: 38px; padding: 2px 8px; border: 1px solid #aecbc8;
  border-radius: 8px; color: #244957; background: #fff; font-size: .77rem; font-weight: 850;
}
.lab-route button svg { width: 16px; height: 16px; }
.lab-route button[aria-pressed="true"] { border-color: #2f8c80; background: #d6f8ec; color: #134d51; }
.lab-route button[data-outcome="pass"] { border-color: #398961; }
.lab-route button[data-outcome="force"], .lab-route button[data-outcome="travel"] { border-color: #a74946; background: #fff1df; }
.lab-budget { margin-inline-start: auto; padding: 4px 7px; border: 1px solid #c4bde8; border-radius: 6px; background: #f1edff; color: #4e3e82; font-size: .74rem; font-weight: 850; }
.lab-budget[data-over="true"] { border-color: #bc6256; background: #fff1df; color: #7c322a; }
.lab-workbench { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .98fr); gap: 9px; }
.lab-parts, .lab-reading { min-width: 0; padding: 7px 8px; border: 1px solid #bfd7d5; border-radius: 10px; background: #fff; }
.lab-parts > p { margin-bottom: 4px; color: #2d5961; font-size: .74rem; font-weight: 850; }
.lab-options, .lab-readouts { display: grid; gap: 5px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lab-readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.lab-options button {
  min-height: 44px; min-width: 0; padding: 3px 2px; border: 1px solid #b4cdce; border-radius: 7px;
  background: #f4fafc; color: #254d60; font-size: .77rem; line-height: 1.12; font-weight: 850;
}
.lab-options button:hover { background: #e7f9ef; }
.lab-options button[aria-pressed="true"] { border-color: #20816a; background: #d9fae6; color: #145449; box-shadow: inset 0 -2px #7bcab0; }
.lab-options small { display: block; margin-top: 2px; font-size: .65rem; font-weight: 700; }
.lab-reading { display: grid; align-content: center; color: #305562; line-height: 1.13; }
.lab-reading > span, .lab-reading small { font-size: .68rem; }
.lab-reading strong { font-size: 1.18rem; color: #19644e; }
.lab-reading[data-over="true"] strong { color: #9a392e; }
.lab-reading meter { width: 100%; height: 6px; margin-top: 3px; background: #e1eae8; border-radius: 4px; }
.lab-reading meter::-webkit-meter-bar { border: 0; background: #e1eae8; border-radius: 4px; }
.lab-reading meter::-webkit-meter-optimum-value { background: #248b6e; }
.lab-reading meter::-webkit-meter-suboptimum-value, .lab-reading meter::-webkit-meter-even-less-good-value { background: #bc584a; }
.lab-feedback { display: flex; justify-content: space-between; align-items: center; min-height: 49px; gap: 6px; padding: 5px 9px; border: 1px solid #bad6e5; border-radius: 9px; background: #eaf6ff; color: #21465f; }
.lab-feedback[data-tone="fail"] { border-color: #e3af92; background: #fff2e6; color: #722f26; }
.lab-feedback[data-tone="success"] { border-color: #85cbb0; background: #dcf9e8; color: #1b5646; }
.lab-feedback strong { display: block; font-size: .83rem; line-height: 1.15; }
.lab-feedback p { margin: 1px 0 0; font-size: .74rem; line-height: 1.25; }
.lab-stars { flex: 0 0 auto; color: #795014; font-size: 1rem; white-space: nowrap; }
.lab-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 42px; padding: 5px 11px;
  border: 1px solid transparent; border-radius: 9px; color: #173c4c; font-size: .81rem !important; line-height: 1.12;
  font-weight: 850 !important; text-align: center; text-decoration: none;
}
.lab-soft { border-color: #a9c9cc; background: #f6fdff; }
.lab-soft:hover { background: #e7f8ff; }
.lab-primary { background: linear-gradient(135deg, #166a5f, #137e66); border-color: #086153; color: #fff; }
.lab-primary:hover { background: #146051; }
.lab-reset { min-width: 42px; padding-inline: 5px; }
.lab-speed { min-width: 42px; font-variant-numeric: tabular-nums; }
.lab-speed[aria-pressed="true"] { background: #e7d9ff; border-color: #8b6dbc; color: #41226e; }
.lab-next { margin-inline-start: auto; background: #fce8a6; border-color: #d9ab52; color: #573b20; }
.lab-next:hover { background: #ffdc7a; }
.lab-footer-strip { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; }
.lab-help { margin-top: 10px; padding: 7px 10px; border: 1px solid #bfd7d5; border-radius: 10px; background: #fff; }
.lab-help > summary { color: #254d60; font-size: .86rem; font-weight: 800; cursor: pointer; }
.lab-help .game-reading { margin-top: 9px; }

.lab-layout:is(:fullscreen, .is-expanded) {
  display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 0;
  width: 100%; height: 100%; padding: 0; background: #eafbf6;
}
.lab-layout.is-expanded { position: fixed; inset: 0; z-index: 1000; height: 100dvh; }
body:has(.lab-layout.is-expanded) { overflow: hidden; }
body:has(.lab-layout.is-expanded) :is(.site-header, .games-footer, .lab-intro, .game-crumbs, .lab-help, .skip) { visibility: hidden; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-settings { display: none; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-cabinet {
  grid-template-rows: minmax(0, 1fr) auto; height: 100%; border: 0; border-radius: 0;
  overflow: auto; overscroll-behavior: contain;
}
.lab-layout:is(:fullscreen, .is-expanded) .lab-board { height: auto; min-height: 0; padding: max(7px, env(safe-area-inset-top)) 10px 7px; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-machine { width: 94%; max-height: none; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-console { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.lab-layout:is(:fullscreen, .is-expanded) .lab-display-controls button { background: #12384c9e; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-character { max-width: 165px; }
.lab-layout:is(:fullscreen, .is-expanded) .lab-character img { max-height: 220px; }
@media (min-width: 781px) and (max-height: 820px) {
  .lab-board { height: clamp(245px, calc(100svh - 482px), 350px); }
}
@media (max-width: 780px) {
  .lab-settings { grid-template-columns: minmax(0, 1fr) auto; gap: 5px; }
  .lab-missions { grid-column: 1 / -1; }
  .lab-footer-strip { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 540px) {
  .lab-page .lab-main { width: calc(100% - 14px); }
  .lab-settings { padding: 5px; }
  .lab-settings label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .lab-missions button { min-height: 37px; gap: 2px; }
  .lab-mission-icon { width: 18px; height: 21px; }
  .lab-mission-icon svg { width: 13px; height: 13px; }
  .lab-board { height: clamp(235px, 42vh, 330px); padding: 7px; }
  .lab-console { padding: 7px; gap: 6px; }
  .lab-workbench { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .lab-parts, .lab-reading { padding: 4px 6px; }
  .lab-reading { grid-template-columns: 1fr auto; column-gap: 4px; }
  .lab-reading small { grid-column: 1 / -1; }
  .lab-reading meter { grid-column: 1 / -1; }
  .lab-reading strong { font-size: .96rem; }
  .lab-options button { min-height: 39px; }
  .lab-route button { min-height: 35px; padding-inline: 5px; }
  .lab-display-controls button { width: 37px; height: 37px; }
  .lab-button { min-height: 38px; padding-inline: 7px; }
  .lab-button svg { width: 15px; height: 15px; }
  .lab-character { width: 16%; }
  .lab-character img { max-height: 94px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .lab-layout:is(:fullscreen, .is-expanded) .lab-cabinet { grid-template-columns: minmax(0, 1.2fr) minmax(280px, 1fr); grid-template-rows: minmax(0, 1fr); }
  .lab-layout:is(:fullscreen, .is-expanded) .lab-console { align-content: center; }
  .lab-layout:is(:fullscreen, .is-expanded) .lab-workbench { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .lab-layout:is(:fullscreen, .is-expanded) .lab-footer-strip { grid-template-columns: minmax(0, 1fr); }
  .lab-layout:is(:fullscreen, .is-expanded) .lab-character { width: 16%; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-board::before { transition: none; transform: none !important; }
  .lab-character img, .lab-confetti i { animation: none !important; }
  .lab-confetti { display: none; }
}
