:root {
  color-scheme: light;
  --forest: #173f36;
  --forest-soft: #285c4d;
  --cream: #fff8df;
  --paper: #fffdf4;
  --sun: #ffd84a;
  --sun-deep: #e5a914;
  --coral: #ec684f;
  --blue: #4caeb8;
  --grass: #79b94b;
  --grass-light: #a7d66d;
  --soil: #ad7040;
  --ink: #183832;
  --muted: #64766b;
  --shadow: rgba(28, 54, 36, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #d8ecd0;
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Avenir Next", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 18% 6%, rgba(255, 255, 255, 0.76), transparent 24rem),
    #d8ecd0;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
[tabindex]:focus-visible,
input:focus-visible + span {
  outline: 4px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 7px #173f36;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 200;
  transform: translateY(-140%);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: #173f36;
  font-weight: 900;
}

.skip-link:focus {
  transform: translateY(0);
}

.game {
  display: grid;
  width: 100%;
  height: 100svh;
  min-height: 100svh;
  grid-template-rows: auto 1fr;
}

.game-bar {
  position: relative;
  z-index: 40;
  display: grid;
  min-height: 74px;
  grid-template-columns: minmax(230px, 1fr) auto minmax(156px, 1fr);
  align-items: center;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--forest);
  color: #fff;
  box-shadow: 0 6px 20px rgba(15, 50, 39, 0.22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 42px;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.68);
  border-radius: 50% 46% 50% 42%;
  background: var(--sun);
  color: var(--forest);
  font-size: 1.3rem;
  box-shadow: inset 0 -4px 0 rgba(191, 137, 15, 0.25);
  transform: rotate(-5deg);
}

.brand p,
.brand h1 {
  margin: 0;
}

.brand p {
  color: #cbe8d4;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.brand h1 {
  margin-top: 1px;
  color: #fff8d4;
  font-size: clamp(1rem, 2vw, 1.35rem);
  line-height: 1;
}

.farm-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #eefbea;
  font-size: 0.78rem;
  white-space: nowrap;
}

.stat-pill strong {
  color: #fff;
  font-size: 0.95rem;
}

.coin-pill {
  background: #fff4c1;
  color: #5b4312;
}

.coin-pill span:first-child {
  color: #e2a70d;
}

.coin-pill strong {
  color: #4a370d;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.round-button,
.close-button {
  display: grid;
  width: 42px;
  min-width: 42px;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
}

.round-button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.round-button:active {
  transform: scale(0.93);
}

.play-area {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.farm-map {
  position: relative;
  display: grid;
  min-height: 0;
  margin: 12px 16px 0;
  overflow: hidden;
  grid-template-columns: 30px repeat(9, minmax(30px, 1fr)) 18px;
  grid-template-rows: 126px repeat(7, minmax(0, 1fr)) 28px;
  border: 5px solid #fff7da;
  border-radius: 25px;
  background:
    linear-gradient(90deg, transparent 0 52%, rgba(245, 217, 154, 0.88) 52% 60%, transparent 60%),
    linear-gradient(0deg, transparent 0 14%, rgba(245, 217, 154, 0.9) 14% 24%, transparent 24%),
    repeating-linear-gradient(105deg, rgba(48, 107, 55, 0.08) 0 2px, transparent 2px 16px),
    #8cc65b;
  box-shadow: 0 12px 30px var(--shadow), inset 0 0 0 2px rgba(49, 111, 55, 0.14);
  isolation: isolate;
  touch-action: none;
}

.farm-map::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 22% 54%, rgba(245, 221, 88, 0.24) 0 2px, transparent 3px),
    radial-gradient(circle at 75% 64%, rgba(255, 255, 255, 0.23) 0 3px, transparent 4px);
  background-size: 39px 34px, 53px 47px;
  content: "";
}

.farm-map[data-z="1"]::after,
.farm-map[data-z="2"]::after {
  position: absolute;
  right: 50%;
  bottom: 9px;
  z-index: 24;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(45, 135, 69, 0.94);
  color: #fff;
  content: "GODOWN LEVEL +" attr(data-z);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: translateX(50%);
}

