:root {
  --bg: #7bb36a;
  --panel: #fffdf2;
  --ink: #243028;
  --muted: #5a685d;
  --accent: #2b7a4e;
  --accent-2: #ce8a35;
  --line: #cfc4aa;
  --danger: #b23a3a;
  --plowed-tile-image: url('/assets/tiles/plowed.png');
  --empty-tile-image: url('/assets/tiles/empty.png');
  --tile-overlap-scale: 1.1;
  --tile-blend-opacity: 0.28;
  --topbar-height: 58px;
  --hud-bottom: 96px;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
}
body.game-screen {
  overflow: hidden;
}
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  min-height: 100vh;
}

.auth-bg {
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #f8f4ea, #e7dfcf);
}

.auth-card {
  width: min(460px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 28px rgba(41, 34, 20, 0.16);
}

h1, h2 { margin-top: 0; }

label {
  display: block;
  margin-bottom: 12px;
  font-weight: 600;
}

input, select, button {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #c8bfae;
  font: inherit;
}

button {
  background: linear-gradient(180deg, #318b5b, #256d47);
  border-color: #1d5c3b;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,0.26) inset, 0 4px 10px rgba(29, 47, 35, 0.24);
}

button:disabled {
  background: #98a39a;
  border-color: #98a39a;
  cursor: not-allowed;
  box-shadow: none;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.inline-check input {
  width: auto;
  margin: 0;
}

.alert {
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.error {
  background: #fce9e9;
  border: 1px solid #f0bbbb;
  color: #8c2f2f;
}

.game-bg {
  background:
    radial-gradient(1200px 500px at 20% -10%, rgba(255,255,255,0.35), rgba(255,255,255,0)),
    radial-gradient(1000px 500px at 90% 115%, rgba(50,93,52,0.38), rgba(50,93,52,0)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 6px, rgba(0,0,0,0.03) 6px 12px),
    linear-gradient(180deg, #85bd71, #6fa65f 45%, #5d8f4f);
}

body.profile-page.game-bg {
  background:
    radial-gradient(900px 360px at 8% -8%, rgba(255,255,255,0.28), rgba(255,255,255,0)),
    radial-gradient(840px 340px at 94% 115%, rgba(39,78,41,0.24), rgba(39,78,41,0)),
    linear-gradient(180deg, #79b368 0%, #6da55d 52%, #639953 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.game-screen {
  height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: linear-gradient(180deg, #fff7e7, #efe4cd);
  border-bottom: 1px solid #b89f70;
  box-shadow: 0 2px 0 rgba(255,255,255,0.45) inset, 0 6px 16px rgba(48,35,18,0.2);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-stats-btn {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, #3d9867, #2e754f);
  border: 1px solid #245d3f;
  color: #fff;
}

.sound-btn {
  min-width: 44px;
  padding: 8px 10px;
}

.sound-panel {
  position: absolute;
  right: 16px;
  top: calc(var(--topbar-height) - 4px);
  z-index: 760;
  width: min(280px, calc(100vw - 24px));
  border-radius: 12px;
  padding: 10px;
  background: rgba(245, 237, 216, 0.98);
  border: 1px solid rgba(174, 154, 111, 0.92);
  box-shadow: 0 10px 22px rgba(18, 30, 20, 0.28);
  display: grid;
  gap: 8px;
}

.sound-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.sound-row input[type="range"] {
  margin: 0;
  width: 100%;
  accent-color: #2e7a4d;
  min-height: 32px;
  padding: 0;
}

.sound-toggle-btn {
  min-height: 34px;
  width: auto;
  padding: 6px 10px;
}

.inv-warn {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  font-weight: 800;
  color: #fff;
  background: rgba(176, 43, 43, 0.95);
  border: 1px solid rgba(255, 230, 230, 0.8);
}

#statsToggleBtn {
  display: none;
}

.nav-links a, .linkish {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.inline-form { margin: 0; }

.linkish {
  background: transparent;
  border: 0;
  padding: 0;
  width: auto;
  cursor: pointer;
  box-shadow: none;
}

#gameArea {
  position: relative;
  width: 100vw;
  flex: 1;
  min-height: 0;
  height: 100%;
  padding-bottom: calc(var(--hud-bottom) + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  background:
    radial-gradient(900px 420px at 20% 10%, rgba(255,255,255,0.2), transparent),
    repeating-linear-gradient(45deg, rgba(39,102,47,0.12) 0 10px, rgba(26,76,32,0.12) 10px 20px),
    linear-gradient(180deg, #63b257, #529a49 45%, #4b8d42);
  touch-action: none;
  overscroll-behavior: none;
  cursor: grab;
}

.game-screen.panning,
.game-screen.panning * {
  user-select: none;
  -webkit-user-select: none;
}

.game-screen.panning #gameArea {
  cursor: grabbing;
}

#gameArea.paint-plow {
  cursor: url('/assets/cursors/plow.png') 0 31, pointer;
}

#gameArea.paint-plant {
  cursor: url('/assets/cursors/seeds.png') 0 31, pointer;
}

#gameArea.paint-harvest {
  cursor: url('/assets/cursors/harvest.png') 0 31, pointer;
}

#gameArea.paint-animal-harvest {
  cursor: url('/assets/cursors/hand.png') 0 31, pointer;
}

#gameArea.mode-build {
  cursor: url('/assets/cursors/hammer.png') 0 31, pointer;
}

#gameArea.mode-build.destroy-active {
  cursor: url('/assets/cursors/sledge%20hammer.png') 0 31, pointer;
}

#gameArea.mode-build .tile:hover,
#gameArea.mode-build .tile.state-empty:hover,
#gameArea.mode-build .tile.state-plowed:hover,
#gameArea.mode-build .tile.state-growing:hover,
#gameArea.mode-build .tile.state-ready:hover,
#gameArea.mode-build .tile.not-allowed:hover {
  cursor: url('/assets/cursors/hammer.png') 0 31, pointer !important;
}

#gameArea.mode-build.destroy-active .tile:hover,
#gameArea.mode-build.destroy-active .tile.state-empty:hover,
#gameArea.mode-build.destroy-active .tile.state-plowed:hover,
#gameArea.mode-build.destroy-active .tile.state-growing:hover,
#gameArea.mode-build.destroy-active .tile.state-ready:hover,
#gameArea.mode-build.destroy-active .tile.not-allowed:hover {
  cursor: url('/assets/cursors/sledge%20hammer.png') 0 31, pointer !important;
}

