* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}
body {
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  color: #30433e;
  background: #faf6ed;
}
button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}
button,
select,
.home {
  min-height: 48px;
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: #30433e;
  font: inherit;
  font-weight: 750;
  padding: 10px 16px;
  box-shadow: 0 3px 0 #dfded4;
  cursor: pointer;
}
button:active {
  transform: translateY(2px);
  box-shadow: none;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 4px solid #e99038;
  outline-offset: 4px;
}
.primary {
  background: #39766c;
  color: #fff;
  box-shadow: 0 4px 0 #28594f;
}
.shell {
  max-width: 1440px;
  margin: 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));
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}
.home {
  text-decoration: none;
  display: grid;
  place-items: center;
  width: 50px;
  padding: 8px;
}
.brand {
  flex: 1;
}
.brand small {
  display: block;
  font-size: 10px;
  letter-spacing: 2px;
  color: #73847b;
  margin-bottom: 2px;
}
.brand h1 {
  font-size: clamp(18px, 2.5vw, 26px);
  margin: 0;
}
.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}
.scene-name {
  font-weight: 800;
  min-width: 120px;
  text-align: center;
}
.arrow {
  font-size: 25px;
  width: 50px;
  padding: 5px;
}
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  gap: 18px;
  align-items: center;
}
.stage {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 10px 36px #30433e12;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage img {
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.scene-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}
.board {
  position: relative;
  aspect-ratio: 4/3;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-title {
  font-size: 12px;
  letter-spacing: 1px;
  color: #76867e;
  text-align: center;
}
.question {
  font-size: clamp(19px, 3vw, 30px);
  font-weight: 800;
  text-align: center;
  margin: 8px 0 18px;
  min-height: 40px;
}
.question[lang="en"] {
  color: #355e56;
}
.start-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
  background: #f9f5e7d9;
  backdrop-filter: blur(5px);
}
.start-layer p {
  margin: 0;
  font-size: clamp(20px, 4vw, 32px);
  font-weight: 800;
}
.start-layer button {
  font-size: 23px;
  padding: 18px 30px;
}
.hidden,
[hidden] {
  display: none !important;
}
.status {
  min-height: 28px;
  text-align: center;
  font-size: 16px;
  font-weight: 650;
  color: #39766c;
  margin: 14px 0 2px;
}
.sound {
  width: 50px;
  padding: 8px;
  font-size: 20px;
}
.footer-note {
  font-size: 12px;
  color: #7d8981;
  text-align: center;
  margin: 12px 0;
}
.speed {
  display: flex;
  padding: 4px;
  background: #e8ede5;
  border-radius: 20px;
  gap: 3px;
}
.speed button {
  box-shadow: none;
  background: transparent;
  padding: 9px 13px;
}
.speed button[aria-pressed="true"] {
  background: #39766c;
  color: white;
}
.target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 70px;
}
.target img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}
.target strong {
  font-size: 28px;
}
.target span {
  font-size: 17px;
  color: #6d8177;
}
.replay {
  font-size: 21px;
}
.item {
  position: absolute;
  border: 0;
  background: none;
  box-shadow: none;
  padding: 0;
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
}
.item:active {
  transform: translate(-50%, -50%);
  box-shadow: none;
}
.item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.item.found {
  filter: drop-shadow(0 0 9px #ffdb73);
  outline: 4px solid #ffdb73;
  border-radius: 25%;
}
.numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.numbers button {
  font-size: 30px;
  border-radius: 20px;
  aspect-ratio: 1;
  min-width: 0;
  padding: 4px;
  background: #fffdf7;
}
.numbers .correct {
  background: #39766c;
  color: #fff;
}
.number-sidebar {
  width: 210px;
}
.count-workspace {
  grid-template-columns: minmax(0, 1fr) 210px;
}
.actor {
  position: absolute;
  pointer-events: none;
  will-change: transform;
}
.actor img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #30433e80;
  display: grid;
  place-items: center;
  padding: 18px;
}
.dialog-card {
  background: #fffaf0;
  border-radius: 30px;
  padding: 24px;
  max-width: 520px;
  max-height: 94dvh;
  overflow: auto;
  text-align: center;
  width: 100%;
}
.dialog-card h2 {
  margin: 0 0 12px;
}
.dialog-card img {
  max-width: 100%;
  max-height: 50dvh;
  object-fit: contain;
  border-radius: 14px;
  touch-action: auto;
  -webkit-touch-callout: default;
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}
.dialog-card p {
  font-size: 14px;
  color: #61746a;
}
@media (max-width: 700px) {
  .shell {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .topbar {
    gap: 7px;
  }
  .brand small {
    font-size: 8px;
    letter-spacing: 1px;
  }
  .topbar button {
    padding: 8px 11px;
  }
  .workspace {
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) 62px;
  }
  .count-workspace {
    grid-template-columns: 1fr;
  }
  .number-sidebar {
    width: 100%;
  }
  .numbers {
    grid-template-columns: repeat(9, 1fr);
    gap: 5px;
  }
  .numbers button {
    font-size: 24px;
    min-height: 46px;
    border-radius: 13px;
  }
  .question {
    margin: 8px 0 12px;
  }
  .stage {
    border-radius: 20px;
  }
  .toolbar {
    gap: 6px;
    margin: 12px 0;
  }
  .sidebar-title {
    font-size: 10px;
  }
  .speed button {
    font-size: 13px;
    padding: 9px;
  }
  .target strong {
    font-size: 23px;
  }
  .footer-note {
    margin: 8px 0;
  }
  .board {
    aspect-ratio: 1/1;
  }
  .finding-stage .board {
    aspect-ratio: 4/3;
  }
  .item {
    min-height: 44px;
    min-width: 44px;
  }
}
@media (max-height: 540px) and (orientation: landscape) {
  .shell {
    max-width: 1100px;
  }
  .topbar {
    min-height: 42px;
  }
  .topbar button,
  .home {
    min-height: 42px;
  }
  .brand small {
    display: none;
  }
  .toolbar {
    margin: 6px 0;
  }
  .question {
    font-size: 19px;
    margin: 4px 0;
    min-height: 25px;
  }
  .workspace {
    max-width: 850px;
    margin: auto;
  }
  .board {
    height: calc(100dvh - 180px);
    aspect-ratio: 4/3;
    width: auto;
  }
  .stage {
    width: 100%;
    max-width: calc((100dvh - 180px) * 1.3333);
    margin: auto;
  }
  .status {
    margin: 6px 0;
  }
  .target {
    min-height: 44px;
  }
  .target img {
    width: 42px;
    height: 42px;
  }
  .footer-note {
    display: none;
  }
  .count-workspace {
    grid-template-columns: minmax(0, 1fr) 190px;
  }
  .numbers {
    grid-template-columns: repeat(3, 1fr);
  }
  .number-sidebar {
    width: 190px;
  }
  .numbers button {
    min-height: 44px;
    font-size: 24px;
  }
  .start-layer button {
    padding: 12px 24px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
.sand-stage {
  max-width: min(75dvh, 800px);
  margin: auto;
  width: 100%;
}
#painting {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}
.palette {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.swatch {
  width: 50px;
  height: 50px;
  min-height: 50px;
  border: 4px solid white;
  border-radius: 50%;
  padding: 0;
  box-shadow: 0 2px 6px #0002;
}
.swatch[aria-pressed="true"] {
  outline: 3px solid #30433e;
  outline-offset: 3px;
}
.keyboard-help {
  font-size: 12px;
  color: #7d8981;
  margin: auto;
  max-width: 800px;
}
.sand-workspace {
  max-width: 960px;
  margin: auto;
}
@media (max-width: 700px) {
  .palette {
    grid-template-columns: 1fr;
    gap: 9px;
  }
  .swatch {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .sidebar {
    align-items: center;
  }
  .sand-workspace {
    align-items: start;
  }
  .sand-stage {
    margin-top: 16px;
  }
}
@media (max-height: 540px) and (orientation: landscape) {
  .sand-stage {
    max-width: calc(100dvh - 150px);
  }
  .sand-workspace {
    grid-template-columns: minmax(0, 1fr) 126px;
    max-width: 650px;
  }
  .palette {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .swatch {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }
  .keyboard-help {
    display: none;
  }
}
.count-workspace {
  max-width: min(1100px, calc(133.333dvh - 92px));
  margin: auto;
}
.finding-stage {
  max-width: min(1100px, calc(133.333dvh - 293px));
  margin: auto;
}
@media (max-width: 700px) {
  .count-workspace,
  .finding-stage {
    max-width: 100%;
  }
  .numbers {
    grid-template-columns: repeat(3, 1fr);
    max-width: 240px;
    width: 100%;
    margin: auto;
    gap: 7px;
  }
  .numbers button {
    aspect-ratio: auto;
    min-height: 48px;
  }
  .board {
    aspect-ratio: 4/3;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .finding .toolbar {
    position: absolute;
    top: 62px;
    left: 22px;
    width: 172px;
    gap: 4px;
  }
  .finding .scene-name {
    min-width: 64px;
    max-width: 72px;
    font-size: 14px;
  }
  .finding .arrow {
    width: 44px;
  }
  .finding .target {
    position: absolute;
    left: 26px;
    top: 137px;
    width: 160px;
    flex-wrap: wrap;
    text-align: center;
    gap: 8px;
  }
  .finding .target img {
    width: 58px;
    height: 58px;
  }
  .finding .target strong {
    font-size: 22px;
  }
  .finding .target .replay {
    min-height: 44px;
  }
  .finding .finding-stage {
    width: calc((100dvh - 100px) * 1.3333);
    max-width: calc(100vw - 220px);
    margin: 10px auto 0;
    transform: translateX(75px);
  }
  .finding .board {
    height: auto;
    width: 100%;
    aspect-ratio: 4/3;
  }
  .finding .status {
    margin-left: 150px;
  }
  .sand .swatch {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

.sand-stage { aspect-ratio: 1; }
#painting { position: absolute; inset: 0; transform-origin: 0 0; }
.view-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 10px auto; }
.view-tools button { min-width: 44px; min-height: 44px; padding: 8px 12px; }
.view-tools input { width: clamp(70px, 18vw, 160px); height: 44px; accent-color: #39766c; }
.view-tools input:focus-visible { outline: 3px solid #e99038; outline-offset: 3px; }
.view-tools output { width: 48px; font-size: 13px; text-align: center; }
#pan[aria-pressed="true"] { background: #39766c; color: white; }
.panning #painting { cursor: grab; }
.panning #painting:active { cursor: grabbing; }
@media (max-width: 380px) { .view-tools { gap: 4px; } .view-tools button { padding: 8px; } }
@media (max-height: 540px) and (orientation: landscape) { .sand-stage { max-width: calc(100dvh - 205px); } .view-tools { margin: 4px auto; } }
@media (max-width: 700px) {
  .view-tools { gap: 4px; }
  .view-tools button { padding: 8px; font-size: 14px; }
  .view-tools output { width: 40px; }
  .view-tools input { width: 70px; }
  #pan { width: 72px; }
}
@media (max-width: 360px) { .view-tools output { display: none; } }
