:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --cookie-brown: #7a310d;
  --cream: #fff4d8;
  --pink: #f76583;
  --pink-dark: #bb2e43;
  --green: #76b836;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: grid;
  place-items: center;
  background: #1597df;
  overscroll-behavior: none;
  user-select: none;
}

img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

input {
  user-select: text;
  -webkit-touch-callout: default;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 0.22rem solid #fff;
  outline-offset: 0.18rem;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  width: min(100vw, calc(100dvh * 1500 / 2668));
  height: min(100dvh, calc(100vw * 2668 / 1500));
  max-width: 1500px;
  max-height: 2668px;
  overflow: hidden;
  background: #28a8ee url("assets/background/background-candyland.png") center / cover no-repeat;
  box-shadow: 0 0 3rem rgb(15 80 108 / 30%);
  container-type: inline-size;
  isolation: isolate;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
  background: url("assets/background/background-candyland.png") center / cover no-repeat;
}

.screen.is-active {
  display: block;
  animation: screen-in 300ms ease-out both;
}

.image-button {
  appearance: none;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 0.7rem 0.5rem rgb(88 40 14 / 22%));
  transition: transform 120ms ease, filter 120ms ease;
}

.image-button img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.image-button:active {
  transform: translateY(2.5%) scale(0.96);
  filter: drop-shadow(0 0.3rem 0.25rem rgb(88 40 14 / 18%));
}

.start-logo {
  position: absolute;
  z-index: 1;
  top: 8.2%;
  left: 50%;
  width: 82%;
  height: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 1rem 0.8rem rgb(80 35 8 / 22%));
}

.start-loading {
  --loading-progress: 8%;
  position: absolute;
  z-index: 5;
  top: 57%;
  left: 50%;
  display: grid;
  width: 62%;
  gap: 2.2cqw;
  transform: translateX(-50%);
  color: #fff8de;
  font-size: 4.1cqw;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 0.35cqw 0 #8d3f18;
}

.start-loading-track {
  height: 4.2cqw;
  overflow: hidden;
  border: 0.65cqw solid #fff1c4;
  border-radius: 999px;
  background: rgb(117 55 25 / 55%);
  box-shadow: inset 0 0.45cqw 0.8cqw rgb(71 30 14 / 25%);
}

.start-loading-fill {
  width: var(--loading-progress);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #88d04d, #ffe266);
  transition: width 180ms ease;
}

.start-screen.is-loading .start-logo,
.start-screen.is-loading .image-button {
  visibility: hidden;
  pointer-events: none;
}

.start-screen.is-ready .start-loading {
  display: none;
}

.start-actions {
  position: absolute;
  z-index: 2;
  top: 51.5%;
  left: 50%;
  display: flex;
  width: 72%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: clamp(0.55rem, 1.2dvh, 1.2rem);
}

.start-button {
  width: 100%;
}

.start-utility-actions {
  position: absolute;
  z-index: 2;
  right: 4.5%;
  bottom: max(3.8%, env(safe-area-inset-bottom));
  left: 4.5%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.start-utility-button {
  width: 26%;
}

.exit-button {
  position: absolute;
  z-index: 4;
  top: max(1.2%, env(safe-area-inset-top));
  right: 2.6%;
  width: 16.2%;
}

.game-logo {
  position: absolute;
  z-index: 1;
  top: 0.55%;
  left: 50%;
  width: 60.48cqw;
  height: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 0.75rem 0.6rem rgb(80 35 8 / 18%));
}

.mistake-tracker {
  position: absolute;
  z-index: 3;
  top: 19.1%;
  left: 50%;
  display: grid;
  width: max-content;
  grid-template-columns: repeat(3, 12.533cqw);
  gap: 1.067cqw;
  transform: translateX(-50%);
}

.mistake-slot {
  position: relative;
  display: block;
  width: 12.533cqw;
  aspect-ratio: 188 / 185;
}

.mistake-slot-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0.28rem 0.2rem rgb(91 43 12 / 18%));
}

.mistake-cross {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6.8cqw;
  height: auto;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0.16rem 0.1rem rgb(131 21 16 / 24%));
}

