@font-face {
  font-family: "Fredoka";
  src: url("assets/fredoka-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Fredoka";
  src: url("assets/fredoka-600.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  --navy: #164a7a;
  --navy-dark: #0d355a;
  --sky: #bdecf7;
  --ice: #e6f9ff;
  --porcelain: #fffdf5;
  --ivory: #fff2d9;
  --ivory-deep: #ecd39e;
  --coral: #e95147;
  --coral-deep: #a92f35;
  --pearl: #fff1cc;
  --pearl-deep: #b8cdd2;
  --wood: #a76a3d;
  --green: #34a62a;
  --green-deep: #23741d;
  --control-height: 64px;
  --marker-row-height: 32px;
  --marker-gap: 1px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--sky);
  color: var(--navy);
  font-family: "Fredoka", sans-serif;
  font-size: clamp(15px, 1.45vmin, 18px);
  -webkit-font-smoothing: antialiased;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 7px var(--navy);
}

button:disabled {
  cursor: default;
}

img,
video {
  display: block;
  max-width: 100%;
}

.visually-hidden,
.guide-copy,
.reaction-name,
.level-done,
.board-heading,
.board-title,
.choice-note,
.mambo-copy,
#feedback,
#demoBannerText,
.intro-caption,
.play-button > span,
.demo-skip span,
.ok-button span,
.next-button span,
.modal-primary > span,
.finale-home > span,
.icon-control span,
.comparison-copy {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

[hidden] {
  display: none !important;
}

.world-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.world-background::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgb(51 171 220 / 0.05), transparent 48%, rgb(12 58 86 / 0.08));
}

.world-background img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.06) contrast(1.015);
}

.world-portrait {
  display: none;
}

.corner-rune {
  position: fixed;
  z-index: 400;
  left: max(5px, env(safe-area-inset-left));
  bottom: max(7px, env(safe-area-inset-bottom));
  width: clamp(30px, 3.2vw, 42px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgb(12 44 67 / 0.22));
}

#app {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100svh;
}

.screen {
  width: 100%;
  height: 100svh;
}

.intro-screen {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(20px, 1fr) auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  isolation: isolate;
}

.intro-art {
  position: absolute;
  inset: 0;
  z-index: -2;
  overflow: hidden;
}

.intro-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.intro-title-frame {
  justify-self: center;
  max-width: min(90vw, 850px);
  padding: clamp(9px, 1.6vh, 15px) clamp(22px, 4vw, 46px);
  text-align: center;
}

h1 {
  margin: 0;
  color: var(--navy-dark);
  font-size: clamp(2rem, 5.2vmin, 4rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-shadow: 0 1px 2px rgb(255 255 255 / 0.95), 0 0 8px rgb(255 255 255 / 0.7);
  text-wrap: balance;
}

.intro-bottom {
  grid-row: 3;
  align-self: end;
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 0;
}

.intro-caption {
  margin: 0;
  padding: 7px 19px;
  color: var(--navy-dark);
  font-size: clamp(0.95rem, 1.9vmin, 1.15rem);
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 2px rgb(255 255 255 / 0.95), 0 0 8px rgb(255 255 255 / 0.7);
}

.play-button {
  min-width: clamp(188px, 22vw, 260px);
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  padding: 5px 24px 5px 7px;
  border: 2px solid #bfe5eb;
  border-radius: 999px;
  background: linear-gradient(180deg, #fffefa, #ffefce);
  box-shadow:
    0 8px 18px rgb(9 51 79 / 0.22),
    inset 0 2px 0 #fff,
    inset 0 -5px 10px rgb(180 140 76 / 0.11);
  font-size: clamp(1.2rem, 2.4vmin, 1.55rem);
  font-weight: 600;
  cursor: pointer;
}

.play-button img {
  width: 56px;
  height: 56px;
}

.game-screen {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1vh, 10px);
  padding:
    max(8px, env(safe-area-inset-top))
    max(16px, calc((100vw - 1120px) / 2))
    max(7px, env(safe-area-inset-bottom))
    max(16px, calc((100vw - 1120px) / 2));
}

.game-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.level-progress {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: clamp(9px, 1.8vw, 18px);
}

.level-tokens {
  display: flex;
  gap: clamp(4px, 0.6vw, 7px);
}

.level-token {
  min-width: clamp(31px, 3.3vw, 42px);
  min-height: 31px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 3px 7px;
  border: 1px solid rgb(255 255 255 / 0.78);
  border-radius: 999px;
  background: rgb(255 253 246 / 0.86);
  box-shadow: 0 3px 8px rgb(10 51 79 / 0.13);
  font-weight: 600;
}

.level-token.current-level {
  border-color: #7ab8d7;
  background: var(--navy);
  box-shadow:
    0 3px 8px rgb(10 51 79 / 0.2),
    inset 0 1px 0 rgb(255 255 255 / 0.3);
  color: #fff;
}

.level-token.completed-level {
  border-color: #6db667;
  background: #f7fff1;
}

.level-token.locked-level {
  color: rgb(22 74 122 / 0.56);
}

.level-done {
  font-size: 0.75rem;
}

.task-stars {
  display: flex;
  align-items: center;
  gap: 1px;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 2px rgb(10 51 79 / 0.15));
}

.task-stars img {
  width: clamp(26px, 3.3vw, 38px);
  height: clamp(26px, 3.3vw, 38px);
  object-fit: contain;
}

.empty-star {
  opacity: 0.55;
}

.level-label {
  margin: 0;
  padding: 5px 13px;
  border-radius: 999px;
  background: rgb(255 253 246 / 0.82);
  box-shadow: 0 3px 8px rgb(10 51 79 / 0.12);
  color: var(--navy-dark);
  font-size: clamp(0.76rem, 1.35vmin, 0.92rem);
  font-weight: 600;
  white-space: nowrap;
}

.game-body {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(180px, 18vw, 240px);
  align-items: end;
  gap: clamp(18px, 2.8vw, 34px);
}

.message-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 0.85vh, 8px);
}

