:root {
  color-scheme: light;
  --ink: #4a2a1b;
  --leaf: #2d8c5a;
  --leaf-deep: #1f6d49;
  --cream: #fff5df;
  --gold: #ffc83d;
  --danger: #d95f4b;
  --shadow: rgba(91, 48, 22, 0.2);
  --soft-shadow: rgba(80, 99, 52, 0.18);
  --finger-cursor: url("assets/ui/cursor-finger-pc.png") 12 5, auto;
  --finger-pointer: url("assets/ui/cursor-finger-pc.png") 12 5, pointer;
  --finger-press: url("assets/ui/cursor-finger-press.png") 12 8, pointer;
  --hammer-cursor: url("assets/ui/cursor-hammer.png") 30 28, pointer;
  --hammer-down-cursor: url("assets/ui/cursor-hammer-down.png") 34 70, pointer;
}

* {
  box-sizing: border-box;
  cursor: inherit;
}

html,
body {
  min-height: 100%;
  cursor: var(--finger-cursor);
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
  background:
    linear-gradient(rgba(255, 250, 233, 0.18), rgba(255, 250, 233, 0.32)),
    url("assets/images/garden-bg.png") center / cover fixed;
  overflow-x: hidden;
  user-select: none;
  cursor: var(--finger-cursor);
}

body.modal-scroll-locked {
  overflow: hidden;
}

body.game-active {
  overflow: hidden;
}

html:active,
body:active,
body:active .app,
body:active .modal,
body:active button {
  cursor: var(--finger-press);
}

body.hammer-visible .playfield,
body.hammer-visible .playfield * {
  cursor: var(--hammer-cursor);
}

body.hammer-visible.hammer-swinging .playfield,
body.hammer-visible.hammer-swinging .playfield * {
  cursor: var(--hammer-down-cursor);
}

body.home-screen .topbar,
body.home-screen .stage {
  visibility: hidden;
  pointer-events: none;
}

button,
input {
  font: inherit;
}

input {
  user-select: text;
  cursor: text;
}

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

button {
  -webkit-tap-highlight-color: transparent;
  cursor: var(--finger-pointer);
}

.app {
  width: min(1260px, calc(100vw - 18px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: var(--finger-cursor);
}

.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;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 252px) minmax(330px, 410px) 58px;
  gap: 0;
  align-items: center;
  justify-content: center;
  max-width: 740px;
  width: 100%;
  margin: 0 auto;
}

.brand,
.stats {
  position: relative;
  min-width: 0;
  border: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(0 12px 20px var(--soft-shadow));
}

.brand {
  aspect-ratio: 620 / 198;
  background-image: none;
  display: grid;
  align-items: center;
  padding: 0;
  filter: drop-shadow(0 12px 14px rgba(96, 55, 20, 0.2));
}

.brand-content {
  min-width: 0;
}

.title-logo {
  width: min(100%, 372px);
  max-height: 120px;
  object-fit: contain;
  object-position: left center;
  display: block;
  filter: drop-shadow(0 5px 4px rgba(91, 48, 22, 0.15));
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.5vw, 2.25rem);
  line-height: 1.05;
  color: #5d321a;
  letter-spacing: 0;
}

.brand p:not(.sr-only) {
  margin-top: -2px;
  font-weight: 900;
  color: var(--leaf-deep);
  font-size: clamp(0.84rem, 1.2vw, 1rem);
}

.stats {
  width: min(100%, 400px);
  aspect-ratio: 660 / 132;
  background-image: url("assets/ui/top-stats-frame.png");
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 6px;
  padding: 4.8% 5.2% 4.2%;
}

.stat {
  min-width: 0;
  min-height: 0;
  padding: 0 6px;
  display: grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  text-align: center;
}

.stat span {
  font-size: clamp(0.66rem, 0.86vw, 0.74rem);
  font-weight: 900;
  color: var(--leaf-deep);
}

.stat strong {
  min-width: 0;
  font-size: clamp(0.96rem, 1.62vw, 1.48rem);
  line-height: 1;
  color: #6a3416;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-settings-btn {
  justify-self: start;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: end center;
  padding-bottom: 4px;
}

