@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 {
  --ink: #174a7e;
  --ink-deep: #103858;
  --coral: #e97c64;
  --coral-deep: #c75f4d;
  --ivory: #f7eedc;
  --warm-white: #fffaf0;
  --ice: #dff5fc;
  --ice-deep: #a9dce9;
  --amber: #d89134;
  --focus: #ffd36a;
  --bead-gap: 2px;
  --bead-size: 32px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--ice);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: 18px;
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.bead:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

[hidden] {
  display: none !important;
}

.sr-only,
.row-label,
.row-slider > span {
  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;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.scene-background {
  position: fixed;
  z-index: -2;
  inset: 0;
  display: block;
  background: var(--ice);
}

.scene-background img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(12px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 53% 50%, rgba(255, 250, 240, 0.12), transparent 50%),
    linear-gradient(180deg, rgba(223, 245, 252, 0.06), rgba(13, 89, 119, 0.045));
}

.topbar {
  position: relative;
  z-index: 20;
  width: min(100%, 1400px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  min-width: 0;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.94);
}

.brand-title {
  display: block;
  font-size: clamp(22px, 2vw, 26px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.game-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(4px, 0.65vw, 10px);
}

.wood-control {
  position: relative;
  width: 56px;
  height: 56px;
  min-width: 56px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: transparent;
  background-image: var(--control-normal);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  cursor: pointer;
  filter: drop-shadow(0 4px 5px rgba(30, 58, 63, 0.2));
  text-decoration: none;
  transition: transform 120ms ease, filter 120ms ease;
}

.wood-control:hover {
  transform: translateY(-2px) scale(1.035);
  filter: drop-shadow(0 6px 7px rgba(30, 58, 63, 0.24));
}

.wood-control:active:not(:disabled) {
  transform: translateY(1px) scale(0.96);
  background-image: var(--control-pressed);
}

.wood-control:disabled {
  cursor: default;
  background-image: var(--control-disabled, var(--control-normal));
  transform: none;
}

.control-pause {
  --control-normal: url("assets/ui/button-pause-normal.webp");
  --control-pressed: url("assets/ui/button-pause-pressed.webp");
  --control-disabled: url("assets/ui/button-pause-disabled.webp");
}

.control-sound {
  --control-normal: url("assets/ui/button-volume-normal.webp");
  --control-pressed: url("assets/ui/button-volume-pressed.webp");
  --control-disabled: url("assets/ui/button-volume-disabled.webp");
}

.control-sound[aria-pressed="true"] {
  --control-normal: url("assets/ui/button-mute-normal.webp");
  --control-pressed: url("assets/ui/button-mute-pressed.webp");
  --control-disabled: url("assets/ui/button-mute-disabled.webp");
}

.control-restart {
  --control-normal: url("assets/ui/button-replay-normal.webp");
  --control-pressed: url("assets/ui/button-replay-pressed.webp");
  --control-disabled: url("assets/ui/button-replay-disabled.webp");
}

.control-home {
  --control-normal: url("assets/ui/button-home-normal.webp");
  --control-pressed: url("assets/ui/button-home-pressed.webp");
  --control-disabled: url("assets/ui/button-home-disabled.webp");
}

.control-help {
  --control-normal: url("assets/ui/button-help-normal.webp");
  --control-pressed: url("assets/ui/button-help-normal.webp");
}

.control-help:active:not(:disabled) {
  filter: drop-shadow(0 2px 4px rgba(30, 58, 63, 0.2)) brightness(0.94);
}

.game-main {
  width: min(100%, 1400px);
  flex: 1;
  margin: 6px auto 0;
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.challenge-copy {
  position: relative;
  z-index: 9;
  width: min(100%, 650px);
  display: grid;
  justify-items: center;
  margin: 6px auto 0;
  padding: 20px 22px 16px;
  background: #fffcf5;
  background-clip: padding-box;
  border-radius: 24px;
  border: 18px solid transparent;
  border-image-source: url("assets/deluxe/ice-panel.webp");
  border-image-slice: 16% 10% fill;
  border-image-width: 18px;
  border-image-repeat: stretch;
  text-align: center;
}

.level-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  text-transform: none;
}

.level-name::before {
  margin-right: 7px;
  content: "·";
}

.challenge-copy h1 {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: clamp(36px, 4vw, 44px);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1;
}

.challenge-copy h1 output {
  display: inline-grid;
  min-width: 1.15em;
  min-height: 1.15em;
  margin-left: 0.08em;
  place-items: center;
  padding: 0 0.14em 0.04em;
  border: 1px solid rgba(23, 74, 126, 0.24);
  border-radius: 0.22em;
  background: #fff;
  box-shadow: inset 0 0 0 3px rgba(223, 245, 252, 0.72);
  font-size: 60px;
}

.task-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.2vw, 18px);
  margin-top: 10px;
}

