:root {
  color-scheme: light;
  --room: #d8dedb;
  --enamel: #eef1ee;
  --enamel-2: #dfe5e1;
  --navy: #172434;
  --navy-2: #20384a;
  --stage: #102d3b;
  --ink: #14202d;
  --muted: #52616b;
  --line: #9ba8a4;
  --focus: #2e817f;
  --focus-dark: #175b5c;
  --signal: #e7b642;
  --action: #df603d;
  --action-dark: #a83d2a;
  --danger: #bd4537;
  --success: #24715f;
  --white: #f7f8f4;
  --topbar-height: 62px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --z-topbar: 20;
  --z-dialog: 60;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

html {
  background: var(--room);
}

body {
  overflow: hidden;
  background: var(--room);
  color: var(--ink);
  font-family: "Aptos", "Noto Sans", "Microsoft JhengHei", "PingFang TC",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
select {
  min-width: 0;
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  border: 0;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px var(--navy) !important;
}

[hidden] {
  display: none !important;
}

.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 {
  display: grid;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: var(--z-topbar);
  display: grid;
  grid-template-columns: minmax(148px, 1fr) auto minmax(148px, 1fr);
  align-items: center;
  min-width: 0;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  background: var(--navy);
  color: var(--white);
  box-shadow: 0 3px 0 #0c1722;
}

.back-link,
.settings-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  color: var(--white);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.back-link {
  grid-column: 1;
  width: fit-content;
  text-decoration: none;
}

.back-link:hover,
.settings-button:hover {
  color: #ffffff;
}

.back-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid rgba(247, 248, 244, 0.55);
  border-radius: 50%;
  font-size: 1rem;
  transition: border-color 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.back-link:hover .back-mark {
  border-color: var(--signal);
  transform: translateX(-2px);
}

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

.lab-mark {
  display: grid;
  width: 35px;
  height: 35px;
  place-items: center;
  border-radius: 50%;
  background: var(--signal);
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 900;
}

.title-lockup > div {
  min-width: 0;
}

.title-lockup h1 {
  margin: 0;
  font-family: "Bahnschrift Condensed", "Arial Narrow", sans-serif;
  font-size: 1.18rem;
  font-stretch: condensed;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
}

.title-lockup div > span {
  display: block;
  margin-top: 3px;
  color: #b9c9cf;
  font-size: 0.66rem;
  line-height: 1;
}

.settings-button {
  grid-column: 3;
  justify-self: end;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.settings-glyph {
  display: grid;
  gap: 4px;
  width: 24px;
}

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

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

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

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

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

.lab-layout {
  display: grid;
  grid-template-columns: minmax(430px, 820px) minmax(350px, 430px);
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 3vw, 42px);
  min-width: 0;
  min-height: 0;
  padding: 22px max(22px, env(safe-area-inset-right)) 26px max(22px, env(safe-area-inset-left));
  overflow: auto;
}

.observation-bay {
  display: grid;
  width: min(100%, 820px);
  min-width: 0;
  justify-self: end;
}

.bay-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  min-height: 56px;
  padding: 0 8px 10px;
}

.bay-code,
.panel-index,
.dialog-heading span {
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.bay-heading h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  text-wrap: balance;
}

.status-lamp {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #76817d;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}

.app-shell[data-phase="playing"] .status-lamp {
  background: var(--signal);
  animation: statusPulse 1.1s ease-in-out infinite;
}

.app-shell[data-phase="resolved"] .status-lamp,
.app-shell[data-phase="final"] .status-lamp {
  background: var(--focus);
}

.question-counter {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex: 0 0 auto;
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
}

.question-counter strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.specimen-frame {
  position: relative;
  min-width: 0;
  padding: clamp(10px, 1.4vw, 16px);
  border: 3px solid var(--navy);
  border-radius: 14px;
  background: #cbd2cf;
  box-shadow: 0 7px 0 #909b97;
}

.frame-pin {
  position: absolute;
  z-index: 2;
  width: 8px;
  height: 8px;
  border: 2px solid #7b8783;
  border-radius: 50%;
  background: var(--enamel);
}

.pin-nw,
.pin-ne {
  top: 5px;
}

.pin-sw,
.pin-se {
  bottom: 5px;
}

.pin-nw,
.pin-sw {
  left: 5px;
}

.pin-ne,
.pin-se {
  right: 5px;
}

.specimen-stage {
  position: relative;
  isolation: isolate;
  container-type: inline-size;
  aspect-ratio: 8 / 5;
  overflow: hidden;
  border-radius: 8px;
  background: var(--stage);
  box-shadow: inset 0 0 0 2px #071b25;
}

.specimen-stage::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 52%, rgba(1, 13, 19, 0.42) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 32%);
}