.playfield {
  position: relative;
  width: min(100%, 740px);
  min-height: min(720px, calc(100svh - 118px));
  padding: clamp(16px, 2.6vw, 34px);
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 30px;
  background: rgba(237, 250, 203, 0.2);
  box-shadow: 0 20px 42px rgba(52, 97, 43, 0.2);
  backdrop-filter: blur(5px);
  overflow: visible;
  display: grid;
  place-items: center;
}

.playfield::before {
  display: none;
}

.board {
  position: relative;
  z-index: 1;
  width: min(100%, clamp(260px, calc(100svh - 194px), 650px));
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: clamp(14px, 2.2vw, 24px);
  place-items: center;
}

.hole {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 0.92;
  border: 0;
  padding: 0;
  background: transparent;
  touch-action: manipulation;
  isolation: isolate;
}

.hole:focus-visible {
  outline: 4px solid rgba(255, 200, 61, 0.9);
  outline-offset: 4px;
  border-radius: 32px;
}

.hole:focus:not(:focus-visible) {
  outline: 0;
}

.hole-front {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 0;
  width: 106%;
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 14px 12px rgba(88, 54, 30, 0.22));
}

.mole-holder,
.fx-holder {
  position: absolute;
  left: 50%;
  bottom: 15%;
  width: 104%;
  aspect-ratio: 1;
  transform: translate(-50%, 22%) scale(0.74);
  opacity: 0;
  transform-origin: 50% 86%;
  transition:
    opacity 120ms ease,
    transform 160ms cubic-bezier(0.22, 1.3, 0.36, 1);
  pointer-events: none;
}

.mole-holder {
  z-index: 3;
}

.fx-holder {
  z-index: 4;
}

.mole-img,
.fx-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border: 0;
  outline: 0;
  pointer-events: none;
}

.mole-img:not([src]),
.fx-img:not([src]) {
  visibility: hidden;
}

.hole.is-active .mole-holder {
  opacity: 1;
  transform: translate(-50%, -7%) scale(1.04);
}

.hole.is-gold .mole-holder {
  filter: drop-shadow(0 0 16px rgba(255, 205, 61, 0.76));
}

.hole.is-hit .mole-holder {
  opacity: 1;
  transform: translate(-50%, -2%) scale(0.98);
}

.hole.show-fx .fx-holder {
  opacity: 1;
  transform: translate(-50%, -4%) scale(0.94);
}

.toast {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 18px;
  min-width: 116px;
  max-width: min(84%, 340px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 245, 223, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 22px rgba(111, 71, 28, 0.18);
  font-weight: 900;
  text-align: center;
  color: #6b351a;
  pointer-events: none;
}

.primary-btn,
.ghost-btn,
.icon-btn {
  position: relative;
  z-index: 1;
  min-height: 48px;
  border-radius: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  font-size: clamp(1.08rem, 1.7vw, 1.32rem);
  font-weight: 1000;
  border: 0;
  color: #633218;
  cursor: var(--finger-pointer);
  white-space: nowrap;
  transition:
    transform 140ms ease,
    filter 140ms ease,
    box-shadow 140ms ease;
}

.primary-btn img,
.ghost-btn img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  margin-right: 8px;
  pointer-events: none;
}

.primary-btn::before,
.ghost-btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: url("assets/ui/button-unified.png") center / contain no-repeat;
  pointer-events: none;
}

.single-action .primary-btn img {
  display: none;
}

.icon-btn {
  flex: 0 0 auto;
  width: clamp(58px, 5vw, 68px);
  height: clamp(58px, 5vw, 68px);
  min-height: clamp(58px, 5vw, 68px);
  padding: 3px;
  border-radius: 50%;
}

.icon-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.primary-btn,
.primary-action {
  background: transparent;
  box-shadow: none;
}

.ghost-btn {
  background: transparent;
  border: 0;
  color: var(--leaf-deep);
}