.world-progress,
.star-progress {
  display: flex;
  align-items: center;
  gap: 3px;
}

.world-marker {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid rgba(23, 74, 126, 0.34);
  border-radius: 50%;
  color: var(--ink);
  background: #fff;
}

.world-marker svg {
  width: 22px;
  height: 22px;
}

.world-marker.current {
  color: var(--ink);
  border-color: var(--ink);
  background: #fff;
  box-shadow: inset 0 0 0 3px var(--ice);
}

.world-marker.complete {
  color: var(--warm-white);
  border-color: var(--ink);
  background: var(--ink);
}

.star-slot {
  width: 30px;
  height: 30px;
}

.star-slot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.bay-work {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: clamp(500px, 66vh, 640px);
  margin-top: 2px;
}

.sopo-guide {
  position: absolute;
  z-index: 4;
  bottom: 8px;
  left: clamp(0px, 1.6vw, 24px);
  width: clamp(260px, 25vw, 320px);
  margin: 0;
  pointer-events: none;
}

.sopo-frame {
  position: relative;
}

.sopo-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 0.74 / 1;
  object-fit: contain;
  filter: drop-shadow(0 10px 13px rgba(22, 65, 76, 0.23));
}

.sopo-name {
  display: none;
}

.sopo-guide p {
  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;
}

.board-wrap {
  position: relative;
  width: calc(100% - clamp(230px, 26vw, 340px));
  max-width: 980px;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  padding-top: 4px;
}

.board-heading {
  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;
}

.wood-board {
  position: relative;
  width: 100%;
  min-height: 270px;
  aspect-ratio: 2 / 1;
  flex: 0 0 auto;
  background: #fffcf5;
  background-clip: padding-box;
  border-radius: 24px;
  border: 24px solid transparent;
  border-image-source: url("assets/deluxe/ice-panel.webp");
  border-image-slice: 16% 10% fill;
  border-image-width: 24px;
  border-image-repeat: stretch;
  filter: drop-shadow(0 12px 12px rgba(30, 66, 74, 0.18));
}

.bead-row {
  position: absolute;
  left: 7%;
  width: 86%;
  display: grid;
  grid-template-rows: minmax(36px, 1fr) 56px;
  min-width: 0;
  padding: 0;
}

.bead-row[data-row="top"] {
  top: 4%;
  height: 44%;
}

.bead-row[data-row="bottom"] {
  top: 52%;
  height: 44%;
}

.rod {
  position: relative;
  min-width: 0;
  min-height: 36px;
  margin: 0 5px;
  touch-action: none;
}

