:root {
  color-scheme: dark;
  --ink: #fff4dd;
  --muted: #c9c0aa;
  --panel: rgba(18, 21, 19, 0.74);
  --line: rgba(255, 244, 221, 0.18);
  --leaf: #4ee08f;
  --sky: #59c9ff;
  --gold: #ffd35c;
  --rose: #ff6d86;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101410;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

#farmShell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 540px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 16%, rgba(89, 201, 255, 0.12), transparent 34%),
    linear-gradient(180deg, #171611 0%, #111a16 48%, #19170f 100%);
}

html[data-runtime="discord"] #farmShell,
body[data-runtime="discord"] #farmShell {
  min-height: 0;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#farmCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.farm-hud {
  position: absolute;
  z-index: 7;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(180px, 1fr);
  align-items: start;
  gap: 12px;
  pointer-events: none;
}

.farm-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.farm-cluster.right {
  justify-content: flex-end;
}

.farm-button,
.farm-brand,
.farm-stat,
.farm-center,
.farm-presence,
.farm-toast {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
}

.farm-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
  font-size: 12px;
  font-weight: 950;
}

.farm-login[data-auth="authenticated"] {
  border-color: rgba(78, 224, 143, 0.72);
  color: #dfffea;
}

.farm-login[data-auth="pending"] {
  border-color: rgba(255, 211, 92, 0.72);
  color: var(--gold);
}

.farm-login[data-auth="error"] {
  border-color: rgba(255, 109, 134, 0.72);
  color: #ffd7df;
}

.farm-brand {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(78, 224, 143, 0.92), rgba(255, 211, 92, 0.84)),
    var(--panel);
  color: #102016;
  font-size: 16px;
  font-weight: 950;
}

.farm-stat {
  min-width: 72px;
  height: 48px;
  padding: 7px 10px;
  border-radius: 8px;
}