.icon-btn {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.danger {
  border-color: rgba(217, 95, 75, 0.36);
  color: #9d3b2c;
}

.danger-text {
  color: #9d3b2c;
}

.primary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  transform: translateY(-2px);
  filter: saturate(1.05);
}

.primary-btn:active,
.ghost-btn:active,
.icon-btn:active {
  transform: translateY(1px) scale(0.99);
}

.primary-btn:disabled,
.ghost-btn:disabled,
.icon-btn:disabled {
  cursor: default;
  transform: none;
  opacity: 0.58;
}

.score-pop {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 24%;
  transform: translate(-50%, 0);
  padding: 5px 10px;
  border-radius: 999px;
  color: #6c330f;
  background: rgba(255, 238, 124, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.86);
  font-weight: 1000;
  box-shadow: 0 8px 14px rgba(117, 74, 20, 0.2);
  animation: float-score 680ms ease forwards;
  pointer-events: none;
}

@keyframes float-score {
  to {
    opacity: 0;
    transform: translate(-50%, -34px) scale(1.08);
  }
}

.hammer-cursor {
  display: none;
  position: fixed;
  z-index: 40;
  --hammer-x: -999px;
  --hammer-y: -999px;
  --hammer-hotspot-x: 0px;
  --hammer-hotspot-y: 0px;
  left: 0;
  top: 0;
  width: 86px;
  height: 86px;
  background: url("assets/sprites/hammer-swing/frames/hammer-01.png") center / contain no-repeat;
  transform: translate3d(
    calc(var(--hammer-x) - var(--hammer-hotspot-x)),
    calc(var(--hammer-y) - var(--hammer-hotspot-y)),
    0
  );
  pointer-events: none;
  opacity: 0;
  will-change: transform;
  filter: drop-shadow(0 10px 9px rgba(80, 45, 20, 0.22));
}

body.playing-with-hammer .hammer-cursor.is-visible {
  opacity: 1;
}

.hammer-cursor.is-swinging {
  animation: hammer-frame 165ms steps(1, end);
}

@keyframes hammer-frame {
  0% {
    background-image: url("assets/sprites/hammer-swing/frames/hammer-01.png");
  }
  34% {
    background-image: url("assets/sprites/hammer-swing/frames/hammer-03.png");
  }
  67% {
    background-image: url("assets/sprites/hammer-swing/frames/hammer-04.png");
  }
}

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(54, 100, 64, 0.34);
  backdrop-filter: blur(7px);
  cursor: var(--finger-cursor);
}

.start-modal {
  padding: clamp(12px, 2.5vw, 34px);
  background:
    linear-gradient(rgba(255, 249, 229, 0.06), rgba(255, 249, 229, 0.12)),
    url("assets/images/start-bg.png") center / cover no-repeat;
  backdrop-filter: none;
  overflow: hidden;
  place-items: stretch center;
  cursor: var(--finger-cursor);
}