.rod::before {
  position: absolute;
  z-index: 0;
  top: 50%;
  right: -5px;
  left: -5px;
  height: 4px;
  border-radius: 999px;
  content: "";
  background: linear-gradient(#f7fbfb, #9eabb0 48%, #64777d);
  box-shadow: 0 1px 1px rgba(21, 51, 59, 0.32), inset 0 1px 0 #fff;
  transform: translateY(-50%);
}

.bead {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: var(--bead-size);
  height: var(--bead-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: grab;
  touch-action: none;
  transform: translate(var(--drag-x, 0px), -50%);
  will-change: transform;
}

.bead:disabled {
  cursor: default;
}

.bead:active {
  cursor: grabbing;
}

.bead-body {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(0 2px 2px rgba(43, 46, 39, 0.2));
  transition: transform 140ms ease, filter 140ms ease;
}

.bead[data-color="coral"] .bead-body {
  background-image: url("assets/deluxe/bead-coral.webp");
}

.bead[data-color="ivory"] .bead-body {
  background-image: url("assets/deluxe/bead-ivory.webp");
}

.bead[data-active="true"] .bead-body {
  filter: drop-shadow(0 2px 2px rgba(43, 46, 39, 0.2)) brightness(1.025);
}

.bead.dragging {
  z-index: 8;
}

.bead.dragging .bead-body {
  filter: drop-shadow(0 4px 5px rgba(43, 46, 39, 0.25)) brightness(1.04);
  transform: scale(1.08);
}

.row-slider {
  position: relative;
  display: grid;
  min-height: 56px;
  align-items: center;
  padding: 0 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.row-slider:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.row-slider input {
  width: 100%;
  min-width: 0;
  height: 56px;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-x;
  -webkit-appearance: none;
  appearance: none;
}

.row-slider input:disabled {
  cursor: default;
  opacity: 0.52;
}

.row-slider input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ice-deep), rgba(169, 220, 233, 0.48));
  box-shadow: inset 0 1px 1px rgba(23, 74, 126, 0.2);
}

.row-slider input::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border: 2px solid #7e9097;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff, #b9c7ca 58%, #788b92);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.9), 0 2px 4px rgba(24, 65, 79, 0.2);
  -webkit-appearance: none;
}

.row-slider input::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ice-deep), rgba(169, 220, 233, 0.48));
  box-shadow: inset 0 1px 1px rgba(23, 74, 126, 0.2);
}

.row-slider input::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid #7e9097;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff, #b9c7ca 58%, #788b92);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.9), 0 2px 4px rgba(24, 65, 79, 0.2);
}

.board-footer {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 8px 10px;
}

.live-count {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  border: 2px solid rgba(23, 74, 126, 0.18);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.98);
}

.live-count span {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
}

.live-count output {
  min-width: 1.15em;
  font-size: 36px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
}

.okay-button {
  --okay-art-size: 86px;
  position: relative;
  z-index: 5;
  width: var(--okay-art-size);
  height: auto;
  min-width: 72px;
  min-height: calc(var(--okay-art-size) + 4px + 1.2em);
  flex: 0 0 auto;
  display: inline-grid;
  grid-template-rows: var(--okay-art-size) auto;
  gap: 4px;
  justify-items: center;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 6px 7px rgba(24, 72, 57, 0.22));
  transition: transform 130ms ease, filter 130ms ease;
}

.okay-art {
  width: 100%;
  height: var(--okay-art-size);
  background: url("assets/ui/button-check-normal.webp") center / contain no-repeat;
}

.okay-label {
  color: var(--ink);
  font: 600 17px/1.2 Fredoka, "Trebuchet MS", sans-serif;
}

.okay-button:hover:not(:disabled) {
  transform: scale(1.045);
  filter: drop-shadow(0 8px 9px rgba(24, 72, 57, 0.27));
}

.okay-button:active:not(:disabled) {
  transform: scale(0.96);
}

.okay-button:active:not(:disabled) .okay-art {
  background-image: url("assets/ui/button-check-pressed.webp");
}

.okay-button:disabled {
  cursor: default;
  filter: drop-shadow(0 3px 4px rgba(24, 72, 57, 0.16));
}

.okay-button:disabled .okay-art {
  background-image: url("assets/ui/button-check-disabled.webp");
}

.comparison {
  width: min(100%, 650px);
  margin: 4px auto;
  padding: 12px 16px 14px;
  border: 1px solid rgba(23, 74, 126, 0.22);
  border-radius: 16px;
  color: var(--ink);
  background: var(--warm-white);
  box-shadow: 0 5px 14px rgba(30, 58, 63, 0.1);
}

.comparison > p {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.4;
}

.comparison-line {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  min-width: 0;
  min-height: 26px;
  font-size: 16px;
  font-weight: 600;
}

.comparison-line > strong {
  font-size: 22px;
  text-align: right;
}

.mini-beads {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  gap: 2px;
}

.mini-bead {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--coral-deep);
  border-radius: 50%;
  background: var(--coral);
}

.mini-bead.empty {
  border-color: #cabb9e;
  background: rgba(255, 255, 255, 0.56);
}

.mini-bead.extra {
  border-color: var(--amber);
  background: #f4d38d;
}

