/* Fonts (art/fonts, from Google Fonts, SIL OFL). Two sets under role names:
   menus are pixel (Jacquard 24 titles, Jersey 10 buttons and labels, VT323 text),
   the battle is gothic (Grenze Gotisch headings, Grenze for everything else, also on the canvas).
   size-adjust evens out the pixel faces, which run small, so one font-size reads the same in either set.
   A weight range on single-weight faces stops the browser smearing them into a fake bold. */
@font-face { font-family: 'Menu Display'; src: url(art/fonts/jacquard-24.woff2) format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Menu UI'; src: url(art/fonts/jersey-10.woff2) format('woff2'); font-weight: 100 900; size-adjust: 124%; font-display: swap; }
@font-face { font-family: 'Menu Body'; src: url(art/fonts/vt323.woff2) format('woff2'); size-adjust: 128%; font-display: swap; }
@font-face { font-family: 'Game Display'; src: url(art/fonts/grenze-gotisch.woff2) format('woff2'); font-weight: 100 900; size-adjust: 106%; font-display: swap; }
@font-face { font-family: 'Game UI'; src: url(art/fonts/grenze.woff2) format('woff2'); font-weight: 100 900; size-adjust: 106%; font-display: swap; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--ink-1); color: var(--bone-1);
  font-family: var(--body-font);
  user-select: none;
}
#game { position: fixed; inset: 0; display: block; cursor: default; }
.hidden { display: none !important; }

button {
  font: inherit; color: var(--bone-1); background: var(--umber-2);
  border: 1px solid var(--wood-4); border-radius: 4px; padding: 6px 14px; cursor: pointer;
}
button:hover { background: var(--umber-3); }
button.primary { background: var(--wood-2); border-color: var(--gold-0); }
button.primary:hover { background: var(--wood-3); }

/* Top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 38px;
  display: flex; align-items: center; gap: 18px; padding: 0 14px;
  background: linear-gradient(var(--stone-0), var(--ink-2)); border-bottom: 2px solid var(--wood-2);
  font-size: 16px; z-index: 5;
}
#topbar > * { white-space: nowrap; }
#topbar .res { display: flex; align-items: center; gap: 6px; min-width: 70px; }
#topbar .ico { font-size: 16px; }
#topbar .spacer { flex: 1; }
#topbar button { padding: 2px 10px; }
#btn-idle.has-idle { background: var(--wood-3); border-color: var(--gold-2); color: var(--gold-4); }
.wave { color: var(--ember-4); }
#btn-fullscreen { font-size: 17px; line-height: 1; }
.card .fs-hint { margin: -8px 0 18px; }
.card .fs-hint button { font-size: 14px; padding: 4px 14px; }
#btn-music.off, #btn-pixel.off { opacity: 0.4; text-decoration: line-through; }
#info .status { color: var(--gold-3); margin-bottom: 2px; }
#info .chip .st { position: absolute; top: -3px; right: -3px; font-size: 11px; line-height: 1; }
.wave.soon { color: var(--blood-5); font-weight: bold; }

/* Bottom panel */
#panel {
  position: fixed; left: 0; right: 0; bottom: 0; height: 196px;
  display: flex; gap: 10px; padding: 8px;
  background: linear-gradient(var(--stone-0), var(--ink-2)); border-top: 2px solid var(--wood-2); z-index: 5;
}
#minimap { background: var(--ink-0); border: 1px solid var(--wood-2); cursor: pointer; flex: none; }
#info {
  flex: 1; min-width: 0; padding: 8px 12px; background: var(--ink-2);
  border: 1px solid var(--umber-3); border-radius: 4px; overflow: hidden;
}
#info h3 { margin: 0 0 6px; font-size: 18px; color: var(--gold-3); }
#info .stats { font-size: 13px; color: var(--stone-9); line-height: 1.6; }
#info .hpbar { height: 8px; background: var(--blood-0); border-radius: 3px; overflow: hidden; margin: 4px 0 8px; max-width: 260px; }
#info .hpbar > div { height: 100%; background: var(--leaf-5); }
#info .multi { display: flex; flex-wrap: wrap; gap: 4px; }
#info .chip {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: var(--stone-0); border: 1px solid var(--umber-4); border-radius: 4px; position: relative; cursor: pointer;
}
#info .chip .mini { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: var(--blood-0); }
#info .chip .mini > div { height: 100%; background: var(--leaf-5); }
#info .queue { display: flex; gap: 4px; margin-top: 6px; align-items: center; }
#info .queue .chip { width: 34px; height: 34px; font-size: 18px; }
#info .progress { height: 6px; background: var(--stone-0); border-radius: 3px; overflow: hidden; width: 200px; }
#info .progress > div { height: 100%; background: var(--gold-0); }

#commands {
  width: 300px; flex: none; display: grid; grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 56px; gap: 6px; align-content: start;
}
#commands .cmd {
  position: relative; padding: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1.1;
}
#commands .cmd small { font-size: 10px; color: var(--sand-1); }
#commands .cmd .key {
  position: absolute; top: 2px; right: 4px; font-size: 10px; color: var(--gold-3);
}
#commands .cmd.disabled { opacity: 0.4; }
#commands .cmd.active { background: var(--leaf-0); border-color: var(--leaf-6); }

/* Floating messages */
#messages {
  position: fixed; left: 50%; bottom: 210px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 6;
}
#messages div {
  background: color-mix(in srgb, var(--ink-0) 65%, transparent); padding: 4px 12px; border-radius: 4px; font-size: 15px;
  transition: opacity 0.6s;
}

