/* Grubs of War — garden-almanac-at-war UI
   Palette: loam #2a1f17 · kraft #e8d5a8 · leaf #5da345 · ladybug #d8402c
            beetle #3e6fd8 · honey #f2b632 (metamorphosis gold) */

:root {
  --loam: #2a1f17;
  --loam-2: #4a2e18;
  --kraft: #e8d5a8;
  --kraft-hi: #f2e4c0;
  --kraft-deep: #c9a96c;
  --leaf: #5da345;
  --leaf-dark: #3f7a2c;
  --ladybug: #d8402c;
  --beetle: #3e6fd8;
  --honey: #f2b632;
  --honey-dark: #96690e;
  --wood-hi: #a06a3c;
  --wood: #8a5a33;
  --wood-dark: #7a4a28;
  --cream: #f7ecd4;
  --display: 'Luckiest Guy', 'Arial Rounded MT Bold', 'Chalkboard SE', 'Comic Sans MS', cursive;
  --body: 'Nunito', 'Avenir Next', 'Trebuchet MS', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--body);
  background: #1a1410;
  color: var(--loam);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
kbd {
  font-family: var(--body);
  font-size: 0.72em;
  font-weight: 800;
  background: rgba(42, 31, 23, 0.85);
  color: var(--cream);
  border-radius: 4px;
  padding: 1px 5px 2px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 1.5px 0 rgba(0, 0, 0, 0.5);
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--honey);
  outline-offset: 2px;
}

#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; display: block; cursor: crosshair; touch-action: none; }
body.touch #game { cursor: default; }
#hud button, .tc-btn { touch-action: none; }
#menu, #weaponPanel { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#weaponPanel .w-btn { touch-action: pan-y; } /* taps still fire; vertical scroll stays possible */
.touch-note { font-size: 12px; font-weight: 700; opacity: 0.75; margin-top: 8px; line-height: 1.5; }

/* ============================= HUD ============================= */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; font-size: 14px; }
#hud > * { pointer-events: none; }

#hudTop {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: flex; align-items: flex-start; gap: 12px;
}

/* team planks */
#teamPlanks { display: flex; flex-direction: column; gap: 6px; min-width: 190px; }
.plank-team {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 8px;
  align-items: center;
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 55%, var(--wood-dark));
  border: 2px solid var(--loam-2);
  border-left: 6px solid var(--team-c, #888);
  border-radius: 7px;
  padding: 4px 9px 5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 3px 6px rgba(0, 0, 0, 0.35);
  opacity: 0.82;
  transition: opacity 0.25s, transform 0.25s;
}
.plank-team.active { opacity: 1; transform: scale(1.04); }
.pt-name {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.4px;
  color: var(--cream);
  text-shadow: 0 1.5px 0 rgba(0, 0, 0, 0.45);
  grid-column: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}
.pt-bar {
  grid-column: 1 / span 2;
  height: 7px;
  background: rgba(20, 12, 6, 0.65);
  border-radius: 4px;
  overflow: hidden;
}
.pt-bar span {
  display: block; height: 100%;
  background: linear-gradient(180deg, var(--team-c, #999), var(--team-dark, #555));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.pt-dots { grid-column: 2; grid-row: 1; display: flex; gap: 3px; justify-content: flex-end; }
.pt-dots i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--team-c, #999);
  border: 1.5px solid rgba(20, 12, 6, 0.55);
}
.pt-dots i.evo { background: var(--honey); box-shadow: 0 0 5px var(--honey); }
.pt-dots i.dead { background: transparent; border-style: dashed; opacity: 0.5; }

/* turn timer token */
#turnToken {
  margin: 0 auto;
  width: 64px; height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, var(--wood-hi) 0 28%, var(--wood) 29% 55%, var(--wood-dark) 56% 78%, var(--wood) 79%);
  border: 3px solid var(--loam-2);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.25), 0 4px 8px rgba(0, 0, 0, 0.4);
  display: grid; place-items: center;
}
#timerText {
  font-family: var(--display);
  font-size: 24px;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}
#turnToken.urgent { animation: pulse 0.8s infinite; border-color: var(--ladybug); }
#turnToken.urgent #timerText { color: #ffb0a0; }
@keyframes pulse { 50% { transform: scale(1.09); } }

