:root {
  color-scheme: light;
  --paper: #f7f8f4;
  --bench: #e5ebe5;
  --bench-deep: #d1dbd2;
  --glass: #d8eee8;
  --glass-edge: #0b675a;
  --green: #153f39;
  --green-2: #0b675a;
  --ink: #17302c;
  --muted: #526861;
  --line: #91a49d;
  --line-soft: #c5d0ca;
  --coral: #c64b36;
  --coral-dark: #a63e2d;
  --brass: #d1a94c;
  --brass-dark: #785d1d;
  --white: #fff;
  --shadow: rgba(23, 48, 44, 0.18);
  --topbar-height: 72px;
  --focus: #ffb000;
  font-family: "Segoe UI Variable", "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(21, 63, 57, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 63, 57, 0.035) 1px, transparent 1px),
    var(--bench);
  background-size: 28px 28px;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

button,
a,
select,
input {
  touch-action: manipulation;
}

button {
  color: inherit;
}

button:not(:disabled),
a,
select,
input {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(255, 176, 0, 0.28);
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(168px, 1fr) auto minmax(168px, 1fr);
  align-items: center;
  min-height: var(--topbar-height);
  padding: 10px clamp(14px, 2.4vw, 34px);
  color: var(--paper);
  background: var(--green);
  border-bottom: 5px solid var(--brass);
  box-shadow: 0 4px 0 rgba(23, 48, 44, 0.16);
}

.topbar::after {
  position: absolute;
  right: 0;
  bottom: -9px;
  left: 0;
  height: 4px;
  content: "";
  background: repeating-linear-gradient(
    90deg,
    var(--green) 0 10px,
    transparent 10px 18px
  );
  opacity: 0.38;
}

.back-link {
  grid-column: 1;
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-height: 44px;
  gap: 9px;
  padding: 8px 11px;
  color: inherit;
  font-size: 0.82rem;
  font-weight: 750;
  text-decoration: none;
  letter-spacing: 0.02em;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.back-mark {
  font-size: 1.24rem;
  line-height: 1;
}

.title-lockup {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 11px;
  min-width: 0;
}

.lab-seal {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--green);
  font-family: Bahnschrift, "Arial Narrow", sans-serif;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  background: var(--brass);
  border: 2px solid var(--paper);
  border-radius: 50%;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.22);
}

.title-lockup h1 {
  margin: 0;
  font-family: Bahnschrift, "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: clamp(1.1rem, 2.2vw, 1.48rem);
  font-stretch: condensed;
  line-height: 1.05;
  letter-spacing: 0.015em;
}

.title-lockup div > span {
  display: block;
  margin-top: 3px;
  color: #c8ddd6;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions {
  grid-column: 3;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 10px;
}

.sensor-status {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  color: #d8e8e3;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid rgba(216, 232, 227, 0.32);
}

.sensor-status::before {
  width: 7px;
  height: 7px;
  content: "";
  background: var(--brass);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(209, 169, 76, 0.22);
}

.sensor-status[data-state="active"]::before {
  background: #77d493;
}

.sensor-status[data-state="denied"]::before {
  background: var(--coral);
}

.settings-button,
.dialog-close {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background: transparent;
}

.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 11px;
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 800;
}

.settings-button:hover {
  color: var(--green);
  background: var(--paper);
}

.settings-glyph {
  display: grid;
  width: 20px;
  gap: 3px;
}

.settings-glyph i {
  position: relative;
  display: block;
  width: 100%;
  height: 2px;
  background: currentColor;
}

.settings-glyph i::after {
  position: absolute;
  top: -2px;
  width: 6px;
  height: 6px;
  content: "";
  background: currentColor;
  border: 1px solid var(--green);
  border-radius: 50%;
}

.settings-glyph i:nth-child(1)::after,
.settings-glyph i:nth-child(3)::after {
  left: 3px;
}

.settings-glyph i:nth-child(2)::after {
  right: 3px;
}

.lab-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.78fr) minmax(280px, 0.72fr);
  min-height: calc(100dvh - var(--topbar-height));
  gap: clamp(10px, 1.6vw, 22px);
  padding: clamp(14px, 2vw, 28px);
}

.bottle-bench,
.control-rail {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--shadow);
}

.bottle-bench {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 500px;
  overflow: hidden;
  border-top: 5px solid var(--green-2);
}