.leaf-fall {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.game-leaf-fall {
  display: none;
  z-index: 2;
}

body.game-active:not(.home-screen) .game-leaf-fall {
  display: block;
}

.leaf-fall span {
  position: absolute;
  top: -9svh;
  left: var(--leaf-left, 50%);
  width: var(--leaf-size, 18px);
  height: calc(var(--leaf-size, 18px) * 0.58);
  border-radius: 70% 0 70% 0;
  background: var(--leaf-color, rgba(175, 222, 127, 0.58));
  opacity: 0.72;
  filter: blur(0.1px);
  transform: rotate(var(--leaf-tilt, -20deg));
  animation: leaf-fall var(--leaf-duration, 12s) linear var(--leaf-delay, 0s) infinite;
}

.leaf-fall span::after {
  content: "";
  position: absolute;
  inset: 46% 12% auto 12%;
  height: 1px;
  background: rgba(95, 139, 70, 0.28);
  transform: rotate(-12deg);
}

.leaf-fall span:nth-child(1) { --leaf-left: 6%; --leaf-size: 18px; --leaf-delay: -2s; --leaf-duration: 13s; --leaf-color: rgba(183, 226, 132, 0.56); }
.leaf-fall span:nth-child(2) { --leaf-left: 14%; --leaf-size: 15px; --leaf-delay: -7s; --leaf-duration: 10s; --leaf-color: rgba(250, 174, 194, 0.48); }
.leaf-fall span:nth-child(3) { --leaf-left: 22%; --leaf-size: 22px; --leaf-delay: -4s; --leaf-duration: 15s; --leaf-color: rgba(189, 230, 145, 0.5); }
.leaf-fall span:nth-child(4) { --leaf-left: 32%; --leaf-size: 14px; --leaf-delay: -11s; --leaf-duration: 12s; --leaf-color: rgba(255, 188, 205, 0.44); }
.leaf-fall span:nth-child(5) { --leaf-left: 43%; --leaf-size: 19px; --leaf-delay: -5s; --leaf-duration: 16s; --leaf-color: rgba(173, 221, 123, 0.54); }
.leaf-fall span:nth-child(6) { --leaf-left: 51%; --leaf-size: 13px; --leaf-delay: -9s; --leaf-duration: 11s; --leaf-color: rgba(247, 179, 199, 0.44); }
.leaf-fall span:nth-child(7) { --leaf-left: 61%; --leaf-size: 20px; --leaf-delay: -1s; --leaf-duration: 14s; --leaf-color: rgba(194, 232, 149, 0.5); }
.leaf-fall span:nth-child(8) { --leaf-left: 70%; --leaf-size: 16px; --leaf-delay: -8s; --leaf-duration: 13s; --leaf-color: rgba(255, 194, 210, 0.46); }
.leaf-fall span:nth-child(9) { --leaf-left: 78%; --leaf-size: 23px; --leaf-delay: -3s; --leaf-duration: 17s; --leaf-color: rgba(176, 224, 130, 0.5); }
.leaf-fall span:nth-child(10) { --leaf-left: 86%; --leaf-size: 15px; --leaf-delay: -12s; --leaf-duration: 12s; --leaf-color: rgba(248, 181, 199, 0.42); }
.leaf-fall span:nth-child(11) { --leaf-left: 93%; --leaf-size: 18px; --leaf-delay: -6s; --leaf-duration: 15s; --leaf-color: rgba(192, 232, 147, 0.5); }
.leaf-fall span:nth-child(12) { --leaf-left: 38%; --leaf-size: 16px; --leaf-delay: -14s; --leaf-duration: 18s; --leaf-color: rgba(255, 190, 208, 0.4); }

@keyframes leaf-fall {
  0% {
    translate: 0 -10svh;
    rotate: 0deg;
  }
  35% {
    translate: 28px 36svh;
    rotate: 120deg;
  }
  70% {
    translate: -20px 72svh;
    rotate: 260deg;
  }
  100% {
    translate: 18px 112svh;
    rotate: 360deg;
  }
}

.modal[hidden] {
  display: none;
}

.modal-dialog {
  position: relative;
  width: min(94vw, 780px);
  max-height: min(92svh, 780px);
  overflow: auto;
  scrollbar-color: #d59852 rgba(255, 245, 223, 0.65);
  scrollbar-width: thin;
  padding: clamp(24px, 3.4vw, 42px);
  text-align: center;
  border-radius: 30px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.settings-modal .modal-dialog,
.leaderboard-modal .modal-dialog,
.result-modal .modal-dialog {
  filter: none;
  box-shadow: none;
}

.start-modal .start-dialog,
.settings-modal .modal-dialog {
  transform: scale(var(--dialog-scale, 1));
  transform-origin: center;
  position: relative;
  z-index: 2;
}

body.start-intro .start-logo-title {
  opacity: 0;
  animation: intro-logo 680ms ease-out 120ms forwards;
}

body.start-intro .rule-card {
  opacity: 0;
  transform: translateY(28px);
  animation: intro-card 560ms cubic-bezier(0.2, 0.82, 0.22, 1) forwards;
}

body.start-intro .rule-card:nth-child(1) {
  animation-delay: 760ms;
}

body.start-intro .rule-card:nth-child(2) {
  animation-delay: 920ms;
}

body.start-intro .rule-card:nth-child(3) {
  animation-delay: 1080ms;
}

body.start-intro .rule-card:nth-child(4) {
  animation-delay: 1240ms;
}

body.start-intro .start-dialog > .modal-actions {
  opacity: 0;
  transform: translateY(var(--home-actions-y, 0)) scale(0.72);
  animation: intro-start-button 620ms cubic-bezier(0.16, 0.9, 0.2, 1.18) 1560ms forwards;
}

@keyframes intro-logo {
  from {
    opacity: 0;
    filter: blur(3px) drop-shadow(0 14px 16px rgba(85, 45, 18, 0.08));
  }
  to {
    opacity: 1;
    filter: blur(0) drop-shadow(0 14px 16px rgba(85, 45, 18, 0.2));
  }
}

@keyframes intro-card {
  from {
    opacity: 0;
    transform: translateY(28px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes intro-start-button {
  from {
    opacity: 0;
    transform: translateY(var(--home-actions-y, 0)) scale(0.72);
  }
  70% {
    opacity: 1;
    transform: translateY(var(--home-actions-y, 0)) scale(1.06);
  }
  to {
    opacity: 1;
    transform: translateY(var(--home-actions-y, 0)) scale(1);
  }
}

.modal-dialog::-webkit-scrollbar {
  width: 12px;
}

.modal-dialog::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 245, 223, 0.78);
  border: 3px solid rgba(255, 255, 255, 0.7);
}

.modal-dialog::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, #f4c169, #c98642);
  border: 3px solid rgba(255, 245, 223, 0.9);
}

.frame-start,
.frame-rules,
.frame-leaderboard {
  background-color: transparent;
  background-image: none;
  border: 46px solid transparent;
  border-image-repeat: stretch;
  border-image-slice: 124 fill;
  border-image-width: 46px;
}

.frame-start {
  border-image-source: url("assets/ui/start-frame.png");
}

.frame-rules {
  border-image-source: url("assets/ui/rules-frame.png");
  border-image-slice: 112 fill;
}

.frame-leaderboard {
  border-image-source: url("assets/ui/leaderboard-frame.png");
  border-image-slice: 122 fill;
}

.start-dialog {
  width: min(94vw, 1020px);
  max-height: none;
  overflow: visible;
  padding: 0;
  border: 0;
  border-image-source: none;
  background: transparent;
  box-shadow: none;
  display: grid;
  justify-items: center;
  grid-template-rows: auto auto 1fr;
  align-content: start;
  gap: clamp(4px, 1svh, 10px);
  min-height: calc(100svh - clamp(24px, 5vw, 68px));
}

.start-leaderboard-btn {
  position: fixed;
  top: clamp(10px, 1.5vw, 20px);
  right: clamp(10px, 1.5vw, 20px);
  width: clamp(67px, 6.4vw, 90px);
  height: clamp(67px, 6.4vw, 90px);
  min-height: clamp(67px, 6.4vw, 90px);
  z-index: 4;
}

.small-dialog {
  width: min(92vw, 520px);
  max-height: min(94svh, 620px);
  overflow: auto;
  padding: clamp(18px, 2.4vw, 28px);
}

.leaderboard-dialog,
.result-dialog {
  width: min(94vw, 640px);
}

.result-dialog {
  max-height: min(88svh, 600px);
  padding-top: clamp(16px, 2.3vw, 26px);
  padding-bottom: clamp(16px, 2.3vw, 26px);
}

.modal-dialog h2 {
  font-size: clamp(1.6rem, 4.4vw, 2.65rem);
  color: #6b351a;
  letter-spacing: 0;
}

.start-logo-title {
  display: flex;
  justify-content: center;
  transform: translateY(clamp(-16px, -2svh, -6px));
}

.start-logo-title img {
  width: min(92vw, 930px);
  max-height: min(36svh, 330px);
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 14px 16px rgba(85, 45, 18, 0.2));
}

.modal-lead {
  margin: 4px auto 10px;
  max-width: 520px;
  color: var(--leaf-deep);
  font-weight: 900;
  line-height: 1.42;
}

.close-btn {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 12px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: var(--finger-pointer);
  filter: drop-shadow(0 8px 10px rgba(91, 48, 22, 0.22));
  transition:
    transform 150ms ease,
    filter 150ms ease;
}

.close-btn img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.start-close-btn {
  display: none;
}

.close-btn:hover {
  transform: translateY(-2px) rotate(4deg) scale(1.06);
  filter: drop-shadow(0 10px 12px rgba(91, 48, 22, 0.26)) saturate(1.08);
}

.close-btn:active {
  transform: translateY(1px) rotate(-3deg) scale(0.98);
}

.small-dialog .close-btn {
  top: 16px;
  right: 18px;
  width: 46px;
  height: 46px;
}

.small-dialog h2 {
  min-height: 46px;
  display: grid;
  place-items: center;
  margin: -6px 54px 2px;
  font-size: clamp(1.5rem, 3.6vw, 2.18rem);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.5vw, 18px);
  margin: 0 auto;
  width: min(94vw, 1000px);
  align-self: start;
}

