* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1d2417;
  --panel: #262f1e;
  --panel2: #2f3a25;
  --edge: rgba(255, 255, 255, 0.12);
  --ink: #f0eee6;
  --dim: rgba(240, 238, 230, 0.65);
  --accent: #ffd24d;
  --danger: #ff6b6b;
  --ok: #8de07a;
  --blue: #8fd0ff;
  /* tiling SVG noise: coarse cloudy mottle + fine grain, blended as `overlay`
     so the mid-gray base is invisible and only the variation shows through */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.028' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='360' height='360' fill='%23808080'/%3E%3Crect width='360' height='360' filter='url(%23b)' opacity='0.65'/%3E%3Crect width='360' height='360' filter='url(%23a)' opacity='0.45'/%3E%3C/svg%3E");
}

html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(255, 210, 77, 0.07), transparent),
    var(--bg);
  color: var(--ink);
  overflow-y: auto;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
small { color: var(--dim); }

/* ---- generic surfaces -------------------------------------------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 20px 22px;
}
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 6, 0.8);
}

/* ---- login -------------------------------------------------------------- */
.login-card { width: min(520px, 92vw); text-align: center; }
.login-form { display: contents; }   /* a real form for password managers, without its own box */
.login-card h1 { font-size: 30px; margin-bottom: 6px; }
.tagline { color: var(--dim); margin-bottom: 18px; }
.login-card input {
  display: block; width: 80%; margin: 8px auto;
  font-size: 16px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--edge); background: rgba(255,255,255,0.07);
  color: #fff; outline: none; text-align: center; font-family: inherit;
}
#login-btn {
  margin: 14px auto 0; font-size: 17px; font-weight: 700;
  padding: 11px 24px; border: none; border-radius: 11px;
  background: #c0392b; color: #fff;
}
#login-btn:hover { background: #e74c3c; }
#login-status { min-height: 20px; margin-top: 8px; color: var(--danger); font-size: 13px; }
/* "your old world is gone" reads as an omen to start over, not an error */
#login-status.apocalypse { color: var(--accent); font-size: 14px; line-height: 1.4; }
.howto { margin-top: 18px; text-align: left; font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 5px; }

/* ---- app shell: a full-bleed base/world canvas with the HUD floating over it ----- */
#app { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; z-index: 1; }

/* the top bar docks flush to the top edge (full width), padded down past the phone
   camera/notch via the safe-area inset. profile | resources | bible | settings — each
   its own clickable cell spanning the bar's two rows. --top-inset is the height every
   other top-anchored element (rails, raid HUD, modals, toast) clears the bar by. */
/* --top-inset clears the top bar; --bottom-inset clears the bottom rails + chat strip.
   modals sit between the two so they never cover the bar or the Hero/World/chat buttons. */
:root { --top-inset: calc(56px + env(safe-area-inset-top)); --bottom-inset: calc(72px + env(safe-area-inset-bottom)); }
/* content sheets sit BELOW the nav rails (which must stay clickable), so they pad their
   foot enough that the last row scrolls clear of the rails + chat strip, not behind them */
:root { --sheet-foot: calc(200px + env(safe-area-inset-bottom)); }
#topbar {
  position: fixed; z-index: 30; top: 0; left: 0; right: 0;
  display: flex; align-items: stretch; gap: 8px;
  background: var(--panel); border: none; border-bottom: 1px solid var(--edge);
  border-radius: 0; padding: calc(6px + env(safe-area-inset-top)) 12px 6px; font-size: 15px;
}
/* each top-bar element is its own button cell, two rows tall */
.topcell {
  display: flex; align-items: center; gap: 7px;
  background: none; color: var(--ink); font: inherit;
  border: 1px solid transparent; border-radius: 9px;
  padding: 2px 9px; cursor: pointer;
}
.topcell:hover { border-color: var(--edge); background: rgba(0, 0, 0, 0.18); }
.topcell.active { border-color: var(--accent); background: rgba(255, 210, 77, 0.12); }
.topcell-icon { font-size: 18px; }
#profile-btn .pfx-av { font-size: 24px; line-height: 1; }
#profile-btn .pfx-id { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
#profile-btn .pfx-id b { font-size: 13px; color: var(--ink); max-width: 9ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#profile-btn .pfx-id small { font-size: 11px; color: var(--dim); }

/* the resource cell: 4 resources up top, offense/defense beneath; tap = status */
#resbar { margin: 0 auto; flex-direction: column; gap: 1px; padding: 1px 10px; }
.resrow { display: flex; align-items: center; gap: 13px; }
.resrow.combat { justify-content: center; gap: 18px; }
.res { display: flex; align-items: center; gap: 3px; font-size: 13px; white-space: nowrap; }
.res b { color: var(--accent); font-weight: 700; }
.res.off b { color: #ff9b6b; }
.res.def b { color: var(--blue); }
/* status-modal rows */
.statline { display: flex; align-items: baseline; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-size: 14px; }
.statline > span { min-width: 132px; color: var(--dim); }
.statline > b { color: var(--ink); font-weight: 700; }
.statline > em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--dim); text-align: right; }

/* the queue chips (top-left) + next-raid (top-right) float over the canvas in containers
   that fold away via a chevron; empty space clicks through */
.hudrail > * { pointer-events: auto; }
#leftbar { position: fixed; z-index: 20; left: 8px; top: calc(var(--top-inset) + 4px); bottom: 8px;
  width: auto; max-width: 340px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  overflow-y: auto; overscroll-behavior: contain; pointer-events: none; }
#rightbar { position: fixed; z-index: 25; right: 8px; top: calc(var(--top-inset) + 4px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
/* the fold chevron caps each container; collapsing hides the content but keeps the chevron */
.hud-collapse { background: var(--panel); color: var(--dim); border: 1px solid var(--edge);
  border-radius: 8px; width: 26px; height: 18px; padding: 0; font-size: 12px; line-height: 1; cursor: pointer; }
.hud-collapse:hover { color: var(--ink); border-color: var(--accent); }
/* ID-specific so it beats the #ops / #raid-hud display rules */
#leftbar.hud-min #ops, #rightbar.hud-min #raid-hud { display: none; }
.hudrail.hud-min .hud-collapse { transform: scaleX(-1); }
/* the queue chips: a compact stack of icon + in-use/max count */
#ops { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.qchip { display: flex; align-items: center; gap: 5px; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 10px; padding: 5px 9px; cursor: pointer; color: var(--ink); font-size: 13px; line-height: 1; }
.qchip:hover { border-color: var(--accent); }
.qchip.busy { border-color: rgba(255, 210, 77, 0.55); }
.qchip.locked { opacity: 0.55; }
.qchip .qci { font-size: 16px; }
.qchip .qct { font-weight: 700; color: var(--accent); }
.qchip.locked .qct { color: var(--dim); font-weight: 400; }
/* the next-raid indicator; tap for the rarity breakdown */
#raid-hud { cursor: pointer; display: flex; flex-direction: column; align-items: flex-end; gap: 0;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; padding: 4px 10px; }
#raid-hud:hover, #raid-hud.active { border-color: var(--accent); }
#raid-hud .rhlabel { font-size: 9px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; }
#raid-hud .raidline { font-size: 13px; }
/* ---- bottom side rails + chat strip ----------------------------------------------
   two vertical rails hug the screen edges — Commander anchors the bottom-left, World the
   bottom-right — each collapsing to just its anchor. The chat strip sits between them on
   the same line. flex column with the rail bottom-anchored puts the anchor at the bottom. */