.bench-heading,
.rail-heading,
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.bench-heading > div,
.rail-heading > div {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.bench-heading h2,
.rail-heading h2,
.dialog-heading h2 {
  margin: 0;
  font-family: Bahnschrift, "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: 0.94rem;
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.status-lamp {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  background: var(--brass);
  border: 1px solid var(--brass-dark);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(209, 169, 76, 0.2);
}

.app-shell[data-phase="running"] .status-lamp {
  background: #39a85c;
  border-color: #216c39;
}

.app-shell[data-phase="paused"] .status-lamp {
  background: var(--coral);
  border-color: var(--coral-dark);
}

.instrument-code {
  overflow: hidden;
  color: var(--muted);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.bottle-workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(86px, 0.22fr) minmax(250px, 1fr) minmax(96px, 0.28fr);
  min-height: 0;
  align-items: center;
  gap: clamp(6px, 1.2vw, 18px);
  padding: clamp(12px, 1.6vw, 22px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 54%, rgba(11, 103, 90, 0.09), transparent 42%),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(21, 63, 57, 0.048) 27px 28px),
    #edf1eb;
}

.bottle-workspace::before {
  position: absolute;
  right: 4%;
  bottom: 4%;
  left: 4%;
  height: 22px;
  content: "";
  background: rgba(21, 63, 57, 0.1);
  border: 1px solid rgba(21, 63, 57, 0.14);
  border-radius: 50%;
  filter: blur(3px);
}

.gravity-instrument {
  position: relative;
  z-index: 3;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  align-self: stretch;
  padding: 12px 6px;
  border-right: 1px dashed var(--line);
}

.gravity-instrument > span {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.gravity-instrument strong {
  color: var(--green);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: clamp(0.65rem, 1.2vw, 0.78rem);
  letter-spacing: -0.03em;
}

.gravity-compass {
  position: relative;
  width: clamp(64px, 7vw, 90px);
  aspect-ratio: 1;
  border: 2px solid var(--green-2);
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--green) 0 2px, transparent 3px),
    repeating-radial-gradient(circle, transparent 0 10px, rgba(11, 103, 90, 0.13) 11px 12px),
    var(--paper);
  box-shadow: inset 0 0 0 5px var(--bench-deep), 3px 3px 0 var(--shadow);
}

.axis {
  position: absolute;
  top: 50%;
  left: 50%;
  background: rgba(21, 63, 57, 0.24);
  transform: translate(-50%, -50%);
}

.axis-x {
  width: 76%;
  height: 1px;
}

.axis-y {
  width: 1px;
  height: 76%;
}

.gravity-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  background: var(--coral);
  border: 2px solid var(--coral-dark);
  border-radius: 50%;
  box-shadow: 2px 2px 0 rgba(166, 62, 45, 0.22);
  transform: translate(-50%, -50%);
  transition: left 120ms linear, top 120ms linear;
}

.bottle-rig {
  position: relative;
  z-index: 2;
  justify-self: center;
  width: min(100%, 470px);
  height: 100%;
  min-height: 380px;
  max-height: 670px;
}

.bottle-rig.is-shaking {
  animation: vessel-shake 320ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.bottle-rig.is-adding .bottle-badge {
  animation: badge-stamp 360ms ease-out;
}

.bottle-rig.is-impacting #physics-canvas {
  animation: impact-flash 180ms ease-out;
}

#physics-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 380px;
  outline-offset: -5px;
}

@keyframes vessel-shake {
  0%,
  100% { transform: translateX(0) rotate(0); }
  18% { transform: translateX(-5px) rotate(-0.8deg); }
  42% { transform: translateX(5px) rotate(0.7deg); }
  66% { transform: translateX(-3px) rotate(-0.4deg); }
  84% { transform: translateX(2px) rotate(0.25deg); }
}

@keyframes badge-stamp {
  0% { transform: rotate(-4deg) scale(1); }
  42% { transform: rotate(-1deg) scale(1.12); }
  100% { transform: rotate(-4deg) scale(1); }
}

@keyframes impact-flash {
  0% { filter: brightness(1); }
  45% { filter: brightness(1.16) saturate(1.08); }
  100% { filter: brightness(1); }
}

.bottle-badge {
  position: absolute;
  z-index: 4;
  right: 14%;
  bottom: 13%;
  display: grid;
  width: 82px;
  min-height: 66px;
  place-items: center;
  padding: 5px;
  color: rgba(21, 63, 57, 0.72);
  text-align: center;
  pointer-events: none;
  border: 1px solid rgba(21, 63, 57, 0.42);
  transform: rotate(-4deg);
}