#tooltip {
  position: fixed; z-index: 20; max-width: 260px; pointer-events: none;
  background: var(--ink-2); border: 1px solid var(--wood-4); border-radius: 4px; padding: 8px 10px; font-size: 13px;
}
#tooltip b { color: var(--gold-3); }
#tooltip .cost { color: var(--gold-3); margin: 2px 0 4px; }

/* The game's own cursor while the pointer is locked in full screen (src/vpointer.js): the size of a system
   arrow, so the action badge the game draws beside it (axe, pick, sword...) stays clear of it. */
#vcursor {
  display: none; position: fixed; left: 0; top: 0; width: 13px; height: 19px; z-index: 1000; pointer-events: none;
  background: no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='19'%3E%3Cpath d='M1 1 L1 15 L4.4 11.8 L6.8 17.2 L9 16.2 L6.7 11 L11.2 11 Z' fill='%23e8d9a8' stroke='%231a120c' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E");
}
#vcursor.cross {
  width: 22px; height: 22px; margin: -11px 0 0 -11px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22'%3E%3Cg stroke-linecap='square'%3E%3Cpath d='M11 1V8M11 14V21M1 11H8M14 11H21' stroke='%231a120c' stroke-width='4'/%3E%3Cpath d='M11 1V8M11 14V21M1 11H8M14 11H21' stroke='%23e8d9a8' stroke-width='1.6'/%3E%3C/g%3E%3C/svg%3E");
}
#vtip {
  display: none; position: fixed; z-index: 999; pointer-events: none; max-width: 260px;
  background: var(--ink-2); border: 1px solid var(--wood-4); border-radius: 4px; padding: 4px 8px; font-size: 12px;
}
.vhover { filter: brightness(1.25); }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--ink-2) 85%, transparent), color-mix(in srgb, var(--ink-0) 95%, transparent));
}
.card {
  max-width: 560px; padding: 28px 34px; text-align: center;
  background: var(--ink-2); border: 2px solid var(--wood-4); border-radius: 8px; box-shadow: 0 0 60px color-mix(in srgb, var(--ember-3) 15%, transparent);
}
.card h1 { margin: 0; font-size: 46px; letter-spacing: 2px; color: var(--gold-3); text-shadow: 0 0 18px color-mix(in srgb, var(--amber-1) 50%, transparent); }
.card h2 { margin-top: 0; color: var(--gold-3); }
.card .sub { color: var(--blood-6); font-style: italic; color: var(--sand-1); }
.card .diff { display: flex; justify-content: center; gap: 12px; margin: 22px 0; }
.card .diff button { font-size: 18px; padding: 8px 22px; }
.card .howto { text-align: left; font-size: 14px; color: var(--stone-9); line-height: 1.5; }
.card table { margin: 0 auto 12px; text-align: left; font-size: 14px; border-collapse: collapse; }
.card td { padding: 3px 10px; }
.card td:first-child { color: var(--gold-3); white-space: nowrap; }

/* Setup screen */
.card.setup { max-width: 820px; width: calc(100% - 32px); max-height: 94vh; overflow-y: auto; padding: 22px 28px; }
.card.setup h1 { font-size: 40px; }
.card h4 { margin: 16px 0 8px; text-align: left; color: var(--gold-3); font-size: 15px; letter-spacing: 1px; text-transform: uppercase; }
.factions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.factions button, .maps button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; text-align: center;
  background: var(--stone-0); border: 2px solid var(--umber-4);
}
.factions button .ic { font-size: 30px; }
.factions button b { font-size: 14px; }
.factions button small, .maps button small { font-size: 11px; color: var(--stone-9); }
.factions button.sel, .maps button.sel, .chips button.sel { border-color: var(--gold-3); background: var(--umber-3); box-shadow: 0 0 12px color-mix(in srgb, var(--gold-3) 25%, transparent); }
.faction-info { text-align: left; font-size: 13px; color: var(--stone-9); background: var(--ink-2); border: 1px solid var(--umber-2); border-radius: 4px; padding: 8px 12px; margin-top: 8px; line-height: 1.5; }
.faction-info ul { margin: 4px 0 0; padding-left: 18px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 12px; font-size: 14px; }
.maps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.maps canvas { width: 92px; height: 92px; max-width: 100%; image-rendering: pixelated; }
.maps button b { font-size: 12px; }
.go { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
/* The setup's two steps (Main.setupStep). */
.steps { display: flex; justify-content: center; gap: 8px; margin: 4px 0 14px; }
.steps .step-tab { padding: 5px 14px; font-size: 14px; opacity: 0.7; }
.steps .step-tab b { display: inline-block; width: 20px; height: 20px; line-height: 20px; border-radius: 50%; margin-right: 6px; background: var(--ink-2); font-size: 12px; }
.steps .step-tab.sel { opacity: 1; border-color: var(--gold-3); }
.steps .step-tab.sel b { background: var(--gold-3); color: var(--ink-0); }
.card.setup .step { display: none; }
.card.setup[data-step="1"] .step1, .card.setup[data-step="2"] .step2 { display: block; }
.card.setup .step2 > .sub { margin-top: 0; }
.card.setup .step2 .row2 { grid-template-columns: 2fr 1fr; }
.card.setup .step2 .maps { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.card.setup .step2 .maps canvas { width: 64px; height: 64px; }
.card.setup .step2 .go { position: sticky; bottom: -22px; margin: 12px -28px -22px; padding: 12px 0 14px;
  background: linear-gradient(transparent, var(--ink-1) 30%); }
details.advanced { margin-top: 16px; border-top: 1px solid color-mix(in srgb, var(--wood-4) 50%, transparent); padding-top: 10px; }
details.advanced summary { cursor: pointer; color: var(--stone-9); font-size: 14px; }
details.advanced[open] summary { margin-bottom: 4px; }
button.big { font-size: 20px; padding: 10px 30px; }
@media (max-width: 700px) {
  .factions { grid-template-columns: repeat(2, 1fr); }
  .maps { grid-template-columns: repeat(3, 1fr); }
  .row2, .card.setup .step2 .row2 { grid-template-columns: 1fr; }
  .card.setup { padding: 16px; }
  .card.setup .step2 .go { margin: 12px -16px -16px; bottom: -16px; }
}

/* Command buttons: cooldown sweep, locked (tier) state */
#commands .cmd { overflow: hidden; }
#commands .cmd .cd { position: absolute; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--ink-0) 55%, transparent); pointer-events: none; }
#commands .cmd .cdt { position: absolute; top: 50%; left: 0; right: 0; transform: translateY(-50%); font-size: 18px; font-weight: bold; color: var(--bone-3); text-shadow: 0 0 4px var(--ink-0); pointer-events: none; }
#commands .cmd.locked { opacity: 0.3; filter: grayscale(1); }
#info .chip .lv { position: absolute; top: -3px; left: -3px; font-size: 9px; background: var(--umber-1); color: var(--gold-3); border-radius: 6px; padding: 0 3px; }
#commands { grid-auto-rows: 52px; }

/* Portrait art (tools/portraits). Files are stored at 2x for sharp display on high-DPI screens. */
img.art { display: block; width: 32px; height: 32px; border-radius: 3px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink-0) 60%, transparent); }
img.art.inline { display: inline-block; width: 20px; height: 20px; vertical-align: middle; }
#info .chip img.art { width: 32px; height: 32px; }
#info .queue .chip img.art { width: 28px; height: 28px; }
#commands .cmd.locked img.art, #commands .cmd.disabled img.art { filter: grayscale(0.7); }
#info .single { display: flex; gap: 12px; align-items: flex-start; }
#info .single .body { flex: 1; min-width: 0; }
#info img.portrait {
  object-fit: cover;
  flex: none; width: 96px; height: 96px; border: 2px solid var(--wood-4); border-radius: 4px;
  box-shadow: 0 0 0 1px var(--ink-0), 0 2px 8px color-mix(in srgb, var(--ink-0) 60%, transparent);
}
img.px { image-rendering: pixelated; }

