:root {
  --ink: #2a1b10;
  --parch: #f7e9c6;
  --parch-d: #e6d09c;
  --wood: #a8692f;
  --gold: #ffd23f;
  --mana: #5ec8ff;
  --red: #d6402f;
  --p0: #2f80ff;
  --p1: #ff3d3d;
  --font: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #56b2ef; color: var(--ink); font-family: 'Fredoka', system-ui, sans-serif; }
[hidden] { display: none !important; }
#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game { touch-action: none; }
#bg, #ui { pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 45%, rgba(30, 18, 8, 0.12) 25%, rgba(30, 18, 8, 0.62) 100%); overflow-y: auto; z-index: 10; }
/* the demo battle behind menus is calmer: desaturated and a little darker, so the panels read */
#stage { transition: filter .45s; }
body.menu-open #stage { filter: saturate(.5) brightness(.93); }
.panel {
  width: min(420px, 100%); background: var(--parch); border: 4px solid var(--ink); border-radius: 12px; padding: 22px 22px 18px;
  box-shadow: 0 8px 0 rgba(42, 27, 16, 0.55), inset 0 -6px 0 var(--parch-d); display: flex; flex-direction: column; gap: 10px; margin: auto;
}
.panel.wide { width: min(720px, 100%); }
.logo { font-family: var(--font); font-weight: 700; font-size: clamp(34px, 7vw, 52px); line-height: 1; margin: 0; text-align: center; color: #ffcf33;
  -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink), 0 6px 10px rgba(0,0,0,.25); letter-spacing: 1px; }