.board-wrap.success .wood-board {
  animation: board-success 620ms ease both;
}

.board-wrap.retry .wood-board {
  animation: board-retry 440ms ease both;
}

.tutorial-layer {
  width: 100%;
  max-width: 100%;
  min-height: 48px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.tutorial-layer[hidden] {
  display: none;
}

.skip-demo {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 56px;
  padding: 8px 16px;
  border: 2px solid #fff;
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 4px 10px rgba(19, 56, 74, 0.14);
}

.demo-caption {
  min-width: 0;
  max-width: 100%;
  flex: 0 1 auto;
  margin: 0;
  padding: 9px 15px 10px;
  border: 1px solid rgba(23, 74, 126, 0.2);
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 12px rgba(20, 63, 80, 0.1);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}

.tutorial-hand {
  position: fixed;
  z-index: 51;
  width: clamp(64px, 8vw, 102px);
  height: auto;
  transform: translate(-12%, 10%);
  transition: left 430ms ease, top 430ms ease, opacity 180ms ease;
  filter: drop-shadow(0 6px 8px rgba(33, 50, 54, 0.3));
  pointer-events: none;
}

.scene-dialog {
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.scene-dialog::backdrop {
  background: rgba(13, 54, 76, 0.46);
  backdrop-filter: blur(4px);
}

.scene-dialog[open] {
  animation: dialog-fade 180ms ease-out both;
}

.corner-rune {
  position: fixed;
  z-index: 2;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: max(8px, env(safe-area-inset-left));
  width: clamp(38px, 5vw, 58px);
  height: auto;
  opacity: 0.88;
  pointer-events: none;
  filter: drop-shadow(0 3px 5px rgba(25, 51, 57, 0.2));
}

.intro-dialog {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  overflow: auto;
  background: var(--intro-wide, url("assets/intro-wide.webp")) center / cover no-repeat;
}

.intro-dialog::backdrop {
  background: var(--ice);
}

.intro-content {
  position: relative;
  z-index: 1;
  width: min(100%, 1400px);
  min-height: 100%;
  margin: auto;
  padding:
    max(22px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  align-items: center;
}

.framed-title {
  width: min(92vw, 510px);
  justify-self: center;
  align-self: start;
  padding: clamp(12px, 1.8vw, 18px) clamp(18px, 3vw, 29px);
  border: 1px solid rgba(184, 162, 128, 0.52);
  border-radius: 22px;
  background: rgba(247, 238, 220, 0.9);
  box-shadow: 0 10px 26px rgba(16, 61, 81, 0.15);
  text-align: center;
}

.framed-title h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(27px, 4.1vw, 47px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1;
  text-wrap: balance;
}

.framed-title p {
  margin: 7px 0 0;
  color: #5d564d;
  font-size: clamp(15px, 1.7vw, 20px);
  line-height: 1.25;
}

.big-play {
  grid-row: 3;
  justify-self: center;
  align-self: end;
  display: grid;
  justify-items: center;
  gap: 7px;
  min-width: 56px;
  min-height: 56px;
  margin: 0 0 max(2px, env(safe-area-inset-bottom));
  padding: 0;
  border: 0;
  color: var(--ink);
  background: none;
  font-size: clamp(18px, 2vw, 21px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.play-art {
  width: clamp(108px, 18vw, 124px);
  aspect-ratio: 1;
  display: block;
  background: url("assets/ui/button-play-normal.webp") center / contain no-repeat;
  filter: drop-shadow(0 7px 8px rgba(24, 62, 64, 0.22));
}

.play-label {
  padding: 3px 12px 4px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(247, 238, 220, 0.9);
  line-height: 1;
}

.big-play:hover {
  transform: scale(1.04);
}

.big-play:active {
  transform: scale(0.97);
  filter: brightness(0.97);
}

.big-play:active .play-art {
  background-image: url("assets/ui/button-play-pressed.webp");
}

.big-play:disabled .play-art {
  background-image: url("assets/ui/button-play-disabled.webp");
}

.wood-dialog {
  width: min(92vw, 680px);
  max-height: min(92vh, 760px);
  overflow: auto;
}

.pause-dialog {
  width: min(560px, calc(100vw - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))));
  max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
  overflow: auto;
  overscroll-behavior: contain;
}

.pause-panel {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  align-items: center;
  gap: 16px 22px;
  padding: clamp(24px, 5vw, 38px);
  border: 16px solid transparent;
  border-image-source: url("assets/deluxe/ice-panel.webp");
  border-image-slice: 16% 10%;
  border-image-width: 16px;
  border-image-repeat: stretch;
  border-radius: 30px;
  background: var(--warm-white);
  box-shadow: 0 24px 60px rgba(16, 50, 65, 0.3);
}

.pause-sopo {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: contain;
  object-position: center bottom;
}

.pause-copy h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(35px, 7vw, 47px);
  font-weight: 600;
  line-height: 1;
}

.pause-copy p {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
}

.pause-resume {
  grid-column: 1 / -1;
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 96px;
  min-height: 110px;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: none;
  font-weight: 600;
  cursor: pointer;
}

.pause-resume-art {
  width: 84px;
  height: 84px;
  display: block;
  background: url("assets/ui/button-play-normal.webp") center / contain no-repeat;
  filter: drop-shadow(0 6px 7px rgba(24, 62, 64, 0.2));
}

.pause-resume-label {
  line-height: 1;
}

.pause-resume:active .pause-resume-art {
  background-image: url("assets/ui/button-play-pressed.webp");
}

.pause-resume:disabled .pause-resume-art {
  background-image: url("assets/ui/button-play-disabled.webp");
}

.dialog-panel,
.reward-panel {
  position: relative;
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid rgba(184, 162, 128, 0.6);
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 250, 240, 0.99), rgba(226, 244, 248, 0.99));
  box-shadow: 0 24px 60px rgba(16, 50, 65, 0.3), inset 0 1px 0 #fff;
}

