html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f6eed9;
  overscroll-behavior: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}

#touch-controls {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.pad.right {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid #26346e;
  background: rgba(251, 246, 234, 0.5);
  color: #26346e;
  font-size: 38px;
  line-height: 1;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#touch-controls button.pressed {
  background: rgba(107, 70, 193, 0.35);
}

#btn-undo {
  width: 52px !important;
  height: 52px !important;
  margin-bottom: 52px;
  font-size: 24px !important;
}

#btn-dash {
  width: 64px !important;
  height: 64px !important;
  margin-bottom: 26px;
  font-size: 30px !important;
  color: #b8860b !important;
}

body:not([data-dash="on"]) #btn-dash { display: none; }

/* The thumb stick: a faint ring waits bottom left, and jumps to wherever the thumb lands. */
#stick {
  position: absolute;
  left: calc(max(18px, env(safe-area-inset-left)) + 56px);
  top: calc(100% - max(16px, env(safe-area-inset-bottom)) - 56px);
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  border: 3px dashed rgba(38, 52, 110, 0.45);
  background: rgba(251, 246, 234, 0.22);
  opacity: 0.75;
}

#stick.active {
  opacity: 1;
  border-style: solid;
}

#stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  border: 3px solid #26346e;
  background: rgba(251, 246, 234, 0.75);
}

#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: rgba(38, 30, 70, 0.97);
  color: #fbf6ea;
  font: 26px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  line-height: 1.4;
}

#rotate-hint::before {
  content: "📱";
  display: block;
  font-size: 72px;
  margin-bottom: 18px;
  animation: turn-phone 2.4s ease-in-out infinite;
}

@keyframes turn-phone {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  #rotate-hint::before { animation: none; transform: rotate(-90deg); }
}

@media (pointer: coarse) {
  #touch-controls { display: block; }
}

/* Upright phones: bigger controls in the space under the page. */
@media (pointer: coarse) and (orientation: portrait) {
  #touch-controls button { width: 96px; height: 96px; font-size: 42px; }
  #btn-dash { width: 72px !important; height: 72px !important; }
  #btn-undo { width: 58px !important; height: 58px !important; }
  .pad.right { right: max(22px, env(safe-area-inset-right)); bottom: max(34px, env(safe-area-inset-bottom)); }
  #stick { left: calc(max(22px, env(safe-area-inset-left)) + 66px); top: calc(100% - max(34px, env(safe-area-inset-bottom)) - 66px); width: 132px; height: 132px; margin: -66px 0 0 -66px; }
}

#btn-sound {
  position: fixed;
  top: max(64px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* Start the page again (touch screens, while playing): asks for a second tap. */
#btn-restart {
  position: fixed;
  top: max(160px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 20px;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.8);
  color: #2b2f5c;
  font: bold 18px system-ui, sans-serif;
  cursor: pointer;
  display: none;
}
#btn-restart.confirm { background: #f7d04a; font-size: 14px; }
@media (pointer: coarse) {
  body[data-state="playing"] #btn-restart,
  body[data-state="paused"] #btn-restart { display: block; }
}

#btn-lang {
  position: fixed;
  top: max(112px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.8);
  color: #2b2f5c;
  font: bold 13px system-ui, sans-serif;
  cursor: pointer;
}

#btn-easy {
  position: fixed;
  top: max(160px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 20px;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.8);
  color: #2b2f5c;
  font: bold 13px system-ui, sans-serif;
  cursor: pointer;
}
/* Play together: one moves Garabato, the other draws. Same look as the little-ones button. */
#btn-together {
  position: fixed;
  top: calc(max(160px, env(safe-area-inset-top)) + 50px);
  right: max(14px, env(safe-area-inset-right));
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 20px;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.8);
  color: #2b2f5c;
  font: bold 13px system-ui, sans-serif;
  cursor: pointer;
}
#btn-together[aria-pressed="true"] { background: #b9e6a8; border-color: #3f7a2e; }
body:not([data-state="title"]) #btn-together { visibility: hidden; }
#btn-together:focus-visible { outline: 3px solid #fbf6ea; outline-offset: 2px; }

#btn-continue {
  position: fixed;
  top: calc(max(160px, env(safe-area-inset-top)) + 100px);
  right: max(14px, env(safe-area-inset-right));
  max-width: 46vw;
  min-height: 48px;
  padding: 6px 20px;
  border-radius: 24px;
  border: 3px solid #b8860b;
  background: #f7d04a;
  color: #2b2f5c;
  font: 19px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(120, 80, 10, 0.35);
}
#btn-continue[hidden],
body:not([data-state="title"]) #btn-continue { display: none; }
#btn-continue:focus-visible { outline: 3px solid #26346e; outline-offset: 3px; }