.card .gallery-link { margin: 12px 0 0; font-size: 13px; }
.card .gallery-link a { color: var(--sand-1); }

/* ===================== Front end: title, menus, end screens ===================== */
:root {
  --stone: var(--stone-0); --stone-hi: var(--umber-3); --stone-lo: var(--ink-2);
  --gold: var(--gold-3); --gold-deep: var(--gold-0); --ink: var(--bone-1); --dim: var(--sand-0);
  --pixel-font: 'Menu UI', 'Trebuchet MS', sans-serif;
  --logo-font: 'Menu Display', 'Menu UI', Georgia, serif;
  --body-font: 'Menu Body', 'Menu UI', monospace;
}
/* In battle the same roles switch to the gothic set. */
#topbar, #panel, #tooltip, #messages, #tutor, #cheat, #netbanner, #netping, #chatline {
  --pixel-font: 'Game UI', Georgia, serif;
  --logo-font: 'Game Display', 'Game UI', Georgia, serif;
  --body-font: 'Game UI', Georgia, serif;
  font-family: var(--body-font);
}
/* Counters keep their width as they tick. */
#topbar .res, #info .stats, #tooltip .cost { font-variant-numeric: lining-nums tabular-nums; }

.screen { position: fixed; inset: 0; z-index: 30; overflow: hidden; background: var(--ink-1); }

/* Pixel-art scenes: kept crisp, gently drifting. */
.title-art, .end-art {
  position: absolute; inset: -3%;
  background: center / cover no-repeat;
  image-rendering: pixelated;
  animation: drift 60s ease-in-out infinite alternate;
}
.title-art { background-image: url(art/menu/title.png); }
.end.won .end-art { background-image: url(art/menu/victory.png); }
.end.lost .end-art { background-image: url(art/menu/defeat.png); }
@keyframes drift { from { transform: scale(1.0) translate(0, 0); } to { transform: scale(1.06) translate(-1.5%, 1%); } }

#title::after, .end::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 35%, color-mix(in srgb, var(--ink-0) 0%, transparent) 30%, color-mix(in srgb, var(--ink-0) 55%, transparent) 100%),
              linear-gradient(to bottom, color-mix(in srgb, var(--ink-0) 15%, transparent), color-mix(in srgb, var(--ink-0) 0%, transparent) 30%, color-mix(in srgb, var(--ink-0) 55%, transparent));
}

/* Floating embers. */
.embers { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.embers i {
  position: absolute; bottom: -10px; width: 4px; height: 4px; background: var(--amber-1);
  box-shadow: 0 0 6px 1px color-mix(in srgb, var(--amber-1) 80%, transparent); opacity: 0;
  animation: ember linear infinite;
}
@keyframes ember {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 0.9; }
  100% { transform: translate(var(--dx, 40px), -95vh); opacity: 0; }
}

