:root {
  --ink: oklch(0.28 0.025 73);
  --ink-soft: oklch(0.47 0.035 73);
  --paper: oklch(0.985 0.018 92);
  --cream: oklch(0.955 0.052 91);
  --sun: oklch(0.87 0.15 94);
  --coral: oklch(0.67 0.18 28);
  --coral-dark: oklch(0.52 0.16 28);
  --teal: oklch(0.65 0.09 190);
  --leaf: oklch(0.62 0.12 145);
  --line: oklch(0.78 0.035 85);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --body-font: "Avenir Next", "Trebuchet MS", sans-serif;
  --display-font: "Cooper Black", "Arial Rounded MT Bold", ui-rounded, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--cream);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--body-font);
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 12% 14%, oklch(0.88 0.09 186 / 0.48) 0 11%, transparent 11.3%),
    radial-gradient(circle at 88% 84%, oklch(0.79 0.11 29 / 0.28) 0 13%, transparent 13.3%);
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}

button,
input,
label {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

.parent-playland-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.75rem;
  padding: 0.65rem 0.9rem;
  color: var(--ink);
  background: oklch(98.5% 0.018 92 / 92%);
  border: 2px solid oklch(78% 0.035 85 / 70%);
  border-radius: 999px;
  font-weight: 900;
  text-decoration: none;
}

.parent-playland-link:focus-visible {
  outline: 4px solid oklch(55% 0.16 246);
  outline-offset: 3px;
}

button:focus-visible,
label[for]:focus-within,
canvas:focus-visible {
  outline: 4px solid oklch(0.55 0.16 246);
  outline-offset: 4px;
}

button:disabled {
  cursor: default;
  opacity: 0.42;
}

[hidden] {
  display: none !important;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--space-md);
  width: 100%;
  height: 100dvh;
  padding:
    max(var(--space-md), env(safe-area-inset-top))
    max(var(--space-lg), env(safe-area-inset-right))
    max(var(--space-md), env(safe-area-inset-bottom))
    max(var(--space-lg), env(safe-area-inset-left));
}

.game-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  min-height: 58px;
  padding-inline: clamp(0px, 2vw, 24px);
}

.title-lockup {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--coral-dark);
  transform: rotate(-1.5deg);
}

.title-splotch {
  width: 52px;
  height: 52px;
  overflow: visible;
  fill: var(--sun);
  stroke: var(--ink);
  stroke-width: 2.5;
}

.title-splotch circle {
  fill: var(--ink);
  stroke: none;
}

.title-lockup div {
  display: flex;
  align-items: baseline;
  gap: 0.28em;
  font-family: var(--display-font);
  font-size: clamp(1.4rem, 4vw, 2.15rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.title-lockup strong {
  color: var(--ink);
  font-weight: 900;
}

.child-hint {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  max-width: 42ch;
  padding: var(--space-sm) var(--space-lg);
  color: var(--ink);
  font-size: clamp(0.82rem, 2.2vw, 1rem);
  font-weight: 750;
  background: oklch(0.99 0.025 97 / 0.82);
  border: 2px dashed oklch(0.65 0.06 78);
  border-radius: 18px 22px 17px 24px;
}

.hint-finger {
  display: block;
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: transparent;
  background: var(--coral);
  border: 3px solid var(--ink);
  border-radius: 50%;
}

.studio {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-md);
  min-height: 0;
}

.paper-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 228px) * 4 / 3));
  max-width: 1080px;
  aspect-ratio: 4 / 3;
  place-self: center;
  padding: clamp(7px, 1.3vw, 14px);
  background: var(--paper);
  border: 2px solid oklch(0.77 0.035 86);
  border-radius: 14px 8px 18px 11px;
  box-shadow:
    0 5px 0 oklch(0.72 0.045 83),
    0 14px 28px oklch(0.38 0.04 70 / 0.18);
  transform: rotate(0.15deg);
}

.paper-wrap::before,
.paper-wrap::after {
  position: absolute;
  z-index: 2;
  width: clamp(52px, 10vw, 92px);
  height: 22px;
  content: "";
  background: oklch(0.91 0.08 91 / 0.88);
  border: 1px solid oklch(0.78 0.055 89 / 0.65);
}

.paper-wrap::before {
  top: -11px;
  left: 12%;
  transform: rotate(-4deg);
}