.bottle-badge span,
.bottle-badge small {
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.49rem;
  letter-spacing: 0.1em;
}

.bottle-badge strong {
  font-family: Bahnschrift, "Arial Narrow", sans-serif;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.measure-scale {
  position: absolute;
  z-index: 4;
  top: 24%;
  right: 11%;
  bottom: 23%;
  width: 18px;
  pointer-events: none;
  border-right: 1px solid rgba(21, 63, 57, 0.45);
}

.measure-scale i {
  position: absolute;
  right: 0;
  width: 9px;
  height: 1px;
  background: rgba(21, 63, 57, 0.45);
}

.measure-scale i:nth-child(1) { top: 0; }
.measure-scale i:nth-child(2) { top: 25%; }
.measure-scale i:nth-child(3) { top: 50%; }
.measure-scale i:nth-child(4) { top: 75%; }
.measure-scale i:nth-child(5) { bottom: 0; }

.measure-scale i:nth-child(3) {
  width: 14px;
}

.ready-panel {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: min(82%, 360px);
  padding: clamp(16px, 2.2vw, 26px);
  color: var(--ink);
  background: rgba(247, 248, 244, 0.96);
  border: 2px solid var(--green);
  box-shadow: 7px 7px 0 rgba(21, 63, 57, 0.22);
  transform: translate(-50%, -49%);
}

.ready-panel[hidden] {
  display: none;
}

.ready-index {
  display: block;
  margin-bottom: 8px;
  color: var(--green-2);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.61rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.ready-panel h2 {
  max-width: 12ch;
  margin: 0;
  font-family: Bahnschrift, "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: clamp(1.55rem, 3.6vw, 2.65rem);
  font-stretch: condensed;
  line-height: 0.98;
  letter-spacing: -0.025em;
}

.ready-panel > p:not(.ready-hint) {
  max-width: 35ch;
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: clamp(0.76rem, 1.35vw, 0.9rem);
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.action-button {
  border-radius: 0;
}

.primary-button {
  min-height: 48px;
  padding: 11px 16px;
  color: var(--white);
  font-weight: 850;
  letter-spacing: 0.015em;
  border: 2px solid var(--coral-dark);
  background: var(--coral);
  box-shadow: 4px 4px 0 rgba(166, 62, 45, 0.25);
}

.primary-button:hover:not(:disabled) {
  color: var(--white);
  background: var(--coral-dark);
  transform: translateY(-1px);
}

.primary-button:active:not(:disabled) {
  box-shadow: 1px 1px 0 rgba(166, 62, 45, 0.25);
  transform: translate(2px, 2px);
}

.ready-panel .primary-button {
  width: 100%;
}

.ready-hint {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.66rem;
  text-align: center;
}

kbd {
  display: inline-grid;
  min-width: 24px;
  min-height: 22px;
  place-items: center;
  padding: 2px 5px;
  color: var(--green);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 1;
  background: var(--white);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 3px;
}

.impact-label {
  position: absolute;
  z-index: 10;
  top: 18%;
  left: 50%;
  max-width: 85%;
  padding: 7px 12px;
  color: var(--white);
  font-family: Bahnschrift, "Arial Narrow", "Noto Sans TC", sans-serif;
  font-size: clamp(0.75rem, 1.5vw, 0.95rem);
  font-weight: 850;
  letter-spacing: 0.06em;
  text-align: center;
  pointer-events: none;
  background: var(--coral);
  border: 1px solid var(--coral-dark);
  box-shadow: 3px 3px 0 rgba(166, 62, 45, 0.24);
  transform: translateX(-50%) rotate(-1deg);
}

.impact-label[hidden] {
  display: none;
}

.stage-note {
  position: relative;
  z-index: 3;
  align-self: end;
  margin: 0 0 14px;
  padding-left: 12px;
  color: var(--muted);
  font-size: clamp(0.64rem, 1.1vw, 0.76rem);
  line-height: 1.55;
  border-left: 3px solid var(--brass);
}

.control-rail {
  display: flex;
  min-height: 0;
  flex-direction: column;
  align-self: stretch;
  overflow: hidden;
  border-top: 5px solid var(--coral);
}

.rail-heading {
  min-height: 56px;
}

.rail-heading > div {
  display: block;
}

.rail-heading > div > span,
.dialog-heading > div > span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.55rem;
  font-weight: 750;
  letter-spacing: 0.13em;
}

.rail-version {
  padding: 3px 6px;
  color: var(--green);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.62rem;
  font-weight: 800;
  border: 1px solid var(--line);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.metric {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding: clamp(10px, 1.4vw, 16px) 10px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric strong {
  overflow: hidden;
  color: var(--green);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: clamp(1rem, 2.3vw, 1.4rem);
  line-height: 1;
  text-overflow: ellipsis;
}

.action-bank {
  display: grid;
  gap: 9px;
  padding: clamp(12px, 1.7vw, 18px);
}

.action-button {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  min-height: 64px;
  padding: 8px 11px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--white);
  box-shadow: 3px 3px 0 rgba(23, 48, 44, 0.1);
}

.action-button:hover:not(:disabled) {
  border-color: var(--green-2);
  background: #eef6f1;
  transform: translateY(-1px);
}

.action-button:active:not(:disabled) {
  box-shadow: 1px 1px 0 rgba(23, 48, 44, 0.1);
  transform: translate(2px, 2px);
}

.action-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--white);
  font-size: 1.3rem;
  font-weight: 900;
  background: var(--green-2);
  border: 1px solid var(--green);
}

.shake-button .action-icon {
  color: var(--green);
  background: var(--brass);
  border-color: var(--brass-dark);
}

.action-button strong,
.action-button small {
  display: block;
}

.action-button strong {
  font-size: 0.84rem;
  line-height: 1.15;
}

.action-button small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.62rem;
}