.title-content {
  position: relative; z-index: 2; height: 100%;
  display: flex; flex-direction: column; align-items: center; padding-top: 7vh;
}
.logo {
  margin: 0; font-family: var(--logo-font); font-weight: 400;
  font-size: clamp(56px, 10vw, 132px); line-height: 0.95; letter-spacing: 2px; color: var(--gold);
  text-shadow: 0 4px 0 var(--wood-1), 0 8px 0 var(--umber-1), 0 0 30px color-mix(in srgb, var(--amber-1) 45%, transparent);
  text-align: center;
}
.tagline {
  margin: 10px 0 0; font-family: var(--pixel-font); font-size: clamp(14px, 1.6vw, 20px);
  color: var(--bone-0); letter-spacing: 3px; text-transform: uppercase; text-shadow: 0 2px 0 var(--ink-0);
}
.title-menu { margin-top: auto; margin-bottom: 14vh; display: flex; flex-direction: column; gap: 12px; width: min(340px, 86vw); }
/* While the orchestra loads, a bar stands where the menu will be. */
.title-loading { display: none; margin-top: auto; margin-bottom: 14vh; width: min(340px, 86vw); text-align: center;
  font-family: var(--pixel-font); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--bone-0);
  text-shadow: 0 1px 0 var(--ink-0); }
.load-bar { height: 10px; margin-bottom: 10px; border: 2px solid var(--wood-2); background: color-mix(in srgb, var(--ink-0) 70%, transparent); }
.load-bar i { display: block; height: 100%; width: 0; background: var(--gold-3); transition: width 0.15s; }
#title.loading .title-loading { display: block; }
#btn-enter { display: none; width: 100%; }
#title.ready .load-bar, #title.ready #load-text { display: none; }
#title.ready #btn-enter { display: block; }
#title.loading .title-menu { display: none; }
.title-foot {
  position: absolute; z-index: 2; right: 16px; bottom: 12px; font-family: var(--pixel-font);
  font-size: 12px; color: color-mix(in srgb, var(--bone-1) 60%, transparent); text-shadow: 0 1px 0 var(--ink-0);
}

/* Chunky stone-and-gold pixel buttons. */
.pbtn {
  font-family: var(--pixel-font); font-weight: 600; font-size: 17px; letter-spacing: 1px;
  color: var(--ink); text-decoration: none; text-align: center; cursor: pointer;
  background: var(--stone); padding: 10px 18px; border: 3px solid var(--ink-1); border-radius: 0;
  box-shadow: inset 3px 3px 0 var(--stone-hi), inset -3px -3px 0 var(--stone-lo), 0 4px 0 var(--ink-0);
  text-shadow: 0 2px 0 var(--ink-0); transition: transform 0.06s, filter 0.1s; display: block;
}
.pbtn:hover { filter: brightness(1.25); background: var(--umber-2); }
.pbtn:active { transform: translateY(3px); box-shadow: inset 3px 3px 0 var(--stone-lo), inset -3px -3px 0 var(--stone-hi), 0 1px 0 var(--ink-0); }
.pbtn.primary {
  background: var(--wood-3); color: var(--sand-2);
  box-shadow: inset 3px 3px 0 var(--gold-0), inset -3px -3px 0 var(--umber-2), 0 4px 0 var(--ink-0);
}
.pbtn.primary:hover { background: var(--wood-4); }
.pbtn.big { font-size: 22px; padding: 14px 22px; }
.pbtn.small { font-size: 14px; padding: 6px 12px; }
.title-menu .pbtn { backdrop-filter: blur(2px); }

/* Framed panels. */
.card.frame {
  border-radius: 0; border: 4px solid var(--ink-1); background: color-mix(in srgb, var(--ink-2) 94%, transparent);
  box-shadow: inset 0 0 0 3px var(--wood-2), inset 0 0 0 6px var(--ink-2), 0 10px 40px color-mix(in srgb, var(--ink-0) 70%, transparent);
}
.ptitle {
  font-family: var(--logo-font) !important; font-weight: 400 !important; color: var(--gold);
  font-size: 54px !important; letter-spacing: 1px; margin: 0; text-shadow: 0 3px 0 var(--wood-0), 0 0 18px color-mix(in srgb, var(--amber-1) 35%, transparent);
}
h2.ptitle { font-size: 46px !important; margin-bottom: 14px; }
.opt-list { display: flex; flex-direction: column; gap: 10px; min-width: 300px; margin-bottom: 16px; }
.opt-row { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.pbtn.opt { display: flex; justify-content: space-between; align-items: center; gap: 16px; text-align: left; }
.pbtn.opt span { color: var(--gold); min-width: 34px; text-align: right; }
.overlay.dim { background: color-mix(in srgb, var(--ink-0) 60%, transparent); }

/* The New Battle screen sits over the darkened title art. */
.setup-screen { background: var(--ink-1) url(art/menu/title.png) center / cover no-repeat; image-rendering: pixelated; }
.setup-screen::before { content: ''; position: absolute; inset: 0; background: color-mix(in srgb, var(--ink-1) 72%, transparent); }
.setup-screen .card { position: relative; image-rendering: auto; }
.setup-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.setup-head .ptitle { text-align: center; }
.card.setup h4 { font-family: var(--pixel-font); letter-spacing: 2px; }
.card.setup .chips button, .card.setup .go button, .maps button {
  border-radius: 0; font-family: var(--pixel-font);
  box-shadow: inset 2px 2px 0 var(--stone-hi), inset -2px -2px 0 var(--stone-lo);
}

/* Faction cards with their illustrations. */
.factions button.art-card { position: relative; padding: 0; overflow: hidden; border-radius: 0; aspect-ratio: 3 / 4; justify-content: flex-end; border: 3px solid var(--ink-1); }
.factions button.art-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; transition: transform 0.25s; }
.factions button.art-card:hover img { transform: scale(1.04); }
.factions button.art-card .label {
  position: relative; width: 100%; padding: 26px 6px 8px; display: flex; flex-direction: column; gap: 2px;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--ink-0) 0%, transparent), color-mix(in srgb, var(--ink-1) 92%, transparent) 45%);
}
.factions button.art-card b { font-family: var(--pixel-font); font-size: 15px; color: var(--gold); text-shadow: 0 2px 0 var(--ink-0); }
.factions button.art-card small { color: var(--bone-0); }
.factions button.art-card.sel { border-color: var(--gold-3); box-shadow: 0 0 0 2px var(--gold-3), 0 0 22px color-mix(in srgb, var(--gold-3) 50%, transparent); }
.factions button.art-card:not(.sel) img { filter: saturate(0.7) brightness(0.8); }

