:root {
  color-scheme: light;
  --ink: #263d3b;
  --ink-soft: #5f716d;
  --cream: #fff9e8;
  --paper: #fffdf7;
  --mint: #dff2e8;
  --mint-deep: #9bcdbd;
  --teal: #2c7068;
  --yellow: #f6c84b;
  --yellow-dark: #d69a23;
  --coral: #df6849;
  --coral-dark: #b84b36;
  --blue: #8fd7e2;
  --line: #c9d9d3;
  --shadow: rgba(50, 76, 71, .16);
  font-family: "Trebuchet MS", "Avenir Next", Avenir, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #e9f5ef;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 28%, rgba(255, 255, 255, .72) 0 2px, transparent 3px),
    radial-gradient(circle at 92% 68%, rgba(255, 255, 255, .62) 0 3px, transparent 4px),
    #e9f5ef;
  background-size: 48px 48px, 70px 70px, auto;
}

button,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 4px solid #268b82;
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.paper-noise {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .23;
  background-image: repeating-linear-gradient(102deg, transparent 0 9px, rgba(38, 61, 59, .025) 10px, transparent 11px 21px);
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: calc(11px + env(safe-area-inset-top, 0px)) max(24px, calc(24px + env(safe-area-inset-right, 0px))) 11px max(24px, calc(24px + env(safe-area-inset-left, 0px)));
  background: var(--cream);
  border-bottom: 2px solid #d8ded5;
  box-shadow: 0 4px 14px rgba(43, 78, 70, .08);
}

.back-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 10px;
  color: var(--teal);
  border-radius: 12px;
  font-weight: 900;
  text-decoration: none;
}

.back-link > span:first-child {
  font-size: 25px;
  line-height: 1;
}

.back-link:hover {
  background: #edf5e9;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 47px;
  height: 47px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--coral);
  border: 3px solid #fff;
  border-radius: 50% 44% 52% 46%;
  box-shadow: 0 0 0 2px var(--coral), 2px 4px 0 rgba(130, 55, 39, .15);
  font-size: 25px;
  font-weight: 900;
  transform: rotate(-7deg);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(20px, 2.2vw, 28px);
  letter-spacing: -.035em;
  line-height: 1;
}

.brand p {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.top-actions {
  justify-self: end;
  display: flex;
  gap: 8px;
}

.round-button {
  min-width: 44px;
  height: 44px;
  padding: 0 13px;
  color: var(--teal);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 3px 0 #b9ccc6;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.round-button:hover {
  background: #f2fbf7;
  border-color: var(--mint-deep);
}

.round-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b9ccc6;
}

.round-button[aria-pressed="false"] {
  color: #7b8986;
  background: #edf0ed;
  box-shadow: none;
}

main {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 18px max(20px, env(safe-area-inset-right, 0px)) max(28px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
}

.mode-switch {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
}

.mode-button {
  min-height: 43px;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, .68);
  border: 2px solid #cdded8;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.mode-button.active {
  color: #6e4810;
  background: #fff3b9;
  border-color: var(--yellow-dark);
  box-shadow: 0 3px 0 #d7ad3e;
}

.mode-button.locked {
  color: #75817e;
  border-style: dashed;
}

.unlock-hint {
  margin: 0 0 0 3px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
}

.stepper {
  max-width: 660px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 0 auto 15px;
  padding: 0;
  list-style: none;
}

.stepper li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #82908d;
  font-size: 11px;
}

.stepper li::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 15px;
  right: 50%;
  width: 100%;
  height: 3px;
  background: #c7d9d3;
}

.stepper li:first-child::before {
  display: none;
}

.stepper span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: #d7e5df;
  border: 2px solid #b7ccc5;
  border-radius: 50%;
  font-weight: 900;
}

.stepper b {
  font-weight: 900;
}

.stepper li.current,
.stepper li.done {
  color: var(--ink);
}