.mistake-cross.is-visible {
  animation: mistake-pop 180ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.board {
  position: absolute;
  z-index: 2;
  top: 27.2%;
  left: 50%;
  width: 89.5%;
  aspect-ratio: 1340 / 1354;
  transform: translateX(-50%);
}

.board-art,
.tray-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.board-grid {
  position: absolute;
  top: 8.55%;
  left: 6.75%;
  display: grid;
  width: 86.55%;
  height: 85.7%;
  grid-template-columns: repeat(var(--grid-size, 4), 1fr);
  grid-template-rows: repeat(var(--grid-size, 4), 1fr);
}

.game-screen.is-mode-6 .board-grid {
  top: 8.604%;
  left: 7.425%;
  width: 85.075%;
  height: 84.195%;
}

.sudoku-cell {
  position: relative;
  appearance: none;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 8%;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.sudoku-cell img {
  display: block;
  width: 70%;
  max-height: 70%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 0.35rem 0.28rem rgb(93 45 13 / 20%));
}

.sudoku-cell.is-given {
  cursor: default;
}

.sudoku-cell.is-given img {
  filter: drop-shadow(0 0.28rem 0.22rem rgb(93 45 13 / 18%));
}

.sudoku-cell.is-player img {
  animation: candy-pop 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.sudoku-cell.is-conflict {
  border-radius: 17%;
  background: rgb(255 80 80 / 20%);
  animation: cell-shake 340ms ease-in-out;
}

.candy-tray {
  position: absolute;
  z-index: 3;
  top: 78.3%;
  left: 50%;
  width: 89%;
  aspect-ratio: 1331 / 339;
  transform: translateX(-50%);
}

.candy-options {
  position: absolute;
  top: 12%;
  left: 6.4%;
  display: grid;
  width: 87.2%;
  height: 72%;
  grid-template-columns: repeat(var(--grid-size, 4), 1fr);
  align-items: center;
}

.candy-option {
  position: relative;
  appearance: none;
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 7%;
  border: 0;
  border-radius: 30%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 150ms ease, filter 150ms ease, background-color 150ms ease;
}

.candy-option img {
  display: block;
  width: 76%;
  max-height: 82%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 0.3rem 0.25rem rgb(91 43 12 / 18%));
}

.candy-option[aria-pressed="true"] {
  z-index: 2;
  transform: translateY(-9%) scale(1.12);
  background: rgb(94 190 63 / 62%);
  box-shadow: inset 0 0 0 0.14rem rgb(235 255 210 / 82%);
  filter: drop-shadow(0 0 0.7rem #83eb58);
}

.candy-option[aria-pressed="true"] img {
  filter: drop-shadow(0 0.32rem 0.24rem rgb(50 94 21 / 34%));
}

.game-screen.is-mode-6 .candy-option {
  width: 82%;
  height: auto;
  aspect-ratio: 1;
  justify-self: center;
  padding: 4%;
  border-radius: 28%;
}

.game-screen.is-mode-6 .candy-option img {
  width: 82%;
  max-height: 82%;
}

.toast {
  position: absolute;
  z-index: 8;
  top: 26.5%;
  left: 50%;
  max-width: 82%;
  padding: 0.42em 1em;
  border: 0.12em solid #fff1c4;
  border-radius: 999px;
  background: rgb(103 43 13 / 91%);
  color: #fff8de;
  font-size: clamp(0.78rem, 2.2dvh, 1.25rem);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 0.75rem);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4.2%;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(83 35 32 / 48%);
  backdrop-filter: blur(5px) saturate(0.92);
}

.dialog {
  position: relative;
  display: flex;
  width: 91.6%;
  max-height: 88%;
  overflow: auto;
  flex-direction: column;
  justify-content: center;
  padding: 8cqw 7.2cqw 6.4cqw;
  border: 1.067cqw solid #d97278;
  border-radius: 5.467cqw;
  background: linear-gradient(145deg, rgb(255 253 238 / 97%), rgb(255 232 190 / 97%));
  box-shadow:
    inset 0 0 0 0.8cqw #fff2bd,
    inset 0 0 0 1.25cqw #f6b5b2,
    0 1.067cqw 0 #a94b52,
    0 2.6cqw 4.6cqw rgb(73 27 26 / 36%);
  color: var(--cookie-brown);
  text-align: center;
  animation: dialog-pop 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

#help-modal .dialog {
  max-height: 92%;
  min-height: 0;
  justify-content: flex-start;
  padding: 5.6cqw 5.6cqw 4.8cqw;
}
#leaderboard-modal .dialog { min-height: 48%; }
#exit-modal .dialog { min-height: 35%; }
#failure-modal .dialog,
#complete-modal .dialog { min-height: 43%; }

.dialog-small {
  padding-top: 8cqw;
}

.dialog h2 {
  margin: 0 0 3.8cqw;
  color: #8b3f2c;
  font-size: 6cqw;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.dialog-copy,
.completion-time {
  margin: 3.8cqw 0;
  color: #75422f;
  font-size: 3.733cqw;
  font-weight: 800;
  line-height: 1.48;
  text-wrap: pretty;
}

.leaderboard-dialog {
  max-height: 82%;
  justify-content: flex-start;
  padding: 7cqw 6cqw 5.5cqw;
}

.leaderboard-tabs {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, 1fr);
  gap: 2.2cqw;
}

.leaderboard-tab,
.leaderboard-more,
.leaderboard-submit {
  appearance: none;
  min-height: 9cqw;
  border: 0.45cqw solid #bf6670;
  border-radius: 999px;
  background: #fff5d9;
  color: #8b3f2c;
  font-size: 3.3cqw;
  font-weight: 900;
  cursor: pointer;
}

.leaderboard-tab.is-selected,
.leaderboard-submit {
  border-color: #4d7b28;
  background: linear-gradient(#a9d96a, #70af3f);
  color: #fffce9;
  text-shadow: 0 0.22cqw 0 rgb(57 98 31 / 60%);
}

.leaderboard-status,
.leaderboard-note {
  margin: 2.4cqw 0;
  color: #75422f;
  font-size: 3.05cqw;
  font-weight: 800;
  line-height: 1.35;
}

.leaderboard-list {
  display: grid;
  width: 100%;
  margin: 0;
  padding: 0;
  gap: 1.4cqw;
  list-style: none;
}

.leaderboard-item {
  display: grid;
  min-height: 8.5cqw;
  padding: 1.2cqw 2cqw;
  grid-template-columns: 7cqw minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.5cqw;
  border-radius: 2.2cqw;
  background: rgb(255 255 255 / 62%);
  font-size: 3.1cqw;
  font-weight: 900;
}

.leaderboard-rank {
  display: grid;
  width: 5.7cqw;
  height: 5.7cqw;
  place-items: center;
  border-radius: 50%;
  background: #77ae39;
  color: white;
}

.leaderboard-name {
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-time { color: #bd4d68; }
.leaderboard-empty { padding: 5cqw 2cqw; font-size: 3.2cqw; font-weight: 800; }
.leaderboard-more { width: 100%; margin-top: 2cqw; }
.leaderboard-close-button { margin-top: 3cqw !important; }

.leaderboard-form {
  width: 100%;
  margin: 0 0 4cqw;
  text-align: left;
}

.leaderboard-form label {
  color: #75422f;
  font-size: 3.2cqw;
  font-weight: 900;
}

.nickname-row {
  display: grid;
  margin-top: 1.3cqw;
  grid-template-columns: minmax(0, 1fr) 24cqw;
  gap: 2cqw;
}

.nickname-row input {
  min-width: 0;
  min-height: 9.2cqw;
  padding: 0 3cqw;
  border: 0.45cqw solid #d59a75;
  border-radius: 999px;
  background: #fffdf1;
  color: #75422f;
  font-size: 3.3cqw;
  font-weight: 800;
  outline: none;
}

.nickname-row input:focus { border-color: #70af3f; box-shadow: 0 0 0 0.7cqw rgb(112 175 63 / 22%); }
.leaderboard-submit:disabled { cursor: default; opacity: 0.62; }

.game-copyright {
  position: absolute;
  z-index: 12;
  right: 0;
  bottom: max(0.55%, env(safe-area-inset-bottom));
  left: 0;
  margin: 0;
  color: rgb(255 250 225 / 88%);
  font-size: 2.35cqw;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 0.2cqw 0.3cqw rgb(72 32 18 / 60%);
  pointer-events: none;
}

.help-figure {
  display: flex;
  width: 100%;
  margin: 0;
  flex-direction: column;
  align-items: center;
}

.help-demo {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 0.8cqw;
}

.help-demo-board {
  position: relative;
  width: 72cqw;
  aspect-ratio: 1340 / 1354;
}

.help-board-art,
.help-tray-art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.help-demo-grid {
  position: absolute;
  top: 8.55%;
  left: 6.75%;
  display: grid;
  width: 86.55%;
  height: 85.7%;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.help-target-cell {
  z-index: 1;
  margin: 5%;
  border-radius: 17%;
  background: rgb(115 205 69 / 44%);
  box-shadow: inset 0 0 0 0.8cqw rgb(104 190 55 / 82%), 0 0 2.4cqw rgb(117 221 64 / 65%);
  grid-area: 3 / 1;
}

.help-demo-candy {
  z-index: 2;
  width: 64%;
  max-height: 68%;
  place-self: center;
  object-fit: contain;
  filter: drop-shadow(0 0.35cqw 0.25cqw rgb(91 43 12 / 22%));
}

.help-pos-one { grid-area: 1 / 2; }
.help-pos-two { grid-area: 1 / 4; }
.help-pos-three { grid-area: 2 / 4; }
.help-pos-four { grid-area: 4 / 4; }

.help-demo-tray {
  position: relative;
  width: 75cqw;
  aspect-ratio: 1331 / 339;
}

.help-tray-options {
  position: absolute;
  top: 12%;
  left: 6.4%;
  display: grid;
  width: 87.2%;
  height: 72%;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
}

.help-tray-options span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border-radius: 28%;
}

.help-tray-options span.is-selected {
  background: rgb(102 196 62 / 54%);
  box-shadow: inset 0 0 0 0.65cqw rgb(222 255 202 / 70%);
}

.help-tray-options img {
  display: block;
  width: 72%;
  max-height: 80%;
  object-fit: contain;
  filter: drop-shadow(0 0.3cqw 0.22cqw rgb(91 43 12 / 20%));
}

.help-step {
  position: absolute;
  z-index: 5;
  padding: 1.4cqw 2.2cqw;
  border: 0.6cqw solid #f2c98f;
  border-radius: 3.2cqw;
  background: rgb(255 252 235 / 94%);
  color: #9c311e;
  font-size: 4cqw;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 0.7cqw 0 rgb(170 92 39 / 18%);
}

.help-step-place {
  top: 41%;
  right: 21%;
}

.help-step-pick {
  top: -12%;
  right: 0;
}

.help-hand {
  position: absolute;
  z-index: 6;
  display: block;
  width: 12.8cqw;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 0.55cqw 0.35cqw rgb(93 45 13 / 24%));
}

.help-hand-board {
  top: 61.3%;
  left: 14.8%;
}

.help-hand-tray {
  top: 45.1%;
  left: 36.4%;
}

.help-rule-copy {
  max-width: 28em;
  margin: 2.2cqw 0 3.2cqw;
  color: #75422f;
  font-size: 3.45cqw;
  font-weight: 800;
  line-height: 1.48;
  text-align: center;
  text-wrap: pretty;
}

.cookie-button {
  appearance: none;
  min-width: 43%;
  min-height: 10.2cqw;
  padding: 1.5cqw 2.2cqw;
  border: 0.533cqw solid #aa3e58;
  border-radius: 999px;
  background: linear-gradient(#ff8fa6, #ed5d7c);
  color: #fffce9;
  font-size: 3.733cqw;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0.267cqw 0 rgb(139 41 67 / 68%);
  box-shadow:
    inset 0 0.8cqw 0 rgb(255 255 255 / 38%),
    0 0.8cqw 0 #9b3450;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
}

.cookie-button:active {
  transform: translateY(0.55cqw);
  box-shadow: inset 0 0.65cqw 0 rgb(255 255 255 / 28%), 0 0.2cqw 0 #8a3048;
}

.cookie-button-secondary {
  border-color: #4d7b28;
  background: linear-gradient(#a9d96a, #70af3f);
  text-shadow: 0 0.267cqw 0 rgb(57 98 31 / 68%);
  box-shadow: inset 0 0.8cqw 0 rgb(255 255 255 / 38%), 0 0.8cqw 0 #4a7627;
}

.dialog > .cookie-button {
  align-self: center;
  margin-top: auto;
}

.dialog-actions {
  display: grid;
  width: 100%;
  margin-top: auto;
  grid-template-columns: 1fr 1fr;
  gap: 3.333cqw;
}

.dialog-actions .cookie-button {
  width: 100%;
  min-width: 0;
}

.failure-mark {
  display: grid;
  width: 1.7em;
  height: 1.7em;
  margin: 0 auto 0.2em;
  place-items: center;
  border: 0.1em solid #a42d31;
  border-radius: 50%;
  background: #f26976;
  color: #fff7dd;
  font-size: 7cqw;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -0.12em 0 rgb(137 28 38 / 28%);
}

.completion-time {
  margin: 1.2cqw 0 5.2cqw;
  color: #d0506c;
  font-size: 6.2cqw;
  line-height: 1;
}

@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes candy-pop {
  from { opacity: 0; transform: scale(0.45) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes mistake-pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.55); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4%); }
  50% { transform: translateX(4%); }
  75% { transform: translateX(-2%); }
}

@keyframes dialog-pop {
  from { opacity: 0; transform: translateY(1rem) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