#world {
  position: absolute;
  left: 0;
  top: 0;
  will-change: auto;
  transform-origin: 0 0;
  transform: translate3d(0, 0, 0) scale(1);
  transition: none;
  backface-visibility: hidden;
  transform-style: flat;
}

.farm-sign-wrap {
  position: absolute;
  transform: translate(-50%, -100%);
  z-index: 640;
  pointer-events: none;
}

.farm-sign-btn {
  width: clamp(92px, 14vw, 180px);
  height: auto;
  aspect-ratio: 2.68 / 1;
  margin: 0;
  min-height: 0;
  min-width: 0;
  max-width: 92vw;
  padding: 0;
  border-radius: 0;
  border: 0;
  background: transparent;
  color: #2f2518;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.55), 0 1px 2px rgba(0, 0, 0, 0.25);
  box-shadow: none;
  display: block;
  pointer-events: auto;
  cursor: pointer;
  position: relative;
  overflow: visible;
}

.farm-sign-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
  pointer-events: none;
}

.farm-sign-btn:disabled {
  opacity: 1;
  cursor: default;
  background: transparent;
  border: 0;
  box-shadow: none;
}

#farmSignText {
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
  width: 58%;
  height: 38%;
  position: absolute;
  left: 21%;
  top: 24%;
  z-index: 1;
  text-align: center;
  line-height: 1.02;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  pointer-events: none;
}

.farm-sign-edit {
  position: absolute;
  top: 8%;
  right: 12%;
  z-index: 1;
  font-size: 15px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.82;
  border-radius: 999px;
  padding: 3px 6px;
  background: rgba(240, 224, 184, 0.84);
  border: 1px solid rgba(114, 88, 45, 0.58);
}

.farm-sign-btn:hover .farm-sign-edit {
  opacity: 1;
}

.farm-name-editor {
  position: absolute;
  left: 50%;
  top: calc(var(--topbar-height) + 12px);
  transform: translateX(-50%);
  z-index: 705;
  width: min(360px, calc(100vw - 16px));
}