.siderail {
  position: fixed; z-index: 35; bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 7px; align-items: stretch; pointer-events: none;
}
.siderail > * { pointer-events: auto; }
#bar-left { left: 10px; }
#bar-right { right: 10px; }
.srbtn {
  position: relative; width: 62px; padding: 6px 4px 5px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 14px;
  font-size: 20px; line-height: 1; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
.srbtn:hover { border-color: var(--accent); }
.srbtn.active { background: var(--panel2); border-color: rgba(255, 210, 77, 0.6); }
.srbtn .sri { font-size: 20px; }
.srlbl { font-size: 9px; font-weight: 700; color: var(--dim); white-space: nowrap; }
.srbtn.active .srlbl { color: var(--accent); }
/* the anchors stay put when the rail collapses; World is the prominent accent toggle */
.sr-anchor { background: var(--panel2); border-color: rgba(255, 210, 77, 0.5); }
#world-toggle { background: var(--accent); color: #1a1208; border-color: transparent; }
#world-toggle .srlbl { color: #1a1208; }
#world-toggle:hover { filter: brightness(1.08); border-color: transparent; }
/* the collapse chevron caps each rail; collapsing hides every button but the anchor */
.sr-collapse {
  align-self: center; width: 30px; height: 16px; padding: 0; cursor: pointer;
  background: var(--panel); color: var(--dim); border: 1px solid var(--edge);
  border-radius: 8px; font-size: 12px; line-height: 1;
}
.sr-collapse:hover { color: var(--ink); border-color: var(--accent); }
.siderail.collapsed .srbtn:not(.sr-anchor) { display: none; }
.siderail.collapsed .sr-collapse { transform: scaleX(-1); }

/* the chat strip spans the bottom between the rails: latest line, tap opens the log modal */
#chat-strip {
  position: fixed; z-index: 34; bottom: calc(14px + env(safe-area-inset-bottom));
  left: 84px; right: 84px;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 12px;
  padding: 9px 14px; cursor: pointer; color: var(--ink); font-size: 13px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
#chat-strip:hover, #chat-strip.active { border-color: var(--accent); }
#chat-strip .cs-icon { font-size: 16px; flex: none; }
/* text-align:left because the strip is a <button> (which defaults to centered) */
#chat-strip .cs-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); text-align: left; }
#chat-strip .badge { position: static; transform: none; flex: none; }
/* the live march list under the 🎯 count on the world screen */
#march-list { display: flex; flex-direction: column; gap: 5px; max-width: 320px; }
#march-list .march-pill { font-size: 12px; }

.sidecard {
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 12px; padding: 10px 12px;
}
.statrow {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 13px; padding: 3px 0;
}
.statrow span:first-child { color: var(--dim); flex: 1; }
.statrow b { color: var(--accent); }
.statrow small { font-size: 11px; color: var(--dim); min-width: 52px; text-align: right; }
#morale-row { justify-content: center; padding: 5px 0; }

.march-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--edge);
  border-radius: 999px; padding: 4px 12px; font-size: 12px;
}
.march-pill b { color: var(--accent); }
/* mining marches carry a second-line depletion bar */
.march-pill.mining-pill { flex-direction: column; align-items: stretch; gap: 5px; border-radius: 12px; }
.mptop { display: flex; align-items: center; gap: 6px; }
/* override the rail .qbar's row-context flex-basis so it's a thin full-width bar here */
.mining-pill .qbar.mine { flex: none; width: auto; height: 15px; margin: 0; }
.qbar.mine i { background: linear-gradient(180deg, #d6aa54, #a8842f); }
/* recon-ready row in the attack modal */
.recon-ready { background: rgba(120, 200, 120, 0.12); border-radius: 8px; padding: 6px 8px; }
.recon-ready b { color: var(--ok); }
.mcancel {
  margin-left: auto; padding: 0 6px; border-radius: 999px;
  background: none; border: 1px solid var(--edge); color: var(--dim);
  font-size: 11px; line-height: 16px;
}
.mcancel:hover { color: #fff; border-color: var(--danger); background: rgba(255, 107, 107, 0.18); }

/* the next-task flyout rides off the right of the Tasks button (visual only — tap the
   button itself); it folds away when the left rail collapses since it's a child of Tasks */
.hint-flyout {
  position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: rgba(255, 210, 77, 0.14); border: 1px solid rgba(255, 210, 77, 0.4);
  border-radius: 10px; padding: 7px 11px; font-size: 12px; font-weight: 400; color: var(--ink);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35); pointer-events: none;
}
/* the Steward guidance button gets a subtle gold ring to read as a prompt */
#steward-btn { border-color: rgba(255, 210, 77, 0.5); }
/* when he has unread guidance, the button pulses with a ? badge — inviting a tap instead of
   his dialog auto-opening over the world */
#steward-btn.nudge { border-color: var(--accent); animation: stewardpulse 1.3s ease-in-out infinite; }
#steward-btn.nudge::after {
  content: '?'; position: absolute; top: -5px; right: -5px;
  background: var(--accent); color: #1a1205; font-size: 11px; font-weight: 800;
  width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 999px;
  box-shadow: 0 0 0 2px var(--bg);
}
@keyframes stewardpulse {
  0%, 100% { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(255, 210, 77, 0); }
  50% { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), 0 0 13px 3px rgba(255, 210, 77, 0.6); }
}
/* a march's offensive power in the march list */
.mpw { color: #ff9b6b; font-weight: 700; font-size: 12px; }
/* the Barracks modal hosts the army/training panel — set it off from the building's own
   level + upgrade info above it */
.flock-panel { margin-top: 14px; padding-top: 4px; border-top: 1px solid var(--edge); }

/* sub-nav shared by the Commander + Army sheets (Army folds into the Commander section) */
.subnav { display: flex; gap: 5px; margin-bottom: 12px; }
.subtab {
  flex: 1; text-align: center; background: var(--panel); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 10px; padding: 8px 10px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.subtab:hover { border-color: var(--accent); }
.subtab.active { background: var(--panel2); border-color: rgba(255, 210, 77, 0.5); color: var(--accent); }
.badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 999px; min-width: 16px; height: 16px; line-height: 16px; text-align: center;
  padding: 0 3px;
}
/* bible + lore are top-bar icon buttons now */

/* the active view fills the canvas. base/world go edge-to-edge (the HUD floats over
   them); content screens inset so their scroll clears the floating rails + bars */
.panel { position: absolute; inset: 0; overflow: hidden; }
.panel.canvas { background: none; border: none; border-radius: 0; }
/* the base village + world map stretch to fill the full-bleed canvas */
.panel.canvas #map-viewport, .panel.canvas #village-viewport { height: 100%; max-height: none; border-radius: 0; }
.panel.sheet { background: var(--panel2); overflow-y: auto; padding: 72px 16px var(--sheet-foot); }
/* content screens hide the canvas HUD — the bottom nav + toggle drive navigation */
#app.on-sheet #leftbar, #app.on-sheet #rightbar { display: none; }

/* right rail operations */
#ops { display: flex; flex-direction: column; gap: 10px; }
.opscard {
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.opscard h4 { font-size: 12px; color: var(--dim); margin-bottom: 6px; font-weight: 700; }
.opscard .qhint { display: block; font-size: 10px; color: var(--dim); opacity: 0.8; margin-top: 5px; }

/* ---- the village ------------------------------------------------------------- */
.qcard {
  width: 100%; text-align: left;
  background: var(--panel2); border: 1px solid var(--edge); border-radius: 11px;
  color: var(--ink); padding: 8px 11px; margin-bottom: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.qcard:hover { border-color: var(--accent); }
.qcard b { font-size: 12px; }
.qcard small { font-size: 11px; color: var(--dim); }
.qcard.hint { border-style: dashed; opacity: 0.85; }
.qcard.hint:hover { border-color: var(--accent); opacity: 1; }
/* one job per line, progress bar with the countdown readable inside it */
.qline { display: flex; align-items: center; gap: 6px; font-size: 11px; margin-top: 3px; }
.qline .qwait { color: var(--dim); font-style: normal; margin-left: auto; font-size: 10px; }
/* fixed-size bars so every job line reads the same regardless of label length */
.qbar {
  position: relative; flex: 0 0 104px; height: 17px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.45); overflow: hidden; margin-left: auto;
}
.qbar i { display: block; height: 100%; background: var(--accent); opacity: 0.55; }
.qbar.research i { background: var(--blue); }
.qbar.train i { background: var(--ok); }
.qbar em {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-style: normal; font-size: 11px; font-weight: 700; color: var(--ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9); white-space: nowrap;
}
.queue-row .bar { height: 6px; border-radius: 3px; background: rgba(0,0,0,0.45); overflow: hidden; min-width: 60px; }
.queue-row .bar i { display: block; height: 100%; background: var(--accent); }
.ophp { display: block; height: 6px; border-radius: 3px; background: rgba(0,0,0,0.45); overflow: hidden; }
.ophp i { display: block; height: 100%; background: var(--accent); transition: width 0.5s; }
.pips-sm { color: var(--accent); font-size: 9px; letter-spacing: 1px; }
/* rarity colors (raids AND gear): white / green / blue / purple / orange */
.rt0 { color: #f0eee6; }
.rt1 { color: var(--ok); }
.rt2 { color: var(--blue); }
.rt3 { color: #bb6aff; }
.rt4 { color: #ff9b3d; text-shadow: 0 0 8px rgba(255, 155, 61, 0.4); }
/* next-raid card: rarity + countdown share one line; ⓘ opens the raid-types modal */
.opscard.raidcard { text-align: center; }
.opscard.raidcard h4 { display: flex; align-items: center; justify-content: center; gap: 4px; }
.opscard.raidcard .qhint { text-align: center; }
.raidline { display: inline-block; font-size: 15px; font-weight: 700; transform-origin: center; }
/* a one-shot "pop" the rAF tick fires on a rising cadence (once a minute from 5:00, then
   every second under 30s). It scales from the centered card, so it never pushes siblings. */
.raidline.raidpop { animation: raidpop 0.55s ease; }
@keyframes raidpop {
  0% { transform: scale(1); }
  35% { transform: scale(1.22); text-shadow: 0 0 12px currentColor; }
  100% { transform: scale(1); text-shadow: none; }
}
.raidinfo { background: none; border: none; color: var(--dim); cursor: pointer; font-size: 13px; padding: 0 3px; vertical-align: 1px; }
.raidinfo:hover { color: var(--ink); }
.raidtypes { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.raidrow { display: grid; grid-template-columns: 88px 70px 92px 1fr; gap: 8px; align-items: baseline;
  padding: 7px 9px; background: rgba(0, 0, 0, 0.22); border: 1px solid var(--edge); border-radius: 9px; }
.raidrow .raidname { font-weight: 700; }
.raidrow .raidcad, .raidrow .raidmult { font-size: 12px; }
.raidrow .raidnote { font-size: 11px; color: var(--dim); }
@media (max-width: 560px) { .raidrow { grid-template-columns: 1fr auto auto; } .raidrow .raidnote { grid-column: 1 / -1; } }
/* the incoming-raid header at the top of the raid modal */
.raidnext { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--edge); background: rgba(0, 0, 0, 0.25); }
.raidnext .rn-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim); }
.raidnext .rn-tier { font-size: 22px; font-weight: 700; margin: 2px 0 6px; }
.raidnext .rn-note { font-size: 13px; color: var(--ink); }
.raidnext .rn-est { font-size: 12px; color: var(--dim); margin-top: 6px; }
/* the matching tier in the list below is ringed */
.raidrow.incoming { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* ---- the Commander tab ------------------------------------------------------- */
.hero-grid { display: grid; grid-template-columns: 240px 1fr; gap: 14px; align-items: start; }
.hero-card {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 7px;
  text-align: center;
}
.hero-name { font-size: 17px; color: var(--accent); }
/* the paperdoll: a human face peeking out of a chicken suit */
.pdoll { position: relative; width: 96px; height: 96px; }
.pdoll .pd-chicken { font-size: 84px; line-height: 96px; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.45)); }
.pdoll .pd-face {
  position: absolute; left: 50%; top: 24%; transform: translateX(-58%);
  font-size: 22px; line-height: 1;
}
.herobar { flex: none; width: 100%; height: 16px; }
.vigorbar { flex: none; width: 100%; height: 14px; }
.vigorbar i { background: linear-gradient(180deg, #d8a04a, #b97f2e); }
.hero-stats { width: 100%; }
.gear-row { display: flex; gap: 8px; margin-bottom: 8px; }
.gearslot {
  flex: 1; display: flex; flex-direction: column; gap: 5px;
  background: var(--panel2); color: var(--ink); border-radius: 11px; padding: 9px 8px;
  border: 2px solid var(--edge); cursor: pointer; font-size: 12px;
}
.gearslot .gtop { display: flex; align-items: center; gap: 8px; width: 100%; }
.gearslot .gicon { font-size: 27px; }
.gearslot .ginfo { display: flex; flex-direction: column; text-align: left; flex: 1; gap: 1px; }
.gearslot .ginfo b { font-size: 13px; }
.gearslot .ginfo small { font-size: 11px; color: var(--dim); }
.gearslot .qbar.gearbar { flex: none; width: 100%; margin: 0; height: 14px; }
.gcmp { color: var(--accent); }
.gcmp b { color: var(--ok); }
.gearslot.empty { border-style: dashed; opacity: 0.75; }
.gearslot:hover { border-color: var(--accent); }
.gearslot.gr0 { border-color: rgba(240, 238, 230, 0.55); }
.gearslot.gr1 { border-color: rgba(141, 224, 122, 0.7); }
.gearslot.gr2 { border-color: rgba(143, 208, 255, 0.7); }
.gearslot.gr3 { border-color: rgba(187, 106, 255, 0.75); }
.gearslot.gr4 { border-color: rgba(255, 155, 61, 0.85); box-shadow: 0 0 9px rgba(255, 155, 61, 0.3); }
.talent-row small { line-height: 1.35; }

/* ── hero roster: one card per row, all four roles, locked until earned ───────── */
.hero-listhead { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.hero-listhead b { font-size: 17px; color: var(--accent); }
.hero-listhead small { color: var(--dim); font-size: 12px; text-align: right; }
.hero-list { display: flex; flex-direction: column; gap: 10px; }
.hcard {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--edge); border-left: 4px solid var(--edge);
  border-radius: 14px; padding: 11px 14px; color: var(--ink); cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.hcard.recruited:hover { border-color: var(--accent); transform: translateY(-1px); }
.hcard.locked { cursor: default; opacity: 0.6; box-shadow: none; }
/* role accent stripe down the left edge (shared by the card + the detail header) */
.rl-warlord { border-left-color: #ff8d5c; }
.rl-raider { border-left-color: #ffd24d; }
.rl-breaker { border-left-color: #8fd0ff; }
.rl-guardian { border-left-color: #8de07a; }
.hc-port {
  position: relative; flex: none; width: 58px; height: 58px; border-radius: 12px;
  background: var(--panel2); border: 1px solid var(--edge);
  display: flex; align-items: center; justify-content: center;
}
.hc-port .pd-chicken { font-size: 46px; line-height: 1; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4)); }
.hc-port .pd-face { position: absolute; left: 50%; top: 22%; transform: translateX(-58%); font-size: 15px; }
.hc-port .hc-lock { font-size: 24px; }
.hc-role { position: absolute; right: -6px; bottom: -6px; font-size: 18px; background: var(--panel); border-radius: 999px; padding: 1px 2px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5); }
.hc-mid { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hc-name { font-size: 15px; }
.hcard.recruited .hc-name { color: var(--accent); }
.hc-sub { color: var(--dim); font-size: 11px; line-height: 1.3; }
.hc-stars { color: var(--accent); font-size: 13px; letter-spacing: 1px; }
.hc-nostar { color: var(--dim); font-size: 11px; }
.hc-right { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; }
.hc-lvl { font-size: 15px; }
.hc-pw { color: #ff9b6b; font-weight: 700; font-size: 12px; }
.hc-loc { color: var(--dim); font-size: 11px; }
.hc-unlock { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.hc-unlockg { color: var(--blue); font-size: 13px; }
.hc-go { flex: none; color: var(--dim); font-size: 22px; }

/* ── hero detail: a Golden-Wings-style header + sub-tabbed sheet ──────────────── */
.hero-detail { display: flex; flex-direction: column; gap: 12px; }
.hero-detailhead {
  position: relative; display: flex; align-items: center; gap: 16px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--edge); border-left: 4px solid var(--edge);
  border-radius: 16px; padding: 18px 16px;
}
.hero-detailhead::before {
  content: ''; position: absolute; left: -40px; top: -40px; width: 180px; height: 180px;
  border-radius: 50%; opacity: 0.18; background: var(--accent); filter: blur(20px);
}
.rl-warlord.hero-detailhead::before { background: #ff8d5c; }
.rl-raider.hero-detailhead::before { background: #ffd24d; }
.rl-breaker.hero-detailhead::before { background: #8fd0ff; }
.rl-guardian.hero-detailhead::before { background: #8de07a; }
.hero-back {
  position: absolute; top: 10px; left: 12px; z-index: 2;
  background: rgba(0, 0, 0, 0.35); color: var(--ink); border: 1px solid var(--edge);
  border-radius: 9px; padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.hero-back:hover { border-color: var(--accent); color: var(--accent); }
.hd-portrait {
  position: relative; flex: none; width: 104px; height: 104px; margin-top: 14px; z-index: 1;
  border-radius: 16px; background: var(--panel2); border: 1px solid var(--edge);
  display: flex; align-items: center; justify-content: center;
}
.hd-portrait .pd-chicken { font-size: 88px; line-height: 1; filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.45)); }
.hd-portrait .pd-face { position: absolute; left: 50%; top: 22%; transform: translateX(-58%); font-size: 23px; }
.hd-role { position: absolute; right: -8px; bottom: -8px; font-size: 26px; background: var(--panel); border-radius: 999px; padding: 2px 3px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.hd-id { flex: 1; display: flex; flex-direction: column; gap: 3px; z-index: 1; min-width: 0; }
.hd-name { font-size: 19px; color: var(--accent); }
.hd-title { color: var(--dim); font-size: 12px; }
.hd-stars { color: var(--accent); font-size: 15px; letter-spacing: 1px; }
.hd-stars small { color: var(--dim); letter-spacing: normal; }
.hd-pw { font-size: 14px; margin-top: 2px; }
.hd-pw b { color: #ff9b6b; font-size: 17px; }
.hd-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.hd-stats > div {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 11px;
  padding: 9px 4px; text-align: center; display: flex; flex-direction: column; gap: 3px;
}
.hd-stats small { color: var(--dim); font-size: 11px; }
.hd-stats b { font-size: 16px; }
.hero-subnav { margin: 4px 0 0; }
.hero-subpanel { display: flex; flex-direction: column; gap: 6px; }
.hd-roledesc { font-style: italic; font-size: 13px; margin: 2px 0; }
.hd-capstone { font-size: 13px; color: var(--dim); margin: 2px 0; }
.hd-capstone.active { color: var(--accent); font-weight: 700; }
.cmdrow {
  display: flex; align-items: center; gap: 8px; margin: 8px 0;
  font-size: 13px; cursor: pointer;
}
.cmdrow small { color: var(--dim); }
@media (max-width: 900px) { .hero-grid { grid-template-columns: 1fr; } }
/* the four gear slots (weapon/armor/charm/bag) stack 2x2 on phones — four in a row
   overflows a narrow panel and shoves the layout sideways */
@media (max-width: 560px) { .gear-row { display: grid; grid-template-columns: 1fr 1fr; } }

#vtools {
  display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px;
}
.vguestchip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; cursor: help;
  background: rgba(80, 160, 90, 0.18); border: 1px solid rgba(80, 160, 90, 0.5);
}
/* the base is its own scrollable coordinate grid (mirrors the overworld map) */
#village-viewport {
  overflow: auto; height: 100%; border-radius: 12px;
  cursor: grab; scrollbar-width: thin; background: #2c3a22;
  display: flex;   /* centre the base when the grid is narrower than the viewport */
  /* JS owns pan + pinch-zoom on the base, so a touch never scrolls the page, fires the
     browser's pinch-zoom, or selects text — the base is full of buildings to drag across */
  touch-action: none; -webkit-user-select: none; user-select: none;
}
#village-viewport.panning { cursor: grabbing; }
#village-grid {
  display: grid; gap: 0; width: fit-content; position: relative;
  /* scroll-safe centring: auto margins centre the grid while it fits and collapse to
     0 once it overflows, so panning still reaches every edge when zoomed in */
  margin: auto;
  padding: 8px; border-radius: 12px;
  background:
    repeating-linear-gradient(104deg, rgba(222, 240, 175, 0.04) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(76deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 6px),
    radial-gradient(140% 120% at 50% 45%, #5a7a42 0%, #4a6336 55%, #3a4c2c 100%);
}
#village-grid::after {   /* one grain wash over the whole yard */
  content: ''; position: absolute; inset: 8px; z-index: 1; pointer-events: none;
  border-radius: 5px; background: var(--grain); mix-blend-mode: overlay; opacity: 0.4;
}
/* cosmetic fog ringing the walls + terrain scenery scattered through it */
.vfogband {
  position: absolute; z-index: 3; pointer-events: none;
  background: rgba(8, 11, 6, 0.6); box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.5);
}
.vfogdec {
  position: absolute; transform: translate(-50%, -50%); z-index: 1; pointer-events: none;
  opacity: 0.5; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}
/* the perimeter wall ringing the buildable interior — straw → brick L5 → stone L10.
   The frame is just a positioner with NO pointer events; only the four edge strips below
   are clickable, leaving the interior free for panning + building. */
.vwallframe { position: absolute; z-index: 4; pointer-events: none; --wallw: max(6px, calc(var(--tile) * 0.32)); }
.vwall-edge { position: absolute; pointer-events: auto; cursor: pointer; }
.vwall-edge.top { top: 0; left: 0; right: 0; height: var(--wallw); }
.vwall-edge.bottom { bottom: 0; left: 0; right: 0; height: var(--wallw); }
.vwall-edge.left { top: 0; bottom: 0; left: 0; width: var(--wallw); }
.vwall-edge.right { top: 0; bottom: 0; right: 0; width: var(--wallw); }
.vwall-edge:hover { filter: brightness(1.3); }
.vwallframe.w0 .vwall-edge { background: repeating-linear-gradient(90deg, rgba(210, 200, 170, 0.45) 0 8px, transparent 8px 16px), repeating-linear-gradient(0deg, rgba(210, 200, 170, 0.45) 0 8px, transparent 8px 16px); }
.vwallframe.w1 .vwall-edge { background: #b89a4a; }
.vwallframe.w2 .vwall-edge { background: #9c5a40; }
.vwallframe.w3 .vwall-edge { background: #8a8780; box-shadow: 0 0 8px rgba(255, 210, 77, 0.4); }
/* the level/era badge under each building */
.vlvlbadge {
  position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%); z-index: 3;
  font-size: 9px; font-weight: 800; line-height: 1.4; white-space: nowrap; pointer-events: none;
  background: rgba(10, 14, 8, 0.78); border-radius: 999px; padding: 0 5px; color: rgba(240, 238, 230, 0.95);
}
.vlvlbadge::before { content: '●'; font-size: 7px; margin-right: 3px; vertical-align: 1px; }
.vlvlbadge.cat-resource::before { color: #9bd97c; }
.vlvlbadge.cat-combat::before { color: #ff9a8a; }
.vlvlbadge.cat-utility::before { color: #8fd0ff; }
.vlvlbadge.cat-core::before { color: var(--accent); }

#map-viewport {
  overflow: auto; max-height: 72vh; border-radius: 12px;
  cursor: grab; scrollbar-width: thin;
  /* we own pan + pinch via pointer events; without this the browser hijacks touch and
     pinch-zooms the whole page instead of the map */
  touch-action: none; -webkit-user-select: none; user-select: none;
}
#map-viewport.panning { cursor: grabbing; user-select: none; }
/* a building/decoration is a grid item filling its footprint cells; emoji centered */
.vplot {
  position: relative; z-index: 4; display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; color: var(--ink); padding: 0; touch-action: none;
  /* fill the exact grid footprint. A <button> sizes to its intrinsic width (~64px) instead of
     stretching to the track, so on a zoomed-in (small --tile) mobile grid the centered emoji
     drifted right of its cell; min-width:0 lets it shrink to the cell, width/height pin it there */
  width: 100%; height: 100%; min-width: 0; min-height: 0;
}
.vplot .vemoji {
  font-size: calc(var(--tile) * 0.82); line-height: 1;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5));
  transition: transform 0.12s;
}
.vplot:hover { z-index: 7; }
.vplot:hover .vemoji { transform: scale(1.12); }
.vplot.egg .vemoji { font-size: calc(var(--tile) * 1.95); animation: eggbreathe 4.5s ease-in-out infinite; }
.vplot.egg::before {
  content: ''; position: absolute; inset: -12%;
  background: radial-gradient(closest-side, rgba(255, 232, 150, 0.42), rgba(255, 232, 150, 0.12) 55%, transparent 75%);
  pointer-events: none; animation: eggglow 4.5s ease-in-out infinite;
}
@keyframes eggbreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes eggglow { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; } }
.vplot .upready { position: absolute; top: -2px; right: -2px; z-index: 5; font-size: 13px; pointer-events: none; }
/* movable cosmetic decorations */
.vplot.vdecplot .vemoji { font-size: calc(var(--tile) * 0.8); }
.dec-pond .vemoji { filter: drop-shadow(0 0 9px rgba(95, 165, 255, 0.65)); }
.dec-fire .vemoji { animation: decfire 0.5s ease-in-out infinite alternate; transform-origin: bottom center; }
@keyframes decfire {
  from { transform: scale(1) rotate(-3deg); filter: drop-shadow(0 0 6px rgba(255, 140, 40, 0.7)); }
  to { transform: scale(1.12) rotate(3deg); filter: drop-shadow(0 0 12px rgba(255, 175, 60, 0.95)); }
}
.dec-garden .vemoji { animation: decsway 3.6s ease-in-out infinite; transform-origin: bottom center; }
@keyframes decsway { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
.vplot.stage-silver .vemoji { filter: drop-shadow(0 6px 5px rgba(0,0,0,0.45)) drop-shadow(0 0 7px rgba(190, 200, 215, 0.8)); }
.vplot.stage-gold .vemoji { filter: drop-shadow(0 6px 5px rgba(0,0,0,0.45)) drop-shadow(0 0 9px rgba(255, 210, 77, 0.9)); }
/* rail-style village bars overlay the top of the footprint: timer readable inside,
   color-coded per queue (gold construction, blue research, green hatching) */
.vplot .vbar2 {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%); z-index: 5;
  width: calc(var(--tile) * 1.7); min-width: 22px; max-width: 80px; height: 11px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.66); overflow: hidden;
}
/* a building that's upgrading *and* working stacks its two bars in a column at the same anchor,
   so the build + research/train/forge timers sit below each other instead of overlapping */
.vplot .vbars {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.vplot .vbars .vbar2 { position: relative; top: auto; left: auto; transform: none; }
.vplot .vbar2 i { display: block; height: 100%; background: var(--accent); opacity: 0.6; }
.vplot .vbar2.research i { background: var(--blue); }
.vplot .vbar2.train i { background: var(--ok); }
.vplot .vbar2.forge i { background: linear-gradient(180deg, #b8bcc4, #878d96); opacity: 0.85; }
.vplot .vbar2 em {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-style: normal; font-size: 9px; font-weight: 700; color: var(--ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

/* the south gate + corner turrets, positioned in grid pixels by the renderer */
.vgate {
  position: absolute; transform: translate(-50%, -50%); z-index: 5;
  font-size: calc(var(--tile) * 0.95); line-height: 1; cursor: pointer;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}
.vgate:hover { transform: translate(-50%, -50%) scale(1.15); }
.vturret {
  position: absolute; transform: translate(-50%, -50%); z-index: 6;
  background: none; border: none; cursor: pointer; color: var(--ink);
  font-size: calc(var(--tile) * 0.72); line-height: 1; padding: 0;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5));
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.vturret:hover { transform: translate(-50%, -50%) scale(1.15); }
.vturret.empty { opacity: 0.5; }
.vturret .vtlvl {
  font-size: 8px; font-weight: 700; border-radius: 999px; padding: 0 5px;
  background: rgba(10, 14, 8, 0.7); color: rgba(240, 238, 230, 0.9);
}
.vturret .vtbusy { position: absolute; top: -7px; right: -7px; font-size: 11px; animation: vbuild-swing 0.9s ease-in-out infinite; }
/* a wall or turret under construction pulses on the base so you can see it building without
   opening the construction queue */
.vwallbusy {
  position: absolute; top: -6px; left: 50%; z-index: 6; pointer-events: none;
  font-size: calc(var(--tile) * 0.5); filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
  animation: vwallbusy-swing 0.9s ease-in-out infinite;
}
.vwallframe.building .vwall-edge { animation: vwall-glow 1.1s ease-in-out infinite; }
@keyframes vbuild-swing { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(14deg); } }
@keyframes vwallbusy-swing { 0%, 100% { transform: translateX(-50%) rotate(-12deg); } 50% { transform: translateX(-50%) rotate(14deg); } }
@keyframes vwall-glow {
  0%, 100% { box-shadow: none; filter: brightness(1); }
  50% { box-shadow: 0 0 8px 2px rgba(255, 210, 77, 0.7); filter: brightness(1.4); }
}
/* turret eras match the wall: straw, brick, stone — the badge wears the era's colors */
.vturret.vt2 .vtlvl { background: rgba(110, 56, 34, 0.85); }
.vturret.vt3 .vtlvl { background: rgba(70, 68, 62, 0.9); color: #ffd24d; }
.vturret.vt3 { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 5px rgba(255, 210, 77, 0.4)); }

/* egg prereq chips in the upgrade modal */
.req-met { color: var(--ok); }
.req-unmet { color: var(--danger); }

/* the Steward guidance emoji, used in his menu modal */
.tut-e { font-size: 16px; margin-right: 2px; }

/* ---- move mode: gridlines, footprint highlight, lifted building, ✓/✗ actions ---- */
#village-grid.moving-on { touch-action: none; }   /* drag repositions instead of scrolling */
#move-gridlines {
  position: absolute; inset: 8px; z-index: 2; pointer-events: none;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 calc(var(--tile) - 1px), rgba(255, 255, 255, 0.16) calc(var(--tile) - 1px) var(--tile)),
    repeating-linear-gradient(0deg, transparent 0 calc(var(--tile) - 1px), rgba(255, 255, 255, 0.16) calc(var(--tile) - 1px) var(--tile));
}
#move-hi {
  /* a grid item (placed by grid-column/row in setMovePos), not absolutely positioned, so it
     lands in exactly the building's cell on every device */
  z-index: 3; pointer-events: none; border-radius: 3px; box-shadow: inset 0 0 0 2px currentColor;
}
#move-hi.ok { color: #5fe07a; background: rgba(95, 224, 122, 0.22); }
#move-hi.bad { color: #ff6b6b; background: rgba(255, 107, 107, 0.22); }
.vplot.moving { z-index: 10; opacity: 0.92; pointer-events: none; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5)); }
.vplot.moving .vemoji { transform: scale(1.14); }
#move-actions {
  /* left/top are set in setMovePos so the controls follow the ghost (translateX centres on it) */
  position: fixed; z-index: 40; transform: translateX(-50%);
  display: flex; gap: 20px; pointer-events: auto;
}
.move-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.85);
  font-size: 25px; line-height: 1; cursor: pointer; color: #fff; padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center;
}
.move-btn.ok { background: #4caf50; }
.move-btn.bad { background: #e5544b; }
.move-btn.del { background: #6b7280; }
.move-btn[disabled] { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }
.move-btn:not([disabled]):hover { filter: brightness(1.1); }
#ops .mslot { display: block; text-align: center; margin: 4px 0; }

/* ---- map ----------------------------------------------------------------------- */
#map-grid {
  display: grid; gap: 0; width: fit-content; margin: 0 auto;
  background: rgba(0,0,0,0.25); padding: 8px; border-radius: 12px;
}
/* one continuous grain wash over the whole board — it crosses tile seams, so
   the eye reads terrain, not a grid of swatches; sits under marches (z 2) */
#map-grid::after {
  content: ''; position: absolute; inset: 8px; z-index: 1;
  pointer-events: none; border-radius: 5px;
  background: var(--grain);
  mix-blend-mode: overlay; opacity: 0.55;
}
.tile {
  width: var(--tile, 42px); height: var(--tile, 42px);
  border: none; border-radius: 0;
  background-color: #2a331f; font-size: calc(var(--tile, 42px) * 0.48); line-height: 1;
  display: flex; align-items: center; justify-content: center; position: relative;
  color: var(--ink);
}
/* terrain dressing: recessed water, raised mountains, parched flats, bare dirt */
.tile.tr-grass, .tile.home {
  background-image:
    repeating-linear-gradient(104deg, rgba(222, 240, 175, 0.05) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(76deg, rgba(0, 0, 0, 0.07) 0 1px, transparent 1px 5px);
}
/* survivor name tag under each discovered base — truncated, never blocks tile clicks */
.tile.home .home-name {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 1px; max-width: calc(var(--tile, 42px) * 1.9);
  padding: 0 3px; font-size: calc(var(--tile, 42px) * 0.22); line-height: 1.4;
  font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: rgba(0, 0, 0, 0.62); color: #fff; border-radius: 4px;
  pointer-events: none; z-index: 6;
}
/* shade deltas stay subtle — the #map-grid grain wash carries the organic
   variation; strong per-tile shades read as a checkerboard with gap 0 */
.tile.tr-grass.g1 { background-color: #2c3521; }
.tile.tr-grass.g2 { background-color: #28311d; }
.tile.tr-water {
  background: linear-gradient(180deg, #2d4f6b, #243f58);
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.55), inset 0 -1px 2px rgba(160, 210, 255, 0.12);
}
.tile.tr-water.g1 { background: linear-gradient(180deg, #2a4a66, #223b53); }
.tile.tr-mount {
  background: linear-gradient(180deg, #50544a, #43463c);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.09), 0 2px 4px rgba(0, 0, 0, 0.35);
}
.tile.tr-desert {
  background-color: #5d5538;
  background-image: repeating-linear-gradient(45deg, rgba(255, 235, 180, 0.04) 0 2px, transparent 2px 6px);
}
.tile.tr-desert.g1 { background-color: #635a3c; }
.tile.tr-dirt { background-color: #4b4129; }
.tdecor {
  font-size: calc(var(--tile, 42px) * 0.36); opacity: 0.7; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55));
}
.tile.tr-mount .tdecor { font-size: calc(var(--tile, 42px) * 0.55); opacity: 0.9; }
/* scenery toggle (🌳 in map tools) — peaks stay: they're terrain, not dressing */
#map-grid.decor-off .tile:not(.tr-mount) .tdecor { display: none; }
#map-tools {
  display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px;
}
.mslot {
  border: 1px dashed var(--edge); border-radius: 999px;
  padding: 3px 12px; font-size: 12px; color: var(--dim);
}
.mslot.busy { border-style: solid; color: var(--ink); background: var(--panel2); }
.tile:hover { outline: 1px solid var(--accent); outline-offset: -1px; z-index: 2; }
/* grid coordinates surface in the tile's upper-right on hover */
.tile:hover::after {
  content: "(" attr(data-x) "," attr(data-y) ")";
  position: absolute; top: 0; right: 0; z-index: 6;
  font-size: 9px; line-height: 1; font-weight: 700; letter-spacing: -0.3px;
  padding: 1px 2px; border-bottom-left-radius: 3px;
  background: rgba(12, 16, 9, 0.82); color: #e9f2d8;
  pointer-events: none;
}
.tile.fog { background: #181d12; }
.tile.fog:hover { outline-color: rgba(255, 255, 255, 0.35); }
.tile.fogedge { filter: brightness(0.75) saturate(0.7); }
.tile.mine { outline: 2px solid var(--ok); outline-offset: -2px; }
.tile.home { background-color: #33402a; }
.tile.throne { background: #4a3015; font-size: calc(var(--tile, 42px) * 0.62); }
.tile.pack { font-size: calc(var(--tile, 42px) * 0.34); opacity: 0.92; }
.tile.pack .lvlb { color: #cfe3b8; }
/* rarity frames (match the gear/raid ladder): Common = white, Uncommon = green,
   Rare = blue, Epic = purple, Legendary = orange. Inset rings keep terrain seamless. */
.tile.pack { box-shadow: inset 0 0 0 1px rgba(236, 240, 244, 0.5); }
.tile.uncommonnest { box-shadow: inset 0 0 0 1px rgba(110, 210, 120, 0.8), inset 0 0 6px rgba(110, 210, 120, 0.3); }
.tile.elite { box-shadow: inset 0 0 0 1px rgba(95, 165, 255, 0.75), inset 0 0 6px rgba(95, 165, 255, 0.3); }
.tile.epicnest { box-shadow: inset 0 0 0 2px rgba(187, 106, 255, 0.85), inset 0 0 7px rgba(187, 106, 255, 0.4); }
.tile.throne { box-shadow: inset 0 0 0 2px rgba(255, 155, 61, 0.9), inset 0 0 9px rgba(255, 155, 61, 0.45); }
.tile.outpost {
  background-color: #3d3a26;
  box-shadow: inset 0 0 0 1px rgba(255, 210, 77, 0.55), inset 0 0 6px rgba(255, 210, 77, 0.2);
}
/* the endgame Goblin King settlement seat — a ruined court, deep crimson ring */
.tile.settlement { background: #3a1024; font-size: calc(var(--tile, 42px) * 0.6);
  box-shadow: inset 0 0 0 2px rgba(255, 92, 138, 0.95), inset 0 0 11px rgba(255, 92, 138, 0.5); }
/* corruption: produce nests rotted magenta that creep outward from the seat */
.tile.corrupt { background-color: #2e0e2a;
  box-shadow: inset 0 0 0 2px rgba(214, 74, 196, 0.9), inset 0 0 8px rgba(214, 74, 196, 0.5); }
/* a boss guard minion — a small crown pip marks it as part of the court */
.tile.guard::after { content: '👑'; position: absolute; top: -2px; left: 1px;
  font-size: 0.4em; line-height: 1; opacity: 0.85; pointer-events: none; }
/* a shielded boss (guards still ring it) dims and flies a shield */
.tile.shielded { filter: saturate(0.7) brightness(0.82); }
.tile .shieldmark { position: absolute; bottom: -1px; right: 1px; font-size: 0.42em;
  line-height: 1; filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8)); pointer-events: none; }
/* settlements grow on the map: 🏕️ camp (L1-4, white border), 🏡 hamlet (L5-9, green
   uncommon ring), 🏯 citadel (L10, blue rare ring) */
.tile.home { box-shadow: inset 0 0 0 2px rgba(236, 240, 244, 0.5); }
.tile.home.s-unc { box-shadow: inset 0 0 0 2px rgba(110, 210, 120, 0.9), inset 0 0 10px rgba(110, 210, 120, 0.42); }
.tile.home.s-rare { box-shadow: inset 0 0 0 2px rgba(95, 165, 255, 0.92), inset 0 0 11px rgba(95, 165, 255, 0.46); }
/* bases (settlements / throne / seat / outpost) span a 3x3 grid area — let the element
   stretch to fill all nine cells (the base .tile width/height pins it to one), then
   center the icon at a size that fills the block */
.tile.base-center { width: auto; height: auto; font-size: calc(var(--tile, 42px) * 1.7); z-index: 1; }
.tile.base-center .lvlb { font-size: 12px; }
/* relocation: a live 3x3 footprint preview (green = clear, red = blocked) on hover */
#map-grid.placing .tile { cursor: crosshair; }
.tile.foot-ok { box-shadow: inset 0 0 0 2px rgba(120, 225, 140, 0.95) !important; background-color: rgba(80, 200, 110, 0.28) !important; }
.tile.foot-bad { box-shadow: inset 0 0 0 2px rgba(240, 110, 110, 0.95) !important; background-color: rgba(220, 80, 80, 0.25) !important; }
/* mining veins: amber ring; green when your miners are on it, dim when taken */
/* mining veins carry no rarity ring (they're not enemies) — the ⛏️ + a soft amber glow
   read them as resources; your own dig gets a faint green wash, taken ones dim */
.tile.mine-node { font-size: calc(var(--tile, 42px) * 0.34); }
.tile.mine-node .lvlb { color: #f0d8a0; }
.tile.mine-node.mining { background-color: rgba(120, 210, 120, 0.18); }
.tile.mine-node.taken { opacity: 0.6; }
/* a rocking hammer marks a vein that's actively being worked */
.tile.mine-node .minehammer {
  position: absolute; top: -2px; right: 1px; font-size: 0.5em; line-height: 1;
  transform-origin: 70% 90%; animation: minerock 0.55s ease-in-out infinite;
}
@keyframes minerock { 0%, 100% { transform: rotate(-22deg); } 50% { transform: rotate(28deg); } }
/* a target with flocks inbound flashes red, alternating with its tier color */
.tile.underatk { animation-duration: 1.1s; animation-timing-function: steps(1); animation-iteration-count: infinite; }
.tile.ua-norm { animation-name: flashnorm; }
.tile.ua-unc { animation-name: flashunc; }
.tile.ua-elite { animation-name: flashelite; }
.tile.ua-epic { animation-name: flashepic; }
.tile.ua-champ { animation-name: flashchamp; }
@keyframes flashnorm {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.95); }
  50% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.15); }
}
@keyframes flashunc {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.95); }
  50% { box-shadow: inset 0 0 0 2px rgba(110, 210, 120, 0.95), inset 0 0 6px rgba(110, 210, 120, 0.3); }
}
@keyframes flashelite {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.95); }
  50% { box-shadow: inset 0 0 0 2px rgba(95, 165, 255, 0.95), inset 0 0 6px rgba(95, 165, 255, 0.3); }
}
@keyframes flashepic {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.95); }
  50% { box-shadow: inset 0 0 0 2px rgba(187, 106, 255, 0.95), inset 0 0 8px rgba(187, 106, 255, 0.4); }
}
@keyframes flashchamp {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 70, 70, 0.95); }
  50% { box-shadow: inset 0 0 0 2px rgba(255, 155, 61, 0.95), inset 0 0 9px rgba(255, 155, 61, 0.45); }
}
.tile .lvlb {
  position: absolute; bottom: -1px; right: 1px; font-size: 9px; font-weight: 700;
  color: var(--accent); text-shadow: 0 1px 2px #000;
}
.tile .dot {
  position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 4px var(--ok);
}
.maplegend { text-align: center; margin-top: 10px; font-size: 12px; color: var(--dim); }

/* ---- march overlay ---------------------------------------------------------- */
#map-grid { position: relative; }
#march-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#march-overlay .mlines, #march-overlay .mlines svg { position: absolute; inset: 0; }
.march-marker {
  position: absolute; top: 0; left: 0; font-size: 15px; line-height: 1;
  transition: transform 1s linear; pointer-events: auto; z-index: 3;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}
.march-marker.foreign { opacity: 0.55; }
.atkmark {
  position: absolute; top: -5px; left: -5px; font-size: 12px;
  animation: atkpulse 1s ease-in-out infinite;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}
@keyframes atkpulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.4); opacity: 1; }
}

