:root {
  color-scheme: dark;
  --page: #1f1026;
  --cream: #fff0dc;
  --muted: #dfc1ce;
  --pink: #f7aebd;
  --gold: #ffd69e;
  --line: #ad829555;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: var(--cream);
  background: var(--page);
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 30% -15%, #54243d, transparent 65%),
    radial-gradient(ellipse at 85% 100%, #371730, transparent 52%), var(--page);
}
button, progress { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
button:disabled { cursor: default; opacity: .55; }
[hidden] { display: none !important; }
.shell { width: min(1090px, calc(100% - 64px)); margin-inline: auto; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
}
.brand, .top-actions, .game-actions { display: flex; align-items: center; gap: .55rem; }
.brand {
  gap: .75rem;
  font-family: Georgia, serif;
  font-size: 1.08rem;
  font-weight: 700;
}
.brand-icon {
  display: grid;
  place-items: center;
  width: 2.05rem;
  height: 2.05rem;
  flex: 0 0 auto;
  border: 1px solid #f4a4bb86;
  border-radius: 50%;
  background: #f4a4bb1a;
  color: var(--pink);
  font: 1.18rem/1 Georgia, serif;
}
.quiet {
  min-height: 44px;
  padding: .48rem .76rem;
  border: 1px solid #cd9cad63;
  border-radius: 8px;
  background: #f4aec00b;
  color: var(--cream);
  font-size: .875rem;
  font-weight: 700;
  white-space: nowrap;
  touch-action: manipulation;
}
.quiet:hover:not(:disabled) { background: #f4aec025; border-color: #cd9cadac; }
.sound { display: flex; align-items: center; justify-content: center; gap: .4rem; }
#sound-icon { color: var(--pink); font-size: 1rem; line-height: 1; }
.shop {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  gap: 16px;
  padding-block: clamp(20px, 3.3vw, 43px);
}
.gift, .game-panel { border: 1px solid var(--line); border-radius: 21px; }
.gift {
  position: relative;
  display: flex;
  min-height: 500px;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  text-align: center;
  isolation: isolate;
  background: #371a35;
  box-shadow: 0 14px 40px #120a1a5c;
}
.gift::before, .gift::after {
  position: absolute;
  z-index: -1;
  content: "";
  inset: 0;
}
.gift::before {
  background: url("sweet-shop.webp") 51% 54% / cover no-repeat;
}
.gift::after {
  background: linear-gradient(180deg, #361831 0%, #381a34f0 17%, #3a1c35a6 28%, #341b3500 46%, #341b3500 63%, #2f142dd9 90%, #2c142e 100%);
}
.gift-copy { padding: 48px 17px 0; }
.dedication, .chapter-count {
  margin: 0;
  color: var(--gold);
  font-size: .875rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.dedication span { color: var(--pink); margin-inline: .24rem; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; }
h1 {
  margin: 15px 0 0;
  font-size: clamp(2rem, 4.3vw, 3.9rem);
  line-height: .98;
  font-weight: 700;
  letter-spacing: -.062em;
  text-shadow: 0 2px 15px #281128b8;
}
h1 em {
  display: inline-block;
  margin-top: .1em;
  color: var(--pink);
  font-weight: 500;
  font-size: 1.1em;
}
.gift-footer { padding: 22px 20px 28px; }
.gift-footer p { margin: 0 0 10px; font-weight: 700; }
.gift-signature { color: var(--gold); font: italic 1.07rem Georgia, serif; }
.gift-signature span { color: var(--pink); margin-inline-end: .3rem; font-size: .8em; }

.game-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
  padding: clamp(16px, 2.3vw, 27px);
  background: linear-gradient(153deg, #4a2441, #32172f 68%);
  box-shadow: 0 14px 40px #120a1a5c, inset 0 1px #ffc4d219;
}
.game-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: .4rem; }
.game-heading h2 {
  margin: 3px 0 2px;
  font-size: clamp(1.55rem, 2.7vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: -.045em;
  text-wrap: balance;
}
.level-steps { display: flex; gap: 6px; padding-block: 0 8px; }
.level-steps span {
  width: 9px;
  height: 9px;
  border: 1px solid #dca8b780;
  border-radius: 50%;
  background: #f6bac410;
}
.level-steps .done { background: #f8b5c4; border-color: #f8b5c4; }
.level-steps .current { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 9px #ffca9680; }
.game-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.game-stats div {
  display: grid;
  place-content: center;
  gap: 2px;
  min-height: 57px;
  border: 1px solid #d6a0b343;
  border-radius: 10px;
  background: #25102279;
  text-align: center;
}
.game-stats span { color: var(--muted); font-size: .875rem; }
.game-stats strong {
  font-size: clamp(1.18rem, 2.45vw, 1.48rem);
  line-height: 1.04;
  font-variant-numeric: tabular-nums;
}
.game-stats div:nth-child(2) strong { color: var(--gold); }
progress {
  display: block;
  flex: 0 0 5px;
  width: 100%;
  height: 5px;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  appearance: none;
  background: #1c0e24;
}
progress::-webkit-progress-bar { background: #1c0e24; }
progress::-webkit-progress-value {
  border-radius: 20px;
  background: linear-gradient(90deg, #f696b4, #ffcf96);
  transition: width 260ms ease;
}
progress::-moz-progress-bar { border-radius: 20px; background: linear-gradient(90deg, #f696b4, #ffcf96); }
.board-frame {
  width: min(100%, 442px);
  margin-inline: auto;
  padding: clamp(6px, 1.2vw, 10px);
  border: 1px solid #d8a0b069;
  border-radius: 15px;
  background: #241021;
  box-shadow: inset 0 1px #ffcde41b, 0 5px 14px #1c0a225f;
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(3px, .55vw, 5px);
  overflow: hidden;
  border-radius: 8px;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #c887a32d;
  border-radius: clamp(5px, .77vw, 9px);
  background: #431f3c;
  -webkit-tap-highlight-color: transparent;
}
.cell.alt { background: #391b36; }
.cell:hover { border-color: #efb7c988; }
.cell:focus-visible { outline-offset: -3px; z-index: 1; }
.cell.moving { z-index: 2; }
.cell.selected, .cell.hinted { border-color: var(--gold); background: #67364f; }
.cell.selected { box-shadow: inset 0 0 0 1px var(--gold); }
.cell.hinted { box-shadow: 0 0 7px #ffce8e91 inset; animation: glimmer 1s ease-in-out infinite alternate; }
.cell .candy { width: 100%; height: 100%; pointer-events: none; }
.candy { display: flex; justify-content: center; align-items: center; }
@keyframes glimmer { to { box-shadow: 0 0 14px #ffce8ed0 inset; } }
.game-footer { display: flex; min-height: 44px; gap: 6px 10px; align-items: center; justify-content: space-between; }
.game-footer p { margin: 0; color: var(--muted); font-size: .875rem; line-height: 1.25; }
.game-actions { gap: .4rem; }
.game-actions .quiet { padding-inline: .65rem; }

dialog {
  width: min(430px, calc(100% - 30px));
  max-height: calc(100% - 36px);
  overflow: auto;
  padding: clamp(22px, 6vw, 40px);
  color: var(--cream);
  border: 1px solid #f0b3c17d;
  border-radius: 20px;
  background: radial-gradient(ellipse at top, #66334f, #341b37 75%);
  box-shadow: 0 18px 90px #160b1bbd;
  text-align: center;
}
dialog::backdrop { background: #180c21c8; backdrop-filter: blur(4px); }
.dialog-sparkle { margin-bottom: 9px; color: var(--pink); font: 2.35rem/1 Georgia, serif; }
dialog h2 { margin: .45rem 0 .7rem; font-size: clamp(1.7rem, 6vw, 2.55rem); letter-spacing: -.038em; text-wrap: balance; }
dialog p:not(.chapter-count) { margin-block: .7rem; color: var(--muted); font-size: 1rem; line-height: 1.5; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .65rem; margin-top: 1.35rem; }
.primary {
  min-height: 44px;
  padding: .55rem 1.1rem;
  border: 1px solid #ffdfd3;
  border-radius: 8px;
  background: #f9bec5;
  color: #391831;
  font-weight: 800;
  touch-action: manipulation;
}
.primary:hover { background: #ffdad3; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (max-height: 850px) and (min-width: 761px) and (orientation: landscape) {
  .topbar { min-height: 64px; }
  .shop { padding-block: 18px; }
  .game-panel { gap: 8px; padding: 18px clamp(14px, 2.2vw, 23px); }
  .game-stats div { min-height: 50px; }
  .board-frame {
    width: min(100%, clamp(314px, calc(100vh - 320px), 442px));
    width: min(100%, clamp(314px, calc(100svh - 320px), 442px));
  }
}
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) {
  .shell { width: min(540px, calc(100% - 24px)); }
  .topbar { min-height: 57px; }
  .brand { gap: .4rem; font-size: .9rem; line-height: 1.05; }
  .brand-icon { width: 1.65rem; height: 1.65rem; font-size: .95rem; }
  .top-actions .quiet { padding-inline: .5rem; }
  .shop { grid-template-columns: minmax(0, 1fr); gap: 9px; padding-block: 10px 18px; }
  .gift { min-height: 112px; justify-content: center; text-align: left; border-radius: 14px; }
  .gift::before { background-size: cover; background-position: 63% 60%; }
  .gift::after { background: linear-gradient(90deg, #38192ffb 0%, #38192fd5 50%, #38192f1c 92%); }
  .gift-copy { padding: 12px 14px; }
  .gift-footer { display: none; }
  h1 { margin-top: 7px; font-size: clamp(1.58rem, 5.5vw, 2.2rem); }
  .dedication { letter-spacing: .07em; }
  .game-panel { padding: 11px; gap: 8px; border-radius: 14px; }
  .game-stats div { min-height: 48px; }
  .level-steps { padding-block-end: 5px; }
}
@media (min-width: 761px) and (max-width: 1100px) and (orientation: portrait) {
  .shell { width: min(590px, calc(100% - 48px)); }
  .topbar { min-height: 66px; }
  .brand { font-size: 1.08rem; }
  .shop { gap: 12px; padding-block: 16px 24px; }
  .gift { min-height: 140px; }
  .gift-copy { padding-inline: 22px; }
  .game-panel { padding: 18px; }
  .game-stats div { min-height: 57px; }
  .board-frame { width: min(100%, 482px); }
}
@media (max-width: 350px) {
  .shell { width: calc(100% - 16px); }
  .brand { max-width: 105px; }
  .top-actions { gap: .3rem; }
  .top-actions .quiet { padding-inline: .38rem; }
  .game-panel { padding: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
