/* Under the Mountain Gate — framed fantasy interface over the battlefield.
   Heavy frames, bevels and metal trim hold the controls; parchment carries
   the text. The frame material follows the race you play (body[data-race]):
   dwarves get dark granite with gold trim, orcs dark timber with bone trim. */

:root {
  --ink: #2b2016;
  --ink-soft: #5a4632;
  --parchment: #eadcbc;
  --parchment-dark: #d6c39a;
  --iron: #26221f;
  --iron-light: #3a342e;
  --gold: #c99a2e;
  --rare: #c9772e;
  --dwarf: #8fb4e0;
  --orc: #e08a6f;
  --ok: #4c7a34;
  --warn: #a2422e;
  --font-display: 'Cinzel', Georgia, serif;
  --font-body: 'Crimson Text', Georgia, serif;

  /* Theme (dwarves by default). */
  --frame-hi: #5d6570;
  --frame: #363c45;
  --frame-lo: #191c21;
  --trim: #e0b85a;
  --trim-mid: #a8822e;
  --trim-lo: #5a3f12;
  --accent: #e8b84a;
  --gem: #f08a2a;
  --text-on-frame: #efe6d0;
  --texture:
    radial-gradient(circle at 30% 40%, #ffffff0d 0 1.5px, transparent 2.5px) 0 0 / 23px 19px,
    radial-gradient(circle at 70% 70%, #0000002a 0 2px, transparent 3px) 0 0 / 31px 27px,
    radial-gradient(circle at 50% 20%, #ffffff08 0 3px, transparent 4px) 0 0 / 47px 41px;
}

body[data-race='orcs'] {
  --frame-hi: #6e4a2c;
  --frame: #432c1a;
  --frame-lo: #1f140b;
  --trim: #e2d4ac;
  --trim-mid: #a8966c;
  --trim-lo: #4e3e26;
  --accent: #d0452e;
  --gem: #d0283c;
  --texture:
    repeating-linear-gradient(0deg, transparent 0 6px, #0000002a 6px 7px, transparent 7px 13px, #ffffff0a 13px 14px),
    repeating-linear-gradient(90deg, transparent 0 140px, #00000040 140px 142px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #15110d;
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  user-select: none;
}

button { font-family: inherit; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 1100px;
}

.glyph { width: 1em; height: 1em; display: block; flex: none; }

/* ------------------------------------------------------------ shared frame pieces */
/* Frame material: the race's stone or timber, lit from above. */
.frame-bg, #topbar, #commandbar, .cmd-name, .toast, #tooltip .tip-head {
  background: var(--texture), linear-gradient(var(--frame-hi), var(--frame) 45%, var(--frame-lo));
}

/* Metal trim: a bright edge over a darker bevel. */
.trim-edge {
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--trim-mid), inset 0 1px 0 1px var(--trim);
}

/* Rivets on the four corners of a framed panel. */
.riveted::after {
  content: ''; position: absolute; inset: 3px; pointer-events: none;
  background:
    radial-gradient(circle at 5px 5px, var(--trim) 0 1.6px, var(--trim-lo) 2.4px, transparent 3px) top left / 10px 10px no-repeat,
    radial-gradient(circle at 5px 5px, var(--trim) 0 1.6px, var(--trim-lo) 2.4px, transparent 3px) top right / 10px 10px no-repeat,
    radial-gradient(circle at 5px 5px, var(--trim) 0 1.6px, var(--trim-lo) 2.4px, transparent 3px) bottom left / 10px 10px no-repeat,
    radial-gradient(circle at 5px 5px, var(--trim) 0 1.6px, var(--trim-lo) 2.4px, transparent 3px) bottom right / 10px 10px no-repeat;
}

/* Bevelled frame button (system buttons, stances, abilities). */
.sq, .stance, .ability, .tab {
  position: relative;
  color: var(--text-on-frame);
  background: linear-gradient(#ffffff1a, #0000 40%, #00000040), var(--frame);
  border: 1px solid #000;
  box-shadow: inset 0 0 0 1px var(--trim-lo), inset 0 1px 0 1px #ffffff26, inset 0 -2px 0 1px #00000060;
  transition: filter 0.08s, box-shadow 0.08s;
}
.sq:hover, .stance:hover, .ability.ok:hover, .tab:hover { filter: brightness(1.18); }
.sq:active, .stance:active, .ability.ok:active { box-shadow: inset 0 0 0 1px var(--trim-lo), inset 0 2px 4px 1px #000a; transform: translateY(1px); }

/* ------------------------------------------------------------ top bar */
#topbar {
  position: relative; z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 50px;
  padding: 0 10px;
  color: var(--text-on-frame);
  border-bottom: 1px solid #000;
  box-shadow: inset 0 -3px 0 var(--trim-mid), inset 0 -4px 0 var(--trim), 0 3px 8px #000a;
}
.res-group { display: flex; gap: 8px; }
.res.plate {
  display: flex; align-items: center; gap: 7px; padding: 3px 10px 3px 7px; min-width: 86px;
  background: linear-gradient(#00000080, #00000050);
  border: 1px solid #000; border-radius: 3px;
  box-shadow: inset 0 0 0 1px var(--trim-lo), 0 1px 0 #ffffff1a;
  line-height: 1.05; cursor: default; white-space: nowrap;
}
.res.plate .glyph { width: 24px; height: 24px; filter: drop-shadow(0 1px 1px #000); }
.res .v { display: block; font-size: 18px; font-weight: 600; text-shadow: 0 1px 2px #000; }
.res small { display: block; font-size: 12px; opacity: 0.75; }
#r-supply { --side: var(--mine, var(--dwarf)); }
.gold { color: #f6c958; }
.rare { color: #ffa45a; }
body[data-race='orcs'] .rare { color: #ff7a6a; }

.holds { display: flex; align-items: center; gap: 12px; font-family: var(--font-display); font-size: 12px; white-space: nowrap; min-width: 0; }
.hold { display: flex; flex-direction: column; gap: 2px; }
.hold.enemy { align-items: flex-end; }
.hold-name { font-size: 11px; line-height: 1; text-shadow: 0 1px 2px #000; letter-spacing: 0.5px; }
.hold-name small { margin-left: 4px; font: 12px var(--font-body); opacity: 0.8; letter-spacing: 0; }
.hold .bar {
  position: relative; width: 190px; height: 15px;
  background: linear-gradient(#000, #1a1612);
  border: 1px solid #000; border-radius: 2px;
  box-shadow: 0 0 0 1px var(--trim-mid), inset 0 1px 3px #000;
}
.hold .bar i {
  display: block; height: 100%; transition: width 0.25s;
  background: linear-gradient(#ffffff55, transparent 45%, #0000004d), var(--left, var(--dwarf));
}
.hold.enemy .bar i { background: linear-gradient(#ffffff55, transparent 45%, #0000004d), var(--right, var(--orc)); margin-left: auto; }
.hold .bar i.low { animation: barpulse 0.9s ease-in-out infinite; }
@keyframes barpulse { 50% { filter: brightness(1.6); } }
.hold .bar em {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 600 11px var(--font-body); font-style: normal; color: #fff; text-shadow: 0 0 2px #000, 0 1px 1px #000;
}
.medallion {
  position: relative; display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 8px;
  background: radial-gradient(ellipse at 50% 30%, #ffffff22, transparent 70%), var(--frame-lo);
  border: 1px solid #000; border-radius: 20px;
  box-shadow: 0 0 0 2px var(--trim-mid), 0 0 0 3px #000, inset 0 0 6px #000;
}
.medallion .crest .glyph { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px #000); }
.clock { font-size: 20px; color: #f6e7b8; min-width: 52px; text-align: center; text-shadow: 0 1px 2px #000; }

.sys { display: flex; align-items: center; gap: 5px; font-size: 13px; white-space: nowrap; }
.sys button { height: 30px; min-width: 32px; border-radius: 3px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.sys button .glyph { width: 17px; height: 17px; }
.sys button.cheat {
  padding: 0 8px; color: #f6c958; background: #0006; border: 1px dashed var(--trim-mid); box-shadow: none;
}
.sys button.cheat.ai { color: var(--orc); }
.sys button.blocked { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 10px #e0b040, inset 0 0 0 1px var(--trim); } }

/* ------------------------------------------------------------ battlefield */
#field { position: relative; flex: 1; min-height: 300px; }
#battlefield { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#battlefield:active { cursor: grabbing; }
/* Darken the corners a touch so the eye settles on the field (a CSS layer,
   so the browser composites it instead of the canvas repainting it). */
#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 75% 70% at 50% 55%, transparent 55%, rgba(8, 4, 0, 0.38));
}

/* Commander: a name plate with crest, and square ability icons below it. */
#commander {
  position: absolute; top: 32px; right: 10px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  pointer-events: auto;
}
.cmd-name {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 4px 14px 4px 4px; border: 1px solid #000; border-radius: 3px;
  font-family: var(--font-display); font-size: 11px; color: var(--text-on-frame); text-align: right;
  box-shadow: inset 0 0 0 1px var(--trim-mid), 0 3px 8px #000a;
}
.cmd-name img { width: 34px; height: 34px; border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-mid); }
.cmd-name b { display: block; font-size: 14px; color: #f6c958; text-shadow: 0 1px 2px #000; }
.cmd-abilities { display: flex; gap: 6px; }
.ability {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 78px; padding: 5px 4px 4px; border-radius: 3px;
  font-size: 12px; line-height: 1.1; opacity: 0.7;
  box-shadow: inset 0 0 0 1px var(--trim-lo), inset 0 1px 0 1px #ffffff26, 0 3px 8px #000a;
}
.ability.ok { opacity: 1; }
.ability.locked .ab-icon img { filter: grayscale(1) brightness(0.6); }
.ab-icon {
  position: relative; display: block; width: 52px; height: 52px; overflow: hidden;
  border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-mid);
}
.ability.ok .ab-icon { box-shadow: 0 0 0 1px var(--trim), 0 0 8px var(--accent); }
.ab-icon img { display: block; width: 100%; height: 100%; }
.ability .cd {
  position: absolute; inset: 0; pointer-events: none;
  background: conic-gradient(#000000b0 var(--cd, 0deg), transparent 0);
}
.ability .cd-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 600 18px var(--font-body); color: #fff; text-shadow: 0 0 3px #000, 0 1px 2px #000;
}
.ability .key, .stance .key {
  display: inline-block; min-width: 15px; padding: 0 3px;
  font: 600 11px/14px var(--font-body); text-align: center; color: #fff;
  background: #000c; border: 1px solid var(--trim-mid); border-radius: 2px;
}
.ab-icon .key { position: absolute; left: 1px; top: 1px; }
.ability .aname { display: block; font-family: var(--font-display); font-size: 10px; letter-spacing: 0.3px; color: var(--text-on-frame); }
.ability.summon { width: 170px; padding: 8px; font-family: var(--font-display); font-size: 12px; }
.ability.summon small { font-family: var(--font-body); font-size: 12px; opacity: 0.8; }
.ability.summon.ok { box-shadow: inset 0 0 0 1px var(--trim), 0 0 10px var(--accent); }

/* Event banners: a short feed at the top left, clear of the sites and commander. */
#toasts {
  position: absolute; top: 32px; left: 10px; width: 400px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none;
}
.toast {
  position: relative; max-width: 100%; padding: 4px 14px 4px 12px;
  color: var(--text-on-frame); font-size: 15px; line-height: 1.2; text-shadow: 0 1px 2px #000;
  border: 1px solid #000; border-left: 4px solid #9a927c;
  box-shadow: inset 0 0 0 1px var(--trim-lo), 0 2px 6px #000a;
  clip-path: polygon(0 0, 100% 0, calc(100% - 8px) 50%, 100% 100%, 0 100%);
  transition: opacity 0.6s;
}
.toast.mine { border-left-color: var(--mine, var(--dwarf)); }
.toast.theirs { border-left-color: var(--theirs, var(--orc)); }
.toast-warn { border-left-color: #e0b040; color: #ffd98a; }
.toast-ability, .toast-commander, .toast-longwar { font-family: var(--font-display); font-size: 13px; }
.toast.fade { opacity: 0; }

#paused {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #0008; cursor: pointer;
}
#paused .banner {
  padding: 10px 46px;
  font-family: var(--font-display); font-size: 30px; letter-spacing: 3px; color: #f6e7b8; text-shadow: 0 2px 3px #000;
  background: var(--texture), linear-gradient(var(--frame-hi), var(--frame) 45%, var(--frame-lo));
  border: 1px solid #000; box-shadow: inset 0 0 0 1px var(--trim-mid), inset 0 0 0 3px var(--frame-lo), 0 6px 20px #000;
  clip-path: polygon(0 0, 100% 0, calc(100% - 16px) 50%, 100% 100%, 0 100%, 16px 50%);
}
#paused { flex-direction: column; gap: 8px; }
#paused small { color: #efe2c4; font-size: 15px; text-shadow: 0 1px 2px #000; }

/* ------------------------------------------------------------ command bar */
#commandbar {
  position: relative; display: flex; gap: 8px; height: 220px; padding: 9px 9px 8px;
  border-top: 1px solid #000;
  box-shadow: inset 0 3px 0 var(--trim-mid), inset 0 4px 0 var(--trim), inset 0 10px 14px #0006;
}

/* Orders: framed console with three command buttons. */
#orders {
  position: relative; width: 220px; padding: 8px 10px; flex: none;
  background: linear-gradient(#0000004d, #00000026);
  border: 1px solid #000; border-radius: 3px;
  box-shadow: inset 0 0 0 1px var(--trim-lo), inset 0 2px 8px #000a;
  color: var(--text-on-frame);
}
#orders h3, #tabs { font-family: var(--font-display); }
#orders h3 { margin: 0 0 7px; font-size: 13px; letter-spacing: 2px; color: var(--trim); text-shadow: 0 1px 2px #000; text-align: center; }
.stances { display: flex; flex-direction: column; gap: 5px; }
.stance {
  display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 5px;
  font-family: var(--font-display); font-size: 14px; letter-spacing: 0.5px; text-align: left; border-radius: 3px;
}
.stance-icon {
  display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center;
  background: radial-gradient(#ffffff22, #0006); border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-lo);
}
.stance-icon .glyph { width: 22px; height: 22px; }
.stance-hold { --side: var(--mine, var(--dwarf)); }
.stance-label { flex: 1; }
.stance.active { color: #fff; box-shadow: inset 0 0 0 1px var(--trim), inset 0 0 12px #0008, 0 0 8px var(--accent); }
.stance.active .stance-icon { box-shadow: 0 0 0 1px var(--trim); }
.stance-advance.active { background: linear-gradient(#ffffff22, #0000 40%, #00000050), #7a2a1c; }
.stance-hold.active { background: linear-gradient(#ffffff22, #0000 40%, #00000050), #5a5a3a; }
.stance-retreat.active { background: linear-gradient(#ffffff22, #0000 40%, #00000050), #2d4a6b; }
.army-summary { cursor: default; margin-top: 8px; font-size: 13px; line-height: 1.25; color: var(--text-on-frame); opacity: 0.85; font-style: italic; text-align: center; }
.army-summary .pip { color: #f2c14e; font-size: 10px; font-style: normal; }

/* The command panel: parchment set into the frame. */
#panel {
  position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0;
  background:
    radial-gradient(ellipse at 25% 0%, #f6ecd3 0%, transparent 55%),
    radial-gradient(ellipse at 90% 100%, #c8b080 0%, transparent 50%),
    linear-gradient(var(--parchment), var(--parchment-dark));
  border: 1px solid #000; border-radius: 3px;
  box-shadow: 0 0 0 1px var(--trim-mid), 0 0 0 2px #000, inset 0 0 18px #6b4a2266;
}
#tabs { display: flex; gap: 3px; padding: 0 8px; margin-top: -1px; }
.tab {
  padding: 5px 18px 6px; font-size: 13px; letter-spacing: 1px; border-radius: 0 0 4px 4px;
  color: #d9ccb0;
}
.tab.active {
  color: #fff; padding-top: 7px;
  background: linear-gradient(#ffffff26, #0000 50%, #00000040), var(--frame-hi);
  box-shadow: inset 0 0 0 1px var(--trim), 0 2px 6px #0006;
}
#cards {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px; padding: 7px 10px 6px; overflow-y: auto; align-content: start;
}
.card {
  position: relative; display: flex; gap: 8px; align-items: center; text-align: left;
  min-height: 57px; padding: 4px 8px 4px 4px; overflow: hidden;
  background: linear-gradient(#fbf4e2, #efe2c2); border: 1px solid #8a7048; border-radius: 3px; color: var(--ink);
  box-shadow: 0 1px 0 #fff8 inset, 0 1px 2px #0003;
  transition: transform 0.08s, box-shadow 0.08s;
}
.card.ok { border-color: #5a4020; }
.card.ok:hover { transform: translateY(-1px); box-shadow: 0 4px 10px #0004, 0 0 0 1px var(--trim-mid); background: linear-gradient(#fffaf0, #f4e8cc); }
.card:active { transform: translateY(1px); }
.card:not(.ok) { background: linear-gradient(#efe6d2, #e2d4b4); }
.card .icon {
  position: relative; flex: none; width: 47px; height: 47px;
  border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-mid), 0 2px 3px #0006;
  background: #222;
}
.card.ok .icon { box-shadow: 0 0 0 1px var(--trim), 0 0 6px var(--trim-mid); }
.card .icon img { display: block; width: 100%; height: 100%; }
.card:not(.ok) .icon img { filter: saturate(0.55) brightness(0.85); }
.card .icon .glyph { display: none; }
.card.locked .icon img { filter: grayscale(1) brightness(0.45); }
.card.locked .icon .g-lock {
  display: block; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; transform: translate(-50%, -50%);
  color: #d9ccb0; filter: drop-shadow(0 1px 2px #000);
}
.card.locked .body { opacity: 0.6; }
.card.done .icon img { filter: saturate(0.4) brightness(0.7); }
.card.done .icon .g-check {
  display: block; position: absolute; right: 2px; bottom: 2px; width: 20px; height: 20px;
}
.card.done .title { color: var(--ink-soft); }
.card .body { min-width: 0; }
.card .title { font-family: var(--font-display); font-weight: 600; font-size: 13px; line-height: 1.15; letter-spacing: 0.2px; }
.card .cost { font-size: 14px; font-weight: 600; }
.card .sub { font-size: 13px; color: var(--ink-soft); line-height: 1.15; }
.card .gold, .q-group .gold { color: #8a5d00; }
.card .rare { color: #a8461a; }
body[data-race='orcs'] .card .rare { color: #a0202c; }
.dim { opacity: 0.75; font-weight: 400; }
.why { color: var(--warn); font-weight: 400; }
.card .badge {
  position: absolute; right: -1px; bottom: -1px; display: none; min-width: 18px; padding: 0 4px;
  font: 600 12px/16px var(--font-body); text-align: center; color: #fff;
  background: #000d; border: 1px solid var(--trim-mid);
}
.card .progress { position: absolute; left: 0; bottom: 0; width: 100%; height: 4px; background: #0000; }
.card .progress i { display: block; height: 100%; width: 0; background: linear-gradient(#b8e07a, #4c7a34); box-shadow: 0 0 4px #8fcf5a; }

/* production queue (bottom of the command panel) */
#queue {
  display: flex; align-items: center; gap: 14px; height: 34px; padding: 0 10px; flex: none;
  border-top: 1px solid #a88f60; background: #3a28100d; overflow: hidden; white-space: nowrap; font-size: 13px;
}
.q-label { font-family: var(--font-display); font-size: 11px; letter-spacing: 1px; color: var(--ink-soft); }
.q-empty { color: var(--ink-soft); font-style: italic; }
.q-group { display: inline-flex; align-items: center; gap: 4px; }
.q-now { position: relative; display: inline-block; width: 26px; height: 26px; }
.q-now img { width: 26px; height: 26px; border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-mid); }
.q-bar { position: absolute; left: 0; right: 0; bottom: -4px; height: 3px; background: #0004; }
.q-bar b { display: block; height: 100%; width: 0; background: linear-gradient(#b8e07a, #4c7a34); }
.q-name { margin: 0 3px 0 3px; font-weight: 600; }
.q-wait { width: 18px; height: 18px; border: 1px solid #000; opacity: 0.8; }

/* ------------------------------------------------------------ tooltip */
/* A framed header (icon, name, cost) over a parchment body. */
#tooltip {
  position: fixed; z-index: 50; max-width: 340px; pointer-events: none; overflow: hidden;
  background: linear-gradient(#f4ead2, #e4d4ae); color: var(--ink);
  border: 1px solid #000; border-radius: 3px;
  box-shadow: 0 0 0 1px var(--trim-mid), 0 0 0 2px #000, 0 8px 20px #000c;
  padding: 0 10px 8px; font-size: 14px; line-height: 1.25; opacity: 0; transition: opacity 0.1s;
}
#tooltip.show { opacity: 1; }
#tooltip > b:first-child {
  display: block; margin: 0 -10px 4px; padding: 5px 10px;
  background: var(--texture), linear-gradient(var(--frame-hi), var(--frame) 45%, var(--frame-lo));
  border-bottom: 1px solid var(--trim-mid);
}
#tooltip b { color: #6b2a1c; font-family: var(--font-display); font-size: 13px; }
#tooltip > b:first-child, #tooltip .tip-head b { color: #f6c958; font-size: 14px; text-shadow: 0 1px 2px #000; }
#tooltip .tip-head {
  display: flex; align-items: center; gap: 8px; margin: 0 -10px 4px; padding: 6px 10px;
  border-bottom: 1px solid var(--trim-mid); color: var(--text-on-frame);
}
#tooltip .tip-icon { width: 40px; height: 40px; border: 1px solid #000; box-shadow: 0 0 0 1px var(--trim-mid); flex: none; }
#tooltip .tip-line { display: block; font-size: 13px; margin-top: 1px; }
#tooltip .tip-head .gold { color: #f6c958; }
#tooltip .tip-head .rare { color: #ffa45a; }
#tooltip p { margin: 5px 0; }
#tooltip table { border-collapse: collapse; margin-top: 4px; width: 100%; }
#tooltip td { padding: 2px 8px 2px 0; vertical-align: top; border-top: 1px solid #b59f7466; }
#tooltip td:first-child { color: var(--ink-soft); font-family: var(--font-display); font-size: 11px; letter-spacing: 0.5px; padding-top: 4px; white-space: nowrap; }
#tooltip .gold { color: #8a5d00; font-weight: 600; }
#tooltip .rare { color: #a8461a; font-weight: 600; }
#tooltip .dim { color: var(--ink-soft); }

/* ------------------------------------------------------------ screens */
/* Title and end screens hide the battle HUD; the field fills the window. */
body[data-mode='title'] #topbar, body[data-mode='title'] #commandbar,
body[data-mode='title'] #commander, body[data-mode='title'] #toasts,
body[data-mode='end'] #topbar, body[data-mode='end'] #commandbar,
body[data-mode='end'] #commander, body[data-mode='end'] #toasts { display: none; }

/* ------------------------------------------------------------ overlays */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #0000 30%, #000a);
}
body[data-mode='title'] #overlay-start { align-items: flex-end; padding-bottom: 3vh; background: linear-gradient(#0000 35%, #000b); }
.hidden { display: none !important; }

/* A framed panel: frame material outside, parchment inside. */
.parchment {
  position: relative; width: min(880px, 94vw); padding: 0 34px 18px;
  background:
    radial-gradient(ellipse at 20% 0%, #f8eed6, transparent 60%),
    radial-gradient(ellipse at 90% 100%, #c8b080aa, transparent 55%),
    linear-gradient(var(--parchment), var(--parchment-dark));
  border: 1px solid #000; border-radius: 3px;
  box-shadow: 0 0 0 3px var(--frame), 0 0 0 4px var(--trim-mid), 0 0 0 5px #000, inset 0 0 24px #6b4a2255, 0 24px 60px #000c;
}
.parchment h1 {
  margin: 0 -34px 6px; padding: 12px 20px 10px; text-align: center;
  font-family: var(--font-display); font-weight: 800; font-size: 38px; letter-spacing: 3px;
  color: #f6d47a; text-shadow: 0 2px 0 #3a2208, 0 0 18px #000, 0 3px 6px #000;
  background: var(--texture), linear-gradient(var(--frame-hi), var(--frame) 50%, var(--frame-lo));
  border-bottom: 1px solid #000; box-shadow: inset 0 -2px 0 var(--trim-mid), inset 0 -3px 0 var(--trim);
}
.parchment h1::before, .parchment h1::after { content: '◆'; margin: 0 14px; font-size: 0.42em; vertical-align: middle; color: var(--trim); }

/* On the title, the game's name is a banner over the sky. */
#overlay-start h1 {
  position: fixed; top: 7vh; left: 50%; transform: translateX(-50%); margin: 0; white-space: nowrap;
  padding: 18px 70px 16px; font-size: 52px;
  border: 1px solid #000; box-shadow: inset 0 0 0 1px var(--trim-mid), inset 0 0 0 4px var(--frame-lo), inset 0 0 0 5px var(--trim-lo), 0 12px 30px #000c;
  clip-path: polygon(0 0, 100% 0, calc(100% - 26px) 50%, 100% 100%, 0 100%, 26px 50%);
}
body:not([data-mode='title']) #overlay-start h1 { position: static; transform: none; margin: 0 -34px 6px; font-size: 38px; padding: 12px 20px 10px; clip-path: none; box-shadow: inset 0 -2px 0 var(--trim-mid), inset 0 -3px 0 var(--trim); }
#overlay-start .parchment { padding-top: 14px; }
body:not([data-mode='title']) #overlay-start .parchment { padding-top: 0; }

.parchment h2 { margin: 0 0 2px; font-family: var(--font-display); font-size: 14px; letter-spacing: 1px; color: #6b2a1c; }
.race-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 6px 0 2px; font-size: 17px; }
.race-blurb { text-align: center; font-size: 14px; color: var(--ink-soft); margin: 4px 0 8px; min-height: 18px; }
.lede { text-align: center; font-style: italic; font-size: 17px; color: var(--ink-soft); margin: 8px 30px 10px; }
.howto { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 26px; font-size: 15px; padding: 10px 0 0; border-top: 1px solid #b59f7488; }
.howto p { margin: 0; }
.start-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; font-size: 17px; }
.seg { display: flex; box-shadow: 0 0 0 1px #000; border-radius: 3px; }
.seg button, .start-row button:not(.big) {
  padding: 6px 14px; font-size: 16px; color: var(--ink);
  background: linear-gradient(#fbf4e2, #e6d6b2); border: 1px solid #8a7048;
  box-shadow: inset 0 1px 0 #fff8;
}
.seg button + button { border-left: none; }
.seg button:first-child { border-radius: 3px 0 0 3px; }
.seg button:last-child { border-radius: 0 3px 3px 0; }
.seg button:hover, .start-row button:not(.big):hover { background: linear-gradient(#fffaf0, #efe2c4); }
.seg button.active {
  color: #f6e7b8; background: linear-gradient(#ffffff22, #0000 45%, #00000040), var(--frame);
  box-shadow: inset 0 0 0 1px var(--trim-mid);
}
.start-row button.big {
  font-family: var(--font-display); font-size: 19px; letter-spacing: 1px; padding: 9px 30px; border-radius: 3px;
  color: #fff4d6; text-shadow: 0 1px 2px #000;
  background: linear-gradient(#ffffff30, #0000 45%, #00000050), #7a2a1c;
  border: 1px solid #000; box-shadow: inset 0 0 0 1px var(--trim), 0 0 0 1px var(--trim-lo), 0 3px 8px #0006;
}
.start-row button.big:hover { filter: brightness(1.15); box-shadow: inset 0 0 0 1px var(--trim), 0 0 12px var(--accent); }
.fine { text-align: center; font-size: 13px; color: var(--ink-soft); margin: 12px 0 0; }

/* End screen: a compact panel beside the fallen stronghold. */
#overlay-end { justify-content: flex-start; padding: 0 5vw; background: linear-gradient(90deg, #0000 30%, #0008); }
#overlay-end.panel-right { justify-content: flex-end; }
#overlay-end:not(.panel-right) { background: linear-gradient(270deg, #0000 30%, #0008); }
#overlay-end .parchment { width: min(520px, 92vw); }
#overlay-end h1 { font-size: 46px; letter-spacing: 6px; }
#overlay-end.won h1 { color: #f6d47a; }
#overlay-end:not(.won) h1 { color: #e88a6a; text-shadow: 0 2px 0 #2a0a04, 0 0 18px #000, 0 3px 6px #000; }
#end-stats { margin: 6px auto 0; border-collapse: collapse; font-size: 16px; width: 100%; }
#end-stats th { font-family: var(--font-display); font-size: 13px; padding: 2px 12px; text-align: center; }
#end-stats td { padding: 3px 12px; text-align: center; border-top: 1px solid #b59f74; }
#end-stats td:first-child { text-align: left; color: var(--ink-soft); }

/* Shown only when the game's code fails to load or crashes. */
#load-error {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 1000;
  max-width: min(640px, calc(100vw - 32px)); padding: 12px 16px;
  background: #3a1410; color: #f6e7b8; border: 2px solid #a8822e; border-radius: 4px;
  font: 15px/1.45 Georgia, serif; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
#load-error.hidden { display: none; }
#load-error code { background: rgba(0, 0, 0, 0.35); padding: 0 4px; }
#load-error small { opacity: 0.8; }
