/* SKY SQUAD DEFENSE — field equipment, not a dashboard
   The chrome is moulded tan plastic: matte, slightly warm, lightly textured,
   with recessed wells and raised keys. Colour is reserved for meaning — the
   two fireteams, and things that are on fire. Everything else is plastic and
   ink. Mobile first: the canvas owns the screen and panels slide over it as
   sheets. From 900px up, the sheets dock permanently as side columns. */

:root {
  /* The plastic itself — four steps of one warm brown. Field equipment that
     has been outside for years: dark, dirty, and quiet next to the map. The
     ◐ key drops it a further step for night use. */
  --shell:        #4a3d2e;
  --shell-hi:     #5d4e3b;
  --shell-lo:     #3a2f23;
  --shell-deep:   #241d15;
  /* recessed areas: darker, cooler, where readouts sit */
  --well:         #2e2c26;
  --well-hi:      #3b3830;
  --well-lo:      #21201b;

  --bg: #14140f;
  --panel: rgba(74, 61, 46, 0.97);
  --panel-solid: #4a3d2e;
  --line: rgba(70, 64, 50, 0.34);
  --line-strong: rgba(52, 47, 36, 0.6);

  /* ink on plastic, and the reverse for recessed readouts */
  --text: #ede3d2;
  --dim: #b8a98f;
  --dimmer: #8d7f68;
  --screen-text: #d9d2bd;
  --screen-dim: #9a937f;

  --teal: #3fd6c2;         /* CHARLIE — pale enough to read on brown */
  --purple: #c08ef5;       /* BRAVO */
  --teal-bright: #14b8a6;  /* same two, for use on the dark map */
  --purple-bright: #a855f7;
  --red: #e4675a;
  --blue: #74a6d8;
  --green: #8fc47a;
  --yellow: #e0b545;
  --orange: #e08442;

  --sheet-h: 42vh;
  font-synthesis: none;
}

/* Night shell: the same mouldings and the same lighting, one further step
   down. Almost black, with just enough brown left in it to still read as
   plastic rather than a hole in the screen. */
:root[data-theme="dark"] {
  --shell:      #241e17;
  --shell-hi:   #322a20;
  --shell-lo:   #1a150f;
  --shell-deep: #0c0a07;

  --panel: rgba(36, 30, 23, 0.97);
  --panel-solid: #241e17;

  --text:   #ded3bf;
  --dim:    #a2957c;
  --dimmer: #7a6e5a;
}

/* THE GRAIN.
   Real coarse plastic is not a flat fill — it is thousands of tiny facets,
   each catching light on one edge and shadow on the other. Fractal noise from
   an inline SVG gives exactly that, and because it is a data URI it costs no
   request and tiles forever. The two crossed hatches on top add the moulded
   directionality you feel on a rifle grip, and the vertical wash is the light
   coming from above. */
:root {
  /* Coarse: a low base frequency gives big-ish flecks rather than TV static,
     and three octaves keeps them irregular. Opacity is baked in because a
     background-image cannot carry one. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.62' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.92'/%3E%3C/svg%3E");
  --key-on-ink: #f6eedd;    /* latched keys sink into a darker well — light ink */
  --hatch:
    repeating-linear-gradient(58deg, rgba(255,255,255,0.035) 0 1px, rgba(0,0,0,0.030) 1px 3px),
    repeating-linear-gradient(-31deg, rgba(255,255,255,0.022) 0 1px, rgba(0,0,0,0.020) 1px 4px);
}
/* Latched keys sink into a well cut below whichever shell is fitted. */
.btn.on, .seg button.on { background-color: #2b2219; }
:root[data-theme="dark"] .btn.on,
:root[data-theme="dark"] .seg button.on { background-color: #120e0a; }

/* One class, used by every moulded surface. */
.plastic,
.panel, #topbar, #bottombar, .overlay, .rolepop, .ov-head, .ov-foot {
  background-color: var(--shell);
  background-image:
    var(--grain),
    var(--hatch),
    linear-gradient(180deg, rgba(255,255,255,0.11), rgba(0,0,0,0.09));
  background-blend-mode: overlay, normal, normal, normal;
  background-size: 120px 120px, auto, auto, auto;
}
/* The grain has to be visible on the keys too, or they read as stickers on a
   textured panel rather than parts of the same moulding. */
.btn, .bigbtn, .iconbtn, .ghostbtn, .card, .slot, .kit, .sold, .ft-head {
  background-image:
    var(--grain),
    linear-gradient(180deg, rgba(255,255,255,0.20), rgba(0,0,0,0.10));
  background-blend-mode: overlay, normal;
  background-size: 120px 120px, auto;
}

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

.hidden { display: none !important; }

/* Dev-only controls. The deploy script stamps body.env-dev on the dev build
   and strips it on promote, so these simply do not exist in production. */
.dev-only { display: none !important; }
body.env-dev .dev-only { display: flex !important; }

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  /* long-press on a phone raises the same callout the right mouse button
     does on desktop — neither belongs over the battlefield */
  -webkit-touch-callout: none;
}

