.farm-page {
  --farm-paper: #f3eedf;
  --farm-panel: #faf4e6;
  --farm-ink: #352d23;
  --farm-soft: #685b48;
  --farm-line: #cabc9d;
  --farm-action: #344d35;
  --farm-focus: #ac713c;
  margin: 0;
  min-height: 100vh;
  background: var(--farm-paper);
  color: var(--farm-ink);
  font: 500 15px system-ui, sans-serif;
}
:root[data-theme="dark"] .farm-page {
  --farm-paper: #201f19;
  --farm-panel: #2c2a21;
  --farm-ink: #f3ebd7;
  --farm-soft: #d0bfa0;
  --farm-line: #544d3d;
  --farm-action: #486a4a;
  --farm-focus: #d0a06a;
}
.farm-page * { box-sizing: border-box; }

.farm-page .account-link { left: auto; right: 62px; }
.farm-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 65px;
  padding: 9px clamp(12px, 3vw, 28px);
}
.farm-header h1 {
  margin: 0;
  font: 700 clamp(1.9rem, 4vw, 3.15rem) / .98 "Young Serif", Georgia, serif;
  letter-spacing: -.07em;
}
.farm-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-left: -10px;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  font: 700 clamp(1rem, 3vw, 1.55rem) "Segoe Print", cursive;
  transition: background-color 160ms ease, transform 160ms ease;
}
.farm-back:hover { background: var(--farm-line); transform: translateX(-3px); }
.farm-back:active { transform: scale(.96); }
.farm-shell { width: min(100% - 44px, 1350px); margin-inline: auto; padding: 9px 0 24px; }
.farm-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); align-items: start; gap: 15px; }
.farm-world { min-width: 0; }

.farm-map {
  position: relative;
  height: clamp(410px, 72vh, 710px);
  overflow: hidden;
  border: 2px solid #495841;
  border-radius: 12px 12px 5px 5px;
  background: #99bc78;
  box-shadow: 0 4px 0 #53433120;
}
#farm-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#farm-canvas[data-harvestable="true"] { cursor: pointer; }
#farm-canvas:active { cursor: grabbing; }