.paper-wrap::after {
  right: 10%;
  bottom: -10px;
  transform: rotate(3deg);
}

#paintCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--paper);
  border-radius: 7px 5px 10px 6px;
  cursor: crosshair;
  touch-action: none;
}

#paintCanvas.paint-pop {
  animation: paper-pop 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes paper-pop {
  50% { transform: scale(0.997); }
}

.canvas-busy {
  position: absolute;
  inset: 14px;
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--space-lg);
  padding: var(--space-xl);
  color: var(--ink);
  font-weight: 800;
  text-align: center;
  background: oklch(0.985 0.02 92 / 0.94);
  border-radius: 8px;
}

.busy-sun {
  width: 54px;
  height: 54px;
  background: var(--sun);
  border: 5px solid var(--ink);
  border-radius: 50%;
  animation: busy-turn 2.2s linear infinite;
}

@keyframes busy-turn {
  to { transform: rotate(360deg) scale(0.92); }
}

.palette {
  display: flex;
  justify-content: center;
  gap: clamp(5px, 1.2vw, 12px);
  min-width: 0;
  padding: var(--space-xs) 2px;
}

.color-button {
  position: relative;
  min-width: 58px;
  width: clamp(58px, 9.5vw, 78px);
  min-height: 58px;
  aspect-ratio: 1;
  padding: 0;
  background: var(--paint);
  border: clamp(4px, 0.65vw, 6px) solid var(--paper);
  border-radius: 44% 56% 48% 52% / 52% 46% 54% 48%;
  box-shadow: 0 0 0 2px var(--ink), 0 5px 0 oklch(0.42 0.04 75 / 0.35);
  cursor: pointer;
  transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 160ms ease;
  touch-action: manipulation;
}

.color-button:nth-child(2n) {
  transform: rotate(3deg);
}

.color-button:nth-child(3n) {
  transform: rotate(-3deg);
}

.color-button.is-selected {
  z-index: 1;
  box-shadow: 0 0 0 4px var(--ink), 0 8px 0 oklch(0.42 0.04 75 / 0.25);
  transform: translateY(-7px) rotate(-2deg) scale(1.04);
}

.color-button:active {
  transform: translateY(2px) scale(0.96);
}