/* wind */
#windBox {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: linear-gradient(180deg, var(--wood-hi), var(--wood-dark));
  border: 2px solid var(--loam-2);
  border-radius: 7px;
  padding: 5px 10px 7px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
  min-width: 130px;
}
#windLabel {
  font-family: var(--display); font-size: 10px; letter-spacing: 1.6px;
  color: var(--kraft); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  display: flex; gap: 6px; align-items: center;
}
#windArrow { font-size: 12px; }
#windBar {
  width: 110px; height: 8px;
  background: rgba(20, 12, 6, 0.65);
  border-radius: 4px;
  position: relative; overflow: hidden;
}
#windBar::after {
  content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px;
  width: 2px; background: rgba(255, 255, 255, 0.5);
}
#windFill {
  height: 100%;
  background: linear-gradient(90deg, #cdeafa, #7fb8e8);
  border-radius: 4px;
  transition: width 0.3s, margin-left 0.3s;
}

#pauseBtn, #centerBtn {
  pointer-events: auto;
  width: 40px; height: 40px;
  border-radius: 9px;
  border: 2px solid var(--loam-2);
  background: linear-gradient(180deg, var(--wood-hi), var(--wood-dark));
  color: var(--cream);
  font-size: 16px;
  box-shadow: 0 3px 0 var(--loam-2);
}
#pauseBtn:active, #centerBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--loam-2); }
#centerBtn { font-size: 20px; line-height: 1; }

/* banner — a sign dropped on twine */
#banner {
  position: absolute; top: 86px; left: 50%;
  transform: translateX(-50%);
  font-family: var(--display);
  font-size: 21px;
  letter-spacing: 0.5px;
  color: var(--loam);
  background: linear-gradient(180deg, var(--kraft-hi), var(--kraft));
  border: 3px solid var(--loam-2);
  border-radius: 10px;
  padding: 9px 22px 7px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 0 0 3px rgba(255, 255, 255, 0.3);
  white-space: nowrap;
  z-index: 6;
}
.banner-show { animation: bannerDrop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes bannerDrop {
  from { transform: translateX(-50%) translateY(-90px) rotate(-2deg); }
  to { transform: translateX(-50%) translateY(0) rotate(0); }
}
#banner.evolve { background: linear-gradient(180deg, #ffe9b0, var(--honey)); border-color: var(--honey-dark); text-shadow: 0 1px 0 #fff3; }
#banner.warn { background: linear-gradient(180deg, #f7c0b4, #e88a76); }
#banner.flood { background: linear-gradient(180deg, #bcdcf5, #7fb8e8); }

#toasts {
  position: absolute; top: 150px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 5px; align-items: center;
  z-index: 6;
}
.toast {
  font-weight: 800; font-size: 13px;
  color: var(--cream);
  background: rgba(42, 31, 23, 0.88);
  border: 1.5px solid rgba(232, 213, 168, 0.45);
  border-radius: 999px;
  padding: 4px 14px;
  animation: toastIn 0.25s ease;
  transition: opacity 0.5s;
}
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