.specimen-stage::after {
  content: "";
  position: absolute;
  z-index: 4;
  top: -12%;
  bottom: -12%;
  left: -2px;
  width: 2px;
  pointer-events: none;
  background: rgba(231, 182, 66, 0.62);
  opacity: 0;
  box-shadow: 0 0 7px rgba(231, 182, 66, 0.35);
}

.app-shell[data-phase="playing"] .specimen-stage::after {
  opacity: 1;
  animation: scanSpecimen 2.3s linear infinite;
}

#specimen-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  transition: filter 100ms linear, transform 240ms var(--ease-out);
}

.viewfinder {
  position: absolute;
  z-index: 3;
  inset: clamp(15px, 3vw, 28px);
  pointer-events: none;
}

.viewfinder > span {
  position: absolute;
  width: clamp(18px, 4vw, 38px);
  height: clamp(18px, 4vw, 38px);
  border-color: rgba(247, 248, 244, 0.56);
  border-style: solid;
}

.viewfinder > span:nth-child(1) {
  top: 0;
  left: 0;
  border-width: 2px 0 0 2px;
}

.viewfinder > span:nth-child(2) {
  top: 0;
  right: 0;
  border-width: 2px 2px 0 0;
}

.viewfinder > span:nth-child(3) {
  right: 0;
  bottom: 0;
  border-width: 0 2px 2px 0;
}

.viewfinder > span:nth-child(4) {
  bottom: 0;
  left: 0;
  border-width: 0 0 2px 2px;
}

.crosshair-x,
.crosshair-y {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  background: rgba(247, 248, 244, 0.24);
  transform: translate(-50%, -50%);
}

.crosshair-x {
  width: 30px;
  height: 1px;
}

.crosshair-y {
  width: 1px;
  height: 30px;
}

.timer-instrument,
.blur-instrument {
  position: absolute;
  z-index: 5;
  top: 14px;
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 7px;
  background: rgba(8, 26, 35, 0.9);
  color: var(--white);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.timer-instrument {
  left: 14px;
}

.blur-instrument {
  right: 14px;
}

.timer-instrument span,
.blur-instrument span {
  color: #b7c8cc;
  font-size: 0.58rem;
}

.timer-instrument strong,
.blur-instrument strong {
  color: var(--signal);
  font-size: 0.94rem;
  line-height: 1;
}

.result-message {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 18px;
  width: min(calc(100% - 36px), 520px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-size: clamp(0.82rem, 1.6vw, 1rem);
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 5px 0 rgba(2, 14, 21, 0.42);
}

.result-message.correct,
.result-message.is-correct {
  background: #d7ebe2;
  color: #164f43;
}

.result-message.wrong,
.result-message.is-wrong {
  background: #f2d8d2;
  color: #7f2e25;
}

.result-message.is-visible {
  animation: resultEnter 220ms var(--ease-out);
}

.focus-readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  padding: 13px 8px 0;
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
  font-weight: 700;
}

.focus-meter {
  position: relative;
  height: 9px;
  overflow: hidden;
  border-radius: 2px;
  background: #adb8b4;
}

.focus-fill {
  position: absolute;
  inset: 0;
  background: var(--focus);
  transform: scaleX(var(--focus-progress, 0));
  transform-origin: left center;
  transition: transform 100ms linear;
}

.focus-meter i {
  position: relative;
  z-index: 2;
  float: left;
  width: 20%;
  height: 100%;
  border-right: 2px solid var(--room);
}

.control-console {
  position: relative;
  width: min(100%, 430px);
  min-width: 0;
  max-height: 100%;
  justify-self: start;
  overflow: auto;
  border: 3px solid var(--navy);
  border-radius: 14px;
  background: var(--enamel);
  box-shadow: 7px 7px 0 rgba(23, 36, 52, 0.22);
}

.control-console::before {
  content: "RECOGNITION CONTROL";
  display: block;
  padding: 10px 16px 9px;
  border-bottom: 3px solid var(--navy);
  background: var(--navy-2);
  color: #d8e2e2;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.61rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

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

.stat-module {
  min-width: 0;
  padding: 13px 12px 11px;
}

.stat-module + .stat-module {
  border-left: 1px solid var(--line);
}

.stat-module span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 700;
}

.stat-module strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.1rem, 2.2vw, 1.45rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  text-overflow: ellipsis;
}