.color-white svg {
  width: 52%;
  fill: none;
  stroke: var(--ink-soft);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.child-actions {
  display: flex;
  position: absolute;
  right: max(var(--space-lg), env(safe-area-inset-right));
  bottom: max(var(--space-sm), env(safe-area-inset-bottom));
  z-index: 4;
  gap: var(--space-sm);
}

.round-action {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 50px;
  padding: 7px var(--space-md);
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 800;
  background: oklch(0.975 0.02 92 / 0.94);
  border: 2px solid var(--ink);
  border-radius: 16px 13px 17px 12px;
  box-shadow: 0 3px 0 var(--ink);
}

.round-action svg {
  width: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.round-action:active {
  box-shadow: none;
  transform: translateY(3px);
}

.parent-lock {
  position: fixed;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 10px;
  color: oklch(0.43 0.07 145 / 0.7);
  background: transparent;
  border: 0;
  border-radius: 50%;
  touch-action: none;
}

.parent-lock svg {
  width: 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.parent-lock-a {
  top: max(4px, env(safe-area-inset-top));
  right: max(4px, env(safe-area-inset-right));
}

.parent-lock-b {
  bottom: max(3px, env(safe-area-inset-bottom));
  left: max(3px, env(safe-area-inset-left));
}

.parent-hold-active .parent-lock {
  color: var(--leaf);
  background: oklch(0.97 0.04 145 / 0.9);
  box-shadow: inset 0 0 0 3px var(--leaf);
}

.parent-whisper {
  position: fixed;
  bottom: max(5px, env(safe-area-inset-bottom));
  left: max(48px, calc(env(safe-area-inset-left) + 48px));
  z-index: 3;
  margin: 0;
  color: oklch(0.5 0.04 110 / 0.68);
  font-size: 0.66rem;
  font-weight: 700;
}

.parent-panel {
  width: min(680px, calc(100% - 24px));
  max-height: min(92dvh, 900px);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 26px 18px 24px 20px;
  box-shadow: 0 14px 0 oklch(0.26 0.025 73 / 0.2);
}

.parent-panel::backdrop {
  background: oklch(0.25 0.035 73 / 0.58);
}

.parent-sheet {
  max-height: calc(92dvh - 6px);
  padding: var(--space-xl);
  overflow-y: auto;
  overscroll-behavior: contain;
  user-select: text;
}

.parent-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-xl);
  margin-bottom: var(--space-lg);
}

.eyebrow {
  margin: 0 0 var(--space-xs);
  color: var(--coral-dark);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.parent-heading h1 {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(1.85rem, 7vw, 2.65rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.close-button {
  width: 52px;
  min-width: 52px;
  height: 52px;
  padding: 0 0 5px;
  color: var(--ink);
  font-size: 2.2rem;
  line-height: 1;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.privacy-banner {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: var(--space-md);
  padding: var(--space-lg);
  color: oklch(0.31 0.065 160);
  background: oklch(0.92 0.055 155);
  border: 2px solid oklch(0.57 0.09 155);
  border-radius: 17px 24px 18px 20px;
}

.privacy-banner svg {
  width: 42px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.privacy-banner strong {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: 1rem;
}

.privacy-banner p,
.camera-help,
.camera-message,
.offline-card p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-xl);
}

.photo-button {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: var(--space-md);
  min-height: 90px;
  padding: var(--space-md);
  color: var(--ink);
  text-align: left;
  border: 3px solid var(--ink);
  border-radius: 18px 24px 17px 21px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
}

.camera-button {
  background: var(--sun);
}

.import-button {
  background: oklch(0.82 0.09 189);
}

.photo-button svg {
  width: 49px;
  fill: none;
  stroke: currentColor;
  stroke-linejoin: round;
  stroke-width: 3.2;
}

.photo-button span {
  display: grid;
  gap: 3px;
}

.photo-button strong {
  font-size: 1.05rem;
}

.photo-button small {
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 650;
}

.photo-button:active,
.done-button:active,
.primary-button:active,
.secondary-button:active {
  box-shadow: none;
  transform: translateY(4px);
}

.camera-help {
  max-width: 68ch;
  margin: var(--space-md) 2px var(--space-lg);
  color: var(--ink-soft);
}

.clear-photo-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  min-height: 52px;
  padding: var(--space-sm) var(--space-lg);
  color: oklch(0.49 0.15 28);
  font-weight: 850;
  background: oklch(0.95 0.045 28);
  border: 2px solid oklch(0.61 0.13 28);
  border-radius: 15px;
}

.clear-photo-button svg {
  width: 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.settings-group {
  display: grid;
  gap: 1px;
  margin-top: var(--space-xl);
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 17px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xl);
  min-height: 68px;
  padding: var(--space-md) var(--space-lg);
  background: oklch(0.975 0.018 91);
  cursor: pointer;
}

.setting-row + .setting-row {
  border-top: 1px solid var(--line);
}

.setting-row > span:first-child {
  display: grid;
  gap: 2px;
}

.setting-row strong {
  font-size: 0.94rem;
}

.setting-row small {
  color: var(--ink-soft);
  font-size: 0.74rem;
}

.switch {
  position: relative;
  width: 58px;
  height: 34px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: oklch(0.75 0.025 82);
  border: 2px solid var(--ink);
  border-radius: 999px;
  transition: background 160ms ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  content: "";
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
  transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.switch input:checked + span {
  background: var(--leaf);
}

.switch input:checked + span::after {
  transform: translateX(24px);
}

.switch input:focus-visible + span {
  outline: 4px solid oklch(0.55 0.16 246);
  outline-offset: 3px;
}

.offline-card {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: start;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  padding: var(--space-lg);
  color: var(--ink);
  background: oklch(0.955 0.025 190);
  border: 2px dashed oklch(0.63 0.065 190);
  border-radius: 18px 15px 21px 17px;
}

.offline-card h2 {
  margin: 0 0 var(--space-xs);
  font-size: 0.95rem;
}

.offline-card small {
  display: block;
  margin-top: var(--space-xs);
  color: var(--ink-soft);
  font-size: 0.7rem;
}

.status-dot {
  width: 14px;
  height: 14px;
  margin-top: 3px;
  background: var(--sun);
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.status-dot.is-ready {
  background: var(--leaf);
}

.status-dot.is-warning {
  background: var(--coral);
}

.done-button,
.primary-button,
.secondary-button {
  min-height: 54px;
  padding: var(--space-md) var(--space-xl);
  color: var(--ink);
  font-weight: 900;
  border: 3px solid var(--ink);
  border-radius: 17px 20px 16px 21px;
  box-shadow: 0 4px 0 var(--ink);
}

.done-button {
  width: 100%;
  margin-top: var(--space-xl);
  background: var(--coral);
  color: var(--paper);
}

.primary-button {
  background: var(--sun);
}

.secondary-button {
  background: var(--paper);
}

.camera-stage h2 {
  margin: var(--space-xl) 0 var(--space-md);
  font-family: var(--display-font);
  font-size: 1.65rem;
}

.video-frame {
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px 22px 14px 20px;
}

#cameraPreview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-message {
  min-height: 2.5em;
  margin: var(--space-md) 0;
  color: var(--ink-soft);
}

.camera-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: var(--space-md);
}

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

.noscript-message {
  position: fixed;
  inset: 25% var(--space-xl) auto;
  z-index: 50;
  padding: var(--space-xl);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  text-align: center;
}

.calm-mode {
  background-image: none;
}

.calm-mode .color-button {
  filter: saturate(0.72);
}

.calm-mode #paintCanvas.paint-pop {
  animation: none;
}

@media (orientation: landscape) {
  .game-shell {
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--space-sm);
  }

  .studio {
    grid-template-columns: minmax(0, 1fr) clamp(70px, 8vw, 92px);
    grid-template-rows: minmax(0, 1fr);
    gap: clamp(12px, 2vw, 28px);
    padding: 0 clamp(38px, 5vw, 70px) clamp(3px, 1vh, 10px);
  }

  .paper-wrap {
    width: min(100%, calc((100dvh - 100px) * 4 / 3));
    max-height: calc(100dvh - 100px);
  }

  .palette {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.65vh, 8px);
  }

  .color-button {
    width: clamp(56px, 7vh, 72px);
    min-height: 56px;
  }
}

