:root {
  color-scheme: light;
  --ink: #17233f;
  --ink-soft: #45516c;
  --paper: #fffdf1;
  --panel: #ffffff;
  --screen: #a9df67;
  --screen-deep: #7ebd4a;
  --screen-soft: #cdf29a;
  --accent: #f5c543;
  --accent-strong: #e99a2c;
  --pink: #ef4f9c;
  --blue: #5eb6f2;
  --shadow: rgba(23, 35, 63, 0.18);
  --hard-shadow: #30456a;
  --tile-face: #fffef5;
  --tile-edge: #d7e6ba;
  --tray: #27324c;
  --tray-slot: #49637c;
  --board-wash: rgba(255, 255, 255, 0.16);
}

body[data-theme="sunset"] {
  --screen: #ffc777;
  --screen-deep: #e98552;
  --screen-soft: #ffe1a9;
  --accent: #ff775f;
  --accent-strong: #d95545;
  --pink: #da4b87;
  --blue: #397fbf;
  --tile-edge: #f3d3a7;
}

body[data-theme="candy"] {
  --screen: #c6d4ff;
  --screen-deep: #8c9fe7;
  --screen-soft: #e7ecff;
  --accent: #ff8eb8;
  --accent-strong: #df5f92;
  --pink: #ce4fa7;
  --blue: #6e83e5;
  --tile-edge: #deddf7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--screen);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

body {
  min-height: 100svh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #2e4f88;
  outline-offset: 3px;
}

svg {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app {
  position: relative;
  min-height: 100svh;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  min-height: 100svh;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}

.screen.is-active {
  z-index: 2;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.loading-screen {
  padding-bottom: env(safe-area-inset-bottom);
}

#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 42px;
  padding: 32px 22px 26px;
  overflow: hidden;
}

#loading-screen::before,
#loading-screen::after {
  content: "";
  position: absolute;
  left: -8%;
  width: 116%;
  height: 12px;
  background: var(--screen-deep);
  transform: rotate(-3deg);
  opacity: 0.56;
}

#loading-screen::before {
  top: 13%;
}

#loading-screen::after {
  bottom: 17%;
  transform: rotate(2deg);
}

.loading-logo {
  position: relative;
  z-index: 1;
  text-align: center;
}

.loading-logo__small {
  display: inline-block;
  padding: 5px 12px;
  border: 3px solid var(--ink);
  background: var(--accent);
  font-size: 15px;
  font-weight: 900;
  transform: rotate(-2deg);
  box-shadow: 5px 5px 0 var(--ink);
}

.loading-logo h1 {
  margin: 22px 0 0;
  color: var(--paper);
  font-size: clamp(42px, 14vw, 74px);
  line-height: 1;
  letter-spacing: 0;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 8px 8px 0 rgba(23, 35, 63, 0.2);
}

.loading-progress {
  position: relative;
  z-index: 1;
  width: min(84vw, 520px);
}

.loading-progress__track {
  height: 38px;
  padding: 5px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
}

.loading-progress__bar {
  width: 2%;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 180ms ease;
}

.loading-progress p {
  margin: 13px 2px 0;
  text-align: right;
  font-size: 16px;
  font-weight: 900;
  -webkit-text-stroke: 2px var(--paper);
  paint-order: stroke fill;
}

.health-note {
  position: absolute;
  z-index: 1;
  right: 22px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 22px;
  margin: 0;
  text-align: center;
  font-size: clamp(12px, 3.5vw, 15px);
  font-weight: 800;
  line-height: 1.25;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.7);
  paint-order: stroke fill;
}

#menu-screen {
  display: flex;
  flex-direction: column;
  padding:
    max(18px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  background: #171728;
  overflow: hidden;
}

.menu-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #151525 0 68%, #2a3148 68% 100%);
  box-shadow:
    inset 0 0 0 5px rgba(255, 255, 255, 0.06),
    0 10px 0 rgba(0, 0, 0, 0.28);
}