/* bug card */
#bugCard {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 10px; align-items: center;
  background: linear-gradient(165deg, var(--kraft-hi), var(--kraft) 70%, var(--kraft-deep));
  border: 2.5px solid var(--loam-2);
  border-radius: 13px;
  padding: 9px 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 0 0 4px rgba(255, 255, 255, 0.22);
  pointer-events: auto;
}
#bcPortrait {
  width: 72px; height: 72px;
  background: radial-gradient(circle at 50% 35%, #fdf6e2, var(--kraft) 75%);
  border: 2.5px solid var(--team-c, var(--loam-2));
  border-radius: 50%;
}
#bcInfo { display: flex; flex-direction: column; gap: 3px; min-width: 148px; }
#bcName {
  font-family: var(--display); font-size: 17px; letter-spacing: 0.4px;
  color: var(--team-dark, var(--loam));
}
#bcForm { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: 0.65; margin-top: -3px; }
.bcBar {
  position: relative; height: 13px;
  background: rgba(42, 31, 23, 0.8);
  border-radius: 7px;
  overflow: hidden;
}
.bcBar > div { height: 100%; border-radius: 7px; transition: width 0.35s ease; }
#bcHpFill { background: linear-gradient(180deg, #7fc75e, var(--leaf-dark)); }
.bcBar span {
  position: absolute; inset: 0;
  font-size: 9.5px; font-weight: 900; color: #fff;
  display: grid; place-items: center;
  letter-spacing: 0.6px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
#bcMeterWrap { height: 12px; }
#bcMeterFill {
  background: linear-gradient(90deg, #c98c1e, var(--honey) 60%, #ffdf8a);
  position: relative;
}
#bcMeterWrap.full #bcMeterFill { animation: meterGlow 0.9s infinite alternate; }
#bcMeterWrap.evolved #bcMeterFill { background: linear-gradient(90deg, var(--honey), #ffe9b0); }
@keyframes meterGlow { from { filter: brightness(1); } to { filter: brightness(1.45); } }
#bcAbility {
  pointer-events: auto;
  display: flex; align-items: center; gap: 7px;
  background: linear-gradient(180deg, #ffe9b0, var(--honey));
  border: 2.5px solid var(--honey-dark);
  border-radius: 10px;
  padding: 7px 10px;
  box-shadow: 0 3px 0 var(--honey-dark);
  text-align: left;
}
#bcAbility:not(:disabled):hover { filter: brightness(1.06); }
#bcAbility:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--honey-dark); }
#bcAbility:disabled { filter: grayscale(0.75) brightness(0.85); cursor: default; }
#bcAbilityIcon { font-size: 17px; }
#bcAbilityName { font-family: var(--display); font-size: 12.5px; color: var(--loam); }
#bcAbilityUses { font-size: 10px; font-weight: 900; color: var(--honey-dark); letter-spacing: 2px; }

/* weapon dock */
#weaponDock {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  pointer-events: auto;
}
#fusePill {
  font-size: 11.5px; font-weight: 900;
  background: rgba(42, 31, 23, 0.88);
  color: var(--kraft);
  border-radius: 999px;
  padding: 3px 6px;
  display: flex; align-items: center; gap: 6px;
}
#fusePill b { color: var(--honey); font-size: 13px; }
#fusePill button {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(232, 213, 168, 0.5);
  background: rgba(232, 213, 168, 0.18);
  color: var(--kraft);
  font-size: 15px; font-weight: 900; line-height: 1;
}
#fusePill button:active { background: rgba(232, 213, 168, 0.4); }
#weaponToggle {
  display: flex; align-items: center; gap: 9px;
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 55%, var(--wood-dark));
  border: 2.5px solid var(--loam-2);
  border-radius: 11px;
  padding: 9px 14px;
  box-shadow: 0 4px 0 var(--loam-2), 0 7px 14px rgba(0, 0, 0, 0.35);
  color: var(--cream);
}
#weaponToggle:hover { filter: brightness(1.07); }
#weaponToggle:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--loam-2); }
#wtIcon { font-size: 21px; }
#wtName { font-family: var(--display); font-size: 14px; letter-spacing: 0.4px; text-shadow: 0 1.5px 0 rgba(0, 0, 0, 0.4); }
#wtAmmo { font-weight: 900; font-size: 12px; color: var(--honey); }

#weaponPanel {
  display: grid;
  grid-template-columns: repeat(3, 132px);
  gap: 6px;
  background: linear-gradient(165deg, var(--kraft-hi), var(--kraft) 70%, var(--kraft-deep));
  border: 2.5px solid var(--loam-2);
  border-radius: 13px;
  padding: 10px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45), inset 0 0 0 4px rgba(255, 255, 255, 0.22);
  max-height: 62vh; overflow-y: auto;
}
.w-btn {
  position: relative;
  display: grid;
  grid-template-columns: 26px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 7px;
  text-align: left;
  background: rgba(255, 252, 240, 0.55);
  border: 2px solid rgba(74, 46, 24, 0.35);
  border-radius: 9px;
  padding: 6px 8px;
  transition: transform 0.08s;
}
.w-btn:hover { background: rgba(255, 252, 240, 0.9); transform: translateY(-1px); }
.w-btn.sel { border-color: var(--leaf-dark); background: #e4f2d2; box-shadow: 0 0 0 2px var(--leaf); }
.w-btn.off { opacity: 0.45; cursor: default; }
.w-btn .w-ico { font-size: 19px; grid-row: 1 / span 2; }
.w-btn .w-name { font-weight: 800; font-size: 12px; color: var(--loam); }
.w-btn .w-ammo { font-size: 10.5px; font-weight: 900; color: var(--honey-dark); }
.w-btn kbd { position: absolute; top: 4px; right: 5px; }

#turnHint {
  position: absolute; bottom: 108px; left: 50%; transform: translateX(-50%);
  font-size: 12.5px; font-weight: 800;
  color: var(--cream);
  background: rgba(42, 31, 23, 0.82);
  border-radius: 999px;
  padding: 5px 16px;
  opacity: 0;
  white-space: nowrap;
}
#turnHint.fade { animation: hintFade 6s ease forwards; }
@keyframes hintFade { 0% { opacity: 0; } 8% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

.cpu-turn #weaponDock, .cpu-turn #bcAbility, .cpu-turn #turnHint { display: none; }

/* ============================= MENUS ============================= */
#menu {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(26, 18, 10, 0.25), rgba(26, 18, 10, 0.62));
  overflow-y: auto;
}
.screen { width: 100%; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 26px 16px; }