@media (max-width: 620px) {
  .game-shell {
    gap: var(--space-sm);
    padding-inline: max(var(--space-sm), env(safe-area-inset-left));
  }

  .game-heading {
    min-height: 50px;
    padding-inline: var(--space-xs);
  }

  .title-splotch {
    width: 40px;
    height: 40px;
  }

  .title-lockup div {
    display: grid;
    gap: 0;
    font-size: 1.22rem;
  }

  .child-hint {
    max-width: 56%;
    padding: 6px 10px;
    font-size: 0.72rem;
    line-height: 1.15;
  }

  .studio {
    grid-template-rows: auto auto;
    align-content: start;
    gap: var(--space-sm);
  }

  .paper-wrap {
    width: min(100%, calc((100dvh - 205px) * 4 / 3));
  }

  .palette {
    display: grid;
    grid-template-columns: repeat(4, minmax(58px, 1fr));
    width: 100%;
  }

  .color-button {
    min-width: 58px;
    width: 100%;
    min-height: 58px;
  }

  .child-actions {
    right: max(var(--space-sm), env(safe-area-inset-right));
  }

  .round-action {
    min-width: 50px;
    padding-inline: 9px;
  }

  .round-action span {
    display: none;
  }

  .parent-whisper {
    display: none;
  }

  .parent-sheet {
    padding: var(--space-lg);
  }

  .photo-actions {
    grid-template-columns: 1fr;
  }

  .photo-button {
    min-height: 78px;
  }
}

@media (max-width: 620px) and (orientation: landscape) {
  .game-heading {
    position: absolute;
    top: max(4px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    z-index: 3;
  }

  .child-hint {
    display: none;
  }

  .studio {
    grid-template-columns: minmax(0, 1fr) 104px;
    padding: 0 50px 0 70px;
  }

  .paper-wrap {
    width: min(100%, calc((100dvh - 24px) * 4 / 3));
    max-height: calc(100dvh - 24px);
  }

  .palette {
    display: grid;
    grid-template-columns: repeat(2, 48px);
    width: 104px;
  }

  .color-button {
    width: 48px;
    min-width: 48px;
    min-height: 48px;
  }
}

@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;
  }
}