input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

#app { position: fixed; inset: 0; display: block; }

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

/* ---------------------------------------------------------------- top bar */

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: stretch; gap: 1px;
  background-color: var(--shell);
  border-bottom: 1px solid var(--shell-deep);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.36);
  padding: 0;
  z-index: 30;
  height: 46px;
  padding-top: env(safe-area-inset-top);
  height: calc(46px + env(safe-area-inset-top));
}

.tb { display: flex; flex-direction: column; justify-content: center; padding: 4px 9px; min-width: 0; }
.tb-label { font-size: 8.5px; letter-spacing: 0.14em; color: var(--dim); text-transform: uppercase; line-height: 1.2; }
.tb-value { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#tbLevel { border-right: 1px solid var(--line); min-width: 96px; }
#tbLevel .tb-value { color: var(--yellow); }
#tbCap { flex: 1; border-right: 1px solid var(--line); min-width: 0; }
#tbForce { border-right: 1px solid var(--line); }
#tbTimer { border-right: 1px solid var(--line); min-width: 62px; }

.capbar {
  position: relative; height: 6px; margin-top: 3px;
  background: rgba(0,0,0,0.42); border-radius: 2px; overflow: hidden;
}
.capbar > i {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #b91c1c, var(--red));
  transition: width 0.18s linear;
}
.capbar.recovering > i { background: linear-gradient(90deg, #0d8074, var(--teal)); }

.state-SECURE { color: var(--green); }
.state-CONTESTED { color: var(--yellow); }
.state-ENEMY { color: var(--red); }
.state-RECOVERING { color: var(--teal); }

#tbBtns { display: flex; align-items: center; gap: 4px; padding: 0 6px; margin-left: auto; }

/* Narrow screens cannot fit five columns. Drop the capture readout onto its
   own full-width row so the bar itself is never squeezed out. */
@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; height: auto; padding-top: env(safe-area-inset-top); }
  #tbLevel { min-width: 0; flex: 1; }
  #tbCap {
    order: 9; flex: 1 0 100%;
    border-right: none; border-top: 1px solid var(--line);
    padding-top: 3px; padding-bottom: 5px;
  }
  #tbTimer { min-width: 54px; }
  .tb-label { font-size: 8px; }
  .tb-value { font-size: 12px; }
  #alerts { top: calc(92px + env(safe-area-inset-top)); }
}
.iconbtn {
  background-color: var(--shell);
  border: 1px solid var(--shell-deep); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 2px 0 var(--shell-deep);
  color: var(--dim); border-radius: 5px;
  width: 32px; height: 32px; font-size: 13px; line-height: 1;
  display: grid; place-items: center; cursor: pointer; padding: 0;
  font-family: inherit;
}
.iconbtn:active { transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(0,0,0,0.34); }
/* latched: sunk, with the amber lamp showing on its edge */
.iconbtn.on {
  color: var(--text); border-color: var(--yellow);
  background-image: var(--grain), linear-gradient(180deg, rgba(0,0,0,0.14), rgba(255,255,255,0.10));
  transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.34), inset 0 -2px 0 var(--yellow);
}

/* ---------------------------------------------------------------- alerts */

#alerts {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(52px + env(safe-area-inset-top));
  z-index: 25; width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  pointer-events: none;
}
.alert {
  font-size: 11px; letter-spacing: 0.1em; font-weight: 700;
  padding: 5px 12px; border-radius: 3px;
  background: rgba(6,10,16,0.88); border: 1px solid var(--line);
  animation: alertIn 0.18s ease-out;
  max-width: 100%; text-align: center;
}
@keyframes alertIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.alert.bad { color: #fff; background: rgba(120,20,20,0.9); border-color: rgba(239,68,68,0.6); }
.alert.warn { color: var(--yellow); border-color: rgba(234,179,8,0.45); }
.alert.good { color: var(--green); border-color: rgba(34,197,94,0.45); }
.alert.contact { color: var(--orange); border-color: rgba(249,115,22,0.5); }
.alert.level { color: var(--yellow); background: rgba(40,32,4,0.92); border-color: rgba(234,179,8,0.6); font-size: 12px; }

/* --------------------------------------------------------- targeting mode */

#targeting {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 40;
  background: rgba(8,14,22,0.96); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 8px 10px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
#targetingText { font-size: 11px; letter-spacing: 0.1em; font-weight: 700; color: var(--teal); }
#targeting button {
  font-family: inherit; font-size: 10px; letter-spacing: 0.08em;
  background: rgba(239,68,68,0.16); border: 1px solid rgba(239,68,68,0.5);
  color: #ffb4b4; border-radius: 4px; padding: 5px 9px; cursor: pointer;
}