.stepper li.current span {
  color: #fff;
  background: var(--coral);
  border-color: var(--coral-dark);
  box-shadow: 0 3px 0 #a64c38;
  transform: rotate(-4deg) scale(1.08);
}

.stepper li.done span {
  color: #fff;
  background: var(--teal);
  border-color: #20544e;
}

.stepper li.done::before,
.stepper li.current::before {
  background: var(--teal);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(330px, .75fr);
  gap: 18px;
  align-items: start;
}

.experiment-card,
.control-card {
  background: var(--paper);
  border: 2px solid #cfddd8;
  box-shadow: 0 12px 30px var(--shadow);
}

.experiment-card {
  overflow: hidden;
  border-radius: 26px 26px 18px 18px;
}

.control-card {
  padding: 20px;
  border-radius: 22px 22px 18px 18px;
}

.scene-head {
  min-height: 75px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 20px 13px;
  background: var(--cream);
  border-bottom: 2px dashed #d6d6c8;
}

.scene-head h2,
.panel-heading h2,
.result-panel h2 {
  margin: 2px 0 0;
  font-size: clamp(20px, 2vw, 27px);
  letter-spacing: -.025em;
  line-height: 1.1;
}

.eyebrow {
  margin: 0;
  color: var(--coral-dark);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.score-badge {
  min-width: 88px;
  padding: 7px 12px;
  text-align: center;
  background: var(--yellow);
  border: 2px solid var(--yellow-dark);
  border-radius: 14px 17px 13px 16px;
  box-shadow: 2px 3px 0 #cf9d28;
  transform: rotate(2deg);
}

.score-badge span {
  display: block;
  color: #755016;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.score-badge strong {
  font-size: 20px;
}

.score-badge i {
  color: #ce8730;
  font-size: 15px;
  font-style: normal;
}

.bridge-scene {
  position: relative;
  min-height: 455px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,.3), transparent 42%),
    #cfece8;
}

#bridge-svg {
  width: min(94%, 760px);
  height: auto;
  overflow: visible;
}

#bridge-svg > rect {
  opacity: .48;
}

.table-line {
  fill: none;
  stroke: #83b7ad;
  stroke-width: 4;
}

.support > path:first-child {
  fill: #df6849;
  stroke: #9d3f31;
  stroke-width: 3;
}

.support-shine {
  fill: #f69070;
  opacity: .75;
}

#bridge-art .paper-main {
  fill: url(#paper-gradient);
  stroke: #53736d;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#bridge-art .accordion-paper {
  fill: none;
  stroke: #fffaf0;
  stroke-width: 17;
}

#bridge-art .accordion-fold {
  stroke: #806f57;
  stroke-width: 2;
  stroke-dasharray: 5 6;
}

#bridge-art .paper-fold {
  fill: none;
  stroke: #b9a98b;
  stroke-width: 2;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
  opacity: .85;
}

#bridge-art .paper-edge {
  fill: #eadcc1;
  stroke: #53736d;
  stroke-width: 3;
  stroke-linejoin: round;
}

#bridge-art .reinforcement {
  fill: none;
  stroke: var(--coral);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 10 6;
}

#bridge-art.building {
  animation: build-in .75s cubic-bezier(.22, .9, .25, 1.2) both;
  transform-origin: center;
}

#bridge-art.collapsed {
  animation: collapse .75s cubic-bezier(.4, 0, .8, .3) both;
  transform-origin: 220px 151px;
}

#coin-stack .coin-side,
#falling-coin path {
  fill: #bd7b25;
  stroke: #86531e;
  stroke-width: 2;
}

#coin-stack .coin-top,
#falling-coin ellipse {
  fill: url(#coin-gradient);
  stroke: #86531e;
  stroke-width: 2;
}

#coin-stack text,
#falling-coin text {
  fill: #805019;
  font-size: 9px;
  font-weight: 900;
  text-anchor: middle;
}