/* ---- army ------------------------------------------------------------------------- */
.unit-row, .queue-row, .garrison-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 11px; padding: 10px 14px; margin-bottom: 8px;
}
.unit-row .uicon { font-size: 26px; }
.unit-row .uinfo { flex: 1; }
.unit-row .uinfo b { display: block; font-size: 14px; }
.unit-row .uinfo small { font-size: 12px; }
.ucount { font-size: 18px; font-weight: 700; color: var(--accent); min-width: 44px; text-align: center; }
.trainbtns { display: flex; gap: 5px; }

/* ── barracks (Hen House) training: stat panel + the troop-tier ladder ─────────── */
.barr-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 4px; }
.barr-stats > div {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 11px;
  padding: 9px 4px; text-align: center; display: flex; flex-direction: column; gap: 3px;
}
.barr-stats small { color: var(--dim); font-size: 11px; }
.barr-stats b { font-size: 15px; }
/* the LW-style train picker: selected-unit stats flow to fit, class tabs, a tier rail,
   and a count slider — the rail borrows the Search ladder's chip language */
.train-stats { grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); }
.train-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 2px; }
.tier-rail { display: flex; gap: 7px; overflow-x: auto; padding: 6px 2px 8px; -webkit-overflow-scrolling: touch; }
.tier-card {
  flex: 0 0 84px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--panel); border: 2px solid var(--edge); border-radius: 12px; padding: 8px 4px;
  color: var(--ink); cursor: pointer; font: inherit;
}
.tier-card b { font-size: 12px; }
.tier-card small { font-size: 10px; color: var(--dim); white-space: nowrap; max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.tier-card .tc-emoji { font-size: 22px; line-height: 1.15; }
.tier-card.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.tier-card.locked { opacity: .55; filter: grayscale(.6); }
.train-slide { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; }
.train-slide input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 26px; }
.tr-n { min-width: 46px; text-align: right; font-size: 18px; }
/* the Encampment's Drill Ground: a full-width count bar + tier cards for the garrison */
.camp-count { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 2px 4px; font-size: 14px; }
.camp-count b { font-size: 16px; }
.camp-bar { height: 12px; border-radius: 6px; background: rgba(0, 0, 0, .45); overflow: hidden; border: 1px solid var(--edge); }
.camp-bar i { display: block; height: 100%; background: var(--accent); transition: width .45s ease; }
.camp-n { font-size: 12px !important; font-weight: 800; color: var(--ink) !important; }
.tier-card .btn.small { padding: 2px 8px; min-height: 24px; margin-top: 2px; }
/* the tier ladder scrolls sideways so the higher, still-locked tiers stay in view */
.tier-ladder { display: flex; gap: 9px; overflow-x: auto; padding: 2px 2px 8px; -webkit-overflow-scrolling: touch; }
.tier-chip {
  flex: 0 0 92px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 12px; padding: 11px 6px;
  text-align: center;
}
.tier-chip .tc-icon { font-size: 30px; line-height: 1; }
.tier-chip .tc-lvl { font-size: 13px; }
.tier-chip .tc-mult { color: var(--dim); font-size: 11px; }
.tier-chip .tc-tag { font-size: 10px; font-weight: 700; }
.tier-chip.tier-cur { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 210, 77, 0.3); }
.tier-chip.tier-cur .tc-lvl, .tier-chip.tier-cur .tc-tag { color: var(--accent); }
.tier-chip.tier-have { opacity: 0.85; }
.tier-chip.tier-have .tc-tag { color: var(--ok); }
.tier-chip.tier-next { border-color: var(--blue); }
.tier-chip.tier-next .tc-tag { color: var(--blue); }
.tier-chip.tier-locked { opacity: 0.5; }
.tier-chip.tier-locked .tc-icon { filter: grayscale(0.8); }
.section-h { margin: 14px 0 8px; font-size: 14px; color: var(--dim); font-weight: 700; }
/* tabbed modal (Settings / Devs, and reused by the Game Bible) */
.settabs { display: flex; gap: 6px; margin: 4px 0 12px; flex-wrap: wrap; border-bottom: 1px solid var(--edge); padding-bottom: 8px; }
.settab {
  background: none; border: 1px solid var(--edge); color: var(--dim); cursor: pointer;
  border-radius: 999px; padding: 5px 13px; font-size: 13px; font-weight: 600;
}
.settab:hover { color: var(--ink); }
.settab.active { background: var(--accent); border-color: var(--accent); color: #1a1206; }
/* the Game Bible: a single-line underline tab strip (scrolls sideways if it can't fit) */
#bible-tabs { flex-wrap: nowrap; gap: 0; padding-bottom: 0; overflow-x: auto; scrollbar-width: none; }
#bible-tabs::-webkit-scrollbar { display: none; }
#bible-tabs .settab {
  flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap;
  background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 8px 4px; font-size: 13px;
}
#bible-tabs .settab:hover { color: var(--ink); }
#bible-tabs .settab.active { background: none; color: var(--accent); border-bottom-color: var(--accent); }
#bible-tabs .settab + .settab { border-left: 1px solid var(--edge); }   /* divider so adjacent tabs don't bleed */
.bible-body { max-height: 62vh; overflow-y: auto; padding-right: 6px; }
/* each Bible entry is a collapsible panel: a clickable title row + a hidden detail body */
.bible-entry { border: 1px solid var(--edge); border-radius: 10px; margin: 0 0 8px; overflow: hidden; background: rgba(0, 0, 0, 0.15); }
.bible-head { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: none; border: none; color: var(--ink); cursor: pointer; text-align: left; font: inherit; }
.bible-head:hover { background: rgba(255, 255, 255, 0.04); }
.bible-name { flex: 1; font-size: 14px; }
.bible-chev { color: var(--dim); font-size: 12px; transition: transform 0.15s; }
.bible-entry:not(.collapsed) .bible-chev { transform: rotate(90deg); }
.bible-detail { padding: 0 12px 11px; }
.bible-entry.collapsed .bible-detail { display: none; }
.bible-stages { font-size: 22px; line-height: 1.2; margin: 4px 0 8px; }
.bible-arrow { color: var(--dim); font-size: 14px; margin: 0 5px; vertical-align: 3px; }
.bible-toolbar { display: flex; justify-content: flex-end; margin: 2px 0 10px; }
.bible-note { font-size: 12px; color: var(--dim); margin: 6px 0; line-height: 1.5; }
.bible-note.small { font-size: 11px; }
.bible-note b:not([class]) { color: var(--ink); }   /* classed bolds (rt0–rt4 rarities) keep their own color */
.bible-tbl { width: 100%; border-collapse: collapse; font-size: 11px; margin: 4px 0 2px; }
.bible-tbl th { text-align: left; color: var(--dim); font-weight: 600; padding: 3px 6px; border-bottom: 1px solid var(--edge); }
.bible-tbl td { padding: 3px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.catpill { font-size: 10px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--edge); white-space: nowrap; }
.catpill.cat-resource { color: #9bd97c; border-color: rgba(155, 217, 124, 0.5); }
.catpill.cat-combat { color: #ff9a8a; border-color: rgba(255, 154, 138, 0.5); }
.catpill.cat-utility { color: #8fd0ff; border-color: rgba(143, 208, 255, 0.5); }
/* monster spawner controls */
.spawn-rarity { display: flex; gap: 8px; margin: 10px 0; }
.spawn-slider { width: 55%; accent-color: var(--accent); }
.spawn-slider.wide { width: 100%; margin: 6px 0 2px; }
#spawn-lbl { font-size: 16px; }
.spawn-new { font-size: 11px; color: var(--accent); margin-left: 6px; }

/* ---- morale chip ----------------------------------------------------------------- */
#morale-chip { font-size: 13px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--edge); }
#morale-chip.morale-f { color: var(--ok); border-color: rgba(141, 224, 122, 0.4); }
#morale-chip.morale-h { color: var(--danger); border-color: rgba(255, 107, 107, 0.5); animation: atkpulse 1.4s infinite; }

/* ---- bag (tabbed inventory) -------------------------------------------------------- */
#bag-tabs { display: flex; gap: 0; flex: none; border-bottom: 1px solid var(--edge); margin-bottom: 8px; }
#bag-tabs .bagtab {
  flex: 1 1 0; min-width: 0; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font: inherit; font-size: 13px; font-weight: 700; padding: 7px 4px;
  cursor: pointer; white-space: nowrap;
}
#bag-tabs .bagtab:hover { color: var(--ink); }
#bag-tabs .bagtab.active { color: var(--ink); border-bottom-color: var(--accent); }
#bag-tabs .bagtab + .bagtab { border-left: 1px solid var(--edge); }   /* divider between tabs, like the Bible */

#bag-grid {
  /* tiles wrap to new rows and scroll vertically — never sideways (overflow-x: hidden guards
     against a scrollbar-width / narrow-viewport edge case forcing a horizontal scrollbar) */
  flex: 1 1 auto; min-height: 96px; overflow: hidden auto; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; padding: 2px;
}
.bag-empty, .bag-pick { grid-column: 1 / -1; color: var(--dim); font-size: 13px; padding: 18px 4px; text-align: center; }

.bag-tile {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 2px solid var(--rar, var(--edge)); border-radius: 12px; cursor: pointer; padding: 0;
}
.bag-tile:hover { background: var(--panel2); }
.bag-tile .bt-icon { font-size: 28px; }
.bag-tile .bt-qty {
  position: absolute; right: 3px; bottom: 2px;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 11px; font-weight: 800;
  border-radius: 6px; padding: 0 5px; line-height: 16px;
}
.bag-tile.sel { box-shadow: 0 0 0 2px var(--rar, var(--accent)), 0 0 12px var(--rar, transparent); }
.bag-tile .newdot { position: absolute; top: -4px; right: -4px; width: 10px; height: 10px; border-radius: 999px; background: var(--danger); }
.bag-tile.rarity-common { --rar: rgba(240, 238, 230, 0.4); }
.bag-tile.rarity-uncommon { --rar: rgba(141, 224, 122, 0.6); }
.bag-tile.rarity-rare { --rar: rgba(143, 208, 255, 0.7); }
.bag-tile.rarity-epic { --rar: rgba(187, 106, 255, 0.8); }

/* reserve a fixed footprint so selecting/clearing an item doesn't shuffle the modal */
#bag-detail { flex: none; min-height: 156px; border-top: 1px solid var(--edge); margin-top: 8px; padding-top: 10px; }
#bag-detail .bd-head, #build-detail .bd-head { display: flex; align-items: center; gap: 10px; }
#bag-detail .bd-icon, #build-detail .bd-icon { font-size: 26px; }
#bag-detail .bd-id, #build-detail .bd-id { display: flex; flex-direction: column; }
#bag-detail .bd-id b, #build-detail .bd-id b { font-size: 15px; }
#bag-detail .bd-rar, #build-detail .bd-rar { color: var(--dim); font-size: 12px; }
#bag-detail .bd-desc, #build-detail .bd-desc { color: var(--ink); font-size: 13px; margin: 8px 0 10px; }

/* the build menu: tabbed by category, a tile grid, and a detail strip */
#build-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--edge); margin-bottom: 8px; }
#build-tabs button {
  flex: 1 1 0; min-width: 0; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font: inherit; font-size: 13px; font-weight: 700; padding: 7px 4px; cursor: pointer; white-space: nowrap;
}
#build-tabs button:hover { color: var(--ink); }
#build-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
#build-tabs button + button { border-left: 1px solid var(--edge); }
#build-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px;
  /* room for the corner badges (top -7px / right -5px) so they don't overflow the box and
     trip overflow-y:auto into also showing a horizontal scrollbar */
  max-height: 42vh; overflow-x: hidden; overflow-y: auto; align-content: start; padding: 9px 8px 4px;
}
.build-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 12px; padding: 11px 6px 9px;
  color: var(--ink); cursor: pointer;
}
.build-tile:hover { background: var(--panel2); border-color: var(--accent); }
.build-tile.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.build-tile.locked { opacity: 0.55; }
.build-tile .bt-icon { font-size: 30px; line-height: 1; }
.build-tile .bt-name { font-size: 12px; font-weight: 700; text-align: center; line-height: 1.2; }
.build-tile .bt-badge {
  position: absolute; top: -7px; right: -5px; font-size: 9px; font-weight: 700;
  background: rgba(10, 14, 8, 0.92); border: 1px solid var(--edge); border-radius: 999px; padding: 1px 6px; white-space: nowrap;
}
.build-tile .bt-badge.poor { color: var(--accent); }
#build-detail { border-top: 1px solid var(--edge); margin-top: 10px; padding-top: 10px; min-height: 118px; }

