.farm-overlay {
    position: fixed;
    inset: 0;
    /* Above every game HUD, but below the shared dialog layer. */
    z-index: 2147482998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
    background: rgba(10, 18, 12, .78);
    backdrop-filter: blur(4px);
}

.farm-overlay.hidden { display: none !important; }

/* The farm is a full-screen feature page. Keep the underlying portrait and
   landscape HUD from covering its header, store buttons, and scroll area. */
#ui-layer.farm-open > .hud-container,
#ui-layer.farm-open > #team-hud,
#ui-layer.farm-open > #hud-collapse-toggle,
#ui-layer.farm-open > #hud-exp-bar-container,
#ui-layer.farm-open > #afk-online-banner {
    visibility: hidden !important;
    pointer-events: none !important;
}

.farm-shell {
    width: min(980px, 96vw);
    height: min(650px, 92vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #253421;
    background: linear-gradient(150deg, #f3edcf, #dce6bd);
    border: 3px solid #795b32;
    border-radius: 14px;
    box-shadow: 0 18px 55px rgba(0, 0, 0, .6);
    font-family: "Microsoft YaHei", sans-serif;
}

.farm-header {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 62px;
    padding: 8px 14px;
    color: #f8f1d8;
    background: linear-gradient(90deg, #355b32, #55783f);
    box-sizing: border-box;
}

.farm-title-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    color: #fff4c2;
    font: 700 22px/1 serif;
    border: 2px solid #d8c786;
    border-radius: 9px;
    background: #2d4c2a;
}

.farm-heading { min-width: 0; flex: 1; }
.farm-heading h2 { margin: 0 0 3px; font-size: 19px; }
.farm-heading p { margin: 0; color: #dce8ca; font-size: 12px; }
.farm-close { width: 34px; height: 34px; border: 0; border-radius: 50%; color: white; background: rgba(0,0,0,.25); cursor: pointer; }

.farm-tabs { display: grid; grid-template-columns: repeat(5, 1fr); background: #c9d8a9; border-bottom: 1px solid #92a273; }
.farm-tab { min-height: 42px; border: 0; border-right: 1px solid #a7b489; color: #40513b; background: transparent; font-weight: 700; cursor: pointer; }
.farm-tab.active { color: #fff; background: #65834e; }

.farm-content { flex: 1; min-height: 0; padding: 14px; overflow: auto; box-sizing: border-box; }
.farm-field-note { margin-bottom: 10px; padding: 8px 12px; color: #53604a; background: rgba(255,255,255,.55); border-radius: 8px; font-size: 12px; }
.farm-water-btn { display:block; margin:8px auto 0; padding:7px 12px; border:1px solid #4d7f3c; border-radius:8px; background:linear-gradient(#89bb66,#4f813d); color:#fff9df; font-weight:700; box-shadow:0 2px 0 #294820; cursor:pointer; }
.farm-grid { display: grid; grid-template-columns: repeat(6, minmax(112px, 1fr)); gap: 10px; }
.farm-plot { position: relative; min-height: 150px; padding: 8px; overflow: hidden; border: 2px solid #8b673d; border-radius: 12px; color: #f5ead1; background: linear-gradient(#79532f, #543820); cursor: pointer; }
.farm-plot.empty { color: #6c573b; background: repeating-linear-gradient(135deg, #b98a51, #b98a51 12px, #ae7e46 12px, #ae7e46 24px); }
.farm-plot.locked { color: #746e62; border-color: #9b968c; background: #c8c3b8; }
.farm-plot:disabled { cursor: default; }
.farm-plot > span:first-child:not(.farm-crop-image) { display: block; font-weight: 700; }
.farm-plot strong, .farm-plot small { position: relative; z-index: 2; display: block; text-shadow: 0 1px 2px #2d1b0f; }
.farm-plot small { min-height: 30px; margin-top: 4px; font-size: 11px; }
.farm-crop-image { display: block; width: 72px; height: 72px; margin: 0 auto 3px; background-position: center; background-repeat: no-repeat; background-size: contain; image-rendering: pixelated; }
.farm-plot.ready { border-color: #e0bd48; box-shadow: inset 0 0 16px rgba(255,224,92,.25); }
.farm-plot i { position: absolute; right: 8px; bottom: 7px; left: 8px; height: 5px; overflow: hidden; border-radius: 4px; background: rgba(0,0,0,.35); }
.farm-plot i b { display: block; height: 100%; background: #9bd050; }

.farm-card-grid { display: grid; grid-template-columns: repeat(2, minmax(250px, 1fr)); gap: 10px; }
.farm-store-card { display: grid; grid-template-columns: 76px 1fr auto; grid-template-rows: auto auto; gap: 6px 10px; align-items: center; padding: 10px; border: 1px solid #a68a5e; border-radius: 10px; background: rgba(255,255,255,.64); }
.farm-store-card .farm-crop-image { grid-row: 1 / 3; margin: 0; }
.farm-store-card div { grid-column: 2; grid-row: 1 / 3; }
.farm-store-card strong, .farm-store-card small { display: block; }
.farm-store-card small { margin-top: 3px; color: #68705f; font-size: 11px; }
.farm-store-card button, .farm-exchange-row button { min-width: 72px; padding: 7px 9px; border: 0; border-radius: 6px; color: white; background: #607d45; cursor: pointer; }

.farm-list, .farm-exchange { display: flex; flex-direction: column; gap: 8px; max-width: 760px; margin: 0 auto; }
.farm-list-row, .farm-exchange-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid #a8b48e; border-radius: 9px; color: #33402d; background: rgba(255,255,255,.68); box-sizing: border-box; }
.farm-list-row { cursor: pointer; text-align: left; }
.farm-list-row span, .farm-exchange-row span { display: flex; flex-direction: column; }
.farm-list-row small, .farm-exchange-row small { margin-top: 3px; color: #727b69; }
.farm-list-row em { color: #67813d; font-style: normal; }
.farm-exchange h3 { margin: 8px 0 2px; color: #435838; }
.farm-exchange-row.reward { border-color: #c5a764; background: rgba(255,248,218,.75); }
.farm-visits { display: flex; flex-direction: column; gap: 8px; max-width: 760px; margin: 0 auto; }
.farm-visit-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid #a8b48e; border-radius: 9px; color: #33402d; background: rgba(255,255,255,.72); }
.farm-visit-row.steal { border-color: #d4aa62; background: rgba(255,241,207,.78); }
.farm-visit-row.water { border-color: #89b6c6; background: rgba(230,247,249,.78); }
.farm-visit-row span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.farm-visit-row small { color: #68705f; font-size: 12px; }
.farm-visit-icon { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; background: rgba(255,255,255,.65); font-size: 18px; }
.farm-visit-row time { color: #7b806f; font-size: 11px; white-space: nowrap; }
.farm-loading, .farm-empty { display: grid; min-height: 220px; place-items: center; color: #63705a; }
.farm-empty.compact { min-height: 60px; }

@media (orientation: portrait), (max-width: 640px) {
    .farm-overlay { padding: max(8px, env(safe-area-inset-top)) 7px max(8px, env(safe-area-inset-bottom)); }
    .farm-shell { width: 96vw; height: 91vh; border-width: 2px; }
    .farm-header { min-height: 56px; padding: 7px 10px; }
    .farm-title-mark { width: 36px; height: 36px; flex-basis: 36px; font-size: 19px; }
    .farm-heading h2 { font-size: 16px; }
    .farm-content { padding: 9px; }
    .farm-grid { grid-template-columns: repeat(3, minmax(88px, 1fr)); gap: 7px; }
    .farm-plot { min-height: 132px; padding: 6px; }
    .farm-crop-image { width: 62px; height: 62px; }
    .farm-card-grid { grid-template-columns: 1fr; }
    .farm-store-card { grid-template-columns: 66px 1fr auto; padding: 8px; }
    .farm-store-card .farm-crop-image { width: 60px; height: 60px; }
    .farm-tab { min-height: 39px; font-size: 12px; }
}

@media (orientation: landscape) and (max-height: 520px) {
    .farm-shell { height: 96vh; }
    .farm-header { min-height: 48px; }
    .farm-grid { grid-template-columns: repeat(6, minmax(96px, 1fr)); }
    .farm-plot { min-height: 126px; }
    .farm-crop-image { width: 58px; height: 58px; }
}