.terrain {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.field {
  position: absolute;
  border: 3px solid rgba(89, 77, 33, 0.18);
  border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, #8ab94f 0 8px, #b5d56e 8px 13px, #719e3e 13px 15px);
  box-shadow: inset 0 0 18px rgba(67, 92, 34, 0.24);
  opacity: 0.72;
  transform: rotate(-2deg);
}

.field-one {
  right: 4%;
  bottom: 29%;
  width: 28%;
  height: 19%;
}

.field-two {
  top: 39%;
  left: 35%;
  width: 20%;
  height: 17%;
  transform: rotate(3deg);
}

.pond {
  position: absolute;
  right: 2%;
  bottom: 2%;
  width: 13%;
  height: 14%;
  border: 4px solid rgba(236, 225, 160, 0.7);
  border-radius: 45% 55% 50% 42%;
  background: radial-gradient(ellipse at 36% 25%, #b9edf0, #54aeb7 70%);
  box-shadow: inset 0 5px 12px rgba(255, 255, 255, 0.35);
}

.farmhouse {
  position: absolute;
  top: 23%;
  right: 5%;
  font-size: clamp(2.6rem, 5vw, 4.8rem);
  filter: drop-shadow(0 7px 4px rgba(40, 65, 36, 0.22));
}

.upgrade-prop {
  position: absolute;
  z-index: 1;
  display: grid;
  width: 54px;
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background: rgba(255, 249, 214, 0.8);
  font-size: 1.8rem;
  opacity: 0;
  transform: scale(0.2) rotate(-12deg);
  transition: opacity 380ms ease, transform 520ms cubic-bezier(0.17, 0.89, 0.35, 1.35);
}

.upgrade-prop.is-built {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.upgrade-coop { left: 6%; bottom: 34%; }
.upgrade-orchard { right: 29%; top: 30%; }
.upgrade-barn { left: 25%; bottom: 4%; }
.upgrade-windmill { right: 18%; bottom: 2%; }

.coordinate-grid,
.map-entities {
  display: grid;
  grid-area: 2 / 2 / 9 / 11;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
}

.coordinate-grid {
  z-index: 2;
  overflow: hidden;
  border: 2px solid rgba(23, 63, 54, 0.28);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.05);
}

.grid-cell {
  position: relative;
  border-right: 1px dashed rgba(23, 63, 54, 0.2);
  border-bottom: 1px dashed rgba(23, 63, 54, 0.2);
}

.grid-cell.is-target {
  background: rgba(255, 226, 75, 0.42);
  box-shadow: inset 0 0 0 3px rgba(255, 244, 153, 0.7);
  animation: targetGlow 1.45s ease-in-out infinite alternate;
}

.grid-cell.is-x-axis {
  background-image: linear-gradient(180deg, transparent 42%, rgba(213, 67, 57, 0.68) 42% 58%, transparent 58%);
}

.grid-cell.is-y-axis {
  background-image: linear-gradient(90deg, transparent 42%, rgba(39, 120, 194, 0.72) 42% 58%, transparent 58%);
}

.grid-cell.is-x-axis.is-y-axis {
  background-image:
    linear-gradient(180deg, transparent 42%, rgba(213, 67, 57, 0.7) 42% 58%, transparent 58%),
    linear-gradient(90deg, transparent 42%, rgba(39, 120, 194, 0.74) 42% 58%, transparent 58%);
}

.grid-cell.is-origin::before {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: grid;
  width: clamp(20px, 2.8vw, 34px);
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid #fff6b0;
  border-radius: 50%;
  background: #e8ae18;
  color: #684909;
  content: "✦";
  font-size: 0.72rem;
  box-shadow: 0 3px 7px rgba(79, 60, 13, 0.24);
  transform: translate(-50%, -50%);
}

.grid-cell::after {
  position: absolute;
  right: 4px;
  bottom: 2px;
  color: rgba(25, 63, 52, 0.46);
  content: attr(data-coordinate);
  font-size: clamp(0.43rem, 1vw, 0.66rem);
  font-weight: 800;
}

@keyframes targetGlow {
  to { background: rgba(255, 226, 75, 0.7); }
}

.axis {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  color: rgba(23, 63, 54, 0.72);
  pointer-events: none;
}

.axis strong {
  display: grid;
  width: 21px;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff8d4;
  font-size: 0.75rem;
}

.axis span {
  font-size: 0.48rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.axis-y {
  top: 52%;
  left: 3px;
  flex-direction: column;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
}

.axis-x {
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
}

.mission-card,
.inventory-card {
  position: absolute;
  z-index: 12;
  top: 12px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  background: rgba(255, 253, 244, 0.96);
  box-shadow: 0 8px 20px rgba(44, 69, 38, 0.17);
  backdrop-filter: blur(8px);
}

.mission-card {
  left: 12px;
  width: min(430px, calc(68% - 20px));
  padding: 10px 12px;
}

.mission-topline,
.inventory-heading,
.target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mission-topline {
  color: #628072;
  font-size: 0.54rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.day-badge {
  border-radius: 999px;
  padding: 3px 7px;
  background: #e4f2d8;
  color: #38613c;
}

.mission-main {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  margin-top: 5px;
}

.mission-icon {
  display: grid;
  width: 43px;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 13px;
  background: #fff0a8;
  font-size: 1.55rem;
}

.mission-icon img {
  display: block;
  width: 94%;
  height: 94%;
  object-fit: contain;
}

.mission-main h2,
.mission-main p {
  margin: 0;
}

.mission-main h2 {
  font-size: clamp(0.92rem, 1.7vw, 1.13rem);
  line-height: 1.05;
}

.mission-main p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.67rem;
}

.target-row {
  margin-top: 6px;
  border-radius: 9px;
  padding: 5px 8px;
  background: var(--forest);
  color: #fff;
}

.target-row span {
  color: #cbe8d4;
  font-size: 0.54rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.target-row strong {
  color: #ffe56f;
  font-size: 0.82rem;
}

.route-hint {
  overflow: hidden;
  margin: 4px 0 0;
  color: #526960;
  font-size: 0.63rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-progress {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.task-dot {
  height: 4px;
  flex: 1;
  border-radius: 999px;
  background: #dbe3d7;
}

.task-dot.is-complete {
  background: var(--grass);
}

.task-dot.is-current {
  background: var(--sun);
}

.inventory-card {
  right: 12px;
  width: min(250px, calc(32% - 12px));
  padding: 9px 11px;
}

.inventory-heading {
  color: #61756b;
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.inventory-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 7px;
}

.inventory-items div {
  display: grid;
  min-width: 0;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 10px;
  padding: 5px 3px;
  background: #f2f4df;
  text-align: center;
}

.inventory-items strong {
  font-size: 0.9rem;
}

.inventory-items small {
  grid-column: 1 / -1;
  color: #66766d;
  font-size: 0.5rem;
  font-weight: 800;
}

.map-entities {
  z-index: 5;
  pointer-events: none;
}

.map-entity {
  position: relative;
  display: grid;
  place-items: center;
  align-self: center;
  justify-self: center;
  transform: translateY(-2px);
}

.entity-bubble {
  display: grid;
  width: clamp(42px, 5.4vw, 66px);
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 42% 54% 48% 55%;
  background: rgba(255, 250, 217, 0.86);
  font-size: clamp(1.55rem, 3.2vw, 2.55rem);
  filter: drop-shadow(0 5px 3px rgba(39, 77, 43, 0.2));
  transform: rotate(var(--tilt, 0deg));
}

.entity-bubble img {
  display: block;
  width: 96%;
  height: 96%;
  object-fit: contain;
}

.entity-label {
  position: absolute;
  top: calc(100% - 3px);
  left: 50%;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(24, 56, 50, 0.9);
  color: #fff;
  font-size: clamp(0.46rem, 0.85vw, 0.6rem);
  font-weight: 900;
  white-space: nowrap;
  transform: translateX(-50%);
}

.map-entity.is-target .entity-bubble {
  border-color: #fff5a3;
  box-shadow: 0 0 0 5px rgba(255, 216, 74, 0.56);
  animation: entityBounce 1.05s ease-in-out infinite alternate;
}

.map-entity.is-done .entity-bubble::after {
  position: absolute;
  top: -7px;
  right: -8px;
  display: grid;
  width: 22px;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #2d9f62;
  color: #fff;
  content: "✓";
  font-size: 0.7rem;
  font-weight: 900;
}

.map-entity.is-locked {
  filter: grayscale(0.7);
  opacity: 0.56;
}

@keyframes entityBounce {
  to { transform: translateY(-5px) rotate(var(--tilt, 0deg)); }
}

.player {
  position: relative;
  z-index: 10;
  display: grid;
  width: clamp(45px, 5vw, 68px);
  height: clamp(60px, 7.2vw, 92px);
  place-items: center;
  align-self: center;
  justify-self: center;
  transition: transform 150ms ease;
  will-change: transform;
}

.player img {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
  filter: drop-shadow(0 5px 4px rgba(35, 62, 38, 0.28));
}

.player-ring {
  position: absolute;
  right: 8%;
  bottom: -3px;
  left: 8%;
  height: 22%;
  z-index: 1;
  border: 4px solid var(--sun);
  border-radius: 50%;
  opacity: 0.86;
}

.player-shadow {
  position: absolute;
  right: 8%;
  bottom: 1%;
  left: 8%;
  height: 18%;
  border-radius: 50%;
  background: rgba(31, 64, 39, 0.28);
  filter: blur(3px);
}

.player-name {
  position: absolute;
  top: calc(100% - 4px);
  left: 50%;
  z-index: 4;
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff9db;
  color: #284e41;
  font-size: clamp(0.46rem, 0.8vw, 0.58rem);
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(42, 68, 39, 0.18);
  transform: translateX(-50%);
}

.player[data-edge-bottom="true"] .player-name {
  top: auto;
  bottom: calc(100% - 6px);
}

.player.is-moving {
  transform: translateY(-4px) scale(1.05);
}

.player.is-acting {
  animation: actionHop 520ms ease-in-out infinite alternate;
}

.player.is-acting .player-ring {
  animation: actionRing 600ms ease-out infinite;
}

@keyframes actionHop {
  to { transform: translateY(-14px) rotate(3deg); }
}

@keyframes actionRing {
  to { inset: -16px; opacity: 0; }
}

.toast {
  position: absolute;
  right: 50%;
  bottom: 19px;
  z-index: 30;
  max-width: min(88%, 500px);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 9px 15px;
  background: rgba(23, 63, 54, 0.95);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 15px);
  transition: opacity 180ms ease, transform 220ms ease;
}

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

.celebration-layer {
  position: absolute;
  inset: 0;
  z-index: 25;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: 52%;
  left: 50%;
  width: 9px;
  height: 13px;
  border-radius: 2px;
  background: var(--confetti-color);
  animation: confettiBurst 900ms cubic-bezier(0.12, 0.67, 0.25, 1) forwards;
}

@keyframes confettiBurst {
  to {
    opacity: 0;
    transform: translate(var(--confetti-x), var(--confetti-y)) rotate(var(--confetti-spin));
  }
}

.control-deck {
  position: relative;
  z-index: 20;
  display: grid;
  min-height: 224px;
  grid-template-columns: minmax(220px, 1fr) minmax(210px, 0.72fr) minmax(260px, 1fr);
  align-items: end;
  gap: 14px;
  padding: 12px max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), #e9f1dc 42%),
    #e9f1dc;
  box-shadow: 0 -8px 24px rgba(40, 71, 48, 0.13);
}

.left-controls {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.axis-stack {
  display: grid;
  width: min(204px, 100%);
  gap: 9px;
}

.axis-pad {
  display: grid;
  overflow: hidden;
  border: 4px solid #fff;
  border-radius: 24px;
  background: #356e60;
  box-shadow: 0 7px 0 #234c43, 0 10px 20px rgba(32, 65, 49, 0.18);
}

.y-pad {
  border-color: #eaf6ff;
  background: #2f82ca;
  box-shadow: 0 7px 0 #1c5789, 0 10px 20px rgba(23, 74, 113, 0.2);
}

.axis-pad.y-pad button {
  background: #3b96df;
}

.axis-pad.y-pad button:hover { background: #49a5ec; }
.axis-pad.y-pad button:active,
.axis-pad.y-pad button.is-pressed { background: #1f69a8; }
.axis-pad.y-pad > span { background: #174f7f; }
.axis-pad.y-pad > span small { color: #c5e6ff; }

.x-pad {
  border-color: #fff0ed;
  background: #cf493d;
  box-shadow: 0 7px 0 #8e2f29, 0 10px 20px rgba(105, 40, 34, 0.19);
}

.axis-pad.x-pad button {
  background: #df5a4d;
}

.axis-pad.x-pad button:hover { background: #ed6a5c; }
.axis-pad.x-pad button:active,
.axis-pad.x-pad button.is-pressed { background: #b33831; }
.axis-pad.x-pad > span { background: #8f2f2a; }
.axis-pad.x-pad > span small { color: #ffd5ce; }

.z-pad {
  grid-template-columns: 1fr 60px 1fr;
  border-color: #eaf7e8;
  background: #3b9256;
  box-shadow: 0 6px 0 #28673d, 0 9px 17px rgba(35, 87, 51, 0.2);
}

.axis-pad.z-pad button {
  min-width: 0;
  min-height: 48px;
  background: #4aa566;
  font-size: 0.84rem;
  font-weight: 1000;
}

.axis-pad.z-pad button:hover { background: #59b675; }
.axis-pad.z-pad button:active,
.axis-pad.z-pad button.is-pressed { background: #2d7946; }
.axis-pad.z-pad > span { background: #27643c; }
.axis-pad.z-pad > span strong { font-size: 1.15rem; }
.axis-pad.z-pad > span small { color: #c9ead1; font-size: 0.36rem; }

.z-pad.is-locked {
  filter: saturate(0.38);
  opacity: 0.78;
}

.axis-pad button {
  display: grid;
  min-width: 58px;
  min-height: 52px;
  place-items: center;
  border: 0;
  background: #437f6f;
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.axis-pad button:hover {
  background: #4c907d;
}

.axis-pad button:active,
.axis-pad button.is-pressed {
  background: #245748;
  transform: scale(0.94);
}

.axis-pad button:disabled {
  background: #83958d;
  color: #dce3df;
  cursor: not-allowed;
}

.axis-pad > span {
  display: grid;
  place-items: center;
  background: #173f36;
  color: #fff;
  line-height: 1;
}

.axis-pad > span strong {
  font-size: 1.65rem;
}

.axis-pad > span small {
  margin-top: 2px;
  color: #b9dccc;
  font-size: 0.44rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.y-pad {
  grid-template-rows: 48px 42px 48px;
}

.x-pad {
  justify-self: end;
  grid-template-columns: minmax(64px, 1fr) 104px minmax(64px, 1fr);
}

.x-pad button {
  min-height: 90px;
}

.coordinate-console {
  align-self: end;
  border: 2px solid #fff;
  border-radius: 22px;
  padding: 10px 16px;
  background: rgba(255, 253, 240, 0.92);
  text-align: center;
  box-shadow: 0 6px 16px rgba(40, 70, 48, 0.12);
}

.work-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  border: 0;
  border-radius: 12px;
  background: #d8dfd2;
  color: #718078;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 4px 0 #aeb7aa;
}

.work-button.is-ready {
  background: linear-gradient(150deg, #ffdf58, #ecb92b);
  color: #604809;
  box-shadow: 0 4px 0 #bd8b16, 0 0 0 5px rgba(255, 216, 74, 0.19);
  animation: readyPulse 850ms ease-in-out infinite alternate;
}

.work-button:active,
.work-button.is-pressed {
  box-shadow: 0 1px 0 #99741b;
  transform: translateY(3px);
}

.work-button:disabled {
  cursor: not-allowed;
}

@keyframes readyPulse {
  to { box-shadow: 0 4px 0 #bd8b16, 0 0 0 9px rgba(255, 216, 74, 0.3); }
}

.coordinate-console p {
  margin: 0;
  color: #718177;
  font-size: 0.49rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.coordinate-values {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 5px 0;
}

.coordinate-values span {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.coordinate-values small {
  color: #5f796e;
  font-size: 0.72rem;
  font-weight: 900;
}

.coordinate-values strong {
  color: var(--forest);
  font-size: 1.55rem;
  line-height: 1;
}

.coordinate-values i {
  color: #b0beae;
  font-style: normal;
}

.coordinate-console .console-tip {
  overflow: hidden;
  color: #557064;
  font-size: 0.55rem;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  overflow: auto;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(14, 48, 39, 0.74);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  backdrop-filter: blur(8px);
}

.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.start-card,
.info-card {
  position: relative;
  width: min(94vw, 570px);
  border: 5px solid rgba(255, 255, 255, 0.8);
  border-radius: 30px;
  padding: 26px clamp(20px, 5vw, 40px) 24px;
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 223, 85, 0.23), transparent 23%),
    radial-gradient(circle at 90% 88%, rgba(100, 182, 100, 0.18), transparent 26%),
    var(--paper);
  box-shadow: 0 26px 70px rgba(7, 37, 28, 0.32);
  text-align: center;
  transform: translateY(18px) scale(0.97);
  transition: transform 230ms ease;
}

.modal-backdrop.is-open .start-card,
.modal-backdrop.is-open .info-card {
  transform: translateY(0) scale(1);
}

.start-art {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: -48px auto 12px;
  font-size: 2.5rem;
  filter: drop-shadow(0 5px 4px rgba(41, 66, 38, 0.16));
}

.start-art span:nth-child(2) {
  font-size: 3.5rem;
  transform: translateY(-8px);
}

.start-kicker {
  margin: 0;
  color: #d15b45;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.start-card h2,
.info-card h2 {
  margin: 5px 0 7px;
  color: var(--forest);
  font-size: clamp(1.55rem, 5vw, 2.25rem);
  line-height: 1.05;
}

.start-intro,
.info-card > p:not(.start-kicker):not(.wallet-line) {
  max-width: 470px;
  margin: 0 auto;
  color: #5e7167;
  font-size: 0.86rem;
  line-height: 1.42;
}

.character-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 18px 0 14px;
}

.character-card {
  position: relative;
  display: grid;
  min-width: 0;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  border: 3px solid #d9e4d5;
  border-radius: 18px;
  padding: 9px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.character-card:hover {
  transform: translateY(-2px);
}

.character-card.is-selected {
  border-color: var(--sun-deep);
  background: #fff9dc;
  box-shadow: 0 5px 14px rgba(97, 77, 27, 0.12);
}

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

.portrait-wrap {
  display: block;
  width: 58px;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #e5ebdc;
}

.portrait-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
}

.character-card > span:nth-of-type(2) {
  display: grid;
}

.character-card strong {
  font-size: 0.83rem;
}

.character-card small {
  margin-top: 2px;
  color: #718077;
  font-size: 0.61rem;
}

.character-card i {
  position: absolute;
  top: -7px;
  right: -7px;
  display: none;
  width: 24px;
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2e9860;
  color: #fff;
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 900;
}

.character-card.is-selected i {
  display: grid;
}

.control-lesson {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.control-lesson span {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 12px;
  padding: 7px;
  background: #edf3e6;
}

.control-lesson strong {
  display: grid;
  width: 27px;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--forest);
  color: #fff;
  font-size: 0.79rem;
}

.lesson-x strong { background: #c94339; }
.lesson-y strong { background: #2b7fc3; }
.lesson-z strong { background: #388a51; }
.lesson-work strong { background: #d69f19; }

.control-lesson small {
  overflow: hidden;
  color: #576c62;
  font-size: 0.62rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button,
.secondary-button,
.text-button,
.upgrade-buy {
  width: 100%;
  min-height: 50px;
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  border: 0;
  background: var(--forest);
  color: #fff;
  box-shadow: 0 5px 0 #0b2e26;
}

.primary-button:hover {
  background: #245c4d;
}

.primary-button:active {
  box-shadow: 0 1px 0 #0b2e26;
  transform: translateY(4px);
}

.secondary-button {
  margin-top: 10px;
  border: 2px solid #2f6b59;
  background: #fff;
  color: #235343;
}

.text-button {
  min-height: 38px;
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: #596c62;
  font-size: 0.76rem;
  text-decoration: underline;
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  border-color: #dce5d8;
  background: #edf3e8;
  color: #38584e;
  font-size: 1.5rem;
  line-height: 1;
}

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

.how-list li {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  border-radius: 16px;
  padding: 9px 12px;
  background: #edf3e7;
}

.how-list strong {
  display: grid;
  width: 42px;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--forest);
  color: #fff;
  font-size: 1.2rem;
}

.how-list .help-x strong { background: #c94339; }
.how-list .help-y strong { background: #2b7fc3; }
.how-list .help-z strong { background: #388a51; }
.how-list .help-work strong { background: #d69f19; }

.how-list span {
  color: #4f675c;
  font-size: 0.84rem;
  font-weight: 800;
}

.keyboard-note {
  margin-bottom: 18px !important;
  border-radius: 10px;
  padding: 7px 10px;
  background: #fff7d1;
  font-size: 0.68rem !important;
}

.wallet-line {
  margin: 8px auto 14px;
  color: #5a6f64;
  font-size: 0.84rem;
}

.wallet-line strong {
  color: #8b650d;
}

.upgrade-list {
  display: grid;
  max-height: min(52vh, 410px);
  gap: 9px;
  margin: 14px 0 18px;
  overflow: auto;
  text-align: left;
}

.upgrade-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 2px solid #dfe7db;
  border-radius: 15px;
  padding: 9px;
  background: #fff;
}

.upgrade-item.is-owned {
  border-color: #9ecb91;
  background: #eff8e9;
}

.upgrade-icon {
  display: grid;
  width: 46px;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 13px;
  background: #fff2b8;
  font-size: 1.55rem;
}

.upgrade-copy {
  display: grid;
  min-width: 0;
}

.upgrade-copy strong {
  font-size: 0.8rem;
}

.upgrade-copy small {
  margin-top: 2px;
  color: #68786f;
  font-size: 0.59rem;
}

.upgrade-buy {
  width: auto;
  min-width: 77px;
  min-height: 38px;
  border: 0;
  border-radius: 11px;
  padding: 6px 10px;
  background: var(--forest);
  color: #fff;
  font-size: 0.66rem;
}

.upgrade-buy:disabled {
  background: #d7ded4;
  color: #718078;
  cursor: not-allowed;
}

.upgrade-item.is-owned .upgrade-buy {
  background: #40925f;
  color: #fff;
}

.day-stars {
  margin: -45px 0 8px;
  color: var(--sun-deep);
  font-size: 2rem;
  letter-spacing: 0.08em;
  text-shadow: 0 3px 0 #fff;
}

.sale-total {
  display: grid;
  margin: 20px 0 13px;
  border-radius: 18px;
  padding: 13px;
  background: #fff2b8;
}

.sale-total > span {
  color: #8b690f;
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.sale-total strong {
  margin-top: 3px;
  color: #5a4208;
  font-size: 1.9rem;
}

.sale-total i {
  color: #e5a914;
  font-style: normal;
}

.screen-reader-live {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.noscript {
  position: fixed;
  inset: 20px;
  z-index: 300;
  display: grid;
  place-items: center;
  border-radius: 20px;
  padding: 20px;
  background: #fff;
  color: #173f36;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 820px) {
  .game-bar {
    min-height: 66px;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .farm-stats {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    z-index: 20;
    transform: translateX(-50%);
  }

  .stat-pill {
    min-height: 32px;
    padding: 4px 8px;
    font-size: 0.64rem;
    box-shadow: 0 3px 8px rgba(30, 58, 38, 0.12);
  }

  .stat-pill:not(.coin-pill) {
    background: rgba(23, 63, 54, 0.9);
  }

  .header-actions {
    grid-column: 2;
  }

  .play-area {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .farm-map {
    margin-top: 25px;
    grid-template-rows: 118px repeat(7, minmax(0, 1fr)) 26px;
  }

  .control-deck {
    min-height: 214px;
    grid-template-columns: minmax(185px, 1fr) minmax(145px, 0.7fr) minmax(210px, 1fr);
    gap: 8px;
    padding-top: 10px;
  }

  .axis-pad button {
    min-width: 50px;
  }

  .x-pad {
    grid-template-columns: minmax(52px, 1fr) 80px minmax(52px, 1fr);
  }
}

@media (max-width: 640px) {
  body {
    overflow-y: auto;
  }

  .game {
    height: auto;
    min-height: 100svh;
  }

  .brand p {
    display: none;
  }

  .brand h1 {
    font-size: 0.95rem;
  }

  .brand-mark {
    width: 34px;
  }

  .round-button {
    width: 38px;
    min-width: 38px;
  }

  .farm-stats {
    gap: 4px;
  }

  .play-area {
    min-height: 720px;
    grid-template-rows: minmax(410px, 59svh) 310px;
    overflow: visible;
  }

  .farm-map {
    margin: 24px 7px 0;
    grid-template-columns: 24px repeat(9, minmax(0, 1fr)) 8px;
    grid-template-rows: 142px repeat(7, minmax(24px, 1fr)) 22px;
    border-width: 3px;
    border-radius: 18px;
  }

  .mission-card,
  .inventory-card {
    top: 9px;
  }

  .mission-card {
    left: 8px;
    width: calc(100% - 16px);
    padding: 8px 9px;
  }

  .mission-main {
    grid-template-columns: 35px 1fr;
    gap: 7px;
  }

  .mission-icon {
    width: 35px;
    border-radius: 10px;
    font-size: 1.25rem;
  }

  .mission-main h2 {
    font-size: 0.88rem;
  }

  .target-row {
    margin-top: 4px;
    padding: 4px 7px;
  }

  .inventory-card {
    top: 107px;
    right: 8px;
    left: 8px;
    display: flex;
    width: auto;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
  }

  .inventory-heading {
    gap: 5px;
  }

  .inventory-items {
    display: flex;
    margin-top: 0;
  }

  .inventory-items div {
    display: flex;
    min-width: 52px;
    padding: 3px;
  }

  .inventory-items small {
    display: none;
  }

  .control-deck {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px max(10px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .left-controls {
    grid-column: 1;
    grid-row: 1 / 3;
    justify-content: flex-start;
    gap: 7px;
  }

  .y-pad {
    grid-template-rows: 48px 39px 48px;
  }

  .axis-pad button {
    min-width: 50px;
    min-height: 48px;
  }

  .coordinate-console {
    grid-column: 2;
    grid-row: 1;
    align-self: end;
    padding: 7px 8px;
  }

  .coordinate-console .console-tip {
    display: -webkit-box;
    margin-top: 3px;
    overflow: hidden;
    font-size: 0.46rem;
    line-height: 1.12;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .work-button {
    min-height: 36px;
    margin-top: 5px;
  }

  .x-pad {
    width: 100%;
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: 1fr 57px 1fr;
  }

  .x-pad button {
    min-height: 58px;
  }

  .axis-pad > span strong {
    font-size: 1.35rem;
  }

  .axis-pad > span small {
    font-size: 0.38rem;
  }

  .coordinate-values {
    margin: 4px 0 0;
  }

  .coordinate-values strong {
    font-size: 1.25rem;
  }

  .grid-cell::after,
  .entity-label,
  .player-name {
    display: none;
  }

  .entity-bubble {
    width: clamp(34px, 10vw, 48px);
    border-width: 2px;
    font-size: 1.45rem;
  }

  .player {
    width: clamp(40px, 11vw, 54px);
  }

  .player img {
    height: 100%;
  }

  .axis span {
    display: none;
  }

  .character-picker {
    grid-template-columns: 1fr;
  }

  .control-lesson {
    grid-template-columns: repeat(2, 1fr);
  }

  .start-card,
  .info-card {
    padding: 23px 18px 20px;
  }

  .start-art {
    margin-top: -43px;
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  .game-bar {
    min-height: 58px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .play-area {
    grid-template-rows: minmax(260px, 1fr) 188px;
  }

  .farm-map {
    margin-top: 7px;
    grid-template-rows: 104px repeat(7, minmax(0, 1fr)) 22px;
  }

  .control-deck {
    min-height: 188px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .y-pad {
    grid-template-rows: 39px 34px 39px;
  }

  .axis-pad button {
    min-height: 39px;
  }

  .x-pad button {
    min-height: 76px;
  }

  .mission-card {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .mission-main {
    margin-top: 3px;
  }

  .route-hint,
  .task-progress {
    display: none;
  }

  .modal-backdrop {
    align-items: start;
  }

  .start-card,
  .info-card {
    margin: 16px auto;
  }
}

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