/* ---------------------------------------------------------------- panels */

.panel {
  position: absolute; z-index: 28;
  background-color: var(--shell);
  border: 1px solid var(--shell-deep);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.34),
    inset 0 -1px 0 rgba(0,0,0,0.22),
    0 6px 18px rgba(0,0,0,0.45);
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* Stamped label on the shell, the way a hatch is labelled on real kit. */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid var(--shell-deep);
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.28);
  font-size: 9px; letter-spacing: 0.2em; font-weight: 700;
  color: var(--dim); text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  flex: 0 0 auto;
}
/* The body is a recess milled into the plastic — darker, with the light
   catching the top lip. Readouts live down here, in pale ink on dark. */
.panel-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 9px; flex: 1 1 auto; touch-action: pan-y;
  background-color: var(--shell);
  color: var(--text);
  box-shadow: inset 0 3px 6px rgba(0,0,0,0.16);
}

/* mobile: bottom sheets.
   They stop ABOVE the bottom bar rather than covering it — CALL REINFORCEMENTS
   and the spawn toggle have to stay reachable no matter which panel is open. */
@media (max-width: 899px) {
  .panel {
    left: 0; right: 0;
    bottom: calc(104px + env(safe-area-inset-bottom));
    height: var(--sheet-h);
    transform: translateY(calc(100% + 120px));
    transition: transform 0.22s cubic-bezier(0.22,0.9,0.3,1);
    border-radius: 12px 12px 0 0;
  }
  .panel[data-open="1"] { transform: none; }
}

/* desktop: docked columns */
@media (min-width: 900px) {
  #panelSquad { left: 0; top: calc(46px + env(safe-area-inset-top)); bottom: 62px; width: 268px; border-left: none; }
  #panelOrders { right: 0; top: calc(46px + env(safe-area-inset-top)); bottom: 62px; width: 300px; border-right: none; }
  .panel { transform: none !important; }
  #tabs { display: none; }
}

/* ------------------------------------------------------------ roster list */

.ft-head {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 7px; margin: 3px 0 5px;
  border-left: 3px solid var(--teal);
  background: var(--shell-lo);
  cursor: pointer; border-radius: 0 4px 4px 0;
}
.ft-head.purple { border-left-color: var(--purple); }
.ft-head.sel { background: var(--shell-hi); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4); }
.ft-head.purple.sel { background: var(--shell-hi); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4); }
.ft-name { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; }
.ft-meta { font-size: 9.5px; color: var(--dim); margin-left: auto; letter-spacing: 0.06em; }