#coin-stack.collapsed {
  animation: coins-collapse .7s cubic-bezier(.4, 0, .8, .3) both;
  transform-origin: 220px 151px;
}

.falling-coin {
  display: none;
}

.falling-coin.drop {
  display: block;
  animation: coin-drop .34s ease-in both;
}

.sparkles {
  fill: none;
  stroke: #df6849;
  stroke-width: 4;
  stroke-linecap: round;
  opacity: .55;
}

.sparkles circle {
  fill: #f6c84b;
  stroke: none;
}

.cloud {
  position: absolute;
  width: 80px;
  height: 22px;
  background: rgba(255, 255, 255, .52);
  border-radius: 999px;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 0;
  background: inherit;
  border-radius: 50%;
}

.cloud::before {
  left: 12px;
  width: 34px;
  height: 34px;
}

.cloud::after {
  right: 10px;
  width: 25px;
  height: 25px;
}

.cloud-one {
  top: 60px;
  left: 7%;
}

.cloud-two {
  top: 105px;
  right: 5%;
  transform: scale(.72);
}

.coin-counter {
  position: absolute;
  top: 15px;
  left: 15px;
  min-width: 94px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255, 253, 247, .92);
  border: 2px solid #b7d1c9;
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(51, 82, 75, .1);
}

.coin-counter strong {
  font-size: 24px;
  line-height: 1;
}

.coin-counter > span:last-child {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 900;
}

.coin-small,
.coin-button-icon {
  display: grid;
  place-items: center;
  color: #8d5a1c;
  background: var(--yellow);
  border: 2px solid #aa6a1e;
  border-radius: 50%;
  box-shadow: inset -2px -2px 0 #d4982a;
  font-weight: 900;
}

.coin-small {
  width: 25px;
  height: 25px;
  font-size: 10px;
}

.scene-message {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 15px;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: auto;
  padding: 9px 15px;
  color: var(--ink);
  text-align: center;
  background: rgba(255, 253, 247, .94);
  border: 2px solid #b8d0c9;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(51, 82, 75, .1);
  font-size: 13px;
  font-weight: 900;
}

.test-controls {
  padding: 13px 20px 17px;
  text-align: center;
  background: var(--cream);
  border-top: 2px dashed #d6d6c8;
}

.coin-button {
  min-width: 245px;
  min-height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 22px;
  color: #fff;
  background: var(--coral);
  border: 3px solid var(--coral-dark);
  border-radius: 19px;
  box-shadow: 0 6px 0 #a84331, 0 9px 14px rgba(104, 44, 32, .18);
  cursor: pointer;
}

.coin-button:hover {
  background: #e97657;
}

.coin-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a84331;
}

.coin-button:disabled {
  opacity: .7;
}

.coin-button-icon {
  width: 39px;
  height: 39px;
  flex: none;
  color: #7a4d18;
  border-color: #9a601b;
}

.coin-button b,
.coin-button small {
  display: block;
  text-align: left;
}

.coin-button b {
  font-size: 18px;
}

.coin-button small {
  margin-top: 1px;
  font-size: 10px;
  font-weight: 800;
  opacity: .9;
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 15px;
}

.number-dot {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border: 3px solid #fff;
  border-radius: 47% 53% 45% 55%;
  box-shadow: 0 0 0 2px var(--teal);
  font-size: 18px;
  font-weight: 900;
  transform: rotate(-4deg);
}