/* kraft sheet */
.sheet {
  position: relative;
  background: linear-gradient(160deg, var(--kraft-hi), var(--kraft) 55%, #dcc48e);
  border: 2.5px solid #b89468;
  border-radius: 16px;
  box-shadow: 0 20px 55px rgba(10, 6, 2, 0.55), inset 0 0 0 6px rgba(255, 255, 255, 0.2), inset 0 0 70px rgba(150, 105, 14, 0.12);
  padding: 26px 30px;
  max-width: min(1060px, 94vw);
}
.sheet::before {
  content: ''; position: absolute; inset: 9px;
  border: 2px dashed rgba(90, 60, 30, 0.3);
  border-radius: 10px;
  pointer-events: none;
}
.sheet-title {
  font-family: var(--display);
  font-size: 30px;
  color: var(--loam);
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

/* plank buttons */
.plank-btn {
  position: relative;
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.8px;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 50%, var(--wood-dark));
  border: 3px solid var(--loam-2);
  border-radius: 11px;
  padding: 12px 26px 9px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), inset 0 -3px 0 rgba(0, 0, 0, 0.22), 0 5px 0 var(--loam-2), 0 8px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.07s, filter 0.15s;
}
.plank-btn::before, .plank-btn::after {
  content: ''; position: absolute; top: 7px; width: 6px; height: 6px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d8c8a8, #6a5138 65%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}
.plank-btn::before { left: 8px; }
.plank-btn::after { right: 8px; }
.plank-btn:hover { filter: brightness(1.1); }
.plank-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 2px 0 var(--loam-2), 0 4px 8px rgba(0, 0, 0, 0.3); }
.plank-btn.big { font-size: 22px; padding: 15px 38px 11px; }
.plank-btn.go { background: linear-gradient(180deg, #74b856, var(--leaf) 50%, var(--leaf-dark)); border-color: #2e5c20; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.22), 0 5px 0 #2e5c20, 0 8px 14px rgba(0, 0, 0, 0.35); }
.plank-btn.go:active { box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), 0 2px 0 #2e5c20; }
.plank-btn.danger { background: linear-gradient(180deg, #e06a52, var(--ladybug) 50%, #a02a1c); border-color: #6e1c10; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28), 0 5px 0 #6e1c10, 0 8px 14px rgba(0, 0, 0, 0.35); }
.plank-btn.danger:active { box-shadow: inset 0 2px 0 rgba(255,255,255,0.28), 0 2px 0 #6e1c10; }

.chip-btn {
  font-weight: 800; font-size: 12.5px;
  color: var(--loam);
  background: rgba(255, 252, 240, 0.65);
  border: 2px solid rgba(74, 46, 24, 0.4);
  border-radius: 999px;
  padding: 6px 14px;
  transition: background 0.15s;
}
.chip-btn:hover { background: rgba(255, 252, 240, 0.95); }
.chip-row { display: flex; gap: 8px; justify-content: center; }

/* ---- title ---- */
#scrTitle { gap: 26px; }
.sign-post { position: relative; padding-top: 54px; }
.sign-post::before, .sign-post::after {
  content: ''; position: absolute; top: 0; width: 3px; height: 58px;
  background: repeating-linear-gradient(180deg, #d9c08a 0 6px, #b89468 6px 9px);
  transform: rotate(6deg);
}
.sign-post::before { left: 22%; transform: rotate(-7deg); }
.sign-post::after { right: 22%; }
.sign.plank-lg {
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 45%, var(--wood-dark));
  border: 4px solid var(--loam-2);
  border-radius: 16px;
  padding: 26px 48px 20px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.25), inset 0 -5px 0 rgba(0, 0, 0, 0.25), 0 14px 34px rgba(0, 0, 0, 0.5);
  transform: rotate(-1.5deg);
  animation: signSway 6s ease-in-out infinite;
  text-align: center;
}
@keyframes signSway { 0%, 100% { transform: rotate(-1.7deg); } 50% { transform: rotate(-0.6deg); } }
.logo {
  font-family: var(--display);
  font-size: clamp(46px, 9vw, 84px);
  line-height: 0.95;
  color: var(--cream);
  letter-spacing: 2px;
  text-shadow: 0 3px 0 var(--loam-2), 0 6px 0 rgba(0, 0, 0, 0.35), 0 10px 20px rgba(0, 0, 0, 0.4);
}
.logo-of {
  display: inline-block;
  font-size: 0.38em;
  color: var(--honey);
  margin: 0 10px;
  transform: rotate(-6deg) translateY(-0.5em);
  text-shadow: 0 2px 0 var(--honey-dark);
}
.tagline {
  margin-top: 8px;
  font-family: var(--display);
  font-size: clamp(13px, 2.2vw, 18px);
  color: var(--honey);
  letter-spacing: 1.6px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.title-foot .credit { font-size: 12px; font-weight: 700; color: rgba(247, 236, 212, 0.85); text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.attract-badge {
  position: absolute; right: 22px; bottom: 20px;
  font-family: var(--display); font-size: 11px; letter-spacing: 1.6px;
  color: var(--cream);
  background: rgba(216, 64, 44, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 6px 14px 4px;
  transform: rotate(3deg);
  animation: badgePulse 2.4s infinite;
}
@keyframes badgePulse { 50% { transform: rotate(3deg) scale(1.06); } }

/* ---- setup ---- */
.setup-sheet { width: min(1060px, 94vw); }
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 218px 1fr;
  gap: 18px;
  align-items: start;
}
.setup-mid { display: flex; flex-direction: column; gap: 7px; align-items: stretch; }
.opt-label {
  font-family: var(--display); font-size: 12px; letter-spacing: 1.4px;
  color: rgba(42, 31, 23, 0.65);
  margin-top: 7px;
}
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg.seg-col { flex-direction: column; }
.seg button {
  flex: 1;
  font-weight: 800; font-size: 12.5px;
  color: var(--loam);
  background: rgba(255, 252, 240, 0.5);
  border: 2px solid rgba(74, 46, 24, 0.35);
  border-radius: 8px;
  padding: 7px 8px;
}
.seg button.on {
  background: var(--leaf);
  border-color: var(--leaf-dark);
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}
.team-card {
  background: rgba(255, 252, 240, 0.45);
  border: 2.5px solid var(--team-c, #999);
  border-radius: 13px;
  padding: 13px;
  display: flex; flex-direction: column; gap: 10px;
}
.team-head { display: flex; align-items: center; gap: 8px; }
.team-name {
  flex: 1; min-width: 0;
  font-family: var(--display); font-size: 15px;
  color: var(--team-dark, var(--loam));
  background: transparent;
  border: none; border-bottom: 2px dashed rgba(74, 46, 24, 0.4);
  padding: 3px 2px;
}
.team-kind { font-size: 11px; font-weight: 900; white-space: nowrap; opacity: 0.75; }
.swatch-row { display: flex; gap: 7px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--sw);
  border: 2.5px solid rgba(42, 31, 23, 0.35);
}
.swatch.on { border-color: var(--loam); box-shadow: 0 0 0 2.5px rgba(255, 255, 255, 0.75); }
.slot-row { display: flex; gap: 7px; flex-wrap: wrap; }
.slot {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: radial-gradient(circle at 50% 32%, #fdf6e2, rgba(232, 213, 168, 0.85) 78%);
  border: 2px solid rgba(74, 46, 24, 0.4);
  border-radius: 11px;
  padding: 5px 6px 4px;
  transition: transform 0.1s;
}
.slot:hover { transform: translateY(-2px); border-color: var(--team-c, var(--loam)); }
.slot span { font-size: 10px; font-weight: 900; color: var(--loam); }
.slot canvas { width: 54px; height: 54px; }
.setup-actions { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 20px; }

/* species picker modal */
#pickerModal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(20, 14, 8, 0.6);
  padding: 18px;
  overflow-y: auto;
}
.picker-sheet {
  background: linear-gradient(160deg, var(--kraft-hi), var(--kraft));
  border: 2.5px solid #b89468;
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6);
  max-width: min(980px, 94vw);
  text-align: center;
}
.picker-sheet h3 { font-family: var(--display); font-size: 22px; margin-bottom: 14px; }
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(272px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.pick-card {
  text-align: left;
  background: rgba(255, 252, 240, 0.6);
  border: 2px solid rgba(74, 46, 24, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  transition: transform 0.1s, border-color 0.1s;
}
.pick-card:hover { transform: translateY(-2px); border-color: var(--honey-dark); background: #fdf3d8; }
.pick-icons { display: flex; align-items: center; justify-content: center; gap: 4px; }
.pick-arrow { color: var(--honey-dark); font-size: 15px; font-weight: 900; }
.pick-name { font-family: var(--display); font-size: 14.5px; color: var(--loam); text-align: center; }
.pick-name em { font-style: normal; color: var(--honey-dark); }
.pick-tag { font-size: 10.5px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; opacity: 0.6; text-align: center; margin-bottom: 5px; }
.pick-desc { font-size: 11.5px; font-weight: 700; line-height: 1.35; color: rgba(42, 31, 23, 0.85); }
.pick-desc.gold { color: var(--honey-dark); margin-top: 3px; }

/* ---- guide ---- */
.guide-sheet { width: min(1080px, 94vw); max-height: 92vh; overflow-y: auto; }
.meter-note {
  display: flex; gap: 14px; align-items: center;
  background: linear-gradient(90deg, rgba(242, 182, 50, 0.28), rgba(242, 182, 50, 0.1));
  border: 2px solid var(--honey-dark);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13.5px; font-weight: 700; line-height: 1.45;
  margin-bottom: 16px;
}
.meter-demo {
  flex: 0 0 54px; height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, #c98c1e, var(--honey) 60%, #ffdf8a);
  box-shadow: 0 0 10px rgba(242, 182, 50, 0.8);
  animation: meterGlow 0.9s infinite alternate;
}
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.guide-card {
  background: rgba(255, 252, 240, 0.55);
  border: 2px solid rgba(74, 46, 24, 0.3);
  border-radius: 12px;
  padding: 12px 14px;
}
.gline { font-size: 12px; font-weight: 700; line-height: 1.4; margin-top: 4px; color: rgba(42, 31, 23, 0.9); }
.gline.gold { color: var(--honey-dark); }
.gblurb { font-size: 11.5px; font-style: italic; opacity: 0.65; margin-top: 6px; }

/* ---- help ---- */
.help-sheet { width: min(1020px, 94vw); max-height: 92vh; overflow-y: auto; }
.help-cols { display: grid; grid-template-columns: 1fr 1.1fr; gap: 26px; margin-bottom: 16px; }
.help-cols h3 { font-family: var(--display); font-size: 17px; margin: 12px 0 8px; color: var(--loam); }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 3.5px 8px 3.5px 0; font-size: 12.5px; font-weight: 700; }
.keys td:first-child { white-space: nowrap; }
.rules { list-style: none; }
.rules li { font-size: 12.5px; font-weight: 700; line-height: 1.45; padding-left: 18px; position: relative; margin-bottom: 5px; }
.rules li::before { content: '🌱'; position: absolute; left: 0; font-size: 10px; top: 2px; }
.w-list { display: flex; flex-direction: column; gap: 4px; }
.w-row {
  display: grid;
  grid-template-columns: 26px 108px 30px 1fr;
  gap: 8px; align-items: baseline;
  font-size: 11.5px; font-weight: 700;
  background: rgba(255, 252, 240, 0.45);
  border-radius: 7px;
  padding: 4px 9px;
}
.w-row .w-ico { font-size: 15px; }
.w-row em { font-style: normal; color: var(--honey-dark); font-weight: 900; }

/* ---- pause & game over ---- */
.pause-sheet { min-width: 320px; }
.pause-btns { display: flex; flex-direction: column; gap: 11px; align-items: stretch; }
.over-sheet { min-width: min(680px, 92vw); text-align: center; }
.over-banner {
  font-family: var(--display);
  font-size: clamp(26px, 5vw, 40px);
  color: var(--team-c, var(--loam));
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5), 0 4px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 4px;
}
.over-quip { font-size: 14px; font-weight: 700; font-style: italic; opacity: 0.7; margin-bottom: 18px; }
.over-stats { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.over-stats th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
  color: rgba(42, 31, 23, 0.6);
  padding: 5px 8px;
}
.over-stats td {
  font-size: 14.5px; font-weight: 800;
  padding: 8px;
  background: rgba(255, 252, 240, 0.5);
  border-top: 6px solid transparent;
}
.over-stats td.st-name {
  font-family: var(--display);
  color: var(--team-c);
  border-left: 6px solid var(--team-c);
  border-radius: 8px 0 0 8px;
  text-align: left;
}

/* ============================= TOUCH CONTROLS ============================= */
#touchControls { position: absolute; inset: 0; pointer-events: none; display: none; }
.touch-mode #touchControls { display: block; }
.cpu-turn #touchControls { display: none; }

.tc-btn {
  pointer-events: auto;
  position: absolute;
  width: 58px; height: 58px;
  border-radius: 50%;
  font-size: 23px; line-height: 1;
  color: var(--cream);
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 55%, var(--wood-dark));
  border: 2.5px solid var(--loam-2);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 4px 0 var(--loam-2), 0 6px 12px rgba(0, 0, 0, 0.35);
  opacity: 0.93;
}
.tc-btn:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 2px 0 var(--loam-2); }
.tc-btn.off { filter: grayscale(0.7) brightness(0.8); }

#tcLeft  { left: calc(14px + env(safe-area-inset-left, 0px));  bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
#tcRight { left: calc(80px + env(safe-area-inset-left, 0px));  bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
#tcJump  { left: calc(14px + env(safe-area-inset-left, 0px));  bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
#tcFlip  { left: calc(80px + env(safe-area-inset-left, 0px));  bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

#tcFire {
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 84px; height: 84px;
  font-family: var(--display); font-size: 17px; letter-spacing: 1px;
  background: linear-gradient(180deg, #e06a52, var(--ladybug) 55%, #a02a1c);
  border-color: #6e1c10;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 5px 0 #6e1c10, 0 8px 14px rgba(0, 0, 0, 0.4);
}
#tcFire:active { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 2px 0 #6e1c10; }

#tcAbility {
  right: calc(108px + env(safe-area-inset-right, 0px));
  bottom: calc(38px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #ffe9b0, var(--honey));
  border-color: var(--honey-dark);
  color: var(--loam);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), 0 4px 0 var(--honey-dark), 0 6px 12px rgba(0, 0, 0, 0.35);
}
#tcAbility:active { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), 0 2px 0 var(--honey-dark); }
#tcAbilityUses {
  position: absolute; right: -3px; top: -5px;
  font-family: var(--body); font-size: 11px; font-weight: 900;
  background: var(--loam); color: var(--honey);
  border-radius: 999px; padding: 1px 6px;
}

#tcRotate {
  pointer-events: auto;
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(126px + env(safe-area-inset-bottom, 0px));
  font-weight: 900; font-size: 13px;
  color: var(--cream);
  background: rgba(42, 31, 23, 0.9);
  border: 2px solid rgba(232, 213, 168, 0.5);
  border-radius: 999px;
  padding: 8px 18px;
}

/* touch-mode HUD shuffle: card + dock move inboard of the button clusters */
.touch-mode kbd { display: none; }
.touch-mode #bcAbility { display: none; }
.touch-mode #bugCard {
  left: calc(146px + env(safe-area-inset-left, 0px));
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: scale(0.8);
  transform-origin: bottom left;
  padding: 7px 10px;
}
.touch-mode #weaponDock {
  right: calc(210px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: scale(0.9);
  transform-origin: bottom right;
}
.touch-mode #turnHint { bottom: 178px; }

