:root {
  color-scheme: light;
  --ink: #342046;
  --muted: #5c4a68;
  --purple: #5b317e;
  --berry: #aa365c;
  --lavender: #f1e4fb;
  --mint: #e4f4e7;
  --gold: #ffe597;
  --paper: #fff7e8;
  --inset-top: var(--safe-area-inset-top, env(safe-area-inset-top));
  --inset-right: var(--safe-area-inset-right, env(safe-area-inset-right));
  --inset-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
  --inset-left: var(--safe-area-inset-left, env(safe-area-inset-left));
  font: 600 100%/1.4 ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(155deg, var(--paper) 35%, #f4ecfb 76%, var(--mint));
}
.app {
  max-width: 1120px;
  margin: auto;
  --gutter: clamp(12px, 3vw, 28px);
  padding: max(12px, var(--inset-top)) max(var(--gutter), var(--inset-right))
    max(16px, var(--inset-bottom)) max(var(--gutter), var(--inset-left));
}
.app.is-playing {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: max(6px, var(--inset-top));
  padding-bottom: max(6px, var(--inset-bottom));
}
#game {
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  --tile-size: 48px;
  --tile-inset: calc(var(--tile-size) / 2 + 5px);
  --tile-glyph: clamp(27px, 6.5vw, 41px);
}
button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
:is(button, a):focus-visible { outline: 3px solid #2559a2; outline-offset: 3px; }
button:disabled { cursor: default; }
button:active:not(:disabled) { filter: brightness(.94); }
.primary:disabled { opacity: .56; box-shadow: none; }
.top, .brand { display: flex; align-items: center; gap: 10px; }
.top { justify-content: space-between; margin-bottom: 14px; }
.brand {
  min-width: 0;
  gap: 5px;
  color: var(--ink);
  font-size: clamp(1.13rem, 3.6vw, 1.75rem);
  font-weight: 900;
  letter-spacing: -.04em;
}
.brand strong { color: var(--berry); }
.brand span { overflow-wrap: anywhere; }
.brand-mark { flex: 0 0 38px; width: 38px; height: 38px; object-fit: contain; }
.stars { white-space: nowrap; padding: 6px 10px; border-radius: 13px; background: #fff0b9; }
.home { display: grid; gap: 14px; }
.intro {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(74px, 31%, 176px);
  align-items: center;
  gap: 5px;
  padding: clamp(12px, 3vw, 26px);
  border: 1px solid #e8d7f0;
  border-radius: 24px;
  background: radial-gradient(ellipse at 83% 65%, #ffe8ad 0 22%, transparent 53%), linear-gradient(135deg, #f4e7fc, #fff1d7);
  box-shadow: 0 8px 0 #e3d3ec;
}
.intro h1 {
  margin: 0;
  font-size: clamp(1.9rem, 6.3vw, 3.85rem);
  line-height: .98;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}
.intro h1 em { font-style: normal; color: var(--berry); }
.intro p { margin: 8px 0 0; color: var(--muted); font-size: clamp(.87rem, 2.35vw, 1.02rem); }
.hero-mark { display: block; width: 122%; max-width: none; height: auto; margin-inline-start: -11%; filter: drop-shadow(0 7px 7px #55336b35); animation: peekberry-bob 2.6s ease-in-out infinite; }
@keyframes peekberry-bob { 50% { transform: translateY(-5px) rotate(2deg); } }
.card, .collection {
  min-width: 0;
  padding: 13px;
  background: #fffefa;
  border: 1px solid #e6d9ed;
  border-radius: 20px;
  box-shadow: 0 4px 0 #e8d9ed80;
}
.home-actions { display: grid; gap: 8px; margin-bottom: 12px; }
.home-actions .primary { min-height: 56px; font-size: 1.18rem; font-weight: 850; }
fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }
legend, .collection h2 { margin: 0 0 7px; font-size: 1.06rem; font-weight: 850; }
.ages { display: grid; gap: 7px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ages button { padding: 7px 4px; background: #faf5fc; border: 2px solid #f0e7f4; transition: transform .16s ease, background .16s ease; }
.ages button:active { transform: scale(.97); }
.ages [aria-pressed="true"] { color: var(--purple); background: var(--lavender); border-color: #855aa2; }
.ages small { display: block; font-size: .73rem; }
.primary, .secondary, .quiet { padding: 8px 12px; }
.primary { color: white; background: var(--purple); box-shadow: inset 0 -3px #34204659; }
.secondary, .icon-button { color: var(--purple); background: var(--lavender); }
.quiet { background: transparent; color: var(--purple); text-decoration: underline; }
.install { display: block; width: 100%; margin-top: 8px; }
#install-help { margin-bottom: 0; font-size: .9rem; }
.collection ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 0;
  margin: 0;
}
.collection li {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  padding: 3px 3px 6px;
  border-radius: 12px;
  background: #f6edf9;
  font-size: .82rem;
}
.collection li[data-complete="true"] { background: var(--mint); }
.collection li span {
  display: grid;
  place-items: center;
  min-height: 44px;
  margin-bottom: 4px;
  border-radius: 9px;
  background: url("brand/world-thumbs.jpg") var(--world-thumb) / 300% 200% no-repeat, var(--world-color);
  font-size: 1.45rem;
}
footer a { display: inline-flex; align-items: center; min-height: 48px; color: var(--purple); }
.toolbar {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 3px 0 7px;
}
.icon-button { width: 48px; font-size: 1.5rem; }
.round-name { min-width: 0; }
.round-name h1 { margin: 0; font-size: clamp(1.08rem, 3.6vw, 1.55rem); line-height: 1.12; }
.round-name small { color: var(--muted); }
.round-name progress {
  display: inline-block;
  width: min(32%, 112px);
  height: 8px;
  margin-inline-start: 5px;
  accent-color: var(--purple);
}
.playfield {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 0 6px 9px;
  margin-inline: -6px;
  scroll-padding-block: 8px;
}
.play-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: center;
  border-top: 1px solid #dfcce9;
  padding-top: 6px;
}
.play-buttons { display: flex; gap: 6px; align-items: stretch; }
.hint { flex: 1; color: var(--ink); background: var(--gold); font-weight: 850; }
.hint:disabled { opacity: .6; }
.instruction, .feedback { font-size: .95rem; color: var(--muted); }
.instruction { margin: 2px 0 7px; }
.feedback { grid-column: 1 / -1; min-height: 1.4em; margin: 0; font-weight: 700; }
.round-option { padding-inline: 8px; }
.board { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
figure { min-width: 0; margin: 0; }
figure > .art { outline: 3px solid #fff; }
figcaption { padding: 0 4px 5px; font-size: .9rem; font-weight: 850; }
figcaption b {
  display: inline-grid;
  place-items: center;
  width: 1.55em;
  height: 1.55em;
  border-radius: .5em;
  color: var(--purple);
  background: var(--lavender);
}
#right figcaption b { color: white; background: var(--purple); }
figcaption span { font-weight: 650; }
.art {
  position: relative;
  aspect-ratio: 1.78;
  min-height: 178px;
  border: 4px solid #fffcf5;
  border-radius: 20px;
  box-shadow: 0 5px 0 #e5d6e9, 0 11px 20px #49336c19;
  background: linear-gradient(#fff8ed25, #fff8ed25), var(--world-art) center / cover, var(--world-color);
}
.ocean { --world-art: url("brand/ocean-storybook.jpg"); --world-color: #90d8e3; --world-thumb: 0 0; }
.space { --world-art: url("brand/space.jpg"); --world-color: #69619a; --world-thumb: 50% 0; }
.farm { --world-art: url("brand/farm.jpg"); --world-color: #b6db9e; --world-thumb: 100% 0; }
.jungle { --world-art: url("brand/jungle.jpg"); --world-color: #97cc9a; --world-thumb: 0 100%; }
.arctic { --world-art: url("brand/arctic.jpg"); --world-color: #c5e3f9; --world-thumb: 50% 100%; }
.garden { --world-art: url("brand/garden.jpg"); --world-color: #d9e6a7; --world-thumb: 100% 100%; }
.art.practice { min-height: 170px; aspect-ratio: 1.78; }
.piece {
  position: absolute;
  display: grid;
  place-items: center;
  left: clamp(var(--tile-inset), var(--tile-x), 100% - var(--tile-inset));
  top: clamp(var(--tile-inset), var(--tile-y), 100% - var(--tile-inset));
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  line-height: 1;
  font-size: var(--tile-glyph);
  text-shadow: 0 3px 2px #3420464d, 0 0 7px #fff8ed;
  user-select: none;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}
.piece:not(button) { pointer-events: none; }
.piece:focus-visible { outline: 3px solid white; box-shadow: 0 0 0 6px #2559a2; }
.piece.found { background: #fff4; box-shadow: 0 0 0 3px white, 0 0 0 7px #f05c75, 0 0 20px 9px #ffed7c99; animation: found-pop .35s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes found-pop { from { scale: .65; } to { scale: 1; } }
.piece.found::after {
  content: "✓";
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: white;
  background: var(--purple);
  font: 900 12px/1 system-ui, sans-serif;
}
.piece.hinted { background: #fff7a8a8; box-shadow: 0 0 0 3px white, 0 0 0 7px #f3b329, 0 0 22px 11px #ffed7c; animation: hint-pulse 1.15s ease-in-out infinite alternate; }
@keyframes hint-pulse { to { scale: 1.15; } }
dialog:not([open]) { display: none; }
dialog[open] {
  position: fixed;
  inset: 0;
  width: min(390px, calc(100% - 28px));
  height: fit-content;
  max-height: calc(100% - 28px);
  max-height: calc(100dvh - max(14px, var(--inset-top)) - max(14px, var(--inset-bottom)));
  margin: auto;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 22px;
  padding: 20px;
  text-align: center;
  overflow: auto;
}
dialog::backdrop { background: #28213ac9; }
dialog[data-fallback] { z-index: 5; box-shadow: 0 0 0 100vmax #28213ac9; }
dialog h2 { margin: 0; }
dialog button { width: 100%; }
dialog button + button { margin-top: 8px; }
.celebrate { display: block; width: 94px; height: 94px; object-fit: contain; margin: 0 auto 2px; }
.legal { max-width: 64ch; margin: auto; }
.legal a { color: var(--purple); }
@media (min-width: 700px) {
  .home { grid-template-columns: 1fr 1fr; align-items: center; padding-top: 12px; }
  .collection, footer { grid-column: 1 / -1; }
  .card, .collection { padding: 18px; }
  .collection ul { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .collection li span { min-height: 64px; }
}
@media (min-width: 320px) and (max-width: 699px) {
  .collection ul { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 640px), (orientation: landscape) and (min-width: 520px) {
  .play-buttons { justify-self: end; min-width: 144px; }
}
@media (min-width: 700px) and (min-height: 700px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(12px, 2vw, 24px); }
  .art { aspect-ratio: 1.32; min-height: 255px; }
  .art.practice { min-height: 255px; }
  #game { --tile-size: clamp(56px, 7vw, 78px); --tile-glyph: clamp(39px, 5vw, 58px); }
}
@media (min-width: 740px) and (min-height: 560px) {
  #game {
    --tile-size: clamp(60px, 8vw, 76px);
    --tile-glyph: clamp(44px, 6vw, 59px);
    grid-template-rows: auto minmax(0, max-content) auto;
    align-content: start;
    gap: 8px;
  }
  .art { aspect-ratio: 1.32; min-height: 255px; }
  .art.practice { min-height: 255px; }
}
@media (orientation: landscape) and (max-height: 460px) {
  .art:not(.practice) { aspect-ratio: 2.25; min-height: 146px; }
  .feedback:empty { min-height: 0; }
}
@media (orientation: landscape) and (max-height: 460px) and (min-width: 480px) {
  .top { margin-bottom: 8px; }
  .home { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 10px; padding-top: 0; }
  .intro { padding: 10px; }
  .intro h1 { font-size: clamp(1.75rem, 4vw, 2.3rem); }
  .collection, footer { grid-column: 1 / -1; }
}
@media (max-width: 699px), (max-height: 699px) {
  #game { --tile-size: clamp(44px, 13vw, 58px); --tile-glyph: clamp(32px, 9vw, 43px); }
  .art:not(.practice) { aspect-ratio: 1.78; min-height: 170px; }
  .play-controls { padding-bottom: max(6px, var(--inset-bottom)); }
}
@media (max-height: 300px) {
  .app.is-playing { height: auto; min-height: 100vh; }
  #game { grid-template-rows: auto auto auto; }
  .playfield { overflow: visible; }
}

.scene-edit {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  --radius: 12%;
  mask-image: radial-gradient(circle closest-side at var(--spot-x) var(--spot-y), black 0 35%, transparent 100%);
  mask-size: 100% 100%;
}
.scene-edit[data-age="6"] { --radius: 10%; }
.scene-edit[data-age="8"] { --radius: 8%; }
.scene-edit[data-age="11"] { --radius: 6%; }
.scene-edit {
  mask-image: radial-gradient(circle at var(--spot-x) var(--spot-y), black 0 calc(var(--radius) * .65), transparent var(--radius));
}
.scene-edit span {
  position: absolute;
  inset: 0;
  background: linear-gradient(#fff8ed25, #fff8ed25), var(--world-art) center / cover, var(--world-color);
  transform-origin: var(--spot-x) var(--spot-y);
}
.scene-edit.bright span { filter: brightness(1.65) saturate(.65); transform: scale(1.5); }
.scene-edit.warm span { filter: sepia(.72) saturate(1.5) brightness(1.35); transform: scale(1.4); }
.scene-edit.cool span { filter: hue-rotate(35deg) brightness(1.22); transform: scale(1.3); }
.scene-edit.shade span { filter: brightness(.76); transform: scale(1.19); }
.scene-edit.soft span { transform: scale(1.38); }
.scene-edit.tint span { filter: hue-rotate(-20deg) saturate(1.35); transform: scale(1.14); }
.scene-marker { pointer-events: none; }
.scene-marker.hinted { pointer-events: auto; }

.board .art.reef-art {
  aspect-ratio: 1;
  min-height: 0;
  background: url("brand/ocean-storybook.jpg") center / 100% 100%;
}
.reef-edit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: url("brand/ocean-alternate.jpg") center / 100% 100%;
}

.board .art.garden.reef-art {
  background: url("brand/garden-pair.jpg") left center / 200% 100%;
}
.garden .reef-edit {
  background: url("brand/garden-pair.jpg") right center / 200% 100%;
}