.farm-name-editor-card {
  background: rgba(245, 237, 216, 0.97);
  border: 1px solid rgba(174, 154, 111, 0.92);
  border-radius: 12px;
  box-shadow: 0 12px 22px rgba(16, 31, 13, 0.35);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.farm-name-editor-card input {
  margin: 0;
}

.farm-name-editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hud-backdrop {
  position: absolute;
  inset: 0;
  z-index: 495;
  background: rgba(10, 18, 12, 0.32);
}

.hud-panel {
  position: absolute;
  z-index: 500;
  background: rgba(245, 237, 216, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border: 1px solid rgba(174, 154, 111, 0.9);
  box-shadow: 0 10px 24px rgba(19, 35, 20, 0.3);
}

#hudLeft {
  left: 16px;
  top: 16px;
  width: min(268px, calc(100vw - 28px));
}

.panel {
  background: linear-gradient(180deg, #fffef6, #f2ead6);
  border: 1px solid #c8b487;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.45) inset, 0 4px 10px rgba(36,29,15,0.12);
}

.hud-panel.panel {
  background: rgba(245, 237, 216, 0.88);
  border: 1px solid rgba(174, 154, 111, 0.9);
  box-shadow: 0 5px 12px rgba(19, 35, 20, 0.16);
}

.status-panel {
  display: grid;
  gap: 9px;
  width: 100%;
}

.status-block {
  background: transparent;
  border-radius: 0;
  padding: 2px 0;
  display: grid;
  gap: 5px;
  border-top: 1px solid rgba(96, 104, 86, 0.22);
}

.status-block:first-child {
  border-top: 0;
  padding-top: 0;
}

.overview {
  grid-template-columns: 62px 1fr;
  align-items: center;
}

.level-badge {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: radial-gradient(circle at 28% 28%, #fff5da, #e2bd62);
  border: 1px solid #b59248;
  color: #3f2c10;
  font-weight: 700;
  font-size: 11px;
}

.level-badge strong {
  font-size: 17px;
  line-height: 1;
}

.xp-wrap {
  display: grid;
  gap: 4px;
}

.xp-label {
  font-size: 11px;
  color: #54615a;
  display: flex;
  justify-content: space-between;
}

.xp-track {
  height: 7px;
  border-radius: 999px;
  background: #d7d8d2;
  overflow: hidden;
  max-width: 150px;
}

.xp-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5da95e, #2f7f4a);
  transition: width 220ms ease;
}

.storage-track {
  max-width: 100%;
}

.storage-fill {
  transition: width 180ms ease;
}

.storage-fill.storage-ok {
  background: linear-gradient(90deg, #5da95e, #2f7f4a);
}

.storage-fill.storage-warn {
  background: linear-gradient(90deg, #d1b23f, #9f7d1f);
}

.storage-fill.storage-danger {
  background: linear-gradient(90deg, #d16868, #a43d3d);
}

.storage-fill.storage-full {
  animation: storage-full-pulse 0.75s infinite;
}

@keyframes storage-full-pulse {
  0%,100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

.status-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #617167;
}

.coin-line {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.1;
}

.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  line-height: 1.2;
}

.status-row span {
  color: #617167;
}

.expand-btn {
  margin-top: 3px;
  padding: 7px 8px;
  min-height: 34px;
  font-size: 13px;
}

.expand-btn:disabled {
  opacity: 0.62;
}

.expand-need {
  min-height: 14px;
  font-size: 11px;
}

.toast-message {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translate(-50%, -6px);
  max-width: min(560px, calc(100vw - 24px));
  min-width: min(240px, calc(100vw - 32px));
  z-index: 550;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, transform 220ms ease, visibility 220ms;
  border: 1px solid transparent;
  box-shadow: 0 6px 14px rgba(24, 34, 20, 0.2);
}

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

.toast-message.toast-success {
  background: rgba(228, 247, 233, 0.94);
  border-color: #a9d9b4;
  color: #1f5a30;
}

.toast-message.toast-info {
  background: rgba(250, 245, 213, 0.94);
  border-color: #dfd08e;
  color: #5b4a12;
}

.toast-message.toast-error {
  background: rgba(252, 230, 230, 0.95);
  border-color: #efb8b8;
  color: #7a1f1f;
}

.tractor-status {
  position: absolute;
  left: 50%;
  top: calc(var(--topbar-height) + 10px);
  transform: translateX(-50%);
  z-index: 730;
  pointer-events: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(57, 98, 68, 0.88);
  background: rgba(225, 242, 228, 0.94);
  color: #1f4c32;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 10px rgba(16, 38, 23, 0.2);
}

.tractor-confirm-backdrop {
  position: absolute;
  inset: 0;
  z-index: 735;
  display: grid;
  place-items: center;
  background: rgba(11, 18, 13, 0.36);
}

.tractor-confirm-panel {
  width: min(360px, calc(100vw - 22px));
  border-radius: 12px;
  border: 1px solid #beab7a;
  background: linear-gradient(180deg, #f3ead2, #e3d5b4);
  box-shadow: 0 12px 24px rgba(18, 30, 20, 0.35);
  padding: 12px;
  color: #2a342c;
  display: grid;
  gap: 8px;
}

.tractor-confirm-panel p {
  margin: 0;
  color: #39493d;
}

.tractor-confirm-meta {
  font-size: 12px;
  color: #4a5b4d;
}

.tractor-confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-float {
  position: absolute;
  z-index: 560;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(26, 33, 24, 0.64);
  border: 1px solid rgba(255,255,255,0.18);
  color: #eef6ec;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  transform: translateY(0);
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  transition: opacity 900ms ease, transform 900ms ease;
}

.action-float.show {
  opacity: 1;
  transform: translateY(-18px);
}

.action-float .coin-plus {
  color: #8af0a8;
}

.action-float .coin-minus {
  color: #ff9f9f;
}

.action-float .xp-plus {
  color: #a5d6ff;
}

.action-float .xp-zero {
  color: #d7e0ec;
}

.build-cursor-badge {
  position: absolute;
  z-index: 640;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(35, 51, 34, 0.72);
  color: #eef6ec;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.build-cursor-badge img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.read-only-banner {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 620;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(46, 59, 39, 0.86);
  border: 1px solid rgba(255,255,255,0.22);
  color: #eef6ec;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
}

.return-farm-top {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 621;
  width: auto;
  margin: 0;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #3d9867, #2e754f);
  border: 1px solid #245d3f;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 12px rgba(16, 27, 14, 0.24);
}

#gameArea.read-only-mode #hudBottom {
  opacity: 0.55;
}

#gameArea.read-only-mode #hudBottom button,
#gameArea.read-only-mode #hudBottom input,
#gameArea.read-only-mode #hudBottom select {
  pointer-events: none;
}

#gameArea.read-only-mode .tile:hover {
  cursor: not-allowed !important;
}

.leaderboard-modal {
  position: absolute;
  inset: 0;
  z-index: 720;
  background: rgba(9, 18, 11, 0.45);
  display: grid;
  place-items: center;
}

.expand-confirm-modal {
  position: absolute;
  inset: 0;
  z-index: 715;
  background: rgba(9, 18, 11, 0.46);
  display: grid;
  place-items: center;
  padding: 12px;
}

.expand-confirm-panel {
  width: min(520px, calc(100vw - 20px));
  border-radius: 14px;
  background: rgba(245, 237, 216, 0.98);
  border: 1px solid rgba(174, 154, 111, 0.92);
  box-shadow: 0 14px 24px rgba(16, 31, 13, 0.35);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.expand-confirm-head {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(138, 124, 93, 0.42);
  background: rgba(255, 249, 234, 0.72);
}

.expand-confirm-body {
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.expand-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  font-size: 13px;
}

.expand-line span {
  color: #617167;
}

.coins-after-row strong {
  font-size: 15px;
}

.coins-after-row.low strong {
  color: #8b5d00;
}

.coins-after-row.critical strong {
  color: #8f2323;
}

.expand-sustain-text {
  margin: 2px 0 0;
  padding: 8px 9px;
  border-radius: 10px;
  background: rgba(255, 248, 232, 0.82);
  border: 1px solid rgba(185, 163, 122, 0.55);
  font-size: 12px;
  color: #4a4a3a;
  line-height: 1.35;
}

.expand-sustain-text.low {
  background: rgba(255, 243, 210, 0.9);
  border-color: rgba(193, 146, 64, 0.6);
}

.expand-sustain-text.critical {
  background: rgba(255, 232, 232, 0.92);
  border-color: rgba(196, 90, 90, 0.62);
  color: #6d1f1f;
}

.expand-confirm-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(138, 124, 93, 0.32);
}

.expand-confirm-btn.low-funds {
  filter: saturate(0.78);
}

.leaderboard-panel {
  width: min(920px, calc(100vw - 16px));
  max-height: min(84dvh, calc(100dvh - var(--topbar-height) - env(safe-area-inset-bottom, 0px) - 16px));
  border-radius: 14px;
  background: rgba(245, 237, 216, 0.97);
  border: 1px solid rgba(174, 154, 111, 0.92);
  box-shadow: 0 14px 24px rgba(16, 31, 13, 0.35);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.leaderboard-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid rgba(138, 124, 93, 0.4);
}

.leaderboard-tabs {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.lb-tab {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  min-height: 36px;
  border-radius: 9px;
  background: rgba(56, 84, 53, 0.9);
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: none;
}

.lb-tab.active {
  background: linear-gradient(180deg, #3a9a62, #2e7a4d);
}

.leaderboard-list {
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 66px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(106, 118, 88, 0.35);
  background: rgba(241, 239, 226, 0.86);
}

.lb-row.you {
  border-color: rgba(47, 115, 74, 0.88);
  box-shadow: 0 0 0 1px rgba(47, 115, 74, 0.35) inset;
}

.lb-rank {
  font-weight: 800;
  color: #3b4d2d;
}

.lb-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lb-main span {
  font-size: 12px;
  color: #5e6a61;
}

.lb-view-btn {
  min-height: 36px;
}

.leaderboard-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(138, 124, 93, 0.4);
}

.muted { color: var(--muted); }

.farm-grid {
  position: relative;
  width: 520px;
  height: 320px;
  pointer-events: auto;
  overflow: visible;
}

.farm-layer {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.ground-layer {
  pointer-events: auto;
}

.object-layer {
  pointer-events: none;
}

.crop-layer {
  pointer-events: none;
}

.preview-layer {
  pointer-events: none;
}

.tile-stack {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
}

.tile {
  position: absolute;
  width: calc(var(--tile-w) * var(--tile-overlap-scale));
  height: calc(var(--tile-h) * var(--tile-overlap-scale));
  padding: 0;
  border: 1px solid rgba(70, 53, 30, 0.35);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: none;
  transition: transform 70ms ease, background-color 70ms ease;
  transform: translate(-50%, -50%);
  transform-origin: center;
  overflow: visible;
  isolation: isolate;
  z-index: 1;
  backface-visibility: hidden;
  transform-style: flat;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: inherit;
  pointer-events: none;
  background:
    radial-gradient(120% 85% at 30% 20%, rgba(255,255,255,0.22), rgba(255,255,255,0) 62%),
    radial-gradient(120% 90% at 72% 72%, rgba(0,0,0,0.18), rgba(0,0,0,0) 68%),
    linear-gradient(135deg, rgba(0,0,0,0.14), rgba(255,255,255,0.06));
  opacity: var(--tile-blend-opacity);
  mix-blend-mode: multiply;
}

.tile-debug {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: rgba(18, 28, 22, 0.92);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.75),
    0 0 2px rgba(255, 255, 255, 0.75);
}

.tile:hover {
  outline: 1px solid rgba(255,255,255,0.2);
}

.tile:active {
  transform: translate(-50%, -50%) scale(0.98);
}

.tile.state-empty {
  background-color: #688912;
  background-image: var(--empty-tile-image), linear-gradient(180deg, #7b9f1e, #688912);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}
.tile.state-plowed {
  background-color: #7e5638;
  background-image: var(--plowed-tile-image), linear-gradient(180deg, #9b6941, #77482d);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}
.tile.state-growing {
  background-color: #6c9a37;
  background-image: var(--plowed-tile-image), linear-gradient(180deg, rgba(117, 176, 86, 0.65), rgba(65, 120, 49, 0.65));
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}
.tile.state-ready {
  background-color: #7a8f3d;
  background-image: var(--empty-tile-image), linear-gradient(180deg, rgba(201, 174, 79, 0.55), rgba(146, 118, 42, 0.55));
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}
.tile.selected {
  outline: 2px solid #203527;
}

.tile.paint-hit {
  outline: 2px solid rgba(255,255,255,0.2);
}

.tile.ground-cover {
  overflow: hidden;
}

.crop-actor {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  transform-origin: bottom center;
  pointer-events: none;
  overflow: visible;
  backface-visibility: hidden;
  transform-style: flat;
}

.crop-sprite {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  backface-visibility: hidden;
  transform-style: flat;
}

.crop-shadow {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.32;
  overflow: visible;
  background:
    radial-gradient(62% 38% at 50% 54%, rgba(0, 0, 0, 0.34), rgba(0, 0, 0, 0.08) 62%, rgba(0, 0, 0, 0) 100%);
}

.crop-shadow img {
  display: none;
}

.tile.state-empty:hover {
  cursor: url('/assets/cursors/plow.png') 0 31, pointer;
}

.tile.state-plowed:hover {
  cursor: url('/assets/cursors/seeds.png') 0 31, pointer;
}

.tile.state-ready:hover {
  cursor: url('/assets/cursors/harvest.png') 0 31, pointer;
}

.tile.state-growing:hover {
  cursor: default;
}

.tile.not-allowed:hover {
  cursor: not-allowed;
}

.tile.tractor-tile:hover {
  cursor: url('/assets/cursors/hand.png') 0 31, pointer;
}

.tile.animal-tile:hover {
  cursor: url('/assets/cursors/hand.png') 0 31, pointer;
}

.tile.animal-soil {
  background-image: var(--plowed-tile-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.legend {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.placed-object {
  position: absolute;
  transform: translate(-50%, -100%);
  transform-origin: bottom center;
  pointer-events: none;
  transition: opacity 80ms linear;
  filter: none;
  backdrop-filter: none;
  will-change: auto;
  backface-visibility: hidden;
  transform-style: flat;
}

.placed-object img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  transition: none;
  filter: none;
  backdrop-filter: none;
  backface-visibility: hidden;
  transform-style: flat;
}

.placed-object.item-barn,
.build-preview.item-barn {
  overflow: hidden;
}

.placed-object.item-barn img,
.build-preview.item-barn img {
  object-position: center bottom;
  /*
    Footprint clamp:
    Keep full upper structure, but force ground-contact region
    to a 2x2 diamond front edge so forward apron is hidden.
  */
  clip-path: polygon(
    0% 0%,
    100% 0%,
    100% 82%,
    76% 90%,
    50% 96%,
    24% 90%,
    0% 82%
  );
}

.placed-object.fence-item {
  transform: translate(-50%, -100%);
  transition: none;
  filter: none;
  backdrop-filter: none;
}

.placed-object.fence-item img {
  object-fit: fill;
  object-position: center bottom;
  transition: none;
  filter: none;
  backdrop-filter: none;
}

.placed-object.animal-object {
  pointer-events: none;
}

.placed-object.animal-object .animal-needs-feed {
  position: absolute;
  left: 50%;
  top: 70%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: rgba(174, 41, 41, 0.92);
  border: 1px solid rgba(255, 233, 233, 0.75);
  box-shadow: 0 2px 5px rgba(18, 18, 18, 0.28);
}

.placed-object.animal-object .animal-storage-full {
  position: absolute;
  left: 58%;
  top: 70%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 9px;
  color: #fff;
  background: rgba(116, 64, 20, 0.94);
  border: 1px solid rgba(255, 233, 194, 0.8);
  box-shadow: 0 2px 5px rgba(18, 18, 18, 0.28);
}

.placed-object.animal-object.state-ready img {
  filter: saturate(1.1) brightness(1.06);
}

.placed-object.tractor-face-right img {
  transform: scaleX(-1);
  transform-origin: center bottom;
}

.preview-cell {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  transform: translate(-50%, -50%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border: 2px dashed rgba(255,255,255,0.95);
  background: rgba(84, 195, 111, 0.22);
}

.preview-cell.invalid {
  border-color: rgba(246, 103, 103, 0.95);
  background: rgba(219, 54, 54, 0.26);
}

.build-preview {
  position: absolute;
  transform: translate(-50%, -100%);
  transform-origin: bottom center;
  opacity: 0.45;
  pointer-events: none;
  filter: brightness(1.1);
}

.build-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.invalid-placement {
  opacity: 0.25 !important;
}

.occluded {
  opacity: 0.35;
  pointer-events: none;
  transition: opacity 80ms linear;
}

.hud-bottom {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(32, 46, 35, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 18px rgba(16, 27, 14, 0.28);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.camera-hud {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 610;
  width: 186px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(32, 46, 35, 0.62);
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 8px 18px rgba(16, 27, 14, 0.28);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  gap: 6px;
}

.cam-title {
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #dbe8dd;
  font-weight: 700;
}

.cam-zoom-row {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 6px;
  align-items: center;
}

.cam-zoom-value {
  text-align: center;
  color: #edf8ef;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 7px 4px;
}

.cam-move-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
}

#camUpBtn { grid-column: 2; grid-row: 1; }
#camLeftBtn { grid-column: 1; grid-row: 2; }
#camRightBtn { grid-column: 3; grid-row: 2; }
#camDownBtn { grid-column: 2; grid-row: 2; }

.cam-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cam-btn {
  margin: 0;
  width: 100%;
  padding: 7px 8px;
  min-height: 34px;
  border-radius: 8px;
  background: linear-gradient(180deg, #3d9867, #2e754f);
  border: 1px solid #245d3f;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(255,255,255,0.24) inset, 0 3px 8px rgba(12, 22, 13, 0.25);
}

.cam-btn:focus-visible {
  outline: 2px solid rgba(221, 255, 231, 0.9);
  outline-offset: 1px;
}

.hidden {
  display: none !important;
}

.tool-tabs {
  display: inline-flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.22);
}

.tool-tab {
  width: auto;
  margin: 0;
  border-radius: 0;
  padding: 7px 12px;
  background: rgba(36, 58, 39, 0.85);
  border: 0;
  color: #d8e8d9;
  font-size: 13px;
  box-shadow: none;
}

.tool-tab.active {
  background: linear-gradient(180deg, #3a9a62, #2e7a4d);
  color: #fff;
}

.build-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.build-slot {
  min-width: 270px;
}

.danger-soft {
  background: linear-gradient(180deg, #a55e56, #834740);
  border-color: #6d352f;
}

.danger-soft.active {
  outline: 2px solid rgba(255, 205, 205, 0.6);
}

.seed-slot {
  width: auto;
  min-width: 240px;
  margin: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(245, 237, 216, 0.95);
  color: #1f2d23;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.seed-slot img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.seed-slot span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.clear-seed {
  width: auto;
  margin: 0;
  padding: 7px 10px;
  border-radius: 10px;
}

.seed-picker {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  z-index: 700;
  width: min(520px, calc(100vw - 28px));
  max-height: min(56dvh, calc(100dvh - var(--topbar-height) - var(--hud-bottom) - env(safe-area-inset-bottom, 0px) - 18px));
  border-radius: 14px;
  padding: 10px;
  background: rgba(245, 237, 216, 0.96);
  border: 1px solid rgba(174, 154, 111, 0.92);
  box-shadow: 0 14px 24px rgba(16, 31, 13, 0.35);
  display: grid;
  gap: 8px;
}

.seed-picker.hidden {
  display: none;
}

.seed-picker-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.seed-picker-head strong {
  flex: 0 0 auto;
}

.picker-min-btn {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  min-height: 36px;
  border-radius: 9px;
  background: rgba(56, 84, 53, 0.9);
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: none;
}

.seed-picker-head input {
  margin: 0;
  flex: 1;
}

.seed-list {
  overflow: auto;
  max-height: 320px;
  display: grid;
  gap: 6px;
  padding-right: 3px;
  background: rgba(103, 137, 18, 0.08);
  border-radius: 10px;
  border: 1px solid rgba(108, 132, 79, 0.25);
}

.seed-empty {
  padding: 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.68);
  color: #5e6a61;
}

.item-group {
  display: grid;
  gap: 6px;
  padding: 4px;
}

.item-group-title {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #4f5f45;
  padding: 2px 6px;
}

.item-row {
  width: 100%;
  margin: 0;
  min-height: 64px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(106, 118, 88, 0.35);
  background: rgba(241, 239, 226, 0.86);
  color: #233128;
  text-align: left;
}

.item-row.hidden-row {
  display: none;
}

.item-row:hover {
  border-color: rgba(72, 119, 55, 0.62);
  background: rgba(244, 246, 234, 0.95);
}

.item-row.active {
  border-color: rgba(47, 115, 74, 0.88);
  box-shadow: 0 0 0 1px rgba(47, 115, 74, 0.35) inset;
}

.item-icon {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(0,0,0,0.1);
  overflow: hidden;
}

.item-icon img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.item-row[data-type="seed"] .item-icon img {
  width: 40px;
  height: 40px;
}

.stage-dots {
  position: absolute;
  left: 4px;
  bottom: 2px;
  display: inline-flex;
  gap: 2px;
}

.stage-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(78, 121, 54, 0.55);
}

.item-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.item-main strong {
  font-size: 14px;
  line-height: 1.1;
}

.item-main .meta {
  font-size: 12px;
  color: #5e6a61;
}

.item-right {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

.item-cost {
  font-size: 13px;
  line-height: 1;
  font-weight: 700;
  color: #465741;
}

.item-action {
  width: auto;
  margin: 0;
  min-height: 34px;
  min-width: 78px;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 12px;
  box-shadow: none;
}

.item-row.unaffordable {
  opacity: 0.82;
}

.item-row.locked {
  opacity: 0.58;
}

.item-row.locked .item-icon::after {
  content: "??";
  position: absolute;
  right: -5px;
  bottom: -5px;
  font-size: 12px;
}

.item-row.unaffordable .item-action,
.item-row.locked .item-action {
  background: rgba(116, 128, 116, 0.65);
  border-color: rgba(95, 105, 95, 0.7);
  cursor: not-allowed;
}

.seed-warning {
  margin: 0;
  min-height: 18px;
  color: #9d3226;
  font-weight: 600;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 6px;
}

.swatch.empty { background: #c4ad7a; }
.swatch.plowed { background: #8b5d3b; }
.swatch.growing { background: #54a15f; }
.swatch.ready { background: #d89a32; }

.profile-panel {
  max-width: 980px;
  margin: 24px auto 34px;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid rgba(180, 160, 117, 0.72);
  box-shadow: 0 10px 26px rgba(26, 37, 20, 0.22);
}

.profile-panel h1 {
  margin: 0 0 16px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.profile-grid-compact {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.profile-grid div {
  background: #f8f2e5;
  border-radius: 12px;
  padding: 12px 14px;
}

.profile-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.profile-section {
  margin-top: 22px;
}

.profile-section h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.profile-table-wrap {
  background: #f8f2e5;
  border: 1px solid rgba(174, 154, 111, 0.6);
  border-radius: 10px;
  overflow: auto;
}

.profile-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

.profile-table th,
.profile-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(174, 154, 111, 0.35);
  text-align: left;
  font-size: 13px;
}

.profile-table th {
  background: #efe4cd;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #465741;
}

.profile-table tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 820px) {
  .profile-panel {
    margin: 14px 10px 20px;
    padding: 14px;
  }

  .profile-grid {
    gap: 10px;
  }

  .profile-section {
    margin-top: 16px;
  }
}

@media (max-width: 1023px) {
  .topbar {
    padding: 10px 12px;
  }

  .topbar-stats-btn {
    display: inline-block;
  }

  #statsToggleBtn {
    display: inline-block;
  }

  #hudLeft {
    left: 10px;
    top: 10px;
    width: min(320px, calc(100vw - 20px));
    max-height: calc(100% - 22px);
    overflow: auto;
    transform: translateX(calc(-100% - 16px));
    transition: transform 180ms ease;
  }

  #gameArea.hud-open #hudLeft {
    transform: translateX(0);
  }

  .hud-bottom {
    position: fixed;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    transform: none;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  .tool-tabs,
  .seed-slot,
  .clear-seed,
  .build-controls {
    flex: 0 0 auto;
  }

  .seed-slot {
    min-width: 220px;
  }

  .seed-slot span {
    max-width: 150px;
  }

  .camera-hud {
    left: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 108px);
    width: 182px;
  }

  .cam-btn,
  .tool-tab,
  .clear-seed,
  .topbar-stats-btn {
    min-height: 44px;
  }

  .seed-slot,
  .build-slot {
    min-height: 44px;
  }

  .sound-panel {
    right: 10px;
    top: calc(var(--topbar-height) + 2px);
  }

  .seed-picker {
    width: calc(100vw - 16px);
    left: 8px;
    transform: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 108px);
    max-height: calc(100dvh - var(--topbar-height) - var(--hud-bottom) - env(safe-area-inset-bottom, 0px) - 18px);
  }

  .hud-panel {
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
}

@media (min-width: 600px) and (max-width: 1023px) {
  #hudLeft {
    width: min(340px, calc(100vw - 24px));
  }

  .hud-bottom {
    left: 10px;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    padding: 10px;
  }

  .camera-hud {
    left: auto;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 126px);
    width: 172px;
  }

  .seed-slot {
    min-width: 250px;
  }

  .seed-picker {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 120px);
  }
}

@media (max-width: 599px) {
  .topbar {
    gap: 8px;
  }

  .nav-links {
    gap: 10px;
  }

  .nav-links a,
  .linkish {
    font-size: 14px;
  }

  .sound-panel {
    right: 8px;
    left: 8px;
    width: auto;
    top: calc(var(--topbar-height) + 4px);
  }

  #hudLeft {
    width: min(92vw, 340px);
    border-radius: 10px;
  }

  .status-panel {
    gap: 8px;
  }

  .level-badge {
    width: 50px;
    height: 50px;
  }

  .hud-bottom {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    border-radius: 12px;
    padding: 7px;
  }

  .tool-tab {
    padding: 8px 10px;
    font-size: 13px;
  }

  .seed-slot {
    min-width: 188px;
    padding: 7px 8px;
    gap: 8px;
  }

  .seed-slot img {
    width: 30px;
    height: 30px;
  }

  .seed-slot span {
    font-size: 13px;
    max-width: 128px;
  }

  .clear-seed {
    font-size: 12px;
    padding: 7px 9px;
  }

  .camera-hud {
    left: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
    width: 160px;
    padding: 7px;
  }

  .cam-zoom-value {
    font-size: 11px;
  }

  .seed-picker {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 106px);
    padding: 8px;
  }

.leaderboard-panel {
    width: calc(100vw - 8px);
    max-height: calc(100dvh - 10px - env(safe-area-inset-bottom, 0px));
    border-radius: 10px;
  }

  .leaderboard-head {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lb-row {
    grid-template-columns: 52px 1fr;
  }

  .lb-view-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .item-row {
    grid-template-columns: 44px 1fr auto;
    min-height: 60px;
    font-size: 13px;
  }

  .item-main .meta {
    font-size: 11px;
  }
}

.inventory-panel {
  width: min(760px, calc(100vw - 16px));
}

.inventory-head-note {
  font-size: 12px;
}

.inventory-list {
  gap: 8px;
}

.inventory-row {
  grid-template-columns: 48px 1fr auto;
}

.inventory-actions {
  gap: 6px;
}

.inventory-actions .item-action {
  min-width: 72px;
  padding: 6px 10px;
}









/* Safe-area and dynamic viewport reliability overrides */
#gameArea {
  padding-bottom: calc(var(--hud-bottom) + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 1024px) {
  #hudLeft {
    max-height: calc(100dvh - var(--topbar-height) - var(--hud-bottom) - env(safe-area-inset-bottom, 0px) - 14px);
    overflow-y: auto;
  }

  #gameArea {
    padding-bottom: calc(var(--hud-bottom) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  .hud-bottom {
    position: fixed;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  }

  .camera-hud {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--hud-bottom) + 12px);
  }

  .seed-picker {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--hud-bottom) + 12px);
    max-height: calc(100dvh - var(--topbar-height) - var(--hud-bottom) - env(safe-area-inset-bottom, 0px) - 18px);
  }

  .leaderboard-panel {
    max-height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-bottom, 0px) - 12px);
  }
}

@media (min-width: 600px) and (max-width: 1024px) {
  .hud-bottom {
    left: 10px;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  }

  .camera-hud {
    left: auto;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--hud-bottom) + 20px);
  }
}

@media (max-width: 768px) {
  #gameArea {
    padding-bottom: calc(var(--hud-bottom) + env(safe-area-inset-bottom, 0px) + 10px);
  }

  .hud-bottom {
    left: 8px;
    right: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  }

  .camera-hud {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--hud-bottom) + 12px);
  }

  .seed-picker {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--hud-bottom) + 10px);
  }

  .farm-sign-btn {
    width: clamp(92px, 28vw, 150px);
    max-width: 56vw;
    font-size: 13px;
  }

  .farm-sign-edit {
    opacity: 1;
    font-size: 16px;
  }

  .farm-name-editor {
    top: calc(var(--topbar-height) + 8px);
  }
}