.stat-module:first-child strong {
  color: var(--action-dark);
}

.stat-module strong.is-updated {
  animation: counterKick 260ms var(--ease-out);
}

.phase-panel {
  padding: clamp(18px, 2.4vw, 26px);
}

.panel-copy {
  margin-bottom: 20px;
}

.panel-copy h2,
.final-panel h2 {
  margin: 7px 0 9px;
  color: var(--ink);
  font-size: clamp(1.3rem, 2.4vw, 1.72rem);
  font-weight: 850;
  letter-spacing: -0.025em;
  line-height: 1.12;
  text-wrap: balance;
}

.panel-copy p,
.final-text,
.settings-dialog p {
  max-width: 65ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.58;
  text-wrap: pretty;
}

.difficulty-field {
  min-width: 0;
  margin: 0 0 19px;
  padding: 0;
  border: 0;
}

.difficulty-field legend {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
}

.difficulty-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.difficulty-button {
  min-height: 62px;
  padding: 9px 6px 8px;
  border: 2px solid #aab5b1;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 180ms var(--ease-out), background 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.difficulty-button:hover {
  border-color: var(--focus);
  transform: translateY(-1px);
}

.difficulty-button.is-active,
.difficulty-button[aria-pressed="true"] {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--white);
}

.difficulty-button strong,
.difficulty-button span {
  display: block;
}

.difficulty-button strong {
  font-size: 0.86rem;
}

.difficulty-button span {
  margin-top: 4px;
  color: inherit;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.61rem;
  opacity: 0.72;
}

.primary-button,
.hint-button,
.answer-button {
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms var(--ease-out), background 160ms var(--ease-out), border-color 160ms var(--ease-out);
}

.primary-button {
  width: 100%;
  min-height: 46px;
  padding: 11px 16px;
  background: var(--action);
  color: #1d1d1a;
  box-shadow: 0 4px 0 var(--action-dark);
}

.primary-button:hover {
  background: #ef714d;
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--action-dark);
}

.primary-button:disabled,
.hint-button:disabled,
.answer-button:disabled {
  cursor: not-allowed;
}

.controls-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.45;
  text-align: center;
}

kbd {
  display: inline-grid;
  min-width: 22px;
  min-height: 22px;
  place-items: center;
  border: 1px solid #8f9b97;
  border-radius: 4px;
  background: #ffffff;
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  box-shadow: 0 2px 0 #aab3af;
}

.round-progress {
  margin-bottom: 15px;
}

.round-progress > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.7rem;
}

.round-progress strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 2px;
  background: #bdc6c2;
}

.progress-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--action);
  transform: scaleX(var(--round-progress, 0));
  transform-origin: left center;
  transition: transform 240ms var(--ease-out);
}

.hint-callout {
  margin-bottom: 11px;
  padding: 10px 12px;
  border: 2px solid #b99333;
  border-radius: 7px;
  background: #f4e8bd;
  color: #5b481c;
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.4;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.answer-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 9px 12px;
  border: 2px solid #aab5b1;
  background: #f9faf7;
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.22;
  text-align: left;
}

.answer-button:hover:not(:disabled) {
  border-color: var(--focus);
  background: #e2eeea;
  transform: translateY(-1px);
}

.answer-button .answer-key,
.answer-button .option-key {
  display: grid;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
}

.answer-button.correct,
.answer-button.is-correct {
  border-color: var(--success);
  background: #d7ebe2;
  color: #154e42;
}

.answer-button.wrong,
.answer-button.is-wrong {
  border-color: var(--danger);
  background: #f2d8d2;
  color: #782a22;
}

.answer-button:disabled:not(.correct):not(.wrong):not(.is-correct):not(.is-wrong) {
  opacity: 0.54;
}

.round-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
  margin-top: 13px;
}

.hint-button {
  min-height: 42px;
  padding: 9px 14px;
  border: 2px solid #b99333;
  background: transparent;
  color: #725a22;
}

.hint-button:hover:not(:disabled) {
  background: #f4e8bd;
}

.hint-button:disabled {
  opacity: 0.55;
}

.next-button {
  grid-row: 1;
}

.final-panel {
  text-align: center;
}

.final-score {
  margin: 14px 0 5px;
  color: var(--action-dark);
  font-family: "Bahnschrift Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(3.4rem, 8vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 0.9;
}

.final-text {
  margin: 0 auto 22px;
}

.settings-dialog {
  position: fixed;
  z-index: var(--z-dialog);
  width: min(calc(100vw - 32px), 390px);
  margin: auto;
  padding: 0;
  border: 3px solid var(--navy);
  border-radius: 12px;
  background: var(--enamel);
  color: var(--ink);
  box-shadow: 8px 8px 0 rgba(23, 36, 52, 0.32);
}