.sold {
  display: grid;
  grid-template-columns: 30px 34px 1fr auto;
  align-items: center; gap: 7px;
  padding: 4px 6px; border-radius: 3px; margin-bottom: 3px;
  cursor: pointer; border: 1px solid transparent;
  background: var(--shell-lo);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.20), 0 1px 0 rgba(255,255,255,0.26);
}
.sold:active, .sold.sel {
  background: var(--shell-hi);
  border-color: var(--shell-deep);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
}
.sold.dead { opacity: 0.35; }
.sold.down { background: rgba(120,20,20,0.24); }
.sold-cs { font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.10); }
.sold-kit { font-size: 9px; color: var(--dim); letter-spacing: 0.06em; }
.sold-bar { height: 4px; background: rgba(0,0,0,0.42); box-shadow: inset 0 1px 2px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.28); border-radius: 2px; overflow: hidden; margin-top: 2px; }
.sold-bar > i { display: block; height: 100%; background: var(--green); }
.sold-bar.low > i { background: var(--yellow); }
.sold-bar.crit > i { background: var(--red); }
.sold-tag { font-size: 8.5px; letter-spacing: 0.08em; padding: 1px 4px; border-radius: 3px; white-space: nowrap; }
.tag-down { background: rgba(239,68,68,0.2); color: #ff9a9a; }
.tag-vuln { background: rgba(255,255,255,0.14); color: #fff; }
.tag-queue { background: rgba(59,130,246,0.2); color: #9dc0ff; }
.tag-empty { background: rgba(0,0,0,0.16); color: var(--dim); }
.tag-lead { background: rgba(234,179,8,0.18); color: var(--yellow); }

/* ---------------------------------------------------------- order buttons */

.grp { margin-bottom: 11px; }
/* Engraved into the recess: a hairline rule runs off the end of the label,
   the way panel sections are divided on real equipment. */
.grp-title {
  font-size: 8.5px; letter-spacing: 0.22em; color: var(--dim);
  text-transform: uppercase; margin: 0 0 7px 0; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.grp-title::after {
  content: ''; flex: 1 1 auto; height: 2px;
  background: linear-gradient(90deg, rgba(0,0,0,0.22) 0 50%, rgba(255,255,255,0.34) 50% 100%);
  background-size: 100% 1px, 100% 1px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.3);
}
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.btns.three { grid-template-columns: repeat(3, 1fr); }

/* Buttons are colour-coded by what they DO, so the panel isn't a wall of
   identical grey: movement teal, defensive blue, toggles amber/green,
   destructive red. Each carries an icon so it reads at a glance. */
/* A key moulded from the same plastic. Category shows as a painted stripe
   down its left edge, not as a wash over the whole face — so a panel of
   fifteen of them still reads as one instrument rather than a paint chart. */
.btn {
  --bc: 109,101,83;                  /* accent as "r,g,b" */
  font-family: inherit; font-size: 9.5px; letter-spacing: 0.07em; font-weight: 700;
  background-color: var(--shell);
  border: 1px solid var(--shell-deep);
  border-left: 4px solid rgb(var(--bc));
  color: var(--text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  border-radius: 3px; padding: 7px 5px; cursor: pointer;
  text-align: center; line-height: 1.2;
  min-height: 46px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.42),
    inset 0 -2px 0 rgba(0,0,0,0.16),
    0 2px 0 var(--shell-deep),
    0 3px 4px rgba(0,0,0,0.35);
}
.btn .ico { width: 19px; height: 19px; color: rgb(var(--bc)); flex: 0 0 auto; }
/* pressed: the key sinks into the shell */
.btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.34), 0 0 0 var(--shell-deep);
}
/* latched on: the key stays down and its lamp is lit */
.btn.on {
  background-color: var(--shell-lo);
  background-image: var(--grain), linear-gradient(180deg, rgba(0,0,0,0.16), rgba(255,255,255,0.10));
  border-color: rgb(var(--bc));
  color: var(--key-on-ink);
  transform: translateY(2px);
  box-shadow:
    inset 0 2px 5px rgba(0,0,0,0.40),
    inset 4px 0 0 rgb(var(--bc));
}
.btn.on .ico { color: var(--key-on-ink); }
.btn:disabled {
  opacity: 1; cursor: default;
  color: var(--dimmer);
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.10), rgba(0,0,0,0.10));
  border-left-color: var(--shell-lo);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 1px 0 var(--shell-deep);
}
.btn:disabled .ico { color: var(--dimmer); }
.btn.wide { grid-column: 1 / -1; }
.btn small { display: block; font-size: 8px; color: var(--dim); letter-spacing: 0.05em; font-weight: 600; }
.btn.on small { color: var(--key-on-ink); opacity: 0.75; }

/* categories */
.btn.mv { --bc: 23,121,111; }        /* movement    — field green  */
.btn.df { --bc: 47,93,134; }         /* defensive   — slate blue   */
.btn.tg { --bc: 168,121,15; }        /* toggle      — amber paint  */
.btn.go2{ --bc: 74,122,60; }         /* affirmative — olive        */
.btn.danger { --bc: 163,49,36; }     /* destructive — oxide red    */
.btn.neutral{ --bc: 109,101,83; }

/* the fire toggle flips colour with its state */
.btn.fire-on  { --bc: 74,122,60; }
.btn.fire-off { --bc: 163,49,36; }

/* soldier silhouettes */
/* The photo: a grey silhouette on a darker grey card, framed in the colour of
   the fireteam the man belongs to. The frame is the only colour on it — the
   figure itself never takes the team tint, so a roster reads as nine ID cards
   rather than nine coloured blobs. */