fieldset {
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.shape-choice {
  min-height: 76px;
  padding: 7px 7px 8px;
  color: var(--ink-soft);
  background: #fff;
  border: 2px solid #cad9d4;
  border-radius: 13px;
  box-shadow: 0 3px 0 #d5dfdb;
  font-weight: 900;
  cursor: pointer;
}

.shape-choice svg {
  width: 80px;
  max-width: 100%;
  height: 36px;
  display: block;
  margin: 0 auto 1px;
  overflow: visible;
}

.shape-choice path {
  fill: none;
  stroke: currentColor;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shape-choice:hover,
.shape-choice.selected,
.distance-options button:hover,
.distance-options button.selected {
  color: var(--teal);
  background: #e9f8f1;
  border-color: var(--teal);
}

.shape-choice.selected,
.distance-options button.selected {
  box-shadow: 0 3px 0 var(--teal);
}

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

.distance-options button {
  min-height: 56px;
  padding: 6px 3px;
  color: var(--ink-soft);
  background: #fff;
  border: 2px solid #cad9d4;
  border-radius: 12px;
  cursor: pointer;
}

.distance-options span,
.distance-options b {
  display: block;
}

.distance-options span {
  height: 18px;
  color: var(--coral);
  letter-spacing: -1px;
  white-space: nowrap;
}

.distance-options b {
  margin-top: 2px;
  font-size: 11px;
}

.free-controls {
  margin: 14px 0;
  padding: 12px;
  background: #eaf6f2;
  border: 2px dashed var(--mint-deep);
  border-radius: 14px;
}

.fold-control > span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.fold-control output {
  color: var(--teal);
  font-weight: 900;
}

.fold-control input {
  width: 100%;
  height: 32px;
  margin: 4px 0 7px;
  accent-color: var(--coral);
}

.reinforce-control {
  min-height: 49px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: #fff;
  border: 2px solid #c5d9d2;
  border-radius: 11px;
  cursor: pointer;
}

.reinforce-control input {
  position: absolute;
  opacity: 0;
}

.check-box {
  width: 27px;
  height: 27px;
  flex: none;
  display: grid;
  place-items: center;
  color: transparent;
  background: #f3f5f3;
  border: 2px solid #9fb6ae;
  border-radius: 7px;
  font-weight: 900;
}

.reinforce-control input:checked + .check-box {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.reinforce-control input:focus-visible + .check-box {
  outline: 4px solid #268b82;
  outline-offset: 3px;
}

.reinforce-control b,
.reinforce-control small {
  display: block;
}

.reinforce-control b {
  font-size: 12px;
}

.reinforce-control small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 700;
}

.prediction {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 15px 0;
  padding: 10px;
  background: #fff4bf;
  border: 2px dashed #d7a92e;
  border-radius: 14px;
}

.prediction > div:first-child {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.prediction-icon {
  width: 31px;
  height: 31px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--coral);
  border-radius: 50%;
  font-weight: 900;
  transform: rotate(-7deg);
}

.prediction-copy b,
.prediction-copy small {
  display: block;
}

.prediction-copy b {
  font-size: 12px;
}

.prediction-copy small {
  margin-top: 2px;
  color: #796226;
  font-size: 9px;
  font-weight: 800;
}

.stepper-control {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper-control button {
  width: 35px;
  height: 35px;
  padding: 0;
  color: var(--teal);
  background: #fff;
  border: 2px solid #bd9b3c;
  border-radius: 10px;
  font-size: 21px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.stepper-control output {
  min-width: 34px;
  text-align: center;
  font-size: 23px;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  min-height: 55px;
  padding: 10px 18px;
  color: #fff;
  background: var(--teal);
  border: 3px solid #1d534d;
  border-radius: 15px;
  box-shadow: 0 5px 0 #173f3b;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button:hover {
  background: #378078;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #173f3b;
}

.result-panel {
  position: relative;
  padding-top: 8px;
}

.result-panel .eyebrow {
  margin-right: 70px;
}

.result-panel h2 {
  max-width: 300px;
  margin-top: 5px;
}

.result-sticker {
  position: absolute;
  top: -5px;
  right: 1px;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  color: #704717;
  background: var(--yellow);
  clip-path: polygon(50% 0%, 62% 13%, 80% 6%, 86% 24%, 100% 32%, 89% 50%, 100% 66%, 82% 74%, 78% 94%, 60% 87%, 46% 100%, 35% 85%, 15% 92%, 13% 71%, 0 61%, 12% 45%, 2% 27%, 23% 22%, 30% 3%);
  font-size: 13px;
  font-weight: 900;
  transform: rotate(8deg);
}

.result-copy {
  margin: 10px 0;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.comparison {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 9px;
  margin: 13px 0;
}

.comparison > div {
  padding: 9px;
  text-align: center;
  background: #f2f8f4;
  border: 2px solid #c9dad4;
  border-radius: 12px;
}

.comparison span,
.comparison strong {
  display: block;
}

.comparison div span {
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
}

.comparison strong {
  margin-top: 2px;
  font-size: 24px;
}

.comparison-arrow {
  color: var(--coral);
  font-size: 20px;
  font-weight: 900;
}

.discovery {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  padding: 10px;
  background: #fff2b4;
  border: 2px solid #e1bd4f;
  border-radius: 13px;
}

.discovery > span {
  font-size: 20px;
}

.discovery p {
  margin: 0;
  color: #65501a;
  font-size: 12px;
  line-height: 1.45;
}

.attempts {
  margin-top: 17px;
  padding-top: 14px;
  border-top: 2px dashed #cfddd8;
}

.attempts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.attempts h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.attempts-head > div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.attempts-head > div > span {
  padding: 3px 8px;
  color: var(--teal);
  background: #e4f3ed;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
}

.attempts-head button {
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--ink-soft);
  background: #fff;
  border: 2px solid #cad9d4;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.attempt-list {
  display: grid;
  gap: 6px;
}

.empty-attempts {
  margin: 0;
  padding: 10px;
  color: #7c8c88;
  text-align: center;
  background: #f3f6f3;
  border: 2px dashed #ccd9d4;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 700;
}

.attempt-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #f4f8f5;
  border: 2px solid #d1ddd8;
  border-radius: 10px;
}

.attempt-shape {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--mint);
  border-radius: 8px;
  font-size: 17px;
}

.attempt-row b,
.attempt-row small {
  display: block;
}

.attempt-row b {
  font-size: 11px;
}

.attempt-row small {
  margin-top: 1px;
  color: var(--ink-soft);
  font-size: 9px;
}

.attempt-score {
  color: var(--coral-dark);
  font-size: 15px;
  font-weight: 900;
}

.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  background: rgba(25, 48, 44, .72);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  background: var(--cream);
  border: 3px solid var(--teal);
  border-radius: 24px 27px 21px 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}

.modal-icon {
  display: block;
  margin-bottom: 5px;
  font-size: 35px;
}

.modal-card h2 {
  margin: 0 40px 10px 0;
  font-size: 26px;
}

.modal-card ol {
  margin: 0;
  padding-left: 23px;
}

.modal-card li,
.modal-card p {
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.modal-card .primary-button {
  margin-top: 7px;
}

.modal-close {
  position: absolute;
  top: 13px;
  right: 14px;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--teal);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 50%;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
}

.celebration {
  position: fixed;
  z-index: 90;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: -30px;
  width: 12px;
  height: 20px;
  background: var(--confetti-color);
  border-radius: 3px;
  animation: confetti-fall 1.55s ease-in forwards;
  transform: rotate(var(--confetti-turn));
}

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

@keyframes build-in {
  0% { opacity: 0; transform: translateY(-45px) rotate(-4deg); }
  72% { opacity: 1; transform: translateY(4px) rotate(1deg); }
  100% { opacity: 1; transform: translateY(0) rotate(0); }
}

@keyframes coin-drop {
  from { transform: translateY(-32px) rotate(-8deg); opacity: 0; }
  to { transform: translateY(78px) rotate(0); opacity: 1; }
}

@keyframes collapse {
  0% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(9px) rotate(-1deg); }
  100% { transform: translateY(74px) rotate(7deg); opacity: .72; }
}