.rule-card {
  min-height: 0;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  filter: drop-shadow(0 12px 14px rgba(91, 48, 22, 0.18));
  aspect-ratio: 1 / 1;
}

.rule-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.start-dialog > .modal-actions {
  align-self: end;
  margin-top: 0;
  padding-bottom: clamp(4px, 1.2svh, 14px);
  transform: translateY(var(--home-actions-y, 0));
}

.home-start-button {
  width: min(58vw, 344px) !important;
  min-height: 0;
  aspect-ratio: 1600 / 752;
  padding: 0;
  color: transparent;
}

.home-start-button::before {
  background-image: url("assets/ui/start-button.png");
}

.home-start-button img,
.home-start-button span {
  display: none;
}

.modal-actions .primary-btn,
.modal-actions .ghost-btn {
  width: min(100%, 340px);
  aspect-ratio: 340 / 92;
}

.start-dialog .home-start-button {
  width: min(58vw, 344px);
  aspect-ratio: 1600 / 752;
}

.single-action .primary-btn {
  width: min(100%, 340px);
  aspect-ratio: 340 / 92;
}

.settings-list {
  display: grid;
  gap: 10px;
  margin: 8px auto 0;
}

.volume-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 84px 36px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
  border: 2px solid rgba(255, 255, 255, 0.72);
  color: #70401f;
  font-weight: 1000;
}