/* rotate-for-best-view chip (portrait phones only) */
#rotateHint {
  display: none;
  position: fixed; z-index: 30;
  top: calc(66px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  align-items: center; gap: 10px;
  font-weight: 900; font-size: 12.5px;
  color: var(--cream);
  background: rgba(42, 31, 23, 0.92);
  border: 2px solid rgba(232, 213, 168, 0.5);
  border-radius: 999px;
  padding: 7px 8px 7px 16px;
  pointer-events: auto;
  white-space: nowrap;
}
#rotateHint button {
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: rgba(232, 213, 168, 0.25);
  color: var(--cream); font-size: 12px; font-weight: 900;
}
@media (orientation: portrait) and (max-width: 760px) {
  body.touch #rotateHint:not(.dismissed) { display: flex; }
}

/* ---- small screens ---- */
@media (max-width: 900px) {
  .setup-grid { grid-template-columns: 1fr; }
  .help-cols { grid-template-columns: 1fr; }
  #teamPlanks { min-width: 130px; }
  .pt-name { max-width: 100px; }
  #bugCard { transform: scale(0.88); transform-origin: bottom left; } /* .touch-mode #bugCard overrides via higher specificity */
}

@media (max-width: 760px) {
  #hud { font-size: 12px; }
  #hudTop { gap: 7px; }
  #teamPlanks { min-width: 104px; }
  .pt-name { max-width: 80px; font-size: 11px; }
  #turnToken { width: 48px; height: 48px; border-width: 2.5px; }
  #timerText { font-size: 18px; }
  #windBox { min-width: 86px; padding: 4px 7px 6px; }
  #windBar { width: 70px; }
  #banner { font-size: 15px; top: 62px; padding: 7px 14px 5px; white-space: normal; text-align: center; max-width: 88vw; }
  #toasts { top: 118px; }
  #weaponPanel { grid-template-columns: repeat(2, 122px); max-height: 42vh; }
  #bcPortrait { width: 56px; height: 56px; }
  #bcInfo { min-width: 118px; }
  #bcName { font-size: 14px; }
  #turnHint { font-size: 11px; white-space: normal; text-align: center; max-width: 92vw; }
  .sheet { padding: 18px 14px; }
  .sheet-title { font-size: 24px; margin-bottom: 12px; }
  .pick-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
  .over-stats td { font-size: 12px; padding: 6px 4px; }
  .over-stats th { font-size: 9px; padding: 4px; }
}