.map-top, .map-foot {
  position: absolute;
  inset-inline: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.map-top { top: 12px; }
.map-foot { bottom: 12px; font-size: .75rem; }
.wallet, .map-foot span, #center-map {
  border: 1px solid #55483275;
  border-radius: 6px;
  background: #fbf3d9;
  color: #3d3326;
  box-shadow: 0 2px 0 #4d49312b;
}
.wallet {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
}
.wallet > span:last-child { color: #6b5638; font-size: .82rem; }
.coin { width: 15px; height: 15px; border: 2px solid #a87028; border-radius: 50%; background: #f0bb54; box-shadow: inset 0 0 0 2px #ffd885; }
.map-foot span { padding: 4px 7px; }
#center-map { padding: 6px 8px; pointer-events: auto; font: 700 .72rem system-ui, sans-serif; }

.farm-shop {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: clamp(445px, 77vh, 760px);
  overflow: hidden;
  border: 1px solid var(--farm-line);
  border-radius: 11px;
  background: var(--farm-panel);
}
.farm-guide {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--farm-line);
}
.guide-copy { grid-column: 1 / -1; }
.farm-guide [hidden] { display: none; }
.guide-copy h2 { margin: 0; font: 700 1.28rem / 1.1 "Young Serif", Georgia, serif; letter-spacing: -.03em; }
.guide-copy p { margin: 4px 0 0; color: var(--farm-soft); font-size: .8rem; line-height: 1.4; }
.guide-progress { display: grid; gap: 4px; color: var(--farm-soft); font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.guide-progress progress { width: 106px; height: .52rem; appearance: none; border: 0; background: var(--farm-line); border-radius: 1px; }
.guide-progress progress::-moz-progress-bar { background: var(--farm-focus); }
.guide-progress progress::-webkit-progress-bar { background: var(--farm-line); }
.guide-progress progress::-webkit-progress-value { background: var(--farm-focus); }

.shop-items { display: grid; grid-template-columns: minmax(0, 1fr); }
.shop-item {
  position: relative;
  display: grid;
  grid-template-columns: 31px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 70px;
  padding: 9px 11px;
}
.shop-item + .shop-item { border-top: 1px solid var(--farm-line); }
.shop-item[data-next="true"] { box-shadow: inset 2px 0 var(--farm-focus); }
.shop-copy h3 { margin: 0; font: 700 1rem / 1.12 "Young Serif", Georgia, serif; }
.shop-copy h3 span, .shop-copy p { color: var(--farm-soft); font: 650 .7rem / 1.25 system-ui, sans-serif; }
.shop-copy p { margin: 4px 0 0; }
.shop-icon { position: relative; display: grid; place-items: center; width: 31px; height: 33px; }
.shop-icon::before, .shop-icon::after { position: absolute; content: ""; }
.icon-hat::before { width: 18px; height: 13px; top: 7px; background: #e2b374; border: 2px solid #805936; border-radius: 7px 7px 3px 3px; }
.icon-hat::after { width: 27px; height: 5px; top: 19px; background: #ce9956; border: 1px solid #805936; border-radius: 50%; }
.icon-tool::before { width: 4px; height: 26px; background: #916947; transform: rotate(36deg); border-radius: 2px; }
.icon-tool::after { width: 14px; height: 6px; top: 6px; right: 3px; border-radius: 2px 2px 4px 4px; background: #809487; transform: rotate(36deg); }
.icon-field::before { width: 25px; height: 19px; border: 2px solid #795337; border-radius: 4px; background: repeating-linear-gradient(90deg, #966542 0 3px, #d7ab68 3px 6px); transform: rotate(-9deg); }
.icon-field::after { width: 17px; height: 2px; left: 7px; top: 15px; background: #f0d795; transform: rotate(-9deg); }

.farm-page button { cursor: pointer; }
.shop-item button, .harvest-button {
  padding: 7px 8px;
  border: 1px solid var(--farm-line);
  border-radius: 5px;
  background: transparent;
  color: var(--farm-ink);
  font: 750 .74rem system-ui, sans-serif;
  white-space: nowrap;
}
.shop-item[data-next="true"] button:not(:disabled) { background: var(--farm-action); color: #fff9e9; border-color: transparent; }
.farm-page button:disabled { cursor: default; color: var(--farm-soft); opacity: .65; }
.farm-page button:not(:disabled):hover { filter: brightness(.88); }
.farm-page button:not(:disabled):active { translate: 0 1px; }
.farm-message:empty { display: none; }
.farm-message { margin: 0; padding: 7px 15px; border-top: 1px solid var(--farm-line); color: var(--farm-soft); font-size: .77rem; }
.farm-page :focus-visible { outline: 2px solid var(--farm-focus); outline-offset: 3px; }
#farm-canvas:focus-visible { outline-offset: -4px; }

@media (max-width: 830px) {
  .farm-page .account-link { max-width: 100px; display: block; line-height: 40px; }
}
@media (max-width: 770px) {
  .farm-shell { width: calc(100% - 24px); }
  .farm-board { grid-template-columns: minmax(0, 1fr); }
  .farm-map { height: min(58vh, 500px); min-height: 335px; }
  .farm-shop { max-height: 420px; }
  .shop-item { min-height: 57px; }
}
@media (max-width: 570px) {
  .farm-header { grid-template-columns: minmax(0, 1fr); gap: 7px; min-height: 0; }
  .farm-header h1 { padding-top: 3px; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  .farm-page button:not(:disabled):active { translate: none; }
  .farm-back, .farm-back:hover, .farm-back:active { transition: none; transform: none; }
}

.map-locations { display: flex; flex-wrap: wrap; gap: 5px; padding-top: 10px; }
.map-locations button {
  border: 1px solid var(--farm-line);
  border-radius: 5px;
  padding: 5px 7px;
  background: var(--farm-panel);
  color: var(--farm-ink);
  font: 650 .71rem system-ui, sans-serif;
}
.guide-actions { grid-column: 2; grid-row: 2; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.shop-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; scrollbar-gutter: stable; overscroll-behavior: contain; }
.shop-category {
  margin: 0;
  padding: 6px 11px;
  border-block: 1px solid var(--farm-line);
  color: var(--farm-soft);
  font-size: .7rem;
  letter-spacing: .055em;
  text-transform: uppercase;
}
.shop-category:first-child { border-top: 0; }
.icon-stand::before { width: 24px; height: 14px; top: 13px; background: #ad8254; border: 2px solid #7c5f46; border-radius: 2px; }
.icon-stand::after { width: 26px; height: 9px; top: 5px; border-radius: 3px; background: repeating-linear-gradient(90deg, #c66a58 0 4px, #f1d6a0 4px 8px); }
.icon-mower::before, .icon-tractor::before { width: 26px; height: 9px; top: 15px; border-radius: 3px; background: #7d9a64; box-shadow: 0 4px #4b5141; }
.icon-mower::after { width: 6px; height: 13px; top: 7px; left: 5px; border-left: 3px solid #72604b; rotate: -25deg; }
.icon-tractor::after { width: 12px; height: 11px; top: 7px; right: 5px; border-radius: 3px; background: #d4a663; }
.icon-orchard::before { width: 21px; height: 19px; top: 4px; border-radius: 50%; background: #699259; box-shadow: 0 5px #806745; }
.icon-orchard::after { width: 4px; height: 4px; top: 11px; left: 9px; border-radius: 50%; background: #f28c57; box-shadow: 8px -3px #f28c57, 8px 5px #f28c57; }

.map-controls { display: flex; gap: 4px; pointer-events: auto; }
.map-controls button {
  border: 1px solid #55483275;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fbf3d9;
  color: #3d3326;
  box-shadow: 0 2px 0 #4d49312b;
  font: 800 .82rem system-ui, sans-serif;
}
.map-purchase {
  position: absolute;
  z-index: 2;
  top: 56px;
  left: 12px;
  display: grid;
  gap: 3px;
  max-width: calc(100% - 24px);
  padding: 8px 13px;
  border: 1px solid #a5774c;
  border-radius: 7px;
  background: #fff4cf;
  color: #3d3326;
  box-shadow: 0 3px #5c572b4a;
  pointer-events: none;
}
.map-purchase[hidden] { display: none; }
.map-purchase strong { font: 750 1rem "Young Serif", Georgia, serif; }
.map-purchase span { color: #78503c; font-size: .72rem; font-weight: 700; }
.icon-greenhouse::before { width: 25px; height: 20px; top: 6px; background: #98c4aa; clip-path: polygon(0 42%, 50% 0, 100% 42%, 100% 100%, 0 100%); }
.icon-greenhouse::after { width: 3px; height: 17px; top: 10px; background: #5c866c; }
@media (prefers-reduced-motion: no-preference) {
  .map-purchase.has-purchase { animation: receipt-in 300ms cubic-bezier(.2,.85,.3,1.2) both; }
  @keyframes receipt-in { from { opacity: 0; translate: 0 -9px; scale: .93; } to { opacity: 1; translate: 0 0; scale: 1; } }
}

.farm-contract {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 9px 12px 12px;
}
.farm-contract[data-next="true"] { box-shadow: inset 3px 0 var(--farm-focus); }
.farm-contract button:not(:disabled) { background: var(--farm-action); color: #fff9e9; border-color: transparent; }
@media (prefers-reduced-motion: no-preference) {
  .farm-map.purchase-impact::after {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(115deg, transparent 20%, #fff0ab72 46%, #fff9d0a8 51%, transparent 72%);
    background-size: 240% 100%;
    box-shadow: inset 0 0 65px #f4c97b;
    animation: farm-purchase-impact 580ms ease-out both;
  }
  @keyframes farm-purchase-impact {
    0% { opacity: .95; background-position: 100% 0; }
    100% { opacity: 0; background-position: 0 0; }
  }
}

#farm-music { margin-inline-start: auto; }
#farm-music[aria-pressed="true"] { border-color: var(--farm-focus); }