.volume-toggle {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  cursor: var(--finger-pointer);
}

.volume-toggle img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  pointer-events: none;
}

.volume-toggle.is-muted {
  filter: grayscale(0.45) saturate(0.7);
  opacity: 0.72;
}

.switch-control {
  width: 78px;
  height: 38px;
  border: 3px solid rgba(111, 70, 31, 0.24);
  border-radius: 999px;
  padding: 3px;
  background: linear-gradient(180deg, #ead6b2, #cfa26c);
  cursor: var(--finger-pointer);
  box-shadow:
    inset 0 2px 2px rgba(96, 55, 20, 0.18),
    0 5px 10px rgba(91, 48, 22, 0.12);
}

.switch-knob {
  width: 26px;
  height: 26px;
  display: block;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.92), transparent 34%),
    linear-gradient(180deg, #fff7d4, #e9b65f);
  box-shadow: 0 3px 6px rgba(91, 48, 22, 0.22);
  transition:
    transform 160ms ease,
    background 160ms ease;
}

.switch-control.is-on {
  background: linear-gradient(180deg, #9fdd84, #368e5e);
}

.switch-control.is-on .switch-knob {
  transform: translateX(38px);
}

.switch-value {
  text-align: right;
  color: var(--leaf-deep);
  position: relative;
  z-index: 1;
}

.settings-game-actions[hidden] {
  display: none;
}

.settings-game-actions {
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.settings-game-actions .primary-btn,
.settings-game-actions .ghost-btn {
  width: min(100%, 300px);
  min-height: 42px;
}

#pauseEndButton {
  filter: none;
}

#pauseEndButton::before {
  filter: grayscale(1) saturate(0.85);
}