/* End screens. */
.end { display: flex; align-items: center; justify-content: center; }
.end-card { position: relative; z-index: 2; max-width: 560px; text-align: center; }
.end-card .ptitle { font-size: 72px !important; }
.end-card:has(.end-table) { max-width: min(760px, calc(100vw - 32px)); }
#end-stats { overflow-x: auto; margin: 4px 0 16px; }
.end-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.end-table th, .end-table td { padding: 5px 8px; text-align: right; white-space: nowrap; }
.end-table thead th { color: var(--gold-3); font-weight: normal; border-bottom: 1px solid var(--wood-4); }
.end-table tbody th { text-align: left; font-weight: normal; }
.end-table tbody tr + tr { border-top: 1px solid color-mix(in srgb, var(--wood-4) 40%, transparent); }
.end-table tr.me { background: color-mix(in srgb, var(--gold-3) 10%, transparent); }
.end-table td.top { color: var(--gold-3); }
.end-table .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.end.lost .end-card .ptitle { color: var(--ember-3); text-shadow: 0 3px 0 var(--blood-0), 0 0 18px color-mix(in srgb, var(--ember-2) 45%, transparent); }

/* ===================== In-game HUD, in the front-end's pixel style ===================== */
/* Carved dark stone with a gold edge, chunky bevels, pixel font for numbers and labels. */
#topbar, #panel {
  background:
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--bone-3) 2.5%, transparent) 0 2px, color-mix(in srgb, var(--ink-0) 0%, transparent) 2px 6px),
    linear-gradient(var(--stone-0), var(--ink-2));
  font-family: var(--pixel-font);
}
#topbar {
  height: 42px; gap: 10px; padding: 0 10px;
  border-bottom: 3px solid var(--ink-1);
  box-shadow: inset 0 -3px 0 var(--wood-2), inset 0 -6px 0 var(--ink-2), 0 4px 10px color-mix(in srgb, var(--ink-0) 50%, transparent);
}
#topbar .res {
  min-width: 82px; gap: 6px; padding: 3px 10px 3px 4px;
  background: var(--ink-1); border: 2px solid var(--ink-1);
  box-shadow: inset 2px 2px 0 var(--ink-0), inset -2px -2px 0 var(--umber-2);
  font-size: 17px; font-weight: 600; color: var(--gold); text-shadow: 0 2px 0 var(--ink-0);
}
#topbar img.ico { width: 26px; height: 26px; image-rendering: pixelated; flex: none; }
#topbar button, #panel button {
  font-family: var(--pixel-font); font-weight: 600; color: var(--ink); border-radius: 0;
  background: var(--stone); border: 2px solid var(--ink-1); padding: 3px 9px; font-size: 15px;
  box-shadow: inset 2px 2px 0 var(--stone-hi), inset -2px -2px 0 var(--stone-lo), 0 2px 0 var(--ink-0);
  text-shadow: 0 1px 0 var(--ink-0);
}
#topbar button:hover, #panel button:hover { filter: brightness(1.25); background: var(--umber-2); }
#topbar button:active, #panel button:active { transform: translateY(2px); box-shadow: inset 2px 2px 0 var(--stone-lo), inset -2px -2px 0 var(--stone-hi); }
#btn-idle { display: flex; align-items: center; gap: 4px; }
#btn-idle img.ico { width: 22px !important; height: 22px !important; }
#btn-idle.has-idle { background: var(--wood-3); border-color: var(--ink-1); color: var(--sand-2); box-shadow: inset 2px 2px 0 var(--gold-0), inset -2px -2px 0 var(--umber-2), 0 2px 0 var(--ink-0); animation: idlePulse 1.2s steps(2) infinite; }
@keyframes idlePulse { 50% { filter: brightness(1.3); } }
#topbar .wave { font-size: 15px; letter-spacing: 1px; text-shadow: 0 2px 0 var(--ink-0); }
#topbar .wave.soon { color: var(--ember-3); animation: idlePulse 0.8s steps(2) infinite; }

#panel {
  height: 200px; gap: 8px; padding: 10px 8px 8px;
  border-top: 3px solid var(--ink-1);
  box-shadow: inset 0 3px 0 var(--wood-2), inset 0 6px 0 var(--ink-2), 0 -4px 10px color-mix(in srgb, var(--ink-0) 50%, transparent);
}
/* Recessed wells for the minimap, the info panel and the command grid. */
#minimap, #info, #commands {
  background-color: var(--ink-1); border: 3px solid var(--ink-1); border-radius: 0;
  box-shadow: inset 3px 3px 0 var(--ink-0), inset -3px -3px 0 var(--umber-2), 0 0 0 2px var(--wood-2);
}
#minimap { image-rendering: pixelated; }
#info { padding: 8px 12px; }
#commands { padding: 6px; width: 312px; grid-auto-rows: 52px; }
#info h3 { font-family: var(--logo-font); font-weight: 700; font-size: 20px; letter-spacing: 1px; text-shadow: 0 2px 0 var(--ink-0); }
#info .stats { font-family: var(--body-font); }
#info .status { font-family: var(--pixel-font); }