.dialog-panel h2,
.reward-panel h2,
.finale-content h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(31px, 5vw, 47px);
  font-weight: 600;
  line-height: 1;
}

.dialog-panel > p {
  margin: 10px 0 20px;
  color: #5f5a52;
}

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(23, 74, 126, 0.26);
  border-radius: 50%;
  color: var(--ink);
  background: var(--warm-white);
  font-size: 31px;
  line-height: 1;
  cursor: pointer;
}

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

.pause-panel > .level-menu {
  grid-column: 1 / -1;
}

.level-choice {
  min-height: 96px;
  padding: 8px 4px;
  border: 1px solid rgba(23, 74, 126, 0.2);
  border-radius: 18px;
  color: var(--ink);
  background: #fffaf0;
  cursor: pointer;
}

.level-choice:hover:not(:disabled) {
  border-color: var(--ink);
  background: #fffdf7;
}

.level-choice:disabled {
  cursor: default;
  border-style: dashed;
  color: #6c7880;
  background: #f1f5f5;
}

.level-choice.current {
  border: 3px solid var(--ink);
  background: #eaf8fc;
  box-shadow: inset 0 0 0 1px #fff;
}

.level-choice svg {
  display: block;
  width: 34px;
  height: 34px;
  margin: 2px auto 5px;
}

.level-choice span {
  display: block;
  font-weight: 600;
}

.level-choice small {
  display: block;
  margin-top: 4px;
  color: inherit;
  font-size: 12px;
  line-height: 1.2;
}

.resume-button,
.next-level,
.replay-tutorial,
.replay-all {
  min-height: 56px;
  margin-top: 22px;
  padding: 10px 26px;
  border: 1px solid var(--ink-deep);
  border-radius: 999px;
  color: var(--warm-white);
  background: var(--ink);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink-deep);
}

.resume-button:hover,
.next-level:hover,
.replay-tutorial:hover,
.replay-all:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--ink-deep);
}

.resume-button:active,
.next-level:active,
.replay-tutorial:active,
.replay-all:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink-deep);
}

.help-dialog {
  width: min(94vw, 800px);
}

.help-lede {
  max-width: 56ch;
}

.mini-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mini-step {
  position: relative;
  min-width: 0;
  padding: 15px 10px 11px;
  border: 1px solid rgba(23, 74, 126, 0.16);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.7);
  text-align: center;
}

