:root {
  --farm-ink: #4c315b;
  --farm-purple: #8b58ba;
  --farm-pink: #ed72a9;
  --farm-cream: #fffaf2;
}

body.farm-page {
  color: var(--farm-ink);
  background:
    radial-gradient(circle at 8% 12%, rgba(255,255,255,.96) 0 2px, transparent 3px),
    radial-gradient(circle at 82% 8%, rgba(255,255,255,.86) 0 3px, transparent 4px),
    linear-gradient(180deg, #faeafa 0, #fff9f0 32rem, #eef9ff 100%);
  background-size: 82px 82px, 128px 128px, auto;
}

.farm-main { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 120px; }
.farm-top-stat { display: flex; align-items: baseline; gap: 3px; min-width: 72px; justify-content: center; padding: 8px 12px; border-radius: 999px; background: #fff; box-shadow: 0 7px 20px rgba(91,50,114,.12); }
.farm-top-stat strong { color: var(--farm-pink); font-size: 1.1rem; }
.farm-top-stat small { font-weight: 800; color: #856e91; }

.farm-hero { display: grid; grid-template-columns: minmax(0, 1.2fr) auto; gap: 32px; align-items: center; padding: 34px clamp(24px,5vw,62px); border: 3px solid rgba(255,255,255,.9); border-radius: 36px; background: linear-gradient(135deg, rgba(255,255,255,.92), rgba(255,237,248,.88)); box-shadow: 0 22px 55px rgba(100,59,124,.15); overflow: hidden; position: relative; }
.farm-hero::after { content: "✦"; position: absolute; right: 42%; top: 18px; color: #f4b4d3; font-size: 2rem; transform: rotate(16deg); }
.farm-hero h1 { margin: 6px 0 12px; font-size: clamp(2.3rem,6vw,5rem); line-height: .94; letter-spacing: -.04em; }
.farm-hero h1 em { color: var(--farm-pink); font-style: normal; }
.farm-hero > div > p:last-child { max-width: 670px; margin: 0; font-size: clamp(1rem,2vw,1.25rem); line-height: 1.55; }
.farm-hero-progress { display: grid; grid-template-columns: repeat(2,minmax(100px,1fr)); gap: 12px; min-width: 300px; }
.farm-hero-progress span { display: grid; place-items: center; padding: 16px; border-radius: 22px; background: #fff; box-shadow: 0 8px 24px rgba(93,52,116,.1); }
.farm-hero-progress strong { font-size: 1.65rem; color: var(--farm-purple); }
.farm-hero-progress small { font-weight: 800; color: #796883; }
.farm-hero-progress .game-button { grid-column: 1/-1; }

.farm-picker { margin: 38px 0 18px; }
.farm-section-title { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin: 0 10px 14px; }
.farm-section-title h2, .farm-area-heading h2, .farm-growth-guide h2 { margin: 4px 0; font-size: clamp(1.55rem,3vw,2.25rem); }
.farm-section-title > p { max-width: 360px; margin: 0; font-weight: 700; color: #806e88; }
.farm-area-tabs { display: flex; gap: 10px; overflow-x: auto; padding: 6px 5px 14px; scrollbar-width: thin; scroll-snap-type: x proximity; }
.farm-area-tab { flex: 0 0 155px; display: grid; grid-template-columns: 44px 1fr; gap: 9px; align-items: center; min-height: 66px; padding: 8px 11px; border: 2px solid #ead9ed; border-radius: 20px; color: var(--farm-ink); background: rgba(255,255,255,.88); text-align: left; font: inherit; cursor: pointer; scroll-snap-align: start; transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease; }
.farm-area-tab:hover { transform: translateY(-2px); }
.farm-area-tab[aria-selected="true"] { border-color: var(--farm-pink); box-shadow: 0 8px 22px rgba(224,92,151,.18); background: #fff7fb; }
.farm-area-tab img { width: 44px; height: 44px; object-fit: cover; border-radius: 14px; }
.farm-area-tab strong { display: block; font-size: .92rem; line-height: 1.08; }
.farm-area-tab small { display: block; margin-top: 4px; font-weight: 800; color: #8a718f; }

.farm-area-card { border: 3px solid #fff; border-radius: 34px; background: rgba(255,255,255,.9); box-shadow: 0 24px 64px rgba(75,48,95,.18); overflow: hidden; }
.farm-area-heading { display: grid; grid-template-columns: auto minmax(0,1fr) auto auto; gap: 18px; align-items: center; padding: 18px 22px; }
.farm-area-heading p { margin: 0; }
.farm-area-count { display: grid; text-align: right; }
.farm-area-count strong { font-size: 1.3rem; color: var(--farm-pink); }
.farm-area-count small { font-weight: 800; color: #8a748f; }
.farm-arrow { width: 50px; height: 50px; border: 0; border-radius: 50%; background: #f8e9f7; color: var(--farm-purple); font: 900 2rem/1 system-ui; cursor: pointer; }
.farm-arrow:hover { background: #f1d4ee; }

.farm-scene-shell { position: relative; background: #dff5dc; }
.farm-scene { position: relative; aspect-ratio: 16 / 9; overflow: hidden; isolation: isolate; }
.farm-background { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; }
.farm-residents { position: absolute; inset: 0; z-index: 2; }
.farm-home { position: absolute; left: var(--home-x); top: var(--home-y); width: var(--home-w); aspect-ratio: 1.78; transform: translate(-50%,-72%); pointer-events: none; isolation: isolate; }
.farm-home:hover,.farm-home:focus-within { z-index: 100 !important; }
.farm-unicorn { position: absolute; z-index: 2; left: 50%; top: 72%; width: 100%; aspect-ratio: var(--asset-ratio,.9); transform: translate(var(--anchor-x,-50%),var(--anchor-y,-98%)) scale(var(--growth)); transform-origin: var(--origin-x,50%) var(--origin-y,98%); border: 0; padding: 0; border-radius: 24%; outline: 0 solid transparent; background: transparent; pointer-events: auto; cursor: pointer; filter: drop-shadow(0 7px 5px rgba(44,39,62,.24)); transition: transform .22s ease, filter .22s ease, outline-color .18s ease; }
.farm-unicorn:hover, .farm-unicorn:focus-visible { transform: translate(var(--anchor-x,-50%),var(--anchor-y,-98%)) scale(calc(var(--growth) + .04)); filter: drop-shadow(0 9px 7px rgba(78,39,93,.31)) drop-shadow(0 0 3px rgba(255,255,255,.9)); z-index: 100 !important; }
.farm-unicorn:focus-visible { outline: 4px solid rgba(255,255,255,.9); outline-offset: 3px; }
.farm-home--cutout .farm-unicorn { width: 72%; }
.farm-unicorn img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.farm-empty { position: absolute; z-index: 3; left: 50%; top: 55%; transform: translate(-50%,-50%); width: min(340px,80%); display: grid; place-items: center; padding: 20px; border: 3px solid rgba(255,255,255,.85); border-radius: 24px; background: rgba(255,255,255,.86); text-align: center; box-shadow: 0 10px 30px rgba(67,47,78,.15); backdrop-filter: blur(8px); }
.farm-empty[hidden] { display: none; }
.farm-empty span { color: var(--farm-pink); font-size: 2rem; }
.farm-empty small { margin-top: 6px; line-height: 1.35; }
.farm-scene-hint { position: absolute; z-index: 5; right: 12px; bottom: 12px; margin: 0; padding: 8px 12px; border-radius: 999px; color: #5d4366; background: rgba(255,255,255,.88); font-size: .8rem; font-weight: 800; box-shadow: 0 5px 18px rgba(63,38,76,.14); pointer-events: none; }

.farm-growth-guide { display: grid; grid-template-columns: 150px minmax(0,1fr) auto; gap: 24px; align-items: center; margin-top: 28px; padding: 20px 28px; border: 3px solid #fff; border-radius: 30px; background: linear-gradient(135deg,#fff8f1,#f6eeff); box-shadow: 0 15px 40px rgba(88,55,104,.11); }
.farm-growth-guide > img { width: 150px; height: 130px; object-fit: contain; mix-blend-mode: multiply; }
.farm-growth-guide p { margin: 5px 0; line-height: 1.5; }
.farm-stage-dots { display: flex; gap: 6px; align-items: end; }
.farm-stage-dots span { display: block; width: 12px; height: calc(14px + var(--i, 0) * 3px); border-radius: 999px; background: linear-gradient(#ef8fba,#8d63bd); }
.farm-stage-dots span:nth-child(1){--i:1}.farm-stage-dots span:nth-child(2){--i:3}.farm-stage-dots span:nth-child(3){--i:5}.farm-stage-dots span:nth-child(4){--i:7}.farm-stage-dots span:nth-child(5){--i:9}

.farm-bottom-nav a { display: grid; place-items: center; gap: 2px; color: #725c78; text-decoration: none; font-weight: 800; font-size: .74rem; }
.farm-bottom-nav a.active { color: var(--farm-purple); }
.farm-bottom-nav img { width: 34px; height: 34px; object-fit: contain; }
.farm-unicorn-dialog { width: min(680px,calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 30px; border: 3px solid #fff; border-radius: 32px; color: var(--farm-ink); background: linear-gradient(#fff,#fff5fb); text-align: center; box-shadow: 0 30px 90px rgba(53,32,65,.32); overflow-y: auto; }
.farm-unicorn-dialog::backdrop { background: rgba(54,37,65,.56); backdrop-filter: blur(4px); }
.farm-dialog-art { position: relative; height: clamp(230px,48vw,360px); max-height: 40dvh; margin: -8px 0 10px; overflow: hidden; border: 2px solid rgba(255,255,255,.9); border-radius: 25px; background: linear-gradient(145deg,#fff9fd,#edf8ff); }
.farm-dialog-art img { position: absolute; z-index: 1; inset: 0; display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; object-fit: contain; filter: drop-shadow(0 12px 9px rgba(75,46,88,.2)); }
.farm-dialog-glow { position: absolute; width: 180px; height: 180px; border-radius: 50%; background: radial-gradient(circle,#ffe5a7 0,#f7b9df 38%,transparent 70%); animation: glowPulse 2s ease-in-out infinite; }
@keyframes glowPulse { 50% { transform: scale(1.08); opacity: .78 } }
.farm-unicorn-dialog h2 { margin: 4px 0 8px; font-size: 2rem; }
.farm-memory-title { margin: 8px 0 4px; color: #7550a1; font-size: 1.12rem; }
.farm-unicorn-dialog > p { margin: 7px 0; }
.farm-unicorn-meta { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 7px; font-weight: 900; color: #775c82; }
.farm-rarity { padding: 4px 9px; border-radius: 999px; color: #fff; background: #a96abf; font-size: .72rem; letter-spacing: .02em; text-transform: uppercase; }
.farm-rarity.rare { background: linear-gradient(135deg,#c45ec8,#7559c8); }
.farm-rarity.mythical { background: linear-gradient(135deg,#54bde0,#8b58ce); }
.farm-rarity.legendary { color: #6f3f76; background: linear-gradient(110deg,#fff0a2,#ffa9e0,#aeeeff,#fff0a2); box-shadow: 0 0 12px rgba(249,114,211,.38); }
.farm-dialog-progress { height: 15px; margin: 18px 0 8px; padding: 3px; border-radius: 999px; background: #eaddec; overflow: hidden; }
.farm-dialog-progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg,#ec75ab,#9164bc,#67bfe0); transition: width .3s ease; }
.farm-dialog-stage { display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; }
.farm-dialog-stage span { color: #836e88; font-weight: 800; }
.farm-unicorn-dialog .game-button { width: 100%; margin-top: 14px; }
.farm-memory-album { margin: 20px -8px 4px; padding: 15px 0 12px; border-block: 2px dashed #edc9df; text-align: left; }
.farm-memory-album header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 8px 10px; }
.farm-memory-album header div { display: flex; align-items: center; gap: 7px; }
.farm-memory-album header div > span { color: #e96fa7; font-size: 1.3rem; }
.farm-memory-album h3 { margin: 0; font-size: 1.1rem; }
.farm-memory-album header > strong { color: #886c91; font-size: .82rem; }
.farm-memory-album > p { margin: 9px 8px 0; color: #806b87; font-size: .8rem; font-weight: 800; }
.farm-memory-strip { display: grid; grid-auto-flow: column; grid-auto-columns: clamp(112px,32vw,145px); justify-content: start; gap: 10px; padding: 4px 8px 10px; overflow-x: auto; scroll-snap-type: x proximity; }
.farm-memory-strip button { position: relative; min-width: 0; padding: 5px 5px 9px; border: 3px solid #fff; border-radius: 19px; color: #634c70; background: #fff; box-shadow: 0 5px 16px rgba(87,54,101,.13); text-align: center; scroll-snap-align: start; cursor: pointer; }
.farm-memory-strip button.active { border-color: #e876ae; background: #fff3fa; box-shadow: 0 0 0 3px #f8d7e9,0 7px 18px rgba(146,71,122,.2); }
.farm-memory-strip img { display: block; width: 100%; aspect-ratio: 1; border-radius: 13px; object-fit: contain; background: linear-gradient(145deg,#fdf3fb,#eef8ff); }
.farm-memory-strip button span { position: absolute; top: 9px; left: 9px; display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; color: #fff; background: #9a65bb; font-size: .72rem; font-weight: 900; }
.farm-memory-strip button strong { display: block; margin-top: 6px; font-size: .76rem; line-height: 1.15; }

@media (max-width: 760px) {
  .farm-unicorn-dialog { width: calc(100% - 12px); max-height: calc(100dvh - 12px); padding: 18px 14px 22px; border-radius: 25px; }
  .farm-dialog-art { height: min(300px,40dvh); min-height: 210px; margin: -3px 28px 10px; border-radius: 20px; }
  .farm-unicorn-dialog h2 { font-size: 1.65rem; }
  .farm-memory-album { margin-inline: -4px; }
  .farm-memory-album header { align-items: start; }
  .farm-memory-album header > strong { flex: 0 0 auto; }
  .farm-memory-strip { grid-auto-columns: clamp(108px,34vw,132px); }
  .farm-main { width: min(100% - 18px,620px); padding-top: 16px; }
  .farm-hero { grid-template-columns: 1fr; gap: 20px; padding: 24px 20px; border-radius: 28px; }
  .farm-hero::after { right: 18px; }
  .farm-hero-progress { min-width: 0; }
  .farm-section-title { display: block; margin-inline: 5px; }
  .farm-section-title > p { margin-top: 6px; }
  .farm-area-tab { flex-basis: 142px; }
  .farm-area-card { border-radius: 27px; }
  .farm-area-heading { grid-template-columns: auto minmax(0,1fr) auto; gap: 9px; padding: 14px 10px; }
  .farm-area-heading .farm-arrow:first-child { order: 0; }
  .farm-area-heading > div:nth-child(2) { order: 1; }
  .farm-area-count { display: none; }
  .farm-area-heading .farm-arrow:last-child { order: 2; }
  .farm-arrow { width: 42px; height: 42px; }
  .farm-area-heading h2 { font-size: 1.45rem; }
  .farm-area-heading p:not(.game-kicker) { font-size: .82rem; line-height: 1.25; }
  /* Keep the illustrated homes readable instead of squeezing ten scenes into
     370px. The child can pan one consistently aligned 16:9 farm. */
  .farm-scene-shell { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: #db91bd #fff3fa; }
  .farm-scene { width: 720px; max-width: none; aspect-ratio: 16 / 9; }
  .farm-home { left: var(--home-x); top: var(--home-y); width: var(--home-w); }
  .farm-scene-hint { left: 50%; right: auto; transform: translateX(-50%); width: max-content; max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .farm-growth-guide { grid-template-columns: 92px 1fr; gap: 12px; padding: 16px; border-radius: 24px; }
  .farm-growth-guide > img { width: 92px; height: 100px; }
  .farm-stage-dots { grid-column: 1/-1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .farm-unicorn, .farm-unicorn.legendary, .farm-unicorn img, .farm-dialog-glow { animation: none; }
}

.farm-unicorn-dialog .dialog-x { z-index: 5; }