/* Mobile hotbar final layout override (no horizontal scroll) */
@media (max-width: 768px) {
  :root {
    --hud-bottom: 126px;
  }

  #gameArea {
    padding-bottom: calc(max(var(--hud-bottom), 126px) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  .hud-bottom {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 0;
    transform: none;
    width: auto;
    max-width: none;
    min-height: 126px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px;
    align-items: stretch;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: hidden;
  }

  .tool-tabs {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    border-radius: 11px;
  }

  .tool-tab {
    width: 100%;
    min-height: 44px;
    padding: 10px 8px;
    font-size: 13px;
    text-align: center;
  }

  .seed-slot,
  .build-slot {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    grid-column: 1;
  }

  .seed-slot span {
    max-width: 100%;
    min-width: 0;
  }

  #clearSeedBtn,
  #clearBuildBtn,
  #clearAnimalBtn {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    margin: 0;
    font-size: 0;
    line-height: 1;
    display: inline-grid;
    place-items: center;
  }

  #clearSeedBtn::before,
  #clearBuildBtn::before,
  #clearAnimalBtn::before {
    content: "✕";
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
  }

  .build-controls,
  #animalControls {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    align-items: stretch;
  }

  .build-controls .build-slot,
  #animalControls .build-slot {
    grid-column: 1 / -1;
  }

  #rotateBuildBtn,
  #destroyModeBtn,
  #rotateAnimalBtn,
  #destroyAnimalModeBtn {
    min-height: 44px;
    width: 100%;
    padding: 8px 6px;
    margin: 0;
    font-size: 12px;
  }

  .hud-bottom button {
    min-height: 44px;
  }

  .hud-bottom button:active {
    transform: translateY(1px);
    filter: brightness(0.94);
  }
}