.guide-line {
  position: relative;
  width: auto;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.guide-line::after {
  content: none;
}

.sopo-media {
  width: clamp(96px, 9vw, 118px);
  height: clamp(84px, 8vw, 104px);
  flex: 0 0 auto;
}

.sopo-media video,
.sopo-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sopo-still {
  display: none;
}

.guide-name,
.reaction-name {
  margin: 0;
  color: #397397;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.instruction-text {
  margin: 1px 0 0;
  color: var(--navy-dark);
  font-size: clamp(0.91rem, 1.5vmin, 1.08rem);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}

.demo-banner {
  width: auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.demo-skip {
  min-width: 64px;
  min-height: 64px;
  display: grid;
  place-items: center;
  padding: 2px;
  border: 1px solid rgb(255 255 255 / 0.9);
  border-radius: 22px;
  background: rgb(255 255 255 / 0.82);
  box-shadow: 0 3px 8px rgb(10 51 79 / 0.1);
  cursor: pointer;
}

.demo-skip img,
.next-button img,
.modal-primary img,
.finale-home img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.board-area {
  position: relative;
  width: min(100%, 720px);
  height: clamp(230px, 27vh, 300px);
  flex: 0 0 auto;
  margin-top: 2px;
}

.bead-board {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(30px, 4.6vh, 46px) 7% clamp(28px, 4vh, 44px);
  border: 0;
  border-radius: 32px;
  background: url("assets/ice-tray.webp") center / 100% 100% no-repeat;
  box-shadow:
    0 14px 25px rgb(9 53 80 / 0.19),
    0 4px 0 rgb(85 146 170 / 0.12);
  isolation: isolate;
  transition: box-shadow 180ms ease;
}

.board-heading {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.board-total,
.bead-total {
  margin: 0;
  color: #3b718d;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.board-total {
  padding: 2px 9px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.68);
  color: var(--navy);
}

.board-rows {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: clamp(4px, 1vh, 10px);
  padding: 4px 1%;
}

.bead-row {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 0.9vw, 11px);
}

.bead-row::before {
  content: "";
  position: absolute;
  left: 2.5%;
  right: 2.5%;
  top: calc((100% - var(--marker-row-height) - var(--marker-gap)) / 2);
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, #a86f3c 0 36%, #d09a5e 42% 64%, #81512e 70%);
  box-shadow: 0 1px 2px rgb(69 40 18 / 0.26);
  transform: translateY(-50%);
}

.bead-group {
  --bead-gap: clamp(4px, 0.75vw, 9px);
  --bead-size: clamp(36px, 4.3vmin, 47px);
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, var(--bead-size));
  gap: var(--bead-gap);
  align-items: center;
}

.bead {
  position: relative;
  width: var(--bead-size);
  height: var(--bead-size);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
}

.material-1 .bead {
  background: radial-gradient(circle at 33% 27%, #ffd8cc 0 5%, #ff9789 11%, #e95147 44%, #ba3738 76%, #8d2932 100%);
  box-shadow:
    inset -5px -7px 10px rgb(91 20 30 / 0.22),
    inset 4px 4px 8px rgb(255 255 255 / 0.2),
    0 5px 7px rgb(86 45 35 / 0.25);
}

.material-2 .bead {
  background: radial-gradient(circle at 32% 26%, #fff 0 8%, #fff9e5 18%, #f5e7bd 54%, #cfb98d 83%, #a6a8a3 100%);
  box-shadow:
    inset -5px -7px 10px rgb(84 106 111 / 0.18),
    inset 4px 4px 8px rgb(255 255 255 / 0.52),
    0 5px 7px rgb(86 67 42 / 0.2);
}

.bead-shine {
  position: absolute;
  left: 22%;
  top: 16%;
  width: 28%;
  height: 22%;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.68);
  filter: blur(0.4px);
  transform: rotate(-22deg);
}

.five-marker,
.ten-marker {
  position: relative;
  z-index: 2;
  align-self: center;
  margin-bottom: 0;
  transform: translateY(23px);
  color: #44758d;
  font-size: clamp(18px, 1.45vw, 22px);
  font-weight: 600;
  text-align: center;
}

.five-marker {
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.72);
}

.ten-marker {
  min-width: 24px;
}

.bead-board.retry-nudge {
  animation: calm-nudge 320ms ease-out;
}

.demo-hand {
  position: fixed;
  z-index: 220;
  width: clamp(52px, 6.6vmin, 76px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 4px 3px rgb(10 51 79 / 0.26));
  transition: left 180ms ease, top 180ms ease;
}

.feedback {
  width: min(100%, 720px);
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1px 8px;
  color: var(--navy-dark);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 1px 0 rgb(255 255 255 / 0.72);
}

.feedback:empty {
  visibility: hidden;
}

.feedback-try-again {
  color: var(--navy);
}

.feedback-success {
  color: var(--green-deep);
}

.demo-feedback {
  color: #3f6f88;
}

.comparison-helper {
  width: min(100%, 720px);
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 16px);
  padding: 6px 12px;
  border: 1px solid rgb(255 255 255 / 0.78);
  border-radius: 15px;
  background: rgb(255 253 246 / 0.84);
  box-shadow: 0 4px 11px rgb(9 53 80 / 0.1);
}

.mini-count {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(6px, 1.1vw, 12px);
}

.mini-group {
  display: flex;
  gap: 8px;
}

.mini-ten {
  padding-left: 8px;
  border-left: 1px solid rgb(59 113 141 / 0.28);
}

.mini-five {
  display: grid;
  grid-template-columns: repeat(5, 12px);
  gap: 3px;
}

.mini-counter {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9d91, var(--coral) 60%, var(--coral-deep));
  box-shadow: 0 1px 2px rgb(86 37 31 / 0.18);
}

.comparison-value {
  min-width: 42px;
  color: var(--navy-dark);
  font-size: clamp(34px, 3.3vw, 44px);
  line-height: 1;
  text-align: center;
}

.comparison-copy {
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 8px;
  align-items: center;
}

.comparison-copy strong {
  font-size: 0.8rem;
}

.comparison-copy p {
  margin: 0;
  font-size: 0.75rem;
}

.comparison-marker {
  grid-column: 1 / -1;
  justify-self: start;
  color: #3a7594;
  font-size: 0.75rem;
  font-weight: 600;
}

.answer-area {
  width: min(100%, 720px);
  min-height: 88px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px auto;
  align-items: center;
  gap: clamp(7px, 1vw, 12px);
}

.answer-group {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(7px, 1.2vw, 13px);
}