@keyframes coins-collapse {
  0% { transform: translateY(0) rotate(0); }
  42% { transform: translateY(15px) rotate(2deg); }
  100% { transform: translate(34px, 79px) rotate(16deg); opacity: .78; }
}

@keyframes confetti-fall {
  0% { transform: translateY(-8vh) rotate(0); }
  100% { transform: translateY(108vh) rotate(var(--confetti-turn)); opacity: .3; }
}

@media (max-width: 1000px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
  }

  .brand {
    justify-self: center;
  }

  .workspace {
    grid-template-columns: minmax(0, 1.15fr) minmax(310px, .85fr);
    gap: 12px;
  }

  .bridge-scene {
    min-height: 410px;
  }

  .control-card {
    padding: 16px;
  }
}

/* Portrait tablets stack the workshop while keeping the bridge visible above
   the controls. Landscape tablets retain the side-by-side laboratory layout. */
@media (max-width: 820px), (max-width: 1100px) and (orientation: portrait) {
  .topbar {
    min-height: 67px;
    gap: 9px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
  }

  .back-label,
  .brand p,
  .action-label {
    display: none;
  }

  .back-link {
    width: 44px;
    justify-content: center;
    padding: 0;
  }

  .brand-mark {
    width: 39px;
    height: 39px;
    font-size: 20px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .round-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
  }

  main {
    padding-top: 12px;
  }

  .mode-switch {
    flex-wrap: wrap;
    margin-bottom: 11px;
  }

  .unlock-hint {
    width: 100%;
    text-align: center;
  }

  .stepper {
    margin-bottom: 11px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .bridge-scene {
    min-height: min(45vh, 420px);
  }

  #bridge-svg {
    width: min(85%, 650px);
  }

  .control-card {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(220px, .65fr);
    gap: 16px;
  }

  .attempts {
    margin: 0;
    padding: 0 0 0 16px;
    border-top: 0;
    border-left: 2px dashed #cfddd8;
  }

  .result-panel + .attempts {
    min-height: 170px;
  }
}

