:root {
  --field: #26df82;
  --field-deep: #0ea968;
  --ink: #17241c;
  --cream: #fff8dd;
  --paper: #fffdf0;
  --wood: #8d440d;
  --wood-dark: #5b2705;
  --wood-light: #d28625;
  --blue: #1499ee;
  --blue-dark: #05619d;
  --yellow: #ffe44f;
  --tile-gap: clamp(2px, .65vw, 4px);
}

* { box-sizing: border-box; }

html, body { margin: 0; width: 100%; min-height: 100%; background: #15955f; }

body {
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.game {
  position: relative;
  width: min(100vw, 560px);
  min-height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  background:
    radial-gradient(circle at 18% 20%, rgba(255,255,255,.10) 0 1px, transparent 2px),
    linear-gradient(180deg, #28e28a 0%, var(--field) 62%, #20d579 100%);
  box-shadow: 0 0 48px rgba(2, 74, 43, .35);
}

.game::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .22;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(107deg, transparent 0 75px, rgba(3,104,56,.25) 76px 77px, transparent 78px 154px),
    repeating-linear-gradient(17deg, transparent 0 112px, rgba(255,255,255,.18) 113px 114px, transparent 115px 220px);
}

.grass { position: absolute; width: 22px; height: 11px; border-top: 2px solid rgba(4,108,58,.42); border-radius: 50%; transform: rotate(-7deg); }
.grass::before, .grass::after { content: ""; position: absolute; bottom: 2px; width: 9px; height: 10px; border-left: 2px solid rgba(4,108,58,.42); border-radius: 50%; }
.grass::before { left: 5px; transform: rotate(-18deg); }
.grass::after { left: 12px; transform: rotate(23deg); }
.grass-a { left: 12%; top: 17%; }
.grass-b { right: 8%; top: 37%; transform: scale(.75) rotate(12deg); }
.grass-c { left: 22%; bottom: 11%; transform: scale(.85) rotate(5deg); }

.hud {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 72px;
  padding: calc(env(safe-area-inset-top) + 14px) 14px 0;
  display: grid;
  grid-template-columns: 52px 1fr 76px;
  align-items: start;
}

.icon-button {
  width: 36px; height: 36px; padding: 7px; border: 0; border-radius: 8px; background: #111;
  color: white; box-shadow: 0 3px 0 rgba(0,0,0,.22); cursor: pointer;
}
.icon-button svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }

.timer {
  justify-self: center;
  height: 28px;
  min-width: 82px;
  padding: 0 13px 0 9px;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: #101813;
  color: white;
  font: 800 14px/1 ui-monospace, Consolas, monospace;
  letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.1), 0 3px 8px rgba(0,0,0,.14);
}
.timer svg { width: 16px; fill: none; stroke: white; stroke-width: 2; }
.level-chip { justify-self: end; padding: 6px 9px; color: rgba(4,72,39,.68); font-size: 12px; font-weight: 800; }