/* Logged-out landing page */
body.landing-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background:
    radial-gradient(980px 420px at 16% -6%, rgba(255,255,255,0.18), rgba(255,255,255,0)),
    radial-gradient(920px 420px at 90% 112%, rgba(29,70,33,0.2), rgba(29,70,33,0)),
    linear-gradient(180deg, #72b760 0%, #66a856 56%, #5a984b 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.landing-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #fff7e7, #efe4cd);
  border-bottom: 1px solid #b89f70;
  box-shadow: 0 2px 0 rgba(255,255,255,0.45) inset, 0 6px 16px rgba(48,35,18,0.16);
}

.landing-brand {
  display: inline-flex;
  align-items: center;
}

.landing-brand-sign {
  position: relative;
  display: inline-block;
  width: clamp(120px, 13vw, 180px);
  aspect-ratio: 2.68 / 1;
}

.landing-brand-sign img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.landing-brand-sign strong {
  position: absolute;
  left: 20%;
  top: 24%;
  width: 60%;
  height: 38%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0;
  color: #2a261e;
  font-weight: 800;
  letter-spacing: 0;
  font-size: clamp(9px, 0.95vw, 14px);
  line-height: 0.95;
  text-shadow: 0 1px 0 rgba(255,245,220,0.55);
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
}