.step-number {
  display: grid;
  width: 29px;
  height: 29px;
  margin: 0 auto 10px;
  place-items: center;
  border-radius: 50%;
  color: var(--warm-white);
  background: var(--ink);
  font-weight: 600;
}

.step-diagram {
  display: grid;
  gap: 5px;
}

.step-state {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  color: #6f6659;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.step-target {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--coral-deep);
  border-radius: 50%;
  color: var(--warm-white);
  background: var(--coral);
  font-size: 14px;
  letter-spacing: 0;
}

.step-beads {
  display: flex;
  height: 34px;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 999px;
  background: linear-gradient(#f4f8f8, #8d9da2 48%, #65777c);
}

.step-beads i {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: url("assets/deluxe/bead-coral.webp") center / contain no-repeat;
}

.step-beads i.ivory {
  background-image: url("assets/deluxe/bead-ivory.webp");
}

.step-beads.before {
  justify-content: flex-end;
}

.step-beads.after {
  justify-content: space-between;
}

.step-group {
  display: flex;
  gap: 2px;
}

.step-check {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto;
  object-fit: contain;
}

.mini-step p {
  margin: 8px 0 0;
  color: #5f574c;
  font-size: 14px;
  line-height: 1.25;
}

.narrator-tools {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.narrator-tools button {
  min-height: 48px;
  padding: 7px 17px;
  border: 1px solid rgba(23, 74, 126, 0.28);
  border-radius: 999px;
  color: var(--ink);
  background: var(--warm-white);
  font-weight: 600;
  cursor: pointer;
}

.reward-dialog {
  width: min(92vw, 560px);
}

.reward-panel {
  padding-top: 98px;
  text-align: center;
}

.reward-burst {
  position: absolute;
  top: -48px;
  left: 50%;
  width: 164px;
  height: 164px;
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(0 7px 7px rgba(57, 73, 47, 0.2));
}

.reward-panel p {
  margin: 12px auto 0;
  color: #5f584e;
}

.reward-prop {
  display: block;
  width: 92px;
  height: 92px;
  margin: 13px auto 0;
  object-fit: contain;
  color: var(--ink);
}

.next-level {
  min-width: 190px;
  font-size: 23px;
}

.finale-dialog {
  width: min(92vw, 640px);
}

.finale-content {
  position: relative;
  padding: clamp(80px, 12vw, 116px) clamp(22px, 5vw, 46px) 34px;
  overflow: hidden;
  border: 1px solid rgba(184, 162, 128, 0.56);
  border-radius: 30px;
  background: linear-gradient(155deg, var(--warm-white), #e4f4f7);
  box-shadow: 0 26px 72px rgba(12, 47, 64, 0.34);
  text-align: center;
}

.finale-stars {
  position: absolute;
  top: -35px;
  left: 50%;
  width: 190px;
  transform: translateX(-50%);
}

.finale-content p {
  max-width: 45ch;
  margin: 14px auto 0;
  color: #5f574c;
  font-size: 19px;
}

.finale-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin-top: 22px;
}

.exit-link {
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  padding: 10px 22px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.72);
  font-weight: 600;
  text-decoration: none;
}

.finale-buttons > :is(button, a) {
  margin-top: 0;
}

@keyframes star-pop {
  0% { opacity: 0; transform: scale(0.3) rotate(-18deg); }
  65% { opacity: 1; transform: scale(1.2) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes board-success {
  0%, 100% { filter: drop-shadow(0 12px 12px rgba(30, 66, 74, 0.18)); }
  48% {
    filter:
      drop-shadow(0 12px 12px rgba(30, 66, 74, 0.18))
      drop-shadow(0 0 9px rgba(255, 211, 106, 0.9));
  }
}

@keyframes board-retry {
  0%, 100% { filter: drop-shadow(0 12px 12px rgba(30, 66, 74, 0.18)); }
  50% {
    filter:
      drop-shadow(0 12px 12px rgba(30, 66, 74, 0.18))
      drop-shadow(0 0 7px rgba(216, 145, 52, 0.52));
  }
}

@keyframes dialog-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (min-width: 901px) and (orientation: landscape) {
  .step-beads.before > i {
    flex-basis: min(5.2%, 18px);
    width: min(5.2%, 18px);
    height: auto;
    align-self: center;
    aspect-ratio: 1;
  }

  .step-beads.after > .step-group {
    flex: 0 0 min(35%, 100px);
  }

  .step-beads.after .step-group i {
    flex: 1 1 0;
    width: auto;
    height: auto;
    align-self: center;
    aspect-ratio: 1;
  }
}

@media (max-width: 900px), (orientation: portrait) {
  .challenge-copy {
    padding: 18px;
  }

  .bay-work {
    min-height: 0;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .sopo-guide {
    position: relative;
    bottom: auto;
    left: auto;
    width: clamp(128px, 24vw, 180px);
    margin: -4px auto -8px;
  }

  .sopo-frame img {
    width: auto;
    max-width: 100%;
    height: clamp(132px, 20vh, 180px);
    margin: auto;
    aspect-ratio: auto;
  }

  .board-wrap {
    width: 100%;
    margin: 0;
    padding: 4px 0 0;
  }

  .wood-board {
    aspect-ratio: 1.65 / 1;
  }

  .bead-row[data-row="top"] {
    top: 4%;
    height: 44%;
  }

  .bead-row[data-row="bottom"] {
    top: 52%;
    height: 44%;
  }

  .board-footer {
    min-height: 92px;
    padding: 8px;
  }

  .mini-steps {
    grid-template-columns: 1fr;
  }
}

@media (orientation: portrait) {
  .intro-dialog {
    background:
      linear-gradient(180deg, rgba(255, 250, 240, 0.1), rgba(18, 78, 111, 0.12)),
      var(--intro-tall, url("assets/intro-tall.webp")) center / cover no-repeat;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 16px;
  }

  .app {
    padding: 7px 8px max(10px, env(safe-area-inset-bottom));
  }

  .topbar {
    flex-direction: column-reverse;
    gap: 2px;
  }

  .brand-title {
    font-size: clamp(22px, 7vw, 26px);
  }

  .game-controls {
    gap: 3px;
  }

  .wood-control {
    width: 56px;
    height: 56px;
    min-width: 56px;
  }

  .game-main {
    margin-top: 2px;
  }

  .challenge-copy {
    margin-top: 4px;
    padding: 12px;
    border-width: 10px;
    border-image-width: 10px;
  }

  .level-line {
    font-size: 16px;
  }

  .challenge-copy h1 {
    margin-top: 6px;
    font-size: clamp(32px, 9vw, 36px);
  }

  .challenge-copy h1 output {
    font-size: 48px;
  }

  .task-progress {
    gap: 7px;
    margin-top: 7px;
  }

  .world-marker {
    width: 32px;
    height: 32px;
  }

  .world-marker svg {
    width: 20px;
    height: 20px;
  }

  .star-slot {
    width: 28px;
    height: 28px;
  }

  .sopo-guide {
    width: clamp(128px, 40vw, 154px);
    margin: -4px auto -8px;
  }

  .wood-board {
    min-height: 270px;
    aspect-ratio: 1.65 / 1;
    border-width: 10px;
    border-image-width: 10px;
  }

  .bead-row[data-row="top"] {
    top: 4%;
    height: 44%;
  }

  .bead-row[data-row="bottom"] {
    top: 52%;
    height: 44%;
  }

  .rod {
    min-height: 36px;
    margin: 0 3px;
  }

  .rod::before {
    right: -3px;
    left: -3px;
    height: 3px;
  }

  .row-slider {
    min-height: 56px;
    padding: 0 1px;
  }

  .board-footer {
    min-height: 92px;
    gap: 8px;
    padding: 8px 4px;
  }

  .live-count {
    gap: 6px;
    padding: 7px 11px;
  }

  .live-count span {
    font-size: 18px;
  }

  .live-count output {
    font-size: 36px;
  }

  .okay-button {
    --okay-art-size: 76px;
    min-width: 72px;
  }

  .comparison {
    margin-top: 4px;
    padding: 10px 12px 12px;
  }

  .comparison > p {
    font-size: 16px;
  }

  .comparison-line {
    grid-template-columns: 58px minmax(0, 1fr) 32px;
    gap: 6px;
    font-size: 16px;
  }

  .comparison-line > strong {
    font-size: 20px;
  }

  .demo-caption {
    max-width: 100%;
    padding: 8px 12px 9px;
    font-size: 16px;
  }

  .skip-demo {
    min-height: 48px;
    padding: 7px 12px;
    font-size: 16px;
  }

  .tutorial-hand {
    width: 70px;
  }

  .framed-title {
    padding: 11px 15px;
  }

  .framed-title h1 {
    font-size: clamp(25px, 8vw, 36px);
  }

  .framed-title p {
    margin-top: 5px;
    font-size: 15px;
  }

  .play-art {
    width: 108px;
  }

  .level-menu {
    grid-template-columns: repeat(3, 1fr);
  }

  .pause-panel {
    grid-template-columns: 100px minmax(0, 1fr);
    gap: 14px 16px;
    padding: 20px 16px;
    border-width: 12px;
    border-image-width: 12px;
  }

  .pause-sopo {
    width: 100px;
    height: 100px;
  }

  .dialog-panel,
  .reward-panel {
    padding: 22px 18px;
    border-radius: 23px;
  }

  .reward-panel {
    padding-top: 98px;
  }

  .mini-step {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    text-align: left;
  }

  .step-number {
    grid-row: 1 / span 2;
    margin: 0;
  }

  .step-diagram,
  .step-check {
    grid-column: 2;
    margin: 0;
  }

  .mini-step p {
    grid-column: 2;
    margin: 4px 0 0;
  }

  .step-beads.before > i {
    flex-basis: min(9%, 18px);
    width: min(9%, 18px);
    height: auto;
    aspect-ratio: 1;
  }

  .narrator-tools {
    flex-wrap: wrap;
  }

  .narrator-tools button {
    min-height: 48px;
    flex: 1 1 130px;
  }

  .finale-content p {
    font-size: 17px;
  }
}

@media (orientation: portrait) and (max-height: 700px) {
  .sopo-frame img {
    height: clamp(116px, 18vh, 132px);
  }
}

@media (min-width: 521px) and (max-width: 900px) and (orientation: portrait) {
  .challenge-copy {
    padding: 10px;
    border-width: 12px;
    border-image-width: 12px;
  }

  .challenge-copy h1 output {
    font-size: 54px;
  }

  .sopo-guide {
    width: max-content;
    max-width: 100%;
  }

  .sopo-frame img {
    width: auto;
    height: clamp(120px, 18vw, 150px);
    object-fit: contain;
  }

  .wood-board {
    min-height: 270px;
    aspect-ratio: 2.1 / 1;
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  .app {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .topbar {
    min-height: 52px;
  }

  .brand-title {
    font-size: 22px;
  }

  .game-main {
    position: relative;
    margin-top: 0;
    padding-top: 0;
  }

  .challenge-copy {
    width: min(100%, 650px);
    min-height: 0;
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    align-content: center;
    justify-content: center;
    column-gap: 12px;
    row-gap: 2px;
    margin: 4px auto 0;
    padding: 10px 14px;
  }

  .level-line {
    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;
  }

  .challenge-copy h1 {
    grid-column: 1;
    margin: 0;
    font-size: 32px;
  }

  .challenge-copy h1 output {
    font-size: 48px;
  }

  .task-progress {
    grid-column: 2;
    margin-top: 0;
  }

  .tutorial-layer {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .bay-work {
    display: block;
    min-height: 0;
    margin-top: 0;
  }

  .sopo-guide {
    position: absolute;
    bottom: 0;
    left: 0;
    width: clamp(126px, 17vw, 150px);
    margin: 0;
  }

  .board-wrap {
    width: calc(100% - 180px);
    margin: 0 0 0 auto;
    padding-top: 0;
  }

  .wood-board {
    aspect-ratio: 2.5 / 1;
    min-height: 280px;
  }

  .bead-row[data-row="top"] {
    top: 4%;
    height: 44%;
  }

  .bead-row[data-row="bottom"] {
    top: 52%;
    height: 44%;
  }

  .rod {
    min-height: 36px;
  }

  .board-footer {
    min-height: 98px;
    padding: 8px 4px;
  }

  .okay-button {
    --okay-art-size: 72px;
  }

}

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

  .bead.dragging .bead-body {
    transform: none;
  }
}