.settings-dialog::backdrop {
  background: rgba(13, 24, 33, 0.68);
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px 14px;
  border-bottom: 2px solid var(--line);
}

.dialog-heading h2 {
  margin: 4px 0 0;
  font-size: 1.35rem;
}

.dialog-close {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid var(--navy);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.3rem;
}

.settings-dialog > label {
  display: block;
  margin: 18px 20px 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.settings-dialog select {
  width: calc(100% - 40px);
  min-height: 46px;
  margin: 0 20px;
  padding: 9px 38px 9px 12px;
  border: 2px solid var(--navy);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font-size: 16px;
}

.settings-dialog > p {
  margin: 11px 20px 18px;
  font-size: 0.75rem;
}

.dialog-version {
  display: block;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.63rem;
  text-align: center;
}

.version-info {
  position: fixed;
  z-index: 10;
  right: 8px;
  bottom: 6px;
  color: rgba(20, 32, 45, 0.52);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.58rem;
  pointer-events: none;
}

.app-shell[data-feedback="correct"] .specimen-frame,
.app-shell.is-correct .specimen-frame {
  animation: focusConfirm 360ms var(--ease-out);
}

.app-shell[data-feedback="wrong"] .specimen-frame,
.app-shell.is-wrong .specimen-frame {
  animation: focusReject 300ms var(--ease-out);
}

@keyframes scanSpecimen {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100cqw + 2px));
  }
}

@keyframes statusPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(231, 182, 66, 0.38);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(231, 182, 66, 0);
  }
}

@keyframes resultEnter {
  0% {
    transform: translate(-50%, 10px);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes counterKick {
  0% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(-5px);
    color: var(--action);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes focusConfirm {
  0% {
    box-shadow: 0 7px 0 #909b97;
  }
  45% {
    box-shadow: 0 7px 0 #909b97, 0 0 0 7px rgba(36, 113, 95, 0.2);
  }
  100% {
    box-shadow: 0 7px 0 #909b97;
  }
}

@keyframes focusReject {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-5px);
  }
  65% {
    transform: translateX(4px);
  }
}

@media (max-width: 1040px) and (min-width: 801px) {
  .lab-layout {
    grid-template-columns: minmax(390px, 1fr) minmax(330px, 380px);
    gap: 22px;
  }

  .phase-panel {
    padding: 18px;
  }
}

@media (max-width: 800px) and (min-height: 561px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    padding: 0 9px;
  }

  .back-link {
    width: 40px;
    overflow: hidden;
  }

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

  .settings-button {
    width: 40px;
    justify-content: center;
  }

  .lab-mark {
    width: 31px;
    height: 31px;
  }

  .title-lockup h1 {
    font-size: 1rem;
  }

  .lab-layout {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 16px;
    padding: 14px 14px 28px;
    overflow: visible;
  }

  .observation-bay,
  .control-console {
    width: min(100%, 520px);
    justify-self: center;
  }

  .bay-heading {
    min-height: 47px;
    padding-bottom: 8px;
  }

  .specimen-frame {
    padding: 9px;
    box-shadow: 0 5px 0 #909b97;
  }

  .focus-readout {
    min-height: 29px;
    padding-top: 9px;
  }

  .control-console {
    overflow: visible;
    box-shadow: 5px 5px 0 rgba(23, 36, 52, 0.22);
  }

  .control-console::before {
    padding-block: 8px;
  }

  .stat-module {
    padding-block: 10px 9px;
  }

  .phase-panel {
    padding: 16px;
  }

  .panel-copy {
    margin-bottom: 14px;
  }

  .panel-copy p {
    font-size: 0.8rem;
    line-height: 1.45;
  }

  .difficulty-field {
    margin-bottom: 14px;
  }

  .difficulty-button {
    min-height: 55px;
  }

  #fa-help-btn.fa-help-btn {
    top: 11px;
    right: 52px;
    bottom: auto;
  }
}