/* a placement ghost previewing where a new building will land */
.vplot.ghost { z-index: 9; opacity: 0.72; pointer-events: none; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5)); }
#bag-detail .bd-hint { color: var(--dim); font-size: 12px; font-style: italic; }
#bag-detail .rarity-common { color: #f0eee6; }
#bag-detail .rarity-uncommon { color: #8de07a; }
#bag-detail .rarity-rare { color: #8fd0ff; }
#bag-detail .rarity-epic { color: #bb6aff; }

.bd-qty { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.bd-qty .qrange { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.bd-qty .qbtn {
  flex: none; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--edge);
  background: var(--panel2); color: var(--ink); font-size: 18px; line-height: 1; cursor: pointer;
}
.bd-qty .qbtn:hover { border-color: var(--accent); }
.bd-qty .qread { flex: none; min-width: 34px; text-align: center; font-weight: 800; font-size: 15px; }
.bd-use { width: 100%; }

/* the choice picker rides over the Bag as a second layer */
#submodal-wrap { z-index: 56; align-items: flex-start; padding: calc(var(--top-inset) + 8px) 8px calc(var(--bottom-inset) + 8px); }
#submodal {
  width: min(440px, 92vw); min-height: min(280px, 100%);
  max-height: calc(100dvh - var(--top-inset) - var(--bottom-inset) - 16px);
  overflow-y: auto; display: flex; flex-direction: column;
}
.sub-choices { display: flex; flex-direction: column; gap: 8px; }

