:root {
  color-scheme: only light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: #1b2519;
  --ink: #493c25;
  --wood: #925019;
  --wood-dark: #63340f;
  --cream: #f4f2d1;
  --blue: #0abdf0;
  --blue-dark: #0677a4;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 30%, #33472d 0 28%, transparent 72%),
    #172016;
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: min(100vw, 45dvh, 432px);
  aspect-ratio: 9 / 20;
  max-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background-color: #aafa68;
  background-image: url("./assets/meadow-texture.webp");
  background-size: 118% auto;
  background-position: center;
  box-shadow: 0 0 55px rgb(0 0 0 / 42%);
}

.game-shell::after {
  position: absolute;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  content: "";
  box-shadow: inset 0 0 24px rgb(88 153 37 / 16%);
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 40;
  width: 100%;
  height: 13.4%;
}

.square-button {
  position: absolute;
  display: grid;
  place-items: center;
  width: 10.7%;
  aspect-ratio: 1;
  border: min(0.75vw, 3px) solid #383824;
  border-radius: 11%;
  background: linear-gradient(#13cafd, #059edb);
  box-shadow: 0 3px 0 #075d82, inset 0 0 0 2px rgb(255 255 255 / 30%);
}

.settings-button {
  top: 4.7%;
  left: 2.2%;
}

.settings-button svg {
  width: 68%;
  overflow: visible;
  fill: #fff;
  stroke: #fff;
  stroke-width: 1.8;
}

.settings-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #075d82;
}

.date-plaque {
  position: absolute;
  top: 5.8%;
  left: 50%;
  display: grid;
  min-width: 27%;
  min-height: 25%;
  place-items: center;
  transform: translateX(-50%);
  border-radius: 8%;
  color: #fff;
  background: #080808;
  box-shadow: 0 1px 0 rgb(255 255 255 / 20%);
  font-size: clamp(11px, 3.5vw, 16px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.date-plaque i {
  position: absolute;
  top: 118%;
  left: 50%;
  width: 43%;
  height: 34%;
  transform: translateX(-50%);
  border: min(0.75vw, 3px) solid #111;
  border-radius: 999px;
  background: #fff;
}

.mini-menu {
  position: absolute;
  top: 5.6%;
  right: 2.5%;
  display: flex;
  width: 23.5%;
  height: 27%;
  align-items: center;
  gap: 4%;
  padding-left: 12%;
  border-radius: 999px;
  background: rgb(92 157 68 / 22%);
}

.mini-menu span {
  width: 4px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgb(255 255 255 / 75%);
}

.mini-menu b {
  position: absolute;
  right: 9%;
  width: 18%;
  aspect-ratio: 1;
  border: 2px solid rgb(255 255 255 / 75%);
  border-radius: 50%;
}

.level-chip,
.remaining {
  position: absolute;
  z-index: 20;
  padding: 0.5% 2.2%;
  border: 1px solid rgb(65 95 39 / 25%);
  border-radius: 999px;
  color: #46612f;
  background: rgb(242 255 220 / 45%);
  font-size: clamp(8px, 2.1vw, 10px);
  font-weight: 700;
  backdrop-filter: blur(2px);
}

.level-chip {
  top: 12.2%;
  left: 50%;
  transform: translateX(-50%);
}

.remaining {
  right: 2.6%;
  top: 74.6%;
}

.board {
  position: absolute;
  top: 16.2%;
  left: 3.7%;
  z-index: 10;
  width: 92.6%;
  height: 50%;
}

.tile {
  position: absolute;
  width: 12.5%;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: max(1px, 0.28vw) solid #5e5838;
  border-radius: 7%;
  color: inherit;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 36%), transparent 35%),
    #f1f1cd;
  box-shadow:
    0 2px 0 #6b6544,
    1px 3px 3px rgb(56 60 34 / 35%),
    inset 0 0 0 1px rgb(255 255 255 / 55%);
  cursor: pointer;
  transition: filter 160ms ease, transform 130ms ease, opacity 160ms ease;
  touch-action: manipulation;
}