.result-mascot {
  width: 82px;
  aspect-ratio: 1;
  object-fit: contain;
  margin: -4px auto 4px;
  display: block;
  filter: drop-shadow(0 12px 12px rgba(84, 51, 25, 0.18));
}

#finalScore {
  margin-top: 2px;
  font-size: 1.25rem;
  font-weight: 1000;
  color: var(--leaf-deep);
}

#finalMeta,
#rankLine {
  margin-top: 3px;
  font-weight: 900;
  color: #70401f;
}

.leaderboard-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.leaderboard-dialog {
  max-height: min(92svh, 719px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: clamp(18px, 2.8vw, 28px);
  padding-bottom: clamp(18px, 2.8vw, 28px);
}

.leaderboard-head {
  position: relative;
  flex: 0 0 auto;
  min-height: 56px;
  display: grid;
  place-items: start center;
}

.leaderboard-head h2 {
  transform: translateY(-8px);
}

.leaderboard-head .close-btn {
  top: -12px;
  right: -4px;
}

.leaderboard-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0 4px 8px;
  scrollbar-color: #d59852 rgba(255, 245, 223, 0.65);
  scrollbar-width: thin;
}

.leaderboard-scroll::-webkit-scrollbar {
  width: 10px;
}

.leaderboard-scroll::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 245, 223, 0.72);
}

.leaderboard-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, #f4c169, #c98642);
  border: 2px solid rgba(255, 245, 223, 0.9);
}

.leaderboard-scroll .leaderboard-list {
  margin-top: 0;
}

.leaderboard-actions {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 10px;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  border: 2px solid rgba(255, 255, 255, 0.72);
  font-weight: 900;
}

.result-dialog .leaderboard-list {
  gap: 5px;
  margin-top: 8px;
}

.result-dialog .leaderboard-list li {
  padding: 7px 10px;
}

.result-modal:not([hidden]) .result-dialog {
  animation: result-pop-in 260ms cubic-bezier(0.2, 1.35, 0.32, 1) both;
}

@keyframes result-pop-in {
  from {
    opacity: 0;
    transform: scale(0.72);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.rank-badge {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffe680, #ffb347);
  color: #6b351a;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55);
}

.rank-name {
  min-width: 0;
  overflow: hidden;
}

.rank-name strong,
.rank-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-name span {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--leaf-deep);
}

.rank-score {
  color: #6b351a;
}

.empty-board {
  margin-top: 18px;
  font-weight: 900;
  color: var(--leaf-deep);
}

@media (min-width: 621px) and (max-width: 920px) {
  .start-modal {
    padding: clamp(8px, 2svh, 18px);
  }

  .start-dialog {
    width: min(94vw, 720px);
    min-height: calc(100svh - clamp(16px, 4svh, 36px));
    gap: clamp(5px, 1.2svh, 10px);
  }

  .start-logo-title {
    transform: none;
    margin-top: clamp(4px, 1svh, 10px);
  }

  .start-logo-title img {
    width: min(80vw, 640px);
    max-height: min(25svh, 205px);
  }

  .rule-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(74vw, 560px, calc((100svh - 230px) * 1.08));
    gap: clamp(8px, 1.3svh, 14px);
    align-self: center;
  }

  .start-dialog > .modal-actions {
    padding-bottom: clamp(4px, 1svh, 10px);
  }

  .home-start-button {
    width: min(44vw, 292px) !important;
  }
}

@media (max-width: 1080px) {
  .app {
    width: min(100vw - 18px, 760px);
    padding-top: 0;
    gap: 3px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 60px;
    justify-items: stretch;
    gap: 2px 4px;
  }

  .brand {
    width: min(310px, 72vw);
    grid-column: 1 / -1;
    justify-self: center;
  }

  .stats {
    width: 100%;
  }

  .top-settings-btn {
    align-self: center;
  }
}