.menu-stage__lights {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.menu-stage__lights span {
  position: absolute;
  top: -12%;
  width: 16%;
  height: 84%;
  background: linear-gradient(180deg, rgba(255, 210, 70, 0.74), rgba(255, 210, 70, 0));
  clip-path: polygon(45% 0, 55% 0, 100% 100%, 0 100%);
  transform-origin: 50% 0;
  animation: lightSweep 3.5s ease-in-out infinite alternate;
}

.menu-stage__lights span:nth-child(1) {
  left: 2%;
  transform: rotate(-11deg);
}

.menu-stage__lights span:nth-child(2) {
  left: 30%;
  height: 72%;
  background: linear-gradient(180deg, rgba(234, 75, 170, 0.72), rgba(234, 75, 170, 0));
  animation-delay: -0.8s;
}

.menu-stage__lights span:nth-child(3) {
  right: 30%;
  height: 72%;
  background: linear-gradient(180deg, rgba(95, 189, 255, 0.62), rgba(95, 189, 255, 0));
  animation-delay: -1.7s;
}

.menu-stage__lights span:nth-child(4) {
  right: 2%;
  transform: rotate(11deg);
  animation-delay: -2.5s;
}

@keyframes lightSweep {
  from {
    opacity: 0.55;
    scale: 0.92 1;
  }
  to {
    opacity: 1;
    scale: 1.08 1;
  }
}

.equalizer {
  position: absolute;
  top: 25%;
  right: 10%;
  left: 10%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  height: 42%;
  padding: 14px 18px 0;
  border: 4px solid #f24eb2;
  background: rgba(18, 24, 42, 0.8);
  box-shadow: 0 0 0 3px rgba(66, 222, 214, 0.4);
}

.equalizer span {
  width: 11%;
  min-width: 16px;
  height: 45%;
  background: #5ef1a1;
  animation: equalize 1s ease-in-out infinite alternate;
}

.equalizer span:nth-child(2) {
  height: 72%;
  animation-delay: -0.25s;
}

.equalizer span:nth-child(3) {
  height: 48%;
  animation-delay: -0.5s;
}

.equalizer span:nth-child(4) {
  height: 86%;
  animation-delay: -0.15s;
}

.equalizer span:nth-child(5) {
  height: 62%;
  animation-delay: -0.7s;
}

.equalizer span:nth-child(6) {
  height: 78%;
  animation-delay: -0.35s;
}

.equalizer span:nth-child(7) {
  height: 52%;
  animation-delay: -0.6s;
}

@keyframes equalize {
  to {
    height: 24%;
    opacity: 0.72;
  }
}

.menu-brand {
  position: absolute;
  z-index: 4;
  top: 7%;
  left: 50%;
  width: min(86%, 450px);
  text-align: center;
  transform: translateX(-50%);
}

.menu-brand p {
  display: inline-block;
  margin: 0 0 8px;
  padding: 5px 12px;
  border: 3px solid var(--ink);
  background: var(--pink);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  transform: rotate(-2deg);
}

.menu-brand h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(40px, 11vw, 68px);
  line-height: 1;
  letter-spacing: 0;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 7px 7px 0 rgba(0, 0, 0, 0.24);
}

.hero-character {
  position: absolute;
  z-index: 2;
  bottom: 8%;
  left: 50%;
  width: min(68%, 380px);
  max-height: 72%;
  object-fit: contain;
  filter: drop-shadow(0 18px 15px rgba(0, 0, 0, 0.3));
  transform: translateX(-50%);
  animation: heroDance 1.25s ease-in-out infinite alternate;
}

@keyframes heroDance {
  from {
    transform: translateX(-50%) translateY(0) rotate(-2deg);
  }
  to {
    transform: translateX(-50%) translateY(-16px) rotate(2deg);
  }
}

.primary-pill {
  position: absolute;
  z-index: 3;
  bottom: 7%;
  left: 50%;
  display: inline-flex;
  min-width: min(64%, 340px);
  min-height: 64px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 26px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(22px, 6vw, 31px);
  font-weight: 900;
  transform: translateX(-50%);
  box-shadow:
    0 7px 0 var(--accent),
    0 11px 0 var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease;
}

.primary-pill::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: -12px;
  left: 10px;
  height: 8px;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 96% 100%, 4% 100%);
}

.primary-pill:hover {
  transform: translateX(-50%) translateY(-2px);
}

.primary-pill:active {
  transform: translateX(-50%) translateY(6px);
  box-shadow:
    0 2px 0 var(--accent),
    0 5px 0 var(--ink);
}

.primary-pill svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
  stroke: none;
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
}