.transport-bank {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  padding: 0 clamp(12px, 1.7vw, 18px) clamp(12px, 1.7vw, 18px);
}

.secondary-button {
  min-height: 44px;
  padding: 8px 11px;
  color: var(--green);
  font-size: 0.77rem;
  font-weight: 800;
  border: 1px solid var(--green-2);
  background: var(--paper);
}

.secondary-button:hover:not(:disabled) {
  color: var(--white);
  background: var(--green-2);
}

.control-guide {
  margin-top: auto;
  padding: clamp(12px, 1.6vw, 17px);
  border-top: 1px solid var(--line);
  background:
    repeating-linear-gradient(135deg, rgba(21, 63, 57, 0.035) 0 4px, transparent 4px 8px),
    #eef1ec;
}

.control-guide h3 {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.control-guide dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.control-guide dl > div {
  display: grid;
  grid-template-columns: minmax(86px, auto) 1fr;
  align-items: center;
  gap: 10px;
}

.control-guide dt {
  display: flex;
  gap: 3px;
}

.control-guide dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.3;
}

.settings-dialog {
  width: min(660px, calc(100% - 24px));
  max-height: min(820px, calc(100dvh - 24px));
  padding: 0;
  overflow: auto;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--green);
  border-radius: 0;
  box-shadow: 9px 9px 0 rgba(21, 63, 57, 0.26);
}

.settings-dialog::backdrop {
  background: rgba(12, 35, 32, 0.72);
}

.settings-dialog form {
  margin: 0;
}

.dialog-heading {
  color: var(--paper);
  background: var(--green);
  border-bottom: 5px solid var(--brass);
}

.dialog-heading > div > span {
  color: #c8ddd6;
}

.dialog-heading h2 {
  font-size: 1.2rem;
}

.dialog-close {
  flex: 0 0 auto;
  color: var(--paper);
  font-size: 1.55rem;
  line-height: 1;
}

.dialog-close:hover {
  color: var(--green);
  background: var(--paper);
}

.language-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.45fr) 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.language-row label,
.setting-field > span {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
}

select:hover,
input[type="number"]:hover {
  border-color: var(--green-2);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.setting-field {
  display: grid;
  gap: 6px;
}

.full-field {
  grid-column: 1 / -1;
}

.toggle-field {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #edf1ec;
}

.toggle-field span {
  min-width: 0;
}

.toggle-field strong,
.toggle-field small {
  display: block;
}

.toggle-field strong {
  font-size: 0.77rem;
}

.toggle-field small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.35;
}

.toggle-field input {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  accent-color: var(--green-2);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.dialog-actions .secondary-button {
  min-width: 44px;
}

#fa-help-btn.fa-help-btn,
#fa-help-btn.fa-help-button {
  right: 16px;
  bottom: 16px;
  z-index: 30;
}