.farm-presence {
  display: flex;
  min-width: 112px;
  max-width: 210px;
  height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  overflow: hidden;
  border-radius: 8px;
  color: #dfffea;
  font-size: 11px;
  font-weight: 950;
  line-height: 1.15;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.farm-presence[data-mode="discord"],
.farm-presence[data-mode="discord-demo"] {
  border-color: rgba(89, 201, 255, 0.42);
  color: #d7f2ff;
}

.stat-label,
.center-label {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  line-height: 1;
}

.stat-value {
  display: block;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 950;
  line-height: 1;
}

.farm-center {
  min-width: 194px;
  height: 68px;
  padding: 9px 16px 10px;
  border-radius: 8px;
  text-align: center;
}

.center-value {
  display: block;
  margin-top: 6px;
  color: #fff2bd;
  text-shadow:
    0 0 16px rgba(255, 211, 92, 0.8),
    0 0 28px rgba(78, 224, 143, 0.24);
  font-variant-numeric: tabular-nums;
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 950;
  line-height: 1;
  white-space: nowrap;
}

.farm-toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(150px, calc(env(safe-area-inset-bottom) + 128px));
  min-width: 124px;
  padding: 9px 14px;
  transform: translateX(-50%) translateY(10px);
  border-radius: 8px;
  color: var(--gold);
  text-align: center;
  font-size: 12px;
  font-weight: 950;
  opacity: 0;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.farm-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.farm-guide {
  position: fixed;
  z-index: 9;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(8, 11, 10, 0.64);
  backdrop-filter: blur(10px);
}

.farm-guide[hidden] {
  display: none;
}

.farm-guide-panel {
  width: min(680px, 100%);
  max-height: min(680px, calc(100dvh - 36px));
  overflow: auto;
  border: 1px solid rgba(255, 244, 221, 0.2);
  border-radius: 8px;
  background: rgba(13, 17, 15, 0.92);
  box-shadow:
    0 24px 90px rgba(0, 0, 0, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.farm-guide-head {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  background: rgba(13, 17, 15, 0.96);
  border-bottom: 1px solid rgba(255, 244, 221, 0.12);
}

.farm-guide h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.farm-guide-close {
  flex: 0 0 auto;
}

.farm-guide-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px 20px;
}

.farm-guide-body section {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(255, 244, 221, 0.13);
  border-radius: 8px;
  background: rgba(255, 244, 221, 0.055);
}

.farm-guide h3 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 15px;
  line-height: 1.2;
}

.farm-guide p {
  margin: 0;
  color: #ded2bd;
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.farm-button:hover,
.farm-button:focus-visible,
.farm-primary:hover,
.farm-primary:focus-visible {
  border-color: rgba(255, 211, 92, 0.84);
  outline: none;
  box-shadow:
    0 0 0 3px rgba(255, 211, 92, 0.2),
    0 14px 42px rgba(0, 0, 0, 0.34);
}

.farm-overlay {
  position: fixed;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 100%, rgba(78, 224, 143, 0.09), transparent 42%),
    linear-gradient(180deg, rgba(16, 20, 16, 0.1), rgba(16, 20, 16, 0.7));
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.farm-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.farm-panel {
  width: min(560px, calc(100vw - 48px));
  min-width: 0;
  max-width: calc(100vw - 48px);
  padding: 28px 24px;
  border: 1px solid rgba(255, 244, 221, 0.2);
  border-radius: 8px;
  background: rgba(13, 17, 15, 0.82);
  backdrop-filter: blur(18px);
  text-align: center;
  box-shadow:
    0 24px 90px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.farm-mark {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  place-items: center;
  border: 1px solid rgba(255, 211, 92, 0.42);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(78, 224, 143, 0.22), rgba(89, 201, 255, 0.16)),
    rgba(255, 255, 255, 0.05);
  color: var(--gold);
  font-size: 24px;
  font-weight: 950;
  text-shadow: 0 0 18px rgba(255, 211, 92, 0.55);
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(34px, 7vw, 54px);
  font-weight: 950;
  line-height: 1.04;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.farm-panel p {
  margin: 14px 0 22px;
  color: #ded2bd;
  font-size: clamp(15px, 3.7vw, 18px);
  font-weight: 760;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.farm-primary {
  display: inline-flex;
  min-width: 176px;
  max-width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(255, 211, 92, 0.52);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 211, 92, 0.96), rgba(78, 224, 143, 0.85) 48%, rgba(89, 201, 255, 0.9)),
    #ffd35c;
  color: #111a16;
  cursor: pointer;
  font-size: 16px;
  font-weight: 950;
  box-shadow: 0 16px 46px rgba(255, 211, 92, 0.2);
}

.farm-primary:active {
  transform: translateY(1px);
}

@media (max-width: 820px) {
  #farmShell {
    min-height: 480px;
  }

  .farm-hud {
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  .farm-cluster {
    gap: 6px;
  }

  .farm-button {
    width: 44px;
    height: 44px;
  }

  .farm-stat {
    min-width: 50px;
    height: 44px;
    padding: 6px 8px;
  }

  .farm-presence {
    min-width: 86px;
    max-width: 132px;
    height: 44px;
    padding: 0 9px;
    font-size: 10px;
  }

  .hide-small {
    display: none;
  }

  .farm-center {
    min-width: 118px;
    height: 62px;
    padding: 8px 12px;
  }

  .farm-panel {
    padding: 24px 18px;
  }

  .farm-guide-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;
  }

  #farmShell {
    height: max(100dvh, 1400px);
    min-height: 1400px;
  }

  #farmCanvas {
    touch-action: pan-y;
  }

  .farm-hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    grid-template-columns: auto minmax(112px, 1fr) auto;
    gap: 6px;
  }

  .farm-brand {
    display: none;
  }

  .farm-cluster.right {
    gap: 6px;
  }

  .farm-center {
    min-width: 112px;
    height: 54px;
    padding: 7px 8px;
  }

  .center-value {
    margin-top: 5px;
    font-size: 16px;
  }

  .farm-presence {
    display: none;
  }

  .farm-toast {
    bottom: max(70px, calc(env(safe-area-inset-bottom) + 58px));
    max-width: calc(100vw - 24px);
    white-space: normal;
  }

  .farm-guide {
    align-items: end;
    padding: max(56px, env(safe-area-inset-top)) 10px 10px;
  }

  .farm-guide-panel {
    max-height: calc(100dvh - 66px);
  }
}

@media (max-width: 380px) {
  .farm-hud {
    gap: 4px;
  }

  .farm-button {
    width: 38px;
    height: 40px;
  }

  .farm-center {
    min-width: 128px;
    padding: 7px 6px;
  }

  .center-label {
    font-size: 9px;
  }

  .center-value {
    font-size: 13px;
  }

  .farm-cluster.right {
    gap: 4px;
  }

  .farm-stat {
    min-width: 46px;
    height: 40px;
    padding: 6px;
  }
}

@media (max-height: 520px) {
  #farmShell {
    min-height: 0;
  }

  .farm-overlay {
    padding: 12px;
  }

  .farm-panel {
    width: min(520px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    padding: 18px 18px;
  }

  .farm-mark {
    width: 48px;
    height: 48px;
    margin-bottom: 10px;
    font-size: 21px;
  }

  h1 {
    font-size: clamp(30px, 7vw, 46px);
  }

  .farm-panel p {
    margin: 10px 0 16px;
    font-size: 15px;
    line-height: 1.45;
  }

  .farm-primary {
    min-height: 48px;
  }
}