@media (max-width: 620px) {
  .topbar {
    position: relative;
  }

  .brand {
    gap: 7px;
  }

  .brand-mark {
    display: none;
  }

  .top-actions {
    gap: 5px;
  }

  .top-actions .round-button:first-child {
    display: none;
  }

  main {
    padding-right: 10px;
    padding-left: 10px;
  }

  .mode-button {
    min-height: 42px;
    padding: 7px 10px;
    font-size: 11px;
  }

  .stepper b {
    font-size: 9px;
  }

  .scene-head {
    min-height: 67px;
    padding: 11px 13px;
  }

  .scene-head h2 {
    font-size: 19px;
  }

  .score-badge {
    min-width: 75px;
    padding: 6px 8px;
  }

  .bridge-scene {
    min-height: 310px;
  }

  #bridge-svg {
    width: 110%;
    max-width: none;
  }

  .cloud {
    display: none;
  }

  .coin-counter {
    top: 9px;
    left: 9px;
  }

  .scene-message {
    bottom: 9px;
    font-size: 11px;
  }

  .test-controls {
    padding: 11px;
  }

  .coin-button {
    width: 100%;
    min-width: 0;
  }

  .control-card {
    display: block;
    padding: 15px;
  }

  .attempts {
    margin-top: 16px;
    padding: 13px 0 0;
    border-top: 2px dashed #cfddd8;
    border-left: 0;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .topbar {
    min-height: 58px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    padding-bottom: 6px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 19px;
  }

  .brand p,
  .unlock-hint {
    display: none;
  }

  main {
    padding-top: 9px;
  }

  .mode-switch,
  .stepper {
    margin-bottom: 8px;
  }

  .bridge-scene {
    min-height: 330px;
  }
}

@media (pointer: coarse) {
  .shape-choice,
  .distance-options button,
  .mode-button,
  .stepper-control button {
    min-height: 48px;
  }
}

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