:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: #21332d;
  --game-max-width: 560px;
  --ink: #20332d;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(96, 144, 92, 0.28);
  --leaf: #4e9b61;
  --leaf-dark: #276642;
  --sun: #f5a623;
  --berry: #d64b6b;
  --sky: #4b9bc8;
  --coral: #ff8f70;
  --mint: #42c79b;
}

html {
  height: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: hidden;
  padding: clamp(6px, 1.4vmin, 14px);
  background-color: #b7e7ff;
  background-image: url("../../assets/seaside-girl-dog-right-bg.png");
  background-position: center bottom;
  background-size: cover;
  background-attachment: fixed;
}

.site-logo-link {
  position: fixed;
  top: clamp(10px, 2vmin, 22px);
  left: clamp(10px, 2vmin, 22px);
  z-index: 3;
  width: clamp(38px, 5vw, 64px);
  aspect-ratio: 1;
  background-color: rgba(255, 255, 255, 0.36);
  background-image: url("../../assets/shiguangdao-logo-transparent.png");
  background-position: center;
  background-size: 82% 82%;
  background-repeat: no-repeat;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(22, 88, 119, 0.12);
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.site-logo-link:hover,
.site-logo-link:focus-visible {
  transform: translateY(-2px) scale(1.06);
  background-color: rgba(255, 255, 255, 0.56);
  box-shadow: 0 14px 28px rgba(22, 88, 119, 0.2);
  outline: none;
}

button,
a {
  font: inherit;
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(100%, var(--game-max-width));
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.2vmin, 10px);
}

.game-top,
.score-row,
.game-guide,
.board-panel,
.control-pad {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(57, 91, 65, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px) saturate(1.08);
}

.game-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.back-link,
.restart-button,
.fullscreen-button,
.overlay button,
.control-pad button {
  border: 1px solid rgba(67, 119, 73, 0.36);
  border-radius: 8px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #f3fbea);
  box-shadow: 0 4px 10px rgba(48, 91, 56, 0.1);
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.back-link,
.restart-button {
  padding: 10px 12px;
  white-space: nowrap;
}

.fullscreen-button {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
}

.fullscreen-button[aria-pressed="true"] {
  color: #114238;
  border-color: rgba(66, 199, 155, 0.58);
  background: linear-gradient(180deg, rgba(221, 255, 238, 0.98), rgba(190, 244, 218, 0.92));
}

.back-link:hover,
.restart-button:hover,
.fullscreen-button:hover,
.fullscreen-button:focus-visible,
.overlay button:hover,
.control-pad button:hover {
  transform: translateY(-1px);
  border-color: rgba(66, 199, 155, 0.65);
  box-shadow: 0 12px 24px rgba(31, 77, 84, 0.16);
}

.title-block {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: clamp(6px, 1.2vmin, 12px);
}

.title-block p {
  margin: 0;
  color: #31594b;
  font-size: clamp(11px, 1.8vmin, 14px);
  text-align: right;
  max-width: 24em;
  padding: clamp(5px, 1vmin, 7px) clamp(7px, 1.3vmin, 10px);
  border: 1px solid rgba(78, 155, 97, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 20px rgba(39, 102, 66, 0.08);
}

.title-block h1 {
  margin: 0;
  color: var(--leaf-dark);
  font-size: clamp(22px, 5vmin, 38px);
  line-height: 1.04;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.72);
}

.score-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(5px, 1vmin, 10px);
  padding: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.score-row div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 252, 240, 0.92)),
    var(--panel);
  box-shadow: 0 14px 34px rgba(57, 91, 65, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.86);
  text-align: center;
}

.score-row span {
  color: #5a7670;
  font-size: 12px;
}

.score-row strong {
  color: #1b3a34;
  font-size: clamp(19px, 3vmin, 26px);
  line-height: 1;
}

.game-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(5px, 1vmin, 8px);
  padding: clamp(6px, 1.2vmin, 10px);
}

.guide-chip {
  min-height: clamp(30px, 4.8vmin, 40px);
  display: grid;
  place-items: center;
  padding: 5px 8px;
  border: 1px solid rgba(78, 155, 97, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(246, 252, 240, 0.86));
  color: rgba(23, 52, 47, 0.82);
  text-align: center;
  font-size: clamp(12px, 1.8vmin, 15px);
  font-weight: 800;
}

