:root {
  --bg1: #ffe3f1;
  --bg2: #dff1ff;
  --ink: #4a2c55;
  --pink: #ff6fae;
  --pink-d: #e04d8f;
  --blue: #5bb8ff;
  --blue-d: #3a95dd;
  --yellow: #ffd24a;
  --yellow-d: #e9b520;
  --card: #ffffff;
  --shadow: 0 6px 0 rgba(74, 44, 85, .15), 0 10px 24px rgba(74, 44, 85, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  overflow-x: hidden;
  user-select: none;
}

.screen { display: none; min-height: 100vh; padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
.screen.active { display: block; animation: pop-in .35s ease; }
@keyframes pop-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 18px; color: #fff;
  border: 0; border-radius: 999px; padding: 10px 22px; cursor: pointer;
  background: var(--blue); box-shadow: 0 5px 0 var(--blue-d);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-d); }
.btn.pink { background: var(--pink); box-shadow: 0 5px 0 var(--pink-d); }
.btn.pink:active { box-shadow: 0 1px 0 var(--pink-d); }
.btn.yellow { background: var(--yellow); color: var(--ink); box-shadow: 0 5px 0 var(--yellow-d); }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 #e2d3e8; }
.btn.big { font-size: 28px; padding: 14px 48px; }
.btn.small { font-size: 16px; padding: 6px 14px; }

