/* =====================================================================
   COMBAT TRACKER — a full-screen board with a floating HUD: controls
   along the top, the turn order down the left, the selected character's
   card on the right, and the setup tools in a drawer that slides out.
   Dark glass, gold accents, drop-shadowed text. Names and headings use
   the atlas's medieval lettering; numbers and small text a clean sans.
   ===================================================================== */
.cb-overlay {
  --cb-text: #f3ead8;
  --cb-muted: rgba(243, 234, 216, .62);
  --cb-faint: rgba(243, 234, 216, .38);
  --cb-gold: #f0d27a;
  --cb-gold-deep: #c89b3c;
  --cb-red: #e2574c;
  --cb-blue: #5fb4ff;
  --cb-glass: rgba(20, 15, 11, .58);
  --cb-glass-strong: rgba(24, 18, 13, .94);
  --cb-line: rgba(255, 255, 255, .09);
  --cb-hover: rgba(255, 255, 255, .08);
  --cb-shadow: 0 2px 6px rgba(0, 0, 0, .85), 0 0 1px rgba(0, 0, 0, .9);
  --cb-font-title: "IM Fell English SC", Georgia, serif;
  --cb-font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bar-h: 62px;
  --left-w: 250px;
  --right-w: 350px;

  position: fixed;
  inset: 0;
  z-index: 60;
  color-scheme: dark;
  font-family: var(--cb-font-ui);
  font-size: 15px;
  color: var(--cb-text);
  background: #0c0907;
}
.cb-overlay[hidden], .cb-overlay [hidden] { display: none !important; }
.cb-overlay *, .cb-overlay *::before, .cb-overlay *::after { box-sizing: border-box; }

.cb-window {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, #2c2118 0%, #17110c 58%, #0a0705 100%);
}
.cb-body { position: absolute; inset: 0; }

/* Shared: glass panels and floating text */
.cb-drawer, .cb-card, .cb-battles-menu, .cb-form, .cb-ask-box {
  background: var(--cb-glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  border-radius: 16px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .5);
}
.cb-overlay h2, .cb-overlay h3, .cb-overlay h4, .cb-round, .cb-turn, .cb-hint, .cb-cols, .cb-rows { text-shadow: var(--cb-shadow); }