.brand { position: relative; z-index: 2; text-align: center; margin: 2px 0 10px; color: #092d1b; }
.brand-small { font-size: 10px; font-weight: 900; letter-spacing: .32em; opacity: .62; }
.brand h1 {
  margin: 2px 0 0;
  font: 950 clamp(26px, 8.2vw, 40px)/1 "Microsoft YaHei", sans-serif;
  letter-spacing: -.08em;
  color: white;
  -webkit-text-stroke: 5px #101710;
  paint-order: stroke fill;
  filter: drop-shadow(0 3px 0 #81420b);
}
.brand h1 span { color: #ffe44f; }

.combo {
  position: absolute;
  z-index: 6;
  top: max(102px, calc(env(safe-area-inset-top) + 88px));
  right: 12px;
  width: 142px;
  padding: 7px 10px 8px;
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(9,65,40,.1), rgba(4,45,27,.92), rgba(9,65,40,.12));
  color: white;
  text-align: center;
  font-size: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: .18s ease;
}
.combo.is-visible { transform: translateX(0); opacity: 1; }
.combo strong { color: #edff6b; font-size: 18px; }
.combo-track { height: 4px; margin-top: 3px; background: #0b2618; border-radius: 3px; overflow: hidden; }
.combo-track i { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #c2ff55, white); transform-origin: left; }

.board-wrap {
  position: relative;
  z-index: 3;
  width: min(94vw, 526px);
  aspect-ratio: 1;
  margin-top: auto;
  padding: clamp(8px, 2.2vw, 12px);
  border-radius: 13px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.16), transparent 18%, rgba(0,0,0,.09) 80%),
    repeating-linear-gradient(0deg, var(--wood-light) 0 4px, #b86513 4px 8px);
  box-shadow: 0 8px 0 var(--wood-dark), 0 12px 22px rgba(2,74,43,.28), inset 0 0 0 2px #efac45;
}
.board-wrap::before { content: ""; position: absolute; inset: 9px; border-radius: 5px; background: var(--wood); box-shadow: inset 0 3px 12px rgba(46,16,0,.5); }

.board {
  position: relative;
  z-index: 2;
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: var(--tile-gap);
  touch-action: none;
}

.tile {
  position: relative;
  width: 100%; height: 100%;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: linear-gradient(145deg, #fffef4, #f3edcf);
  box-shadow: 0 2px 0 #cabf90, inset 0 0 0 1px rgba(92,67,22,.22);
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, opacity .18s ease;
  transform: rotate(var(--tilt, 0deg));
  overflow: hidden;
}
.tile::after { content: ""; position: absolute; inset: 5%; background: url("./assets/garden-sprites.png") no-repeat; background-size: 400% 200%; background-position: var(--sprite-x) var(--sprite-y); filter: drop-shadow(0 1px 0 rgba(70,45,5,.2)); }
.tile:hover { filter: brightness(1.05); }
.tile.is-selected { z-index: 5; transform: rotate(var(--tilt, 0deg)) scale(1.11); box-shadow: 0 0 0 4px var(--yellow), 0 4px 0 #b98908; }
.tile.is-hint { animation: hintPulse .55s ease-in-out 3; z-index: 4; }
.tile.is-invalid { animation: invalid .28s ease; }
.tile.is-removing { pointer-events: none; animation: removeTile .32s ease forwards; }
.tile.is-dragging { z-index: 10; transition: none; filter: brightness(1.08); opacity: .92; }
.tile.is-train { box-shadow: 0 0 0 2px rgba(255,244,95,.78), 0 4px 0 #cabf90; }
.tile.is-engine { box-shadow: 0 0 0 4px #fff04d, 0 5px 0 #a87808; filter: brightness(1.12); }

.board-flash { position: absolute; z-index: 8; inset: 8px; border-radius: 7px; pointer-events: none; opacity: 0; background: radial-gradient(circle, rgba(255,250,126,.9), transparent 62%); }
.board-flash.is-active { animation: boardFlash .6s ease-out; }

.tip { position: relative; z-index: 2; min-height: 34px; margin: 17px 22px 5px; color: rgba(4,72,39,.75); text-align: center; font-size: 12px; font-weight: 800; }

.tools { position: relative; z-index: 3; display: flex; gap: 24px; margin: 2px 0 calc(env(safe-area-inset-bottom) + 18px); }
.tool-button {
  position: relative;
  width: 72px; height: 60px;
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-rows: 36px 14px;
  place-items: center;
  padding: 4px 5px 3px;
  border: 2px solid #055c93;
  border-radius: 8px;
  color: white;
  background: linear-gradient(#27b5ff, #087ed0);
  box-shadow: 0 5px 0 #07527d, inset 0 0 0 2px rgba(255,255,255,.23);
  cursor: pointer;
}
.tool-button svg { grid-column: 1; grid-row: 1; width: 31px; height: 31px; fill: var(--yellow); stroke: #4b3a05; stroke-width: 2; }
.tool-button span { grid-column: 1 / 3; grid-row: 2; font-size: 10px; font-weight: 900; }
.tool-button b { align-self: start; justify-self: end; margin: -1px -1px 0 0; min-width: 22px; padding: 2px 4px; border-radius: 10px; background: #101813; font-size: 10px; }
.tool-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #07527d; }
.tool-button:disabled { filter: grayscale(.7); opacity: .55; }

.toast { position: absolute; z-index: 20; left: 50%; bottom: 106px; padding: 9px 15px; border-radius: 20px; color: white; background: rgba(8,31,19,.88); font-size: 12px; font-weight: 800; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; transition: .18s ease; white-space: nowrap; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.modal { position: absolute; z-index: 30; inset: 0; display: grid; place-items: center; padding: 26px; background: rgba(7,71,41,.28); backdrop-filter: blur(5px); }
.modal[hidden] { display: none; }
.modal-dark { background: rgba(0,0,0,.92); color: white; }
.modal-card { position: relative; width: min(100%, 350px); padding: 28px 24px 24px; border-radius: 18px; background: #fff9df; color: var(--ink); text-align: center; box-shadow: 0 10px 0 #5b2705, 0 22px 60px rgba(0,0,0,.28), inset 0 0 0 3px #db942e; }
.modal-card h2 { margin: 5px 0 12px; font-size: 34px; font-weight: 950; letter-spacing: -.08em; }
.modal-card p { margin: 0 auto 20px; max-width: 290px; color: #526258; font-size: 14px; line-height: 1.75; }
.eyebrow { color: #148755 !important; font-size: 11px !important; font-weight: 900; letter-spacing: .18em; }
.mini-board { width: 82px; height: 82px; margin: -68px auto 13px; padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 12px; background: var(--wood); box-shadow: 0 5px 0 var(--wood-dark), 0 0 0 4px #d78824; transform: rotate(-4deg); }
.mini-board i { border-radius: 4px; background: #fff9d9; }
.mini-board i:first-child, .mini-board i:last-child { background: var(--yellow); }
.primary-button { width: 100%; min-height: 50px; border: 0; border-radius: 10px; color: white; background: linear-gradient(#22b4fa, #0879c4); box-shadow: 0 5px 0 #07517d; font-weight: 950; cursor: pointer; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #07517d; }
.primary-button.secondary { margin-top: 12px; background: #2a7d58; box-shadow: 0 5px 0 #155438; }
.result-card { background: transparent; color: white; box-shadow: none; }
.result-card h2 { color: #ffe44f; font-size: 42px; text-shadow: 0 0 18px rgba(255,228,79,.38); }
.result-card p { color: rgba(255,255,255,.76); }
.progress-dots { display: flex; justify-content: center; gap: 12px; margin: 22px 0; }
.progress-dots i { width: 15px; height: 15px; border-radius: 50%; background: #39463f; box-shadow: inset 0 0 0 2px #78867e; }
.progress-dots i.is-done { background: #34e38a; box-shadow: 0 0 0 4px rgba(52,227,138,.18), 0 0 12px rgba(52,227,138,.7); }
.result-burst { position: absolute; width: 250px; height: 250px; background: repeating-conic-gradient(from 0deg, rgba(255,228,79,.5) 0 4deg, transparent 4deg 18deg); -webkit-mask: radial-gradient(circle, transparent 0 25%, #000 70%); animation: spin 16s linear infinite; }
.settings-card h2 { font-size: 26px; }
.setting-row { width: 100%; display: flex; justify-content: space-between; padding: 15px 4px; border: 0; border-bottom: 1px solid rgba(34,70,48,.14); color: var(--ink); background: none; font-weight: 800; cursor: pointer; }
.setting-row b { color: #138852; }
.setting-row.danger b { color: #d55436; }

.particle { position: absolute; z-index: 12; width: 7px; height: 7px; border-radius: 50%; pointer-events: none; animation: particle .68s cubic-bezier(.16,.65,.25,1) var(--spark-delay, 0ms) forwards; }
.spark-0 { background: #fff36b; box-shadow: 0 0 7px #fff36b; }
.spark-1 { width: 5px; height: 10px; border-radius: 60% 10%; background: white; box-shadow: 0 0 6px white; }
.spark-2 { width: 6px; height: 6px; background: #57f5a3; box-shadow: 0 0 7px #57f5a3; }
.spark-ring { position: absolute; z-index: 11; width: 18px; height: 18px; margin: -9px; border: 3px solid rgba(255,248,110,.9); border-radius: 50%; pointer-events: none; animation: sparkRing .52s ease-out forwards; }

@keyframes hintPulse { 50% { transform: scale(1.13); box-shadow: 0 0 0 5px #fff35c, 0 0 18px #fff35c; } }
@keyframes invalid { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes removeTile { 35% { transform: scale(1.15) rotate(3deg); filter: brightness(1.5); } 100% { transform: scale(.2) rotate(18deg); opacity: 0; } }
@keyframes boardFlash { 0% { opacity: 0; } 28% { opacity: 1; } 100% { opacity: 0; } }
@keyframes particle { 0% { transform: translate(-50%, -50%) scale(.25); opacity: 1; } 55% { opacity: 1; } 100% { transform: translate(calc(var(--dx) - 50%), calc(var(--dy) - 50%)) rotate(260deg) scale(.45); opacity: 0; } }
@keyframes sparkRing { from { transform: scale(.2); opacity: 1; } to { transform: scale(5.8); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-height: 850px) { .board-wrap { margin-top: 20px; } .tip { margin-top: 22px; } .tools { margin-top: 8px; } }
@media (max-height: 700px) { .hud { height: 50px; padding-top: 8px; } .brand { display: none; } .board-wrap { width: min(80vh, 94vw); } .tip { margin-top: 13px; } .tools { margin-bottom: 10px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

button:focus-visible { outline: 4px solid white; outline-offset: 3px; }