.avatar {
  display: block; width: 30px; height: 30px;
  border-radius: 2px;
  border: 2px solid var(--shell-lo);
  background: #3a3a38;
  /* dark rebate around the card so the coloured frame reads against tan */
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(0,0,0,0.45);
}
.avatar.ft-teal   { border-color: var(--teal-bright); }
.avatar.ft-purple { border-color: var(--purple-bright); }
.avatar.ft-sl     { border-color: #c9a227; }        /* squad leader: gold */
.avatar.ft-none   { border-color: var(--shell-lo); }
.avatar.sm { width: 26px; height: 26px; }
.glyph { display: block; width: 16px; height: 16px; }

.slot-av { display: flex; align-items: center; gap: 8px; }
.slot-av .avatar { width: 34px; height: 34px; }

/* ------------------------------------------------------------- bottom bar */

#bottombar {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 29;
  background-color: var(--shell);
  border-top: 1px solid var(--shell-hi);
  box-shadow: 0 -3px 10px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.34);
  display: flex; align-items: stretch; gap: 1px;
  height: 58px;
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(58px + env(safe-area-inset-bottom));
}
@media (max-width: 899px) { #bottombar { bottom: 46px; } }

.bb { display: flex; flex-direction: column; justify-content: center; padding: 5px 8px; gap: 3px; }
.bb-label { font-size: 8px; letter-spacing: 0.16em; color: var(--dim); text-transform: uppercase; font-weight: 700; text-shadow: 0 1px 0 rgba(255,255,255,0.10); }
.bb-value { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
#bbReinforce { flex: 1.1; min-width: 0; }
#bbSupply { flex: 1.1; min-width: 0; border-left: 1px solid var(--shell-deep); box-shadow: inset 1px 0 0 rgba(255,255,255,0.26); }
#bbSpawn { border-left: 1px solid var(--shell-deep); border-right: 1px solid var(--shell-deep); box-shadow: inset 1px 0 0 rgba(255,255,255,0.26), inset -1px 0 0 rgba(255,255,255,0.26); }
#bbStatus { flex: 1; min-width: 0; border-right: 1px solid var(--shell-deep); }

.seg {
  display: flex; gap: 0; border: 1px solid var(--shell-deep); border-radius: 3px;
  overflow: hidden; background: var(--well);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.28);
}
.seg button {
  font-family: inherit; font-size: 9px; letter-spacing: 0.1em; font-weight: 700;
  background: transparent; border: none; color: var(--screen-dim);
  padding: 6px 9px; cursor: pointer;
}
/* the selected side is the raised key */
.seg button.on {
  background-color: var(--shell);
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.22), rgba(0,0,0,0.08));
  color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4);
}
.seg button:disabled { opacity: 0.4; }

.bigbtn {
  font-family: inherit; font-size: 10px; letter-spacing: 0.1em; font-weight: 700;
  background-color: var(--shell);
  border: 1px solid var(--shell-deep);
  border-left: 4px solid var(--green);
  color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  border-radius: 3px; padding: 8px 10px; cursor: pointer; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.45),
    0 2px 0 var(--shell-deep), 0 3px 4px rgba(0,0,0,0.35);
}
.bigbtn:active { transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(0,0,0,0.34); }
.bigbtn:disabled {
  color: var(--dimmer); border-left-color: var(--shell-lo);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 1px 0 var(--shell-deep);
}
.bigbtn.waiting { border-left-color: var(--blue); background-image: var(--grain), linear-gradient(180deg, rgba(0,0,0,0.12), rgba(255,255,255,0.10)); }
/* supply sits next to reinforcements — amber so the two never get mixed up */
.bigbtn.alt { border-left-color: var(--yellow); }
.bigbtn.alt.waiting { border-left-color: var(--blue); }

.chip { font-size: 9px; letter-spacing: 0.07em; padding: 2px 6px; border-radius: 3px; }
.chip {
  background: var(--well) !important;
  color: var(--screen-text);
  border: 1px solid var(--well-lo);
  border-radius: 2px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.55), 0 1px 0 rgba(255,255,255,0.28);
  text-shadow: none;
}
.chip.ok { color: #9ec48a; }
.chip.warn { color: #d8b45a; }
.chip.bad { color: #dd8b7f; }
.chip.sup { color: #9dbbd8; }

/* ------------------------------------------------------------------ tabs */

#tabs {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 31;
  height: calc(46px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background-color: var(--shell-lo);
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.12), rgba(0,0,0,0.14));
  border-top: 1px solid var(--shell-hi);
  display: none;
}
/* Declared here, after the base rule, so source order can't flip it back. */
@media (max-width: 899px) { #tabs { display: flex; } }
#tabs button {
  flex: 1; background: transparent; border: none; color: var(--dim);
  font-family: inherit; font-size: 9.5px; letter-spacing: 0.13em; font-weight: 700;
  cursor: pointer; padding: 0;
  text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  border-right: 1px solid rgba(0,0,0,0.16);
}
#tabs button:last-child { border-right: none; }
#tabs button.on {
  color: var(--text);
  background-color: var(--shell);
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.24), rgba(0,0,0,0.06));
  box-shadow: inset 0 2px 0 var(--yellow), inset 0 -2px 4px rgba(0,0,0,0.14);
}

/* --------------------------------------------------------------- overlays */