.round-action {
  display: flex;
  min-width: 0;
  min-height: 76px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.round-action__icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.round-action:nth-child(2) .round-action__icon {
  background: var(--accent);
}

.round-action:nth-child(3) .round-action__icon {
  background: #f78bbd;
}

.round-action:active .round-action__icon {
  transform: translateY(4px);
  box-shadow: none;
}

.page-header,
.game-header {
  display: grid;
  align-items: center;
  gap: 12px;
}

.page-header {
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  width: min(100% - 28px, 760px);
  margin: 0 auto;
  padding-top: max(16px, env(safe-area-inset-top));
}

.page-header p,
.game-heading p {
  margin: 0 0 3px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.page-header h1,
.game-heading h1 {
  margin: 0;
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1.1;
  letter-spacing: 0;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}

.icon-button:active {
  transform: translateY(4px);
  box-shadow: none;
}

.icon-button--dark {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 4px 0 rgba(23, 35, 63, 0.28);
}

#levels-screen {
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background:
    linear-gradient(180deg, var(--screen-soft), var(--screen));
}

.level-summary {
  display: grid;
  width: min(100% - 28px, 760px);
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  margin: 20px auto 16px;
  padding: 15px 18px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 6px 0 rgba(23, 35, 63, 0.18);
}

.level-summary div {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.level-summary span {
  font-size: 34px;
  font-weight: 900;
}

.level-summary p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.level-summary div p {
  color: var(--ink);
}

.level-grid {
  display: grid;
  width: min(100% - 28px, 760px);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 13px;
  margin: 0 auto;
  padding-bottom: 14px;
}

.level-button {
  position: relative;
  display: grid;
  min-height: 152px;
  align-content: end;
  gap: 6px;
  padding: 76px 9px 12px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #f6f1d5;
  box-shadow: 0 7px 0 var(--screen-deep);
  text-align: center;
  cursor: pointer;
}

.level-button::before,
.level-button::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 58%;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 7px;
  background: #fff;
  transform: translateX(-50%) rotate(-6deg);
}

.level-button::before {
  top: 24px;
  z-index: 1;
  background: var(--level-accent, var(--accent));
}

.level-button::after {
  top: 13px;
  z-index: 2;
  background:
    center / 78% 78% no-repeat url("../assets/characters/nailong-cheer.png"),
    #fff;
}

.level-button strong {
  position: relative;
  z-index: 3;
  font-size: 20px;
  line-height: 1;
}

.level-button span {
  position: relative;
  z-index: 3;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.level-button:active:not(.is-locked) {
  transform: translateY(6px);
  box-shadow: 0 1px 0 var(--screen-deep);
}

.level-button.is-locked {
  color: #72798a;
  filter: grayscale(0.7);
  opacity: 0.66;
  cursor: not-allowed;
}

.level-button.is-locked::after {
  background:
    center / 46% 46% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10V8a5 5 0 0 1 10 0v2M6 10h12v10H6z' fill='none' stroke='%2372798a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    #fff;
}

.level-button.is-complete::before {
  background: #74c96f;
}

.level-button.is-complete .level-badge {
  position: absolute;
  z-index: 5;
  top: 8px;
  right: 8px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #72d071;
  color: #fff;
}

#game-screen {
  display: flex;
  flex-direction: column;
  padding:
    max(12px, env(safe-area-inset-top))
    12px
    max(10px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    linear-gradient(180deg, var(--screen-soft), var(--screen));
}

.game-header {
  width: min(100%, 760px);
  grid-template-columns: 48px minmax(0, 1fr) auto;
  margin: 0 auto;
}

.game-heading {
  min-width: 0;
}

.game-heading h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-chip {
  display: flex;
  min-width: 84px;
  min-height: 48px;
  flex-direction: column;
  justify-content: center;
  padding: 5px 12px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 4px 0 rgba(23, 35, 63, 0.18);
  text-align: right;
}

.score-chip span {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.score-chip strong {
  font-size: 20px;
  line-height: 1.1;
}

.round-progress {
  width: min(calc(100% - 12px), 740px);
  height: 11px;
  margin: 10px auto 0;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.round-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 260ms ease;
}

.board-wrap {
  position: relative;
  width: min(100%, 690px);
  min-height: 0;
  flex: 1 1 auto;
  align-self: center;
  margin: 0 auto;
}

.board-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 700px;
  height: 710px;
  transform: translate(-50%, -50%) scale(var(--board-scale, 1));
  transform-origin: center;
}

.board-stage::before {
  content: "";
  position: absolute;
  inset: 8% 5%;
  border-radius: 50%;
  background: var(--board-wash);
}

.tile {
  --accent: #f7c948;
  position: absolute;
  z-index: var(--z, 1);
  width: 84px;
  height: 84px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition:
    left 240ms cubic-bezier(0.2, 0.8, 0.25, 1),
    top 240ms cubic-bezier(0.2, 0.8, 0.25, 1),
    filter 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

.tile__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--tile-face);
  box-shadow:
    0 7px 0 var(--tile-edge),
    0 11px 0 rgba(23, 35, 63, 0.12);
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    filter 140ms ease;
}

.tile__face::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 52%);
}