@media (max-width: 1060px) {
  .lab-layout {
    grid-template-columns: minmax(0, 1.58fr) minmax(250px, 0.72fr);
  }

  .bottle-workspace {
    grid-template-columns: 76px minmax(230px, 1fr);
  }

  .stage-note {
    position: absolute;
    right: 16px;
    bottom: 8px;
    width: min(180px, 31%);
  }

  .sensor-status {
    display: none;
  }
}

@media (max-width: 800px) and (min-height: 561px) {
  :root {
    --topbar-height: 64px;
  }

  .topbar {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    padding: 7px 9px;
  }

  .back-link,
  .settings-button {
    width: 44px;
    padding: 6px;
    border-color: transparent;
  }

  .back-link {
    justify-content: center;
  }

  .back-link > span:last-child,
  .settings-button > span:last-child,
  .title-lockup div > span {
    display: none;
  }

  .title-lockup {
    gap: 8px;
    text-align: left;
  }

  .lab-seal {
    width: 36px;
    height: 36px;
    font-size: 0.75rem;
  }

  .title-lockup h1 {
    overflow: hidden;
    max-width: 210px;
    font-size: clamp(0.95rem, 4.3vw, 1.2rem);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lab-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: auto;
    gap: 12px;
    padding: 12px;
  }

  .bottle-bench {
    min-height: min(620px, calc(100dvh - var(--topbar-height) - 24px));
  }

  .bottle-workspace {
    grid-template-columns: 60px minmax(220px, 1fr);
    padding: 9px;
  }

  .gravity-instrument {
    gap: 7px;
    padding-inline: 2px;
  }

  .gravity-compass {
    width: 52px;
  }

  .gravity-instrument strong {
    font-size: 0.55rem;
    writing-mode: vertical-rl;
  }

  .bottle-rig {
    min-height: 430px;
  }

  #physics-canvas {
    min-height: 430px;
  }

  .ready-panel {
    width: min(84%, 330px);
    padding: 17px;
  }

  .ready-panel h2 {
    font-size: clamp(1.75rem, 9vw, 2.4rem);
  }

  .stage-note {
    right: 11px;
    bottom: 7px;
    width: 42%;
    margin: 0;
    font-size: 0.59rem;
  }

  .control-rail {
    overflow: visible;
  }

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

  .control-guide dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #fa-help-btn.fa-help-btn,
  #fa-help-btn.fa-help-button {
    top: calc(var(--topbar-height) + 8px);
    right: 8px;
    bottom: auto;
  }
}