.tile::after {
  position: absolute;
  inset: 3%;
  border: 1px solid rgb(162 153 100 / 24%);
  border-radius: 5%;
  content: "";
}

.tile svg,
.tray-card svg,
.reserve-card svg,
.flying-tile svg {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 0 rgb(255 255 255 / 65%));
}

.tile.selectable {
  animation: tile-ready 2.2s ease-in-out infinite;
}

.tile.selectable:active {
  transform: scale(0.9);
}

.tile.blocked {
  filter: brightness(0.62) saturate(0.5) contrast(0.92);
  cursor: not-allowed;
}

.tile.blocked::before {
  position: absolute;
  inset: 0;
  z-index: 3;
  content: "";
  background: rgb(45 62 30 / 18%);
}

.tile.invalid {
  animation: shake 300ms ease;
}

.tile.reveal {
  animation: reveal 260ms ease both;
}

.board.shuffling .tile {
  animation: shuffle-flip 380ms ease both;
}

@keyframes tile-ready {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.045); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6%); }
  75% { transform: translateX(6%); }
}

@keyframes reveal {
  from { filter: brightness(0.62) saturate(0.5); transform: scale(0.94); }
  to { filter: brightness(1) saturate(1); transform: scale(1); }
}

@keyframes shuffle-flip {
  0% { transform: rotateY(0) scale(1); }
  48% { transform: rotateY(90deg) scale(0.86); }
  52% { transform: rotateY(-90deg) scale(0.86); }
  100% { transform: rotateY(0) scale(1); }
}

.reserve {
  position: absolute;
  top: 69.4%;
  left: 4%;
  z-index: 24;
  display: flex;
  width: 92%;
  height: 7.2%;
  align-items: flex-end;
  gap: 1.4%;
}

.reserve-card,
.tray-card,
.flying-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: max(1px, 0.28vw) solid #5e5838;
  border-radius: 7%;
  background: #f1f1cd;
  box-shadow: 0 2px 0 #6b6544, 1px 3px 3px rgb(56 60 34 / 28%);
}

.reserve-card {
  width: 12.2%;
  padding: 0;
  animation: reserve-in 260ms cubic-bezier(.2, .9, .25, 1.3) both;
}