.tile__face::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  left: 5px;
  height: 5px;
  background: var(--accent);
  opacity: 0.88;
}

.tile img {
  position: absolute;
  z-index: 2;
  inset: 4px 3px 7px;
  width: calc(100% - 6px);
  height: calc(100% - 11px);
  object-fit: contain;
  pointer-events: none;
}

.tile:not(.is-covered):hover .tile__face {
  transform: translateY(-4px) scale(1.03);
}

.tile:not(.is-covered):active .tile__face {
  transform: translateY(5px) scale(0.98);
  box-shadow:
    0 2px 0 var(--tile-edge),
    0 3px 0 rgba(23, 35, 63, 0.12);
}

.tile.is-covered {
  cursor: default;
}

.tile.is-covered .tile__face {
  filter: brightness(0.68) saturate(0.72);
}

.tile.is-covered .tile__face::after {
  opacity: 0.35;
}

.tile.is-hint .tile__face {
  animation: hintPulse 650ms ease-in-out 3;
}

.tile.is-removing {
  pointer-events: none;
  animation: tileRemove 260ms ease forwards;
}

.tile.is-denied {
  animation: tileDenied 260ms ease;
}

@keyframes hintPulse {
  50% {
    transform: translateY(-8px) scale(1.08);
    box-shadow:
      0 0 0 6px rgba(255, 255, 255, 0.82),
      0 7px 0 var(--tile-edge);
  }
}

@keyframes tileRemove {
  60% {
    transform: scale(1.22) rotate(4deg);
    opacity: 0.9;
  }
  to {
    transform: scale(0.15) rotate(-20deg);
    opacity: 0;
  }
}

@keyframes tileDenied {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

.floating-score-layer {
  position: absolute;
  z-index: 1000;
  inset: 0;
  pointer-events: none;
}

.floating-score {
  position: absolute;
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  animation: scoreFloat 750ms ease forwards;
}

@keyframes scoreFloat {
  to {
    opacity: 0;
    transform: translateY(-72px) scale(1.15);
  }
}

.combo-badge {
  position: absolute;
  z-index: 1200;
  top: 5%;
  left: 50%;
  min-width: 120px;
  padding: 8px 14px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--accent);
  box-shadow: 0 5px 0 rgba(23, 35, 63, 0.22);
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -18px) rotate(-3deg) scale(0.8);
  pointer-events: none;
}

.combo-badge.is-visible {
  animation: comboPop 850ms ease forwards;
}

@keyframes comboPop {
  15%,
  68% {
    opacity: 1;
    transform: translate(-50%, 0) rotate(2deg) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -28px) rotate(-2deg) scale(0.88);
  }
}

.tray-panel {
  width: min(100%, 690px);
  margin: 4px auto 0;
  padding: 7px 10px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--tray);
  box-shadow: 0 5px 0 rgba(23, 35, 63, 0.24);
}

.tray {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.tray-slot {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  min-width: 0;
  place-items: center;
  overflow: hidden;
  border: 2px solid #7891a8;
  border-radius: 6px;
  background: var(--tray-slot);
}

.tray-slot::before {
  content: "";
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.tray-tile {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  padding: 2px;
  border: 0;
  background: var(--paper);
  animation: trayLand 170ms ease;
}

.tray-tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes trayLand {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.8);
  }
}

.power-bar {
  display: grid;
  width: min(100%, 690px);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin: 8px auto 0;
}

.power-button {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 6px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(23, 35, 63, 0.22);
}

.power-button__icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
}

.power-button b {
  position: absolute;
  top: -8px;
  right: -5px;
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  padding: 0 4px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  font-size: 12px;
}

.power-button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: none;
}

.power-button:disabled {
  filter: grayscale(1);
  opacity: 0.5;
  cursor: not-allowed;
}

.modal-layer {
  position: fixed;
  z-index: 5000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 35, 63, 0.62);
  backdrop-filter: blur(5px);
}

.modal-layer[hidden],
.modal-panel[hidden] {
  display: none;
}

.modal-panel {
  position: relative;
  width: min(100%, 450px);
  max-height: min(86svh, 680px);
  overflow-y: auto;
  padding: 20px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow:
    0 10px 0 rgba(23, 35, 63, 0.34),
    0 24px 50px rgba(0, 0, 0, 0.28);
  animation: modalIn 180ms ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-header p,
.modal-panel--result > p {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.modal-header h2,
.modal-panel--result h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
}

.modal-close {
  width: 40px;
  height: 40px;
  box-shadow: none;
}

.setting-row {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 2px solid #e6e1c7;
}

.setting-row strong {
  font-size: 16px;
}

.setting-row p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 56px;
  height: 32px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: absolute;
  inset: 0;
  border: 3px solid var(--ink);
  border-radius: 99px;
  background: #c9ced9;
  cursor: pointer;
  transition: background 160ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: #70cd74;
}