/* Blocky, segmented bars. */
#info .hpbar, #info .progress, #info .chip .mini {
  border-radius: 0; border: 2px solid var(--ink-1); background: var(--ink-2); box-sizing: content-box;
}
#info .hpbar { height: 10px; }
#info .progress { height: 6px; background: var(--ink-2); }
#info .hpbar > div, #info .progress > div, #info .chip .mini > div {
  background-image: repeating-linear-gradient(90deg, color-mix(in srgb, var(--ink-0) 0%, transparent) 0 6px, color-mix(in srgb, var(--ink-0) 35%, transparent) 6px 8px);
  box-shadow: inset 0 2px 0 color-mix(in srgb, var(--bone-3) 25%, transparent);
}
#info .progress > div { background-color: var(--gold-0); }

/* Unit chips and the training queue: bevelled tiles. */
#info .chip {
  border-radius: 0; background: var(--stone-0); border: 2px solid var(--ink-1);
  box-shadow: inset 2px 2px 0 var(--stone-hi), inset -2px -2px 0 var(--stone-lo);
}
#info .chip:hover { filter: brightness(1.25); }
#info .chip img.art, img.art { border-radius: 0; image-rendering: pixelated; }
#info img.portrait { border-radius: 0; border: 3px solid var(--ink-1); box-shadow: 0 0 0 2px var(--wood-2); image-rendering: pixelated; }
#info .chip .lv { border-radius: 0; font-family: var(--pixel-font); border: 1px solid var(--ink-1); }

/* Command buttons. */
#commands .cmd {
  border-radius: 0; background: var(--stone); border: 2px solid var(--ink-1);
  box-shadow: inset 2px 2px 0 var(--stone-hi), inset -2px -2px 0 var(--stone-lo), 0 2px 0 var(--ink-0);
  padding: 2px; gap: 1px;
}
#commands .cmd:hover { filter: brightness(1.3); background: var(--umber-2); }
#commands .cmd:active { transform: translateY(2px); box-shadow: inset 2px 2px 0 var(--stone-lo), inset -2px -2px 0 var(--stone-hi); }
#commands .cmd small { font-family: var(--pixel-font); font-size: 10px; letter-spacing: 0.3px; color: var(--bone-0); text-shadow: 0 1px 0 var(--ink-0); line-height: 1; }
#commands .cmd .key {
  top: 1px; right: 2px; font-family: var(--pixel-font); font-weight: 700; font-size: 11px; color: var(--gold);
  text-shadow: 0 1px 0 var(--ink-0), 1px 0 0 var(--ink-0);
}
#commands .cmd.active { background: var(--moss-2); box-shadow: inset 2px 2px 0 var(--leaf-3), inset -2px -2px 0 var(--moss-0), 0 0 0 2px var(--leaf-6); }
#commands .cmd .cdt { font-family: var(--pixel-font); }

/* Tooltip and messages: framed pixel panels. */
#tooltip {
  border-radius: 0; background: color-mix(in srgb, var(--ink-2) 97%, transparent); border: 3px solid var(--ink-1);
  box-shadow: inset 0 0 0 2px var(--wood-2), 0 6px 16px color-mix(in srgb, var(--ink-0) 60%, transparent);
}
#tooltip b { font-family: var(--pixel-font); font-size: 15px; letter-spacing: 0.5px; }
#tooltip .cost { font-family: var(--pixel-font); font-weight: 600; display: flex; gap: 10px; align-items: center; }
#tooltip .cost img { width: 18px; height: 18px; image-rendering: pixelated; vertical-align: -4px; margin-right: 2px; }
#messages { bottom: 214px; }
#messages div {
  border-radius: 0; font-family: var(--pixel-font); font-size: 15px; letter-spacing: 0.5px;
  background: color-mix(in srgb, var(--ink-1) 88%, transparent); border: 2px solid var(--ink-1); border-left: 4px solid var(--gold-0);
  box-shadow: 0 2px 0 var(--ink-0); text-shadow: 0 1px 0 var(--ink-0); padding: 5px 12px;
}

/* The help screen uses the framed panel too. */
#help .card { border-radius: 0; border: 4px solid var(--ink-1); background: color-mix(in srgb, var(--ink-2) 96%, transparent);
  box-shadow: inset 0 0 0 3px var(--wood-2), inset 0 0 0 6px var(--ink-2), 0 10px 40px color-mix(in srgb, var(--ink-0) 70%, transparent); }
#help .card h2 { font-family: var(--logo-font); font-weight: 400; font-size: 46px; color: var(--gold); text-shadow: 0 3px 0 var(--wood-0); margin-bottom: 10px; }
#help .card td:first-child { font-family: var(--pixel-font); }
#help .card button { font-family: var(--pixel-font); font-weight: 600; border-radius: 0; background: var(--wood-3); color: var(--sand-2); border: 3px solid var(--ink-1); padding: 10px 18px;
  box-shadow: inset 3px 3px 0 var(--gold-0), inset -3px -3px 0 var(--umber-2), 0 4px 0 var(--ink-0); }
/* Two-line labels fit inside the command buttons. */
#commands .cmd img.art { width: 26px; height: 26px; flex: none; }
#commands .cmd small {
  font-size: 9.5px; max-width: 100%; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; text-align: center;
}
#commands { grid-auto-rows: 54px; }