.logo .wordmark { display: block; width: min(100%, 340px); height: auto; margin: -6px auto 0; overflow: visible; }
.wm .wordmark { display: block; width: min(100%, 360px); height: auto; margin: -4px auto 0; overflow: visible; }
.wm.small .wordmark { width: min(60%, 200px); margin: 0 auto 4px; }
.panel.loading { text-align: center; }
.panel.loading p { margin: 6px 0 0; font-weight: 800; color: #7a5a3a; }
/* the bean, faintly, in a corner of the menu's demo battle and nowhere else */
#watermark { position: absolute; right: 2vmin; bottom: 2vmin; width: clamp(72px, 14vmin, 150px); opacity: .14; pointer-events: none; display: none; }
body.demo #watermark { display: block; }
.sub { text-align: center; font-weight: 800; color: #7a5a3a; margin-top: -4px; }
h2, h3 { font-family: var(--font); font-weight: 700; margin: 4px 0 0; }
h2 { font-size: 30px; }
h3 { font-size: 18px; color: #7a4a20; }
h3 small { font-family: 'Fredoka'; font-weight: 500; font-size: 13px; color: #8a6a4a; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 14px; }
input { font: 600 17px 'Fredoka', sans-serif; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; color: var(--ink); min-width: 0; }
input:focus { outline: 3px solid var(--gold); }
.big, .row button, .seg button, .invite-box button, .hist-list button, #replay-bar > button {
  font-family: var(--font); font-size: 20px; padding: 10px 16px; border: 3px solid var(--ink); border-radius: 14px;
  background: #fff3d6; box-shadow: 0 4px 0 var(--ink); transition: transform .06s, box-shadow .06s;
}
.big:active, .row button:active, .seg button:active, .invite-box button:active, .hist-list button:active, #replay-bar > button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.primary, .row button.primary { background: linear-gradient(#ffd85a, #f2a91f); }
.big:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; text-transform: uppercase; letter-spacing: 2px; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.link { background: none; border: 0; text-decoration: underline; font-weight: 800; color: #7a4a20; padding: 4px; }
.foot { font-size: 12px; color: #8a6a4a; text-align: center; margin: 4px 0 0; }
#invite { background: #fff3d6; border: 3px dashed var(--wood); border-radius: 14px; padding: 10px 12px; text-align: center; }
#invite p { margin: 0 0 8px; font-weight: 800; }
.hint { margin: 0; font-size: 14px; color: #7a5a3a; font-weight: 700; }

.factions, .maps { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.factions { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.factions .tile { gap: 3px; padding: 8px 6px; }
.factions .tile canvas.crest { width: 48px; height: 48px; border: 0; }
.factions .tile .roster { display: flex; gap: 1px; justify-content: center; }
.factions .tile .roster canvas { width: 26px; height: 26px; border: 0; }
.factions .tile .blurb { font-family: 'Fredoka'; font-weight: 500; font-size: 11.5px; line-height: 1.15; color: #6a4a2a; text-align: center; min-height: 2.3em; }
.factions .tile .q { font-family: var(--font); font-size: 40px; line-height: 48px; color: #7a4a20; }
.tile { border: 3px solid var(--ink); border-radius: 14px; background: #fff7e2; padding: 6px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font); font-size: 17px; box-shadow: 0 3px 0 var(--ink); }
.tile canvas { width: 64px; height: 64px; border-bottom: 4px solid var(--fc, transparent); border-radius: 0 0 4px 4px; }
.tile.on { background: linear-gradient(#ffe48a, #ffc23a); outline: 3px solid #fff; outline-offset: -6px; }
.tile:disabled { cursor: default; }
.maps .tile { font-size: 16px; padding: 12px 6px; }
.maps .tile small { font-family: 'Fredoka'; font-weight: 500; font-size: 12px; color: #7a5a3a; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; font-size: 17px; }
.seg button.on { background: linear-gradient(#ffe48a, #ffc23a); }

.invite-box { display: flex; gap: 6px; }
.invite-box input { flex: 1; font-size: 14px; }
.invite-box button { font-size: 16px; padding: 8px 12px; }
.code { font-family: var(--font); background: var(--ink); color: var(--gold); padding: 2px 10px; border-radius: 8px; letter-spacing: 3px; font-size: 22px; vertical-align: middle; }
.players { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.vs { font-family: var(--font); font-size: 22px; color: var(--red); -webkit-text-stroke: 1px var(--ink); }
.pcard { border: 3px solid var(--ink); border-radius: 14px; padding: 8px; background: #fff7e2; display: flex; align-items: center; gap: 8px; min-height: 76px; }
.pcard canvas { width: 56px; height: 56px; flex: none; }
.pcard .who { display: flex; flex-direction: column; min-width: 0; }
.pcard .who b { font-family: var(--font); font-weight: 700; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .who span { font-size: 13px; font-weight: 800; color: #7a5a3a; }
.pcard.p0 { border-left: 10px solid var(--p0); }
.pcard.p1 { border-left: 10px solid var(--p1); }
.pcard .ready { color: #2c9a3a; }
.pcard.empty { justify-content: center; color: #8a6a4a; font-weight: 800; border-style: dashed; }
.teamcol { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.teamname { font-family: var(--font); font-size: 16px; color: #fff; -webkit-text-stroke: 0.6px var(--ink); text-shadow: 0 2px 0 var(--ink); }
.teamcol.t0 .teamname { color: var(--p0); }
.teamname .seat-swap { font: 600 12px/1 var(--font); -webkit-text-stroke: 0; text-shadow: none; color: var(--ink); vertical-align: middle; }
.teamcol.t1 .teamname { color: var(--p1); }
.pcard { position: relative; flex-wrap: wrap; }
.pcard.empty { flex-direction: column; }
.seatctl { display: flex; gap: 4px; flex-wrap: wrap; width: 100%; }
.seatctl button { font-size: 12px; padding: 2px 8px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; font-weight: 800; text-transform: capitalize; }
.chat { border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; display: flex; flex-direction: column; }
#chat-log { height: 72px; overflow-y: auto; padding: 6px 10px; font-size: 14px; font-weight: 700; }
.chat input { border: 0; border-top: 2px solid var(--parch-d); border-radius: 0 0 10px 10px; font-size: 14px; width: 100%; }
.help ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-weight: 600; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 8px; padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); pointer-events: none; }
#topbar > * { pointer-events: auto; }
#res { display: flex; flex-direction: column; gap: 3px; flex: none; }
.res { display: flex; align-items: center; gap: 4px; background: rgba(42, 27, 16, 0.82); border-radius: 10px; padding: 2px 10px 2px 4px; color: #fff; font-family: var(--font); font-size: 18px; min-width: 90px; }
.res i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.gold i { background: radial-gradient(circle at 35% 35%, #fff2a8, #f2c230 55%, #c3901a); }
.mana i { background: radial-gradient(circle at 35% 35%, #e6f7ff, #5ec8ff 55%, #2a7fbf); }
.workers i { background: radial-gradient(circle at 50% 40%, #f4c9a1 45%, #7b4a28 46%); }
.res small { font-size: 12px; color: #a8dcff; margin-left: 2px; }
.res.intel { font-size: 13px; padding-left: 10px; color: #cfe6ff; }
.res[hidden] { display: none; }
/* treasury factions (Israel): a gauge under the gold, 0 to twice the treasury floor, with the floor marked at its middle;
   the readout glows while gold above the floor flows into a finished Treasury */
.res.gold { position: relative; }
.res.gold .floor { position: absolute; left: 26px; right: 8px; bottom: 2px; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); }
.res.gold .floor[hidden] { display: none; }
.res.gold .floor span { display: block; height: 100%; width: 0; border-radius: 2px; background: #f2c230; }
.res.gold .floor::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: #fff6d8; border-radius: 1px; }
.res.gold.banking { box-shadow: 0 0 0 2px #7fd0ff, 0 0 12px 2px rgba(127, 208, 255, 0.75); animation: bank 1.6s ease-in-out infinite; }
@keyframes bank { 50% { box-shadow: 0 0 0 2px #7fd0ff, 0 0 4px 1px rgba(127, 208, 255, 0.4); } }
@media (prefers-reduced-motion: reduce) { .res.gold.banking { animation: none; } }
#buttons { display: flex; gap: 5px; flex: 1; overflow-x: auto; overflow-y: hidden; padding: 0 2px 8px; scrollbar-width: none; }
#buttons::-webkit-scrollbar { display: none; }
.btn { position: relative; flex: none; width: 62px; height: 70px; border: 3px solid var(--ink); border-radius: 12px; padding: 0;
  background: linear-gradient(#fff8e4 55%, #f0dcae 55%, #f0dcae 82%, var(--fc, #a8692f) 82%);
  box-shadow: 0 3px 0 var(--ink), inset 0 2px 0 rgba(255,255,255,.7); overflow: hidden; touch-action: manipulation; }
.btn.gap { margin-left: 10px; }
.btn.spell { background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--fc, #3e6ec8) 35%, #fff8e4) 0 45%, color-mix(in srgb, var(--fc, #3e6ec8) 70%, #1d1b2a) 100%); }
.btn canvas { width: 52px; height: 52px; display: block; margin: 1px auto 0; pointer-events: none; }
/* the cost sits inside the icon as a chip with a coin or a mana drop */
.btn .cost { position: absolute; left: 50%; transform: translateX(-50%); bottom: 2px; display: flex; align-items: center; gap: 2px; padding: 0 5px 0 3px; border-radius: 8px;
  background: rgba(42,27,16,.86); border: 1.5px solid var(--ink); font-family: var(--font); font-size: 13px; line-height: 15px; color: #fff; pointer-events: none; white-space: nowrap; }
.btn .cost:empty { display: none; }
.btn .cost::before { content: ''; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); flex: none; }
.btn .cost.g { color: var(--gold); }
.btn .cost.g::before { background: radial-gradient(circle at 35% 35%, #fff2a8, #f2c230 60%, #c3901a); }
.btn .cost.m { color: #9fe0ff; }
.btn .cost.m::before { background: radial-gradient(circle at 35% 35%, #e6f7ff, #5ec8ff 60%, #2a7fbf); }
/* cooldown and research progress: a clockwise sweep */
.btn .cdo { position: absolute; inset: 0; background: conic-gradient(rgba(20, 12, 6, 0.6) calc(var(--cd, 0) * 1turn), transparent 0); pointer-events: none; }
.btn .key { position: absolute; top: 1px; left: 4px; font-size: 11px; font-weight: 800; color: rgba(42,27,16,.65); pointer-events: none; }
.btn .lock { display: none; position: absolute; inset: 0; background: rgba(42, 27, 16, 0.42); pointer-events: none; color: #fff; font-family: var(--font); font-size: 13px;
  align-items: flex-end; justify-content: center; padding-bottom: 2px; }
.btn .lock::before { content: ''; position: absolute; top: 14px; left: 50%; width: 18px; height: 14px; margin-left: -9px; background: var(--gold); border: 2px solid var(--ink); border-radius: 3px; }
.btn .lock::after { content: ''; position: absolute; top: 5px; left: 50%; width: 10px; height: 12px; margin-left: -7px; border: 2px solid var(--ink); border-bottom: 0; border-radius: 8px 8px 0 0; box-shadow: inset 0 0 0 2px var(--gold); }
.btn.locked .lock { display: flex; }
.btn.locked .cost { display: none; }
.btn.unavailable { filter: grayscale(1) brightness(.8); }
.btn.unavailable::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, rgba(42,27,16,.32) 0 4px, transparent 4px 9px); pointer-events: none; }
.btn.researching .lock::before, .btn.researching .lock::after { display: none; }
.btn.researching .lock { background: rgba(42, 27, 16, 0.35); }
.btn.poor canvas { filter: grayscale(.85); opacity: .6; }
.btn.poor .cost { color: #ff8a7a !important; }
.btn.armed { outline: 3px solid #fff; outline-offset: -6px; background: linear-gradient(#fff6b0, #ffd23f); }
.btn.done { display: none; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#side { display: flex; flex-direction: column; gap: 6px; flex: none; }
.mini { width: 44px; height: 44px; border: 3px solid var(--ink); border-radius: 12px; background: linear-gradient(#fff8e4, #f0dcae); font-size: 22px; box-shadow: 0 3px 0 var(--ink); }
#route { background: linear-gradient(#d8ffd0, #8fd67a); }
/* the route's state: a tag left of the route button (out of the layout, over the sky); on narrow screens, where a second
   row of HUD buttons sits there, it stacks under the side buttons instead. A click on it switches the path too. */
#side { position: relative; }
#route-tag { position: absolute; right: calc(100% + 6px); top: 72px; transform: translateY(-50%); display: flex; align-items: center; gap: 6px;
  white-space: nowrap; background: rgba(42, 27, 16, 0.82); color: #fff; font-family: var(--font); font-size: 15px; line-height: 1; padding: 4px 5px 4px 10px;
  border-radius: 10px; cursor: pointer; }
#route-tag[hidden] { display: none; }
#route-tag b { font-weight: 600; }
#route-tag kbd { font: 800 11px/1 var(--font); color: var(--ink); background: #fff6d8; border: 1.5px solid var(--ink); border-radius: 5px; padding: 2px 5px; }
.no-hotkeys #route-tag kbd { display: none; }
@media (max-width: 600px) {
  #route-tag { position: static; transform: none; white-space: normal; text-align: center; justify-content: center; font-size: 11px; padding: 3px 2px; width: 44px; box-sizing: border-box; }
  #route-tag kbd { display: none; }
}


#minimap { position: absolute; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(600px, 80vw); height: 44px; touch-action: none; filter: drop-shadow(0 3px 0 rgba(42,27,16,.45)); }
#minimap canvas { width: 100%; height: 100%; display: block; }
#tip { position: absolute; z-index: 20; max-width: 240px; background: var(--parch); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px; font-size: 13px; font-weight: 700; pointer-events: none; box-shadow: 0 4px 0 rgba(42,27,16,.5); }
#tip b { font-family: var(--font); font-weight: 700; font-size: 17px; display: block; }
#tip .stats { color: #7a4a20; margin-top: 4px; }
#banner { position: absolute; top: calc(var(--top-h, 76px) + 36px); left: 50%; transform: translateX(-50%); background: rgba(42,27,16,.85); color: #fff; font-weight: 800; padding: 6px 14px; border-radius: 10px; pointer-events: none; text-align: center; }
#chat-form { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); width: min(420px, 90vw); }
#chat-form input { width: 100%; }
#toast { position: fixed; left: 50%; bottom: 66px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: rgba(42,27,16,.9); color: #fff; font-weight: 800; padding: 7px 14px; border-radius: 10px; animation: fade 3.2s forwards; text-align: center; max-width: 90vw; }
@keyframes fade { 0% { opacity: 0; transform: translateY(6px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

@media (max-height: 480px) {
  .btn { width: 50px; height: 56px; }
  .btn canvas { width: 40px; height: 40px; }
  .res { font-size: 15px; min-width: 76px; }
  .mini { width: 44px; height: 44px; font-size: 18px; }   /* still a full touch target */
  #minimap { height: 34px; }
}
/* phones: five-unit rosters give 7 unit-row buttons; slimmer buttons keep that row to 4 + 3 instead of 3 + 3 + 1 */
@media (max-width: 420px) {
  .btn { width: 46px; height: 54px; border-radius: 10px; }
  .btn canvas { width: 40px; height: 40px; }
  .btn .key { font-size: 10px; left: 3px; }
  .btn.gap { margin-left: 6px; }
}

/* ---------- release: menu, lobby, HUD and overlays ---------- */
body { touch-action: manipulation; }   /* no double-tap zoom */
input, select { font-size: max(16px, 1em); }   /* iOS zooms into anything smaller on focus */
select { font: 600 16px 'Fredoka', sans-serif; padding: 8px 10px; border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; color: var(--ink); }
a { color: #7a2a1c; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 10px; }
.links .link { text-decoration: underline; }
.quick { align-items: stretch; }
.quick #btn-quick { flex: 1; }
.quick .seg { flex: none; }
.quick .seg button { padding: 6px 10px; }
#open-rooms h3 { margin: 4px 0; font-size: 16px; }
#room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.room { width: 100%; display: grid; grid-template-columns: 1fr auto; grid-template-areas: 'host go' 'meta go'; text-align: left; align-items: center; gap: 0 8px;
  border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; padding: 6px 10px; box-shadow: 0 3px 0 var(--ink); min-height: 48px; }
.room b { grid-area: host; font-family: var(--font); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room span { grid-area: meta; font-size: 13px; font-weight: 700; color: #7a5a3a; }
.room i { grid-area: go; font-style: normal; font-family: var(--font); background: linear-gradient(#ffd85a, #f2a91f); border: 2px solid var(--ink); border-radius: 10px; padding: 4px 12px; }
.foot a { color: inherit; }

.tile .thumb { width: 100%; height: auto; max-width: 168px; aspect-ratio: 192 / 72; border: 2px solid var(--ink); border-radius: 8px; margin-bottom: 4px; }
.maps .tile { padding: 8px 6px 10px; }

.invite { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.invite-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
#invite-link { font-family: var(--font); font-size: clamp(16px, 2.6vw, 21px); letter-spacing: .5px; cursor: copy; background: #fff; }
.invite-box { flex-wrap: wrap; }
.invite-box button { flex: 1 1 auto; }
.qr { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.qr canvas { border: 3px solid var(--ink); border-radius: 10px; image-rendering: pixelated; background: #fffaf0; }
.qr figcaption { font-size: 12px; font-weight: 800; color: #7a5a3a; }
@media (max-width: 560px) { .invite { grid-template-columns: 1fr; } .qr canvas { width: 140px !important; height: 140px !important; } }
#lobby-wait { display: flex; align-items: center; gap: 10px; background: #fff3d6; border: 3px dashed var(--wood); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
#lobby-wait b { font-family: var(--font); font-size: 17px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 4px solid var(--parch-d); border-top-color: var(--ink); animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(1turn); } }
.reduce-motion .spinner { animation-duration: 3s; }
.host-tools { display: flex; flex-direction: column; gap: 8px; border: 3px solid var(--parch-d); border-radius: 12px; padding: 8px 10px; }
.host-tools .row { flex-wrap: wrap; }
.host-tools .row button { font-size: 15px; padding: 6px 10px; flex: 1 1 auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.check input { width: 22px; height: 22px; accent-color: #f2a91f; }
.pcard .mute { position: absolute; top: 4px; right: 4px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; font-size: 14px; width: 30px; height: 30px; padding: 0; }
button:disabled { opacity: .55; cursor: default; }

/* HUD extras */
#clock { position: absolute; top: calc(var(--top-h, 76px) + 34px); left: 50%; transform: translateX(-50%); font-family: var(--font); font-size: 15px; color: #fff;
  background: rgba(42,27,16,.7); border-radius: 8px; padding: 0 8px; pointer-events: none; font-variant-numeric: tabular-nums; }
#banner { top: calc(var(--top-h, 76px) + 60px); }
/* the Wonder: the pyramid bars under the clock (both players see them), the stone control after the worker button,
   the Pharaoh's portrait beside your bar, and the stage-4 warning banner */
#wonder { position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--top-h, 76px) + 58px); width: min(460px, 86vw); display: flex;
  flex-direction: column; gap: 4px; pointer-events: none; }
#wonder[hidden] { display: none; }
body.has-wonder #banner { top: calc(var(--top-h, 76px) + 112px); }
.wbar { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 6px; align-items: center; pointer-events: auto; }
.wbar .wlabel { grid-column: 2; display: flex; justify-content: space-between; gap: 8px; font-family: var(--font); font-size: 13px; color: #fff;
  text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); white-space: nowrap; overflow: hidden; }
.wbar .wlabel span { overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.wbar .wtrack { grid-column: 2; display: flex; gap: 2px; height: 12px; padding: 2px; border: 2px solid var(--ink); border-radius: 7px; background: rgba(42,27,16,.75); }
.wbar .wseg { position: relative; flex-basis: 0; background: #5a4a36; border-radius: 3px; overflow: hidden; }
.wbar .wseg i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(#f3d98c, #d9a92e); transition: width .25s; }
.wbar.t1 .wseg i { background: linear-gradient(#f3d98c, #c98a2e); }
.wbar.t0 .wtrack { box-shadow: 0 0 0 2px var(--p0); } .wbar.t1 .wtrack { box-shadow: 0 0 0 2px var(--p1); }
.wbar.near .wseg:last-child { background: #7a5a26; animation: wnear 1s ease-in-out infinite alternate; }
@keyframes wnear { to { background: #c9902e; } }
.wbar.sealed .wtrack { border-color: #ffe08a; background: rgba(120,92,20,.8); }
.wbar.paused .wseg i { filter: grayscale(.8) brightness(.8); }
.wbar.setting .wseg i { animation: wset 1.2s ease-in-out infinite alternate; }
@keyframes wset { to { filter: brightness(1.25); } }
.wbar.hurt .wtrack { animation: whurt .45s; }
@keyframes whurt { 0%, 60% { background: rgba(200,50,30,.9); } }
.keeper { grid-row: 1 / span 2; grid-column: 1; position: relative; width: 44px; height: 44px; padding: 0; border: 3px solid var(--ink); border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #f6e7b8, #d9a92e); overflow: hidden; box-shadow: 0 2px 0 var(--ink); touch-action: manipulation; }
.keeper canvas { width: 40px; height: 40px; display: block; margin: 0 auto; pointer-events: none; }
.keeper::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: linear-gradient(90deg, #6bd36b var(--hp, 0%), transparent var(--hp, 0%)); }
.keeper span { position: absolute; inset: auto 0 2px 0; text-align: center; font: 700 12px/1 var(--font); color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); pointer-events: none; }
.keeper.dead canvas, .keeper.locked canvas, .keeper.cd canvas { filter: grayscale(1) brightness(.75); }
.keeper.dead { background: #6a6258; }
.keeper.dead span { font-size: 14px; color: #ffd0b0; }
.haul { flex: none; display: flex; align-items: stretch; height: 70px; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; background: #f0dcae;
  box-shadow: 0 3px 0 var(--ink); margin-left: 4px; }
.haul .hb { width: 30px; border: 0; padding: 0; font: 700 24px/1 var(--font); color: var(--ink); background: #fff3d6; touch-action: manipulation; }
.haul .hb:active { background: #f2c230; }
.haul .hv { width: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; border-inline: 2px solid var(--ink);
  background: linear-gradient(#e8cf98, #c9a565); }
.haul .hv i { width: 20px; height: 13px; border: 2px solid var(--ink); border-radius: 2px; background: linear-gradient(#efd9a2 45%, #c9a565 45%); }
.haul .hv b { font: 700 16px/1 var(--font); color: var(--ink); font-variant-numeric: tabular-nums; }
.haul.far .hv i { width: 18px; height: 14px; border: 0; border-radius: 0; background: radial-gradient(circle at 50% 60%, #ffe38a 0 35%, #f2c230 36% 60%, transparent 61%); filter: drop-shadow(0 0 2px #fff3b0); }
.haul.far.alert { animation: far-alert 0.6s ease-in-out infinite alternate; }
@keyframes far-alert { to { border-color: #d2382a; box-shadow: 0 0 0 3px #d2382a; } }
@media (prefers-reduced-motion: reduce) { .haul.far.alert { animation: none; border-color: #d2382a; } }
.haul .hv small { font: 700 10px/1 var(--font); color: #5a3a14; text-transform: uppercase; letter-spacing: .4px; }
#wonder-warn { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); z-index: 8; pointer-events: none; text-align: center; padding: 12px 22px;
  background: rgba(42,27,16,.88); border: 3px solid #ffd96a; border-radius: 16px; box-shadow: 0 0 30px rgba(255,214,90,.55); }
#wonder-warn[hidden] { display: none; }
#wonder-warn b { display: block; font: 700 clamp(20px, 4vw, 34px)/1.1 var(--font); color: #ffe08a; text-shadow: 0 2px 0 var(--ink); }
#wonder-warn small { display: block; margin-top: 4px; font-weight: 800; color: #fff; font-size: 14px; }
#wonder-warn.pop { animation: wpop .5s ease-out; }
@keyframes wpop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@media (max-width: 600px) {
  .haul { height: 54px; border-radius: 10px; }
  .wbar .wlabel { font-size: 11px; }
}
@media (pointer: coarse) { .haul .hb { width: 44px; } .haul .hv { width: 44px; } }
@media (max-height: 480px) { .haul { height: 56px; } }
#spec-badge { position: absolute; left: max(8px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); background: rgba(42,27,16,.85); color: #fff;
  font-family: var(--font); padding: 6px 12px; border-radius: 10px; pointer-events: none; }
body.spectating #buttons, body.spectating #res { visibility: hidden; }
#coach { position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--top-h, 76px) + 64px); width: min(460px, 92vw); background: var(--parch);
  border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px 6px; box-shadow: 0 4px 0 rgba(42,27,16,.5); }
#coach small { font-weight: 800; color: #a8692f; text-transform: uppercase; letter-spacing: .5px; font-size: 11px; }
#coach p { margin: 2px 0 2px; font-weight: 700; font-size: 15px; }
#coach .link { font-size: 13px; padding: 2px 0; }
#coach.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.92); } to { transform: translateX(-50%) scale(1); } }
#wheel { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 6; }
#wheel button { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%) rotate(var(--a)) translate(92px) rotate(calc(-1 * var(--a)));
  min-width: 76px; min-height: 44px; font-family: var(--font); font-size: 17px; border: 3px solid var(--ink); border-radius: 22px; background: #fff3d6; box-shadow: 0 3px 0 var(--ink); }
#wheel button.type { transform: translate(-50%, -50%); background: linear-gradient(#ffd85a, #f2a91f); }
#keys-help { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(30,18,8,.45); pointer-events: none; }
.keys-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 16px; }
#keys-help .panel { width: min(720px, 94vw); }
.krow { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
kbd, .kbtn { font-family: var(--font); min-width: 30px; text-align: center; padding: 2px 8px; border: 2px solid var(--ink); border-radius: 7px; background: #fffaf0; box-shadow: 0 2px 0 var(--ink); }
.kbtn { min-height: 34px; }
.kbtn.wait { background: var(--gold); }
#hotkeys { border: 3px solid var(--parch-d); border-radius: 12px; padding: 6px 10px; }
#hotkeys summary { font-family: var(--font); font-size: 17px; cursor: pointer; }
#hotkeys .keys-grid { margin: 8px 0; max-height: 40vh; overflow-y: auto; }

/* pause, over, settings */
.confirm { background: #ffe1d9; border: 3px solid var(--red); border-radius: 14px; padding: 8px 10px; text-align: center; }
.confirm p { margin: 0 0 6px; font-weight: 800; }
.confirm .row button { flex: 1; }
.danger { background: linear-gradient(#ff8a72, #d6402f) !important; color: #fff; }
.danger-link { background: none; border: 0; color: var(--red); text-decoration: underline; font-weight: 800; margin-right: auto; }
.mutes { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; }
#card { width: 100%; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 4px 0 rgba(42,27,16,.4); }
#over-wonder { width: 100%; aspect-ratio: 560 / 300; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 4px 0 rgba(42,27,16,.4); display: block; margin: 0 0 8px; }
#over-wonder[hidden] { display: none; }
.share-row button { flex: 1; font-size: 16px; }
#rematch-opts { display: flex; align-items: end; gap: 10px; }
#rematch-opts .field { flex: 1; }

/* the crash overlay (errors.js) */
#crash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(30,18,8,.7); }
#crash .panel { width: min(560px, 100%); }
#crash pre { max-height: 40vh; overflow: auto; background: #fffaf0; border: 2px solid var(--ink); border-radius: 10px; padding: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 0; }

/* touch screens: every control at least 44 px */
@media (pointer: coarse) {
  .link, .seatctl button, .danger-link, .pcard .mute, .kbtn, .invite-box button, .host-tools .row button, .row button, .seg button { min-height: 44px; }
  .pcard .mute { min-width: 44px; }
  .seatctl button { padding: 4px 10px; font-size: 14px; }
  .mini { width: 44px; height: 44px; }
}
@media (max-height: 480px) and (pointer: coarse) { .mini { width: 44px; height: 44px; } }
/* portrait phones: the lane is a strip at the bottom, so toasts sit under the clock instead of over the fight */
@media (orientation: portrait) and (max-width: 600px) {
  #toast { top: calc(var(--top-h, 76px) + 64px); bottom: auto; }
  #toast div { font-size: 14px; padding: 5px 12px; }
}
/* touch: the menu's text links and the footer link get full 44 px targets without changing the layout */
@media (pointer: coarse) {
  .links .link, .links a, #coach .link, #crash .link { min-height: 44px; display: inline-flex; align-items: center; box-sizing: border-box; }
  .foot a { display: inline-block; padding: 15px 6px; margin: -15px -6px; }
  .seatctl button { min-width: 44px; }
  .chat input, #chat-input { min-height: 44px; }
  label.check { min-height: 44px; }   /* the whole label is the tap target for its checkbox */
}
/* chat bubbles over the castles during a match */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.bubble { position: absolute; transform: translate(-50%, -100%); max-width: min(240px, 60vw); background: #fffaf0; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px; padding: 4px 10px; font-weight: 700; font-size: 14px; line-height: 1.25;
  box-shadow: 0 3px 0 var(--ink); animation: bubble 5s forwards; white-space: normal; overflow-wrap: anywhere; }
.bubble b { display: block; font-size: 11px; }
.bubble.t0 b { color: var(--p0); } .bubble.t1 b { color: var(--p1); } .bubble.spec { transform: translate(-50%, 0); opacity: .9; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -9px; width: 12px; height: 12px; background: #fffaf0;
  border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: translateX(-50%) rotate(45deg); }
.bubble.spec::after { display: none; }
@keyframes bubble { 0% { opacity: 0; } 6% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
/* the tutorial's highlighted control */
.coach-hl { outline: 4px solid #ffb92e; outline-offset: 3px; border-radius: 12px; animation: coach-hl 1s ease-in-out infinite; position: relative; z-index: 3; }
@keyframes coach-hl { 50% { outline-color: #fff3d6; box-shadow: 0 0 0 8px rgba(255,185,46,.35); } }
#coach .row { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
#help-tut { width: 100%; margin-bottom: 8px; }
/* history */
.hist-rates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 8px 0; }
.hist-rates div { border: 3px solid var(--ink); border-radius: 12px; padding: 6px 8px; background: #fffaf0; display: grid; grid-template-columns: 36px 1fr; gap: 0 8px; align-items: center; }
.hist-rates canvas { width: 36px; height: 36px; grid-row: span 2; }
.hist-rates b { font-size: 15px; } .hist-rates small { font-weight: 700; color: #6a4a2a; }
.hist-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 46vh; overflow: auto; }
.hist-list li { display: flex; gap: 8px; align-items: center; justify-content: space-between; border: 2px solid var(--ink); border-radius: 10px; padding: 4px 4px 4px 10px; background: #fffaf0; font-weight: 700; font-size: 14px; }
.hist-list li.win { border-left: 8px solid #3fa34d; } .hist-list li.loss { border-left: 8px solid #c8412a; }
.hist-list li span { flex: 1; } .hist-list li small { color: #6a4a2a; display: block; font-weight: 600; }
.hist-list li button { min-height: 44px; }
.drop label.link { display: inline-flex; align-items: center; min-height: 44px; }
.drop { border: 3px dashed #a8692f; border-radius: 12px; padding: 12px; text-align: center; margin-top: 10px; font-weight: 700; }
body.dragging .drop, body.dragging #drop-zone { background: #ffe9b8; }
/* replay controls */
#replay-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px); z-index: 7;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; width: min(720px, 94vw); background: var(--parch, #fff3d6);
  border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px; box-shadow: 0 3px 0 var(--ink); font-weight: 800; }
#replay-bar > button, #replay-bar .seg button { min-height: 44px; min-width: 44px; }
#rp-scrub { flex: 1 1 160px; min-height: 44px; }
body.replaying #buttons, body.replaying #res, body.replaying #route, body.replaying #route-tag, body.replaying #gift-btn, body.replaying #wheel-btn { visibility: hidden; }
#replay-bar > button, .hist-list button { font-size: 15px; padding: 4px 12px; }
/* portrait phones: the lane is the strip at the bottom, so the replay controls sit in the sky under the clock */
@media (orientation: portrait) and (max-width: 600px) {
  #replay-bar { bottom: auto; top: calc(var(--top-h, 76px) + 70px); }
}
.maps .map-group { grid-column: 1 / -1; margin: 4px 0 -2px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: #a8692f; }
/* the Codex's (i) on faction cards, and the "What's new" badge */
.factions .tile { position: relative; }
.factions .tile .info { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 50%;
  background: #fff; font: italic 700 16px Georgia, serif; color: var(--ink); box-shadow: 0 2px 0 var(--ink); }
.factions .tile .info:hover { background: #ffe48a; }
@media (pointer: coarse) { .factions .tile .info { width: 36px; height: 36px; top: 2px; right: 2px; } }
.link.notes.fresh::after { content: 'new'; margin-left: 4px; padding: 1px 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; text-decoration: none; display: inline-block; }

/* ---------- the main menu: one card, three big buttons, a player chip and a footer ---------- */
#menu { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding-top: max(16px, env(safe-area-inset-top)); }
body.menu-home #stage { filter: blur(2.5px) saturate(.65) brightness(.72); }
.menu-card { width: min(440px, 100%); gap: 10px; padding: 16px 18px; border-radius: 12px; margin: 0; }
.menu-card .logo .wordmark { width: min(100%, 250px); margin-top: -4px; }
.menu-card .sub { margin: -6px 0 2px; font-size: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 26px; }
.back-arrow { flex: none; width: 48px; height: 48px; border: 3px solid var(--ink); border-radius: 12px; background: #fff7e2; box-shadow: 0 3px 0 var(--ink);
  font: 700 24px var(--font); display: grid; place-items: center; padding: 0; }
.back-arrow:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
/* the three primary actions: equal size, icon + label + one-line subtitle; Play is the one filled button */
.mbtns { display: grid; gap: 10px; }
.mbtn { display: grid; grid-template-columns: 52px 1fr auto; grid-template-areas: 'i t k' 'i s k' 'i x k'; align-items: center; gap: 0 12px; min-height: 76px;
  padding: 8px 14px 8px 10px; text-align: left; border: 3px solid var(--ink); border-radius: 12px; background: #fff7e2; box-shadow: 0 4px 0 var(--ink); }
.mbtn.primary { background: linear-gradient(#ffd85a, #f2a91f); }
.mbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.mbtn .mico { grid-area: i; font-size: 32px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.mbtn b { grid-area: t; font: 700 22px/1.15 var(--font); }
.mbtn small { grid-area: s; font-size: 16px; font-weight: 600; line-height: 1.2; color: #5a3a1a; }
.mbtn small.stats { grid-area: x; color: #a8692f; font-size: 16px; }
.mbtn small.stats:empty { display: none; }
.mbtn kbd { grid-area: k; font: 700 13px var(--font); border: 2px solid #b08a5a; border-radius: 6px; padding: 1px 6px; color: #7a5a3a; background: #fffaf0; }
.mbtn.daily .mico { position: relative; width: 52px; height: 52px; }
.mbtn.daily .mico canvas { width: 34px; height: 34px; position: absolute; }
.mbtn.daily .mico canvas:first-child { left: 0; top: 0; }
.mbtn.daily .mico canvas:last-child { right: 0; bottom: 0; }
@media (pointer: coarse) { .mbtn kbd { display: none; } }
/* secondary actions: small text buttons */
.menu-card .mlinks { gap: 0 4px; margin-top: -2px; }
.menu-card .mlinks .link { min-height: 48px; padding: 4px 6px; font-size: 16px; display: inline-flex; align-items: center; }
/* first visit only: the tutorial offer, which also asks for the name once */
.banner { display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: 'p p p' 'n y x'; align-items: end; gap: 6px 8px; padding: 8px 10px;
  background: #fff3d6; border: 3px solid var(--gold); border-radius: 12px; }
.banner p { grid-area: p; margin: 0; font-weight: 700; font-size: 16px; }
.banner .tut-name { grid-area: n; padding: 8px 10px; min-height: 48px; }
.banner .row { display: contents; }
.banner #tut-yes { grid-area: y; } .banner #tut-no { grid-area: x; }
.banner .row button { font-size: 16px; min-height: 48px; padding: 6px 12px; border-radius: 12px; white-space: nowrap; }
.banner .tut-name { width: 100%; }
/* the player chip in the corner, and its name card */
#player-chip { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); z-index: 2; display: flex; align-items: center;
  gap: 8px; min-height: 48px; max-width: 60vw; padding: 4px 12px 4px 4px; border: 3px solid var(--ink); border-radius: 999px; background: #fff7e2; box-shadow: 0 3px 0 var(--ink);
  font: 600 16px var(--font); }
#player-chip img { width: 36px; height: 36px; border-radius: 50%; background: #ffe48a; border: 2px solid var(--ink); }
#player-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-chip i { font-style: normal; color: #7a5a3a; }
#name-pop { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 58px); right: max(10px, env(safe-area-inset-right)); z-index: 3; width: min(300px, calc(100vw - 20px));
  display: grid; gap: 8px; padding: 12px; background: var(--parch); border: 3px solid var(--ink); border-radius: 12px; box-shadow: 0 5px 0 rgba(42, 27, 16, .5); }
#name-pop button { min-height: 48px; border: 3px solid var(--ink); border-radius: 12px; font: 600 18px var(--font); box-shadow: 0 3px 0 var(--ink); }
/* footer: the version (opens What's new), privacy, guide */
#menu-foot { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0 14px; max-width: 640px; font-size: 16px; font-weight: 600; color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6); padding-bottom: env(safe-area-inset-bottom); }
#menu-foot a, #menu-foot .link { color: #fff; min-height: 44px; display: inline-flex; align-items: center; padding: 0 2px; font-size: 16px; }
#menu-foot #btn-notes { font-weight: 700; }
/* the menu card's two halves: one column below 1024 px, side by side from there */
.mc-main, .mc-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mc-box { border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; padding: 8px 12px 10px; }
.mc-box h3 { margin: 0 0 4px; font-size: 17px; }
.news ul { margin: 0; padding-left: 20px; display: grid; gap: 2px; font-weight: 600; font-size: 16px; }
.news .link { padding: 0; min-height: 36px; font-size: 16px; }
/* today's daily challenge: both crests, the matchup, your best and streak; tapping it starts the match */
.daily-card { display: grid; grid-template-columns: 60px 1fr auto; align-items: center; gap: 0 12px; text-align: left; min-height: 72px; box-shadow: 0 3px 0 var(--ink); font: inherit; color: inherit; }
.daily-card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.dc-crests { position: relative; width: 60px; height: 56px; }
.dc-crests canvas { position: absolute; width: 38px; height: 38px; }
.dc-crests canvas:first-child { left: 0; top: 0; } .dc-crests canvas:last-child { right: 0; bottom: 0; }
.dc-text { display: flex; flex-direction: column; min-width: 0; }
.dc-text small { font-size: 14px; font-weight: 700; color: #7a5a3a; text-transform: uppercase; letter-spacing: .4px; }
.dc-text b { font: 600 17px/1.2 var(--font); }
.dc-text small.stats { text-transform: none; letter-spacing: 0; color: #a8692f; font-size: 15px; }
.dc-text small.stats:empty { display: none; }
.dc-go, .room i { font-style: normal; font: 600 16px var(--font); background: linear-gradient(#ffd85a, #f2a91f); border: 2px solid var(--ink); border-radius: 10px; padding: 6px 14px; }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rooms .hint { margin: 0; font-size: 15px; }
/* the menu's rooms: one line each (host, then mode · map · seats), the Join pill at the end */
.rooms .room { grid-template-columns: auto 1fr auto; grid-template-areas: 'host meta go'; gap: 0 10px; min-height: 48px; padding-top: 2px; padding-bottom: 2px; }
.rooms .room span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rooms .room i { padding: 3px 14px; }
@media (min-width: 1024px) {
  #menu { padding-top: 76px; padding-bottom: 8px; }
  #menu .menu-card { width: min(1100px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 0 30px; padding: 24px 28px; }
  .mc-main { gap: 14px; }
  .mc-main .logo .wordmark { width: min(100%, 380px); }
  .mc-main .sub { font-size: 18px; margin-bottom: 6px; }
  .mc-main .mbtns { gap: 14px; }
  .mc-main .mbtn { min-height: 98px; grid-template-columns: 60px 1fr auto; padding: 10px 18px 10px 12px; }
  .mc-main .mbtn b { font-size: 28px; }
  .mc-main .mbtn .mico { font-size: 40px; }
  .mc-side { align-self: stretch; justify-content: center; gap: 12px; padding-left: 30px; border-left: 3px dashed #d4b37a; }
  .mc-side .mlinks { justify-content: flex-start; margin-top: 0; }
  .mc-side .mlinks .link { padding-left: 0; padding-right: 14px; }
  .banner { grid-template-columns: 1fr auto auto; grid-template-areas: 'p y x'; align-items: center; }
}
@media (min-width: 1024px) and (max-height: 760px) {
  #menu { padding-top: 66px; gap: 4px; }
  #menu .menu-card { padding: 16px 24px; }
  .mc-main { gap: 10px; }
  .mc-main .logo .wordmark { width: 300px; }
  .mc-main .mbtn { min-height: 82px; }
  .mc-main .mbtn b { font-size: 25px; }
  .mc-side { gap: 8px; }
  .mc-box { padding: 6px 12px 8px; }
}
/* the Online card: every online control */
#online .menu-card { width: min(480px, 100%); }
#online .quick #btn-quick { flex: 1; }
#online .big, #online .row button, #online .seg button, #online input { min-height: 52px; border-radius: 12px; }
#online #room-list { max-height: 34vh; overflow-y: auto; }
#setup .card-head + h3 { margin-top: 2px; }
@media (max-height: 700px) and (min-width: 600px) {
  .menu-card .logo .wordmark { width: 190px; }
  .mbtn { min-height: 66px; }
}
@media (max-width: 420px) {
  #menu { gap: 6px; justify-content: flex-start; padding-top: calc(max(10px, env(safe-area-inset-top)) + 58px); }
  .menu-card { padding: 10px 12px; gap: 8px; }
  .menu-card .logo .wordmark { width: 180px; }
  .menu-card .mlinks .link { padding: 4px 5px; }
  .mbtn { min-height: 70px; grid-template-columns: 44px 1fr; }
  .mbtn b { font-size: 21px; }
  #menu-foot { gap: 0 10px; }
  .banner { gap: 6px; }
  .banner .row button { padding: 6px 10px; }
}

/* ---------- match setup: vs computer (#setup) and the online lobby (#lobby) ----------
   A panel the height of the screen at most: a header (title, invite row), the body and a bar at the bottom (your
   faction, status, Leave, the start button). From 1024 px the body is two columns: teams (45%) | map strip over the
   faction grid (55%), and only the faction grid scrolls when the screen is short. Below that it is one column that
   scrolls under the fixed bar; phones get tabs (below). */
.ms-screen { padding: 16px; }
.panel.ms { width: min(1200px, 100%); max-height: calc(100dvh - 32px); gap: 10px; padding: 14px 20px 0; overflow: hidden; }
.ms-head { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; position: relative; }
.ms-head h2 { margin: 0; font-size: 26px; white-space: nowrap; }
.ms-head .card-head h2 { font-size: 26px; }
.invite-row { flex: 1 1 420px; display: flex; gap: 6px; min-width: 0; }
.invite-row input { flex: 1; min-width: 100px; font: 600 16px var(--font); padding: 8px 12px; cursor: copy; background: #fff; letter-spacing: .3px; }
.invite-row button, .ms-bar .leave, .ms .host-tools button, .ms .toggle {
  font: 600 16px var(--font); padding: 6px 12px; min-height: 44px; border: 3px solid var(--ink); border-radius: 12px; background: #fff3d6;
  box-shadow: 0 3px 0 var(--ink); white-space: nowrap; }
.invite-row button:active, .ms-bar .leave:active, .ms .host-tools button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.invite-row button.primary { background: linear-gradient(#ffd85a, #f2a91f); }
.ms-head .qr { position: absolute; right: 0; top: calc(100% + 6px); z-index: 4; background: var(--parch); border: 3px solid var(--ink); border-radius: 12px; padding: 8px;
  box-shadow: 0 5px 0 rgba(42, 27, 16, .5); }
.ms-tabs { display: none; }
.ms-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding-bottom: 8px; }
.ms-teams, .ms-faction { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.ms-map { min-width: 0; }
.ms-body h3 { margin: 0 0 4px; font-size: 17px; }
.ms #lobby-hint { font-size: 15px; }
/* compact seat cards, the two teams side by side */
.ms .players { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; align-items: start; }
.ms .players .vs { align-self: center; }
.ms .pcard { min-height: 60px; padding: 6px 8px; gap: 8px; }
.ms .pcard > canvas, .ms .pcard > .qface, .ms .pcard > .crest { width: 44px; height: 44px; flex: none; }
.ms .pcard .qface { font-size: 24px; }
.ms .pcard .who b { font-size: 17px; }
.ms .pcard .who span { font-size: 14px; }
.ms .pcard.empty { min-height: 50px; padding: 4px 8px; }
.ms .teamcol { gap: 5px; }
.ms .seatctl button { min-height: 32px; font-size: 13px; }
/* host options: one row of small buttons */
.ms .host-tools { flex-direction: row; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; }
.ms .host-tools > * { flex: 1 1 auto; font-size: 15px; padding: 4px 10px; min-height: 40px; }
.ms .toggle { display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; }
.ms .toggle input { width: 18px; height: 18px; accent-color: #f2a91f; margin: 0; }
.ms .toggle:has(input:checked) { background: linear-gradient(#ffe48a, #ffc23a); }
.lobby-me .field { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; }
.lobby-me input { flex: 1; padding: 6px 10px; }
.ms .chat { flex: 0 1 auto; min-height: 96px; }
.ms #chat-log { flex: 1 1 auto; height: 150px; min-height: 52px; }
.maps .tile.on:disabled { opacity: 1; }
/* the map strip: thumbnails in one row, the picked map's name and note under it */
.maps.strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 7px; scrollbar-width: thin; position: relative; scroll-snap-type: x proximity; }
.maps.strip .map-group, .maps.strip .tile small { display: none; }
.maps.strip .tile { flex: 1 1 0; min-width: 66px; max-width: 120px; padding: 4px 4px 5px; font-size: 13px; line-height: 1.1; scroll-snap-align: center; }
.maps.strip .tile > span { max-width: 100%; min-height: 2.2em; display: grid; place-items: center; text-align: center; }
.maps.strip .tile .thumb { margin-bottom: 2px; }
.map-about { margin: 0; font-size: 15px; font-weight: 600; color: #5a3a1a; }
.map-about b { font-family: var(--font); font-weight: 600; color: var(--ink); }
/* the faction grid: compact cards (crest, name, (i)); hovering one previews its roster in the summary under the grid */
.factions.compact { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; align-content: start; padding: 2px 2px 6px; }
.factions.compact .tile { padding: 6px 2px; font-size: 15px; gap: 2px; min-height: 84px; justify-content: center; }
.factions.compact .tile canvas.crest { width: 44px; height: 44px; }
.factions.compact .tile .q { font-size: 32px; line-height: 44px; }
.factions.compact .tile .blurb, .factions.compact .tile .roster { display: none; }
.factions.compact .tile .info { width: 26px; height: 26px; font-size: 14px; top: 3px; right: 3px; }
/* the computer's faction: crests only (.crests: .mini is the HUD's small buttons) */
.factions.crests { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.factions.crests .tile { padding: 4px 2px; font-size: 0; gap: 0; }
.factions.crests .tile canvas.crest { width: 38px; height: 38px; }
.factions.crests .tile .q { font-size: 26px; line-height: 38px; }
.factions.crests .tile .roster, .factions.crests .tile .blurb, .factions.crests .tile .info { display: none; }
.pick-summary { flex: none; display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; grid-template-areas: 'c t more' 'c r more'; align-items: center; gap: 2px 12px;
  padding: 8px 12px; border: 3px solid var(--ink); border-radius: 12px; background: #fffaf0; }
.pick-summary:empty { display: none; }
.pick-summary > .crest, .pick-summary > .qface { grid-area: c; width: 64px; height: 64px; }
.pick-summary .ps-text { grid-area: t; display: flex; flex-direction: column; min-width: 0; }
.pick-summary .ps-text b { font: 700 19px var(--font); }
.pick-summary .ps-text span { font-size: 15px; font-weight: 600; color: #5a3a1a; line-height: 1.25; }
.pick-summary .roster { grid-area: r; display: flex; gap: 2px; }
.pick-summary .roster canvas { width: 38px; height: 38px; }
.pick-summary .link { grid-area: more; font-size: 16px; min-height: 44px; }
.pick-summary.preview { border-style: dashed; background: #fff7e2; }
.qface { display: grid; place-items: center; border: 3px dashed #a8692f; border-radius: 50%; font: 700 30px var(--font); color: #a8692f; background: #fff3d6; }
/* the bar at the bottom */
.ms-bar { flex: none; display: flex; align-items: center; gap: 12px; margin: 0 -20px; padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 3px solid var(--ink); background: var(--parch-d); border-radius: 0 0 8px 8px; }
.ms-mine { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ms-mine > .crest, .ms-mine > .qface { width: 48px; height: 48px; flex: none; }
.ms-mine > .qface { font-size: 24px; }
.ms-mine small { display: block; font-size: 13px; font-weight: 700; color: #7a5a3a; text-transform: uppercase; letter-spacing: .3px; }
.ms-mine b { font: 700 20px var(--font); white-space: nowrap; }
.ms-status { flex: 1; min-width: 0; text-align: right; font-weight: 700; font-size: 16px; color: #5a3a1a; }
.ms-bar .leave { min-height: 52px; padding: 8px 18px; font-size: 18px; }
.ms-bar .big { min-width: 210px; min-height: 58px; font-size: 25px; }
#btn-ready.on { background: linear-gradient(#a6e69a, #56bd4f); }
@media (min-width: 1024px) {
  .ms-body { display: grid; grid-template-columns: minmax(0, 45fr) minmax(0, 55fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'teams map' 'teams faction';
    gap: 10px 24px; overflow: hidden; padding-bottom: 10px; }
  .ms-teams { grid-area: teams; min-height: 0; overflow-y: auto; padding: 0 2px 2px 0; }
  .ms-map { grid-area: map; }
  .ms-faction { grid-area: faction; min-height: 0; }
  .ms-faction .factions.compact { grid-template-columns: repeat(6, minmax(0, 1fr)); overflow-y: auto; min-height: 0; flex: 0 1 auto; }
}

/* ---------- below 1024 px: the menu is one column; what's new is left to the footer's version link ---------- */
@media (max-width: 1023px) {
  #menu-news { display: none !important; }
  #menu .menu-card { width: min(560px, 100%); }
}
/* ---------- phones (600 px and narrower): everything fits 390x844 without scrolling; 48 px targets, 16 px text ---------- */
@media (max-width: 600px) {
  /* the menu: logo, three compact primary buttons, today's challenge as a card, the links in one row */
  #menu { justify-content: flex-start; gap: 6px; padding: calc(max(10px, env(safe-area-inset-top)) + 60px) 12px max(8px, env(safe-area-inset-bottom)); }
  #menu .menu-card { padding: 10px 12px 12px; gap: 8px; }
  .mc-main, .mc-side { gap: 8px; }
  .mc-main .logo .wordmark { width: 176px; }
  .mc-main .sub { font-size: 16px; margin: -8px 0 0; }
  .mbtns { gap: 8px; }
  .mbtn { min-height: 60px; grid-template-columns: 40px 1fr; grid-template-areas: 'i t'; padding: 6px 12px 6px 8px; }
  .mbtn small, .mbtn kbd { display: none; }
  .mbtn b { font-size: 22px; }
  .mbtn .mico { font-size: 28px; }
  #menu-rooms { display: none; }
  .daily-card { min-height: 64px; grid-template-columns: 52px 1fr auto; padding: 6px 10px; }
  .dc-crests { width: 52px; height: 48px; } .dc-crests canvas { width: 32px; height: 32px; }
  .dc-text small { font-size: 16px; text-transform: none; letter-spacing: 0; }
  .dc-text b { font-size: 16px; }
  .dc-text small.stats { font-size: 16px; }
  .dc-go { padding: 10px 14px; }
  .banner { grid-template-columns: 1fr 1fr; grid-template-areas: 'p p' 'y x'; padding: 8px; gap: 6px; }
  .menu-card .mlinks { flex-wrap: nowrap; justify-content: space-between; gap: 0; margin: 0; }
  .menu-card .mlinks .link { min-height: 48px; padding: 4px 2px; font-size: 16px; white-space: nowrap; }
  .mlinks .long { display: none; }
  #menu-foot { gap: 0 12px; }
  #menu-foot a, #menu-foot .link { min-height: 48px; }
  #player-chip { min-height: 48px; }

  /* match setup: the whole screen; tabs (Teams/Opponent, Faction, Map), only the open tab scrolls; the bar stays */
  .ms-screen { padding: 0; place-items: stretch; overflow: hidden; }
  .panel.ms { width: 100%; height: 100dvh; max-height: none; border-radius: 0; border-width: 0; padding: max(8px, env(safe-area-inset-top)) 12px 0; gap: 8px; box-shadow: none; }
  .ms-head { flex-wrap: nowrap; gap: 8px; }
  .ms-head h2 { font-size: 22px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .ms-head .code { font-size: 20px; }
  .invite-row { flex: none; }
  .invite-row input, #btn-copy, #btn-copy-watch, #btn-qr { display: none; }
  .invite-row button { min-height: 48px; padding: 6px 16px; font-size: 17px; }
  .ms-head .back-arrow { width: 48px; height: 48px; }
  .ms-tabs { display: flex; gap: 6px; flex: none; }
  .ms-tabs button { flex: 1; min-height: 48px; font: 600 17px var(--font); border: 3px solid var(--ink); border-radius: 12px; background: #fff3d6; box-shadow: 0 3px 0 var(--ink); }
  .ms-tabs button.on { background: linear-gradient(#ffe48a, #ffc23a); }
  .ms-tabs button[hidden] { display: none; }
  .ms-body { overflow: hidden; gap: 0; padding-bottom: 0; }
  .ms-body > section { display: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 2px 12px; }
  .ms[data-tab="teams"] .ms-teams, .ms[data-tab="faction"] .ms-faction, .ms[data-tab="map"] .ms-map { display: flex; flex-direction: column; gap: 10px; }
  .ms .players { grid-template-columns: 1fr; gap: 4px; }
  .ms .players .vs { justify-self: center; }
  .ms .pcard { min-height: 64px; }
  .ms .pcard .who b { font-size: 18px; }
  .ms .pcard .who span, .ms #lobby-hint, .ms .hint { font-size: 16px; }
  .ms .seatctl button, .pcard .mute { min-height: 48px; min-width: 48px; font-size: 16px; }
  .ms .host-tools > * { min-height: 48px; font-size: 16px; flex: 1 1 40%; }
  .lobby-me .field { font-size: 16px; }
  .lobby-me input, .chat input { min-height: 48px; font-size: 16px; }
  #chat-log { font-size: 16px; }
  .factions.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .factions.compact .tile { font-size: 16px; min-height: 92px; }
  .factions.compact .tile { padding-top: 16px; }
  .factions.compact .tile .info { width: 28px; height: 28px; font-size: 16px; top: 3px; right: 3px; }
  .factions.compact .tile .info::after { content: ''; position: absolute; inset: -10px; }   /* a 48 px target */
  /* seat cards: one row each (face, who, controls) */
  .ms .pcard, .ms .pcard.empty { flex-wrap: nowrap; flex-direction: row; justify-content: flex-start; }
  .ms .pcard .who { flex: 1; }
  .ms .seatctl { width: auto; flex-wrap: nowrap; flex: none; }
  .ms .pcard .mute { position: static; flex: none; }
  .factions.crests { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .factions.crests .tile { min-height: 56px; }
  .ms .seg button { min-height: 48px; }
  .maps.strip { flex-wrap: wrap; overflow: visible; }
  .maps.strip .tile { flex: 1 1 30%; max-width: none; font-size: 16px; min-height: 48px; }
  .map-about { font-size: 16px; }
  .pick-summary { grid-template-columns: 56px minmax(0, 1fr); grid-template-areas: 'c t' 'r r' 'more more'; }
  .pick-summary > .crest, .pick-summary > .qface { width: 56px; height: 56px; }
  .pick-summary .ps-text span { font-size: 16px; }
  .pick-summary .link { justify-self: start; min-height: 48px; }
  .ms-bar { flex-wrap: wrap; gap: 6px 10px; margin: 0 -12px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); border-radius: 0; }
  .ms-status { order: -1; flex: 1 0 100%; text-align: left; font-size: 16px; }
  .ms-mine { flex: 1; }
  .ms-mine > .crest, .ms-mine > .qface { width: 40px; height: 40px; }
  .ms-mine small { display: none; }
  .ms-mine > span { min-width: 0; overflow: hidden; }
  .ms-mine b { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; }
  .ms-bar .leave { min-height: 52px; padding: 6px 12px; font-size: 17px; }
  .ms-bar .big { min-width: 0; flex: 0 0 auto; padding: 8px 22px; min-height: 56px; font-size: 22px; }
}

/* ---------- the Forge (factions with a forge): its button, the marks on unit buttons, the panel ---------- */
.btn.forgebtn { background: radial-gradient(circle at 50% 38%, #fff1c8 0 40%, #d8a843 75%, #7e5420 100%); }
.btn.forgebtn.casting { box-shadow: 0 0 0 2px #ffd36a, 0 0 12px 2px rgba(255, 160, 60, 0.8); animation: bank 1.6s ease-in-out infinite; }
.btn .cost.fg { color: #ffe6a8; }
.btn .cost.fg::before { background: radial-gradient(circle at 35% 35%, #fff6d0, #d8a843 60%, #7e5420); }
@media (prefers-reduced-motion: reduce) { .btn.forgebtn.casting { animation: none; } }
.btn .fmark { position: absolute; top: 2px; right: 3px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; pointer-events: none; }
.btn .fmark:empty { display: none; }
.btn .fmark b { font-size: 13px; line-height: 1; color: #ffb04a; text-shadow: 0 0 2px #2a1b10, 0 0 3px #2a1b10; animation: anvil .7s ease-in-out infinite alternate; }
@keyframes anvil { from { transform: rotate(-12deg); } to { transform: rotate(12deg); } }
.btn .fmark i { width: 8px; height: 8px; border-radius: 2px; border: 1.5px solid var(--ink); background: #d8a843; }
.btn .fmark i.t-blades { background: #fff1b0; }
.btn .fmark i.t-plates { background: #b07a34; }
.btn .fmark i.t-charms { background: #d2452f; }
.forge-panel { position: absolute; z-index: 15; top: calc(var(--top-h, 76px) + 6px); left: 50%; transform: translateX(-50%); width: min(620px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--top-h, 76px) - 70px); overflow-y: auto; background: var(--parch); border: 4px solid var(--ink); border-radius: 14px;
  box-shadow: 0 6px 0 rgba(42, 27, 16, 0.55); padding: 10px 12px 10px; font-weight: 700; }
.fp-head { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: center; margin-bottom: 8px; }
.fp-head b { font-family: var(--font); font-size: 22px; font-weight: 600; color: #7e5420; }
.fp-head small { grid-column: 1; font-size: 12px; color: #6a4a2a; }
.fp-x { grid-column: 2; grid-row: 1 / span 2; width: 44px; height: 44px; border: 3px solid var(--ink); border-radius: 12px; background: #fff8e4; font-size: 18px; }
.fp-grid { display: grid; grid-template-columns: 112px repeat(var(--n, 3), 1fr); gap: 6px; }
.fp-corner { align-self: end; font-size: 12px; color: #6a4a2a; padding: 0 4px 2px; }
.fp-track { display: grid; grid-template-columns: 30px 1fr; column-gap: 4px; align-items: center; font-size: 15px; }
.fp-track canvas { width: 30px; height: 30px; grid-row: 1 / span 2; }
.fp-track small { font-size: 10.5px; color: #6a4a2a; font-weight: 600; line-height: 1.15; }
.fp-unit { display: grid; grid-template-columns: 40px 1fr; column-gap: 4px; align-items: center; min-height: 56px; font-size: 13px; line-height: 1.1; }
.fp-unit canvas { width: 40px; height: 40px; grid-row: 1 / span 2; }
.fp-unit small { color: #6a4a2a; }
.fp-cell { position: relative; min-height: 56px; border: 3px solid var(--ink); border-radius: 10px; background: linear-gradient(#fff8e4, #f0dcae); font-size: 13px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow: hidden; padding: 2px 4px; color: var(--ink); }
.fp-cell i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.fp-cell em { position: absolute; left: 0; bottom: 0; height: 5px; width: 0; background: #ff9a3a; transition: width .25s linear; }
.fp-cell.done { background: linear-gradient(#f3d687, #b07a34); color: #2a1b10; }
.fp-cell.done i { background: #2f5a3a; box-shadow: inset 0 0 0 3px #f3d687; }
.fp-cell.casting { background: linear-gradient(#ffe2b0, #ffb04a); }
.fp-cell.casting i { background: #ff8a2a; animation: anvil .7s ease-in-out infinite alternate; }
.fp-cell.avail i { background: #fff6d0; }
.fp-cell.avail:hover { outline: 3px solid #fff; outline-offset: -6px; }
.fp-cell.blocked { color: #8a5a3a; }
.fp-cell.blocked i { background: #e6d09c; }
.fp-cell.locked { background: repeating-linear-gradient(45deg, #e6d09c 0 6px, #dcc48c 6px 12px); color: #8a6a4a; font-weight: 700; }
.fp-cell.locked i { background: #bfa77a; }
.fp-cell:active { transform: translateY(2px); }
.fp-foot { margin-top: 8px; font-size: 11.5px; color: #6a4a2a; }
@media (max-width: 600px) {
  .forge-panel { top: auto; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px); padding: 8px; }
  .fp-head b { font-size: 18px; }
  .fp-grid { grid-template-columns: 78px repeat(var(--n, 3), 1fr); gap: 5px; }
  .fp-unit { grid-template-columns: 1fr; justify-items: center; text-align: center; font-size: 11px; }
  .fp-unit canvas { grid-row: auto; width: 34px; height: 34px; }
  .fp-track { grid-template-columns: 1fr; justify-items: center; text-align: center; font-size: 13px; }
  .fp-track canvas { grid-row: auto; width: 26px; height: 26px; }
  .fp-track small { display: none; }
  .fp-cell { min-height: 54px; font-size: 12px; }
}

/* ---------- the god picker (a faction with gods, under the faction grid): four cards, two columns on phones ---------- */
.gods { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 6px 2px 8px; }
.gods[hidden] { display: none; }
.gods .gods-head { margin: 0; font: 700 17px var(--font); display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.gods .gods-head small { font: 600 13px 'Fredoka', sans-serif; color: #7a5a3a; }
.gods .gods-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.gods .god { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); grid-template-areas: 'c n' 'p p' 'w w'; align-items: center; align-content: start;
  gap: 2px 6px; padding: 6px 8px 8px; min-height: 44px; text-align: left; border: 3px solid var(--ink); border-radius: 12px; background: #fff8e6; cursor: pointer; }
.gods .god:hover { background: #fff1c8; }
.gods .god.on { background: linear-gradient(#fff3c4, #ffe08a); box-shadow: 0 0 0 3px #2a7fc0 inset; }
.gods .god .gcrest { grid-area: c; width: 40px; height: 40px; }
.gods .god b { grid-area: n; font: 700 18px var(--font); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gods .god .pitch { grid-area: p; font-size: 13.5px; font-weight: 600; line-height: 1.2; color: #3a2a1a; }
.gods .god .weak { grid-area: w; font-size: 12.5px; font-weight: 700; line-height: 1.2; color: #a8231c; }
@media (max-width: 900px) and (min-width: 601px) { .gods .gods-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) {
  .gods .gods-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  .gods .god { grid-template-columns: 34px minmax(0, 1fr); padding: 5px 6px 6px; min-height: 48px; }
  .gods .god .gcrest { width: 34px; height: 34px; }
  .gods .god b { font-size: 16px; }
  .gods .god .pitch { font-size: 12.5px; } .gods .god .weak { font-size: 12px; }
  .gods .gods-head { font-size: 16px; } .gods .gods-head small { font-size: 12px; }
}

/* traps and trails (factions with traps): the trap and Trail Exit buttons carry a count chip top right ("2/4", or the
   units on the trail), and the topbar's "Traps 2/4" readout; the route button turns forest green on the Trail */
.btn.place { background: linear-gradient(#eef6dc 55%, #d6e6b4 55%, #d6e6b4 82%, var(--fc, #2f7a46) 82%); }
.btn .cnt { position: absolute; top: 1px; right: 3px; font: 800 11px/14px var(--font); color: #fff; background: rgba(28, 54, 30, .88); border-radius: 7px; padding: 0 4px; pointer-events: none; }
.btn .cnt:empty { display: none; }
.res.traps { font-size: 15px; }
.res.traps span { font-size: 12px; color: #cfe8c0; }
.res.traps i { border-radius: 3px; background: linear-gradient(135deg, transparent 38%, #a8692f 38% 62%, transparent 62%), linear-gradient(45deg, transparent 38%, #c9a565 38% 62%, transparent 62%), #2f5a34; }
#route.trail { background: linear-gradient(#d8f5c8, #4f9a52); }


/* the kill feed: signature moments (saga heroes), newest on top, under the castle bars on the right */
#feed { position: absolute; right: max(10px, env(safe-area-inset-right)); top: calc(var(--top-h, 70px) + 46px); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; z-index: 4; }
.feed-item { font-family: var(--font); font-size: 14px; color: #fff; background: rgba(42, 27, 16, 0.85); border-radius: 8px; padding: 3px 10px; border-left: 4px solid var(--p1, #c82a2a); transition: opacity 0.5s; max-width: 340px; }
.feed-item.ours { border-left-color: var(--p0, #1f5fc8); }
.feed-item.out { opacity: 0; }
body.demo #feed { display: none; }

/* ---------- the HUD top bar (v0.13) ----------
   A grid: the resource block with the signature pill under it on the left, the three button groups (Army, Spells,
   Build) in the middle, the side buttons on the right. Phones: a slim resource strip and the side buttons, the pill,
   then two rows of buttons (the army; the spells with the Build group after them). The VS chip sits centered under it
   all (--top-h is the bar's height). */
#topbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "res buttons side" "sig buttons side"; align-items: start; column-gap: 10px; row-gap: 5px; }
#res { grid-area: res; display: flex; flex-direction: column; gap: 1px; padding: 4px 12px 4px 6px; background: rgba(42, 27, 16, 0.86); border: 2px solid var(--ink); border-radius: 12px; justify-self: start; }
#res .res { background: none; border-radius: 0; padding: 0; min-width: 0; gap: 6px; font-size: 18px; line-height: 22px; white-space: nowrap; cursor: default; }
#res .res b { font-variant-numeric: tabular-nums; }
#res .res small { font-size: 12px; margin-left: 0; white-space: nowrap; }
#res .gold small { color: #ffe08a; }
#res .res.gold .floor { left: 24px; right: 0; bottom: -1px; }
#restip { position: fixed; z-index: 24; max-width: 260px; padding: 6px 10px; border-radius: 10px; background: var(--parch); border: 2px solid var(--ink); font-size: 13px; font-weight: 700; color: var(--ink); pointer-events: none; box-shadow: 0 3px 0 rgba(42, 27, 16, .45); }
#restip[hidden] { display: none; }

/* the signature pill (signature.js), and its buttons */
#sig { grid-area: sig; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 5px; max-width: 380px; }
#sig[hidden] { display: none; }
.sig-pill { display: flex; align-items: center; gap: 6px; padding: 2px 12px 2px 2px; border-radius: 999px; border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--fc, #888);
  background: rgba(42, 27, 16, 0.88); color: #fff; font-family: var(--font); cursor: pointer; text-align: left; touch-action: manipulation; }
.sig-pill:hover, .sig-pill[aria-expanded="true"] { background: rgba(70, 46, 26, 0.95); }
.sig-crest { width: 28px; height: 28px; flex: none; border-radius: 50%; }
.sig-txt { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.sig-name { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: #ffe6a8; white-space: nowrap; }
.sig-state { font-size: 14px; font-weight: 400; white-space: nowrap; }
#sig .sig-acts { display: flex; gap: 4px; flex-wrap: wrap; }
.sig-act { font: 400 13px/1 var(--font); padding: 5px 9px; border-radius: 9px; border: 2px solid var(--ink); background: #f6ead2; color: var(--ink); cursor: pointer; box-shadow: 0 2px 0 var(--ink); touch-action: manipulation; }
.sig-act.on { background: #ffd23f; }
.sig-act.off { opacity: .55; cursor: not-allowed; }
.sig-act.armed { box-shadow: 0 0 0 2px #fff, 0 0 8px 2px #ffd23f; }

/* the signature card and the enemy card: under what opened them, never over the middle of the battlefield */
#sigcard, #foecard { position: fixed; z-index: 25; width: min(360px, calc(100vw - 16px)); max-height: min(62vh, 540px); overflow-y: auto; padding: 10px 12px 12px;
  background: var(--parch); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 rgba(42, 27, 16, .5); color: var(--ink); font-size: 13px; font-weight: 600; }
#sigcard[hidden], #foecard[hidden] { display: none; }
#sigcard header { border-left: 6px solid var(--fc, #888); padding-left: 8px; margin-bottom: 6px; }
#sigcard header small { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7a4a20; }
#sigcard h3 { margin: 0; font-family: var(--font); font-weight: 400; font-size: 20px; }
#sigcard p { margin: 4px 0; }
#sigcard .sc-lead { font-size: 14px; }
#sigcard dl, #foecard dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; margin: 6px 0; }
#sigcard dt, #foecard dt { font-weight: 800; }
#sigcard dd, #foecard dd { margin: 0; }
#sigcard h4 { margin: 8px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
#sigcard .sc-passive { margin: 0; padding-left: 18px; }
#sigcard .sc-why { font-style: italic; color: #6a4a2a; }
#sigcard .sc-more { margin-top: 4px; font-size: 14px; }
#foecard section + section { margin-top: 8px; padding-top: 8px; border-top: 2px dashed var(--parch-d, #d9c6a0); }
#foecard h4 { margin: 0 0 2px; font-family: var(--font); font-weight: 400; font-size: 17px; border-left: 6px solid var(--fc, #888); padding-left: 8px; }
#foecard h4 small { display: block; font-family: system-ui, sans-serif; font-size: 12px; font-weight: 700; color: #7a4a20; }

/* the three button groups */
#buttons { grid-area: buttons; display: flex; justify-content: safe center; align-items: flex-start; gap: 4px 14px; padding: 0 2px 8px; overflow-x: auto; scrollbar-width: none; }
#buttons::-webkit-scrollbar { display: none; }
/* the route's state hangs under the side buttons, over the sky (never over the buttons) */
#route-tag { right: 0; top: calc(100% + 4px); transform: none; }
/* the mine's state sits left of the mine button (the route's hangs under the side buttons, over the feed's corner) */
#gift-btn svg { display: block; margin: auto; }
/* medium widths: the groups wrap (the Army on one line, the Spells and Build under it) */
@media (max-width: 1100px) and (min-width: 601px) {
  #buttons { flex-wrap: wrap; overflow-x: visible; }
  .btn { width: 56px; height: 64px; }
  .btn canvas { width: 46px; height: 46px; }
  .grp.extra .btn { width: 50px; height: 58px; }
  .grp.extra .btn canvas { width: 40px; height: 40px; }
  .grp.extra .haul { height: 58px; }
}
.grp { display: flex; flex-direction: column; gap: 3px; flex: none; min-width: 0; }
.grp-label { font: 400 11px/1 var(--font); color: #fff; text-transform: uppercase; letter-spacing: .1em; padding-left: 3px; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); }
.grp-row { display: flex; gap: 5px; align-items: flex-start; }
.grp.extra { padding-left: 12px; border-left: 2px dashed rgba(255, 255, 255, 0.55); }
.grp.extra .btn { width: 54px; height: 62px; }
.grp.extra .btn canvas { width: 44px; height: 44px; }
.grp.extra .haul { height: 62px; margin-left: 0; }

/* button states: ready (full color), can't afford (grey, cost in red), cooling down (a sweep), not researched (dark, a
   book and the research cost in gold), not available yet (faded; the tooltip names what it needs) */
.btn .key { top: 3px; left: 3px; min-width: 15px; height: 15px; padding: 0 3px; box-sizing: border-box; border-radius: 5px; background: rgba(42, 27, 16, .78);
  color: #fff; font: 800 10px/15px var(--font); text-align: center; z-index: 2; }
.btn.poor canvas { filter: grayscale(1); opacity: .55; }
.btn.poor .cost { color: #ff7a6a !important; }
.btn.locked { background: linear-gradient(#5e4a36, #3a2b1d); }
.btn.locked canvas { filter: grayscale(.55) brightness(.6); }
.btn .lock { background: none; display: none; }
.btn .lock::before, .btn .lock::after { content: none; }
.btn.locked .lock { display: block; }
.btn .lock .book { position: absolute; top: 3px; right: 3px; width: 16px; height: 13px; border: 1.5px solid var(--ink); border-radius: 2px 4px 4px 2px;
  background: linear-gradient(90deg, #8a3b1c 0 3px, #d9583a 3px 100%); box-shadow: inset -3px 0 0 #fff3d6; }
.btn .lock span { position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 0 5px 0 3px; border-radius: 8px;
  background: rgba(42, 27, 16, .9); border: 1.5px solid var(--ink); font: 400 13px/15px var(--font); color: var(--gold); white-space: nowrap; }
.btn .lock span::before { content: ''; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); background: radial-gradient(circle at 35% 35%, #fff2a8, #f2c230 60%, #c3901a); }
.btn.locked.poor .lock span { color: #ff7a6a; }
.btn.researching .lock span { color: #fff; }
.btn.researching .lock span::before { display: none; }
.btn.unavailable { filter: none; opacity: .42; }
.btn.unavailable::after { content: none; }

/* the VS chip, centered under the top bar; the enemy's name opens the enemy card */
#vschip { position: absolute; left: 50%; top: calc(var(--top-h, 76px) + 6px); transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 3px 4px 3px 4px;
  border-radius: 12px; background: rgba(42, 27, 16, 0.84); border: 2px solid var(--ink); font-family: var(--font); color: #fff; max-width: calc(100vw - 16px); pointer-events: none; }
.vs-team { padding: 1px 9px; border-radius: 8px; border: 2px solid var(--ink); font-size: 14px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-team.t0 { background: var(--p0); } .vs-team.t1 { background: var(--p1); }
.vs-team.foe { pointer-events: auto; cursor: pointer; position: relative; padding-right: 22px; }
.vs-team.foe::after { content: 'i'; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; border-radius: 50%; background: #fff; color: var(--ink); font: 800 10px/13px system-ui, sans-serif; text-align: center; }
.vs-team.foe.live::after { background: #ffd23f; box-shadow: 0 0 0 2px rgba(255, 210, 63, .5); }
#vschip .vs { font-size: 13px; color: #ffe08a; font-weight: 400; }
#vschip #clock { position: static; transform: none; background: none; padding: 0 6px 0 2px; font-size: 14px; }
#wonder { top: calc(var(--top-h, 76px) + 44px); }
#banner { top: calc(var(--top-h, 76px) + 48px); }
#feed { top: calc(var(--top-h, 76px) + 44px); }

@media (max-width: 600px) {
  #topbar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "res side" "sig sig" "buttons buttons"; row-gap: 4px; column-gap: 6px; }
  #res { flex-direction: row; align-items: center; gap: 10px; padding: 2px 10px 2px 5px; }
  #res .res { font-size: 15px; line-height: 20px; gap: 4px; }
  #res .res i { width: 15px; height: 15px; }
  #res .res small { font-size: 11px; }
  #side { flex-direction: row; gap: 4px; }
  #side .mini { width: 40px; height: 40px; font-size: 18px; }
  #route-tag { display: none !important; }
  .sig-crest { width: 22px; height: 22px; }
  .sig-state { font-size: 13px; }
  #buttons { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 4px 8px; padding-bottom: 6px; }
  .grp-label { display: none; }
  .grp.army { flex: 0 0 100%; }
  .grp.extra { padding-left: 6px; flex: 1 1 0; min-width: 0; }
  .grp.extra .grp-row { overflow-x: auto; scrollbar-width: none; }
  .grp.extra .grp-row::-webkit-scrollbar { display: none; }
  .grp-row { gap: 4px; }
  .btn, .grp.extra .btn { width: 40px; height: 48px; border-radius: 9px; }
  .btn canvas, .grp.extra .btn canvas { width: 34px; height: 34px; }
  .btn .cost, .btn .lock span { font-size: 11px; line-height: 13px; padding: 0 3px 0 2px; }
  .btn .key { display: none; }
  .grp.extra .haul { height: 48px; }
  .grp.extra .haul { flex: none; }
  .grp.extra .haul .hb { width: 24px; }
  .grp.extra .haul .hv { width: 36px; }
  #vschip { top: calc(var(--top-h, 76px) + 4px); }
  #sigcard, #foecard { max-height: 52vh; }
  .vs-team { font-size: 13px; max-width: 30vw; }
}

/* terrain features (terrain.js): the icon before a map tile's name and the feature line under the strip; the
   sandstorm's warning banner shares the pyramid warning's look */
.ficon { display: inline-grid; place-items: center; width: 20px; height: 20px; vertical-align: -4px; }
.ficon svg { width: 100%; height: 100%; display: block; }
.maps .tile > span > span .ficon { width: 1.1em; height: 1.1em; margin-right: 3px; vertical-align: -.2em; }
.map-feat { display: block; margin-top: 3px; font-size: 14px; font-weight: 600; }
.map-feat .ficon { margin-right: 5px; }
.map-feat b { font-family: var(--font); font-weight: 600; }
#terrain-warn { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); z-index: 8; pointer-events: none; text-align: center; padding: 12px 22px;
  background: rgba(42,27,16,.88); border: 3px solid #e8b860; border-radius: 16px; box-shadow: 0 0 30px rgba(232,184,96,.55); }
#terrain-warn[hidden] { display: none; }
#terrain-warn b { display: block; font: 700 clamp(20px, 4vw, 34px)/1.1 var(--font); color: #ffd99a; text-shadow: 0 2px 0 var(--ink); }
#terrain-warn small { display: block; margin-top: 4px; font-weight: 800; color: #fff; font-size: 14px; }
#terrain-warn.pop { animation: wpop .5s ease-out; }

/* 2v2: the ping wheel, the team panel and the combo banner (v0.15) */
#ping-btn svg { display: block; margin: auto; }
#ping-btn.armed { outline: 3px solid #f2c230; }
#ping-wheel { position: fixed; width: 0; height: 0; z-index: 30; }
#ping-wheel button { position: absolute; left: 0; top: 0; min-width: 76px; padding: 7px 10px; border-radius: 999px; border: 2px solid #2a1b10; font: 700 14px/1 inherit;
  color: #2a1b10; transform: translate(-50%, -50%) rotate(var(--a)) translate(62px) rotate(calc(-1 * var(--a))); box-shadow: 0 3px 0 #2a1b10; cursor: pointer; }
#ping-wheel button.attack { background: #ff8a6a; } #ping-wheel button.defend { background: #8ec5ff; } #ping-wheel button.help { background: #ffd85a; }
#ping-wheel .dot { position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #2a1b10; }
#team-panel { position: absolute; right: 8px; top: calc(var(--top-h, 64px) + 64px); z-index: 4; background: rgba(247,233,198,0.92); border: 2px solid #2a1b10;
  border-radius: 10px; padding: 4px 8px; font: 600 12px/1.35 inherit; color: #2a1b10; pointer-events: none; }
#team-panel table, #over-team table { border-collapse: collapse; }
#team-panel th, #team-panel td, #over-team th, #over-team td { padding: 1px 6px; text-align: right; white-space: nowrap; }
#team-panel th:first-child, #team-panel td:first-child, #over-team th:first-child, #over-team td:first-child { text-align: left; }
#team-panel th, #over-team th { font-weight: 700; opacity: 0.7; }
#team-panel tr.me td, #over-team tr.me td { font-weight: 800; }
#over-team { margin: 6px auto 10px; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font: 600 13px/1.4 inherit; }
#over-team h3 { margin: 0 0 2px; font-size: 14px; }
#combo-banner { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); z-index: 7; font: 900 44px/1 inherit; color: #ffd85a;
  -webkit-text-stroke: 2px #2a1b10; text-shadow: 0 4px 0 #2a1b10; pointer-events: none; animation: combo-pop 1.2s ease-out both; }
@keyframes combo-pop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }
@media (prefers-reduced-motion: reduce) { #combo-banner { animation: none; } }
@media (max-width: 700px) { #team-panel { top: auto; bottom: 150px; right: 4px; font-size: 11px; } }
body.replaying #ping-btn { visibility: hidden; }
