:root {
  --bg-cream: #fff8f1;
  --bg-blush: #ffe9ee;
  --panel: #ffffff;
  --panel-2: #fff7f4;
  --pink: #ff8fab;
  --pink-deep: #e8608a;
  --mint: #8fe0bb;
  --mint-deep: #3fae7f;
  --lavender: #c9b6f2;
  --gold: #f0b429;
  --gold-deep: #c98a0e;
  --ink: #4a3b4e;
  --ink-soft: #6b5b70;
  --muted: #9c8ca0;
  --good: #3fb871;
  --bad: #e8546b;
  --radius: 18px;
  --shadow: 0 14px 34px rgba(232,140,171,.22);
  --maxw: 720px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow-x: hidden; width: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Tahoma, Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -10%, #fff1de 0%, transparent 45%),
    radial-gradient(circle at 100% 15%, #ffe3ec 0%, transparent 45%),
    linear-gradient(180deg, var(--bg-cream), var(--bg-blush) 70%, #ffe0e8);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
#app { width: 100%; max-width: 100vw; }
img, canvas, svg { max-width: 100%; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- Header ---------- */
#appHeader {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(232,96,138,.14);
  box-shadow: 0 2px 14px rgba(232,140,171,.12);
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brandLogo { width: 40px; height: 40px; border-radius: 50%; object-fit: contain; box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(232,96,138,.25); flex-shrink: 0; }
.brandText { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brandTitle { font-weight: 800; font-size: 17px; color: var(--pink-deep); letter-spacing: .3px; white-space: nowrap; }
.brandSub { font-size: 11px; color: var(--muted); white-space: nowrap; }
#headerRight { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
#playerBadge {
  font-size: 12px;
  background: var(--bg-blush);
  border: 1px solid rgba(232,96,138,.25);
  padding: 6px 10px;
  border-radius: 20px;
  color: var(--ink-soft);
  font-weight: 600;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#livesBadge {
  font-size: 13px;
  background: var(--bg-blush);
  border: 1px solid rgba(232,96,138,.25);
  padding: 5px 10px;
  border-radius: 20px;
  color: var(--pink-deep);
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: .5px;
}
.muteBtn {
  cursor: pointer;
  border: 1px solid rgba(232,96,138,.25);
  background: var(--bg-blush);
  color: var(--pink-deep);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease;
}
.muteBtn:hover { transform: scale(1.08); }

/* ---------- Buttons ---------- */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-size: 15px;
  font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
  font-family: inherit;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.98); }
.btnPrimary {
  background: linear-gradient(135deg, #ff9ebb, var(--pink-deep));
  color: #fff;
  box-shadow: 0 8px 20px rgba(232,96,138,.35);
}
.btnGhost {
  background: #ffffff;
  color: var(--ink-soft);
  border: 1.5px solid rgba(232,96,138,.28);
}
.btnGhost:hover { border-color: var(--pink-deep); }
.btnBlock { width: 100%; margin-top: 10px; }
.hidden { display: none !important; }

/* ---------- Screens ---------- */
#stage {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 26px 14px 40px;
}
.screen { display: none; width: 100%; max-width: var(--maxw); }
.screen.active { display: flex; flex-direction: column; align-items: center; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.loader {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(232,96,138,.18);
  border-top-color: var(--pink-deep);
  animation: spin 1s linear infinite;
  margin: 60px auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#screen-loading { text-align: center; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(232,96,138,.14);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
  width: 100%;
  text-align: center;
}
.card.narrow { max-width: 440px; }
.card.wide { max-width: 640px; }
.cardLogo { width: 64px; height: 64px; border-radius: 50%; margin-bottom: 6px; box-shadow: 0 0 0 4px #fff, 0 0 0 5px rgba(232,96,138,.2); }
.card h1 { margin: 6px 0 4px; font-size: 26px; color: var(--pink-deep); }
.card h2 { margin: 4px 0 6px; font-size: 22px; color: var(--pink-deep); }
.muted { color: var(--muted); font-size: 14px; line-height: 1.55; }
.legal { font-size: 11px; color: #b6a4b8; margin-top: 18px; }

/* ---------- Form ---------- */
#registerForm { text-align: left; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--ink-soft); }
.field input {
  font-size: 15px;
  padding: 12px 13px;
  border-radius: 10px;
  border: 1.5px solid rgba(232,96,138,.2);
  background: #fffdfb;
  color: var(--ink);
  font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--pink-deep); box-shadow: 0 0 0 3px rgba(232,96,138,.15); }
.fieldError { color: var(--bad); min-height: 14px; font-size: 12px; }
.checkField { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 16px; line-height: 1.4; }
.checkField input { margin-top: 3px; }

/* ---------- Home / Levels ---------- */
.homeWrap { width: 100%; text-align: center; }
.homeWrap h2 { color: var(--pink-deep); margin-bottom: 4px; }
.levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.levelCard {
  background: #ffffff;
  border: 1px solid rgba(232,96,138,.16);
  border-left: 5px solid var(--mint);
  border-radius: 14px;
  padding: 18px 14px;
  text-align: left;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(232,140,171,.12);
}
.levelCard:hover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(232,140,171,.22); }
.levelCard .num { font-size: 12px; color: var(--pink-deep); font-weight: 800; letter-spacing: 1px; }
.levelCard h3 { margin: 4px 0 6px; font-size: 17px; color: var(--ink); }
.levelCard p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.levelCard .badge { display: inline-block; margin-top: 10px; font-size: 11px; padding: 3px 9px; border-radius: 20px; }
.badge { background: var(--bg-blush); color: var(--pink-deep); border: 1px solid rgba(232,96,138,.25); }
.levelCard.done { border-left-color: var(--good); }
.levelCard.done::after { content: "✓ Cleared"; position: absolute; top: 12px; right: 12px; font-size: 11px; color: var(--good); font-weight: 700; }
.homeActions { margin-top: 22px; }

/* ---------- Intro ---------- */
.levelTag { display: inline-block; background: var(--bg-blush); color: var(--pink-deep); padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; letter-spacing: .5px; }
.difficultyRow { margin: 8px 0; }
.howBox { text-align: left; background: #fff6f2; border: 1px solid rgba(232,96,138,.12); border-radius: 10px; padding: 14px 16px; margin: 14px 0; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.howBox ul { margin: 0; padding-left: 18px; }
.livesNote {
  font-size: 13px;
  font-weight: 700;
  color: var(--pink-deep);
  background: var(--bg-blush);
  border: 1px solid rgba(232,96,138,.25);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 10px 0;
  letter-spacing: .5px;
}
.homeLivesBanner {
  width: 100%;
  background: rgba(232,84,107,.08);
  border: 1px solid rgba(232,84,107,.3);
  color: #c23f5f;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 16px;
  text-align: left;
}

/* ---------- Game screen ---------- */
#screen-game { align-items: center; }
.gameTopBar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  width: 100%;
  max-width: 440px;
  font-size: 13px;
  font-weight: 700;
  color: var(--pink-deep);
  margin-bottom: 8px;
  padding: 0 4px;
}
.gameLivesLabel { flex-basis: 100%; text-align: center; font-size: 12px; order: 3; }
#gameContainer {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Coupon card ---------- */
.celebrate .confettiTop { font-size: 26px; letter-spacing: 6px; margin-bottom: 4px; }
.couponCard {
  margin: 18px 0;
  background: repeating-linear-gradient(135deg, #fff6e9, #fff6e9 12px, #fff0da 12px, #fff0da 24px);
  border: 2px dashed var(--gold-deep);
  border-radius: 14px;
  padding: 20px 18px;
  position: relative;
}
.couponCard.grand { border-color: var(--gold); box-shadow: 0 0 24px rgba(240,180,41,.25); }
.couponBadge {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #3a2600;
  font-weight: 800;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.couponCard h3 { margin: 4px 0; color: var(--ink); font-size: 17px; }
.couponCard p { color: var(--ink-soft); font-size: 13px; margin: 6px 0; }
.couponCode {
  font-family: 'Courier New', monospace;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--gold-deep);
  background: rgba(255,255,255,.6);
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0 6px;
}
.couponTerms { font-size: 10.5px; color: #a4906a; line-height: 1.4; }
.voidNote {
  font-size: 12px;
  color: #c23f5f;
  background: rgba(232,84,107,.08);
  border: 1px solid rgba(232,84,107,.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin: -6px 0 12px;
  line-height: 1.4;
}
.voidNote:empty { display: none; margin: 0; padding: 0; border: none; }
.copyRow { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 4px; }
.copyMsg { font-size: 12px; color: var(--good); min-width: 60px; text-align: left; }

.summaryHeading { color: var(--pink-deep); font-size: 15px; margin: 22px 0 10px; text-align: left; }
.couponSummaryList { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.miniCoupon {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff6f2;
  border: 1px solid rgba(232,96,138,.16);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
}
.miniCoupon .mcLeft { display: flex; flex-direction: column; }
.miniCoupon .mcLevel { font-size: 11px; color: var(--muted); }
.miniCoupon .mcPrize { color: var(--pink-deep); font-weight: 700; }
.miniCoupon .mcCode { font-family: 'Courier New', monospace; font-size: 12px; color: var(--ink); background: rgba(232,96,138,.08); padding: 4px 8px; border-radius: 6px; }

/* ---------- Footer ---------- */
#appFooter {
  text-align: center;
  padding: 20px 12px 26px;
  color: #b6a4b8;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.footerLogo { width: 30px; height: 30px; border-radius: 50%; opacity: .9; }

/* ---------- Generic game UI helpers (used by level modules) ---------- */
.gcCanvasWrap { position: relative; width: 100%; display: flex; justify-content: center; }
.gcCanvasWrap canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 60vh;
  display: block;
  margin: 0 auto;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.gcHint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------- Cake rotate-puzzle (Gift Box Pick) ---------- */
.puzzleWrap { display: flex; flex-direction: column; align-items: center; width: 100%; }
.puzzlePreview { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 14px; }
.puzzlePreviewImg {
  width: 74px;
  height: 74px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(232,96,138,.3), var(--shadow);
}
.puzzlePreviewLabel { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.puzzleGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  /* Tiles are 1:1, so width also drives height — bound by viewport height
     too, not just width, so the full 3x3 grid always fits without scroll. */
  width: min(100%, 54vh, 340px);
  margin: 0 auto;
}
.puzzleTile {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid #fff;
  box-shadow: 0 6px 14px rgba(232,140,171,.28);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .2s ease, border-color .2s ease;
}
.puzzleTile:hover { box-shadow: 0 8px 18px rgba(232,140,171,.4); }
.puzzleTile.solved { border-color: var(--good); box-shadow: 0 0 0 2px rgba(63,184,113,.35), 0 6px 14px rgba(63,184,113,.25); }
.puzzleGrid.celebrate .puzzleTile { animation: puzzleCelebrate 1s ease-in-out infinite; }
@keyframes puzzleCelebrate {
  0%, 100% { box-shadow: 0 0 0 2px rgba(63,184,113,.35), 0 6px 14px rgba(63,184,113,.25); }
  50% { box-shadow: 0 0 0 4px rgba(240,180,41,.5), 0 8px 20px rgba(240,180,41,.4); }
}

.giftGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; width: 100%; }
.giftBox {
  aspect-ratio: 1;
  background: linear-gradient(160deg, var(--pink), var(--pink-deep));
  border-radius: 16px;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(232,140,171,.35);
  transition: transform .15s ease, box-shadow .2s ease;
  user-select: none;
}
.giftBox:hover { transform: translateY(-3px) scale(1.04); }
.giftBox.opened { cursor: default; transform: none; }
.giftBox.opened.good { background: linear-gradient(160deg, #a6e8c4, var(--mint-deep)); }
.giftBox.opened.bad { background: linear-gradient(160deg, #d9cfe0, #8f7f96); }
.giftBox.hint {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(240,180,41,.3), 0 0 26px 8px rgba(240,180,41,.55);
  animation: giftPulse 0.9s ease-in-out infinite;
}
@keyframes giftPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@media (max-width: 420px) {
  .giftGrid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .giftBox { font-size: 38px; border-radius: 12px; }
}

.memoryGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  /* Cards use aspect-ratio, so height tracks width — bound width by
     viewport height too (not just width) so the whole 4x3 grid always
     fits on screen without needing to scroll to reach the bottom row. */
  width: min(100%, 56vh, 420px);
  margin: 0 auto;
}
.memCard {
  aspect-ratio: 3/4;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--lavender), #a892e0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 6vh, 26px);
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(120,90,160,.25);
  user-select: none;
  transition: transform .12s ease;
}
.memCard.flipped, .memCard.matched { background: linear-gradient(160deg, #fff8ea, #ffe9b8); color: #3a2600; }
.memCard.matched { opacity: .55; cursor: default; }

.progressBarOuter { width: 100%; height: 10px; background: rgba(232,96,138,.1); border-radius: 20px; overflow: hidden; margin-top: 10px; }
.progressBarInner { height: 100%; background: linear-gradient(90deg, var(--pink-deep), var(--gold)); width: 0%; transition: width .25s ease, background .3s ease; }

@media (max-width: 480px) {
  .card { padding: 22px 18px 18px; }
  .brandTitle { font-size: 15px; }
  #stage { padding: 16px 10px 28px; }
  .gameTopBar { flex-wrap: wrap; gap: 4px; }
}

@media (max-width: 360px) {
  #appHeader { padding: 8px 10px; }
  .brandLogo { width: 32px; height: 32px; }
  .brandSub { display: none; }
  #playerBadge { max-width: 32vw; font-size: 11px; padding: 5px 8px; }
  .muteBtn { width: 30px; height: 30px; font-size: 13px; }
  #livesBadge { font-size: 12px; padding: 4px 8px; }
}

/* Belt-and-braces: nothing in the app should ever be able to force a
   horizontal scrollbar, regardless of screen size or content length. */
#stage, .screen, .card, #gameContainer, .levelGrid, .puzzleWrap {
  max-width: 100%;
}