@media (max-width: 420px) {
  .bay-code {
    display: none;
  }

  .bay-heading h2 {
    margin-top: 0;
  }

  .timer-instrument,
  .blur-instrument {
    top: 9px;
    min-height: 34px;
    padding: 6px 8px;
  }

  .timer-instrument {
    left: 9px;
  }

  .blur-instrument {
    right: 9px;
  }

  .viewfinder {
    inset: 15px;
  }

  .result-message {
    bottom: 11px;
    width: calc(100% - 22px);
    padding: 9px 10px;
  }

  .difficulty-group {
    gap: 5px;
  }

  .difficulty-button {
    padding-inline: 3px;
  }

  .answer-button {
    min-height: 48px;
    padding-inline: 9px;
    font-size: 0.78rem;
  }
}

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

  .topbar {
    padding-inline: 12px;
  }

  .back-link,
  .settings-button {
    min-height: 44px;
  }

  .lab-layout {
    grid-template-columns: minmax(330px, 1fr) minmax(310px, 360px);
    gap: clamp(14px, 2.6vw, 26px);
    padding: 8px 18px 10px;
    overflow: hidden;
  }

  .observation-bay {
    width: min(100%, calc((100dvh - var(--topbar-height) - 105px) * 1.6));
    max-height: 100%;
    justify-self: center;
  }

  .bay-heading {
    min-height: 40px;
    padding: 0 5px 6px;
  }

  .bay-code {
    display: none;
  }

  .bay-heading h2 {
    margin-top: 0;
    font-size: 0.82rem;
  }

  .question-counter {
    font-size: 0.6rem;
  }

  .question-counter strong {
    font-size: 0.86rem;
  }

  .specimen-frame {
    min-height: 0;
    padding: 8px;
    box-shadow: 0 4px 0 #909b97;
  }

  .specimen-stage {
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
  }

  .focus-readout {
    min-height: 27px;
    padding: 7px 5px 0;
  }

  .control-console {
    width: min(100%, 360px);
    box-shadow: 4px 4px 0 rgba(23, 36, 52, 0.22);
  }

  .control-console::before {
    padding: 7px 12px 6px;
    font-size: 0.55rem;
  }

  .stat-module {
    padding: 7px 9px 6px;
  }

  .stat-module span {
    margin-bottom: 2px;
    font-size: 0.58rem;
  }

  .stat-module strong {
    font-size: 1rem;
  }

  .phase-panel {
    padding: 11px 13px;
  }

  .panel-copy {
    margin-bottom: 9px;
  }

  .panel-index {
    display: none;
  }

  .panel-copy h2,
  .final-panel h2 {
    margin: 0 0 5px;
    font-size: 1.05rem;
  }

  .panel-copy p {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.68rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .difficulty-field {
    margin-bottom: 9px;
  }

  .difficulty-field legend {
    display: none;
  }

  .difficulty-button {
    min-height: 44px;
    padding: 6px 3px;
  }

  .difficulty-button strong {
    font-size: 0.73rem;
  }

  .difficulty-button span {
    margin-top: 2px;
    font-size: 0.53rem;
  }

  .primary-button {
    min-height: 44px;
    padding-block: 7px;
    font-size: 0.78rem;
    box-shadow: 0 3px 0 var(--action-dark);
  }

  .controls-hint {
    display: none;
  }

  .round-progress {
    margin-bottom: 8px;
  }

  .round-progress > div:first-child {
    margin-bottom: 5px;
  }

  .answer-grid {
    gap: 6px;
  }

  .answer-button {
    min-height: 44px;
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  .answer-button .answer-key,
  .answer-button .option-key {
    flex-basis: 21px;
    width: 21px;
    height: 21px;
  }

  .round-actions {
    margin-top: 7px;
  }

  .hint-button {
    min-height: 44px;
    padding-block: 5px;
    font-size: 0.7rem;
  }

  .final-score {
    margin-top: 8px;
    font-size: 3rem;
  }

  .final-text {
    margin-bottom: 11px;
    font-size: 0.72rem;
  }

  .timer-instrument,
  .blur-instrument {
    top: 9px;
    min-height: 32px;
    padding: 5px 7px;
  }

  .timer-instrument {
    left: 9px;
  }

  .blur-instrument {
    right: 9px;
  }

  .viewfinder {
    inset: 13px;
  }

  .result-message {
    bottom: 10px;
    padding: 8px 10px;
    font-size: 0.72rem;
  }

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

@media (max-width: 700px) and (max-height: 560px) and (orientation: landscape) {
  .lab-layout {
    grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
    gap: 8px;
    padding-inline: 8px;
  }

  .observation-bay,
  .control-console {
    width: 100%;
  }
}

@media (max-width: 620px) and (max-height: 460px) and (orientation: landscape) {
  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

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

  .back-link {
    width: 40px;
    overflow: hidden;
  }

  .settings-button {
    width: 40px;
    justify-content: center;
  }
}

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

  .specimen-stage::after {
    display: none;
  }
}
