:root {
  --accent: #3fae4b;
  --accent-dark: #2d7d36;
  --panel-bg: rgba(20, 24, 18, 0.92);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #0d1510;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  color: #eef3ea;
  user-select: none;
}

#gameRoot { position: fixed; inset: 0; touch-action: none; }
.hidden { display: none !important; }

canvas#gameCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  background: #3d6b2e;
  touch-action: none;
}

/* ---------- overlays / panels ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 5, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 16px;
}
.panel {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 22px 24px;
  max-width: 420px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.panel h1 { margin: 0 0 4px; font-size: 26px; text-align: center; }
.panel h2 { margin: 0 0 14px; font-size: 20px; }
.sub { text-align: center; opacity: 0.75; font-size: 13px; margin: 0 0 18px; }
.fine-print { font-size: 11.5px; opacity: 0.65; line-height: 1.4; margin-top: 14px; }

/* ---------- auth ---------- */
.auth-panel { max-width: 360px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px; border: none;
  background: rgba(255,255,255,0.06); color: #cfd8ca; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--accent); color: #07260a; }
#authForm { display: flex; flex-direction: column; gap: 12px; }
#authForm label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; opacity: 0.85; }
#authForm input {
  padding: 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05); color: #fff; font-size: 16px;
}
.error { color: #ff8a80; font-size: 13px; min-height: 16px; }
.primary-btn, .secondary-btn {
  padding: 13px; border-radius: 12px; border: none; font-size: 15px; font-weight: 700;
  cursor: pointer; width: 100%; margin-top: 6px;
}
.primary-btn { background: var(--accent); color: #07260a; }
.primary-btn:active { background: var(--accent-dark); }
.secondary-btn { background: rgba(255,255,255,0.08); color: #eef3ea; }

/* ---------- HUD ---------- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px 0;
  z-index: 10;
  pointer-events: none;
}
.safe-top { padding-top: calc(10px + var(--safe-top)); }
.safe-bottom { padding-bottom: calc(10px + var(--safe-bottom)); }
.hud-top .pill, .hud-top .icon-btn { pointer-events: auto; }

.pill {
  background: rgba(10,15,8,0.72);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px; font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(2px);
}
.spacer { flex: 1; }
.icon-btn {
  background: rgba(10,15,8,0.72);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff; border-radius: 999px;
  width: 38px; height: 38px; font-size: 17px;
  cursor: pointer;
}

.toasts {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  z-index: 15; pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  background: rgba(10,15,8,0.88);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  animation: toastIn 0.18s ease-out;
}
.toast.err { border-color: #ff6b5e; color: #ffb4ab; }
.toast.ok { border-color: #8ee07a; }
@keyframes toastIn { from { opacity:0; transform: translateY(-6px);} to {opacity:1; transform:none;} }

.big-banner {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(10,15,8,0.9); border: 2px solid var(--accent);
  padding: 16px 26px; border-radius: 16px; font-size: 20px; font-weight: 800;
  text-align: center; z-index: 20; pointer-events: none;
}

/* ---------- joystick ---------- */
.joy-zone {
  position: absolute; left: 0; bottom: 0; top: 0; width: 55%;
  z-index: 8;
  touch-action: none;
}
.joy-base {
  position: absolute; width: 112px; height: 112px; border-radius: 50%;
  background: rgba(255,255,255,0.10); border: 2px solid rgba(255,255,255,0.25);
  z-index: 12; pointer-events: none;
  transform: translate(-50%, -50%);
}
.joy-knob {
  position: absolute; width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255,255,255,0.55);
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}

/* ---------- bottom controls ---------- */
.hud-bottom {
  position: absolute; right: 0; bottom: 0; left: 0;
  display: flex; justify-content: flex-end; align-items: flex-end;
  gap: 10px; padding: 0 12px;
  z-index: 10;
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }

.seed-row { display: flex; flex-direction: column; gap: 8px; margin-right: 4px; margin-bottom: 4px; }
.seed-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(10,15,8,0.78); border: 2px solid transparent;
  border-radius: 999px; padding: 6px 10px; font-size: 13px; font-weight: 700;
  color: #fff; cursor: pointer;
}
.seed-chip.selected { border-color: var(--accent); background: rgba(63,174,75,0.25); }
.seed-chip .n { opacity: 0.8; font-weight: 600; }

.action-cluster { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 4px; }
.side-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(10,15,8,0.78); border: 1px solid rgba(255,255,255,0.18);
  font-size: 22px; color: #fff; cursor: pointer;
}
.boost-btn.active { background: #e0a93a; }
.work-btn {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--accent); border: 3px solid rgba(255,255,255,0.35);
  font-size: 34px; color: #07260a; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.work-btn:active { background: var(--accent-dark); transform: scale(0.96); }
.work-btn.deny { background: #c0392b; }

.boost-bar-wrap {
  position: absolute; right: 16px; bottom: 150px; width: 10px; height: 90px;
  background: rgba(0,0,0,0.4); border-radius: 6px; overflow: hidden; z-index: 9;
}
.boost-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 100%; background: #e0a93a; transition: height 0.1s linear; }

/* ---------- shop ---------- */
.shop-panel { max-width: 480px; }
.shop-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.shop-header h2 { flex: 1; margin: 0; }
.shop-section { margin-bottom: 16px; }
.shop-section h3 { font-size: 13px; text-transform: uppercase; opacity: 0.65; margin: 0 0 8px; letter-spacing: 0.04em; }
.shop-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; background: rgba(255,255,255,0.05); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.shop-row .label { font-weight: 700; font-size: 14px; }
.shop-row .desc { font-size: 11.5px; opacity: 0.65; }
.shop-row .buy-btn {
  background: var(--accent); color: #07260a; border: none; border-radius: 8px;
  padding: 9px 14px; font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.shop-row .buy-btn:disabled { background: #555; color: #999; cursor: not-allowed; }
.shop-row .buy-btn.owned { background: #2d7d36; }
.plot-timer { font-size: 11.5px; color: #ffcf6b; margin-top: 4px; }

.howto-panel ol { padding-left: 20px; font-size: 13.5px; line-height: 1.6; }

@media (min-width: 700px) {
  .joy-zone { width: 40%; }
}