/* ---- reports / tasks ----------------------------------------------------------------- */
.report {
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 11px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px;
}
.report.unread { border-color: rgba(255, 210, 77, 0.5); }
.report-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.report-tools small { margin-left: auto; color: var(--dim); font-size: 11px; }
.tsearch {
  padding: 5px 10px; border-radius: 8px; font-size: 12px; min-width: 150px;
  border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.07); color: var(--ink);
  outline: none; font-family: inherit;
}
.tsearch:focus { border-color: var(--accent); }

/* Large text mode: scale the whole interface ~10% */
body.textlg { zoom: 1.1; }
body.textxl { zoom: 1.2; }
.btn.ghost { background: var(--panel); color: var(--dim); }
.btn.ghost:hover { color: var(--ink); }
.rdel {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 12px; padding: 0 4px; margin-left: 6px;
}
.rdel:hover { color: var(--danger); }
.upready {
  position: absolute; top: 4px; right: 7px;
  color: var(--ok); font-size: 15px; font-weight: 800;
  animation: atkpulse 1.6s ease-in-out infinite;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.report b { display: block; margin-bottom: 4px; }
.report .when { float: right; font-size: 11px; color: var(--dim); }
.report .rline { color: var(--dim); margin-top: 2px; }

.task {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 11px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px;
}
.task .ttext { flex: 1; }
.task .progress { font-size: 12px; color: var(--dim); }
.task.claimed { opacity: 0.5; }
.task .reward { font-size: 12px; color: var(--dim); }
.task .task-prog { color: var(--dim); font-size: 13px; font-weight: 600; }
.task-claimed { font-size: 13px; color: var(--dim); white-space: nowrap; }

/* Main / Daily segmented tabs, matching the Bag and Game Bible */
#task-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--edge); margin-bottom: 12px; }
#task-tabs button {
  flex: 1 1 0; min-width: 0; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font: inherit; font-size: 15px; font-weight: 700; padding: 9px 4px; cursor: pointer; white-space: nowrap;
}
#task-tabs button:hover { color: var(--ink); }
#task-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
#task-tabs button + button { border-left: 1px solid var(--edge); }
/* a red pill on a sub-tab showing how many rewards are claimable in it */
.ttbadge {
  display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px; vertical-align: middle;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px;
  border-radius: 999px; text-align: center;
}
.lore-line { font-size: 16px; line-height: 1.55; font-style: italic; color: var(--ink); padding: 6px 2px 2px; }