.switch input:checked + span::after {
  transform: translateX(24px);
}

.secondary-button,
.primary-button {
  min-height: 50px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(23, 35, 63, 0.2);
}

.secondary-button {
  background: #fff;
}

.secondary-button--danger {
  width: 100%;
  margin-top: 14px;
  background: #ffe2e6;
  color: #9a2c3c;
}

.primary-button {
  background: var(--accent);
}

.secondary-button:active,
.primary-button:active {
  transform: translateY(4px);
  box-shadow: none;
}

.ranking-list {
  display: grid;
  gap: 8px;
}

.ranking-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

.ranking-row__place {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--accent);
  font-weight: 900;
}

.ranking-row strong,
.ranking-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-row small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.ranking-row b {
  font-size: 20px;
}

.empty-ranking {
  margin: 0;
  padding: 26px 12px;
  color: var(--ink-soft);
  text-align: center;
}

.theme-options {
  display: grid;
  gap: 10px;
}

.theme-option {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 8px 12px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.theme-option.is-active {
  box-shadow: inset 0 0 0 4px var(--accent);
}

.theme-swatch {
  display: block;
  width: 48px;
  height: 48px;
  border: 3px solid var(--ink);
  border-radius: 8px;
}

.theme-swatch--meadow {
  background: linear-gradient(135deg, #cbee8e 50%, #75bd4d 50%);
}

.theme-swatch--sunset {
  background: linear-gradient(135deg, #ffe0a4 50%, #ee8b54 50%);
}

.theme-swatch--candy {
  background: linear-gradient(135deg, #e5eaff 50%, #99a9ec 50%);
}

.modal-panel--result {
  padding-top: 74px;
  text-align: center;
}

.modal-panel--result > img {
  position: absolute;
  top: -48px;
  left: 50%;
  width: 150px;
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 12px 9px rgba(23, 35, 63, 0.24));
  transform: translateX(-50%);
}

.result-score {
  display: grid;
  gap: 2px;
  margin: 20px 0;
  padding: 13px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

.result-score span {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.result-score strong {
  font-size: 36px;
}

.result-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.toast {
  position: fixed;
  z-index: 8000;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  max-width: min(88vw, 420px);
  padding: 10px 16px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

@media (max-width: 560px) {
  .menu-stage {
    border-width: 4px;
  }

  .hero-character {
    bottom: 11%;
  }

  .primary-pill {
    bottom: 6%;
  }

  .level-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-button {
    min-height: 142px;
  }

  #game-screen {
    padding-right: 8px;
    padding-left: 8px;
  }

  .game-header {
    gap: 7px;
  }

  .game-header .icon-button {
    width: 42px;
    height: 42px;
  }

  .score-chip {
    min-width: 72px;
    min-height: 42px;
    padding: 3px 8px;
  }

  .score-chip strong {
    font-size: 17px;
  }

  .round-progress {
    margin-top: 7px;
  }

  .board-wrap {
    width: 100%;
  }

  .tray-panel {
    padding: 5px 7px;
    border-width: 3px;
  }

  .tray {
    gap: 3px;
  }

  .power-bar {
    gap: 5px;
  }

  .power-button {
    min-height: 49px;
    flex-direction: column;
    gap: 0;
    padding: 4px 2px;
    font-size: 10px;
  }

  .power-button__icon {
    width: 22px;
    height: 22px;
  }
}

@media (min-width: 760px) {
  .menu-stage {
    width: min(100%, 860px);
    align-self: center;
  }

  .menu-actions {
    width: min(100%, 640px);
    align-self: center;
  }
}

@media (max-height: 720px) {
  .menu-brand {
    top: 4%;
  }

  .menu-brand h1 {
    font-size: clamp(34px, 9vh, 54px);
  }

  .hero-character {
    bottom: 13%;
    max-height: 62%;
  }

  .primary-pill {
    bottom: 5%;
    min-height: 54px;
    font-size: 23px;
  }

  .menu-actions {
    padding-top: 8px;
  }

  .round-action {
    min-height: 62px;
  }

  .round-action__icon {
    width: 42px;
    height: 42px;
  }

  #game-screen {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .power-button {
    min-height: 46px;
  }
}

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