:root {
  --sun: #ffe066;
  --sun-deep: #ffd23f;
  --sun-pale: #fff3b8;
  --ink: #2b2440;
  --pink: #ff5fa8;
  --card-edge: #ffd84d;
  --round: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: linear-gradient(180deg, var(--sun-pale) 0%, var(--sun) 55%, var(--sun-deep) 100%);
  color: var(--ink);
  font-family: var(--round);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

/* soft clouds behind everything, like a sunny sky */
.clouds { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.clouds i {
  position: absolute; width: 220px; height: 70px; border-radius: 40px; background: rgba(255,255,255,.55);
  box-shadow: 60px -26px 0 6px rgba(255,255,255,.55), 130px -8px 0 -4px rgba(255,255,255,.55);
}
.clouds i:nth-child(1) { left: 4%; top: 12%; }
.clouds i:nth-child(2) { right: 12%; top: 30%; transform: scale(.8); }
.clouds i:nth-child(3) { left: 30%; bottom: 8%; transform: scale(1.1); }
.clouds i:nth-child(4) { right: -40px; bottom: 26%; transform: scale(.7); }

.screen { position: fixed; inset: 0; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }

/* ---------- title ---------- */
#title { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3vmin; }
.logo { margin: 0; display: flex; gap: .6vmin; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
.logo .tile {
  display: inline-grid; place-items: center; width: 11vmin; height: 12.5vmin; border-radius: 2.6vmin;
  font: 900 9vmin/1 var(--round); color: #fff; border: .9vmin solid var(--ink);
  text-shadow: 0 .5vmin 0 rgba(0,0,0,.18); transform: rotate(var(--r, 0deg));
}
.logo .gap { width: 4vmin; }
#title-art { display: flex; gap: 2vmin; }
#title-art img { width: 17vmin; height: 17vmin; border-radius: 3vmin; border: .8vmin solid #fff; box-shadow: 0 1vmin 0 rgba(0,0,0,.12); transform: rotate(var(--r)); }
.play {
  width: 22vmin; height: 22vmin; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #7ee08a, #2fb455 70%);
  border: 1.2vmin solid #fff; box-shadow: 0 1.4vmin 0 #1f8f3f, 0 2vmin 3vmin rgba(0,0,0,.18);
  animation: breathe 1.8s ease-in-out infinite;
}
.play svg { width: 100%; height: 100%; fill: #fff; }
.play:active { transform: translateY(1vmin); box-shadow: 0 .4vmin 0 #1f8f3f; }
@keyframes breathe { 50% { transform: scale(1.06); } }

/* ---------- round buttons ---------- */
.round-btn {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff3a6, #ffc928 70%); border: 4px solid #fff;
  box-shadow: 0 5px 0 #e0a100, 0 8px 14px rgba(0,0,0,.15);
}
.round-btn svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 2px 0 rgba(160,100,0,.5)); }
.round-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #e0a100; }
.corner { position: absolute; z-index: 5; left: calc(14px + var(--safe-l)); top: calc(14px + var(--safe-t)); }
.corner.right { left: auto; right: calc(14px + var(--safe-r)); }

/* ---------- library strip ---------- */
#library { display: flex; align-items: center; }
.strip {
  --rows: 2;
  --card: min(calc((100dvh - 120px) / var(--rows) - 22px), 280px);
  height: 100%; width: 100%; overflow-x: auto; overflow-y: hidden; touch-action: pan-x;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows), var(--card));
  align-content: center; gap: 26px 28px; padding: 70px calc(90px + var(--safe-r)) 40px calc(96px + var(--safe-l));
  scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.strip::-webkit-scrollbar { display: none; }
@media (orientation: portrait) { .strip { --rows: 3; --card: min(calc((100dvh - 160px) / 3 - 26px), 240px); } }
.card {
  position: relative; width: var(--card); height: var(--card); border-radius: 22px; background: #fff;
  border: 6px solid var(--card-edge); box-shadow: 0 6px 0 #e9b800, 0 10px 16px rgba(0,0,0,.12);
  overflow: visible; transition: transform .12s;
}
.card img { width: 100%; height: 100%; border-radius: 16px; display: block; object-fit: cover; background: #fff; }
.card:active { transform: scale(.95); }
.card .heart { position: absolute; left: -12px; bottom: -12px; width: 44px; height: 44px; }
.card .heart path { fill: #fff; stroke: #ff8cc6; stroke-width: 4; }
.card.done .heart path { fill: #ff6fb5; stroke: #fff; }
.card .new {
  position: absolute; top: -12px; right: -12px; background: #ff6fb5; color: #fff; border: 3px solid #fff; border-radius: 14px;
  font-weight: 900; font-size: 15px; padding: 4px 8px; letter-spacing: .04em; box-shadow: 0 3px 0 rgba(0,0,0,.12);
}

/* ---------- game ---------- */
#game { background: #fbfaf7; }
.stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 3vmin; padding: 12px calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l)); }
.frame { position: relative; width: var(--board); height: var(--board); flex: none; }
.frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#board { border-radius: 26px; box-shadow: 0 0 0 1px rgba(0,0,0,.05), 0 10px 30px rgba(60,40,0,.12); background: #fff; }
#fx { pointer-events: none; }
.frame.pop { animation: boardpop .7s cubic-bezier(.2,1.6,.4,1); }
@keyframes boardpop { 0% { transform: scale(.96); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }

.chips {
  display: flex; flex-direction: column; gap: 10px; padding: 12px 10px; border-radius: 22px;
  background: #fff6d2; border: 4px solid #ffe08a; transition: transform .4s cubic-bezier(.2,1.4,.4,1), opacity .3s;
}
.chips.out { transform: translateX(140%); opacity: 0; }
@media (orientation: portrait) {
  .stage { flex-direction: column; }
  .chips { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .chips.out { transform: translateY(140%); }
}
.chip {
  --c: #ccc; position: relative; width: var(--chip); height: var(--chip); border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 45%), var(--c);
  border: 3px solid rgba(0,0,0,.12); box-shadow: inset 0 -5px 0 rgba(0,0,0,.14), 0 3px 0 rgba(0,0,0,.08);
  display: grid; place-items: center; transition: transform .18s cubic-bezier(.2,1.6,.4,1);
  font: 900 calc(var(--chip) * .5)/1 var(--round); color: #fff;
  text-shadow: 0 0 3px rgba(0,0,0,.55), 0 2px 0 rgba(0,0,0,.35);
}
.chip.light { color: var(--ink); text-shadow: 0 2px 0 rgba(255,255,255,.8); }
.chip.light.done::before { background: var(--ink); }
.chip::after { content: ""; position: absolute; top: 7px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.7); }
.chip.sel { transform: scale(1.16) translateX(-6px); border-color: #fff; box-shadow: 0 0 0 4px var(--ink), 0 6px 12px rgba(0,0,0,.2); z-index: 1; }
@media (orientation: portrait) { .chip.sel { transform: scale(1.16) translateY(-6px); } }
.chip.done { color: transparent; text-shadow: none; }
.chip.done::before {
  content: ""; position: absolute; inset: 22%; background: #fff; border-radius: 50%;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M10 25 L20 35 L38 13' fill='none' stroke='black' stroke-width='8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M10 25 L20 35 L38 13' fill='none' stroke='black' stroke-width='8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
}
.chip.wiggle { animation: wiggle .5s; }
@keyframes wiggle { 20% { transform: rotate(-12deg) scale(1.1); } 40% { transform: rotate(10deg) scale(1.1); } 60% { transform: rotate(-8deg); } 80% { transform: rotate(5deg); } }

/* the finish buttons take the chips' place: a column on the right, a row below in portrait */
.finish { position: absolute; z-index: 6; right: calc(20px + var(--safe-r)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 22px; animation: rise .5s cubic-bezier(.2,1.5,.4,1); }
@media (orientation: portrait) { .finish { top: auto; bottom: calc(22px + var(--safe-b)); right: 50%; transform: translateX(50%); flex-direction: row; } }
@keyframes rise { from { opacity: 0; translate: 0 40px; } }
.big-btn {
  width: 96px; height: 96px; border-radius: 28px; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffd1ea, #ff6fb5 75%); border: 5px solid #fff;
  box-shadow: 0 6px 0 #d94690, 0 10px 18px rgba(0,0,0,.18);
}
.big-btn.go { background: radial-gradient(circle at 35% 30%, #a8f0b0, #2fb455 75%); box-shadow: 0 6px 0 #1f8f3f, 0 10px 18px rgba(0,0,0,.18); }
.big-btn.no { background: radial-gradient(circle at 35% 30%, #ffc4b8, #ff6a4d 75%); box-shadow: 0 6px 0 #c9462e, 0 10px 18px rgba(0,0,0,.18); }
.big-btn svg { width: 54px; height: 54px; fill: none; stroke: #fff; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.big-btn.go rect { fill: #fff; stroke: none; }
.big-btn:active { transform: translateY(4px); }

.ask { position: fixed; inset: 0; z-index: 20; background: rgba(43,36,64,.4); display: grid; place-items: center; }
.ask-card { background: #fff8dc; border: 6px solid #ffe08a; border-radius: 34px; padding: 26px 34px; display: grid; gap: 20px; justify-items: center; animation: rise .35s cubic-bezier(.2,1.5,.4,1); }
.ask-art svg { width: 90px; height: 90px; fill: none; stroke: #f0a500; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.ask-row { display: flex; gap: 26px; }