.numeral-tile {
  min-width: 0;
  min-height: 88px;
  padding: 5px 8px 3px;
  border: 2px solid #c8e5ea;
  border-radius: 24px;
  background: linear-gradient(155deg, #fff 0%, #fffdf5 55%, #f5e8cd 100%);
  box-shadow:
    0 7px 12px rgb(9 53 80 / 0.16),
    inset 0 2px 0 #fff,
    inset 0 -6px 10px rgb(169 133 72 / 0.07);
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.numeral-tile:hover:not(:disabled) {
  border-color: #6cb1d2;
  transform: translateY(-1px);
}

.numeral-tile.selected-choice {
  border-color: #4aa4e3;
  background: linear-gradient(155deg, #fff 0%, #fff9e8 62%, #efe1bb 100%);
  box-shadow:
    0 0 0 4px rgb(92 177 236 / 0.42),
    0 8px 15px rgb(9 53 80 / 0.18),
    inset 0 2px 0 #fff;
}

.numeral-tile.correct-choice {
  border-color: #6fc45e;
  background: linear-gradient(155deg, #fff 0%, #fbfff2 62%, #e1efcc 100%);
  box-shadow:
    0 0 0 4px rgb(94 190 82 / 0.28),
    0 8px 15px rgb(9 53 80 / 0.16),
    inset 0 2px 0 #fff;
}

.numeral-value {
  display: block;
  color: var(--navy-dark);
  font-size: 64px;
  font-weight: 600;
  line-height: 0.9;
}

.choice-note {
  display: block;
  margin-top: 2px;
  color: #3d7894;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.ok-button {
  min-width: 68px;
  min-height: 68px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.ok-button img {
  width: clamp(66px, 7.5vh, 76px);
  height: clamp(66px, 7.5vh, 76px);
  object-fit: contain;
  filter: drop-shadow(0 5px 5px rgb(10 74 28 / 0.2));
}

.ok-button:disabled {
  opacity: 0.58;
}

.ok-button.demo-success {
  opacity: 1;
}

.ok-button span {
  margin-top: -6px;
  color: var(--navy-dark);
  font-size: 0.75rem;
  font-weight: 600;
}

.next-button {
  min-width: 64px;
  min-height: 68px;
  display: grid;
  place-items: center;
  padding: 2px;
  border: 2px solid #8acb7e;
  border-radius: 22px;
  background: linear-gradient(#fbfff7, #e1f2d8);
  box-shadow:
    0 6px 12px rgb(9 53 80 / 0.15),
    inset 0 2px 0 #fff;
  color: #21651b;
  cursor: pointer;
}

.mambo-reaction {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  align-self: end;
  gap: 1px;
  padding: 0;
  text-align: center;
}

.mambo-media {
  position: relative;
  width: min(100%, 240px);
  aspect-ratio: 1;
}

.mambo-idle,
.mambo-still {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 7px rgb(11 47 72 / 0.22));
}

.mambo-idle {
  display: none;
}

.mambo-reaction.idle-animated .mambo-idle {
  display: block;
}

.mambo-reaction.idle-animated .mambo-still,
.mambo-reaction.idle-framed .mambo-still {
  display: none;
}

.mambo-reaction.idle-framed .mambo-idle {
  display: block;
  object-fit: cover;
}

.mambo-copy {
  position: relative;
  z-index: 2;
  max-width: 230px;
  margin-top: -9px;
  padding: 7px 12px 8px;
  border: 1px solid rgb(255 255 255 / 0.82);
  border-radius: 17px;
  background: rgb(255 253 246 / 0.92);
  box-shadow: 0 6px 14px rgb(9 53 80 / 0.13);
}

.mambo-copy::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -7px;
  width: 13px;
  height: 13px;
  border-top: 1px solid rgb(255 255 255 / 0.9);
  border-left: 1px solid rgb(255 255 255 / 0.9);
  background: rgb(255 253 246 / 0.94);
  transform: translateX(-50%) rotate(45deg);
}

.mambo-copy p:last-child {
  margin: 2px 0 0;
  color: var(--navy-dark);
  font-size: 0.75rem;
  line-height: 1.1;
}

.mambo-reaction.success-pop .mambo-media {
  animation: gentle-pop 480ms ease-out;
}

.game-controls {
  min-height: var(--control-height);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vw, 13px);
  padding-left: 42px;
  padding-right: 4px;
}

.icon-control {
  width: 58px;
  min-width: 56px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 0.7);
  border-radius: 50%;
  background: rgb(255 253 246 / 0.61);
  box-shadow:
    0 4px 10px rgb(9 53 80 / 0.13),
    inset 0 1px 0 rgb(255 255 255 / 0.8);
  color: var(--navy-dark);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.icon-control img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgb(75 42 22 / 0.18));
}

.icon-control:disabled {
  opacity: 0.5;
}

.invalid-state .game-body,
.invalid-state .game-controls,
.invalid-state .game-header {
  visibility: hidden;
}

.invalid-state {
  position: relative;
  display: grid;
  place-items: center;
}

.invalid-state .error-state {
  display: block !important;
  z-index: 5;
  width: min(620px, 90vw);
  padding: 28px;
  border: 1px solid #fff;
  border-radius: 28px;
  background: var(--porcelain);
  box-shadow: 0 12px 28px rgb(9 53 80 / 0.22);
  text-align: center;
}

.error-state h2 {
  margin: 0 0 8px;
}

.error-state p {
  margin: 0;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(70px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background: rgb(10 56 88 / 0.5);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  width: min(760px, 94vw);
  max-height: calc(100svh - 92px);
  overflow: auto;
  padding: clamp(17px, 3vmin, 28px);
  border: 2px solid rgb(255 255 255 / 0.9);
  border-radius: 30px;
  background:
    radial-gradient(circle at 12% 4%, #fff, transparent 30%),
    linear-gradient(145deg, #fffdf7, #f8efdc);
  box-shadow:
    0 18px 40px rgb(8 45 71 / 0.3),
    inset 0 -8px 18px rgb(168 129 65 / 0.08);
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-heading h2 {
  margin: 0;
  color: var(--navy-dark);
  font-size: clamp(1.35rem, 3.1vmin, 2rem);
}

.modal-close,
.modal-primary,
.level-choice,
.help-audio-button,
.demo-from-help {
  min-height: 48px;
  padding: 8px 16px;
  border: 1px solid #c5e4e9;
  border-radius: 16px;
  background: #fffef8;
  box-shadow:
    0 4px 9px rgb(9 53 80 / 0.11),
    inset 0 1px 0 #fff;
  font-weight: 600;
  cursor: pointer;
}

.modal-primary {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-color: #81c971;
  background: linear-gradient(#fbfff8, #dff1d8);
  color: #21651b;
}

.modal-subtitle {
  margin: 20px 0 10px;
}

.level-menu {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.level-choice.current-level-choice {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

.level-choice:disabled {
  box-shadow: none;
  opacity: 0.56;
}

.parent-note,
.audio-unavailable {
  margin: 0 0 14px;
  font-size: 1rem;
  line-height: 1.4;
}

.help-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
}

.help-step {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(76px, auto) auto;
  justify-items: center;
  gap: 8px;
  padding: 11px;
  border-radius: 20px;
  background: rgb(230 248 251 / 0.66);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.7);
  text-align: center;
}

.step-number {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-weight: 600;
}

.step-picture {
  display: grid;
  place-items: center;
  min-height: 76px;
}

.help-step p {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.help-mini-board {
  display: flex;
  gap: 5px;
  padding: 9px 12px;
  border: 4px solid transparent;
  border-radius: 15px;
  background:
    linear-gradient(#fff9ea, #fff4dc) padding-box,
    linear-gradient(145deg, #fff, #9fd7e7) border-box;
}

.help-bead {
  width: clamp(12px, 2.2vmin, 18px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffd1c7, #ec554b 48%, #a62e35);
  box-shadow: 0 2px 3px rgb(67 33 26 / 0.2);
}

.help-tile {
  min-width: 62px;
  min-height: 66px;
  display: grid;
  place-items: center;
  border: 2px solid #4aa4e3;
  border-radius: 20px;
  background: #fffdf6;
  box-shadow:
    0 0 0 4px rgb(92 177 236 / 0.22),
    0 6px 10px rgb(9 53 80 / 0.12);
  font-size: 2rem;
  font-weight: 600;
}

.help-check {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.audio-unavailable {
  margin-top: 16px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgb(224 245 248 / 0.7);
  color: #39708a;
}

.help-audio-controls {
  display: flex;
  gap: 8px;
}

.help-audio-button {
  flex: 1 1 0;
  font-size: 1rem;
  line-height: 1.4;
}

.demo-from-help {
  width: 100%;
  min-height: 56px;
  margin-top: 16px;
  border-color: #8dcbe0;
  background: #effbfd;
  font-size: 1rem;
  line-height: 1.4;
}

.reward-panel,
.finale-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.reward-art {
  width: min(100%, 560px);
  max-height: min(42vh, 340px);
  object-fit: contain;
  filter: drop-shadow(0 10px 8px rgb(8 45 71 / 0.17));
}

.reward-stars {
  display: flex;
  gap: 2px;
  filter: drop-shadow(0 3px 3px rgb(8 45 71 / 0.15));
}

.reward-stars img {
  width: clamp(34px, 5.5vmin, 52px);
  aspect-ratio: 1;
}

.reward-copy {
  margin: 0;
  color: var(--navy-dark);
  font-size: clamp(1rem, 2vmin, 1.2rem);
  font-weight: 600;
}

.reward-actions,
.finale-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.finale-panel .reward-art {
  max-height: min(46vh, 380px);
}

.finale-panel h3 {
  margin: 0;
  color: var(--navy-dark);
  font-size: clamp(1.7rem, 4vmin, 2.8rem);
  line-height: 1;
}

.finale-actions button {
  min-height: 56px;
}

.finale-home {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

@keyframes calm-nudge {
  0%,
  100% {
    transform: translateX(0);
  }
  45% {
    transform: translateX(5px);
  }
}

@keyframes gentle-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 800px) {
  .world-landscape {
    display: none;
  }

  .world-portrait {
    display: block;
  }

  .intro-screen {
    padding:
      max(8px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .intro-title-frame {
    max-width: 94vw;
    padding: 8px 15px;
  }

  h1 {
    font-size: clamp(2rem, 7.4vw, 2.4rem);
  }

  .intro-caption {
    font-size: 0.92rem;
  }

  .play-button {
    min-width: 172px;
    min-height: 58px;
  }

  .game-screen {
    gap: 6px;
    padding:
      max(6px, env(safe-area-inset-top))
      max(9px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(9px, env(safe-area-inset-left));
  }

  .game-header {
    min-height: 32px;
  }

  .level-progress {
    gap: 6px;
  }

  .level-token {
    min-width: 28px;
    min-height: 28px;
    padding: 2px 5px;
    font-size: 0.8rem;
  }

  .level-done {
    display: none;
  }

  .task-stars {
    gap: 0;
  }

  .task-stars img {
    width: 25px;
    height: 25px;
  }

  .level-label {
    padding: 4px 9px;
    font-size: 0.75rem;
  }

  .game-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(100px, 28vw, 190px);
    grid-template-rows: clamp(112px, 30vw, 192px) auto auto auto auto auto;
    align-items: start;
    align-content: center;
    gap: 6px 12px;
  }

  .message-column {
    display: contents;
  }

  .guide-line {
    width: auto;
    height: auto;
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
    align-self: center;
    padding: 0;
  }

  .sopo-media {
    width: clamp(72px, 15vw, 100px);
    height: clamp(64px, 13.5vw, 90px);
  }

  .guide-name {
    display: none;
  }

  .instruction-text {
    font-size: clamp(0.82rem, 2.25vw, 0.98rem);
  }

  .demo-banner {
    width: auto;
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 60px;
    padding: 0;
  }

  .demo-skip {
    min-width: 60px;
    min-height: 60px;
    padding: 2px;
  }

  .board-area {
    width: 100%;
    height: clamp(210px, 27vh, 270px);
    grid-column: 1 / -1;
    grid-row: 3;
    margin: 0;
  }

  .board-title,
  .board-total,
  .bead-total {
    font-size: 0.75rem;
  }

  .board-rows {
    padding: 2px 0;
  }

  .bead-group {
    --bead-size: clamp(32px, 5.8vw, 40px);
  }

  .feedback {
    width: 100%;
    min-height: 22px;
    grid-column: 1 / -1;
    grid-row: 4;
    font-size: 0.75rem;
  }

  .comparison-helper {
    width: 100%;
    grid-column: 1 / -1;
    grid-row: 5;
    min-height: 64px;
    padding: 4px 7px;
  }

  .mini-count {
    width: auto;
  }

  .comparison-copy strong {
    font-size: 0.75rem;
  }

  .comparison-copy p {
    font-size: 0.75rem;
  }

  .answer-area {
    width: 100%;
    grid-column: 1 / -1;
    grid-row: 6;
    min-height: 76px;
    grid-template-columns: minmax(0, 1fr) 68px auto;
    gap: 6px;
  }

  .answer-group {
    gap: 6px;
  }

  .numeral-tile {
    min-height: 76px;
    padding: 4px 3px 2px;
    border-radius: 18px;
  }

  .numeral-value {
    font-size: 64px;
  }

  .choice-note {
    font-size: 0.75rem;
  }

  .ok-button,
  .ok-button img {
    width: 68px;
    height: 68px;
  }

  .ok-button span {
    font-size: 0.75rem;
  }

  .next-button {
    min-width: 60px;
    min-height: 68px;
    padding: 4px;
    border-radius: 18px;
  }

  .mambo-reaction {
    position: relative;
    width: 100%;
    height: 100%;
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
    gap: 0;
  }

  .mambo-media {
    width: 100%;
    max-width: 170px;
    flex: 1 1 auto;
    min-height: 0;
    aspect-ratio: auto;
  }

  .mambo-copy {
    position: absolute;
    bottom: 0;
    width: 100%;
    max-width: none;
    margin-top: 0;
    padding: 4px 5px 5px;
    border-radius: 12px;
  }

  .mambo-copy p:last-child {
    font-size: 0.75rem;
  }

  .reaction-name {
    display: none;
  }

  .game-controls {
    min-height: 58px;
    gap: 4px;
    padding-left: 39px;
    padding-right: 0;
  }

  .icon-control {
    width: 58px;
    min-width: 56px;
    min-height: 58px;
    grid-template-rows: 40px 14px;
  }

  .icon-control img {
    width: 40px;
    height: 40px;
  }

  .icon-control span {
    font-size: 0.75rem;
  }

  .corner-rune {
    width: 32px;
  }

  .modal-layer {
    padding: 10px 10px 64px;
  }

  .modal-dialog {
    width: 96vw;
    max-height: calc(100svh - 74px);
    padding: 15px;
    border-radius: 24px;
  }

  .level-menu,
  .reward-actions,
  .finale-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .help-steps {
    grid-template-columns: 1fr;
  }

  .help-step {
    grid-template-columns: 34px minmax(72px, 105px) 1fr;
    grid-template-rows: auto;
    align-items: center;
    justify-items: start;
    text-align: left;
  }

  .help-audio-controls {
    flex-direction: column;
  }

  .reward-art {
    max-height: 34vh;
  }
}

@media (min-width: 801px) and (orientation: portrait) {
  .game-body {
    align-items: center;
  }

  .mambo-reaction {
    align-self: center;
  }
}

@media (max-width: 800px) and (max-height: 700px) {
  .game-body {
    grid-template-rows: 96px auto auto auto auto auto;
  }

  .board-area {
    height: 170px;
  }

  .mambo-media {
    width: min(100%, 94px);
    max-width: 94px;
  }

  .mambo-copy p:last-child {
    font-size: 0.75rem;
  }
}

@media (max-width: 430px) {
  .game-header {
    gap: 5px;
  }

  .level-progress {
    gap: 4px;
  }

  .level-token {
    min-width: 27px;
    min-height: 26px;
    padding: 2px 4px;
    font-size: 0.78rem;
  }

  .task-stars img {
    width: 22px;
    height: 22px;
  }

  .level-label {
    padding: 4px 7px;
    font-size: 0.75rem;
  }

  .game-body {
    grid-template-columns: minmax(0, 1fr) clamp(88px, 24vw, 102px);
    grid-template-rows: 84px auto auto auto auto auto;
    column-gap: 8px;
    row-gap: 5px;
  }

  .guide-line {
    padding: 0;
  }

  .sopo-media {
    width: 54px;
    height: 50px;
  }

  .instruction-text {
    font-size: clamp(0.75rem, 3.15vw, 0.83rem);
  }

  .demo-banner {
    min-height: 60px;
    padding: 0;
  }

  .demo-skip {
    min-width: 60px;
    min-height: 60px;
  }

  .board-area {
    height: clamp(202px, 28vh, 236px);
  }

  .board-heading {
    min-height: 20px;
  }

  .board-title,
  .board-total,
  .bead-total {
    font-size: 0.75rem;
  }

  .bead-row {
    gap: 4px;
  }

  .bead-group {
    --bead-gap: 3px;
    --bead-size: clamp(18px, 5.6vw, 26px);
  }

  .five-marker,
  .ten-marker {
    transform: translateY(17px);
    font-size: 18px;
  }

  .five-marker {
    min-width: 14px;
    padding-inline: 2px;
  }

  .ten-marker {
    min-width: 17px;
  }

  .feedback {
    font-size: 0.75rem;
  }

  .comparison-helper {
    min-height: 64px;
    gap: 5px;
    padding-inline: 5px;
  }

  .mini-count {
    width: auto;
    gap: 1px;
  }

  .comparison-copy {
    column-gap: 4px;
  }

  .comparison-copy strong {
    font-size: 0.75rem;
  }

  .comparison-copy p {
    font-size: 0.75rem;
  }

  .comparison-marker {
    font-size: 0.75rem;
  }

  .answer-area {
    grid-template-columns: minmax(0, 1fr) 66px auto;
    min-height: 76px;
    gap: 4px;
  }

  .answer-group {
    gap: 4px;
  }

  .numeral-tile {
    min-height: 76px;
    border-radius: 15px;
  }

  .numeral-value {
    font-size: 64px;
  }

  .choice-note {
    font-size: 0.75rem;
  }

  .ok-button,
  .ok-button img {
    width: 66px;
    height: 66px;
  }

  .next-button {
    min-width: 60px;
    min-height: 68px;
    padding: 3px;
  }

  .mambo-copy {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .mambo-copy p:last-child {
    font-size: 0.75rem;
  }
}

@media (min-width: 430px) and (max-width: 800px) and (min-height: 800px) {
  .answer-area {
    min-height: 88px;
    grid-template-columns: minmax(0, 1fr) 76px auto;
  }

  .numeral-tile {
    min-height: 88px;
  }

  .numeral-value {
    font-size: 64px;
  }

  .ok-button,
  .ok-button img {
    width: 76px;
    height: 76px;
  }
}

@media (orientation: landscape) and (min-height: 700px) {
  .game-body {
    align-items: center;
  }

  .answer-area {
    min-height: 88px;
    grid-template-columns: minmax(0, 1fr) 76px auto;
  }

  .numeral-tile {
    min-height: 88px;
  }

  .numeral-value {
    font-size: 64px;
  }

  .ok-button,
  .ok-button img {
    width: 76px;
    height: 76px;
  }
}

@media (max-height: 680px) and (min-width: 801px) {
  .game-screen {
    gap: 5px;
    padding-top: 5px;
    padding-bottom: 4px;
  }

  .game-body {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 12px;
  }

  .guide-line {
    min-height: 0;
    padding: 0;
  }

  .sopo-media {
    width: 66px;
    height: 58px;
  }

  .instruction-text {
    font-size: 0.8rem;
  }

  .demo-banner {
    min-height: 60px;
    padding: 0;
  }

  .demo-skip {
    min-width: 60px;
    min-height: 60px;
  }

  .board-area {
    height: 170px;
  }

  .board-heading {
    min-height: 19px;
  }

  .bead-group {
    --bead-size: 31px;
  }

  .feedback {
    min-height: 19px;
    font-size: 0.75rem;
  }

  .comparison-helper {
    min-height: 60px;
  }

  .answer-area {
    min-height: 64px;
    grid-template-columns: minmax(0, 1fr) 66px auto;
  }

  .numeral-tile {
    min-height: 64px;
  }

  .numeral-value {
    font-size: 48px;
  }

  .ok-button,
  .ok-button img {
    width: 64px;
    height: 64px;
  }

  .mambo-media {
    width: 104px;
  }

  .mambo-copy {
    margin-top: -5px;
    padding: 4px 5px;
  }

  .mambo-copy p:last-child {
    font-size: 0.75rem;
  }

  .reaction-name {
    display: none;
  }
}

@media (max-height: 420px) and (orientation: landscape) {
  .intro-screen {
    padding: 5px 10px;
  }

  .intro-title-frame {
    padding: 3px 18px;
  }

  h1 {
    font-size: clamp(2rem, 5vh, 2.15rem);
  }

  .intro-bottom {
    gap: 4px;
  }

  .intro-caption {
    padding: 3px 12px;
    font-size: 0.8rem;
  }

  .play-button {
    min-width: 160px;
    min-height: 56px;
    padding: 2px 18px 2px 4px;
  }

  .play-button img {
    width: 46px;
    height: 46px;
  }

  .game-screen {
    gap: 3px;
    padding: 4px 8px;
  }

  .game-header {
    min-height: 27px;
  }

  .level-token {
    min-width: 30px;
    min-height: 24px;
    padding: 1px 5px;
    font-size: 0.76rem;
  }

  .task-stars img {
    width: 24px;
    height: 24px;
  }

  .game-body {
    grid-template-columns: minmax(0, 1fr) 86px;
    grid-template-rows: 58px 100px auto 64px;
    gap: 1px 5px;
    align-content: center;
  }

  .message-column {
    display: contents;
  }

  .guide-line {
    grid-column: 1;
    grid-row: 1;
    width: auto;
    height: 58px;
    justify-self: start;
    padding: 0;
    border-radius: 0;
  }

  .sopo-media {
    width: 58px;
    height: 44px;
  }

  .instruction-text {
    font-size: 0.75rem;
  }

  .demo-banner {
    grid-column: 1;
    grid-row: 1;
    width: 56px;
    height: 56px;
    justify-self: end;
    padding: 0;
  }

  .demo-skip {
    min-width: 56px;
    min-height: 56px;
    padding: 1px;
  }

  .board-area {
    grid-column: 1 / -1;
    grid-row: 2;
    width: min(100%, 720px);
    height: 100px;
    justify-self: center;
  }

  .bead-board {
    padding: 16px 7%;
    border-radius: 24px;
  }

  .board-heading {
    min-height: 17px;
  }

  .board-title,
  .board-total,
  .bead-total {
    font-size: 0.75rem;
  }

  .bead-group {
    --bead-size: clamp(18px, 5.6vh, 25px);
  }

  .five-marker,
  .ten-marker {
    transform: translateY(16px);
    font-size: 16px;
  }

  .feedback {
    min-height: 0;
    font-size: 0.75rem;
  }

  .comparison-helper {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 60px;
    padding: 1px 5px;
  }

  .mini-count {
    width: auto;
  }

  .comparison-copy strong,
  .comparison-copy p {
    font-size: 0.75rem;
  }

  .comparison-marker {
    display: none;
  }

  .answer-area {
    grid-column: 1 / -1;
    grid-row: 4;
    min-height: 64px;
    grid-template-columns: minmax(0, 1fr) 64px auto;
    gap: 4px;
  }

  .numeral-tile {
    min-height: 64px;
    border-radius: 14px;
  }

  .numeral-value {
    font-size: 48px;
  }

  .choice-note {
    font-size: 0.75rem;
  }

  .ok-button,
  .ok-button img {
    width: 64px;
    height: 64px;
  }

  .ok-button span {
    font-size: 0.75rem;
  }

  .next-button {
    min-width: 56px;
    min-height: 56px;
    padding: 2px;
    border-radius: 14px;
  }

  .mambo-reaction {
    position: relative;
    grid-column: 2;
    grid-row: 1;
    width: 86px;
    height: 58px;
  }

  .mambo-media {
    width: 70px;
    max-width: 70px;
    height: 58px;
  }

  .mambo-copy {
    display: none;
  }

  .game-controls {
    min-height: 56px;
  }

  .icon-control {
    width: 56px;
    min-height: 56px;
    grid-template-rows: 36px 14px;
  }

  .icon-control img {
    width: 40px;
    height: 40px;
  }

  .corner-rune {
    width: 30px;
  }
}

@media (max-width: 360px) {
  .game-screen {
    padding-inline: 7px;
  }

  .game-controls {
    gap: 3px;
    padding-left: 37px;
  }

  .icon-control {
    width: 56px;
  }

  .level-label {
    display: none;
  }

  .answer-area {
    grid-template-columns: minmax(0, 1fr) 64px auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }



  button:active {
    transform: none !important;
  }
}

/* top-controls-2: one top chrome row, a flexible activity body, and one confirmation row. */
.game-screen {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(5px, 1vh, 9px);
}

.game-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
}

.game-controls {
  min-height: var(--control-height);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(3px, 0.7vw, 8px);
  padding: 0;
}

.icon-control {
  width: clamp(64px, 6vw, 72px);
  min-width: clamp(64px, 6vw, 72px);
  height: clamp(64px, 6vw, 72px);
  min-height: clamp(64px, 6vw, 72px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.icon-control img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.progress-cluster {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(7px, 1.2vw, 13px);
}

.answer-area {
  min-height: 88px;
  display: block;
}

.answer-group {
  width: 100%;
}

.confirmation-controls {
  position: relative;
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.ok-button,
.ok-button img {
  width: clamp(96px, 10vh, 108px);
  height: clamp(96px, 10vh, 108px);
}

.ok-button {
  min-width: 96px;
  min-height: 96px;
}

.next-button {
  position: absolute;
  top: 50%;
  left: calc(50% + clamp(58px, 6vw, 70px));
  min-width: 72px;
  min-height: 76px;
  transform: translateY(-50%);
}

.demo-banner {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.demo-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}

.demo-dot {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 2px solid rgb(255 255 255 / 0.9);
  border-radius: 50%;
  background: rgb(255 253 246 / 0.68);
  box-shadow: 0 3px 8px rgb(10 51 79 / 0.12);
  color: rgb(22 74 122 / 0.58);
  font-size: 22px;
  font-weight: 600;
}

.demo-dot.current-example {
  border-color: #7ab8d7;
  background: var(--navy);
  color: #fff;
  box-shadow:
    0 3px 8px rgb(10 51 79 / 0.2),
    inset 0 1px 0 rgb(255 255 255 / 0.3);
}

.demo-skip {
  display: none !important;
}

.demo-hand {
  width: clamp(100px, 12vmin, 110px);
  height: auto;
  transform-origin: center;
}

.demo-hand.points-to-ok {
  transform: rotate(180deg);
}

.board-rows {
  gap: clamp(2px, 0.7vh, 8px);
  padding: 2px 1%;
}

.bead-row {
  gap: clamp(10px, 2vw, 22px);
}

.bead-half {
  position: relative;
  min-width: 0;
  align-self: stretch;
  display: grid;
  grid-template-rows: minmax(0, 1fr) var(--marker-row-height);
  align-items: center;
  justify-items: center;
  gap: var(--marker-gap);
}

.bead-group {
  grid-row: 1;
}

.five-marker,
.ten-marker {
  position: relative;
  inset: auto;
  min-width: 0;
  min-height: var(--marker-row-height);
  display: grid;
  place-items: center;
  padding: 0 5px;
  transform: none;
  color: #315f78;
  font-size: var(--marker-row-height);
  font-weight: 600;
  line-height: 1;
}

.five-marker {
  position: absolute;
  top: calc((100% - var(--marker-row-height) - var(--marker-gap)) / 2 + 26px);
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.78);
}

.ten-marker {
  position: absolute;
  right: 0;
  bottom: 0;
  padding-inline: 3px;
}

@media (max-width: 800px) {
  .game-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  .game-controls {
    grid-row: 1;
    justify-self: start;
    min-height: 56px;
    gap: 4px;
  }

  .progress-cluster {
    grid-row: 2;
    justify-self: end;
    gap: 5px;
  }

  .game-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(100px, 28vw, 190px);
    grid-template-rows: clamp(112px, 30vw, 192px) auto auto auto auto auto;
    align-items: start;
    align-content: center;
    gap: 6px 12px;
  }

  .message-column {
    display: contents;
  }

  .answer-area {
    width: 100%;
    min-height: 76px;
    grid-column: 1 / -1;
    grid-row: 6;
  }

  .ok-button,
  .ok-button img {
    width: 96px;
    height: 96px;
  }

  .ok-button {
    min-width: 96px;
    min-height: 96px;
  }

  .confirmation-controls {
    min-height: 100px;
  }

  .demo-hand {
    width: 90px;
  }

  .bead-group {
    --bead-size: clamp(28px, 5.8vw, 40px);
  }

}

@media (min-width: 481px) and (max-width: 800px) {
  .icon-control {
    width: 64px;
    min-width: 64px;
    height: 64px;
    min-height: 64px;
  }
}

@media (orientation: portrait) and (min-width: 481px) and (max-width: 800px) and (max-height: 850px) {
  .game-body {
    grid-template-rows: 128px auto auto auto auto auto;
  }
}

@media (max-width: 480px) {
  .icon-control {
    width: 56px;
    min-width: 56px;
    height: 56px;
    min-height: 56px;
  }

  .ok-button,
  .ok-button img {
    width: 80px;
    height: 80px;
  }

  .ok-button {
    min-width: 80px;
    min-height: 80px;
  }

  .confirmation-controls {
    min-height: 86px;
  }

  .next-button {
    left: calc(50% + 48px);
  }

  .bead-group {
    --bead-size: clamp(18px, 5.6vw, 26px);
  }

  .numeral-value {
    font-size: 56px;
  }
}

@media (max-width: 800px) and (max-height: 700px) {
  .game-body {
    grid-template-rows: 96px auto auto auto auto auto;
  }

  .board-area {
    height: 170px;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  .game-screen {
    gap: 3px;
    padding: 4px 8px;
  }

  .game-header {
    min-height: 56px;
  }

  .game-controls {
    min-height: 56px;
  }

  .icon-control {
    width: 56px;
    min-width: 56px;
    height: 56px;
    min-height: 56px;
  }

  .game-body {
    grid-template-columns: minmax(0, 1fr) 86px;
    grid-template-rows: 24px 116px auto 64px;
    gap: 1px 5px;
    align-content: center;
  }

  .message-column {
    display: contents;
  }

  .guide-line {
    display: flex;
    grid-column: 1;
    grid-row: 1;
    width: 58px;
    height: 28px;
    justify-self: start;
    overflow: visible;
  }

  .sopo-media {
    width: 58px;
    height: 44px;
    align-self: center;
  }

  .demo-banner {
    width: calc(100% - 70px);
    min-height: 28px;
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
  }

  .demo-dot {
    width: 26px;
    height: 26px;
    font-size: 18px;
  }

  .board-area {
    width: 100%;
    height: 116px;
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
  }

  .five-marker {
    top: calc((100% - var(--marker-row-height) - var(--marker-gap)) / 2 + 14px);
  }

  .mambo-reaction {
    position: relative;
    width: 86px;
    height: 100px;
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
  }

  .mambo-media {
    width: 80px;
    max-width: 80px;
    height: 100px;
  }

  .mambo-copy {
    display: none;
  }

  .comparison-helper {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 48px;
    padding: 1px 5px;
  }

  .answer-area {
    grid-column: 1 / -1;
    grid-row: 4;
    min-height: 64px;
  }

  .numeral-tile {
    min-height: 64px;
    border-radius: 14px;
  }

  .numeral-value {
    font-size: 48px;
  }

  .bead-board {
    padding: 4px 6%;
    border-radius: 24px;
  }

  .bead-group {
    --bead-gap: clamp(2px, 0.7vw, 5px);
    --bead-size: clamp(18px, 5.6vh, 25px);
  }

  .confirmation-controls {
    min-height: 64px;
  }

  .ok-button,
  .ok-button img {
    width: 64px;
    height: 64px;
  }

  .ok-button {
    min-width: 64px;
    min-height: 64px;
  }

  .next-button {
    left: calc(50% + 44px);
    min-width: 56px;
    min-height: 56px;
  }

  .demo-hand {
    width: 70px;
  }
}

@media (max-width: 480px) {
  :root {
    --marker-row-height: 28px;
  }
}

@media (max-height: 420px) {
  :root {
    --marker-row-height: 24px;
  }
}

@media (orientation: landscape) and (max-height: 370px) {
  .game-screen:has(.game-body #comparisonHelper:not([hidden])) {
    gap: 1px;
  }

  .game-body:has(#comparisonHelper:not([hidden])) {
    grid-template-rows: 0px 116px auto 64px;
  }
}

@media (orientation: landscape) and (min-width: 700px) and (max-height: 370px) {
  .game-header {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3px;
  }

  .progress-cluster {
    grid-row: 1;
    grid-column: 2;
  }

  .game-controls {
    grid-row: 1;
    grid-column: 1;
  }
}

/* juice-deluxe-3: one final actor/layout contract layered over the legacy passes. */
#fx-layer {
  position: fixed;
  inset: 0;
  z-index: 320;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sopo-media,
.mambo-media,
.reward-actor {
  position: relative;
  isolation: isolate;
}

.sopo-media::before,
.mambo-media::before,
.reward-actor::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -12%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 48%, rgb(255 248 222 / 0.64), rgb(255 244 210 / 0.2) 48%, transparent 72%);
  filter: blur(8px);
  pointer-events: none;
}

.sopo-media::after,
.mambo-media::after,
.reward-actor::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: 14%;
  right: 14%;
  bottom: 1%;
  height: 14%;
  border-radius: 50%;
  background: rgb(25 66 83 / 0.2);
  filter: blur(7px);
  pointer-events: none;
}

.sopo-media video,
.sopo-media img,
.mambo-idle,
.mambo-still,
.mambo-cheer,
.reward-actor video,
.reward-actor img {
  position: relative;
  z-index: 1;
}

.sopo-media video,
.sopo-media img,
.mambo-idle,
.mambo-still,
.reward-mambo,
.reward-sopo {
  filter:
    brightness(1.045)
    contrast(1.035)
    drop-shadow(0 9px 6px rgb(11 47 72 / 0.24));
}

.mambo-cheer,
.reward-actor > .reward-cheer {
  position: absolute;
  z-index: 3;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.mambo-cheer.is-visible,
.reward-cheer.is-visible {
  opacity: 1;
}

.mambo-media .mambo-idle,
.mambo-media .mambo-still,
.reward-mambo-frame .reward-mambo {
  opacity: 1;
  transition: opacity 250ms ease;
}

.mambo-media.is-cheering .mambo-idle,
.mambo-media.is-cheering .mambo-still,
.reward-mambo-frame.is-cheering .reward-mambo {
  opacity: 0;
}

.sopo-media.juice-lit::before,
.mambo-media.juice-lit::before {
  animation: actor-warm-light 1500ms ease-out;
}

.reward-scene {
  position: relative;
  width: min(100%, 620px);
  height: clamp(190px, 38vh, 310px);
  max-height: min(46vh, 380px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: visible;
}

.finale-panel .reward-scene {
  height: clamp(210px, 42vh, 340px);
}

.reward-actor {
  height: 100%;
  flex: 0 1 auto;
}

.reward-mambo-frame {
  width: 64%;
}

.reward-sopo-frame {
  width: 33%;
}

.reward-actor video,
.reward-actor img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reward-mambo-fallback,
.reward-sopo-fallback {
  display: none;
}

.reward-mambo-frame.media-fallback .reward-mambo:not(.reward-mambo-fallback),
.reward-sopo-frame.media-fallback .reward-sopo:not(.reward-sopo-fallback) {
  display: none;
}

.reward-mambo-frame.media-fallback .reward-mambo-fallback,
.reward-sopo-frame.media-fallback .reward-sopo-fallback {
  display: block;
}

@keyframes actor-warm-light {
  0% {
    opacity: 0.72;
    transform: scale(0.96);
  }
  38% {
    opacity: 1;
    transform: scale(1.035);
  }
  100% {
    opacity: 0.72;
    transform: scale(1);
  }
}

@media (min-width: 801px) {
  .game-body {
    grid-template-columns: minmax(0, 1fr) clamp(282px, 36vh, 310px);
    align-items: end;
  }

  .guide-line {
    min-height: 158px;
  }

  .sopo-media {
    width: 158px;
    height: 150px;
  }

  .mambo-reaction {
    width: 100%;
  }

  .mambo-media {
    width: clamp(282px, 36vh, 310px);
    height: clamp(282px, 36vh, 310px);
    max-width: 100%;
    aspect-ratio: 1;
  }
}

@media (min-width: 801px) and (max-height: 720px) {
  .guide-line {
    min-height: 96px;
  }

  .sopo-media {
    width: 96px;
    height: 96px;
  }
}

@media (min-width: 801px) and (max-height: 620px) {
  .guide-line {
    min-height: 84px;
  }

  .sopo-media {
    width: 84px;
    height: 84px;
  }
}

@media (max-width: 800px) {
  .game-body {
    grid-template-columns: minmax(0, 1fr) clamp(150px, 28vw, 180px);
    grid-template-rows: 160px auto auto auto auto auto;
    align-items: start;
    align-content: center;
  }

  .guide-line {
    height: 160px;
    align-self: center;
  }

  .sopo-media {
    width: clamp(125px, 34vw, 145px);
    height: clamp(125px, 34vw, 145px);
  }

  .mambo-reaction {
    height: 160px;
    align-self: center;
  }

  .mambo-media {
    width: clamp(160px, 42vw, 172px);
    max-width: none;
    height: clamp(160px, 42vw, 172px);
    flex: 0 0 auto;
    min-height: 0;
    aspect-ratio: 1;
  }

  .reward-scene {
    height: clamp(175px, 32vh, 270px);
  }

  .finale-panel .reward-scene {
    height: clamp(185px, 35vh, 290px);
  }
}

@media (orientation: portrait) and (min-width: 381px) and (max-width: 430px) and (min-height: 700px) {
  .game-body {
    grid-template-columns: minmax(0, 1fr) 170px;
    grid-template-rows: 158px auto auto auto auto auto;
  }

  .guide-line,
  .mambo-reaction {
    height: 158px;
  }

  .sopo-media {
    width: 136px;
    height: 136px;
  }

  .mambo-media {
    width: 168px;
    height: 168px;
  }
}

@media (orientation: portrait) and (max-width: 480px) and (max-height: 699px) {
  .game-body {
    grid-template-columns: minmax(0, 1fr) 130px;
    grid-template-rows: 116px auto auto auto auto auto;
    row-gap: 4px;
  }

  .guide-line,
  .mambo-reaction {
    height: 116px;
  }

  .sopo-media {
    width: 100px;
    height: 100px;
  }

  .mambo-media {
    width: 125px;
    height: 125px;
  }

  .comparison-helper {
    min-height: 60px;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  .game-body {
    grid-template-columns: minmax(0, 1fr) 210px;
    grid-template-rows: 24px 116px auto 64px;
    column-gap: 5px;
  }

  .guide-line {
    grid-column: 2;
    grid-row: 2;
    width: 88px;
    height: 116px;
    justify-self: start;
    align-self: center;
    overflow: visible;
  }

  .sopo-media {
    width: 88px;
    height: 88px;
    align-self: center;
  }

  .demo-banner {
    grid-column: 1;
    grid-row: 1;
    width: calc(100% - 72px);
    justify-self: end;
  }

  .board-area {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    height: 116px;
  }

  .mambo-reaction {
    grid-column: 2;
    grid-row: 2;
    width: 120px;
    height: 116px;
    justify-self: end;
    align-self: center;
  }

  .mambo-media {
    width: 120px;
    max-width: none;
    height: 116px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #fx-layer,
  .mambo-cheer,
  .reward-cheer,
  .reward-mambo:not(.reward-mambo-fallback),
  .reward-sopo:not(.reward-sopo-fallback) {
    display: none !important;
  }

  .reward-mambo-fallback,
  .reward-sopo-fallback {
    display: block !important;
  }
}