.overlay {
  position: absolute; inset: 0; z-index: 60;
  background-color: var(--shell);
  color: var(--text);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.overlay.hidden { display: none; }

.ov-head {
  padding: 12px 16px 10px;
  background-color: var(--shell);
  border-bottom: 1px solid var(--shell-deep);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.34);
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.ov-title { font-size: 17px; font-weight: 800; letter-spacing: 0.24em; color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.12); }
.ov-sub { font-size: 10px; letter-spacing: 0.14em; color: var(--dim); text-shadow: 0 1px 0 rgba(255,255,255,0.10); }
.ov-body { flex: 1; overflow-y: auto; padding: 12px 16px; touch-action: pan-y; }
.ov-foot {
  padding: 10px 16px;
  background-color: var(--shell);
  border-top: 1px solid var(--shell-hi);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

.card {
  border: 1px solid var(--shell-deep); border-radius: 3px;
  background: var(--shell-lo); padding: 11px; margin-bottom: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.24), 0 1px 0 rgba(255,255,255,0.2);
}
.card h3 {
  margin: 0 0 8px; font-size: 10px; letter-spacing: 0.2em;
  color: var(--text); text-transform: uppercase; font-weight: 700;
  text-shadow: 0 1px 0 rgba(255,255,255,0.10);
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Body copy was too small and too dim to read on a phone in daylight. */
.hint { font-size: 12px; color: var(--dim); line-height: 1.6; }
.err { color: #dd8b7f; font-size: 12px; line-height: 1.7; }
.ov-body .hint { font-size: 12.5px; }
.ov-body .card { background: var(--shell-lo); border-color: var(--shell-deep); }
.ov-title { font-size: 18px; }
.ov-sub { font-size: 11px; color: var(--dim); }

/* slot editor */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 6px; }
.slot {
  border: 1px solid var(--shell-deep); border-radius: 3px; padding: 7px;
  background: var(--shell-lo); cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.26), 0 1px 0 rgba(255,255,255,0.2);
}
.slot.sel { border-color: var(--yellow); background: var(--shell-hi); }
.slot.fixed { opacity: 0.92; cursor: default; }
.slot-top { display: flex; justify-content: space-between; align-items: center; gap: 5px; }
.slot-num { font-size: 9px; color: var(--dimmer); letter-spacing: 0.12em; font-weight: 700; text-shadow: 0 1px 0 rgba(255,255,255,0.10); }
.slot-kit { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; margin-top: 2px; color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.10); }
/* The slot's team tag: a painted tab, colour-filled, dark ink on it. */
.slot-ft {
  font-size: 8.5px; letter-spacing: 0.1em; padding: 1px 5px; border-radius: 2px;
  font-weight: 700;
  background: var(--teal-bright); color: #06231f;
}
.slot-ft.purple { background: var(--purple-bright); color: #1d0b30; }
.slot-ft.sl { background: #c9a227; color: #23190a; }
.slot-lead {
  font-size: 8px; letter-spacing: 0.1em; font-weight: 700;
  color: #3d2c05; background: #c9a227;
  display: inline-block; padding: 1px 4px; border-radius: 2px; margin-top: 3px;
}

.kitlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 6px; }
.kit {
  border: 1px solid var(--line); border-radius: 5px; padding: 8px;
  background: var(--well-hi); cursor: pointer; text-align: left;
  font-family: inherit; color: var(--text);
}
.kit:disabled { opacity: 0.3; cursor: default; }
.kit.on { border-color: var(--yellow); background: var(--shell-hi); }
.kit-name { font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; }
.kit-desc { font-size: 9px; color: var(--dim); line-height: 1.45; margin-top: 3px; }
.kit-lim { font-size: 8px; color: var(--orange); letter-spacing: 0.06em; margin-top: 3px; }

.pill {
  font-family: inherit; font-size: 9.5px; letter-spacing: 0.08em; font-weight: 700;
  background-color: var(--shell);
  border: 1px solid var(--shell-deep); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 2px 0 var(--shell-deep);
  color: var(--text); border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.pill.on { background: var(--shell); border-color: var(--yellow); color: var(--text); text-shadow: 0 1px 0 rgba(255,255,255,0.10); box-shadow: inset 0 1px 0 rgba(255,255,255,0.4); }

/* The commit key. Bigger travel than the others, and it is the one place a
   solid painted face is warranted — you should be able to find it blind. */
.go {
  font-family: inherit; font-size: 12px; letter-spacing: 0.16em; font-weight: 800;
  background-color: #6f8f4e;
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.28), rgba(0,0,0,0.14));
  border: 1px solid #46602f; color: #101a08;
  text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  border-radius: 3px; padding: 12px 20px; cursor: pointer; flex: 1;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.5),
    0 3px 0 #46602f, 0 4px 6px rgba(0,0,0,0.4);
}
.go:active { transform: translateY(3px); box-shadow: inset 0 2px 5px rgba(0,0,0,0.4); }
.go:disabled {
  background-color: var(--shell-lo); border-color: var(--shell-deep);
  color: var(--dimmer); text-shadow: 0 1px 0 rgba(255,255,255,0.10);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), 0 2px 0 var(--shell-deep);
}
.ghostbtn {
  font-family: inherit; font-size: 10px; letter-spacing: 0.1em; font-weight: 700;
  background-color: var(--shell);
  border: 1px solid var(--shell-deep); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 2px 0 var(--shell-deep);
  border-radius: 3px; padding: 12px 14px; cursor: pointer;
}
.ghostbtn:active { transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(0,0,0,0.34); }