@media (max-width: 620px) {
  .start-modal {
    padding: clamp(6px, 1.8svh, 12px);
  }

  .start-modal .start-dialog {
    transform: none;
  }

  .app {
    width: min(100vw - 10px, 520px);
    gap: 2px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 3px 5px;
  }

  .brand {
    width: min(360px, 82vw);
    justify-self: center;
  }

  .title-logo {
    width: min(100%, 520px);
    max-height: 168px;
    object-position: center;
    margin: 0 auto;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    aspect-ratio: auto;
    background-image: none;
    filter: drop-shadow(0 8px 12px rgba(80, 99, 52, 0.14));
    padding: 5px;
    gap: 4px;
    border-radius: 16px;
    background:
      linear-gradient(rgba(255, 247, 225, 0.9), rgba(242, 255, 217, 0.82)),
      rgba(255, 245, 223, 0.86);
    border: 2px solid rgba(255, 255, 255, 0.78);
    box-shadow: inset 0 0 0 1px rgba(111, 70, 31, 0.08);
  }

  .stat {
    min-height: 0;
    padding: 5px 2px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.45);
    border: 1px solid rgba(72, 145, 68, 0.16);
  }

  .stat span {
    font-size: 0.7rem;
  }

  .stat strong {
    font-size: 1rem;
  }

  .icon-btn {
    width: 54px;
    height: 54px;
    min-height: 54px;
  }

  .top-settings-btn {
    align-self: stretch;
    justify-self: stretch;
    width: 54px;
    height: 54px;
    min-height: 54px;
    padding: 5px;
    border-radius: 17px;
    background:
      linear-gradient(rgba(255, 248, 230, 0.9), rgba(232, 250, 205, 0.78)),
      rgba(255, 245, 223, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow:
      0 7px 13px rgba(80, 99, 52, 0.16),
      inset 0 0 0 1px rgba(111, 70, 31, 0.08);
  }

  .playfield {
    min-height: auto;
    width: min(100%, 720px);
    padding: 14px 8px 46px;
    border-radius: 24px;
    transform: translateY(-68px);
    margin-bottom: -68px;
  }

  .board {
    width: min(100%, clamp(210px, calc(100svh - 196px), 650px));
    gap: 8px;
  }

  .modal {
    padding: 10px;
  }

  .frame-start,
  .frame-rules,
  .frame-leaderboard {
    border-width: 28px;
    border-image-width: 28px;
  }

  .start-dialog {
    padding: 0;
    gap: clamp(4px, 1.2svh, 8px);
    width: 100%;
    min-height: calc(100svh - clamp(12px, 3.6svh, 24px));
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-content: stretch;
  }

  .rule-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(88vw, 380px, calc((100svh - 240px) * 0.95));
    gap: clamp(4px, 1svh, 8px);
    justify-items: center;
    align-self: center;
  }

  .rule-card {
    width: 100%;
    transform: none;
  }

  .rule-card img {
    width: 100%;
    height: auto;
  }

  .start-logo-title {
    transform: translateY(clamp(16px, 4svh, 42px));
    margin-bottom: clamp(8px, 2svh, 18px);
  }

  .start-logo-title img {
    width: min(84vw, 430px);
    max-height: min(23svh, 160px);
  }

  .home-start-button {
    width: min(62vw, 230px) !important;
  }

  .start-dialog > .modal-actions {
    --home-actions-y: -16px;
  }

  .start-leaderboard-btn {
    width: 61px;
    height: 61px;
    min-height: 61px;
    top: 8px;
    right: 8px;
  }

  .volume-row {
    grid-template-columns: 38px minmax(0, 1fr) 72px 34px;
    gap: 7px;
  }

  .switch-control {
    width: 68px;
    height: 36px;
  }

  .switch-control.is-on .switch-knob {
    transform: translateX(30px);
  }
}

@media (pointer: coarse) {
  html,
  body,
  body *,
  .app,
  .modal,
  .start-modal,
  button {
    cursor: auto !important;
  }

  .hammer-cursor {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .leaf-fall {
    display: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
