:root {
  --ink: #211843;
  --ink-soft: #51466f;
  --line: #261d4b;
  --purple: #7047eb;
  --purple-dark: #4a2bb2;
  --pink: #ff4f91;
  --yellow: #ffc83d;
  --cyan: #3dd9eb;
  --green: #49d17d;
  --red: #ff6969;
  --cream: #fff8df;
  --white: #fff;
  --shadow: rgba(33, 24, 67, .20);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --board-size: 460px;
  --piece-size: 153px;
  --tray-piece-size: 92px;
  --game-gap: 14px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
html { background: #8be6ef; overscroll-behavior: none; }
body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background: #8be6ef;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Avenir Next Rounded", "Trebuchet MS", system-ui, sans-serif;
  font-weight: 800;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
button, input, label { font: inherit; }
button { border: 0; color: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, label:focus-within, [role="button"]:focus-visible {
  outline: 5px solid #fff;
  outline-offset: 4px;
}
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

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

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 10% 12%, rgba(255,255,255,.76) 0 4.5%, transparent 4.7%),
    radial-gradient(circle at 88% 14%, rgba(255,255,255,.48) 0 7%, transparent 7.2%),
    linear-gradient(145deg, #8be6ef 0%, #b1f0d5 44%, #ffd6e9 100%);
}

.view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.view.is-active { animation: screen-in .24s cubic-bezier(.2,.9,.2,1) both; }

@keyframes screen-in {
  from { opacity: 0; transform: scale(.988); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes pop-in {
  0% { opacity: 0; transform: translateY(18px) scale(.94); }
  70% { opacity: 1; transform: translateY(-2px) scale(1.01); }
  100% { opacity: 1; transform: none; }
}
@keyframes coach {
  0%, 12% { transform: translateX(0); opacity: 1; }
  70% { transform: translateX(44px); opacity: 1; }
  100% { transform: translateX(44px); opacity: 0; }
}
@keyframes wrong {
  0%,100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  70% { transform: translateX(6px); }
}
@keyframes correct {
  0% { transform: scale(.92); }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.pop-in { animation: pop-in .42s cubic-bezier(.2,.9,.25,1.12) both; }

/* Shared controls */
.game-button {
  position: relative;
  border: 4px solid var(--line);
  border-radius: 25px;
  cursor: pointer;
  box-shadow: 0 8px 0 var(--button-shadow, rgba(38,29,75,.32));
  transform: translateY(0);
  transition: transform .08s ease, box-shadow .08s ease, filter .14s ease;
}
.game-button:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 var(--button-shadow, rgba(38,29,75,.32));
}
.game-button:hover { filter: brightness(1.025); }

.icon-button {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: white;
  border: 4px solid var(--line);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 0 rgba(38,29,75,.22);
  cursor: pointer;
}
.icon-button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(38,29,75,.22); }
.icon-button img { width: 31px; height: 31px; }
.icon-button--light { background: #fff9ef; }

.text-button {
  min-width: 78px;
  min-height: 48px;
  padding: 0 12px;
  background: rgba(255,255,255,.9);
  border: 3px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(38,29,75,.18);
}
.text-button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(38,29,75,.18); }

.primary-button, .secondary-button {
  min-height: 64px;
  padding: 12px 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: clamp(18px, 2vw, 24px);
}
.primary-button { background: var(--purple); color: #fff; --button-shadow: var(--purple-dark); }
.secondary-button { background: var(--yellow); color: var(--ink); --button-shadow: #bd7d11; }
.primary-button img, .secondary-button img { width: 34px; height: 34px; }

.screen-header {
  width: min(100%, 1100px);
  margin: 0 auto;
  min-height: 70px;
  display: grid;
  grid-template-columns: 86px 1fr 86px;
  align-items: center;
  gap: 12px;
}
.screen-heading { text-align: center; }
.screen-heading h2 { margin: 2px 0 0; font-size: clamp(26px, 3.4vw, 42px); line-height: 1; }
.screen-step { color: var(--purple-dark); font-size: 12px; letter-spacing: .15em; }
.section-kicker { margin: 0 0 14px; color: var(--ink-soft); font-size: 18px; text-align: center; }

/* Home */
.view-home {
  display: grid;
  place-items: center;
  overflow: auto;
}
.home-content {
  position: relative;
  z-index: 2;
  width: min(900px, 94vw);
  display: grid;
  gap: clamp(22px, 4vh, 38px);
}
.brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2vw, 24px);
}
.brand-mark {
  width: clamp(84px, 13vw, 126px);
  filter: drop-shadow(0 8px 0 rgba(33,24,67,.13));
}
.brand-title {
  margin: 0;
  font-size: clamp(42px, 7vw, 76px);
  line-height: .92;
  letter-spacing: -.055em;
  color: var(--pink);
  -webkit-text-stroke: clamp(2px, .35vw, 4px) var(--line);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 rgba(255,255,255,.72);
}
.brand-subtitle {
  margin: 12px 0 0;
  color: var(--purple-dark);
  font-size: clamp(16px, 2.2vw, 24px);
}
.home-actions {
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  gap: clamp(14px, 2vw, 22px);
}
.hero-action {
  min-height: clamp(126px, 18vh, 168px);
  padding: clamp(16px, 2.3vw, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 2.6vw, 28px);
  text-align: left;
  color: var(--ink);
}
.hero-action--camera { background: var(--yellow); --button-shadow: #b9780e; }
.hero-action--gallery { background: #aeeef5; --button-shadow: #3b95a5; }
.hero-action__icon {
  width: clamp(70px, 9vw, 100px);
  height: clamp(70px, 9vw, 100px);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 4px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.78);
}
.hero-action__icon img { width: 68%; height: 68%; }
.hero-action__copy strong { display: block; font-size: clamp(21px, 3vw, 34px); line-height: 1; }
.hero-action__copy small { display: block; margin-top: 9px; color: #463b68; font-size: clamp(14px, 1.7vw, 18px); }
.privacy-chip {
  justify-self: center;
  margin: -8px 0 0;
  padding: 8px 14px;
  border: 2px solid rgba(38,29,75,.14);
  border-radius: 999px;
  background: rgba(255,255,255,.62);
  color: #433865;
  font-size: clamp(12px, 1.5vw, 15px);
}
.privacy-chip span { color: #178c4b; margin-right: 6px; }
.bubble {
  position: absolute;
  width: 170px;
  height: 170px;
  border: 7px solid rgba(38,29,75,.11);
  border-radius: 38% 62% 56% 44% / 46% 38% 62% 54%;
  background: rgba(255,255,255,.18);
  pointer-events: none;
}
.bubble--one { top: -42px; left: -42px; transform: rotate(20deg); }
.bubble--two { right: -52px; bottom: -52px; transform: rotate(-19deg); }

/* Camera */
.view-camera { padding: 0; background: #090713; overflow: hidden; }
.camera-feed { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #111; }
.camera-vignette {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.34), transparent 28%, transparent 65%, rgba(0,0,0,.62));
  pointer-events: none;
}
.camera-frame {
  position: absolute;
  left: 50%; top: 48%;
  width: min(72vw, 64vh, 600px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 5px solid rgba(255,255,255,.92);
  border-radius: 30px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.10);
  pointer-events: none;
}
.camera-frame span::before,
.camera-frame span::after {
  content: "";
  position: absolute;
  width: 68px; height: 68px;
  border-color: var(--yellow);
  border-style: solid;
}
.camera-frame span::before { left: -6px; top: -6px; border-width: 8px 0 0 8px; border-radius: 28px 0 0 0; }
.camera-frame span::after { right: -6px; bottom: -6px; border-width: 0 8px 8px 0; border-radius: 0 0 28px 0; }
.camera-status {
  position: absolute;
  top: calc(18px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: 76vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(10,8,24,.72);
  color: white;
  font-size: clamp(14px, 1.8vw, 18px);
  text-align: center;
  backdrop-filter: blur(8px);
}
.camera-controls {
  position: absolute;
  left: 50%; bottom: calc(22px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(520px, 88vw);
  display: grid;
  grid-template-columns: 70px 1fr 70px;
  align-items: center;
}
.camera-side-button {
  width: 64px; height: 64px;
  border: 4px solid white;
  border-radius: 21px;
  background: rgba(23,18,50,.76);
  display: grid;
  place-items: center;
  justify-self: center;
  cursor: pointer;
}
.camera-side-button img { width: 35px; height: 35px; }
.shutter-button {
  justify-self: center;
  width: 94px; height: 94px;
  padding: 0;
  border: 7px solid white;
  border-radius: 50%;
  background: rgba(255,255,255,.20);
  box-shadow: 0 4px 22px rgba(0,0,0,.38);
  cursor: pointer;
}
.shutter-button span { display: block; width: 65px; height: 65px; margin: auto; border-radius: 50%; background: var(--yellow); border: 4px solid var(--line); }
.shutter-button:active span { transform: scale(.88); }

/* Crop / setup */
.view-crop {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.crop-layout {
  flex: 1;
  min-height: 0;
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, .8fr);
  gap: clamp(16px, 2.5vw, 30px);
  align-items: center;
}
.crop-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 11px;
}
.crop-viewport {
  position: relative;
  width: min(64vh, 60vw, 590px);
  max-width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 6px solid var(--line);
  border-radius: 30px;
  background: #dfe4ea;
  box-shadow: 0 13px 0 rgba(38,29,75,.17), inset 0 0 0 4px rgba(255,255,255,.7);
  touch-action: none;
  cursor: grab;
}
.crop-viewport:active { cursor: grabbing; }
.crop-image {
  position: absolute;
  left: 50%; top: 50%;
  max-width: none;
  transform: translate(-50%, -50%);
  transform-origin: center;
  pointer-events: none;
  will-change: width, height, left, top;
}
.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent 33.1%, rgba(255,255,255,.55) 33.2% 33.6%, transparent 33.7% 66.3%, rgba(255,255,255,.55) 66.4% 66.8%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.1%, rgba(255,255,255,.55) 33.2% 33.6%, transparent 33.7% 66.3%, rgba(255,255,255,.55) 66.4% 66.8%, transparent 66.9%);
  mix-blend-mode: screen;
  opacity: .78;
}
.crop-corners { position: absolute; inset: 14px; border: 3px solid rgba(255,255,255,.8); border-radius: 20px; pointer-events: none; }
.crop-help {
  margin: 4px 0 0;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  color: #40365f;
  font-size: clamp(12px, 1.6vw, 16px);
  text-align: center;
}
.setup-panel {
  align-self: center;
  min-height: 340px;
  padding: clamp(16px, 2vw, 22px);
  border: 5px solid var(--line);
  border-radius: 30px;
  background: rgba(255,255,255,.88);
  box-shadow: 0 11px 0 rgba(38,29,75,.15);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
}
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.difficulty-button {
  min-width: 0;
  padding: 12px 7px 10px;
  border: 4px solid var(--line);
  border-radius: 19px;
  background: #f5f1ff;
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(38,29,75,.17);
  cursor: pointer;
}
.difficulty-button.is-selected {
  background: var(--yellow);
  box-shadow: 0 5px 0 #b9780e, inset 0 0 0 3px white;
  transform: translateY(-2px);
}
.difficulty-button strong { display: block; margin-top: 8px; font-size: 25px; line-height: 1; }
.difficulty-button small { display: block; margin-top: 5px; font-size: 9px; letter-spacing: .08em; color: #4f456e; }
.mini-grid {
  width: 48px; height: 48px;
  margin: auto;
  display: grid;
  gap: 3px;
}
.mini-grid i { display: block; border: 2px solid var(--line); border-radius: 4px; background: white; }
.mini-grid--2 { grid-template-columns: repeat(2, 1fr); }
.mini-grid--3 { grid-template-columns: repeat(3, 1fr); }
.mini-grid--4 { grid-template-columns: repeat(4, 1fr); gap: 2px; }
.start-button { width: 100%; min-height: 78px; font-size: 28px; }
.setup-actions { display: grid; gap: 13px; }
.decorate-button {
  width: 100%;
  min-height: 62px;
  padding: 10px 18px;
  font-size: clamp(18px, 2vw, 22px);
}
.decorate-button > span:first-child { color: var(--purple); font-size: 28px; line-height: 1; }

/* Game */
.view-game { padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left)); overflow: hidden; background: linear-gradient(145deg, #9cecf4, #d2f4df 52%, #ffe1ee); }
.game-toolbar {
  width: min(100%, 1180px);
  height: 74px;
  margin: 0 auto 8px;
  display: grid;
  grid-template-columns: 64px 1fr 72px;
  align-items: center;
  gap: 12px;
}
.game-progress { width: min(520px, 100%); justify-self: center; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.game-progress-label { font-size: clamp(14px, 1.6vw, 18px); color: #453b65; }
.progress-text { font-size: 17px; color: var(--ink); }
.progress-track { grid-column: 1 / -1; height: 15px; overflow: hidden; border: 3px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.88); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .22s ease; }
.reference-button {
  position: relative;
  width: 67px; height: 67px;
  padding: 4px;
  border: 4px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: 0 5px 0 rgba(38,29,75,.18);
  overflow: hidden;
  cursor: pointer;
}
.reference-button > img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.reference-icon { position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; display: grid; place-items: center; border: 3px solid var(--line); border-radius: 10px; background: var(--yellow); }
.reference-icon img { width: 18px; height: 18px; }
.reference-button.is-hinting { transform: translateY(3px); box-shadow: 0 2px 0 rgba(38,29,75,.18); }

.game-stage {
  height: calc(100% - 82px);
  width: min(1280px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto minmax(110px, 1fr);
  gap: var(--game-gap);
  align-items: stretch;
  min-height: 0;
}
.board-zone { min-width: 0; min-height: 0; display: grid; place-items: center; align-content: center; gap: 7px; }
.puzzle-board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  overflow: hidden;
  border: 6px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.62);
  box-shadow: 0 10px 0 rgba(38,29,75,.15), inset 0 0 0 3px rgba(255,255,255,.75);
}
.board-bg-hint {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  opacity: var(--hint-opacity, .14);
  transition: opacity .16s ease;
  pointer-events: none;
}
.board-bg-hint.is-strong { opacity: .58; }
.slots-container { position: absolute; inset: 0; z-index: 2; display: grid; }
.puzzle-slot {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1.5px dashed rgba(38,29,75,.24);
  background: rgba(255,255,255,.025);
  transition: background .1s ease, box-shadow .1s ease;
}
.puzzle-slot.is-target { background: rgba(255,200,61,.34); box-shadow: inset 0 0 0 5px var(--yellow); }
.puzzle-slot.is-wrong { animation: wrong .18s ease 1; box-shadow: inset 0 0 0 5px var(--red); }
.puzzle-slot.is-correct { border-color: transparent; }

.pieces-tray {
  min-width: 0;
  min-height: 0;
  padding: 9px;
  border: 4px solid rgba(38,29,75,.48);
  border-radius: 24px;
  background: rgba(255,255,255,.46);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.5);
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 9px;
  overflow: hidden;
}
.puzzle-piece {
  width: var(--tray-piece-size);
  height: var(--tray-piece-size);
  flex: 0 0 auto;
  border: 4px solid white;
  border-radius: 14px;
  background-repeat: no-repeat;
  box-shadow: 0 5px 0 rgba(38,29,75,.20), 0 7px 12px rgba(38,29,75,.12);
  cursor: grab;
  touch-action: none;
  transition: transform .08s ease, box-shadow .08s ease;
}
.puzzle-piece:active { cursor: grabbing; }
.puzzle-piece.is-selected { outline: 6px solid var(--yellow); outline-offset: 2px; transform: scale(1.04); }
.puzzle-slot > .puzzle-piece { width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; }
.puzzle-piece.is-correct { pointer-events: none; animation: correct .22s ease; }
.puzzle-piece.is-dragging {
  position: fixed;
  z-index: 9999;
  width: var(--piece-size);
  height: var(--piece-size);
  border: 5px solid white;
  border-radius: 16px;
  box-shadow: 0 16px 28px rgba(33,24,67,.34);
  transform: rotate(-2deg) scale(1.04);
  pointer-events: none;
}

.gesture-coach {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #493f68;
  font-size: 13px;
  transition: opacity .2s ease;
}
.gesture-coach.is-hidden { opacity: 0; pointer-events: none; }
.coach-piece, .coach-slot { width: 24px; height: 24px; border: 3px solid var(--line); border-radius: 7px; background: var(--yellow); }
.coach-slot { background: rgba(255,255,255,.78); }
.coach-piece { animation: coach 1.7s ease-in-out 2 .5s; }
.coach-arrow { font-size: 22px; }

/* Win */
.view-win { display: grid; place-items: center; background: rgba(255,248,223,.90); backdrop-filter: blur(10px); overflow: auto; }
#confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-card {
  position: relative;
  z-index: 2;
  width: min(540px, 92vw);
  padding: clamp(18px, 3vw, 28px);
  border: 6px solid var(--line);
  border-radius: 34px;
  background: #fff;
  box-shadow: 0 13px 0 rgba(38,29,75,.17);
  text-align: center;
}
.win-trophy { width: clamp(80px, 14vw, 118px); margin: -8px auto 4px; }
.win-kicker { display: block; color: var(--purple-dark); font-size: 13px; letter-spacing: .13em; }
.win-card h2 { margin: 3px 0 13px; color: var(--pink); font-size: clamp(42px, 7vw, 68px); line-height: 1; -webkit-text-stroke: 3px var(--line); paint-order: stroke fill; }
.win-image { width: min(300px, 58vw); aspect-ratio: 1; object-fit: cover; margin: 0 auto 20px; border: 5px solid var(--line); border-radius: 22px; box-shadow: 0 7px 0 rgba(38,29,75,.15); }
.win-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast {
  position: fixed;
  z-index: 10000;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(560px, 88vw);
  padding: 13px 18px;
  border: 4px solid var(--line);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 7px 0 rgba(38,29,75,.22);
  text-align: center;
  font-size: 15px;
}

@media (orientation: portrait), (max-aspect-ratio: 9/10) {
  .home-content { width: min(680px, 94vw); }
  .home-actions { grid-template-columns: 1fr; }
  .hero-action { min-height: 122px; }
  .crop-layout { grid-template-columns: 1fr; align-content: start; gap: 12px; overflow: auto; padding-bottom: 10px; }
  .crop-viewport { width: min(56vh, calc(100vw - 34px), 560px); }
  .setup-panel { width: min(680px, 100%); min-height: 0; justify-self: center; padding: 13px; gap: 12px; }
  .difficulty-button { padding: 9px 6px 8px; }
  .mini-grid { width: 38px; height: 38px; }
  .start-button { min-height: 64px; }
  .setup-actions { grid-template-columns: 1.25fr .9fr; }
  .decorate-button { min-height: 64px; }

  .game-stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(96px, 1fr);
    align-content: start;
  }
  .board-zone { grid-column: 1 / -1; grid-row: 1; }
  .pieces-tray--left { grid-column: 1; grid-row: 2; }
  .pieces-tray--right { grid-column: 2; grid-row: 2; }
  .pieces-tray { align-content: center; }
}

@media (max-width: 680px), (max-height: 620px) {
  .view { padding-left: calc(10px + var(--safe-left)); padding-right: calc(10px + var(--safe-right)); }
  .brand-mark { width: 76px; }
  .brand-title { font-size: 40px; }
  /* 14px, а не 6px: інакше біла 3D-тінь заголовка (text-shadow 0 7px) налазить на підзаголовок. */
  .brand-subtitle { margin-top: 14px; font-size: 15px; }
  .hero-action { min-height: 105px; border-radius: 22px; }
  .hero-action__icon { width: 66px; height: 66px; border-radius: 19px; }
  .hero-action__copy strong { font-size: 21px; }
  .hero-action__copy small { font-size: 13px; }
  .privacy-chip { font-size: 11px; }

  .screen-header { grid-template-columns: 64px 1fr 64px; min-height: 60px; }
  .icon-button { width: 52px; height: 52px; }
  .text-button { min-width: 62px; min-height: 44px; font-size: 12px; padding: 0 7px; }
  .screen-heading h2 { font-size: 24px; }
  .screen-step { font-size: 10px; }
  .setup-actions { grid-template-columns: 1fr; gap: 8px; }

  .game-toolbar { height: 62px; grid-template-columns: 56px 1fr 60px; margin-bottom: 5px; }
  .reference-button { width: 57px; height: 57px; }
  .game-stage { height: calc(100% - 67px); }
  .gesture-coach { font-size: 11px; min-height: 28px; }
}

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

button:disabled,
.game-button[aria-busy="true"] {
  cursor: progress;
  opacity: .72;
  filter: grayscale(.08);
}

/* Phaser photo editor */
.view-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  background: linear-gradient(145deg, #b4eef4, #e9dcff 58%, #ffe2ed);
}
.editor-header { flex: 0 0 auto; }
.editor-layout {
  flex: 1;
  min-height: 0;
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(292px, 340px);
  gap: clamp(12px, 2vw, 22px);
}
.editor-stage {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 6px solid var(--line);
  border-radius: 30px;
  background: #e9e4fa;
  box-shadow: 0 10px 0 rgba(38,29,75,.16);
  touch-action: none;
}
.editor-stage canvas,
.game-stage canvas { display: block; width: 100%; height: 100%; }
.editor-panel {
  min-height: 0;
  padding: 14px;
  overflow: auto;
  border: 5px solid var(--line);
  border-radius: 28px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 9px 0 rgba(38,29,75,.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.editor-tool-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.editor-tool {
  min-width: 0;
  min-height: 62px;
  padding: 7px 4px;
  border: 3px solid var(--line);
  border-radius: 15px;
  background: #f2edff;
  box-shadow: 0 4px 0 rgba(38,29,75,.17);
  cursor: pointer;
  font-size: 11px;
}
.editor-tool span { display: block; font-size: 23px; margin-bottom: 2px; }
.editor-tool.is-selected { background: var(--yellow); transform: translateY(-2px); box-shadow: 0 5px 0 #b9780e; }
.editor-colors { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.color-dot {
  width: 39px;
  height: 39px;
  padding: 0;
  border: 4px solid white;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 3px var(--line), 0 4px 0 rgba(38,29,75,.18);
  cursor: pointer;
}
.color-dot.is-selected { transform: scale(1.14); box-shadow: 0 0 0 4px var(--yellow), 0 0 0 7px var(--line); }
.sticker-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.sticker-picker button {
  min-width: 0;
  aspect-ratio: 1;
  padding: 6px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #fff9df;
  box-shadow: 0 3px 0 rgba(38,29,75,.16);
  cursor: pointer;
}
.sticker-picker img { width: 100%; height: 100%; object-fit: contain; }
.sticker-controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.sticker-controls button {
  min-height: 43px;
  border: 3px solid var(--line);
  border-radius: 13px;
  background: #e9e4ff;
  box-shadow: 0 3px 0 rgba(38,29,75,.16);
  cursor: pointer;
  font-size: 23px;
}
.sticker-controls .danger-tool { background: #ffb7c9; }
.editor-help { margin: auto 0 0; color: #4d436b; text-align: center; font-size: 12px; line-height: 1.35; }
.editor-finish { width: 100%; min-height: 66px; padding: 9px 12px; font-size: 19px; }
.editor-finish img { width: 30px; height: 30px; }

/* Phaser puzzle canvas replaces the DOM board and trays. */
.game-stage {
  display: block;
  position: relative;
  width: min(1280px, 100%);
  height: calc(100% - 82px);
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  border: 4px solid rgba(38,29,75,.36);
  border-radius: 24px;
  background: rgba(255,255,255,.32);
  touch-action: none;
}

@media (orientation: portrait), (max-aspect-ratio: 9/10) {
  .editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 1fr) auto;
    gap: 9px;
  }
  .editor-panel { padding: 9px; gap: 9px; overflow: visible; }
  .editor-tool-tabs { grid-template-columns: repeat(3, minmax(76px, 1fr)); }
  .editor-tool { min-height: 48px; }
  .editor-tool span { display: inline; font-size: 18px; }
  .sticker-picker { grid-template-columns: repeat(8, 1fr); }
  .sticker-picker button { padding: 3px; }
  .editor-help { display: none; }
  .editor-finish { min-height: 56px; }
}

@media (max-width: 680px), (max-height: 620px) {
  .view-editor { gap: 5px; }
  .editor-layout { grid-template-columns: minmax(0, 1fr) minmax(250px, 300px); grid-template-rows: 1fr; }
  .editor-panel { padding: 8px; gap: 7px; }
  .editor-tool { min-height: 48px; }
  .editor-tool span { font-size: 18px; }
  .color-dot { width: 30px; height: 30px; border-width: 3px; }
  .sticker-picker button { padding: 3px; }
  .editor-help { display: none; }
  .editor-finish { min-height: 52px; font-size: 15px; }
  .game-stage { height: calc(100% - 67px); }
}

@media (orientation: portrait) and (max-width: 680px) {
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: minmax(210px, 1fr) auto; }
  .editor-tool-tabs { grid-template-columns: repeat(3, 1fr); }
  .sticker-picker { grid-template-columns: repeat(8, 1fr); }
}