@keyframes reserve-in {
  from { transform: translateY(40%) scale(0.7); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.tray-wrap {
  position: absolute;
  top: 80.1%;
  left: 2.2%;
  z-index: 25;
  width: 95.6%;
  height: 10.3%;
  border: max(2px, 0.7vw) solid #5e3211;
  border-radius: 2.5%;
  background:
    linear-gradient(rgb(130 67 21 / 40%), transparent 18%),
    #93501c;
  box-shadow:
    inset 0 4px 0 #bc7931,
    inset 0 -5px 0 #71390f,
    0 3px 0 rgb(76 99 37 / 25%);
}

.tray {
  position: absolute;
  inset: 9% 1.9% 18%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border-right: 1px solid rgb(255 219 153 / 14%);
}

.slot:last-child {
  border-right: 0;
}

.tray-card {
  width: 88%;
  animation: tray-in 220ms cubic-bezier(.2, .9, .3, 1.2) both;
}

.tray-card.matching {
  animation: match-pop 260ms ease both;
}

@keyframes tray-in {
  from { transform: translateY(-45%) scale(0.72); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes match-pop {
  0% { transform: scale(1); filter: brightness(1); }
  55% { transform: scale(1.18); filter: brightness(1.45); }
  100% { transform: scale(0.1) rotate(9deg); opacity: 0; }
}

.tray-cap {
  position: absolute;
  top: -16%;
  bottom: -7%;
  width: 2.8%;
  border: 1px solid #66350f;
  border-radius: 50% 50% 18% 18%;
  background: linear-gradient(90deg, #8f501c, #d09347 48%, #87501d);
  box-shadow: inset 0 0 0 1px rgb(255 220 146 / 30%);
}

.tray-cap::before,
.tray-cap::after {
  position: absolute;
  left: -18%;
  width: 136%;
  height: 6%;
  border: 1px solid #62330f;
  border-radius: 999px;
  content: "";
  background: #bd7a35;
}

.tray-cap::before { top: 22%; }
.tray-cap::after { bottom: 18%; }
.tray-cap-left { left: -1.9%; }
.tray-cap-right { right: -1.9%; }

.tray-rail {
  position: absolute;
  right: 1.4%;
  bottom: 9%;
  left: 1.4%;
  height: 9%;
  border-block: 1px solid #61310e;
  background: repeating-linear-gradient(90deg, #9b5b22 0 11%, #d28e40 11% 12%, #8d4a19 12% 14.2%);
}

.tools {
  position: absolute;
  top: 91.2%;
  left: 9.5%;
  z-index: 28;
  display: flex;
  width: 81%;
  height: 7.4%;
  justify-content: space-between;
}

.tool-button {
  position: relative;
  width: 23.6%;
  padding: 0;
  overflow: visible;
  border: max(1px, 0.35vw) solid #315941;
  border-radius: 7%;
  color: #fff;
  background: linear-gradient(#18ccf4, #05a9e0);
  box-shadow: 0 3px 0 #0875a8, inset 0 0 0 2px rgb(255 255 255 / 24%);
  text-shadow: 0 1px 1px #3b4d28, 1px 0 0 #3b4d28;
  transition: filter 180ms, transform 110ms;
}

.tool-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0875a8;
}

.tool-button.used {
  filter: grayscale(0.75) brightness(0.74);
}

.tool-button strong {
  position: absolute;
  right: 0;
  bottom: 2.5%;
  left: 0;
  font-size: clamp(11px, 3.6vw, 16px);
  font-weight: 900;
  letter-spacing: 0.03em;
}

.plus {
  position: absolute;
  top: -11%;
  right: -9%;
  z-index: 3;
  display: grid;
  width: 26%;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #050505;
  font-size: clamp(13px, 4vw, 18px);
  font-weight: 900;
  line-height: 1;
  text-shadow: none;
}

.tool-svg,
.tool-art {
  position: absolute;
  top: 1%;
  left: 14%;
  width: 72%;
  height: 70%;
}

.tool-fill {
  fill: #f4cc55;
  stroke: #664d28;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-line {
  fill: none;
  stroke: #664d28;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-art-remove i {
  position: absolute;
  top: 15%;
  width: 35%;
  aspect-ratio: 0.82;
  transform: rotate(-13deg);
  border: 2px solid #66502b;
  border-radius: 12%;
  background: #f4d267;
  box-shadow: 0 2px 0 rgb(0 0 0 / 15%);
}

.tool-art-remove i:nth-child(1) { left: 4%; }
.tool-art-remove i:nth-child(2) { left: 32%; top: 6%; }
.tool-art-remove i:nth-child(3) { right: 4%; top: 20%; }

.effect-layer {
  position: absolute;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}

.flying-tile {
  position: fixed;
  z-index: 9999;
  margin: 0;
  pointer-events: none;
  transition: transform 230ms cubic-bezier(.32, .02, .2, 1), opacity 230ms ease;
}

.particle {
  position: fixed;
  z-index: 9998;
  width: 7px;
  aspect-ratio: 1;
  border: 1px solid #7e6126;
  background: #fff7cf;
  pointer-events: none;
  animation: particle 480ms ease-out both;
}

@keyframes particle {
  from { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.2) rotate(var(--rot)); opacity: 0; }
}

.toast {
  position: absolute;
  bottom: 20.5%;
  left: 50%;
  z-index: 78;
  max-width: 78%;
  padding: 2.2% 4.5%;
  transform: translate(-50%, 20%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 999px;
  color: #fff;
  background: rgb(31 37 23 / 86%);
  box-shadow: 0 4px 12px rgb(0 0 0 / 22%);
  opacity: 0;
  pointer-events: none;
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 700;
  text-align: center;
  transition: opacity 180ms, transform 180ms;
}

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

.difficulty-overlay {
  position: absolute;
  inset: 0;
  z-index: 65;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 67%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
}

.difficulty-overlay.show {
  opacity: 1;
}

.difficulty-card {
  display: grid;
  width: 84%;
  min-height: 13%;
  place-content: center;
  border-block: 4px solid #050505;
  background: rgb(5 5 5 / 91%);
  text-align: center;
  transform: scale(0.82);
  transition: transform 260ms cubic-bezier(.15, .9, .25, 1.25);
}

.difficulty-overlay.show .difficulty-card {
  transform: scale(1);
}

.difficulty-card strong {
  color: #ff2d2d;
  font-size: clamp(27px, 9vw, 40px);
  font-weight: 950;
  letter-spacing: 0.05em;
  text-shadow: 2px 3px 0 #340000;
}

.difficulty-card span {
  margin-top: 4%;
  color: #fff;
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 700;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: none;
  place-items: center;
}

.modal.open {
  display: grid;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: rgb(16 28 13 / 68%);
  backdrop-filter: blur(2px);
}

.result-card,
.settings-card {
  position: relative;
  z-index: 1;
  display: flex;
  width: 78%;
  flex-direction: column;
  align-items: center;
  padding: 9% 8% 7%;
  border: max(3px, 0.8vw) solid #684217;
  border-radius: 6%;
  background:
    linear-gradient(rgb(255 255 255 / 32%), transparent 21%),
    #f7e8a7;
  box-shadow:
    0 8px 0 #56320f,
    0 18px 35px rgb(0 0 0 / 30%),
    inset 0 0 0 3px #d7ac52;
  text-align: center;
  animation: modal-in 260ms cubic-bezier(.2, .9, .25, 1.2) both;
}

@keyframes modal-in {
  from { transform: translateY(8%) scale(0.82); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.result-card img {
  width: 50%;
  max-height: 23vh;
  margin-top: -35%;
  object-fit: contain;
  filter: drop-shadow(0 6px 4px rgb(74 50 16 / 30%));
}

.result-card.is-fail img {
  width: 32%;
  margin-top: -26%;
  filter: grayscale(0.22) drop-shadow(0 5px 3px rgb(74 50 16 / 30%));
}

.result-card p,
.result-card h1 {
  margin: 0;
}

.result-card #result-kicker {
  margin-top: 2%;
  color: #8b612a;
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 800;
  letter-spacing: 0.16em;
}

.result-card h1 {
  margin-top: 1.5%;
  color: #5e3b15;
  font-size: clamp(28px, 8.8vw, 40px);
  line-height: 1.08;
  text-shadow: 0 2px 0 #fff7cb;
}

.result-card #result-copy {
  margin: 5% 0 7%;
  color: #6b583a;
  font-size: clamp(11px, 3.1vw, 14px);
  line-height: 1.6;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 43px;
  margin-top: 3.5%;
  border-radius: 999px;
  font-weight: 900;
}

.primary-button {
  border: 2px solid #355b25;
  color: #fff;
  background: linear-gradient(#75ca3a, #47a924);
  box-shadow: 0 4px 0 #34751c, inset 0 1px 0 rgb(255 255 255 / 45%);
}

.secondary-button {
  border: 2px solid #81612d;
  color: #5e451e;
  background: #fff4c7;
  box-shadow: 0 3px 0 #b89348;
}

.settings-card {
  width: 76%;
  padding-top: 7%;
}

.settings-card h2 {
  margin: 0 0 6%;
  color: #5e3b15;
  font-size: clamp(22px, 6.8vw, 31px);
}

.setting-row {
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 0 6%;
  border: 1px solid #c39951;
  border-radius: 12px;
  color: #5c4727;
  background: rgb(255 250 218 / 70%);
  font-weight: 750;
}

.setting-row + .setting-row {
  margin-top: 3%;
}

.setting-row b {
  color: #4d9a2a;
}

.danger-row b {
  color: #bd552d;
}

@media (max-aspect-ratio: 9/20) {
  .game-shell {
    width: 100vw;
  }
}

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