:root {
  --ink: #243128;
  --cream: #f5f0dd;
  --moss: #526447;
  --leaf: #6d8a57;
  --honey: #e5a62b;
  --sky: #dce9dc;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.game-shell {
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--sky);
}

.hud {
  z-index: 5;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(130px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(36, 49, 40, 0.25);
  background: rgba(245, 240, 221, 0.94);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  font-family: Georgia, serif;
  font-size: 1.35rem;
  text-decoration: none;
}

.brand b { color: #b37316; font-weight: 700; }
.brand-mark {
  display: grid;
  width: 34px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: .9rem;
  font-style: italic;
}

.stats { display: flex; align-items: center; gap: clamp(15px, 3vw, 36px); }
.stat { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 750; }
.stat small { display: block; color: #657167; font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.stat-icon { color: var(--honey); font-size: .75rem; }

.energy-wrap { width: min(100%, 190px); justify-self: end; }
.energy-label { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: .65rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.energy-track { height: 8px; overflow: hidden; border: 1px solid var(--ink); border-radius: 99px; background: rgba(255,255,255,.45); }
.energy-track span { display: block; width: 100%; height: 100%; background: #7d9b5a; transition: width 180ms linear, background 180ms; }

.viewport { position: relative; min-height: 0; overflow: hidden; background: var(--sky); }
#game { display: block; width: 100%; height: 100%; }

.welcome {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 45, 36, .28);
  backdrop-filter: blur(4px);
}
.welcome[hidden] { display: none; }
.welcome-card {
  width: min(100%, 470px);
  padding: clamp(25px, 5vw, 44px);
  border: 1px solid rgba(36,49,40,.5);
  border-radius: 4px;
  background: rgba(245,240,221,.97);
  box-shadow: 0 22px 70px rgba(26, 38, 29, .24);
}
.kicker { margin: 0 0 11px; color: #687366; font-size: .68rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.welcome h1 { margin: 0 0 16px; font-family: Georgia, serif; font-size: clamp(3rem, 11vw, 5.2rem); font-weight: 400; letter-spacing: -.055em; line-height: .82; }
.welcome p:not(.kicker) { max-width: 390px; margin: 0; color: #536057; line-height: 1.55; }
.how-to { display: grid; grid-template-columns: 1fr 1fr; gap: 11px 16px; margin: 25px 0; font-size: .75rem; }
.how-to span { display: flex; align-items: center; gap: 7px; }
kbd { min-width: 34px; padding: 4px 6px; border: 1px solid #8b9186; border-bottom-width: 2px; border-radius: 3px; background: #fffdf5; text-align: center; font: 700 .63rem ui-monospace, monospace; }
.welcome button {
  width: 100%; min-height: 50px; border: 0; border-radius: 3px; background: var(--ink); color: var(--cream); cursor: pointer; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.welcome button:hover { background: #4e654f; }

.worker-menu {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 45, 36, .42);
  backdrop-filter: blur(5px);
}
.worker-menu[hidden] { display: none; }
.worker-panel {
  width: min(100%, 620px);
  max-height: calc(100% - 20px);
  overflow: auto;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(36,49,40,.55);
  border-radius: 5px;
  background: rgba(245,240,221,.98);
  box-shadow: 0 22px 70px rgba(26,38,29,.28);
}
.worker-panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.worker-panel-heading h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 7vw, 3.25rem); font-weight: 400; letter-spacing: -.045em; line-height: 1; }
.worker-close { width: 38px; height: 38px; flex: none; border: 1px solid rgba(36,49,40,.4); border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; font-size: 1.4rem; line-height: 1; }
.worker-intro { margin: 12px 0 22px; color: #5f695f; font-size: .84rem; }
.worker-options { display: grid; gap: 10px; }
.worker-option {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  grid-template-areas: "art copy price" "art copy count";
  gap: 2px 16px;
  align-items: center;
  width: 100%;
  min-height: 86px;
  border: 1px solid rgba(36,49,40,.32);
  border-radius: 4px;
  padding: 10px 14px;
  background: rgba(255,253,245,.65);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.worker-option:hover:not(:disabled), .worker-option:focus-visible { border-color: var(--ink); background: #fffdf5; transform: translateY(-1px); }
.worker-option:disabled { cursor: not-allowed; opacity: .46; }
.worker-option img { grid-area: art; width: 62px; height: 46px; object-fit: contain; }
.worker-copy { grid-area: copy; }
.worker-copy strong, .worker-copy small { display: block; }
.worker-copy strong { margin-bottom: 4px; font-family: Georgia, serif; font-size: 1.08rem; }
.worker-copy small { color: #657067; font-size: .72rem; line-height: 1.35; }
.worker-price { grid-area: price; color: #9a681c; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.worker-price b { font-size: .9rem; }
.worker-count { grid-area: count; align-self: start; color: #798078; font-size: .62rem; text-align: right; }

.toast {
  position: absolute; top: 18px; left: 50%; z-index: 4; max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 999px; background: rgba(36,49,40,.86); color: #fffbee; font-size: .75rem; opacity: 0; transform: translate(-50%, -8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.carrying { position: absolute; top: 16px; right: 16px; padding: 7px 10px; border: 1px solid rgba(36,49,40,.3); border-radius: 99px; background: rgba(245,240,221,.9); font-size: .7rem; font-weight: 700; }

.game-footer {
  z-index: 5;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px max(18px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  border-top: 1px solid rgba(36,49,40,.25);
  background: var(--cream);
  color: #687267;
  font-size: .72rem;
}
.game-footer p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-footer div { display: flex; gap: 15px; flex: none; }
.game-footer button { border: 0; padding: 2px 0; background: transparent; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.mobile-controls { display: none; position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.joystick { position: absolute; left: max(22px, env(safe-area-inset-left)); bottom: 22px; width: 112px; height: 112px; border: 1px solid rgba(36,49,40,.36); border-radius: 50%; background: rgba(245,240,221,.42); pointer-events: auto; }
.joystick span { position: absolute; left: 35px; top: 35px; width: 42px; height: 42px; border-radius: 50%; background: rgba(36,49,40,.75); }
.action-stack { position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: 22px; display: grid; grid-template-columns: repeat(2, 64px); gap: 10px; align-items: end; pointer-events: auto; }
.action-button { width: 64px; height: 64px; border: 1px solid rgba(36,49,40,.5); border-radius: 50%; background: rgba(245,240,221,.86); color: var(--ink); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.sting-button { grid-row: span 2; align-self: center; width: 76px; height: 76px; background: rgba(36,49,40,.87); color: var(--cream); }
.seed-button, .worker-button { opacity: .45; }
.seed-button.ready, .worker-button.ready { opacity: 1; }

@media (pointer: coarse), (max-width: 760px) {
  .mobile-controls { display: block; }
  .game-footer { display: none; }
  .hud { min-height: 61px; grid-template-columns: auto 1fr; gap: 10px; padding-block: 7px; }
  .brand { font-size: 1.05rem; }
  .brand-mark { width: 29px; }
  .stats { justify-self: end; gap: 12px; }
  .stat { min-width: 36px; font-size: .82rem; }
  .stat small { font-size: .52rem; }
  .energy-wrap { grid-column: 1 / -1; width: 100%; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 9px; }
  .energy-label { margin: 0; gap: 7px; }
  .energy-track { height: 6px; }
  .how-to { grid-template-columns: 1fr; }
  .welcome-card { max-height: calc(100svh - 80px); overflow: auto; }
  .worker-menu { align-items: end; padding: 10px; }
  .worker-panel { width: 100%; max-height: calc(100% - 8px); padding: 22px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 12px 12px 4px 4px; }
  .worker-option { grid-template-columns: 54px minmax(0, 1fr) auto; min-height: 78px; padding: 9px 10px; gap: 2px 10px; }
  .worker-option img { width: 52px; height: 40px; }
}

@media (max-width: 390px) {
  .worker-copy small { font-size: .66rem; }
  .worker-price { font-size: .62rem; }
  .worker-option { grid-template-columns: 46px minmax(0, 1fr) auto; }
  .worker-option img { width: 44px; }
}

@media (max-height: 600px) and (pointer: coarse) {
  .joystick { width: 86px; height: 86px; bottom: 10px; }
  .joystick span { left: 27px; top: 27px; width: 32px; height: 32px; }
  .action-stack { bottom: 10px; grid-template-columns: repeat(2, 52px); }
  .action-button { width: 52px; height: 52px; }
  .sting-button { width: 62px; height: 62px; }
}

@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; } }