/* portrait phones: stack card under the planks, dock above the fire cluster */
@media (max-width: 560px) {
  .touch-mode #bugCard {
    left: calc(6px + env(safe-area-inset-left, 0px));
    bottom: auto;
    top: calc(112px + env(safe-area-inset-top, 0px));
    transform: scale(0.72);
    transform-origin: top left;
  }
  .touch-mode #weaponDock {
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: calc(118px + env(safe-area-inset-bottom, 0px));
    transform: scale(0.82);
  }
  .touch-mode #turnHint { bottom: 152px; }
  #weaponPanel { grid-template-columns: repeat(2, 112px); max-height: 38vh; }
}

/* short landscape phones: compact everything */
@media (max-height: 480px) {
  .touch-mode #bugCard { transform: scale(0.7); left: calc(140px + env(safe-area-inset-left, 0px)); }
  .touch-mode #weaponDock { transform: scale(0.8); }
  .tc-btn { width: 52px; height: 52px; font-size: 20px; }
  #tcRight { left: calc(72px + env(safe-area-inset-left, 0px)); }
  #tcJump { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  #tcFlip { left: calc(72px + env(safe-area-inset-left, 0px)); bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  #tcFire { width: 74px; height: 74px; font-size: 15px; }
  #tcAbility { right: calc(96px + env(safe-area-inset-right, 0px)); bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }
  .touch-mode #turnHint { bottom: 140px; }
}

/* menus: never clip tall sheets on small screens */
@media (max-height: 780px), (max-width: 760px) {
  .screen { justify-content: flex-start; }
  .sheet, .sign-post, .title-buttons { margin-top: 10px; }
  .sheet { margin-bottom: 26px; }
  #scrTitle { padding-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