/* Command card groups: each kind of button has its own frame colour and starts a new row. */
#commands { overflow-y: auto; scrollbar-width: thin; }
#commands .cmd.gstart { grid-column-start: 1; }
#commands .cmd.g-action  { --g-hi: var(--stone-4); --g-lo: var(--dusk-0); background: var(--dusk-1); }
#commands .cmd.g-ability { --g-hi: var(--arcane-4); --g-lo: var(--arcane-0); background: var(--arcane-1); }
#commands .cmd.g-unit    { --g-hi: var(--sky-5); --g-lo: var(--steel-0); background: var(--steel-1); }
#commands .cmd.g-hero    { --g-hi: var(--wood-6); --g-lo: var(--umber-1); background: var(--steel-1); }
#commands .cmd.g-build   { --g-hi: var(--leaf-4); --g-lo: var(--moss-0); background: var(--moss-1); }
#commands .cmd.g-upgrade { --g-hi: var(--gold-0); --g-lo: var(--umber-2); background: var(--umber-2); }
#commands .cmd[class*="g-"] { box-shadow: inset 2px 2px 0 var(--g-hi), inset -2px -2px 0 var(--g-lo), 0 2px 0 var(--ink-0); }
#commands .cmd.g-hero { box-shadow: inset 2px 2px 0 var(--g-hi), inset -2px -2px 0 var(--g-lo), inset 0 0 0 3px var(--sky-5), 0 2px 0 var(--ink-0); }
#commands .cmd.active { background: var(--moss-2); box-shadow: inset 2px 2px 0 var(--leaf-3), inset -2px -2px 0 var(--moss-0), 0 0 0 2px var(--leaf-6); }
#commands .cmd .up {
  position: absolute; top: 1px; left: 3px; font-size: 9px; line-height: 1; color: var(--gold-3); text-shadow: 0 1px 0 var(--ink-0);
}
#commands .cmd .rep {
  position: absolute; bottom: 1px; left: 2px; font-size: 11px; line-height: 1; pointer-events: none;
}
#commands .cmd.repeating { outline: 2px solid var(--leaf-6); outline-offset: -2px; animation: repPulse 1.4s steps(2) infinite; }
@keyframes repPulse { 50% { outline-color: var(--leaf-2); } }
#tooltip .kind {
  font-family: var(--pixel-font); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  display: inline-block; padding: 1px 6px; margin-bottom: 3px; color: var(--sand-2); border: 1px solid var(--ink-1);
}
#tooltip .kind.g-action  { background: var(--stone-2); }
#tooltip .kind.g-ability { background: var(--arcane-2); }
#tooltip .kind.g-unit    { background: var(--sky-2); }
#tooltip .kind.g-hero    { background: var(--wood-4); }
#tooltip .kind.g-build   { background: var(--leaf-1); }
#tooltip .kind.g-upgrade { background: var(--wood-4); }
/* Three grouped rows must fit in the panel well. */
#commands { grid-auto-rows: 50px; gap: 5px; padding: 5px; }

/* Picture buttons: the art is the whole face, the name lives in the tooltip. Square tiles, five per row. */
#commands { grid-template-columns: repeat(5, 52px); grid-auto-rows: 52px; gap: 5px; justify-content: center; }
#commands .cmd { padding: 0; gap: 0; overflow: hidden; }
#commands .cmd small { display: none; }
#commands .cmd img.art.face {
  position: absolute; inset: 0; width: 100%; height: 100%; box-shadow: none; border-radius: 0; image-rendering: pixelated;
}
#commands .cmd .emo { font-size: 28px; line-height: 1; filter: drop-shadow(0 2px 0 var(--ink-0)); }
/* The group frame sits on top of the picture. */
#commands .cmd::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--g-hi, var(--wood-2)), inset 0 0 0 3px color-mix(in srgb, var(--ink-0) 60%, transparent);
}
#commands .cmd.g-hero::after { box-shadow: inset 0 0 0 2px var(--gold-1), inset 0 0 0 3px color-mix(in srgb, var(--ink-0) 60%, transparent); }
#commands .cmd.active::after { box-shadow: inset 0 0 0 3px var(--leaf-6); }
#commands .cmd.repeating { outline: none; }
#commands .cmd.repeating::after { box-shadow: inset 0 0 0 3px var(--leaf-6); animation: repPulse2 1.4s steps(2) infinite; }
@keyframes repPulse2 { 50% { box-shadow: inset 0 0 0 3px var(--leaf-2); } }
#commands .cmd .key, #commands .cmd .up, #commands .cmd .rep, #commands .cmd .cd, #commands .cmd .cdt { z-index: 1; }
#commands .cmd .key {
  top: 3px; right: 3px; padding: 0 3px; line-height: 13px; background: color-mix(in srgb, var(--ink-1) 85%, transparent); font-size: 11px;
}
#commands .cmd .up { top: 3px; left: 3px; padding: 0 2px; line-height: 12px; background: color-mix(in srgb, var(--ink-1) 85%, transparent); }
#commands .cmd .rep { bottom: 3px; left: 3px; background: color-mix(in srgb, var(--ink-1) 85%, transparent); padding: 1px; }
#commands .cmd:hover { filter: brightness(1.2); }
#commands .cmd.disabled { opacity: 1; }
#commands .cmd.disabled img.art.face, #commands .cmd.disabled .emo { filter: grayscale(0.8) brightness(0.55); }
#commands .cmd.locked { opacity: 1; filter: none; }
#commands .cmd.locked img.art.face, #commands .cmd.locked .emo { filter: grayscale(1) brightness(0.5); }

/* Cheat code box (Enter in game) */
#cheat { position: fixed; left: 50%; bottom: 214px; transform: translateX(-50%); z-index: 20; }
#cheat input {
  width: 420px; max-width: calc(100vw - 32px); padding: 7px 10px; font: inherit; font-size: 14px;
  color: var(--bone-1); background: color-mix(in srgb, var(--ink-2) 92%, transparent); border: 1px solid var(--gold-0); border-radius: 4px; outline: none;
}