.result-stat { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 11px; }
.result-stat span:last-child { font-weight: 700; }

/* staging map preview sits behind the overlay, so let clicks reach it */
.overlay.transparent { background: linear-gradient(180deg, rgba(3,5,9,0.96) 0%, rgba(3,5,9,0.72) 42%, rgba(3,5,9,0.2) 100%); }
.overlay.placing { pointer-events: none; background: none; }
.overlay.placing .ov-foot { pointer-events: auto; }
.overlay.placing .ov-head { pointer-events: auto; background: rgba(3,5,9,0.9); }

/* "Peek": get the staging panel out of the way so the player can actually look
   at the ground they're about to defend before deciding to reroll it. */
.overlay.peek { background: none; pointer-events: none; }
.overlay.peek .ov-body { display: none; }
.overlay.peek .ov-head,
.overlay.peek .ov-foot {
  pointer-events: auto;
  background: rgba(3,5,9,0.92);
  border-color: var(--line);
}
.overlay.peek .ov-foot { margin-top: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 9.5px; letter-spacing: 0.08em; color: var(--dim); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.teal { background: var(--teal); }
.dot.purple { background: var(--purple); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-radius: 2px; }

/* ------------------------------------------------------- dev build ribbon */
/* The deploy script stamps <body class="env-dev"> on the dev copy so there is
   never any doubt which build is on screen. */
body.env-dev::after {
  content: 'DEV BUILD';
  position: fixed; z-index: 200;
  right: -34px; top: 16px;
  transform: rotate(45deg);
  background: #b45309; color: #fff;
  font-size: 9px; font-weight: 800; letter-spacing: 0.18em;
  padding: 4px 40px;
  pointer-events: none;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* ------------------------------------------------- casualty / order polish */
.cas {
  border: 1px solid rgba(239,68,68,0.34);
  background: rgba(239,68,68,0.07);
  border-radius: 6px; padding: 7px; margin-bottom: 6px;
}
.cas-head {
  display: flex; align-items: center; gap: 7px; margin-bottom: 6px;
}
.cas-head .avatar { width: 26px; height: 26px; }
.cas-name { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; }
.cas-timer { margin-left: auto; font-size: 11px; font-weight: 700; color: #ff9a9a; }
.cas-note { font-size: 10px; color: #cbb; letter-spacing: 0.05em; }

/* the targeting banner needs to read as "armed", not as a tooltip */
#targeting {
  border-color: var(--yellow);
  box-shadow: 0 0 0 1px rgba(168,121,15,0.35), 0 8px 28px rgba(0,0,0,0.7);
  animation: armed 1.6s ease-in-out infinite;
}
@keyframes armed {
  0%,100% { box-shadow: 0 0 0 1px rgba(168,121,15,0.35), 0 8px 28px rgba(0,0,0,0.7); }
  50%     { box-shadow: 0 0 0 3px rgba(168,121,15,0.28), 0 8px 28px rgba(0,0,0,0.7); }
}
#targetingText { font-size: 11.5px; }

/* fireteam selector chips at the top of the orders panel */
.ftpick { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 10px; }
.ftpick button {
  font-family: inherit; font-weight: 800; font-size: 11px; letter-spacing: 0.12em;
  padding: 9px 6px; border-radius: 5px; cursor: pointer;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(148,163,184,0.3);
  color: #cfe0ee;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ftpick button .avatar { width: 22px; height: 22px; }
.ftpick button.on { color: #fff; }
.ftpick button.on.teal { background: var(--shell); border-color: var(--teal-bright); box-shadow: inset 0 -3px 0 var(--teal-bright); color: var(--text); }
.ftpick button.on.purple { background: var(--shell); border-color: var(--purple-bright); box-shadow: inset 0 -3px 0 var(--purple-bright); color: var(--text); }
.ftpick .cnt { font-size: 9px; opacity: 0.85; font-weight: 600; }

/* ------------------------------------------------------ squad leader block */
/* The SL is the only soldier who can place a rally — the gold frame makes that
   section unmistakable at a glance. */
.sl-block {
  border: 1px solid rgba(234,179,8,0.55);
  border-radius: 7px;
  padding: 4px 4px 2px;
  margin: 2px 0 9px;
  background: linear-gradient(180deg, rgba(234,179,8,0.11), rgba(234,179,8,0.03));
  box-shadow: inset 0 0 12px rgba(234,179,8,0.08);
}
.sl-block .ft-head {
  border-left-color: var(--yellow);
  background: rgba(234,179,8,0.13);
  margin: 0 0 4px;
}
.sl-block .ft-name { color: var(--yellow); }
.sl-block .sold { background: rgba(234,179,8,0.05); }

/* SL attach buttons carry their fireteam's colour: lit when selected, a dark
   tint of the same colour when not. */
.btn.ftteal   { --bc: 23,121,111; }
.btn.ftpurple { --bc: 107,63,158; }

/* -------------------------------------------------- drag between fireteams */
.ftgroup { border-radius: 7px; padding: 1px; transition: background 0.12s; }
.ftgroup.drop { background: rgba(255,255,255,0.09); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35); }
.sold.dragging { opacity: 0.5; outline: 1px dashed rgba(255,255,255,0.6); }
.sold { touch-action: pan-y; }
.draghint { font-size: 9.5px; color: var(--dimmer); letter-spacing: 0.06em; margin: 2px 0 6px 2px; }

/* --------------------------------------------------------- inline kit pick */
.kitpick {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 2px 0 8px; padding: 6px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--shell-lo);
}
.kitpick .kb {
  font-family: inherit; font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em;
  padding: 7px 4px; border-radius: 4px; cursor: pointer;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(148,163,184,0.3);
  color: #dbe8f2; text-align: center;
}
.kitpick .kb.on { background: var(--shell); border-color: var(--yellow); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,0.4); }
.kitpick .kb:disabled { opacity: 0.28; cursor: default; }
.kitpick .note { grid-column: 1/-1; font-size: 10px; color: var(--dim); line-height: 1.5; }
.tag-kit { background: rgba(59,130,246,0.22); color: #a9caff; }

/* ----------------------------------------------------- role popover ------ */
/* Picking a kit used to render a card further down the staging list, which
   meant scrolling away from the soldier you just tapped. This puts the choices
   directly over the man. */
.rolepop-back {
  position: fixed; inset: 0; z-index: 89;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(2px);
}
.rolepop {
  position: fixed; z-index: 90;
  width: min(340px, 94vw);
  /* Reads as a separate moulded part sitting proud of the panel behind it. */
  background-color: var(--shell);
  background-image: var(--grain), linear-gradient(180deg, rgba(255,255,255,0.14), rgba(0,0,0,0.08));
  color: var(--text);
  border: 1px solid var(--shell-deep);
  border-radius: 9px;
  padding: 10px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.9), 0 0 0 1px rgba(0,0,0,0.6);
  max-height: 86vh; overflow-y: auto; overscroll-behavior: contain;
  animation: popIn 0.12s ease-out;
}
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.rolepop-head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.rolepop-head .avatar { width: 40px; height: 40px; flex: 0 0 auto; }
.rolepop-title { font-size: 12px; font-weight: 800; letter-spacing: 0.05em; }
.rolepop-sub { font-size: 9.5px; color: var(--dim); letter-spacing: 0.08em; }
.rolepop-x {
  margin-left: auto; background: rgba(255,255,255,0.06);
  border: 1px solid var(--line); color: var(--text);
  width: 28px; height: 28px; border-radius: 5px; cursor: pointer;
  font-family: inherit; font-size: 13px; line-height: 1;
}
.rolepop-row { display: flex; gap: 5px; margin-bottom: 8px; flex-wrap: wrap; }
.rolepop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.rolepop-grid .kb {
  font-family: inherit; font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  padding: 9px 4px; border-radius: 5px; cursor: pointer;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(148,163,184,0.3);
  color: #dbe8f2; text-align: center; line-height: 1.2;
}
.rolepop-grid .kb small { display: block; font-size: 8px; color: var(--dimmer); font-weight: 500; }
.rolepop-grid .kb.on { background: var(--shell); border-color: var(--yellow); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,0.4); }
.rolepop-grid .kb:disabled { opacity: 0.26; cursor: default; }
.rolepop-note { font-size: 10.5px; color: var(--dim); line-height: 1.5; margin-top: 8px; }

/* THE GRAIN, PART TWO.
   Every surface that layers var(--grain) must also blend it, or the noise
   renders as raw grey and the part looks like unpainted styrofoam. One rule
   for the whole set, so adding a grained component can't forget it. */
.plastic, .panel, #topbar, #bottombar, #tabs, #tabs button.on,
.overlay, .rolepop, .ov-head, .ov-foot,
.btn, .btn.on, .btn:disabled, .bigbtn, .bigbtn.waiting,
.iconbtn, .iconbtn.on, .ghostbtn, .go,
.card, .slot, .kit, .sold, .ft-head, .seg button.on {
  background-blend-mode: overlay;
  background-size: 120px 120px, auto, auto, auto;
}