.task-section-h { margin: 16px 0 8px; font-size: 12px; font-weight: 800; color: var(--dim); text-transform: uppercase; letter-spacing: 0.05em; }
.task-empty { color: var(--dim); font-size: 13px; padding: 4px 4px 10px; }

/* the "all tasks completed" banner — the Steward's "nothing left to point you at" */
.task-alldone {
  background: var(--panel); border: 1px solid var(--accent); border-radius: 12px;
  padding: 20px 14px; text-align: center; font-size: 18px; font-weight: 800; color: var(--accent);
}
.task-alldone-sub { color: var(--dim); font-size: 13px; text-align: center; margin: 8px 6px 2px; }

/* daily refresh countdown bar */
.daily-refresh {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 12px; font-size: 13px; color: var(--dim);
}
.daily-refresh b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* tools row under the tabs: the persistent "hide completed" toggle + Claim All */
.task-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.task-toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; cursor: pointer; user-select: none; }
.task-toggle input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ---- buttons ---------------------------------------------------------------------------- */
.btn {
  background: #3c5a2e; color: #fff; border: 1px solid var(--edge);
  border-radius: 9px; padding: 7px 14px; font-size: 13px;
}
.btn:hover:not(:disabled) { background: #4d7239; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.warn { background: #6e3a2a; }
.btn.warn:hover:not(:disabled) { background: #8a4833; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ---- modal ----------------------------------------------------------------------------- */
/* modals dock in the gap between the top bar and the bottom rails/chat — never under the
   bar (so the ✕ is reachable) and never over the Hero/World/chat buttons */
#modal-wrap { align-items: flex-start; padding: calc(var(--top-inset) + 8px) 8px calc(var(--bottom-inset) + 8px); }
/* a fixed footprint: modals don't resize or shuffle as their content changes */
#modal {
  width: min(560px, 94vw); min-height: min(380px, 100%);
  max-height: calc(100dvh - var(--top-inset) - var(--bottom-inset) - 16px);
  overflow-y: auto; display: flex; flex-direction: column;
}
#modal > :last-child.modal-actions { margin-top: auto; }
/* the heading (and its ✕) stays pinned at the modal top while the body scrolls under it —
   the negative margins bleed it over the card padding so it spans full width and pins flush */
#modal h2, #submodal h2 {
  position: sticky; top: 0; z-index: 3;
  margin: -20px -22px 10px; padding: 18px 22px 10px;
  background: var(--panel); border-radius: 14px 14px 0 0;
  font-size: 19px;
}
#modal h2 .closex, #submodal h2 .closex { float: right; cursor: pointer; color: var(--dim); font-size: 22px; line-height: 1; }
#modal h2 .closex:hover, #submodal h2 .closex:hover { color: var(--ink); }
/* the profile modal: a survivor identity card + lore / survivors / log-out actions */
.profile-card { display: flex; align-items: center; gap: 14px; background: var(--panel2);
  border: 1px solid var(--edge); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.profile-card .pfx-av-lg { font-size: 40px; line-height: 1; }
.profile-card b { font-size: 17px; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel2); color: var(--ink); border: 1px solid var(--edge);
  border-radius: 11px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled { opacity: 0.45; cursor: default; }
.choice .cicon { font-size: 26px; }
.choice .cinfo { flex: 1; }
.choice .cinfo b { display: block; }
.choice .cinfo small { display: block; font-size: 12px; }
.choice .ccost { font-size: 12px; text-align: right; color: var(--dim); white-space: nowrap; }
.modal-stat { font-size: 14px; margin: 4px 0; color: var(--dim); }
.modal-stat b { color: var(--ink); }
.modal-stat.sub { font-size: 12px; opacity: 0.8; margin-top: 2px; }
.modal-stat.warnstat { color: #ff8aa6; }
.modal-stat.warnstat b { color: #ffb3c4; }

/* research tree: collapsible category panels, indented branches, lock dimming */
.rtree-cat {
  display: flex; align-items: center; gap: 6px; width: 100%;
  font-size: 12px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--accent); margin: 12px 0 5px; padding: 2px 2px 4px;
  background: none; border: none; border-bottom: 1px solid var(--edge);
  text-align: left; cursor: pointer; font-family: inherit;
}
.rtree-cat:hover { color: #fff; }
.rtree-chev { display: inline-block; transition: transform 0.15s; font-size: 10px; }
.rtree-cat.collapsed .rtree-chev { transform: rotate(-90deg); }
.rtree-body.collapsed { display: none; }
.rtree-node.d1 { margin-left: 16px; border-left: 2px solid var(--edge); }
.rtree-node.d2 { margin-left: 32px; border-left: 2px solid var(--edge); }
.rtree-node.rtree-locked { opacity: 0.62; }
.rtree-req { color: var(--dim); font-size: 11px; }
.active-research { outline: 1px solid var(--accent); }
/* in modal job rows the progress bar fills the space between title and buttons */
.queue-row .qbar { flex: 1 1 auto; margin-left: 0; min-width: 90px; }
.queue-row .rtitle { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* survivors list: dim the offline, faintly tint the NPCs */
.queue-row.roster-off { opacity: 0.55; }
.queue-row.roster-bot { opacity: 0.8; }

/* wall/turret construction surfaced on the settlement screen */
.defbuild-strip { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.defbuild-strip .queue-row { margin: 0; }

/* wall/turret durability readout */
.durok { color: var(--ok); }
.durmid { color: var(--accent); }
.durlow { color: var(--bad); font-weight: 700; }

/* green ↑ on a troop row: opens the retrain modal */
.upg-arrow {
  background: none; border: none; cursor: pointer; color: var(--ok);
  font-size: 15px; line-height: 1; padding: 0 2px; margin-left: 5px; vertical-align: middle;
}
.upg-arrow:hover { filter: brightness(1.35); transform: translateY(-1px); }

/* the Armory study/craft progress, surfaced on the Commander tab */
.study-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 6px; }
.study-row .qbar { flex: 1 1 auto; margin-left: 0; min-width: 90px; height: 15px; }
.qbar.forge i { background: linear-gradient(180deg, #9aa3ad, #6b7480); }
.numrow { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }
.numrow label { width: 130px; }
.numrow input {
  width: 90px; padding: 6px 10px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--edge); background: rgba(255,255,255,0.07); color: #fff;
  outline: none; font-family: inherit;
}
.btn.qf { padding: 4px 8px; font-size: 11px; background: var(--panel2); }
.btn.qf:hover { background: #3c5a2e; }
/* flock picker steppers: − [count] + MIN MAX ✕ */
.numrow input.unitcount {
  width: 52px; text-align: center; -moz-appearance: textfield; appearance: textfield;
}
.numrow input.unitcount::-webkit-outer-spin-button,
.numrow input.unitcount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.btn.step { padding: 4px 9px; font-size: 13px; line-height: 1; }
/* current/next stat grid used by building modals */
.statgrid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0;
}
.statgrid > div {
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--edge); border-radius: 9px;
  padding: 7px 10px; font-size: 13px;
}
.statgrid small { display: block; color: var(--dim); font-size: 10px; margin-bottom: 2px; }
/* retrain row under each unit in the Army tab */
.upg-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: -4px 0 10px 44px; font-size: 12px; color: var(--dim);
}
.preset-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }

/* ---- attack power comparison ------------------------------------------------ */
#atk-compare {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.22); border: 1px solid var(--edge);
}
.pwrow { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 4px 0; }
.pwrow label { width: 110px; color: var(--dim); }
.pwrow b { min-width: 46px; text-align: right; color: var(--accent); }
.pwtrack {
  flex: 1; height: 10px; border-radius: 5px;
  background: rgba(0, 0, 0, 0.45); overflow: hidden;
}
.pwtrack i { display: block; height: 100%; border-radius: 5px; transition: width .15s; }
.pwtrack i.mine { background: var(--ok); }
.pwtrack i.theirs { background: var(--danger); }
.verdict { margin-top: 8px; font-size: 13px; }
.verdict.dimline { color: var(--dim); margin-top: 4px; }

/* ---- chat modal (opened from the bottom strip) ------------------------------------------ */
.chat-log {
  flex: 1; overflow-y: auto; font-size: 14px;
  display: flex; flex-direction: column; gap: 3px;
  /* clear the sticky heading: its negative top margin otherwise overlaps the first line */
  margin: 12px 0 10px;
}
.chat-log .sys { color: var(--accent); font-style: italic; }
.chat-log .name { font-weight: 700; color: var(--blue); }
.cts { color: var(--dim); font-size: 11px; }
#chat-row { display: flex; gap: 8px; align-items: center; }
#chat-input {
  flex: 1; padding: 8px 12px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--edge); background: rgba(255,255,255,0.06); color: #fff;
  outline: none; font-family: inherit;
}