#btn-arcade {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  right: max(18px, env(safe-area-inset-right));
  height: 44px;
  padding: 0 20px;
  border-radius: 22px;
  box-shadow: 0 3px 0 rgba(40, 30, 80, 0.35);
  border: 2px solid #2b2f5c;
  background: #b9a6f0;
  color: #2b2f5c;
  font: bold 14px system-ui, sans-serif;
  cursor: pointer;
}
body:not([data-state="title"]) #btn-arcade { display: none; }

#btn-home {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  height: 44px;
  padding: 0 22px;
  border-radius: 22px;
  border: 2px solid #2b2f5c;
  background: rgba(253, 248, 236, 0.95);
  color: #2b2f5c;
  font: bold 15px system-ui, sans-serif;
  cursor: pointer;
}
body:not([data-state="arcadeOver"]) #btn-home { display: none; }

/* Choosing who runs in the arcade: just their pictures, no names. */
#arcade-pick {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 20px;
  background: rgba(38, 30, 70, 0.82);
}
#arcade-pick[hidden] { display: none; }
#arcade-pick-title {
  margin: 0;
  color: #fbf6ea;
  font: 30px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
}
#arcade-kids {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  max-width: 760px;
}
#arcade-kids button {
  width: 92px;
  height: 128px;
  padding: 6px;
  border-radius: 18px;
  border: 3px solid #d9a93a;
  background: radial-gradient(circle at 50% 70%, #fff6dc, #f1e0bb);
  cursor: pointer;
  display: grid;
  place-items: end center;
}
#arcade-kids button img {
  max-width: 100%;
  max-height: 112px;
  object-fit: contain;
}
#arcade-kids button:hover,
#arcade-kids button:focus-visible { transform: translateY(-4px); outline: 3px solid #fbf6ea; outline-offset: 2px; }
#arcade-back {
  height: 40px;
  padding: 0 18px;
  border-radius: 20px;
  border: 2px solid #fbf6ea;
  background: transparent;
  color: #fbf6ea;
  font: bold 14px system-ui, sans-serif;
  cursor: pointer;
}
@media (max-height: 430px) {
  #arcade-kids button { width: 74px; height: 104px; }
  #arcade-kids button img { max-height: 90px; }
  #arcade-pick { gap: 10px; }
}

#btn-easy[aria-pressed="true"] { background: #f7d04a; border-color: #b8860b; }
body:not([data-state="title"]) #btn-easy { visibility: hidden; }

#btn-easy:focus-visible,
#btn-lang:focus-visible,
#btn-sound:focus-visible,
#touch-controls button:focus-visible {
  outline: 3px solid #e0b43a;
  outline-offset: 2px;
}

body:not([data-state="playing"]) #touch-controls { visibility: hidden; }

#finale-ui {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
}

#finale-ui[hidden], #keepsake[hidden] { display: none; }

#finale-ui button, #keepsake .actions > * {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 24px;
  border: 2px solid #2b2f5c;
  background: #fbf6ea;
  color: #2b2f5c;
  font: 20px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

#face-done, #keepsake-save {
  background: #5b3fa8 !important;
  color: #fff8e6 !important;
}

#keepsake {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 24px;
  background: rgba(20, 12, 35, 0.45);
}

#keepsake .sheet {
  width: min(560px, 100%);
  margin: auto;
  padding: 20px;
  border-radius: 20px;
  background: #fbf6ea;
  color: #2b2f5c;
  font: 18px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

#keepsake h1 { margin: 0 0 12px; font-size: 26px; font-weight: normal; }

#keepsake img {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

#keepsake label { display: block; margin: 14px 0 6px; }

#keepsake input {
  width: min(320px, 100%);
  min-height: 44px;
  padding: 0 14px;
  border: 2px solid #2b2f5c;
  border-radius: 12px;
  font: 18px "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  text-align: center;
}

#keepsake .actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

#keepsake .tip { margin: 12px 0 0; font-size: 14px; color: #6a5a8c; }

#finale-ui button:focus-visible, #keepsake .actions > *:focus-visible, #keepsake input:focus-visible {
  outline: 3px solid #e0b43a;
  outline-offset: 2px;
}

@media print {
  body > *:not(#keepsake) { display: none !important; }
  #keepsake { position: static; background: none; padding: 0; }
  #keepsake .sheet { box-shadow: none; padding: 0; width: 100%; }
  #keepsake h1, #keepsake label, #keepsake input, #keepsake .actions, #keepsake .tip { display: none; }
  #keepsake img { max-height: none; box-shadow: none; border-radius: 0; }
}

/* Which build is running, so it's easy to tell an old copy from the new one. */
#build-tag {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(6px, env(safe-area-inset-bottom));
  margin: 0;
  font: 11px system-ui, sans-serif;
  color: rgba(255, 248, 230, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
body:not([data-state="title"]) #build-tag { display: none; }