.landing-top-actions {
  display: inline-flex;
  gap: 8px;
}

.landing-link-btn {
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  text-decoration: none;
}

.landing-link-btn.primary {
  background: linear-gradient(180deg, #318b5b, #256d47);
}

.landing-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px 14px calc(20px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 14px;
}

.landing-hero {
  position: relative;
  overflow: hidden;
  min-height: 240px;
  border-radius: 14px;
}

.landing-hero-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(920px 360px at 75% 8%, rgba(255,255,255,0.2), rgba(255,255,255,0)),
    linear-gradient(rgba(27,65,33,0.34), rgba(27,65,33,0.34)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 8px, rgba(0,0,0,0.05) 8px 16px),
    linear-gradient(180deg, #6dbb5b, #4d9046 52%, #42793e);
  filter: saturate(1.1);
}

.landing-hero-content {
  position: relative;
  z-index: 1;
  padding: 24px;
  max-width: 620px;
  color: #f8f4e7;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}

.landing-hero h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 4.6vw, 44px);
  line-height: 1.05;
}

.landing-hero p {
  margin: 0;
  font-size: clamp(15px, 2.1vw, 19px);
  color: #e9e3cf;
}

.landing-cta-row {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.landing-cta {
  width: auto;
  min-width: 138px;
  min-height: 44px;
  border-radius: 11px;
  padding: 10px 16px;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.landing-cta.primary {
  background: linear-gradient(180deg, #3ca46b, #2a7a50);
}

.landing-section h2 {
  margin: 0 0 8px;
  font-size: clamp(20px, 3vw, 30px);
  color: #183124;
}

.landing-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.landing-preview-card {
  padding: 10px;
  border-radius: 12px;
}

.landing-preview-art {
  min-height: 120px;
  border-radius: 10px;
  border: 1px solid rgba(138, 116, 73, 0.45);
  display: grid;
  place-items: center;
  background:
    linear-gradient(165deg, rgba(255,255,255,0.2), rgba(0,0,0,0.05)),
    linear-gradient(180deg, #7dc166, #5a9f4f);
}

.landing-preview-art img {
  max-width: 72%;
  max-height: 100px;
  object-fit: contain;
  image-rendering: auto;
}

.landing-preview-card p {
  margin: 8px 0 0;
  font-weight: 600;
  color: #304131;
}

.landing-shot-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.landing-shot-card {
  padding: 10px;
  border-radius: 12px;
}

.landing-shot {
  position: relative;
  min-height: 180px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(138, 116, 73, 0.45);
  background:
    radial-gradient(320px 140px at 22% 0%, rgba(255,255,255,0.22), rgba(255,255,255,0)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 8px, rgba(0,0,0,0.04) 8px 16px),
    linear-gradient(180deg, #75be62, #589f4d 54%, #4a8642);
}

.shot-layer {
  position: absolute;
  display: block;
  max-width: none;
  image-rendering: auto;
}

.shot-farm .shot-crop {
  width: 42%;
  left: 30%;
  bottom: 20%;
}

.shot-farm .shot-build {
  width: 78%;
  left: 11%;
  bottom: 8%;
  opacity: 0.88;
}

.shot-farm .shot-animal {
  width: 22%;
  left: 12%;
  bottom: 16%;
}

.shot-builds .shot-barn {
  width: 58%;
  left: 21%;
  bottom: 19%;
}

.shot-builds .shot-fence {
  width: 72%;
  left: 14%;
  bottom: 8%;
}

.shot-builds .shot-crop2 {
  width: 26%;
  left: 62%;
  bottom: 15%;
}

.shot-animals .shot-cow {
  width: 34%;
  left: 12%;
  bottom: 18%;
}

.shot-animals .shot-sheep {
  width: 26%;
  left: 52%;
  bottom: 22%;
}

.shot-animals .shot-path2 {
  width: 80%;
  left: 10%;
  bottom: 8%;
  opacity: 0.86;
}

.landing-shot-card p {
  margin: 8px 0 0;
  font-weight: 600;
  color: #304131;
}

.landing-how-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.landing-how-card {
  padding: 10px;
  border-radius: 10px;
}

.landing-how-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.landing-how-card p {
  margin: 0;
  color: #425245;
  font-size: 14px;
}

.landing-why,
.landing-strong-cta,
.landing-seo {
  padding: 14px;
  border-radius: 12px;
}

.landing-why p,
.landing-seo p {
  margin: 0;
  color: #39493d;
  line-height: 1.45;
}

.landing-strong-cta {
  text-align: center;
  background: linear-gradient(180deg, #fff7e7, #ece0c5);
}

.landing-strong-cta p {
  margin: 2px 0 0;
  color: #48584a;
}

.landing-strong-cta .landing-cta-row {
  justify-content: center;
}

.landing-seo {
  background: linear-gradient(180deg, #f3ead2, #e3d5b4);
  border: 1px solid #beab7a;
}

.landing-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 1024px) {
  .landing-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .landing-shot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .landing-how-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .landing-topbar {
    padding: 10px 10px;
  }

  .landing-brand-sign {
    width: clamp(108px, 36vw, 142px);
  }

  .landing-brand-sign strong {
    font-size: clamp(8px, 2.6vw, 11px);
  }

  .landing-main {
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .landing-hero {
    min-height: 208px;
  }

  .landing-hero-content {
    padding: 14px;
  }

  .landing-cta-row {
    gap: 8px;
  }

  .landing-cta {
    flex: 1 1 0;
    min-width: 0;
  }

  .landing-preview-grid,
  .landing-shot-grid,
  .landing-how-grid {
    grid-template-columns: 1fr;
  }
}