/* ---- toast ------------------------------------------------------------------------------ */
/* informational blue by default; green for celebrations — red read as errors */
#toast {
  position: fixed; top: calc(var(--top-inset) + 8px); left: 50%; transform: translateX(-50%);
  background: rgba(35, 70, 110, 0.95); border: 1px solid rgba(143, 208, 255, 0.5);
  padding: 9px 20px; border-radius: 10px; font-size: 14px; z-index: 60;
}
#toast.good { background: rgba(40, 90, 35, 0.95); border-color: rgba(140, 224, 122, 0.5); }

/* ---- update banner ----------------------------------------------------------------------- */
/* shown (via .show) when a reconnect reveals a newer build — sits above modals so it's seen.
   one line on desktop; on phones the message takes the top row, Refresh spans the bottom. */
#update-banner {
  display: none; position: fixed; z-index: 55; top: calc(var(--top-inset) + 8px); left: 50%; transform: translateX(-50%);
  flex-direction: row; align-items: center; flex-wrap: nowrap; gap: 10px; max-width: 92vw;
  background: #0a0d13; color: var(--ink); border: 1px solid var(--blue); border-radius: 12px;
  padding: 8px 10px 8px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}
#update-banner.show { display: flex; }
/* the reconnect cue: shown whenever the live WS link is down (e.g. the tab was paused) */
#conn-banner {
  display: none; position: fixed; z-index: 95; top: calc(var(--top-inset) + 8px); left: 50%; transform: translateX(-50%);
  align-items: center; gap: 7px; max-width: 92vw;
  background: rgba(10, 13, 19, 0.92); color: var(--ink); border: 1px solid rgba(255, 210, 77, 0.5);
  border-radius: 999px; padding: 6px 15px; font-size: 13px; font-weight: 600; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}