/* ===================== Tutorial ===================== */
#tut-pick { margin-top: 14px; }
#tut-pick .tut-done {
  position: absolute; top: 6px; right: 6px; z-index: 1; width: 28px; height: 28px; line-height: 26px;
  font-family: var(--pixel-font); font-size: 18px; color: var(--ink-1); background: var(--leaf-6); border: 2px solid var(--ink-1);
}
#tutor {
  position: fixed; top: 48px; right: 12px; z-index: 6; width: 340px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 196px - 64px); overflow-y: auto; padding: 10px 14px 12px;
  font-family: var(--pixel-font); font-size: 15px; line-height: 1.45; color: var(--ink);
  background: color-mix(in srgb, var(--ink-2) 94%, transparent); border: 3px solid var(--ink-1);
  box-shadow: inset 0 0 0 2px var(--wood-2), 0 6px 24px color-mix(in srgb, var(--ink-0) 60%, transparent);
}
#tutor .tut-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--dim); letter-spacing: 1px; }
#tutor .tut-x { background: none; border: none; color: var(--dim); padding: 0 4px; font-size: 16px; }
#tutor .tut-x:hover { color: var(--gold); background: none; }
#tutor .tut-bar { height: 5px; background: var(--ink-2); margin: 6px 0 8px; }
#tutor .tut-bar > div { height: 100%; background: var(--gold-deep); transition: width 0.4s; }
#tutor h3 { margin: 0 0 6px; font-family: var(--logo-font); font-weight: 700; font-size: 21px; color: var(--gold); text-shadow: 0 2px 0 var(--ink-0); }
#tutor.passed h3 { color: var(--leaf-6); }
#tutor .tut-text p { margin: 0 0 8px; }
#tutor .tut-text b { color: var(--gold-3); }
#tutor .tut-count { margin-top: 6px; color: var(--leaf-6); }
#tutor .tut-tips { margin: 8px 0 0; padding-left: 18px; font-size: 14px; color: var(--bone-0); }
#tutor .tut-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#tutor .tut-btns:empty { display: none; }
#tutor.min { width: auto; }
#tutor.min > :not(.tut-head):not(h3) { display: none; }
#tutor.min h3 { font-size: 16px; margin: 4px 0 0; }
#commands .cmd.tut-glow { outline: 3px solid var(--gold-3); outline-offset: -3px; animation: tutGlow 0.8s steps(2) infinite; }
@keyframes tutGlow { 50% { outline-color: var(--sand-2); } }
@media (max-width: 700px) { #tutor { top: auto; bottom: 206px; right: 8px; width: auto; left: 8px; } }

/* ---------- Online: room, lobby, in-game banner (src/lobby.js) ---------- */
.field { font: inherit; font-size: 15px; padding: 6px 10px; background: var(--ink-1); color: var(--bone-1); border: 1px solid var(--umber-3); border-radius: 4px; }
.field:disabled { opacity: 0.75; }
.field.small { font-size: 13px; padding: 4px 6px; }
.field.code { width: 110px; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-size: 20px; }
#online-name { width: 260px; }
.join-row { display: flex; gap: 10px; align-items: center; }
.room-code { font-size: 26px; letter-spacing: 5px; color: var(--gold-3); }
.small-link { font-size: 12px; padding: 3px 8px; margin-left: 8px; }
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px; background: color-mix(in srgb, var(--ink-1) 70%, transparent); border: 1px solid var(--umber-2); border-radius: 4px; }
.slot.empty { opacity: 0.8; }
.slot .who { min-width: 160px; text-align: left; }
.slot .who.dim { color: var(--stone-7); }
.slot button.small { font-size: 12px; padding: 3px 8px; }
.swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid var(--ink-0); display: inline-block; }
.swatch.none { background: transparent; border-style: dashed; border-color: var(--stone-5); }
.spectators, .note { font-size: 13px; color: var(--stone-7); margin-top: 6px; text-align: left; min-height: 1em; }
#online-status { text-align: center; color: var(--sand-1); }
.check { display: block; text-align: left; font-size: 14px; margin: 4px 0; }
.chat { height: 90px; overflow-y: auto; text-align: left; font-size: 13px; padding: 6px; background: var(--ink-1); border: 1px solid var(--umber-2); border-radius: 4px; margin-bottom: 6px; }
#lobby-say { width: 100%; box-sizing: border-box; }
#netbanner { position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 25; padding: 8px 18px; background: color-mix(in srgb, var(--ink-0) 85%, transparent); color: var(--gold-3); border: 1px solid var(--gold-0); border-radius: 4px; font-size: 15px; pointer-events: none; }
#netping { position: fixed; top: 46px; right: 8px; z-index: 20; font-size: 11px; color: var(--stone-7); pointer-events: none; }
#chatline { position: fixed; bottom: 210px; left: 50%; transform: translateX(-50%); z-index: 26; }
#chatline input { width: 420px; max-width: 80vw; font: inherit; font-size: 15px; padding: 6px 10px; background: var(--ink-1); color: var(--bone-1); border: 1px solid var(--gold-0); border-radius: 4px; }
#pausemenu.online h2::after { content: ' (the battle goes on)'; font-size: 14px; color: var(--stone-7); }
#pausemenu.behind .card { visibility: hidden; }   /* Options or Controls are open over it */
#options { z-index: 31; }
.slot .ready { font-size: 12px; color: var(--stone-7); margin-left: 4px; }
.slot .ready.yes { color: var(--leaf-6); }
#btn-lobby-start:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.6); }
#btn-lobby-start.is-ready { border-color: var(--leaf-6); }