/* ---------- Top bar ---------- */
.cb-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  min-height: var(--bar-h);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  padding: 10px 16px;
  background: linear-gradient(rgba(6, 4, 3, .82), rgba(6, 4, 3, 0));
  pointer-events: none;
}
.cb-bar > * { pointer-events: auto; }
.cb-bar-title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.cb-title {
  margin: 0;
  font-family: var(--cb-font-title);
  font-weight: normal;
  font-size: 1.6rem;
  color: var(--cb-gold);
  white-space: nowrap;
}
.cb-round { font-size: .9rem; color: var(--cb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-bar-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-left: auto; }

/* ---------- Buttons: words, not boxes ---------- */
.cb-btn {
  font: 600 .9rem/1.2 var(--cb-font-ui);
  padding: .5em .85em;
  cursor: pointer;
  color: var(--cb-text);
  text-shadow: var(--cb-shadow);
  border: 0;
  border-radius: 999px;
  background: transparent;
  transition: background .15s, color .15s, transform .1s;
}
.cb-btn:hover { background: var(--cb-hover); }
.cb-btn:active { transform: translateY(1px); }
.cb-btn:focus-visible { outline: 2px solid var(--cb-gold); outline-offset: 1px; }
.cb-btn.on, .cb-maptoggle.on { color: var(--cb-gold); background: rgba(240, 210, 122, .14); }
.cb-btn-gold {
  color: #2a1a08;
  text-shadow: none;
  background: linear-gradient(180deg, #f6dd92, var(--cb-gold-deep));
  box-shadow: 0 4px 16px rgba(200, 155, 60, .35);
}
.cb-btn-gold:hover { background: linear-gradient(180deg, #fbe6a8, #d4a84a); }
.cb-btn-soft { background: rgba(255, 255, 255, .08); }
.cb-danger { color: #ff8c80; }
.cb-heal { color: #8fe39b; }
.cb-link-btn { padding-left: .2em; padding-right: .2em; color: var(--cb-gold); font-weight: 500; }
.cb-link-btn:hover { background: none; color: #fff; }
.cb-close { font-size: 1rem; }
/* On its own page combat can't be closed, unless it has somewhere to go
   back to (the 3D page's "← Atlas"). */
.cb-standalone:not(.cb-can-exit) .cb-close { display: none; }
.cb-can-exit .cb-close { color: var(--cb-gold); font-size: .9rem; }

/* Grid size: a quiet row of numbers */
.cb-sizes { display: inline-flex; margin-right: 6px; }
.cb-size { padding: .5em .55em; font-weight: 500; color: var(--cb-muted); font-variant-numeric: tabular-nums; }
.cb-size.on { color: var(--cb-gold); background: none; text-decoration: underline 2px; text-underline-offset: 6px; }

/* Preset battles dropdown */
.cb-battles { position: relative; }
.cb-battles-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 8;
  width: min(330px, 90vw);
  padding: 10px;
  background: var(--cb-glass-strong);
}
.cb-battles-list { display: grid; gap: 2px; max-height: 55vh; overflow-y: auto; }
.cb-battles-chapter {
  margin: 10px 8px 4px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--cb-gold);
}
.cb-battles-chapter:first-child { margin-top: 2px; }
.cb-battle {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--cb-text);
  border: 0;
  border-radius: 10px;
  background: transparent;
}
.cb-battle:hover, .cb-battle:focus-visible { background: var(--cb-hover); outline: none; }
.cb-battle strong { font-family: var(--cb-font-title); font-weight: normal; font-size: 1.1rem; }
.cb-battle small { font-size: .78rem; color: var(--cb-muted); }
.cb-battles-menu .cb-btn { width: 100%; margin-top: 6px; }
.cb-battles-menu .cb-battles-back { width: auto; margin: 0 0 2px; text-align: left; }
.cb-copy-msg { margin: 0 0 8px; font-size: .95rem; }
.cb-layout-text { width: 100%; font-family: ui-monospace, Consolas, monospace !important; font-size: .8rem !important; white-space: pre; }

/* ---------- Fields ---------- */
.cb-overlay input, .cb-overlay select, .cb-overlay textarea {
  font: inherit;
  color: var(--cb-text);
  background: rgba(255, 255, 255, .07);
  border: 0;
  border-radius: 8px;
  padding: .38em .55em;
}
.cb-overlay input:focus, .cb-overlay select:focus, .cb-overlay textarea:focus { outline: 2px solid rgba(240, 210, 122, .55); background: rgba(255, 255, 255, .11); }
.cb-overlay select option { color: #f3ead8; background: #1c1510; }
.cb-overlay input::placeholder, .cb-overlay textarea::placeholder { color: var(--cb-faint); }
.cb-row { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.cb-row select { flex: 1; min-width: 0; }
.cb-grow { flex: 1; }
.cb-wide { width: 100%; margin-top: 6px; }
.cb-count { width: 3.4em; text-align: center; }
.cb-empty, .cb-note { font-style: italic; color: var(--cb-muted); font-size: .88rem; }
.cb-mini {
  font: 600 .95rem/1 var(--cb-font-ui);
  width: 1.8em;
  height: 1.8em;
  cursor: pointer;
  color: var(--cb-text);
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.cb-mini:hover { background: var(--cb-hover); color: var(--cb-gold); }

/* Section headings: small, spaced capitals */
.cb-overlay h3, .cb-overlay h4 { margin: 0 0 8px; font-weight: 600; }
.cb-side h3, .cb-drawer h4, .cb-sheet-sec h4 {
  font-family: var(--cb-font-ui);
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--cb-gold);
}

/* ---------- The board ---------- */
.cb-map {
  position: absolute;
  top: var(--bar-h);
  right: var(--right-w);
  bottom: 0;
  left: var(--left-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px 12px;
}
.cb-board {
  --lab: 22px;
  width: min(100%, calc(100vh - var(--bar-h) - 120px));
  display: grid;
  grid-template-columns: var(--lab) minmax(0, 1fr);
  grid-template-rows: var(--lab) auto;
}
.cb-cols, .cb-rows {
  display: grid;
  font-size: .72rem;
  font-weight: 600;
  color: var(--cb-faint);
  user-select: none;
}
.cb-cols { grid-template-columns: repeat(var(--n, 10), 1fr); align-items: end; padding-bottom: 4px; }
.cb-rows { grid-template-rows: repeat(var(--n, 10), 1fr); }
.cb-cols span, .cb-rows span { display: grid; place-items: center; }
.cb-rows span { justify-content: end; padding-right: 6px; }
.cb-grid {
  --cell: 28px;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--n, 10), 1fr);
  grid-template-rows: repeat(var(--n, 10), 1fr);
  border-radius: 10px;
  overflow: hidden;
  background-color: #241d16;
  background-size: cover;
  background-position: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(255, 255, 255, .06);
  touch-action: none;
  user-select: none;
}
.cb-cell { position: relative; box-shadow: inset -1px -1px 0 rgba(255, 255, 255, .06); }
.cb-cell:hover { background-color: rgba(255, 255, 255, .07); }
.cb-grid.has-map .cb-cell { box-shadow: inset -1px -1px 0 rgba(255, 245, 220, .14); }
.cb-grid.painting { cursor: crosshair; }
.cb-grid.painting .cb-token { opacity: .8; cursor: pointer; }
.cb-grid.painting .cb-cell:hover { outline: 2px solid var(--cb-gold); outline-offset: -2px; }

/* Under the board: Start (on the 3D page) and a hint */
.cb-foot { display: grid; gap: 8px; justify-items: center; max-width: 100%; }
.cb-foot .cb-view3d { padding: .75em 2.6em; font-size: 1.05rem; letter-spacing: .04em; pointer-events: auto; }
.cb-hint { margin: 0; font-size: .8rem; color: var(--cb-faint); text-align: center; }
.cb-coord { font-style: normal; font-size: .8em; color: var(--cb-faint); font-variant-numeric: tabular-nums; }

/* ---------- Turn order (left) ---------- */
.cb-side {
  position: absolute;
  top: calc(var(--bar-h) + 4px);
  left: 14px;
  z-index: 3;
  width: calc(var(--left-w) - 28px);
  max-height: calc(100% - var(--bar-h) - 80px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.cb-side h3 { padding-left: 8px; }
.cb-turns { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.cb-turn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 12px;
  transition: background .15s;
}
.cb-turn:hover { background: var(--cb-hover); }
.cb-turn.selected { background: rgba(255, 255, 255, .06); box-shadow: inset 2px 0 0 var(--cb-text); }
.cb-turn.current { background: linear-gradient(90deg, rgba(240, 210, 122, .26), rgba(240, 210, 122, 0)); box-shadow: inset 3px 0 0 var(--cb-gold); }
.cb-turn.current .cb-turn-name { color: var(--cb-gold); }
.cb-turn.down { opacity: .42; }
.cb-turn.down .cb-turn-name { text-decoration: line-through; }
.cb-init {
  width: 2.4em;
  padding: .1em .1em !important;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: transparent !important;
  color: var(--cb-muted) !important;
}
.cb-init:hover, .cb-init:focus { background: rgba(255, 255, 255, .08) !important; }
.cb-turn-icon, .cb-hero-icon {
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--tc);
  background: #f7ecd2;
  text-shadow: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.cb-turn-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--cb-font-title);
  font-size: 1.08rem;
}
.cb-turn-name em { font-family: var(--cb-font-ui); font-style: normal; font-size: .7rem; color: var(--cb-faint); }
.cb-turn-hp { font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; color: #8fe39b; }
.cb-turn-hp.hurt { color: #f1c35a; }
.cb-turn-hp.bad { color: #ff7a6e; }
.cb-turns .cb-empty { padding-left: 8px; }
.cb-turn-keys { margin: 10px 0 0 8px; font-size: .72rem; color: var(--cb-faint); text-shadow: var(--cb-shadow); }
/* End combat: out of the way, under the turn order */
.cb-end { margin: 4px 0 0 2px; padding: .4em .6em; font-size: .78rem; font-weight: 500; color: #ff8c80; }

/* ---------- Setup drawer (slides out from the left) ---------- */
.cb-drawer {
  position: absolute;
  top: calc(var(--bar-h) + 4px);
  bottom: 14px;
  left: 14px;
  z-index: 5;
  width: 310px;
  max-width: calc(100% - 28px);
  padding: 14px 16px 18px;
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--cb-glass-strong);
  transform: translateX(calc(-100% - 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform .28s ease, opacity .28s ease;
}
.cb-drawer-open .cb-drawer { transform: none; opacity: 1; pointer-events: auto; }
.cb-drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cb-drawer-head h3 { margin: 0; font-family: var(--cb-font-title); font-weight: normal; font-size: 1.4rem; color: var(--cb-gold); }
.cb-drawer section { padding: 12px 0; }
.cb-drawer section + section { border-top: 1px solid var(--cb-line); }
.cb-drawer h4 { margin-bottom: 4px; }
.cb-drawer-tab {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 4;
  background: rgba(20, 15, 11, .55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.cb-drawer-open .cb-drawer-tab { opacity: 0; pointer-events: none; }

/* Terrain tools, in three groups */
.cb-tool-group { margin: 10px 0 4px; font-size: .72rem; font-weight: 600; color: var(--cb-muted); }
.cb-tools { display: flex; flex-wrap: wrap; gap: 2px; }
.cb-tool { padding: .42em .7em; font-weight: 500; }
.cb-tool.on { color: #2a1a08; text-shadow: none; background: linear-gradient(180deg, #f6dd92, var(--cb-gold-deep)); }

/* Party list in the drawer */
.cb-party { display: grid; gap: 2px; }
.cb-hero { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 2px; border-radius: 10px; }
.cb-hero:hover { background: var(--cb-hover); }
.cb-hero-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--cb-font-title); font-size: 1.02rem; }
.cb-preset-mark { font-size: .75em; opacity: .6; }
.cb-hero .cb-note { font-size: .75rem; }

/* ---------- Character card (right) ---------- */
.cb-card {
  position: absolute;
  top: calc(var(--bar-h) + 4px);
  right: 14px;
  bottom: 14px;
  z-index: 3;
  width: calc(var(--right-w) - 28px);
  padding: 18px 18px 22px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.cb-card-empty { padding: 30px 10px; font-size: .92rem; line-height: 1.5; text-align: center; color: var(--cb-muted); }
.cb-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cb-card-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  flex: none;
  font-size: 30px;
  border-radius: 50%;
  border: 3px solid var(--tc);
  background: #f7ecd2;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, .25), 0 6px 18px rgba(0, 0, 0, .5);
}
.cb-card-head > div { min-width: 0; }
.cb-card-name {
  width: 100%;
  padding: 0 .1em !important;
  font-family: var(--cb-font-title) !important;
  font-size: 1.55rem !important;
  color: var(--cb-text);
  text-shadow: var(--cb-shadow);
  background: transparent !important;
}
.cb-card-name:hover { background: rgba(255, 255, 255, .06) !important; }
.cb-tag {
  display: inline-block;
  margin: 2px 6px 0 2px;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--cb-blue);
}
.cb-tag.enemy { color: var(--cb-red); }
.cb-subtitle { display: inline; font-style: italic; font-size: .85rem; color: var(--cb-muted); }

/* HP: big numbers and a thin bar */
.cb-hp-row { display: grid; gap: 8px; }
.cb-hpbar { order: 2; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.cb-hp-nums { display: flex; align-items: baseline; gap: 4px; font-size: .72rem; font-weight: 600; letter-spacing: .14em; color: var(--cb-muted); }
.cb-hp-nums input {
  width: 2.7em;
  padding: 0 .1em !important;
  font-size: 1.9rem !important;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  background: transparent !important;
}
.cb-hp-nums input:first-of-type { margin-left: 6px; color: #fff; }
.cb-hp-nums input:last-of-type { font-size: 1.2rem !important; color: var(--cb-muted); }
.cb-token-hp i, .cb-hpbar i { display: block; height: 100%; background: #5cc96b; border-radius: inherit; }
.cb-token-hp.hurt i, .cb-hpbar.hurt i { background: #e6b23a; }
.cb-token-hp.bad i, .cb-hpbar.bad i { background: #e2574c; }
.cb-amount { width: 6em; }

/* Stats: label above, number below, no boxes */
.cb-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 8px; margin-top: 16px; }
.cb-stat { display: grid; gap: 2px; font-size: .66rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--cb-muted); }
.cb-stat input, .cb-stat select { width: 100%; font-size: 1.05rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--cb-text); background: transparent; padding-left: 0; }
.cb-stat input:hover, .cb-stat select:hover { background: rgba(255, 255, 255, .06); }
.cb-stat-wide { grid-column: 1 / -1; }

/* Ability scores */
.cb-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; margin-top: 18px; text-align: center; }
.cb-ability { display: grid; justify-items: center; padding: 6px 0; border-radius: 10px; }
.cb-ability:hover { background: var(--cb-hover); }
.cb-ab-k { font-size: .64rem; font-weight: 700; letter-spacing: .1em; color: var(--cb-muted); }
.cb-ab-mod { font-size: 1.25rem; font-weight: 700; line-height: 1.2; color: var(--cb-gold); font-variant-numeric: tabular-nums; }
.cb-ab-score { font-size: .72rem; color: var(--cb-faint); font-variant-numeric: tabular-nums; }

/* Weapons & spells, traits */
.cb-sheet-sec { margin-top: 20px; }
.cb-attacks, .cb-traits { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: .86rem; line-height: 1.42; }
.cb-attacks li { display: flex; align-items: flex-start; gap: 8px; padding-left: 10px; box-shadow: inset 2px 0 0 rgba(226, 87, 76, .7); }
.cb-attacks strong { font-family: var(--cb-font-title); font-weight: normal; font-size: 1.02rem; color: var(--cb-gold); }
.cb-attacks li > span { flex: 1; min-width: 0; }
.cb-x {
  flex: none;
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  font: 600 1rem/1 var(--cb-font-ui);
  cursor: pointer;
  color: var(--cb-faint);
  border: 0;
  border-radius: 50%;
  background: none;
}
.cb-x:hover { color: #fff; background: rgba(226, 87, 76, .55); }
.cb-add-attack-row { margin-top: 10px; }
.cb-add-attack { flex: 1; min-width: 0; font-size: .86rem !important; }
.cb-keep { margin: 8px 0 0; font-size: .76rem; font-style: italic; color: var(--cb-faint); }
.cb-link { padding: 0; font: inherit; font-style: normal; cursor: pointer; color: var(--cb-gold); text-decoration: underline; border: 0; background: none; }
.cb-link:hover { color: #fff; }
.cb-traits li { position: relative; padding-left: 12px; color: rgba(243, 234, 216, .82); }
.cb-traits li::before { content: ""; position: absolute; left: 0; top: .62em; width: 4px; height: 4px; border-radius: 50%; background: var(--cb-gold-deep); }

/* Notes fold-out */
.cb-edit-notes { margin-top: 18px; font-size: .85rem; }
.cb-edit-notes summary { cursor: pointer; font-size: .72rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--cb-muted); }
.cb-edit-notes textarea { width: 100%; margin-top: 6px; resize: vertical; font-size: .88rem; }

/* Conditions */
.cb-conds { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 18px; }
.cb-cond {
  font: 500 .74rem var(--cb-font-ui);
  padding: .3em .65em;
  cursor: pointer;
  color: var(--cb-muted);
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
}
.cb-cond:hover { color: var(--cb-text); background: var(--cb-hover); }
.cb-cond.on { color: #fff; background: rgba(150, 90, 220, .55); box-shadow: 0 0 12px rgba(150, 90, 220, .45); }
.cb-card-actions { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 18px; align-items: center; }
.cb-card .cb-btn { font-size: .85rem; }

/* ---------- Tokens (the 2D grid) ---------- */
.cb-token {
  --span: 1;
  position: absolute;
  left: 6%;
  top: 6%;
  width: calc(var(--span) * 100% - 12%);
  height: calc(var(--span) * 100% - 12%);
  z-index: 2;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  border-radius: 50%;
  border: max(2px, calc(var(--cell) * (.07 + .02 * var(--span)))) solid var(--tc);
  background: #f7ecd2;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .55);
  transition: box-shadow .2s;
}
.cb-token-icon { font-size: calc(var(--cell) * .55 * var(--span)); line-height: 1; pointer-events: none; }
.cb-token-hp {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -14%;
  height: max(3px, calc(var(--cell) * .1));
  border-radius: 3px;
  background: rgba(0, 0, 0, .6);
  overflow: hidden;
  pointer-events: none;
}
.cb-badges { position: absolute; top: calc(var(--cell) * -.2); left: 50%; transform: translateX(-50%); z-index: 1; display: flex; gap: 1px; pointer-events: none; }
.cb-badge {
  display: grid;
  place-items: center;
  width: max(14px, calc(var(--cell) * .4));
  height: max(14px, calc(var(--cell) * .4));
  font-size: max(9px, calc(var(--cell) * .26));
  line-height: 1;
  border-radius: 50%;
  background: #f7ecd2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .7);
}
.cb-badge-more { font-weight: bold; font-size: max(8px, calc(var(--cell) * .2)); color: #2a1a08; background: var(--cb-gold); }
.cb-token.selected { box-shadow: 0 0 0 2px #fff, 0 4px 10px rgba(0, 0, 0, .55); }
.cb-token.current {
  z-index: 3;
  box-shadow: 0 0 0 3px var(--cb-gold), 0 0 16px 4px rgba(240, 210, 122, .85);
  animation: cb-pulse 1.6s ease-in-out infinite;
}
.cb-token.down { filter: grayscale(1) opacity(.5); }
.cb-token.dragging { z-index: 10; cursor: grabbing; transition: none; animation: none; }
@keyframes cb-pulse { 50% { box-shadow: 0 0 0 3px var(--cb-gold), 0 0 24px 8px rgba(240, 210, 122, .55); } }

/* ---------- Terrain: ground ---------- */
.cb-grass {
  background-color: #5f8f3a;
  background-image:
    radial-gradient(ellipse 12% 22% at 22% 78%, #86b84e 60%, transparent 62%),
    radial-gradient(ellipse 10% 20% at 62% 40%, #7fb04a 60%, transparent 62%),
    radial-gradient(ellipse 11% 21% at 80% 82%, #3f6b22 60%, transparent 62%),
    radial-gradient(ellipse 9% 18% at 38% 22%, #3f6b22 60%, transparent 62%),
    linear-gradient(150deg, rgba(255, 255, 210, .25), rgba(255, 255, 255, 0) 50%, rgba(0, 30, 0, .25));
}
.cb-ice {
  background-color: #cfe6f2;
  background-image:
    linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, .9) 47%, transparent 50%),
    linear-gradient(60deg, transparent 70%, rgba(120, 170, 200, .6) 71%, transparent 73%),
    linear-gradient(150deg, rgba(255, 255, 255, .5), rgba(80, 130, 170, .25));
}
.cb-wood {
  background-color: #8a5a2b;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 22%, #5a3a1a 22% 25%),
    linear-gradient(90deg, rgba(0, 0, 0, .12), rgba(255, 220, 170, .12) 50%, rgba(0, 0, 0, .12));
}
.cb-stone {
  background-color: #8d867a;
  background-image:
    linear-gradient(150deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .2)),
    radial-gradient(circle at 30% 30%, rgba(0, 0, 0, .12) 1px, transparent 2px);
  box-shadow: inset 0 0 0 2px rgba(40, 34, 28, .55);
}
.cb-water {
  background-color: #2a6f97;
  background-image:
    radial-gradient(ellipse 40% 10% at 30% 30%, rgba(255, 255, 255, .28) 60%, transparent 62%),
    radial-gradient(ellipse 35% 9% at 70% 70%, rgba(255, 255, 255, .22) 60%, transparent 62%),
    linear-gradient(160deg, rgba(255, 255, 255, .15), rgba(0, 20, 50, .3));
}

/* ---------- Terrain: walls (raised, so they read as solid) ---------- */
.cb-wall, .cb-icewall, .cb-woodwall, .cb-housewood, .cb-housestone,
.cb-wall2, .cb-icewall2, .cb-woodwall2, .cb-housewood2, .cb-housestone2 { z-index: 1; }
/* Houses, seen from above: a tiled roof (red-brown for wood, slate for stone) */
.cb-housewood, .cb-housewood2 {
  background-color: #8a3b26;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 20%, rgba(40, 12, 6, .55) 20% 24%),
    repeating-linear-gradient(90deg, transparent 0 18%, rgba(40, 12, 6, .25) 18% 20%),
    linear-gradient(150deg, rgba(255, 210, 170, .3), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .3));
  box-shadow: inset 0 0 0 2px #5a3a1a, 0 3px 8px rgba(0, 0, 0, .7);
}
.cb-housestone, .cb-housestone2 {
  background-color: #59606a;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 20%, rgba(15, 18, 24, .55) 20% 24%),
    repeating-linear-gradient(90deg, transparent 0 18%, rgba(15, 18, 24, .25) 18% 20%),
    linear-gradient(150deg, rgba(220, 230, 255, .28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .3));
  box-shadow: inset 0 0 0 2px #8d867a, 0 3px 8px rgba(0, 0, 0, .7);
}
/* Twice as high: the same look as the wall, a heavier shadow, and a small 2× mark */
.cb-wall2, .cb-icewall2, .cb-woodwall2, .cb-housewood2, .cb-housestone2 { filter: brightness(.88); }
.cb-wall2::before, .cb-icewall2::before, .cb-woodwall2::before, .cb-housewood2::before, .cb-housestone2::before {
  content: "2×";
  position: absolute;
  top: 2px;
  right: 3px;
  font: 700 max(8px, calc(var(--cell, 28px) * .24))/1 var(--cb-font-ui);
  color: #fff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.cb-tall-toggle { border: 1px dashed rgba(240, 210, 122, .4); }
.cb-woodwall, .cb-woodwall2 {
  background-color: #6e4524;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 22%, #3b2410 22% 25%),
    linear-gradient(150deg, rgba(255, 220, 170, .28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .35));
  box-shadow: inset 2px 2px 0 rgba(255, 220, 170, .25), inset -3px -3px 0 rgba(0, 0, 0, .45), 0 3px 8px rgba(0, 0, 0, .7);
}
.cb-wall, .cb-wall2 {
  background-color: #6e675d;
  background-image:
    radial-gradient(ellipse 22% 18% at 25% 28%, #a39b8c 70%, transparent 74%),
    radial-gradient(ellipse 20% 17% at 70% 22%, #968e80 70%, transparent 74%),
    radial-gradient(ellipse 22% 18% at 48% 62%, #aba394 70%, transparent 74%),
    radial-gradient(ellipse 18% 16% at 15% 80%, #8f8779 70%, transparent 74%),
    radial-gradient(ellipse 20% 17% at 82% 76%, #a0988a 70%, transparent 74%),
    linear-gradient(150deg, rgba(255, 255, 255, .3), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .3));
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .25), inset -3px -3px 0 rgba(0, 0, 0, .4), 0 3px 8px rgba(0, 0, 0, .7);
}
.cb-icewall, .cb-icewall2 {
  background-color: #8fd0ee;
  background-image:
    linear-gradient(135deg, rgba(255, 255, 255, .85) 0 8%, transparent 9% 52%, rgba(255, 255, 255, .5) 53% 56%, transparent 57%),
    linear-gradient(150deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 45%, rgba(20, 90, 140, .35));
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .6), inset -3px -3px 0 rgba(20, 80, 130, .45), 0 3px 8px rgba(0, 0, 0, .6);
}

/* ---------- Terrain: hazards that replace the ground ---------- */
.cb-void {
  background: radial-gradient(circle at 50% 50%, #000 0%, #0d0619 45%, #2a1148 80%, #4b2380 100%);
  box-shadow: inset 0 0 calc(var(--cell, 28px) * .3) rgba(160, 110, 255, .55);
}
.cb-drop {
  background: linear-gradient(180deg, #2e3a46 0%, #07090c 100%);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .18);
}

/* ---------- Terrain: hazards on top of the ground (drawn over it) ---------- */
[class*="cb-o-"]::after { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.cb-o-fire::after {
  background:
    radial-gradient(ellipse 30% 42% at 50% 62%, #fff3b0 0%, rgba(255, 210, 70, .95) 35%, transparent 70%),
    radial-gradient(ellipse 46% 56% at 50% 60%, rgba(255, 120, 30, .95) 0%, rgba(220, 60, 20, .75) 45%, transparent 75%);
  animation: cb-flicker 1.1s ease-in-out infinite alternate;
}
@keyframes cb-flicker { from { transform: scale(.94) translateY(2%); opacity: .9; } to { transform: scale(1.04) translateY(-2%); opacity: 1; } }
.cb-o-tree::after {
  background:
    radial-gradient(circle at 40% 36%, #7fb04a 0 14%, transparent 15%),
    radial-gradient(circle at 50% 50%, #2f6a2a 0 40%, #1d4a1c 44%, transparent 46%),
    radial-gradient(circle at 56% 58%, rgba(0, 0, 0, .45) 0 44%, transparent 50%);
}
.cb-o-boat::after {
  inset: 8% 4%;
  border-radius: 6px;
  background: repeating-linear-gradient(0deg, #8a5a2b 0 30%, #5a3a1a 30% 34%);
  box-shadow: inset 0 0 0 2px #3d2610, 0 2px 4px rgba(0, 0, 0, .5);
}
/* The captain's boat: blue planks with a gold rail, a little bigger */
.cb-o-captainboat::after {
  inset: 2%;
  border-radius: 7px;
  background: repeating-linear-gradient(0deg, #3f74b8 0 30%, #24467a 30% 34%);
  box-shadow: inset 0 0 0 2px #d4a531, inset 0 0 0 4px #1a3358, 0 3px 6px rgba(0, 0, 0, .55);
}
.cb-o-reeds::after {
  background:
    linear-gradient(80deg, transparent 18%, #9aab45 18%, #9aab45 22%, transparent 22%),
    linear-gradient(95deg, transparent 40%, #6f8a2e 40%, #6f8a2e 44%, transparent 44%),
    linear-gradient(85deg, transparent 62%, #b0bf55 62%, #b0bf55 66%, transparent 66%),
    linear-gradient(100deg, transparent 82%, #6f8a2e 82%, #6f8a2e 86%, transparent 86%);
}
.cb-grid .cb-cell:hover { filter: brightness(1.12); }

/* ---------- 3D view (only on the combat3d page): the stage fills the window ---------- */
.cb-stage3d { display: none; }
.cb-in-3d .cb-board, .cb-in-3d .cb-setup-only { display: none; }
.cb-in-3d .cb-map { inset: 0; padding: 0; }
.cb-in-3d .cb-stage3d { display: block; position: absolute; inset: 0; }
/* The square outlines show where a piece can go, so no hint text in 3D. */
.cb-in-3d .cb-hint { display: none; }
.cb-in-3d .cb-foot {
  position: absolute;
  left: var(--left-w);
  right: var(--right-w);
  bottom: 12px;
  z-index: 2;
  pointer-events: none;
}
/* Soft shade along the edges so the floating words read over a bright scene. */
.cb-in-3d .cb-map::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .5), rgba(0, 0, 0, 0) 24%),
    linear-gradient(0deg, rgba(0, 0, 0, .45), rgba(0, 0, 0, 0) 16%),
    linear-gradient(180deg, rgba(0, 0, 0, .4), rgba(0, 0, 0, 0) 12%);
}

/* ---------- Generator form & "Are you sure?" ---------- */
.cb-modal, .cb-ask {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 3, 2, .55);
}
.cb-ask { z-index: 10; }
.cb-form { width: min(560px, 100%); max-height: 100%; overflow-y: auto; padding: 20px 22px; background: var(--cb-glass-strong); }
.cb-form h3 { font-family: var(--cb-font-title); font-weight: normal; font-size: 1.5rem; color: var(--cb-gold); }
.cb-notes, .cb-field { display: grid; gap: 4px; margin-top: 12px; font-size: .85rem; }
.cb-notes textarea, .cb-field textarea { width: 100%; resize: vertical; font-size: .92rem; }
.cb-field > span, .cb-notes > span, .cb-form .cb-stat > span { font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--cb-muted); }
.cb-form .cb-stats { grid-template-columns: repeat(4, 1fr); }
.cb-form .cb-stat input { background: rgba(255, 255, 255, .07); padding-left: .5em; }
.cb-field input[name="name"] { width: 100%; }
.cb-row .cb-field { margin-top: 0; }
.cb-icons, .cb-colors { display: flex; flex-wrap: wrap; gap: 4px; }
.cb-icons label, .cb-colors label { cursor: pointer; }
.cb-icons input, .cb-colors input { position: absolute; opacity: 0; pointer-events: none; }
.cb-icons span {
  display: grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  font-size: 1.15rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
}
.cb-icons input:checked + span { background: rgba(240, 210, 122, .25); box-shadow: inset 0 0 0 2px var(--cb-gold); }
.cb-icons input:focus-visible + span, .cb-colors input:focus-visible + span { outline: 2px solid var(--cb-gold); }
.cb-colors span { display: block; width: 1.7em; height: 1.7em; border-radius: 50%; }
.cb-colors input:checked + span { box-shadow: 0 0 0 3px #fff; }
.cb-icon-custom { margin-top: 6px; width: 16em; }
.cb-checks { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 12px; font-size: .9rem; }
.cb-form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.cb-ask-box { width: min(420px, 100%); padding: 20px 22px; background: var(--cb-glass-strong); }
.cb-ask-text { margin: 0; font-size: 1.02rem; line-height: 1.5; }

/* ---------- Launcher (the small button that follows you around) ---------- */
.cb-launcher {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 15;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #f6e6c3;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #b5442f, #6e1f16 65%, #3d0f0a);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .6);
  transition: transform .15s, filter .15s;
}
.cb-launcher[hidden] { display: none; }
.cb-launcher:hover { filter: brightness(1.2); transform: rotate(-10deg) scale(1.05); }
.cb-launcher:focus-visible { outline: 3px solid #f0d27a; outline-offset: 2px; }

/* ---------- Smaller screens: one scrolling column ---------- */
@media (max-width: 1000px) {
  .cb-window { overflow-y: auto; }
  .cb-body, .cb-bar, .cb-map, .cb-side, .cb-card, .cb-drawer, .cb-drawer-tab { position: static; }
  .cb-bar { background: rgba(6, 4, 3, .85); }
  .cb-body { display: flex; flex-direction: column; gap: 14px; padding: 0 12px 16px; }
  .cb-map { padding: 8px 0 0; }
  .cb-board { width: min(100%, 80vh); }
  .cb-side, .cb-card { width: auto; max-height: none; overflow: visible; }
  .cb-drawer { display: none; width: auto; transform: none; opacity: 1; pointer-events: auto; }
  .cb-drawer-open .cb-drawer { display: block; }
  .cb-drawer-tab { align-self: flex-start; }
  .cb-drawer-open .cb-drawer-tab { display: none; }
  .cb-in-3d .cb-map { position: relative; inset: auto; }
  .cb-in-3d .cb-stage3d { position: relative; inset: auto; height: min(75vh, 640px); }
  .cb-in-3d .cb-foot { position: static; }
  .cb-stats, .cb-form .cb-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .cb-token.current, .cb-o-fire::after { animation: none; }
  .cb-drawer { transition: none; }
}