.board-panel {
  position: relative;
  align-self: center;
  justify-self: center;
  width: auto;
  height: min(100%, 560px);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  padding: clamp(8px, 1.6vmin, 14px);
}

.board-panel > .fullscreen-button {
  position: absolute;
  top: clamp(8px, 1.5vmin, 14px);
  right: clamp(8px, 1.5vmin, 14px);
  z-index: 10;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px) saturate(1.08);
  transform: translateX(calc(100% + 14px));
}

.board-panel:fullscreen > .fullscreen-button {
  transform: none;
}

.board-panel:fullscreen {
  width: min(calc(100vw - 24px), calc(100dvh - 24px));
  height: min(calc(100dvh - 24px), calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  overflow: hidden;
  border-radius: 10px;
  background-color: rgba(238, 248, 231, 0.96);
  background-image: url("../../assets/seaside-girl-dog-right-bg.png");
  background-position: center bottom;
  background-size: cover;
}

.board-panel:fullscreen::backdrop {
  background-color: #b7e7ff;
  background-image: url("../../assets/seaside-girl-dog-right-bg.png");
  background-position: center bottom;
  background-size: cover;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(7px, 1.4vmin, 12px);
  padding: clamp(7px, 1.4vmin, 12px);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 42%),
    #dce9cb;
  border: 2px solid #9fbe8e;
  outline: 4px solid rgba(255, 255, 255, 0.62);
  box-shadow:
    0 18px 38px rgba(47, 82, 51, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tile {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.52);
  color: #1f332d;
  font-weight: 800;
  font-size: clamp(24px, 7vmin, 52px);
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 8px 16px rgba(42, 76, 80, 0.1);
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
}

.tile:not(:empty) {
  transform: scale(1);
}

.tile[data-value="2"] {
  background: #fff7dd;
}

.tile[data-value="4"] {
  background: #ffe9ba;
}

.tile[data-value="8"] {
  background: #ffc180;
  color: #fff;
}

.tile[data-value="16"] {
  background: #ff9b70;
  color: #fff;
}

.tile[data-value="32"] {
  background: #ff7d7c;
  color: #fff;
}

.tile[data-value="64"] {
  background: #f25f73;
  color: #fff;
}

.tile[data-value="128"],
.tile[data-value="256"],
.tile[data-value="512"] {
  background: #57d7ad;
  color: #07392d;
  font-size: clamp(20px, 5.8vmin, 44px);
}

.tile[data-value="1024"],
.tile[data-value="2048"] {
  background: linear-gradient(135deg, #7df0bf, #ffe27a);
  color: #08352b;
  font-size: clamp(18px, 5vmin, 38px);
}

.overlay {
  position: absolute;
  inset: clamp(8px, 1.6vmin, 14px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  text-align: center;
  backdrop-filter: blur(8px) saturate(1.1);
  animation: result-pop 280ms cubic-bezier(0.2, 1.2, 0.3, 1);
  overflow: hidden;
}

.overlay[hidden] {
  display: none;
}

.overlay.result-success {
  border: 2px solid rgba(78, 155, 97, 0.48);
  box-shadow: 0 18px 38px rgba(47, 82, 51, 0.2), inset 0 0 0 999px rgba(246, 255, 239, 0.2);
}

.overlay.result-success::before,
.overlay.result-success::after,
.overlay.result-fail::before,
.overlay.result-fail::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.overlay.result-success::before {
  background:
    radial-gradient(circle at 18% 22%, #ff805c 0 4px, transparent 5px),
    radial-gradient(circle at 34% 12%, #ffd36a 0 5px, transparent 6px),
    radial-gradient(circle at 58% 18%, #42c79b 0 4px, transparent 5px),
    radial-gradient(circle at 78% 26%, #4b9bc8 0 5px, transparent 6px),
    radial-gradient(circle at 70% 72%, #d64b6b 0 4px, transparent 5px),
    radial-gradient(circle at 25% 78%, #f5a623 0 5px, transparent 6px);
  animation: confetti-burst 1180ms ease-out both;
}

.overlay.result-success::after {
  background:
    linear-gradient(135deg, transparent 0 43%, #ff805c 44% 58%, transparent 59%) 12% -28px / 24px 70px no-repeat,
    linear-gradient(45deg, transparent 0 42%, #ffd36a 43% 57%, transparent 58%) 34% -46px / 22px 78px no-repeat,
    linear-gradient(135deg, transparent 0 42%, #35c999 43% 57%, transparent 58%) 62% -38px / 24px 76px no-repeat,
    linear-gradient(45deg, transparent 0 43%, #1597d3 44% 58%, transparent 59%) 86% -30px / 22px 70px no-repeat;
  animation: result-ribbon-fall 1600ms ease-in-out both;
}

.overlay.result-fail {
  border: 2px solid rgba(245, 166, 35, 0.5);
  background:
    radial-gradient(circle at 50% 118%, rgba(66, 199, 155, 0.2), transparent 52%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 253, 240, 0.82));
  box-shadow: 0 18px 38px rgba(96, 72, 36, 0.2), inset 0 0 0 999px rgba(255, 250, 232, 0.16);
}

.overlay.result-fail::before {
  inset: auto -12% -28%;
  height: 58%;
  border-radius: 999px 999px 0 0;
  background:
    radial-gradient(circle at 22% 38%, rgba(255, 212, 112, 0.42) 0 10px, transparent 11px),
    radial-gradient(circle at 78% 42%, rgba(66, 199, 155, 0.34) 0 11px, transparent 12px),
    linear-gradient(180deg, rgba(255, 245, 204, 0.42), rgba(66, 199, 155, 0.16));
  animation: encourage-card-breathe 2200ms ease-in-out infinite;
}

.overlay.result-fail::after {
  inset: 12% 12% auto;
  height: 45%;
  background:
    radial-gradient(circle at 18% 88%, rgba(66, 199, 155, 0.7) 0 4px, transparent 5px),
    radial-gradient(circle at 38% 72%, rgba(245, 166, 35, 0.72) 0 5px, transparent 6px),
    radial-gradient(circle at 63% 86%, rgba(75, 155, 200, 0.62) 0 4px, transparent 5px),
    radial-gradient(circle at 82% 68%, rgba(255, 143, 112, 0.68) 0 5px, transparent 6px);
  animation: encourage-step-rise 1800ms ease-in-out infinite;
}

.overlay.result-fail strong::after {
  content: "继续加油";
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 8px auto 0;
  padding: 4px 12px;
  border: 1px solid rgba(66, 199, 155, 0.3);
  border-radius: 999px;
  color: #276642;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(229, 255, 238, 0.82));
  box-shadow: 0 6px 14px rgba(66, 199, 155, 0.12);
  font-size: clamp(12px, 2.2vmin, 14px);
  line-height: 1.4;
  animation: encourage-card-breathe 2200ms ease-in-out infinite;
}

.overlay > * {
  position: relative;
  z-index: 1;
}

.overlay strong {
  font-size: clamp(28px, 6vmin, 44px);
  color: #17352e;
}

.overlay p {
  margin: 0;
  color: #456b62;
}

.overlay-actions {
  display: flex;
  gap: 10px;
}

.overlay button {
  padding: 10px 14px;
}

.control-pad {
  justify-self: center;
  width: min(100%, var(--game-max-width));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: clamp(8px, 1.4vmin, 12px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 252, 242, 0.93)),
    var(--panel);
}

.control-pad button {
  min-height: clamp(42px, 7vmin, 54px);
  font-size: clamp(20px, 4vmin, 30px);
  font-weight: 800;
}

@keyframes result-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-burst {
  0% {
    opacity: 0;
    transform: scale(0.72) translateY(18px);
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0.72;
    transform: scale(1.08) translateY(-12px);
  }
}

@keyframes result-ribbon-fall {
  0% {
    opacity: 0;
    transform: translateY(-28px) rotate(-3deg);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0.9;
    transform: translateY(78px) rotate(4deg);
  }
}

@keyframes encourage-card-breathe {
  0%,
  100% {
    opacity: 0.72;
    filter: saturate(1);
  }
  50% {
    opacity: 1;
    filter: saturate(1.12);
  }
}

@keyframes encourage-step-rise {
  0% {
    opacity: 0.16;
    transform: translateY(16px);
  }
  45% {
    opacity: 0.74;
  }
  100% {
    opacity: 0.1;
    transform: translateY(-18px);
  }
}

@media (max-width: 520px) {
  body {
    padding: 6px;
  }

  .game-top {
    grid-template-columns: 1fr auto;
  }

  .title-block {
    align-items: end;
  }

  .game-guide {
    grid-template-columns: 1fr;
  }
}