/* ---------- Home ---------- */
#home { text-align: center; padding-top: 28px; }
.logo { margin: 0; line-height: 1; font-size: clamp(38px, 9vw, 64px); font-weight: 800; letter-spacing: -1px; }
.logo .l1 { color: var(--pink); }
.logo .l2 { color: var(--blue); }
.logo .amp { color: var(--yellow-d); }
.logo .l3 { font-size: .7em; color: var(--ink); display: inline-block; transform: rotate(-3deg); }
.duo { display: flex; justify-content: center; gap: 18px; margin: 22px 0 10px; }
.avatar { border-radius: 50%; background-size: cover; background-position: center; border: 5px solid #fff; box-shadow: var(--shadow); flex: none; }
.avatar.lily { background-image: url(photos/lily.jpg?v=2); }
.avatar.bobo { background-image: url(photos/bobo.jpg?v=2); }
.avatar.big { width: 130px; height: 130px; }
.avatar.small { width: 54px; height: 54px; border-width: 3px; }
.bounce { animation: bounce 1.6s ease-in-out infinite; }
.bounce.delay { animation-delay: .4s; }
@keyframes bounce { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }

.bubble {
  position: relative; display: inline-block; background: #fff; border-radius: 20px;
  padding: 10px 16px; font-size: 18px; font-weight: 600; box-shadow: var(--shadow); max-width: 100%;
}
.bubble::after {
  content: ''; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  border: 10px solid transparent; border-top: 0; border-bottom-color: #fff;
}
.bubble.left::after { top: 50%; left: -10px; transform: translateY(-50%); border: 10px solid transparent; border-left: 0; border-right-color: #fff; }
.bubble.talk { animation: wiggle .4s ease; }
@keyframes wiggle { 25% { transform: rotate(-2deg) scale(1.03); } 75% { transform: rotate(2deg) scale(1.03); } }

.menu { display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 26px; }
.tiny { opacity: .6; font-size: 14px; margin-top: 26px; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.topbar h2 { margin: 0; font-size: clamp(20px, 5vw, 28px); text-align: center; flex: 1; }
.stars-total, .stat { background: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 700; box-shadow: var(--shadow); white-space: nowrap; font-size: 15px; }

/* ---------- Level map ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 14px; }
.legend span { background: #fff8; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 14px; }
.lvl {
  position: relative; aspect-ratio: 1; border-radius: 22px; background-size: cover; background-position: center;
  box-shadow: var(--shadow); cursor: pointer; overflow: hidden; border: 4px solid #fff; transition: transform .15s;
}
.lvl:hover { transform: translateY(-3px) rotate(-1deg); }
.lvl .num { position: absolute; top: 4px; left: 6px; background: var(--pink); color: #fff; font-weight: 800; border-radius: 999px; min-width: 30px; text-align: center; padding: 0 6px; }
.lvl .kind { position: absolute; top: 4px; right: 6px; font-size: 20px; filter: drop-shadow(0 1px 1px #0006); }
.lvl .st { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; background: #fffd; font-size: 14px; letter-spacing: 1px; }
.lvl.locked { cursor: not-allowed; }
.lvl.locked::after { content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; background: #ffffffb0; backdrop-filter: blur(4px); }
.lvl.current { border-color: var(--yellow); animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px #ffd24a88, var(--shadow); } }

/* ---------- Game ---------- */
.game-type { text-align: center; font-weight: 700; font-size: 17px; margin-bottom: 8px; }
.play-area { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.board {
  position: relative; background: #fff; border-radius: 16px; padding: 6px; box-shadow: var(--shadow);
  touch-action: none;
}
.board-inner { position: relative; width: 100%; height: 100%; border-radius: 10px; overflow: hidden; background: #f4e8f8; }
.tile {
  position: absolute; background-repeat: no-repeat; cursor: pointer;
  transition: left .15s ease, top .15s ease, transform .2s ease, outline-color .1s;
  outline: 1px solid #ffffff88; outline-offset: -1px;
}
.tile.selected { outline: 4px solid var(--pink); z-index: 2; transform: scale(.94); }
.tile.correct-flash { animation: flash .4s; }
@keyframes flash { 50% { filter: brightness(1.35); } }
.board.solved .tile { outline-color: transparent; }
.board.solved { animation: solved-pop .5s ease; }
@keyframes solved-pop { 50% { transform: scale(1.04) rotate(1deg); } }
.ghost-img { position: absolute; inset: 0; background-size: cover; opacity: .18; }
.slot { position: absolute; border: 1px dashed #c9a8d6; }

/* jigsaw tray */
.tray {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 10px; min-height: 70px;
  background: #ffffffaa; border-radius: 16px; box-shadow: var(--shadow); width: 100%;
}
.piece { border-radius: 6px; box-shadow: 0 2px 4px #0003; cursor: grab; touch-action: none; background-repeat: no-repeat; }
.piece.dragging { position: fixed; z-index: 1000; cursor: grabbing; box-shadow: 0 10px 20px #0005; transform: scale(1.1); pointer-events: none; }
.piece.placeholder { opacity: .2; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* memory */
.mem-grid { display: grid; gap: 8px; }
.mem-card { aspect-ratio: 1; perspective: 600px; cursor: pointer; }
.mem-card .in { position: relative; width: 100%; height: 100%; transition: transform .4s; transform-style: preserve-3d; }
.mem-card.flip .in, .mem-card.done .in { transform: rotateY(180deg); }
.mem-card .face { position: absolute; inset: 0; border-radius: 12px; backface-visibility: hidden; box-shadow: var(--shadow); }
.mem-card .back { background: linear-gradient(135deg, var(--pink), var(--blue)); display: grid; place-items: center; font-size: clamp(22px, 6vw, 36px); color: #fff; border: 3px solid #fff; }
.mem-card .front { background-size: cover; background-position: center; transform: rotateY(180deg); border: 3px solid #fff; }
.mem-card.done .front { border-color: var(--yellow); }

.tools { display: flex; justify-content: center; gap: 12px; margin: 16px 0 8px; }
.chat { display: flex; align-items: center; gap: 14px; justify-content: center; margin-top: 8px; }
.chat .bubble { font-size: 16px; }

/* ---------- Album ---------- */
.hint-text { text-align: center; margin: 0 0 12px; opacity: .75; }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.album-item { background: #fff; padding: 6px 6px 2px; border-radius: 10px; box-shadow: var(--shadow); cursor: pointer; transform: rotate(var(--r, 0deg)); transition: transform .15s; }
.album-item:hover { transform: rotate(0) scale(1.04); }
.album-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; }
.album-item p { margin: 4px 0; text-align: center; font-weight: 700; font-size: 14px; }
.album-item.locked img { filter: blur(10px) grayscale(.6); }
.album-item.locked { cursor: default; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; background: #4a2c5599; display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal.open { display: flex; }
.card { background: var(--card); border-radius: 26px; padding: 18px; text-align: center; max-width: 440px; width: 100%; box-shadow: var(--shadow); animation: pop-in .3s ease; max-height: 94vh; overflow-y: auto; }
.card img { width: 100%; border-radius: 16px; display: block; }
.card h2 { margin: 2px 0 8px; font-size: 30px; color: var(--pink); }
.caption { font-weight: 700; font-size: 18px; margin: 8px 0; }
.win-stars { font-size: 44px; letter-spacing: 6px; }
.win-stars span { display: inline-block; animation: star-in .5s backwards; }
.win-stars span.off { filter: grayscale(1); opacity: .3; }
@keyframes star-in { from { transform: scale(0) rotate(-180deg); } }
.row { display: flex; justify-content: center; gap: 12px; margin-top: 14px; }
.chat.in-modal { justify-content: flex-start; text-align: left; }
.photo-view img { max-height: 70vh; object-fit: contain; }

.peek { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: #4a2c55aa; z-index: 40; }
.peek.open { display: flex; }
.peek img { max-width: min(90vw, 520px); border-radius: 16px; border: 6px solid #fff; animation: pop-in .2s; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }

@media (max-width: 420px) {
  .avatar.big { width: 104px; height: 104px; }
  .level-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .album-grid { grid-template-columns: repeat(2, 1fr); }
}