@media (max-width: 430px) and (min-height: 561px) {
  .bench-heading {
    padding-inline: 10px;
  }

  .instrument-code {
    display: none;
  }

  .bottle-bench {
    min-height: calc(100dvh - var(--topbar-height) - 24px);
  }

  .bottle-workspace {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 3px;
    padding: 7px;
  }

  .gravity-instrument > span {
    font-size: 0.55rem;
  }

  .gravity-compass {
    width: 40px;
  }

  .gravity-dot {
    width: 10px;
    height: 10px;
  }

  .bottle-rig {
    width: 100%;
    min-height: 440px;
  }

  #physics-canvas {
    min-height: 440px;
  }

  .bottle-badge {
    right: 12%;
    bottom: 13%;
    width: 64px;
    min-height: 51px;
  }

  .measure-scale {
    right: 8%;
  }

  .ready-panel {
    width: min(91%, 310px);
    padding: 15px;
  }

  .ready-panel h2 {
    max-width: 10ch;
    font-size: clamp(1.75rem, 9.2vw, 2.25rem);
  }

  .ready-panel > p:not(.ready-hint) {
    margin: 10px 0 14px;
    font-size: 0.75rem;
  }

  .stage-note {
    display: none;
  }

  .action-bank,
  .control-guide dl {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .full-field {
    grid-column: auto;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialog-actions .secondary-button {
    order: 2;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  :root {
    --topbar-height: 54px;
  }

  body {
    overflow: hidden;
  }

  .topbar {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    min-height: var(--topbar-height);
    padding: 5px 8px;
    border-bottom-width: 3px;
  }

  .back-link,
  .settings-button {
    width: 44px;
    height: 42px;
    min-height: 42px;
    justify-content: center;
    padding: 5px;
    border-color: transparent;
  }

  .back-link > span:last-child,
  .settings-button > span:last-child,
  .title-lockup div > span,
  .sensor-status {
    display: none;
  }

  .lab-seal {
    width: 34px;
    height: 34px;
    font-size: 0.72rem;
  }

  .title-lockup h1 {
    overflow: hidden;
    max-width: 240px;
    font-size: 1rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lab-layout {
    grid-template-columns: minmax(0, 1.6fr) minmax(238px, 0.7fr);
    height: calc(100dvh - var(--topbar-height));
    min-height: 0;
    gap: 8px;
    padding: 8px;
  }

  .bottle-bench {
    min-height: 0;
  }

  .bench-heading,
  .rail-heading {
    min-height: 42px;
    padding: 6px 10px;
  }

  .bench-heading h2,
  .rail-heading h2 {
    font-size: 0.78rem;
  }

  .instrument-code {
    font-size: 0.5rem;
  }

  .bottle-workspace {
    grid-template-columns: 54px minmax(210px, 1fr);
    min-height: 0;
    gap: 3px;
    padding: 4px 8px;
  }

  .gravity-instrument {
    gap: 4px;
    padding-block: 4px;
  }

  .gravity-instrument > span {
    font-size: 0.5rem;
  }

  .gravity-compass {
    width: 42px;
  }

  .gravity-instrument strong {
    font-size: 0.5rem;
    writing-mode: vertical-rl;
  }

  .bottle-rig,
  #physics-canvas {
    min-height: 0;
  }

  .bottle-rig {
    height: 100%;
  }

  .bottle-badge {
    right: 13%;
    bottom: 10%;
    width: 57px;
    min-height: 45px;
  }

  .measure-scale {
    top: 22%;
    bottom: 18%;
  }

  .ready-panel {
    width: min(76%, 320px);
    padding: 12px 14px;
    transform: translate(-50%, -49%);
  }

  .ready-index {
    margin-bottom: 4px;
    font-size: 0.49rem;
  }

  .ready-panel h2 {
    max-width: none;
    font-size: clamp(1.25rem, 3.9vw, 1.8rem);
  }

  .ready-panel > p:not(.ready-hint) {
    margin: 7px 0 10px;
    font-size: 0.64rem;
    line-height: 1.35;
  }

  .ready-panel .primary-button {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 0.75rem;
  }

  .ready-hint,
  .stage-note {
    display: none;
  }

  .control-rail {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .metric {
    padding: 8px 5px;
  }

  .metric span {
    font-size: 0.5rem;
  }

  .metric strong {
    font-size: 0.9rem;
  }

  .action-bank {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .action-button {
    grid-template-columns: 30px 1fr;
    min-height: 48px;
    padding: 5px;
  }

  .action-icon {
    width: 26px;
    height: 26px;
    font-size: 0.96rem;
  }

  .action-button strong {
    font-size: 0.65rem;
  }

  .action-button small {
    display: none;
  }

  .transport-bank {
    gap: 6px;
    padding: 0 8px 8px;
  }

  .secondary-button {
    min-height: 44px;
    padding: 5px;
    font-size: 0.65rem;
  }

  .control-guide {
    display: none;
  }

  #fa-help-btn.fa-help-btn,
  #fa-help-btn.fa-help-button {
    top: calc(var(--topbar-height) + 5px);
    right: 5px;
    bottom: auto;
  }
}

@media (max-width: 700px) and (max-height: 560px) and (orientation: landscape) {
  .lab-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(220px, 0.9fr);
    padding: 6px;
    gap: 6px;
  }

  .instrument-code,
  .rail-heading > div > span,
  .rail-version {
    display: none;
  }

  .bottle-workspace {
    grid-template-columns: minmax(0, 1fr);
    padding: 3px;
  }

  .gravity-instrument {
    position: absolute;
    z-index: 6;
    top: 5px;
    left: 5px;
    width: 47px;
    height: auto;
    border: 0;
  }

  .gravity-instrument > span,
  .gravity-instrument strong {
    display: none;
  }

  .gravity-compass {
    width: 40px;
  }

  .bottle-rig {
    width: min(100%, 330px);
  }

  .ready-panel {
    width: min(78%, 250px);
    padding: 10px;
  }

  .ready-panel h2 {
    font-size: 1.15rem;
  }

  .ready-panel > p:not(.ready-hint) {
    max-height: 2.7em;
    overflow: hidden;
    margin: 5px 0 8px;
    font-size: 0.58rem;
  }

  .action-bank {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