#conn-banner.show { display: flex; }
#conn-banner .cb-spin { display: inline-block; animation: cbspin 1.1s linear infinite; }
@keyframes cbspin { to { transform: rotate(360deg); } }
#update-banner .ub-msg { white-space: nowrap; }
#update-banner #update-refresh { flex: none; background: var(--blue); color: #08121d; border: none; padding: 5px 14px; font-weight: 700; }
#update-banner #update-refresh:hover { filter: brightness(1.08); background: var(--blue); }
#update-banner .ub-x { flex: none; background: none; border: none; color: var(--dim); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
#update-banner .ub-x:hover { color: var(--ink); }
@media (max-width: 760px) {
  /* span the width and stack: message (+ ✕) on top, Refresh across the bottom */
  #update-banner { left: 8px; right: 8px; transform: none; max-width: none; flex-wrap: wrap; }
  #update-banner .ub-msg { flex: 1 1 auto; white-space: normal; order: 1; }
  #update-banner .ub-x { order: 2; }
  #update-banner #update-refresh { order: 3; flex: 1 1 100%; }
}

/* ---- compact / phone layout -------------------------------------------------------- */
/* one column, a fixed bottom tab bar, chat as a slim sheet above it */
@media (max-width: 760px) {
  /* the bar stays docked full-width; just tighten the type and padding for phones */
  #topbar { padding: calc(5px + env(safe-area-inset-top)) 8px 5px; font-size: 13px; gap: 4px; }
  #profile-btn .pfx-av { font-size: 20px; }
  #profile-btn .pfx-id b { font-size: 12px; max-width: 7ch; }
  #resbar { padding: 1px 4px; }
  .resrow { gap: 9px; }
  .res { font-size: 12px; }
  .topcell-icon { font-size: 16px; padding: 2px 6px; }

  /* queue chips top-left, the raid indicator top-right — both compact over the canvas */
  #leftbar { left: 6px; right: auto; bottom: auto; width: auto; max-width: 66vw; max-height: 44vh; }
  #rightbar { right: 6px; }
  .hint-flyout { max-width: 44vw; padding: 6px 9px; }

  /* the side rails hug the edges with narrower buttons; chat strip sits between them */
  #bar-left { left: 6px; }
  #bar-right { right: 6px; }
  .srbtn { width: 54px; font-size: 18px; padding: 5px 3px 4px; }
  .srbtn .sri { font-size: 18px; }
  .srlbl { font-size: 8.5px; }

  /* base/world stay full-bleed; content screens fill between the top bar and the nav */
  :root { --sheet-foot: calc(182px + env(safe-area-inset-bottom)); }   /* narrower rails on phones */
  .panel.sheet { padding: calc(var(--top-inset) + 6px) 8px var(--sheet-foot); }
  .card { max-width: 94vw; max-height: 84vh; overflow-y: auto; padding: 14px 14px; }
  /* keep the sticky heading bled over the smaller phone card padding */
  #modal h2, #submodal h2 { margin: -14px -14px 10px; padding: 14px 14px 8px; }

  /* the village's furniture shrinks via the grid's --tile now; do NOT pin a fixed .vplot width
     here — it overrode the cell size and pushed the building icon off its tile on phones */
  .vplot .vemoji { font-size: 23px; }
  .vplot.egg .vemoji { font-size: 50px; }
  .vplot .vlabel { font-size: 8px; max-width: 64px; padding: 0 5px; }
  .vplot .vcircle { width: 28px; height: 28px; font-size: 13px; }
  .vplot .vbar2 { width: 56px; height: 12px; }
  .vturret { font-size: 14px; }
  .vgate { font-size: 19px; }

  /* the chat strip clears the rails on both sides */
  #chat-strip { left: 66px; right: 66px; padding: 8px 11px; font-size: 12px; }
}

/* ---- procedural juice (fx.js): code-driven, no art assets ----------------------- */
#fx-layer { position: fixed; inset: 0; z-index: 9000; pointer-events: none; overflow: hidden; }
.fx-burst { position: fixed; width: 0; height: 0; }
.fx-ring {
  position: absolute; left: 0; top: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid rgba(255, 240, 200, 0.9); border-radius: 50%; animation: fx-ring 0.5s ease-out forwards;
}
@keyframes fx-ring { from { transform: scale(0.4); opacity: 0.9; } to { transform: scale(3.2); opacity: 0; } }
.fx-dust {
  position: absolute; left: 0; top: 0; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px;
  background: radial-gradient(circle, #fff4d6 0%, #caa85e 70%, transparent 100%); border-radius: 50%;
  animation: fx-dust 0.6s ease-out forwards;
}
@keyframes fx-dust {
  from { transform: translate(0, 0) scale(var(--s, 1)); opacity: 0.95; }
  to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
.fx-text {
  position: fixed; transform: translate(-50%, -50%); white-space: nowrap;
  font-weight: 800; font-size: 16px; color: #ffe08a; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), 0 0 2px rgba(0, 0, 0, 0.9);
  animation: fx-text 1.1s cubic-bezier(.2, .7, .3, 1) forwards;
}
.fx-text.good { color: #7fe08a; }
.fx-text.bad { color: #ff7d6b; }
@keyframes fx-text {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -65%) scale(1.1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
.fx-fly { position: fixed; transform: translate(-50%, -50%); font-size: 20px; will-change: transform; transition: transform 0.2s ease-out; pointer-events: none; }
.fx-shake { animation: fx-shake 0.5s cubic-bezier(.36, .07, .19, .97); }
@keyframes fx-shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); }
}
/* a freshly-built/completed building springs in */
.vplot.fx-rise { animation: fx-rise 0.55s cubic-bezier(.2, 1.4, .4, 1); transform-origin: center bottom; z-index: 8; }
@keyframes fx-rise { 0% { transform: scale(0.2); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.vplot.fx-done { animation: fx-done 0.6s ease-out; z-index: 8; }
@keyframes fx-done {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.22); filter: brightness(1.9) drop-shadow(0 0 8px rgba(255, 220, 120, 0.9)); }
  100% { transform: scale(1); filter: brightness(1); }
}
/* the resource bar gives a little kick when stores jump */
#resbar.fx-pulse { animation: fx-pulse 0.5s ease-out; }
@keyframes fx-pulse { 0% { transform: scale(1); } 40% { transform: scale(1.14); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .fx-rise, .fx-done, .fx-shake, .fx-pulse { animation: none !important; } }

/* world map first-load cue — shown in the panel until the canvas mounts */
.map-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 10px; font-weight: 700; color: var(--ink, #f5efe0); background: #dbe3ea; color: #4a5568;
  font-size: 15px; z-index: 5;
}
.map-spin { display: inline-block; animation: map-spin 1.6s linear infinite; font-size: 22px; }
@keyframes map-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .map-spin { animation: none; } }

/* faction banner swatches in settings */
.swatch { width: 34px; min-width: 34px; height: 30px; padding: 0; font-weight: 900; color: #fff; border: 2px solid rgba(0,0,0,0.35); }
.swatch.sel { border-color: #fff; }
.swatch-blue { background: #3d6fd6; }
.swatch-red { background: #c8402f; }
.swatch-yellow { background: #d6a53d; }
.swatch-purple { background: #8a4fc8; }

/* hero / steward sprite portraits — frame 0 of an idle sheet via background-size N*100% */
.hero-sprite { display: inline-block; background-repeat: no-repeat; background-position: 0 0; image-rendering: pixelated; }
.swatch-black { background: #3a3f47; }

/* ---- battle replay (phase 3): DOM sprite theater driven by the report round log ---- */
#rp-stage { position: relative; display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; min-height: 200px; padding: 12px 10px 16px; border-radius: 10px; background: linear-gradient(180deg, rgba(120,160,90,.18), rgba(60,80,45,.35)); overflow: hidden; }
.rp-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rp-side.enemy { align-items: flex-end; }
.rp-row { display: flex; align-items: center; gap: 8px; }
.rp-cnt { font-weight: bold; min-width: 34px; }
/* the enemy pack: a knot of creature sprites that thins as the pool drains */
.rp-pack { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-end; gap: 2px; max-width: 190px; filter: drop-shadow(0 3px 3px rgba(0,0,0,.4)); }
.rp-pack .rp-foespr { transition: opacity .4s, filter .4s; }
.rp-bar { width: 130px; height: 10px; background: rgba(0,0,0,.45); border-radius: 5px; overflow: hidden; }
.rp-bar i { display: block; height: 100%; width: 100%; background: #c94f4f; transition: width .45s ease; }
.rp-bar.mine i { background: #58a65c; }
#rp-banner { position: absolute; left: 0; right: 0; top: 42%; text-align: center; font-weight: bold; font-size: 17px; text-shadow: 0 2px 4px rgba(0,0,0,.55); pointer-events: none; }
#rp-summary { min-height: 18px; margin-top: 6px; }
.rp-float { position: absolute; font-weight: bold; font-size: 15px; text-shadow: 0 1px 3px rgba(0,0,0,.6); animation: rpfloat 1.1s ease-out forwards; pointer-events: none; }
@keyframes rpfloat { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-38px); } }
.rp-shake { animation: rpshake .45s; }
@keyframes rpshake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.rp-lunge { animation: rplunge .5s; }
@keyframes rplunge { 0%,100% { transform: translateX(0); } 40% { transform: translateX(16px); } }
.rp-hit { animation: rphit .5s; }
@keyframes rphit { 0%,100% { filter: none; } 35% { filter: brightness(1.6) saturate(2) hue-rotate(-25deg); } }
.rp-dead { opacity: .35; filter: grayscale(1); }

/* ---- responsive pass (pre-playtest): wrap what can wrap, scroll what cannot -------- */
/* wide data tables (the bible's unit/keep tables) scroll inside their OWN box instead
   of dragging the whole page or modal sideways */
.bible-tbl { display: block; overflow-x: auto; max-width: 100%; }
/* the Lord sheet's sub-tabs (4 now, with Formation) wrap on narrow screens instead of
   forcing the whole sheet wider than the modal */
.hero-subnav { flex-wrap: wrap; row-gap: 4px; }
/* training rows and stepper rows shed their buttons to a second line when squeezed */
.unit-row, .numrow { flex-wrap: wrap; row-gap: 4px; }
.trainbtns { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

@media (max-width: 420px) {
  /* the top bar must never overflow: tighter icon cells + resource gaps */
  #topbar { gap: 3px; }
  .topcell-icon { font-size: 15px; padding: 2px 4px; }
  .resrow { gap: 6px; }
  #profile-btn .pfx-id b { max-width: 6ch; }
  .subtab { padding: 4px 8px; font-size: 12px; }
}

/* fingers need bigger targets than mouse pointers */
@media (pointer: coarse) {
  .btn.small, .step, .subtab, .qf { min-height: 34px; }
  .unitcount { min-height: 30px; }
}

/* very narrow phones (360px Androids, small SEs): the resource rows may wrap and the
   profile name yields first — the top bar must never scroll sideways */
.resrow { flex-wrap: wrap; justify-content: center; }
@media (max-width: 380px) {
  #profile-btn .pfx-id b { max-width: 5ch; }
  .res { font-size: 11px; }
  .resrow { gap: 5px; }
}
