:root {
  --gold: #e6bf55; --gold-d: #a37a1c; --dark: #150f09; --panel: #2a1f14; --panel2: #34261a; --edge: var(--edge); --edge-l: #8c6a33;
  --txt: #f3e7c6; --mut: #b9a77c; --good: #6fd36f; --bad: #e0705f; --blue: #4a8bff;
  --shadow: 0 4px 14px rgba(0, 0, 0, .55);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(ellipse at 50% -10%, #2b2015 0%, #0d0905 70%) fixed; color: var(--txt); font-family: Georgia, "Palatino Linotype", "Times New Roman", serif; }
::selection { background: var(--gold-d); }
* { scrollbar-width: thin; scrollbar-color: var(--edge) #120d08; }
::-webkit-scrollbar { width: 9px; height: 9px; } ::-webkit-scrollbar-track { background: #120d08; } ::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 5px; }

button { font: inherit; color: var(--txt); background: linear-gradient(#4d3a22, #2c1f10); border: 1px solid var(--edge); border-radius: 5px; padding: 5px 11px; cursor: pointer; transition: border-color .12s, background .12s, transform .06s, box-shadow .12s; box-shadow: inset 0 1px 0 rgba(255, 235, 180, .12); }
button:hover:not(:disabled) { border-color: var(--gold); background: linear-gradient(#5f4829, #36260f); box-shadow: 0 0 8px rgba(230, 191, 85, .25), inset 0 1px 0 rgba(255, 235, 180, .18); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
button:disabled { opacity: .42; cursor: default; }
button.primary { background: linear-gradient(#9a7620, #5e4510); border-color: var(--gold); font-weight: bold; text-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
button.primary:hover:not(:disabled) { background: linear-gradient(#b08a28, #6e5114); }
kbd { font: 600 10px/1 ui-monospace, Consolas, monospace; background: rgba(0, 0, 0, .45); border: 1px solid var(--edge); border-radius: 3px; padding: 1px 4px; margin-left: 3px; color: var(--mut); vertical-align: 1px; }
input, select { background: #120d08; color: var(--txt); border: 1px solid var(--edge); border-radius: 4px; padding: 4px 6px; font: inherit; }
.hide { display: none !important; }
.small { font-size: 12px; opacity: .85; }

#app { max-width: 1300px; margin: 0 auto; padding: 8px; }
.panel, #hero, #army, #batui, #terr, #top { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 2px solid var(--edge); border-radius: 8px; box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 235, 180, .08); }

/* top bar */
#top { display: flex; align-items: center; gap: 10px; padding: 6px 10px; margin-bottom: 8px; flex-wrap: wrap; }
#res { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #120d08; border: 1px solid var(--edge); border-radius: 14px; padding: 2px 10px; font-size: 15px; white-space: nowrap; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); }
.chip b { font-weight: 600; }
#income { color: var(--good); font-size: 13px; } #income small { opacity: .7; margin-left: 2px; }
#date { color: var(--gold); font-size: 14px; letter-spacing: .3px; }
.btns { display: flex; gap: 6px; }

/* layout */
#game { display: flex; gap: 8px; align-items: flex-start; }
#stage { position: relative; flex: 0 1 960px; min-width: 0; border: 2px solid var(--edge-l); border-radius: 8px; overflow: hidden; background: #000; box-shadow: var(--shadow), 0 0 0 3px #140e07; }
#stage canvas { display: block; width: 100%; height: auto; aspect-ratio: 960/640; }
#stage canvas#bat { display: none; }
#side { width: 268px; flex: none; display: flex; flex-direction: column; gap: 8px; }
#mini { width: 100%; image-rendering: pixelated; border: 2px solid var(--edge); border-radius: 6px; cursor: pointer; background: #000; box-shadow: var(--shadow); }
#hero, #army, #batui, #terr { padding: 9px; }
#hero h3, #batui h3, #terr h3 { margin: 0 0 6px; color: var(--gold); font-size: 16px; padding-bottom: 4px; border-bottom: 1px solid; border-image: linear-gradient(90deg, var(--edge-l), transparent) 1; }
#hero h3 .small { color: var(--mut); font-weight: normal; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 8px; font-size: 14px; margin-bottom: 4px; }
.bar { height: 11px; background: #0b0805; border: 1px solid var(--edge); border-radius: 6px; margin: 3px 0 6px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .7); }
.bar > i { display: block; height: 100%; border-radius: 6px; transition: width .35s; background-image: linear-gradient(rgba(255, 255, 255, .28), rgba(255, 255, 255, 0) 55%); }
.bar.mv > i { background-color: #d6a43a; } .bar.mn > i { background-color: #3a7ad6; } .bar.xp > i { background-color: #8a5ad6; }
.zrow { padding: 2px 0; font-size: 13px; }
.zdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; border: 1px solid #000; box-shadow: 0 0 5px currentColor; }
.zp { background: #3a8aff; color: #3a8aff; } .ze { background: #e03a3a; color: #e03a3a; } .zn { background: #999; color: #999; }
.hlist { display: flex; gap: 4px; margin-bottom: 6px; }
.hbtn { font-size: 20px; padding: 2px 9px; }
.hbtn.on { border-color: var(--gold); background: linear-gradient(#9a7620, #5e4510); }
.small-btn { margin-top: 6px; width: 100%; font-size: 12px; padding: 4px; }
.stars { color: var(--gold); font-size: 12px; letter-spacing: 1px; }

/* army slots */
#army { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.slot { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; font-size: 23px; line-height: 1; position: relative; background: linear-gradient(#3a2a18, #20160b); }
.slot small { font-size: 12px; margin-top: 3px; color: var(--txt); text-shadow: 0 1px 2px #000; }
.slot.sel { outline: 2px solid var(--gold); box-shadow: 0 0 10px rgba(230, 191, 85, .55); }
.slot.empty { opacity: .3; }
.armyrow { display: grid; grid-template-columns: repeat(7, 56px); gap: 4px; margin-bottom: 6px; }

/* battle panel */
#batui { display: none; }
.inbattle #batui { display: block; }
.inbattle #stage canvas#bat { display: block; }
.inbattle #map, .inbattle #mini, .inbattle #terr, .inbattle #hero, .inbattle #army, .inbattle .btns, .inbattle #tip, .inbattle #banner { display: none !important; }
/* battles use the whole window on big screens: the page width cap is lifted and the battlefield grows to the height available */
@media (min-width: 1000px) and (min-height: 600px) {
  body.inbattle #app { max-width: none; padding: 6px 12px; }
  body.inbattle #top { margin-bottom: 6px; }
  body.inbattle #game { flex-direction: row; gap: 10px; align-items: stretch; }
  body.inbattle #stage { flex: 1 1 auto; width: auto; display: flex; justify-content: center; align-items: center; background: #000; height: calc(100vh - 96px); height: calc(100dvh - 96px); }
  body.inbattle #stage canvas#bat { flex: none; height: auto; aspect-ratio: 960/640; width: min(100%, calc((100vh - 100px) * 1.5)); width: min(100%, calc((100dvh - 100px) * 1.5)); }
  body.inbattle #side { width: 330px; flex: none; display: flex; flex-direction: column; overflow-y: auto; max-height: calc(100vh - 96px); max-height: calc(100dvh - 96px); }
}
#batui .row { display: flex; gap: 5px; margin-bottom: 5px; flex-wrap: wrap; align-items: center; }
#batui .row button { flex: 1; padding: 6px 4px; font-size: 13px; }
.pill { background: #0b0805; border: 1px solid var(--edge); padding: 3px 8px; border-radius: 12px; font-size: 12px; }
#spells { display: flex; flex-direction: column; gap: 3px; margin: 4px 0; }
#spells button { text-align: left; }
#blog { height: 260px; overflow-y: auto; font-size: 12px; background: #0f0a06; border: 1px solid var(--edge); border-radius: 5px; padding: 5px; line-height: 1.35; }
#blog div { padding: 2px 0; border-bottom: 1px solid #251a0e; }

/* floating UI */
#tip { position: absolute; pointer-events: none; background: rgba(12, 8, 4, .92); border: 1px solid var(--gold); padding: 5px 9px; border-radius: 6px; font-size: 13px; max-width: 270px; z-index: 5; box-shadow: var(--shadow); }
#toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 5px; align-items: center; pointer-events: none; z-index: 6; }
#toast div { background: rgba(12, 8, 4, .92); border: 1px solid var(--gold); padding: 6px 14px; border-radius: 6px; font-size: 14px; box-shadow: var(--shadow); animation: toastIn .25s ease-out, fade 2.8s forwards; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { 0%, 82% { opacity: 1; } 100% { opacity: 0; } }
#banner { position: absolute; left: 0; right: 0; top: 36%; text-align: center; pointer-events: none; z-index: 7; opacity: 0; }
#banner b { display: inline-block; font-size: 44px; color: var(--gold); letter-spacing: 3px; text-shadow: 0 0 18px #a37a1c, 0 3px 0 #000, 0 0 3px #000; }
#banner span { display: block; margin-top: 4px; font-size: 20px; color: var(--txt); text-shadow: 0 2px 3px #000; }
#banner.show { animation: bannerAnim 2.1s ease-out forwards; }
@keyframes bannerAnim { 0% { opacity: 0; transform: scale(.8); } 15% { opacity: 1; transform: scale(1.05); } 25% { transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* modal */
#modal { flex-direction: column; gap: 8px; position: fixed; inset: 0; background: rgba(4, 2, 0, .72); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 40; animation: fadeIn .15s ease-out; padding: 10px; }
#modal.hide { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
#mbox { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 3px solid var(--gold); border-radius: 10px; padding: 16px 22px; max-width: 780px; max-height: 92vh; overflow-y: auto; min-width: 340px; box-shadow: 0 10px 40px rgba(0, 0, 0, .8), 0 0 0 4px #140e07; animation: popIn .18s ease-out; }
#mbox h2 { margin: 0 0 8px; color: var(--gold); text-shadow: 0 1px 0 #000; }
#mbox h4 { margin: 10px 0 4px; color: var(--mut); }
#mbox .mb { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; position: sticky; bottom: -16px; padding-top: 6px; background: linear-gradient(transparent, var(--panel) 40%); }
.trow { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 6px 4px; border-bottom: 1px solid #44331c; transition: background .12s; }
.trow:hover { background: rgba(255, 235, 180, .04); }
.trow .ic { font-size: 27px; text-align: center; }
.trow .acts { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 330px; }
.trow .acts input { width: 58px; }

/* selection cards */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid.two { grid-template-columns: repeat(2, 1fr); }
.card { background: linear-gradient(#251a0e, #1a1209); border: 2px solid var(--edge); border-radius: 10px; padding: 11px; text-align: center; cursor: pointer; transition: transform .12s, border-color .12s, box-shadow .12s; }
.card:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, .55), 0 0 12px rgba(230, 191, 85, .25); }
.card.on { border-color: var(--gold); background: linear-gradient(#3d2c15, #281c0d); box-shadow: 0 0 12px rgba(230, 191, 85, .35); }
.card .big { font-size: 40px; filter: drop-shadow(0 2px 3px #000); } .card .crow { font-size: 20px; margin-top: 6px; letter-spacing: 3px; }

/* title screen */
#title { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, #4a3418 0%, #1a1008 55%, #070402 100%); overflow: hidden; }
#title::before { content: ""; position: fixed; inset: -50%; background: conic-gradient(from 0deg at 50% 50%, transparent 0 20%, rgba(230, 191, 85, .07) 25%, transparent 30% 70%, rgba(230, 191, 85, .07) 75%, transparent 80%); animation: spin 40s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.titlebox { position: relative; text-align: center; padding: 34px 56px; border: 3px solid var(--gold); border-radius: 14px; background: rgba(20, 14, 8, .82); box-shadow: 0 0 40px rgba(163, 122, 28, .45), inset 0 0 30px rgba(0, 0, 0, .6); animation: popIn .5s ease-out; }
.titlebox h1 { margin: 0; font-size: 42px; color: var(--gold); text-shadow: 0 0 16px #a37a1c, 0 3px 0 #000; letter-spacing: 1px; }
.titlebox .sub { margin: 8px 0 24px; opacity: .85; font-style: italic; }
.col { display: flex; flex-direction: column; gap: 9px; }
.col button { padding: 11px 46px; font-size: 18px; }

/* responsive: side panel below the map becomes a 2-column grid */
@media (max-width: 1120px) {
  #game { flex-direction: column; }
  #stage { flex: none; width: 100%; }
  #side { width: 100%; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  #mini { grid-column: 1 / -1; max-width: 420px; justify-self: center; }
  .inbattle #batui { grid-column: 1 / -1; }
  #army { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 620px) {
  #side { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  #res { gap: 4px; } .chip { font-size: 13px; padding: 1px 7px; }
  .armyrow { grid-template-columns: repeat(7, 1fr); }
  #banner b { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* ---------- map controls, touch and phone layout ---------- */
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#map { touch-action: none; }
#zoomctl { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 5px; z-index: 8; }
#zoomctl button { width: 38px; height: 38px; padding: 0; font-size: 18px; background: rgba(20, 14, 8, .88); }
.inbattle #zoomctl { display: none; }
#mbar { display: none; }
body.inbattle { padding-bottom: 0; }

@media (max-width: 760px) {
  body { padding-bottom: calc(68px + var(--sab)); }
  body.inbattle { padding-bottom: 232px; }
  #app { padding: 6px; }
  #top { padding: 5px 7px; gap: 6px; }
  #top .btns { display: none; }
  #income, #date { font-size: 11px; }
  #date { flex: 1 1 100%; order: 3; }
  #mbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; gap: 6px; padding: 8px 8px calc(8px + var(--sab)); background: linear-gradient(#2a1f14, #150f09); border-top: 2px solid var(--edge); }
  #mbar button { padding: 12px 4px; font-size: 15px; }
  #mbar button.primary { flex: 1.7; }
  #mbar #mMenu { flex: 0 0 54px; }
  body.inbattle #mbar { display: none; }
  #stage { height: 58vh; min-height: 320px; }
  #stage canvas { aspect-ratio: auto; height: 100%; }
  #map { width: 100%; }
  body.inbattle #stage { overflow: auto; height: calc(100vh - 340px); min-height: 250px; -webkit-overflow-scrolling: touch; }
  body.inbattle #stage canvas#bat { height: 100%; width: auto; max-width: none; aspect-ratio: 3 / 2; }
  body.inbattle #batui { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; border-radius: 12px 12px 0 0; padding: 7px 8px calc(7px + var(--sab)); }
  body.inbattle #batui h3 { display: none; }
  body.inbattle #batui .row button { padding: 11px 2px; font-size: 13px; }
  body.inbattle #batui kbd { display: none; }
  body.inbattle #blog { height: 56px; }
  body.inbattle #spells { max-height: 30vh; overflow-y: auto; }
  #side { grid-template-columns: 1fr; }
  #mini { max-width: 100%; }
  #army { grid-template-columns: repeat(4, 1fr); }
  .slot { font-size: 26px; }
  button { min-height: 38px; }
  #mbox { padding: 12px 12px; min-width: 0; width: 100%; max-height: 94vh; border-radius: 10px; }
  #mbox .mb { bottom: -12px; }
  #mbox .mb button { flex: 1; padding: 11px 6px; }
  .trow { grid-template-columns: 34px 1fr; }
  .trow .acts { grid-column: 1 / -1; justify-content: flex-start; max-width: none; }
  .trow .acts button { flex: 1 1 auto; padding: 9px 8px; }
  .grid, .grid.two { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 8px; } .card .big { font-size: 30px; } .card .crow { font-size: 16px; letter-spacing: 1px; }
  .armyrow { grid-template-columns: repeat(7, 1fr); }
  .titlebox { padding: 22px 22px; margin: 10px; } .titlebox h1 { font-size: 27px; } .col button { padding: 13px 30px; }
  #banner b { font-size: 30px; } #banner span { font-size: 15px; }
  #toast { top: 6px; max-width: 92vw; } #toast div { font-size: 13px; padding: 6px 10px; }
  #tip { max-width: 220px; font-size: 12px; }
}
@media (pointer: coarse) { button, .card, .slot { -webkit-user-select: none; user-select: none; } #zoomctl button { width: 44px; height: 44px; } }
.bonus { color: #8fe08f; }

/* painted resource icons + resource strip shown above every dialog */
.ri { width: 1.25em; height: 1.25em; vertical-align: -.28em; image-rendering: auto; }
.chip small.inc { color: var(--good); font-size: .68em; margin-left: 2px; }
#mres { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 780px; width: 100%; padding: 5px 8px; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 2px solid var(--edge); border-radius: 10px; box-shadow: var(--shadow); flex: none; }
#mres .chip { font-size: 14px; }
@media (max-width: 760px) { #mres { gap: 3px; padding: 4px; } #mres .chip { font-size: 12px; padding: 1px 6px; } #mbox { max-height: calc(94vh - 52px); } }

/* ---------- phone: one fixed screen — resources on top, map in the middle, action bar at the bottom ---------- */
@media (max-width: 760px) {
  body:not(.inbattle) { overflow: hidden; padding-bottom: 0; }
  body:not(.inbattle) #app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 4px; padding: 4px; }
  body:not(.inbattle) #top { margin: 0; flex: none; padding: 4px 6px; gap: 2px 8px; }
  body:not(.inbattle) #res { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  body:not(.inbattle) #res .chip { flex: none; font-size: 12px; padding: 1px 5px; gap: 2px; }
  body:not(.inbattle) #res { gap: 3px; }
  #income, #date { font-size: 11px; order: 3; } #date { flex: 1 1 auto; text-align: right; }
  body:not(.inbattle) #game { flex: 1; min-height: 0; display: block; }
  body:not(.inbattle) #stage { height: 100%; min-height: 0; }
  body:not(.inbattle) #side { display: none; }
  #mbar { position: static; flex: none; gap: 3px; padding: 4px 3px calc(4px + var(--sab)); border: 2px solid var(--edge); border-radius: 8px; }
  #mbar button { flex: 1 1 0; min-width: 0; min-height: 50px; padding: 3px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10px; line-height: 1.1; }
  #mbar button b { font-size: 21px; font-weight: normal; line-height: 1; }
  #mbar button.primary { flex: 1.35; }
  #sheetBody > * { margin-bottom: 8px; }
  #sheetBody #mini { display: block; }
  #sheetBody #army { grid-template-columns: repeat(4, 1fr); }
  #sheetBody .slot { font-size: 30px; }
}

/* painted portraits */
.pic { display: block; margin: 0 auto; border-radius: 7px; image-rendering: auto; }
.pic.round { border-radius: 50%; }
.slot .pic { margin-bottom: 1px; }
.crow .pic, .card .small .pic { display: inline-block; vertical-align: middle; margin: 0 1px; }
.hbtn { padding: 2px 3px; } .hbtn .pic { margin: 0; }
#hero h3 .pic { display: inline-block; vertical-align: middle; }

/* ================= MAIN SCREEN SKELETON (adventure screen): slim top bar, framed map, ornate right column =================
   Pure CSS ornament (no images): stone panels with a double gold rule and corner studs. Everything falls back to the plain panels above. */
body #minipanel, body #hero, body #army, body #terr, body #emblem {
  position: relative; background: var(--grain), linear-gradient(180deg, #231911, #140d08); border: 1px solid #0a0603; border-radius: 6px;
  box-shadow: inset 0 0 0 1px #6b5226, inset 0 0 0 3px #17100a, inset 0 0 0 4px #8c6a33, 0 4px 12px rgba(0, 0, 0, .55);
}
#minipanel::before, #hero::before, #army::before, #terr::before, #emblem::before, #stage::before {
  content: ""; position: absolute; inset: 3px; pointer-events: none; z-index: 3;
  background:
    radial-gradient(circle at 4px 4px, #f6dc8a 0 1.3px, #8a6420 2.2px, transparent 3.2px),
    radial-gradient(circle at calc(100% - 4px) 4px, #f6dc8a 0 1.3px, #8a6420 2.2px, transparent 3.2px),
    radial-gradient(circle at 4px calc(100% - 4px), #f6dc8a 0 1.3px, #8a6420 2.2px, transparent 3.2px),
    radial-gradient(circle at calc(100% - 4px) calc(100% - 4px), #f6dc8a 0 1.3px, #8a6420 2.2px, transparent 3.2px);
}
body #stage { border: 3px solid #8c6a33; border-radius: 6px; box-shadow: 0 0 0 2px #0a0603, 0 0 0 4px #4a3516, 0 6px 18px rgba(0, 0, 0, .7), inset 0 0 0 2px #0a0603; }
#stage::before { inset: 4px; }
body.inbattle #stage::before, body.inbattle #minipanel, body.inbattle #emblem { display: none !important; }
body #side { scrollbar-width: thin; scrollbar-color: #8c6a33 #140d08; }
#side > * { flex: none; }
/* minimap with a compass */
body #minipanel { padding: 8px; }
body #minipanel #mini { display: block; width: 100%; border: 1px solid #000; border-radius: 4px; box-shadow: inset 0 0 0 1px #3a2c18, 0 0 0 1px #3a2c18; }
.compass { position: absolute; right: 13px; top: 13px; width: 40px; height: 40px; border-radius: 50%; pointer-events: none; z-index: 4; background: radial-gradient(circle, rgba(8, 5, 2, .78) 58%, rgba(8, 5, 2, .3)); border: 1px solid #8c6a33; box-shadow: 0 1px 4px #000; }
.compass b { position: absolute; font: 700 7.5px var(--f-head, serif); color: #e6bf55; line-height: 1; text-shadow: 0 1px 1px #000; }
.compass .cn { left: 50%; top: 2px; transform: translateX(-50%); } .compass .cs { left: 50%; bottom: 2px; transform: translateX(-50%); }
.compass .ce { right: 3px; top: 50%; transform: translateY(-50%); } .compass .cw { left: 3px; top: 50%; transform: translateY(-50%); }
.compass em { position: absolute; inset: 11px; background: linear-gradient(135deg, #f6dc8a, #8a6420); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
/* hero card */
body #hero { padding: 9px 10px 10px; }
#hero .hlist { margin-bottom: 8px; padding-bottom: 7px; border-bottom: 1px solid #3a2c18; }
#hero .hcard { display: grid; grid-template-columns: 86px 1fr; grid-template-areas: "port head" "grid grid"; gap: 6px 10px; align-items: center; }
#hero .hport { grid-area: port; position: relative; width: 86px; height: 86px; }
#hero .hport .pic { width: 84px !important; height: 84px !important; border-radius: 50%; border: 3px solid #e6bf55; box-shadow: 0 0 0 2px #0a0603, 0 3px 10px #000, inset 0 0 0 2px #6b4a14; background: #0a0603; }
#hero .hlvl { position: absolute; right: -3px; bottom: -3px; min-width: 25px; height: 25px; padding: 0 3px; box-sizing: border-box; border-radius: 13px; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 35% 30%, #f6dc8a, #a37a1c); color: #2a1a06; font: 700 13px var(--f-head, serif); border: 2px solid #0a0603; box-shadow: 0 1px 4px #000; }
#hero .hhead { grid-area: head; display: flex; flex-direction: column; gap: 3px; min-width: 0; line-height: 1.1; }
#hero .hname { color: var(--gold); font: 700 17px var(--f-head, serif); letter-spacing: 1px; text-transform: uppercase; text-shadow: 0 1px 0 #000; overflow-wrap: anywhere; }
#hero .hcls { font-size: 11.5px; color: var(--mut); }
#hero .hgrid { grid-area: grid; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
#hero .hst { background: linear-gradient(#100b06, #1c140c); border: 1px solid #4a381c; border-radius: 6px; padding: 4px 2px 3px; text-align: center; line-height: 1.05; box-shadow: inset 0 1px 0 rgba(255, 235, 180, .06); }
#hero .hst .hi { display: block; height: 17px; font-size: 15px; } #hero .hst .hi .gi { width: 17px; height: 17px; vertical-align: top; margin: 0; }
#hero .hst b { display: block; font: 700 15px var(--f-head, serif); color: var(--txt); margin-top: 1px; } #hero .hst b .bonus { font-size: 9px; color: #7ddc7a; }
#hero .hst em { font-style: normal; font-size: 9.5px; color: var(--mut); font-weight: 600; }
#hero .hst small { display: block; margin-top: 1px; font: 600 7.5px var(--f-head, serif); letter-spacing: 1px; color: #a8905a; }
#hero .hst u { display: block; height: 3px; margin: 3px 6px 0; border-radius: 2px; text-decoration: none; background: linear-gradient(90deg, var(--c, #d6a43a) var(--p), #0b0805 var(--p)); box-shadow: 0 0 0 1px #000; }
#hero .hst:nth-child(6) u { --c: #3a7ad6; }
#hero .hbar { position: relative; height: 15px; margin: 8px 0 5px; background: #0b0805; border: 1px solid #4a381c; border-radius: 8px; overflow: hidden; }
#hero .hbar > i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#a36ae6, #6a3aa8); transition: width .35s; }
#hero .hbar > span { position: relative; display: block; text-align: center; font: 700 9.5px/13px var(--f-head, serif); letter-spacing: 1px; color: #f1e6ff; text-shadow: 0 1px 1px #000; }
#hero .hmood, #hero .hperks, #hero .hspells { margin-top: 3px; }
#hero .hacts { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 8px; }
#hero .hacts .small-btn { margin: 0; width: auto; min-width: 0; padding: 5px 3px; font-size: 11.5px; line-height: 1.15; }
#hero .hacts .bcnt { opacity: .7; font-size: .85em; }
/* army: a tidy 4x2 grid */
body #army { padding: 9px; gap: 6px; }
body #army .slot { aspect-ratio: 1 / 1.1; border-radius: 6px; border: 1px solid #5a4422; background: radial-gradient(circle at 50% 30%, #33261a, #130d08); box-shadow: inset 0 0 0 1px #000, inset 0 0 0 2px #2a1d0e; overflow: hidden; }
body #army .slot .pic { width: 90% !important; height: auto !important; aspect-ratio: 1; }
body #army .slot small { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 1px 0 2px; font: 700 11px var(--f-head, serif); text-align: center; background: linear-gradient(transparent, rgba(0, 0, 0, .85)); color: #fff; }
body #army .slot.empty { opacity: 1; border-style: dashed; border-color: #3a2c18; background: linear-gradient(#150f09, #0d0905); box-shadow: inset 0 0 0 1px #000; }
body #army .slot.empty::after { content: ""; position: absolute; inset: 24%; opacity: .3; background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path fill='%23e6bf55' d='M16 2c3 4 4 8 0 13 4-2 7-1 7 3 0 3-3 4-5 3 1 2 1 4 0 6h2v3h-8v-3h2c-1-2-1-4 0-6-2 1-5 0-5-3 0-4 3-5 7-3-4-5-3-9 0-13z'/></svg>") center / contain no-repeat; }
body #army .slot.sel { border-color: var(--gold); outline: none; box-shadow: 0 0 0 1px var(--gold), 0 0 12px rgba(230, 191, 85, .5), inset 0 0 0 1px #000; }
#army .sdeco { aspect-ratio: 1 / 1.1; border-radius: 6px; border: 1px solid #3a2c18; position: relative; background: radial-gradient(circle at 50% 40%, rgba(230, 191, 85, .16), transparent 62%), linear-gradient(#150f09, #0d0905); }
#army .sdeco::after { content: ""; position: absolute; inset: 22%; opacity: .45; background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path fill='none' stroke='%23e6bf55' stroke-width='2' stroke-linejoin='round' d='M16 3l11 4v9c0 6-5 10-11 13C10 26 5 22 5 16V7z'/><path fill='%23e6bf55' d='M16 9l2 5h5l-4 3 1.5 5L16 19l-4.500 3L13 17l-4-3h5z'/></svg>") center / contain no-repeat; }
#army > .small { font-size: 10.5px; opacity: .6; line-height: 1.25; text-align: center; }
/* territory + emblem */
body #terr { padding: 8px 10px; }
#terr h3 { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
#terr .zrow, #terr .small { font-size: 12px; }
body #emblem { height: 78px; display: flex; align-items: center; justify-content: center; padding: 6px; background: radial-gradient(ellipse at 50% 45%, rgba(70, 110, 200, .2), transparent 62%), linear-gradient(180deg, #1b130b, #0f0a06); }
#emblem svg { height: 100%; width: auto; max-width: 100%; filter: drop-shadow(0 2px 3px #000); }
@media (max-height: 940px) { #emblem { display: none; } }
@media (max-width: 1120px) { #emblem { display: none; } body #minipanel { grid-column: 1 / -1; max-width: 420px; justify-self: center; width: 100%; box-sizing: border-box; } }
#sheetBody > #minipanel, #sheetBody > #hero, #sheetBody > #army, #sheetBody > #terr { background: none !important; box-shadow: none !important; border: 0 !important; padding: 4px 2px !important; }
#sheetBody > *::before { display: none !important; }
/* slim, single-row top bar on wide screens */
@media (min-width: 1280px) {
  body #top { flex-wrap: nowrap; gap: 10px; padding: 2px 14px; margin-bottom: 8px; min-height: 0; align-items: center; }
  body #top #res { flex: 0 1 500px; flex-wrap: nowrap; min-width: 0; gap: 4px; overflow: hidden; }
  body #top .chip { font-size: 13px; padding: 1px 7px; }
  body #top #income, body #top .dtTurn, body #top .dtDiff { display: none; }
  body #top #date { flex: 1 1 auto; justify-content: center; text-align: center; min-width: 0; }
  body #top .btns { flex: none; gap: 3px; flex-wrap: nowrap; }
  body #top .btns kbd { display: none; }
  body #top .btns button { white-space: nowrap; flex-direction: row; width: auto; }
  body.skin #top .btns button { border-width: 6px 11px; border-image-width: 6px 11px; padding: 0 2px; font-size: 13px; min-height: 0; line-height: 1.2; }
}
/* a medium desktop window keeps the side column as one column beside the map */
@media (min-width: 761px) and (max-width: 1120px) and (min-height: 541px) and (orientation: landscape) {
  body:not(.inbattle) #side { display: flex; flex-direction: column; }
  body:not(.inbattle) #minipanel { max-width: none; width: auto; }
}
/* compact hero card and action buttons on desktop */
@media (min-width: 761px) {
  #hero .hlist.solo { display: none; }
  #hero .hcard { grid-template-columns: 74px 1fr; gap: 5px 9px; }
  #hero .hport { width: 74px; height: 74px; }
  #hero .hport .pic { width: 72px !important; height: 72px !important; }
  #hero .hname { font-size: 16px; }
  #hero .hgrid { gap: 4px; }
  #hero .hst { padding: 2px 2px 2px; }
  #hero .hst .hi { height: 15px; } #hero .hst .hi .gi { width: 15px; height: 15px; }
  #hero .hst b { font-size: 14px; } #hero .hst u { margin-top: 2px; }
  #hero .hbar { margin: 6px 0 4px; height: 14px; }
  #hero .hmood, #hero .hperks, #hero .hspells { font-size: 11px; line-height: 1.25; margin-top: 2px; }
  #hero .hacts { margin-top: 6px; gap: 4px; }
  body.skin #hero .hacts .small-btn { border-width: 6px 10px; border-image-width: 6px 10px; padding: 0 1px; min-height: 0; font-size: 11px; white-space: nowrap; line-height: 1.2; }
  body:not(.inbattle) #side #army > .small { display: none; }
  body #army .slot, #army .sdeco { aspect-ratio: 1 / 1.04; }
  body #minipanel { padding: 7px; }
}

/* town window tabs */
.ttabs { display: flex; gap: 6px; margin: 8px 0 6px; }
.ttab { flex: 1; padding: 9px 6px; font-size: 15px; font-weight: bold; }
.ttab.on { border-color: var(--gold); background: linear-gradient(#9a7620, #5e4510); }

/* drag & drop of troop stacks (town garrison / hero exchange) */
#mbox .armyrow .slot { touch-action: none; }
.slot.lifted { opacity: .35; }
.slot.drop { outline: 2px dashed var(--gold); background: rgba(230, 191, 85, .18); }
.dragghost { position: fixed; z-index: 90; pointer-events: none; transform: translate(-50%, -60%) scale(1.15); width: 58px; display: flex; flex-direction: column; align-items: center; opacity: .92; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .6)); font-size: 12px; }
.dragghost small { text-shadow: 0 1px 2px #000; }

/* ---------- phone LANDSCAPE: map fills the screen, action bar on the right edge, battle UI in a side column ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  html, body { height: 100%; }
  body { overflow: hidden; padding: 0 !important; }
  body #app { max-width: none; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 3px; padding: 3px calc(70px + var(--sar)) 3px calc(3px + var(--sal)); }
  body.inbattle #app { padding-right: calc(3px + var(--sar)); }
  body #top { margin: 0; flex: none; padding: 3px 8px; gap: 8px; flex-wrap: nowrap; align-items: center; }
  body #top .btns, body #income { display: none; }
  body #res { flex: 1 1 auto; flex-wrap: nowrap; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  body #res .chip, #mres .chip { font-size: 12px; padding: 1px 6px; gap: 2px; flex: none; }
  body #date { flex: 0 0 auto; order: 0; font-size: 11px; white-space: nowrap; }
  body #game { flex: 1; min-height: 0; display: flex; flex-direction: row; gap: 4px; }
  body #stage { flex: 1 1 auto; height: 100% !important; min-height: 0 !important; width: auto; }
  body:not(.inbattle) #stage canvas { height: 100%; width: 100%; aspect-ratio: auto; }
  body:not(.inbattle) #side { display: none; }
  body #mbar { display: flex; position: fixed; right: 0; top: 0; bottom: 0; left: auto; width: calc(66px + var(--sar)); flex-direction: column; gap: 3px; padding: 4px calc(4px + var(--sar)) 4px 4px; z-index: 30; border: 0; border-left: 2px solid var(--edge); border-radius: 0; background: linear-gradient(90deg, #2a1f14, #150f09); }
  body #mbar button { flex: 1 1 0; min-height: 0; padding: 1px 0; font-size: 9px; gap: 0; }
  body #mbar button b { font-size: 17px; }
  body.inbattle #mbar { display: none; }
  /* battle: board on the left (fits the height), controls in a column on the right */
  body.inbattle #stage { overflow: hidden !important; display: flex; align-items: center; justify-content: center; }
  body.inbattle #stage canvas#bat { width: auto; height: auto; max-width: 100%; max-height: 100%; aspect-ratio: 3 / 2; }
  body.inbattle #side { display: flex; flex-direction: column; width: 196px; flex: none; min-height: 0; }
  body.inbattle #batui { position: static; display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 5px; border-radius: 8px; }
  body.inbattle #batui h3, body.inbattle #batui kbd { display: none; }
  body.inbattle #batui .row { margin-bottom: 4px; gap: 4px; }
  body.inbattle #batui .row button { padding: 7px 2px; font-size: 12px; min-height: 0; }
  body.inbattle #blog { flex: 1; height: auto; min-height: 36px; font-size: 11px; }
  body.inbattle #spells { max-height: 45%; overflow-y: auto; }
  /* dialogs and title */
  #modal { padding: 4px; gap: 4px; }
  #mbox { max-height: calc(100vh - 50px); max-height: calc(100dvh - 50px); padding: 10px 14px; }
  #mres { padding: 3px 6px; }
  .titlebox { padding: 14px 30px; } .titlebox h1 { font-size: 26px; } .titlebox .sub { margin: 4px 0 12px; } .col { gap: 6px; } .col button { padding: 8px 30px; font-size: 16px; }
  #zoomctl { bottom: 6px; right: 6px; } #zoomctl button { width: 36px; height: 36px; }
}

/* troop slots: the picture must never start the browser's own image drag */
.slot img, .dragghost img, .pic { -webkit-user-drag: none; user-select: none; }
.slot img { pointer-events: none; }
@media (orientation: landscape) and (max-height: 540px) { #tcv { height: 96px !important; object-fit: cover; object-position: 50% 48%; } }
/* the card a clicked plot in the castle picture points at */
.slotflash { animation: slotflash 1.5s ease; }
@keyframes slotflash { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 214, 110, 0); } 25%, 75% { box-shadow: 0 0 0 3px #ffd766, 0 0 22px rgba(255, 214, 110, .7); } }

/* ---------- menu, settings, slots ---------- */
.menugrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menugrid button { padding: 13px 8px; font-size: 15px; }
@media (max-width: 760px) { .menugrid { gap: 6px; } .menugrid button { padding: 8px 6px; font-size: 14px; } }
.setrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #44331c; flex-wrap: wrap; }
.setrow > div:first-child { flex: 1 1 150px; }
.setrow a { color: var(--gold); }
.seg { display: inline-flex; gap: 0; }
.seg button { border-radius: 0; padding: 7px 11px; min-height: 36px; }
.seg button:first-child { border-radius: 6px 0 0 6px; } .seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { border-color: var(--gold); background: linear-gradient(#9a7620, #5e4510); font-weight: bold; }
input[type=range] { accent-color: var(--gold); width: 150px; }
#autosave { position: absolute; right: 10px; top: 10px; z-index: 9; background: rgba(12, 8, 4, .85); border: 1px solid var(--edge-l); border-radius: 12px; padding: 3px 10px; font-size: 12px; animation: fade 1.8s forwards; pointer-events: none; }
#top, #side, #mbox, #mbar { zoom: var(--ui, 1); }
body.lefty #zoomctl { right: auto; left: 8px; }
@media (max-width: 760px) { body.lefty #mbar { flex-direction: row-reverse; } }
@media (orientation: landscape) and (max-height: 540px) { body.lefty #mbar { right: auto; left: 0; border-left: 0; border-right: 2px solid var(--edge); } body.lefty:not(.inbattle) #app { padding-left: calc(70px + var(--sal)); padding-right: calc(3px + var(--sar)); } }

.row2 { display: flex; gap: 6px; } .row2 .small-btn { flex: 1; }
.trow.rep { cursor: pointer; } .trow.rep:hover { background: rgba(255, 235, 180, .08); }
#income, #res { cursor: pointer; }

.ico { display: inline-block; vertical-align: -.28em; border-radius: 50%; image-rendering: auto; }
/* dialogs slide up as bottom sheets on phones */
@media (max-width: 760px) and (orientation: portrait) {
  #modal { align-items: stretch; justify-content: flex-end; padding: 0; gap: 0; }
  #mres { border-radius: 0; border-left: 0; border-right: 0; max-width: none; margin: 0; }
  #mbox { width: 100%; max-width: none; border-radius: 16px 16px 0 0; border-width: 3px 0 0 0; max-height: 82vh; padding-bottom: calc(14px + var(--sab)); animation: sheetUp .22s ease-out; }
}
@keyframes sheetUp { from { transform: translateY(60%); opacity: .4; } to { transform: none; opacity: 1; } }

/* hints and achievements */
#hint { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 36; width: min(480px, calc(100vw - 20px)); background: linear-gradient(180deg, #3a2a18, #24190d); border: 2px solid var(--gold); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); animation: toastIn .3s ease-out; font-size: 14px; line-height: 1.4; }
#hint .hb { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
#hint .hb button { padding: 5px 12px; min-height: 0; }
@media (max-width: 760px) { #hint { top: auto; bottom: calc(84px + var(--sab)); } body.inbattle #hint { display: none; } }
@media (orientation: landscape) and (max-height: 540px) { #hint { top: 40px; bottom: auto; width: min(420px, 60vw); } }
.achgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.achrow { display: flex; gap: 10px; align-items: flex-start; background: rgba(0, 0, 0, .22); border: 1px solid #44331c; border-radius: 8px; padding: 7px 9px; opacity: .7; }
.achrow.on { opacity: 1; border-color: var(--gold-d); background: rgba(230, 191, 85, .08); }
.achrow .bar { margin: 4px 0 2px; height: 8px; } .achrow .ico { flex: none; }
.lockedico { display: inline-flex; align-items: center; justify-content: center; background: #2a2a2a; border: 2px solid #555; font-size: 18px; filter: grayscale(1); }
.achpop { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 95; display: flex; gap: 10px; align-items: center; background: linear-gradient(180deg, #4a3518, #2a1d0c); border: 2px solid var(--gold); border-radius: 12px; padding: 9px 16px 9px 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .7), 0 0 18px rgba(230, 191, 85, .45); animation: achIn .45s cubic-bezier(.2, 1.2, .4, 1); max-width: 92vw; }
.achpop.out { opacity: 0; transform: translateX(-50%) translateY(-14px); transition: all .4s; }
@keyframes achIn { from { opacity: 0; transform: translateX(-50%) translateY(-24px) scale(.9); } to { opacity: 1; transform: translateX(-50%); } }
@media (max-width: 560px) { .achgrid { grid-template-columns: 1fr; } }

/* leaderboard */
.lbrow { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 6px 4px; border-bottom: 1px solid #44331c; }
.lbrow.me { background: rgba(230, 191, 85, .12); }
.lbrank { text-align: center; font-weight: bold; color: var(--mut); } .lbrank.r1 { color: #ffd24a; font-size: 19px; } .lbrank.r2 { color: #d8dde5; font-size: 17px; } .lbrank.r3 { color: #e0955a; font-size: 16px; }
.lbscore { font-size: 18px; font-weight: bold; color: var(--gold); }

.swatch { width: 30px; height: 30px; min-height: 0 !important; padding: 0; border-radius: 50%; border: 2px solid #000; margin: 0 3px 3px 0; }
.swatch.on { outline: 3px solid var(--gold); outline-offset: 1px; }

.townpic { width: 100%; max-width: 130px; border-radius: 10px; border: 2px solid var(--edge-l); box-shadow: var(--shadow); }
#loadmsg { margin: 0 0 6px; min-height: 1em; color: var(--mut); }

/* ---------- interface skin from the art pack (only when art/ui/*.webp exist; body.skin is set by the game) ---------- */
body.skin button:not(.slot):not(.htile):not(.hbtn):not(.swatch):not(.seg button):not(#zoomctl button):not(.ttab) { border: 11px solid transparent; border-image: var(--b-n, url(art/ui/btn_normal.png)) 34 52 fill / 11px 17px stretch; background: none; box-shadow: none; padding: 4px 10px; min-height: 40px; color: #f3e7c6; text-shadow: 0 1px 2px #000; }
body.skin button.primary:not(.slot):not(.seg button):not(#zoomctl button) { border-image-source: var(--b-p, url(art/ui/btn_pressed.png)) !important; color: #2a1a06 !important; text-shadow: 0 1px 0 rgba(255, 240, 190, .5); font-weight: bold; }
body.skin button:disabled { border-image-source: var(--b-d, url(art/ui/btn_disabled.png)) !important; color: #9a9a9a; opacity: .75; }
body.skin button:hover:not(:disabled):not(.slot):not(.seg button) { filter: brightness(1.18); }
body.skin #top { border: 16px solid transparent; border-image: none; background: none; box-shadow: none; position: relative; }
body.skin #mres { border: 12px solid transparent; border-image: var(--f-tb, url(art/ui/frame_toolbar.png)) 26 fill / 12px stretch; background: none; box-shadow: none; }
body.skin #mbox { border: 22px solid transparent; border-image: var(--f-sc, url(art/ui/frame_scroll.png)) 90 / 22px stretch; background-clip: padding-box; box-shadow: 0 10px 40px rgba(0, 0, 0, .8); }
body.skin #zoomctl button { border: 0; background: var(--f-cm, url(art/ui/frame_command.png)) center / 100% 100% no-repeat; box-shadow: none; color: #f3e7c6; font-size: 20px; text-shadow: 0 1px 2px #000; }
body.skin .seg button { border-radius: 0; }

/* ---------- desktop / tablet: the adventure map fills the whole window height ---------- */
@media (min-width: 761px) and (min-height: 541px) and (orientation: landscape) {
  body:not(.inbattle) { overflow: hidden; }
  body:not(.inbattle) #app { max-width: none; height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding: 8px 10px; }
  body:not(.inbattle) #top { flex: none; margin-bottom: 8px; }
  body:not(.inbattle) #game { flex: 1; min-height: 0; align-items: stretch; flex-direction: row; }
  body:not(.inbattle) #stage { flex: 1 1 auto; height: 100%; min-height: 0; }
  body:not(.inbattle) #stage canvas#map { width: 100%; height: 100%; aspect-ratio: auto; }
  body:not(.inbattle) #side { overflow-y: auto; min-height: 0; width: 290px; }
  body:not(.inbattle) #mbar { display: none; }
  body.inbattle #app { max-width: none; }
}

/* ---------- setup screens: wide, quiet stone frames, gold only for the selection ---------- */
#mbox:has(> .setup) { max-width: min(1180px, 96vw); width: min(1180px, 96vw); }
.setup { position: relative; }
.setup .card { border-color: var(--edge); background: linear-gradient(#211710, #17100a); }
.setup .card:hover { border-color: var(--gold); transform: none; box-shadow: 0 0 0 1px var(--gold), 0 6px 18px rgba(0, 0, 0, .55); }
.setup .card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 16px rgba(230, 191, 85, .35); background: linear-gradient(#2e2112, #1d140a); }
.setup .mprev { display: block; width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 7px; border: 1px solid #000; margin-bottom: 6px; }
.flagbtn { width: auto !important; height: 48px !important; min-width: 40px; border-radius: 8px !important; background: #1a120a !important; padding: 2px 4px !important; display: inline-flex; align-items: center; justify-content: center; border: 2px solid #4a381c !important; }
.flagbtn.on { outline: none !important; border-color: var(--gold) !important; box-shadow: 0 0 10px rgba(230, 191, 85, .45); }
.flagimg { display: block; width: auto; filter: drop-shadow(0 2px 2px #000); }
.setrow .flagimg { display: inline-block; vertical-align: middle; }
/* castle cards */
.facgrid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card.fac { padding: 0 0 10px; overflow: hidden; }
.facpic { position: relative; height: 210px; overflow: hidden; background: #0b0805; }
.facpic img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 35%; display: block; }
.facicon { font-size: 80px; display: flex; align-items: center; justify-content: center; height: 100%; }
.ribbon { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 7px; font-size: 22px; font-weight: bold; color: #fff3cf; text-shadow: 0 2px 3px #000; background: linear-gradient(transparent, var(--ban) 70%); letter-spacing: .5px; }
.card.fac .blurb { padding: 8px 12px 2px; font-size: 13px; min-height: 2.6em; }
.card.fac .crow { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin-top: 6px; letter-spacing: 0; }
.card.fac .crow .pic { border: 1px solid #000; }
/* hero chooser */
.hsbody { display: grid; grid-template-columns: 1fr 330px; gap: 16px; align-items: start; }
.hsgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.htile { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px 6px; background: linear-gradient(#211710, #17100a); border: 2px solid var(--edge); border-radius: 10px; }
.htile span { font-weight: bold; font-size: 14px; margin-top: 3px; } .htile small { color: var(--mut); font-size: 11px; }
.htile .pic { border: 2px solid #000; }
.htile.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 14px rgba(230, 191, 85, .35); background: linear-gradient(#2e2112, #1d140a); }
.hspan { position: sticky; top: 0; background: linear-gradient(#1e150c, #130d07); border: 2px solid var(--gold); border-radius: 12px; padding: 14px; text-align: center; }
.hspan h3 { margin: 6px 0 0; font-size: 22px; color: var(--gold); } .hscls { color: var(--mut); font-size: 13px; margin-bottom: 8px; }
.hsbig .pic { border: 3px solid var(--gold); box-shadow: 0 4px 14px #000; }
.hsstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0; }
.hsstats div { background: #0f0a05; border: 1px solid #4a381c; border-radius: 8px; padding: 5px 2px; } .hsstats b { display: block; font-size: 20px; } .hsstats span { font-size: 10px; color: var(--mut); }
.hspan h4 { margin: 10px 0 4px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--mut); }
.hsspells { display: flex; flex-wrap: wrap; gap: 4px; } .hsspells > span { background: #0f0a05; border: 1px solid #4a381c; border-radius: 12px; padding: 2px 8px; font-size: 12px; }
.hsarmy { display: flex; gap: 8px; justify-content: center; } .hsarmy div { display: flex; flex-direction: column; align-items: center; width: 90px; font-size: 11px; } .hsarmy .pic { border: 1px solid #000; }
.hsgo { width: 100%; margin-top: 12px; padding: 11px; font-size: 17px; }
@media (max-width: 860px) { .facgrid { grid-template-columns: repeat(2, 1fr); } .facpic { height: 130px; } .hsbody { grid-template-columns: 1fr; } .hspan { position: static; order: -1; } .hsgrid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 520px) { .facgrid { grid-template-columns: 1fr; } }
.setup .grid.two { grid-template-columns: repeat(4, 1fr); }
.setup .grid.two .small { font-size: 12px; }
@media (max-width: 860px) { .setup .grid.two { grid-template-columns: repeat(2, 1fr); } }

/* ---------- title menu: crest, big primary actions, quiet secondary row ---------- */
.titlebox { min-width: 360px; }
.crest { width: 92px; height: 92px; display: block; margin: -62px auto 6px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .8)); }
.titlebox h1 { font-size: 40px; }
.col #tNew { padding: 15px 46px; font-size: 22px; }
.col .main2 { padding: 11px 46px; font-size: 18px; }
.col .sec2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #4a381c; }
.col .sec2 button { padding: 7px 8px; font-size: 14px; opacity: .88; }
@media (max-height: 560px) { .crest { width: 54px; height: 54px; margin-top: -36px; } .col #tNew { padding: 9px 30px; font-size: 18px; } .col .main2 { padding: 7px 30px; font-size: 15px; } .col .sec2 { margin-top: 6px; padding-top: 6px; } .col .sec2 button { padding: 5px; font-size: 12px; } }

/* ---------- town: wide panorama, large creature pictures and recruit controls, calm locked rows ---------- */
#mbox:has(.townwide) { max-width: min(1060px, 96vw); width: min(1060px, 96vw); }
.trow.big { grid-template-columns: 78px 1fr auto; padding: 9px 6px; gap: 12px; }
.trow.big .ic .pic { border: 2px solid #000; border-radius: 9px; box-shadow: 0 2px 8px rgba(0, 0, 0, .6); }
.trow.big b { font-size: 17px; }
.trow.big .acts { max-width: 420px; gap: 7px; }
.trow.big .acts input { width: 76px; font-size: 18px; padding: 7px 6px; text-align: center; }
.trow.big .acts button { padding: 9px 16px; font-size: 15px; }
.trow.big .acts button[data-buy] { background: linear-gradient(#9a7620, #5e4510); border-color: var(--gold); font-weight: bold; }
.trow.lockedrow { opacity: .5; filter: saturate(.55); } .trow.lockedrow:hover { opacity: .75; }
.lockpill { font-size: 12px; color: var(--mut); border: 1px dashed var(--edge); border-radius: 12px; padding: 3px 10px; white-space: nowrap; }
@media (max-width: 760px) { .trow.big { grid-template-columns: 60px 1fr; } .trow.big .ic .pic { width: 56px; height: 56px; } .trow.big .acts input { width: 64px; } }
@media (max-width: 860px) { .hsbig .pic { width: 92px; height: 92px; } .hspan { padding: 10px; } .hspan h4 { margin-top: 6px; } .hsstats { margin: 4px 0; } .hsarmy .pic { width: 48px; height: 48px; } .hsgo { margin-top: 8px; } }

/* scenarios */
.scngrid { grid-template-columns: repeat(2, 1fr); gap: 12px; align-content: start; }
.card.scn { padding: 8px; } .card.scn b { display: block; margin: 2px 0; }
.scnpan .mprev { margin-bottom: 8px; } .scnb { margin: 6px 0 0; font-size: 14px; line-height: 1.4; text-align: left; }
.scngoal { text-align: left; background: #0f0a05; border: 1px solid var(--gold-d); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.col .main2 { padding: 11px 46px; font-size: 18px; }

/* date block */
#date { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; white-space: normal; max-width: none; color: var(--txt); }
.dtIco { font-size: 26px; filter: drop-shadow(0 1px 3px #000); }
.dtMain { display: flex; flex-direction: column; line-height: 1.05; }
.dtMain small { font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--mut); }
.dtMain b { font-size: 22px; color: var(--gold); text-shadow: 0 1px 0 #000, 0 0 10px rgba(230, 191, 85, .35); font-weight: 700; }
.dtTurn { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--mut); text-align: center; line-height: 1.1; padding: 2px 8px; border-left: 1px solid var(--edge); border-right: 1px solid var(--edge); }
.dtTurn b { font-size: 15px; color: var(--txt); letter-spacing: 0; }
.dtDiff, .dtGoal { font-size: 12px; border: 1px solid var(--edge); background: rgba(0, 0, 0, .35); border-radius: 12px; padding: 2px 9px; white-space: nowrap; }
.dtGoal { color: #f1d98a; border-color: var(--gold-d); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 760px) { .dtIco { font-size: 18px; } .dtMain b { font-size: 15px; } .dtMain small { font-size: 9px; } .dtTurn { display: none; } .dtDiff, .dtGoal { font-size: 10px; padding: 1px 6px; } }

/* the rivals' turn: the whole interface dulls until it is yours again */
#app { transition: filter .35s; }

body.aiturn #top::after { content: "Rivals are moving…"; position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); font-size: 12px; color: var(--mut); background: rgba(0, 0, 0, .6); border-radius: 10px; padding: 2px 12px; z-index: 5; }

/* minimap frame */
#mini { image-rendering: auto; border: 3px solid var(--edge-l); border-radius: 10px; box-shadow: var(--shadow), inset 0 0 0 1px #000, 0 0 0 2px #140e07; touch-action: none; cursor: crosshair; }

/* ---------- day and night: the top bar crossfades between a bright day frame and a dark night frame, the sun gives way to the moon ---------- */
.sky { display: none; }
body.skin .sky { display: block; position: absolute; inset: -16px; border: 16px solid transparent; pointer-events: none; z-index: 0; transition: opacity 1.8s ease; }
body.skin .skyD { border-image: var(--t-d, url(art/ui/topbar_day.png)) 38 fill / 16px stretch; opacity: 1; }
body.skin .skyN { border-image: var(--t-n, url(art/ui/topbar_night.png)) 38 fill / 16px stretch; opacity: 0; }
body.skin.night .skyD { opacity: 0; } body.skin.night .skyN { opacity: 1; }
body.skin #top > :not(.sky) { position: relative; z-index: 1; }
#orb { position: relative; width: 34px; height: 34px; flex: none; overflow: hidden; border-radius: 50%; background: radial-gradient(circle, rgba(0,0,0,.28), rgba(0,0,0,0) 70%); }
#orb b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 26px; filter: drop-shadow(0 1px 3px #000); transition: transform 1.6s cubic-bezier(.5, 0, .3, 1), opacity 1.6s; }
#orb .sun { transform: rotate(0) translateY(0); opacity: 1; } #orb .moon { transform: rotate(60deg) translateY(30px); opacity: 0; }
body.night #orb .sun { transform: rotate(-60deg) translateY(-30px); opacity: 0; } body.night #orb .moon { transform: rotate(0) translateY(0); opacity: 1; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2; background: radial-gradient(ellipse at 50% 45%, rgba(20, 30, 90, .1), rgba(8, 14, 60, .42)); opacity: 0; transition: opacity 2.4s ease; mix-blend-mode: multiply; }
body.night:not(.inbattle) #stage::after { opacity: 1; }

/* =====================================================================
   MEDIEVAL LAYER — fonts, parchment & leather textures, riveted frames
   ===================================================================== */
:root {
  --f-head: 'Cinzel', 'Palatino Linotype', Georgia, serif;
  --f-flav: 'IM Fell English', Georgia, serif;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n' x='0' y='0' width='100%' height='100%'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .05  0 0 0 0 .03  0 0 0 0 .01  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --fibre: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='f' x='0' y='0' width='100%' height='100%'><feTurbulence type='fractalNoise' baseFrequency='.012 .35' numOctaves='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .25  0 0 0 0 .16  0 0 0 0 .06  0 0 0 .38 0'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  --rivets: radial-gradient(circle at 10px 10px, #f6e0a0 0 1.5px, #b88a2a 3px, #4a3208 4.5px, transparent 5.5px) top left / 20px 20px no-repeat,
            radial-gradient(circle at 10px 10px, #f6e0a0 0 1.5px, #b88a2a 3px, #4a3208 4.5px, transparent 5.5px) top right / 20px 20px no-repeat,
            radial-gradient(circle at 10px 10px, #f6e0a0 0 1.5px, #b88a2a 3px, #4a3208 4.5px, transparent 5.5px) bottom left / 20px 20px no-repeat,
            radial-gradient(circle at 10px 10px, #f6e0a0 0 1.5px, #b88a2a 3px, #4a3208 4.5px, transparent 5.5px) bottom right / 20px 20px no-repeat;
}
body { font-family: Georgia, "Palatino Linotype", serif; }
h1, h2, h3, h4, .titlebox h1, #banner b, .ttab, .htile span, .ribbon, .hspan h3, .dtMain b, button { font-family: var(--f-head); }
button { letter-spacing: .5px; font-weight: 700; text-shadow: 0 1px 0 rgba(0, 0, 0, .7); }
.small, .sub, .hscls, .blurb, .scnb, .card .small, #loadmsg, .titlebox .sub { font-family: var(--f-flav); font-size: 13.5px; letter-spacing: .1px; }
.titlebox h1 { font-family: 'Cinzel Decorative', var(--f-head); letter-spacing: 2px; }
.titlebox .sub { font-size: 16px; font-style: italic; }

/* riveted leather panels */
#hero, #army, #terr, #batui, .panel {
  background: var(--rivets), var(--grain), var(--fibre), linear-gradient(180deg, var(--panel2), var(--panel));
  border: 2px solid #0d0803; border-radius: 6px;
  box-shadow: inset 0 0 0 2px var(--edge), inset 0 0 0 4px #0d0803, inset 0 0 26px rgba(0, 0, 0, .65), var(--shadow);
  padding: 14px 15px;
}
#hero h3, #terr h3, #batui h3 { font-family: var(--f-head); letter-spacing: 1.2px; text-transform: uppercase; font-size: 15px; }
.slot { box-shadow: inset 0 0 0 1px #0d0803, inset 0 0 0 2px var(--edge), inset 0 0 10px rgba(0, 0, 0, .55); border-radius: 5px; }

/* dialogs: aged scroll */
#mbox { background: var(--grain), var(--fibre), radial-gradient(ellipse at 50% 0%, rgba(120, 82, 36, .35), transparent 70%), linear-gradient(180deg, var(--panel2), var(--panel)); }
#mbox h2 { font-family: var(--f-head); font-size: 24px; letter-spacing: 1.5px; text-transform: uppercase; position: relative; padding-bottom: 12px; margin-bottom: 12px; text-align: center; text-shadow: 0 2px 0 #000, 0 0 14px rgba(230, 191, 85, .25); }
#mbox h2::after { content: ""; position: absolute; left: 6%; right: 6%; bottom: 0; height: 9px; background: linear-gradient(90deg, transparent, var(--gold-d) 25%, var(--gold) 50%, var(--gold-d) 75%, transparent) center 4px / 100% 1px no-repeat; }
#mbox h2::before { content: ""; position: absolute; left: 50%; bottom: 0; width: 9px; height: 9px; transform: translateX(-50%) rotate(45deg); background: var(--gold); box-shadow: 0 0 0 2px #140e07, 0 0 8px rgba(230, 191, 85, .6); z-index: 1; }
#mbox h2 .small { display: block; font-size: 13px; letter-spacing: 0; text-transform: none; margin-top: 2px; color: var(--mut); text-shadow: none; }
#mbox h4 { font-family: var(--f-head); letter-spacing: 1.5px; text-transform: uppercase; font-size: 12px; color: var(--gold-d); border-bottom: 1px solid #4a381c; padding-bottom: 3px; }

/* cards, rows, tiles: stitched leather */
.card, .htile, .hspan, .setrow, .achrow {
  background: var(--grain), linear-gradient(#2a1d12, #1a1209);
  box-shadow: inset 0 0 0 1px #0d0803, inset 0 0 0 3px rgba(140, 106, 51, .35), inset 0 0 14px rgba(0, 0, 0, .55), 0 3px 8px rgba(0, 0, 0, .45);
  border: 2px solid #4a381c; border-radius: 7px;
}
.setup .card, .setup .htile { background: var(--grain), linear-gradient(#271b10, #181008); }
.card:hover, .htile:hover { box-shadow: inset 0 0 0 1px #0d0803, inset 0 0 0 3px rgba(230, 191, 85, .5), 0 0 14px rgba(230, 191, 85, .3), 0 3px 8px rgba(0, 0, 0, .5); }
.card.on, .htile.on, .setup .card.on { box-shadow: inset 0 0 0 1px #0d0803, inset 0 0 0 3px var(--gold), 0 0 16px rgba(230, 191, 85, .4), 0 3px 8px rgba(0, 0, 0, .5); }
.trow { border-bottom: 1px dashed rgba(140, 106, 51, .55); }
.trow:hover { background: linear-gradient(90deg, rgba(230, 191, 85, .07), transparent); }

/* inputs: ink on parchment */
input, select, textarea { background: linear-gradient(#e6d7ae, #cfbd8c); color: #2a1b0a; border: 2px solid var(--edge); box-shadow: inset 0 2px 5px rgba(60, 35, 10, .45); font-family: var(--f-head); font-weight: 600; border-radius: 3px; }
input::placeholder { color: #7a6544; font-family: var(--f-flav); font-style: italic; font-weight: 400; }
input[type=range] { background: none; box-shadow: none; border: none; }

/* resource chips: coin pouches */
.chip, #res .chip, #mres .chip { background: var(--grain), linear-gradient(#1c130b, #0c0804); border: 2px solid var(--edge); box-shadow: inset 0 0 0 1px #000, inset 0 2px 5px rgba(0, 0, 0, .8), 0 1px 0 rgba(255, 220, 140, .15); font-family: var(--f-head); font-weight: 600; letter-spacing: .3px; }
.pill { font-family: var(--f-head); background: linear-gradient(#1c130b, #0c0804); border: 1px solid var(--edge); }

/* toasts and tooltips: pinned parchment */
#toast div, #tip { background: var(--fibre), linear-gradient(#eadcb2, #d3bf8a); color: #2a1b0a; border: 2px solid var(--edge); box-shadow: inset 0 0 0 1px rgba(255, 245, 210, .6), inset 0 0 12px rgba(120, 80, 30, .45), 0 4px 12px rgba(0, 0, 0, .6); font-family: var(--f-flav); font-size: 15px; border-radius: 4px; text-shadow: none; }
#tip b, #toast div b { color: #5a1a0a; }

/* banners and big titles */
#banner b { font-family: 'Cinzel Decorative', var(--f-head); }
.titlebox { background: var(--rivets), var(--grain), var(--fibre), linear-gradient(180deg, rgba(40, 28, 16, .94), rgba(16, 11, 6, .95)); border: 3px double var(--gold); box-shadow: inset 0 0 0 2px #0d0803, inset 0 0 40px rgba(0, 0, 0, .65), 0 0 40px rgba(163, 122, 28, .45); padding: 40px 58px 34px; }

/* page background: dark worn stone */
html, body { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #2f2216 0%, #0d0905 72%); background-attachment: fixed; }
#mbox .mb { background: linear-gradient(transparent, rgba(14, 9, 5, .88) 55%); }
button.danger { background: linear-gradient(#7a2218, #45120c) !important; border-color: #c4472f !important; color: #ffe6dc; font-size: 13px; padding: 5px 10px; }
button.danger:hover:not(:disabled) { background: linear-gradient(#933022, #55170f) !important; }
body.skin button.danger { border-image: none !important; border: 2px solid #c4472f !important; border-radius: 6px; }
button.disb { margin-top: 6px; width: 100%; }

/* ---------- phone: medieval action bar and menu ---------- */
#mbar button .ic { display: flex; width: 30px; height: 30px; font-size: 0; filter: drop-shadow(0 1px 1px #000); }
#mbar button .ic svg { width: 100%; height: 100%; }
#mbar button span { font-family: var(--f-head); font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: #e8d6a0; text-shadow: 0 1px 0 #000, 0 0 4px #000; }
body.skin #mbar button { border: 1px solid #0d0803; border-image: none; border-radius: 9px; background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .16), transparent 70%), linear-gradient(#3b2d1c, #19110a); box-shadow: inset 0 0 0 1px var(--edge), inset 0 0 0 3px #0d0803, inset 0 1px 0 3px rgba(255, 225, 160, .14), 0 2px 4px rgba(0, 0, 0, .6); padding: 4px 0; min-height: 56px; }
body.skin #mbar button:active { transform: translateY(1px); background: var(--grain), linear-gradient(#17100a, #2d2113); box-shadow: inset 0 0 0 1px var(--gold-d), inset 0 0 0 3px #0d0803, inset 0 3px 8px rgba(0, 0, 0, .8); }
body.skin #mbar button.primary { background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 245, 190, .5), transparent 75%), linear-gradient(#c9962c, #7a5110); box-shadow: inset 0 0 0 1px #ffe08a, inset 0 0 0 3px #3a2506, 0 0 12px rgba(230, 191, 85, .5), 0 2px 4px rgba(0, 0, 0, .6); animation: endGlow 2.6s ease-in-out infinite; }
body.skin #mbar button.primary span { color: #2a1604; text-shadow: 0 1px 0 rgba(255, 235, 170, .8); }
@keyframes endGlow { 50% { box-shadow: inset 0 0 0 1px #fff0b0, inset 0 0 0 3px #3a2506, 0 0 20px rgba(255, 215, 110, .85), 0 2px 4px rgba(0, 0, 0, .6); } }
#mbar { background: var(--grain), linear-gradient(#241a10, #0f0a05); border: 2px solid #0d0803; box-shadow: inset 0 0 0 2px var(--edge), inset 0 0 0 3px #0d0803; }
body.skin #mbar { border: 2px solid #0d0803; border-image: none; background: var(--grain), linear-gradient(#241a10, #0f0a05); }
@media (max-width: 760px) {
  .titlebox { min-width: 0; width: 100%; padding: 36px 18px 20px; }
  .titlebox h1 { font-size: 28px; letter-spacing: 1px; white-space: nowrap; }
  .crest { width: 74px; height: 74px; margin-top: -52px; }
  .col { width: 100%; }
  .col button, .col #tNew { width: 100%; min-height: 56px; padding: 10px 14px; }
  .col #tNew { font-size: 21px; letter-spacing: 1.5px; text-transform: uppercase; }
  .col .main2 { font-size: 17px; letter-spacing: 1px; }
  .col .sec2 { gap: 8px; }
  .col .sec2 button { min-height: 46px; font-size: 13px; padding: 6px 4px; }
  body.skin #top .dtMain b { font-size: 17px; }
}
body.skin #mbar button, body.skin #mbar button.primary { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 9px !important; }
body.skin #mbar button { background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .16), transparent 70%), linear-gradient(#3b2d1c, #19110a) !important; box-shadow: inset 0 0 0 1px var(--edge), inset 0 0 0 3px #0d0803, inset 0 1px 0 3px rgba(255, 225, 160, .14), 0 2px 4px rgba(0, 0, 0, .6) !important; padding: 4px 0 !important; min-height: 56px !important; }
body.skin #mbar button:active { background: var(--grain), linear-gradient(#17100a, #2d2113) !important; box-shadow: inset 0 0 0 1px var(--gold-d), inset 0 0 0 3px #0d0803, inset 0 3px 8px rgba(0, 0, 0, .8) !important; }
body.skin #mbar button.primary { background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 245, 190, .5), transparent 75%), linear-gradient(#c9962c, #7a5110) !important; box-shadow: inset 0 0 0 1px #ffe08a, inset 0 0 0 3px #3a2506, 0 0 12px rgba(230, 191, 85, .5), 0 2px 4px rgba(0, 0, 0, .6) !important; }
/* date text stays legible on the bright day frame */
.dtMain small { color: #f6ecc8; text-shadow: 0 1px 2px #000, 0 0 5px #000; }
.dtMain b { color: #ffe08a; text-shadow: 0 1px 0 #000, 0 0 4px #000, 0 0 9px rgba(0, 0, 0, .8); }
.dtTurn { color: #f6ecc8; text-shadow: 0 1px 2px #000; } .dtTurn b { color: #fff; text-shadow: 0 1px 2px #000; }
.menugrid button[data-mn=exit] { grid-column: 1 / -1; }
.seg { flex-wrap: wrap; max-width: 100%; }
.seg button { flex: 1 1 auto; }
/* inside a phone sheet the panels lose their own frame (the sheet is the frame) */
#sheetBody > #hero, #sheetBody > #army, #sheetBody > #terr { background: none !important; box-shadow: none !important; border: 0 !important; padding: 4px 2px !important; }

/* ---------- castle themes: each realm has its own colours, frames and glow (generated by tools/_themecss.js from themes/<castle>/) ---------- */
body { --ic-hi: color-mix(in srgb, var(--gold) 45%, #fff); --ic-mid: var(--gold); --ic-lo: color-mix(in srgb, var(--gold) 45%, #000); }
body.th-castle { --gold: #ffd766; --gold-d: #c9a23a; --edge: #6f8fc4; --edge-l: #a9c2ea; --panel: #3f5782; --panel2: #2f4468; --txt: #fffaf0; --mut: #cdd8ee; --glow: 110,160,255; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/castle/btn_normal.webp); --b-p: url(themes/castle/btn_pressed.webp); --b-d: url(themes/castle/btn_disabled.webp); --f-tb: url(themes/castle/frame_toolbar.webp); --f-sc: url(themes/castle/frame_scroll.webp); --f-cm: url(themes/castle/frame_command.webp); --t-d: url(themes/castle/topbar_day.webp); --t-n: url(themes/castle/topbar_night.webp); }
html:has(body.th-castle), body.th-castle { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #4d6ea6 0%, #182742 78%); background-attachment: fixed; }
body.th-castle .sky, body.th-castle #mbox { filter: drop-shadow(0 0 7px rgba(110,160,255, .45)); }
body.th-rampart { --gold: #f3dc7a; --gold-d: #b0a040; --edge: #5f9a5a; --edge-l: #9ad093; --panel: #2b6040; --panel2: #1d4a2e; --txt: #f6fbe8; --mut: #bfdcb4; --glow: 120,230,120; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/rampart/btn_normal.webp); --b-p: url(themes/rampart/btn_pressed.webp); --b-d: url(themes/rampart/btn_disabled.webp); --f-tb: url(themes/rampart/frame_toolbar.webp); --f-sc: url(themes/rampart/frame_scroll.webp); --f-cm: url(themes/rampart/frame_command.webp); --t-d: url(themes/rampart/topbar_day.webp); --t-n: url(themes/rampart/topbar_night.webp); }
html:has(body.th-rampart), body.th-rampart { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #3f8a50 0%, #0e2a18 78%); background-attachment: fixed; }
body.th-rampart .sky, body.th-rampart #mbox { filter: drop-shadow(0 0 7px rgba(120,230,120, .45)); }
body.th-tower { --gold: #bfeaff; --gold-d: #6fb4d6; --edge: #5aa6cc; --edge-l: #a0daf2; --panel: #2a4d6e; --panel2: #1d3a58; --txt: #f2fbff; --mut: #bcdcec; --glow: 90,220,255; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/tower/btn_normal.webp); --b-p: url(themes/tower/btn_pressed.webp); --b-d: url(themes/tower/btn_disabled.webp); --f-tb: url(themes/tower/frame_toolbar.webp); --f-sc: url(themes/tower/frame_scroll.webp); --f-cm: url(themes/tower/frame_command.webp); --t-d: url(themes/tower/topbar_day.webp); --t-n: url(themes/tower/topbar_night.webp); }
html:has(body.th-tower), body.th-tower { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #3e86b4 0%, #0f2338 78%); background-attachment: fixed; }
body.th-tower .sky, body.th-tower #mbox { filter: drop-shadow(0 0 7px rgba(90,220,255, .45)); }
body.th-inferno { --gold: #ff7a2a; --gold-d: #b4400f; --edge: #8a1d10; --edge-l: #d8440f; --panel: #1c0c0a; --panel2: #100605; --txt: #f1dcd2; --mut: #b8938a; --glow: 255,80,20; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/inferno/btn_normal.webp); --b-p: url(themes/inferno/btn_pressed.webp); --b-d: url(themes/inferno/btn_disabled.webp); --f-tb: url(themes/inferno/frame_toolbar.webp); --f-sc: url(themes/inferno/frame_scroll.webp); --f-cm: url(themes/inferno/frame_command.webp); --t-d: url(themes/inferno/topbar_day.webp); --t-n: url(themes/inferno/topbar_night.webp); }
html:has(body.th-inferno), body.th-inferno { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #5a1408 0%, #050202 74%); background-attachment: fixed; }
body.th-inferno .sky, body.th-inferno #mbox { filter: drop-shadow(0 0 7px rgba(255,80,20, .45)); }
body.th-necropolis { --gold: #9fe8a8; --gold-d: #4a9a66; --edge: #3d6e4c; --edge-l: #6fae82; --panel: #131b17; --panel2: #0b100d; --txt: #e2f0e6; --mut: #93b09c; --glow: 90,255,150; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/necropolis/btn_normal.webp); --b-p: url(themes/necropolis/btn_pressed.webp); --b-d: url(themes/necropolis/btn_disabled.webp); --f-tb: url(themes/necropolis/frame_toolbar.webp); --f-sc: url(themes/necropolis/frame_scroll.webp); --f-cm: url(themes/necropolis/frame_command.webp); --t-d: url(themes/necropolis/topbar_day.webp); --t-n: url(themes/necropolis/topbar_night.webp); }
html:has(body.th-necropolis), body.th-necropolis { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #17392a 0%, #030605 74%); background-attachment: fixed; }
body.th-necropolis .sky, body.th-necropolis #mbox { filter: drop-shadow(0 0 7px rgba(90,255,150, .45)); }
body.th-dungeon { --gold: #d79bff; --gold-d: #8a50c0; --edge: #5a3a8a; --edge-l: #8f5ec8; --panel: #1d1330; --panel2: #110a1e; --txt: #efe4fa; --mut: #a995c4; --glow: 176,90,255; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/dungeon/btn_normal.webp); --b-p: url(themes/dungeon/btn_pressed.webp); --b-d: url(themes/dungeon/btn_disabled.webp); --f-tb: url(themes/dungeon/frame_toolbar.webp); --f-sc: url(themes/dungeon/frame_scroll.webp); --f-cm: url(themes/dungeon/frame_command.webp); --t-d: url(themes/dungeon/topbar_day.webp); --t-n: url(themes/dungeon/topbar_night.webp); }
html:has(body.th-dungeon), body.th-dungeon { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #35205a 0%, #05030a 74%); background-attachment: fixed; }
body.th-dungeon .sky, body.th-dungeon #mbox { filter: drop-shadow(0 0 7px rgba(176,90,255, .45)); }
body.th-stronghold { --gold: #ffb04a; --gold-d: #b8741f; --edge: #8a5a2a; --edge-l: #c88a3c; --panel: #46301a; --panel2: #2f1f10; --txt: #f6e6cc; --mut: #c4a57c; --glow: 255,150,50; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/stronghold/btn_normal.webp); --b-p: url(themes/stronghold/btn_pressed.webp); --b-d: url(themes/stronghold/btn_disabled.webp); --f-tb: url(themes/stronghold/frame_toolbar.webp); --f-sc: url(themes/stronghold/frame_scroll.webp); --f-cm: url(themes/stronghold/frame_command.webp); --t-d: url(themes/stronghold/topbar_day.webp); --t-n: url(themes/stronghold/topbar_night.webp); }
html:has(body.th-stronghold), body.th-stronghold { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #4a2e16 0%, #0d0805 74%); background-attachment: fixed; }
body.th-stronghold .sky, body.th-stronghold #mbox { filter: drop-shadow(0 0 7px rgba(255,150,50, .45)); }
body.th-fortress { --gold: #dcdc6a; --gold-d: #8a9a2a; --edge: #6a7a30; --edge-l: #9caa52; --panel: #2e3a1a; --panel2: #1d2610; --txt: #eef2da; --mut: #adb88a; --glow: 184,208,72; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/fortress/btn_normal.webp); --b-p: url(themes/fortress/btn_pressed.webp); --b-d: url(themes/fortress/btn_disabled.webp); --f-tb: url(themes/fortress/frame_toolbar.webp); --f-sc: url(themes/fortress/frame_scroll.webp); --f-cm: url(themes/fortress/frame_command.webp); --t-d: url(themes/fortress/topbar_day.webp); --t-n: url(themes/fortress/topbar_night.webp); }
html:has(body.th-fortress), body.th-fortress { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #38481c 0%, #090d05 74%); background-attachment: fixed; }
body.th-fortress .sky, body.th-fortress #mbox { filter: drop-shadow(0 0 7px rgba(184,208,72, .45)); }
body.th-conflux { --gold: #ffe9a0; --gold-d: #c0a050; --edge: #6fa8dc; --edge-l: #b0d8ff; --panel: #314868; --panel2: #223350; --txt: #f6fbff; --mut: #c4d4ea; --glow: 120,220,255; --shadow: 0 4px 14px rgba(0, 0, 0, .6);
  --b-n: url(themes/conflux/btn_normal.webp); --b-p: url(themes/conflux/btn_pressed.webp); --b-d: url(themes/conflux/btn_disabled.webp); --f-tb: url(themes/conflux/frame_toolbar.webp); --f-sc: url(themes/conflux/frame_scroll.webp); --f-cm: url(themes/conflux/frame_command.webp); --t-d: url(themes/conflux/topbar_day.webp); --t-n: url(themes/conflux/topbar_night.webp); }
html:has(body.th-conflux), body.th-conflux { background-image: var(--grain), radial-gradient(ellipse at 50% -10%, #436a9a 0%, #101a2e 78%); background-attachment: fixed; }
body.th-conflux .sky, body.th-conflux #mbox { filter: drop-shadow(0 0 7px rgba(120,220,255, .45)); }
body[class*="th-"] button.primary { text-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
body.th-inferno #stage::before, body.th-necropolis #stage::before, body.th-dungeon #stage::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1; box-shadow: inset 0 0 80px 10px rgba(var(--glow), .22); }
body.th-inferno .skyD, body.th-inferno .skyN { animation: lavaPulse 3.2s ease-in-out infinite; }
@keyframes lavaPulse { 50% { filter: drop-shadow(0 0 14px rgba(255, 90, 20, .85)) brightness(1.12); } }
body.th-necropolis .skyD, body.th-necropolis .skyN { animation: ghostPulse 4s ease-in-out infinite; }
@keyframes ghostPulse { 50% { filter: drop-shadow(0 0 12px rgba(90, 255, 150, .7)); } }
body.th-dungeon .skyD, body.th-dungeon .skyN { animation: ghostPulse2 4s ease-in-out infinite; }
@keyframes ghostPulse2 { 50% { filter: drop-shadow(0 0 12px rgba(176, 90, 255, .75)); } }

body.th-inferno, body.th-necropolis, body.th-dungeon, body.th-fortress { --fibre: none; }

/* turn-your-phone prompt shown in battle */
#rotate { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; background: rgba(6, 4, 2, .94); text-align: center; padding: 24px; }
#rotate.hide { display: none !important; }
.rotbox { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 320px; color: var(--txt); }
.rotbox b { font-family: var(--f-head); font-size: 24px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; }
.rotbox span { font-family: var(--f-flav); font-size: 17px; opacity: .9; }
.rotico { width: 96px; height: 96px; color: var(--gold); animation: rotPhone 2.2s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes rotPhone { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
.rotbox button { margin-top: 10px; font-size: 13px; opacity: .8; }

/* ---------- phone in landscape: the battlefield uses the whole screen, controls float on the right ---------- */
#bZoom { display: none; }
@media (orientation: landscape) and (max-height: 540px) {
  body.inbattle { overflow: hidden !important; padding: 0 !important; }
  body.inbattle #app { padding: 0 !important; max-width: none !important; height: 100vh; height: 100dvh; display: block !important; }
  body.inbattle #top, body.inbattle #mbar { display: none !important; }
  body.inbattle #game { display: block !important; height: 100%; }
  body.inbattle #stage { position: fixed !important; left: 0; top: 0; bottom: 40px; right: 0; width: auto !important; height: auto !important; min-height: 0 !important; overflow: auto !important; display: block !important; border: 0 !important; border-radius: 0 !important; z-index: 5; -webkit-overflow-scrolling: touch; box-shadow: none !important; }
  body.inbattle #stage canvas#bat { display: block !important; height: calc(100% * var(--bk, 1.5)) !important; width: auto !important; max-width: none !important; max-height: none !important; aspect-ratio: 3 / 2; margin: 0 auto; }
  body.inbattle.bzfit #stage canvas#bat { height: 100% !important; }
  /* controls live in a slim bar along the bottom so the battlefield gets the full width */
  body.inbattle #side { position: fixed !important; left: 0; right: 0; bottom: 0; top: auto; width: auto !important; height: calc(40px + var(--sab)); box-sizing: border-box; z-index: 40; display: flex !important; flex-direction: row; padding: 2px calc(4px + var(--sar)) calc(2px + var(--sab)) calc(4px + var(--sal)); }
  body.inbattle #batui { display: flex !important; flex-direction: row; align-items: center; gap: 4px; width: 100%; height: 100%; padding: 2px 4px !important; overflow: visible; border-radius: 8px; background: linear-gradient(rgba(24, 16, 9, .94), rgba(12, 8, 4, .96)) !important; }
  body.inbattle #batui h3, body.inbattle #blog { display: none !important; }
  body.inbattle #batui .row { display: contents !important; }
  body.inbattle #batui button { flex: 1 1 0; min-width: 0; font-size: 11px !important; padding: 4px 2px !important; min-height: 32px; height: 32px; letter-spacing: 0; white-space: nowrap; }
  body.inbattle #batui #bZoom, body.inbattle #batui #bManaB { flex: 0 0 auto; }
  body.inbattle #batui #bZoom { width: 40px; }
  body.inbattle #batui kbd { display: none; }
  body.inbattle #bZoom { display: inline-flex; justify-content: center; align-items: center; }
  body.inbattle #batui .pill { padding: 3px 8px; font-size: 12px; }
  body.inbattle #spells { position: fixed; left: 6px; right: 6px; bottom: calc(44px + var(--sab)); max-height: calc(100dvh - 60px); overflow-y: auto; z-index: 45; padding: 6px; border-radius: 8px; background: rgba(14, 9, 5, .97); border: 1px solid var(--edge); }
}
@media (orientation: landscape) and (max-height: 540px) {
  body.skin.inbattle #batui button { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; background: var(--grain), linear-gradient(#3b2d1c, #19110a) !important; box-shadow: inset 0 0 0 1px var(--edge), inset 0 0 0 2px #0d0803 !important; min-height: 32px !important; padding: 5px 2px !important; font-size: 11px !important; }
  body.skin.inbattle #batui button.primary { background: linear-gradient(var(--gold), color-mix(in srgb, var(--gold) 45%, #000)) !important; color: #2a1604 !important; }
  body.skin.inbattle #batui button:disabled { opacity: .45; }
}

/* ---------- phone landscape: compact title menu (crest and name on the left, buttons on the right) ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  .titlebox { display: grid !important; grid-template-columns: 210px 1fr; grid-template-areas: "crest col" "name col" "sub col"; align-items: center; gap: 2px 20px; width: min(96vw, 720px) !important; max-height: 96vh; padding: 12px 20px 10px !important; margin: auto !important; overflow: hidden; }
  .titlebox .crest { grid-area: crest; width: 74px !important; height: 74px !important; margin: -26px auto 0 !important; }
  .titlebox h1 { grid-area: name; font-size: 24px !important; margin: 0; white-space: nowrap; }
  .titlebox .sub { grid-area: sub; margin: 4px 0 0 !important; font-size: 13px !important; }
  .titlebox #loadmsg { display: none; }
  .titlebox .col { grid-area: col; display: grid !important; grid-template-columns: 1fr 1fr; gap: 6px !important; width: 100%; }
  .col #tNew { grid-column: 1 / -1; min-height: 46px !important; padding: 6px 10px !important; font-size: 18px !important; }
  .col .main2 { min-height: 40px !important; padding: 4px 6px !important; font-size: 14px !important; }
  .col .sec2 { grid-column: 1 / -1; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 5px !important; margin: 2px 0 0 !important; padding-top: 6px !important; }
  .col .sec2 button { min-height: 36px !important; font-size: 10.5px !important; padding: 3px 2px !important; }
}

/* ---------- phone landscape: dialogs use the whole (short) screen ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  #modal { padding: 0 !important; align-items: center; justify-content: center; }
  body:has(#mbox .setup) #mres { display: none !important; }
  #mres { transform: scale(.82); transform-origin: 50% 0; margin-bottom: -10px; }
  #mbox, body.skin #mbox { max-height: calc(100vh - 8px) !important; max-height: calc(100dvh - 8px) !important; max-width: 98vw !important; width: 98vw !important; padding: 4px 10px !important; border-width: 10px !important; border-image-width: 10px !important; }
  #mbox:has(> .setup), #mbox:has(.townwide) { width: 98vw !important; max-width: 98vw !important; }
  #mbox h2, #mbox h2 .small { margin: 0 0 4px !important; padding-bottom: 8px !important; font-size: 15px !important; }
  #mbox h2 .small { display: none; }
  #mbox .mb, body.skin #mbox .mb { margin-top: 4px !important; padding-top: 2px !important; bottom: -4px !important; gap: 6px; }
  #mbox .mb button { padding: 6px 12px !important; min-height: 34px !important; font-size: 13px !important; }
  .scngrid { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  .card.scn { padding: 4px !important; } .card.scn b { font-size: 12px; } .card.scn .small { font-size: 10px; }
  .setup .mprev { aspect-ratio: 3 / 1 !important; margin-bottom: 3px !important; }
  .hsbody { grid-template-columns: 1fr 230px !important; gap: 8px !important; }
  .hspan { position: static !important; order: 0 !important; padding: 6px !important; }
  .hsgrid { grid-template-columns: repeat(5, 1fr) !important; gap: 5px !important; }
  .htile { padding: 3px 2px !important; } .htile .pic { width: 46px; height: 46px; } .htile span { font-size: 11px; } .htile small { display: none; }
  .hsbig .pic { width: 70px !important; height: 70px !important; }
  .hspan h3 { font-size: 15px; margin: 2px 0 0; } .hscls { margin-bottom: 3px; font-size: 11px; }
  .hsstats { margin: 3px 0 !important; } .hsstats b { font-size: 14px; }
  .hspan h4 { margin: 4px 0 2px !important; font-size: 10px; }
  .hsarmy .pic { width: 38px !important; height: 38px !important; } .hsarmy div { width: 70px; font-size: 9px; }
  .hsgo { margin-top: 5px !important; padding: 7px !important; font-size: 13px !important; }
  .facgrid { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  .facpic { height: 78px !important; } .ribbon { font-size: 14px !important; padding: 12px 6px 3px !important; }
  .card.fac .blurb { font-size: 10px !important; padding: 3px 6px 0 !important; min-height: 0 !important; }
  .card.fac .crow { gap: 2px !important; margin-top: 3px !important; } .card.fac .crow .pic { width: 26px !important; height: 26px !important; }
  .setup .grid.two { grid-template-columns: repeat(4, 1fr) !important; gap: 5px !important; }
  .setup .card { padding: 4px !important; }
  #mbox p { margin: 4px 0; }
  #mbox .setup .small { font-size: 10px; }
  .trow.big { grid-template-columns: 52px 1fr auto !important; padding: 4px 2px !important; gap: 8px !important; }
  .trow.big .ic .pic { width: 46px !important; height: 46px !important; }
  #tcv { max-height: 90px; }
  .ttab { padding: 5px 4px !important; font-size: 12px !important; }
  /* army sheet: slots in one compact row instead of tall squares */
  #sheetBody #army { grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)) !important; gap: 5px !important; }
  #sheetBody #army .slot { aspect-ratio: 1 / 1.1 !important; min-height: 0 !important; }
  /* settings: two columns of compact rows */
  #mbox:has(> .setrow) { display: grid !important; grid-template-columns: 1fr 1fr; column-gap: 14px; align-content: start; }
  #mbox:has(> .setrow) > h2, #mbox:has(> .setrow) > .mb { grid-column: 1 / -1; }
  #mbox > .setrow { padding: 4px 0 !important; gap: 6px !important; min-width: 0; }
  #mbox > .setrow > div:first-child { flex: 1 1 110px; font-size: 13px; } #mbox > .setrow .small { font-size: 10px; }
  #mbox > .setrow button { padding: 3px 9px !important; min-height: 28px !important; font-size: 11px !important; }
  #mbox > .setrow input[type=range] { width: 110px; }
  /* how to play: text flows in two columns */
  #mbox .helpbody { grid-template-columns: 1fr 1fr; align-items: start; gap: 6px 10px; } #mbox .helpbody p { padding: 6px 10px 6px 12px; font-size: 12.5px; line-height: 1.4; }
  /* hero sheet: the six stats in one row */
  #mbox .hgrid { grid-template-columns: repeat(6, 1fr) !important; gap: 4px !important; }
  #mbox .hst { padding: 4px 2px !important; } #mbox .hst b { font-size: 14px !important; } #mbox .hst small, #mbox .hst span { font-size: 9px !important; }
  /* difficulty cards: all in one row, compact */
  #mbox .grid.two:has(.card.dif) { grid-template-columns: repeat(4, 1fr) !important; gap: 6px !important; }
  .card.dif { padding: 6px 5px !important; }
  .card.dif .big { margin: 0 !important; } .card.dif .big img, .card.dif .big .gi { width: 34px !important; height: 34px !important; }
  .card.dif > b { font-size: 14px !important; } .card.dif .small { font-size: 10px !important; line-height: 1.2; }
  .card.dif .difstats { margin-top: 4px !important; padding: 3px 5px !important; } .card.dif .difstats div { font-size: 10px !important; padding: 1px 0 !important; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body.skin #mbox button:not(.slot):not(.htile):not(.hbtn):not(.swatch):not(.ttab):not(.flagbtn):not(.danger):not(.primary) { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; background: var(--grain), linear-gradient(#3b2d1c, #19110a) !important; box-shadow: inset 0 0 0 1px var(--edge), inset 0 0 0 2px #0d0803 !important; min-height: 32px !important; padding: 4px 10px !important; font-size: 12px !important; }
  body.skin #mbox button.primary:not(.slot) { background: linear-gradient(var(--gold), color-mix(in srgb, var(--gold) 45%, #000)) !important; color: #2a1604 !important; }
  body.skin #mbox button:disabled { opacity: .45; }
  #mbox .mb button { flex: 0 0 auto !important; }
}
.hsgo2 { display: none; }
@media (orientation: landscape) and (max-height: 540px) { .hsgo2 { display: inline-flex !important; } .hspan .hsgo { display: none !important; } }
@media (orientation: landscape) and (max-height: 540px) {
  body.skin #mbox button.primary:not(.slot) { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; box-shadow: inset 0 0 0 1px #ffe08a, inset 0 0 0 2px #3a2506 !important; min-height: 32px !important; padding: 4px 12px !important; font-size: 13px !important; text-shadow: 0 1px 0 rgba(255, 235, 170, .6) !important; }
}
/* phone landscape: slim top bar so the map keeps the height */
@media (orientation: landscape) and (max-height: 540px) {
  body.skin:not(.inbattle) #top { border-width: 7px !important; padding: 0 6px !important; min-height: 0; }
  body.skin .sky { inset: -7px !important; border-width: 7px !important; border-image-width: 7px !important; }
  body:not(.inbattle) #res .chip { font-size: 11px !important; padding: 0 5px !important; }
  body:not(.inbattle) #date { gap: 5px; }
  body:not(.inbattle) .dtMain small { font-size: 8px; } body:not(.inbattle) .dtMain b { font-size: 14px; }
  body:not(.inbattle) .dtTurn, body:not(.inbattle) .dtDiff { display: none; }
  body:not(.inbattle) .dtGoal { font-size: 10px; padding: 1px 6px; max-width: 150px; }
  #orb { width: 24px; height: 24px; } #orb b { font-size: 18px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  #tcv { max-height: 56px !important; aspect-ratio: auto !important; height: 56px !important; object-fit: cover; }
  #mbox canvas#tcv + .small { display: none; }
  .ttabs { margin: 3px 0 !important; } .ttab { padding: 4px !important; font-size: 12px !important; }
  .trow.big b { font-size: 14px !important; } .trow .small { font-size: 11px !important; }
  .trow.big .acts input { width: 56px !important; font-size: 14px !important; padding: 3px !important; } .trow.big .acts button { padding: 5px 10px !important; font-size: 12px !important; }
}
@media (orientation: landscape) and (max-height: 540px) { .trow .acts, .trow.big .acts { grid-column: auto !important; justify-content: flex-end !important; max-width: none !important; flex-wrap: nowrap !important; } }

/* ---------- Android edge-to-edge: keep everything clear of the status bar, notch, gesture bar and rounded corners ---------- */
:root {
  --sat: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
  --sab: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
  --sal: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
  --sar: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
}
body:not(.inbattle) #app, body #app { padding-top: calc(8px + var(--sat)); padding-left: calc(10px + var(--sal)); padding-right: calc(10px + var(--sar)); }
#title { padding: var(--sat) var(--sar) var(--sab) var(--sal); }
#modal { padding: var(--sat) var(--sar) var(--sab) var(--sal); }
#rotate { padding: calc(24px + var(--sat)) calc(24px + var(--sar)) calc(24px + var(--sab)) calc(24px + var(--sal)); }
@media (max-width: 760px) {
  body:not(.inbattle) #app { padding: calc(4px + var(--sat)) calc(4px + var(--sar)) calc(4px + var(--sab)) calc(4px + var(--sal)) !important; }
  #mbar { padding-bottom: calc(4px + var(--sab)) !important; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body #app { padding: calc(3px + var(--sat)) calc(70px + var(--sar)) calc(3px + var(--sab)) calc(3px + var(--sal)) !important; }
  body.inbattle #app { padding: 0 !important; }
  body.inbattle #side { right: var(--sar) !important; }
  body.inbattle #stage { right: var(--sar) !important; left: var(--sal) !important; top: var(--sat) !important; bottom: calc(40px + var(--sab)) !important; }
  #mbar { padding-right: calc(4px + var(--sar)) !important; }
}
/* landscape phones: seven action buttons must fit the short height */
@media (orientation: landscape) and (max-height: 540px) {
  body.skin #mbar button { min-height: 0 !important; padding: 1px 0 !important; }
  #mbar button .ic { width: 22px !important; height: 22px !important; }
  #mbar button span { font-size: 8.5px !important; letter-spacing: .3px !important; }
  #mbar { gap: 2px !important; padding-top: calc(3px + var(--sat)) !important; padding-bottom: calc(3px + var(--sab)) !important; }
}
body.inbattle #stage { scrollbar-width: none; } body.inbattle #stage::-webkit-scrollbar { display: none; }
@media (max-width: 380px) { body:not(.inbattle) #res .chip { font-size: 11px !important; padding: 0 4px !important; gap: 1px !important; } body:not(.inbattle) #res { gap: 2px !important; } }

/* tablets held upright: map on top, the panels in two columns underneath */
@media (min-width: 761px) and (orientation: portrait) {
  body:not(.inbattle) { overflow: hidden; }
  body:not(.inbattle) #app { max-width: none; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
  body:not(.inbattle) #top { flex: none; margin-bottom: 6px; }
  body:not(.inbattle) #game { flex: 1; min-height: 0; flex-direction: column; align-items: stretch; gap: 6px; }
  body:not(.inbattle) #stage { flex: 1 1 56%; min-height: 0; width: 100%; }
  body:not(.inbattle) #stage canvas#map { width: 100%; height: 100%; aspect-ratio: auto; }
  body:not(.inbattle) #side { flex: 0 0 38%; width: 100% !important; overflow-y: auto; display: grid !important; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; min-height: 0; }
  body:not(.inbattle) #side > #mini { grid-column: 1 / -1; max-width: 300px; justify-self: center; }
  body:not(.inbattle) #mbar { display: none; }
}

/* ---------- game-style equipment: paper doll, item tiles, detail card ---------- */
.eqbon { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 8px; }
.eqb { background: linear-gradient(#26402a, #14260f); border: 1px solid #5fa05f; color: #bff0bf; border-radius: 12px; padding: 2px 10px; font-family: var(--f-head); font-size: 12px; font-weight: 700; }
.doll { display: grid; grid-template-columns: repeat(3, 84px); grid-template-rows: repeat(4, 84px); grid-template-areas: "neck head cape" "weapon hero shield" "ring1 hero ring2" "feet torso ."; gap: 8px; justify-content: center; padding: 10px; border-radius: 12px; background: radial-gradient(ellipse at 50% 40%, rgba(255, 224, 150, .10), transparent 70%), var(--grain), linear-gradient(#20160c, #130d07); box-shadow: inset 0 0 0 1px #000, inset 0 0 0 3px rgba(140, 106, 51, .4), inset 0 0 24px rgba(0, 0, 0, .6); }
.eqs { display: flex; }
.eqt { position: relative; width: 84px; height: 84px; border-radius: 12px; border: 2px solid var(--tc, #4a381c); background: radial-gradient(circle at 50% 35%, #3a2a18, #170f08); box-shadow: inset 0 0 0 1px #000, inset 0 -10px 14px rgba(0, 0, 0, .5), 0 2px 5px rgba(0, 0, 0, .55); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 !important; min-height: 0 !important; }
body.skin .eqt, body.skin .eqt:hover { border-image: none !important; border-width: 2px !important; padding: 0 !important; background: radial-gradient(circle at 50% 35%, #3a2a18, #170f08) !important; box-shadow: inset 0 0 0 1px #000, inset 0 -10px 14px rgba(0, 0, 0, .5), 0 2px 5px rgba(0, 0, 0, .55) !important; }
.eqt.full { box-shadow: inset 0 0 12px color-mix(in srgb, var(--tc) 55%, transparent), inset 0 0 0 1px #000, 0 2px 5px rgba(0, 0, 0, .55) !important; }
.eqt.on { outline: 3px solid var(--gold); outline-offset: 1px; }
.eqt.empty { border-style: dashed; border-color: #3a2c18; background: rgba(0, 0, 0, .25) !important; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .6) !important; }
.eqi { font-size: 44px; line-height: 1; display: flex; } .eqi .pic, .eqi img { width: 52px; height: 52px; }
.eqt small { font-size: 10px; color: #8a7752; font-family: var(--f-head); letter-spacing: .5px; text-transform: uppercase; margin-top: 2px; }
.eqhero { grid-area: hero; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; background: radial-gradient(circle at 50% 30%, rgba(255, 224, 150, .18), transparent 65%); border-radius: 12px; }
.eqhero .pic { border: 3px solid var(--gold); box-shadow: 0 4px 12px #000; } .eqhero b { font-family: var(--f-head); font-size: 14px; color: var(--gold); } .eqhero small { color: var(--mut); font-size: 11px; }
.eqinfo { display: flex; align-items: center; gap: 12px; margin: 10px 0 4px; padding: 10px; border-radius: 10px; background: var(--grain), linear-gradient(#2a1d12, #1a1209); border: 2px solid #4a381c; box-shadow: inset 0 0 0 1px #000; min-height: 76px; flex-wrap: wrap; }
.eqinfo.muted { justify-content: center; color: var(--mut); font-style: italic; font-family: var(--f-flav); }
.eqbig { width: 62px; height: 62px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 38px; border: 2px solid var(--tc); border-radius: 12px; background: radial-gradient(circle at 50% 35%, #3a2a18, #170f08); } .eqbig .pic, .eqbig img { width: 52px; height: 52px; }
.eqtxt { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 1px; } .eqtxt b { font-family: var(--f-head); font-size: 15px; color: var(--gold); }
.eqinfo .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.eqpack { display: grid; grid-template-columns: repeat(auto-fill, 70px); gap: 6px; justify-content: center; } .eqpack .eqt { width: 70px; height: 70px; } .eqpack .eqi { font-size: 36px; } .eqpack .eqi .pic, .eqpack .eqi img { width: 44px; height: 44px; }
.eqsets { display: grid; gap: 5px; } .eqset { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 6px 10px; border-radius: 8px; background: rgba(0, 0, 0, .3); border: 1px solid #3a2c18; font-size: 12px; } .eqset b { font-family: var(--f-head); } .eqset.on { border-color: #5fa05f; background: rgba(40, 90, 40, .25); } .eqset small { opacity: .75; }
@media (max-width: 420px) { .doll { grid-template-columns: repeat(3, 76px); grid-template-rows: repeat(4, 76px); gap: 6px; } .eqt { width: 76px; height: 76px; } }
@media (orientation: landscape) and (max-height: 540px) { .doll { grid-template-columns: repeat(4, 62px); grid-template-rows: repeat(3, 62px); grid-template-areas: "neck head cape hero" "weapon torso shield hero" "ring1 feet ring2 hero"; gap: 5px; padding: 6px; } .doll .eqt { width: 62px; height: 62px; } .doll .eqi { font-size: 32px; } .doll .eqi .pic, .doll .eqi img { width: 38px; height: 38px; } .eqhero .pic { width: 56px !important; height: 56px !important; } }

/* ---------- list rows become game cards (town, kingdom, reports ...) ---------- */
#mbox .trow { background: var(--grain), linear-gradient(#271b10, #181008); border: 1px solid #4a381c !important; border-radius: 9px; margin: 5px 0; padding: 8px 10px; box-shadow: inset 0 0 0 1px #000, inset 0 0 0 3px rgba(140, 106, 51, .18), 0 2px 5px rgba(0, 0, 0, .4); }
#mbox .trow:hover { border-color: var(--gold-d) !important; background: var(--grain), linear-gradient(#32230f, #1d140a); }
#mbox .trow.lockedrow { background: var(--grain), linear-gradient(#1c1812, #120e0a); }
#mbox .trow .ic .pic, #mbox .trow .ic img { border-radius: 8px; }

/* ---------- help as a book of cards ---------- */
.helpbody { display: grid; gap: 8px; }
.helpbody p { margin: 0 !important; padding: 10px 12px 10px 14px; border-radius: 9px; background: var(--grain), linear-gradient(#271b10, #181008); border: 1px solid #4a381c; border-left: 4px solid var(--gold-d); box-shadow: inset 0 0 0 1px #000, 0 2px 5px rgba(0, 0, 0, .35); line-height: 1.5; font-size: 14px; }
.helpbody p > b:first-child { display: block; font-family: var(--f-head); color: var(--gold); letter-spacing: 1px; text-transform: uppercase; font-size: 13px; margin-bottom: 3px; }

/* game icons replacing emoji */
.gi { display: inline-flex; width: 1.2em; height: 1.2em; vertical-align: -.26em; flex: none; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
.gi svg, .gi img { width: 100%; height: 100%; display: block; object-fit: contain; }
/* ---- victory / defeat cards (battle result and end-of-game screen) ---- */
.vic { position: relative; text-align: center; padding: 22px 8px 6px; overflow: hidden; margin: -6px -6px 8px; }
.vic-rays { position: absolute; left: 50%; top: 56px; width: 520px; height: 520px; margin: -260px 0 0 -260px; background: repeating-conic-gradient(rgba(255, 214, 110, .17) 0 8deg, transparent 8deg 20deg); -webkit-mask: radial-gradient(circle, #000 0, transparent 68%); mask: radial-gradient(circle, #000 0, transparent 68%); animation: vicSpin 40s linear infinite; pointer-events: none; }
.vic.lose .vic-rays { background: repeating-conic-gradient(rgba(200, 60, 60, .15) 0 8deg, transparent 8deg 20deg); }
.vic-crest { position: relative; display: flex; margin: 0 auto; width: 84px; height: 84px; align-items: center; justify-content: center; font-size: 42px; border-radius: 50%; background: radial-gradient(circle at 35% 28%, #fff3b0, #d89a22 55%, #6b4510); border: 3px solid #2a1604; box-shadow: 0 0 0 3px #e6bf55, 0 0 26px rgba(255, 214, 110, .55), 0 8px 18px rgba(0, 0, 0, .6); animation: vicPop .7s cubic-bezier(.2, 1.6, .4, 1) both; }
.vic-crest .gi { width: 46px; height: 46px; }
.vic.lose .vic-crest { background: radial-gradient(circle at 35% 28%, #e8c8c8, #8a2a2a 55%, #3a0e0e); box-shadow: 0 0 0 3px #8a4a4a, 0 0 26px rgba(200, 60, 60, .45), 0 8px 18px rgba(0, 0, 0, .6); }
.vic-ribbon { position: relative; display: table; margin: -10px auto 0; padding: 6px 46px 8px; font-family: var(--f-head); font-size: 30px; letter-spacing: 6px; text-transform: uppercase; color: #fff3c4; text-shadow: 0 2px 0 #000, 0 0 14px rgba(255, 200, 80, .5); background: linear-gradient(#c0392f, #7a1c1a); box-shadow: inset 0 0 0 2px #e6bf55; clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 50%, 100% 100%, 0 100%, 18px 50%); animation: vicSlide .6s .15s ease-out both; }
.vic.lose .vic-ribbon { background: linear-gradient(#585868, #24242e); box-shadow: inset 0 0 0 2px #9a8a6a; }
.vic-sub { margin: 10px 0 0; font-family: var(--f-flav); font-size: 15px; opacity: .92; }
.vic-hero { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 10px 0 4px; text-align: left; }
.vic-hero b { display: block; font-family: var(--f-head); color: var(--gold); font-size: 18px; } .vic-hero small { opacity: .75; }
.vic-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.vic-stats > div { background: rgba(0, 0, 0, .35); border: 1px solid #4a381c; border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; }
.vic-stats b { font-family: var(--f-head); font-size: 26px; color: var(--gold); } .vic-stats b.bad { color: #ff9a8a; } .vic-stats b.good { color: #8fe08f; }
.vic-stats span { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; opacity: .7; }
.vic-army { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 6px 0 10px; }
.vic-unit { position: relative; width: 74px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px; background: rgba(0, 0, 0, .3); border: 1px solid #4a381c; border-radius: 10px; }
.vic-unit b { font-family: var(--f-head); font-size: 15px; } .vic-unit small { position: absolute; top: 3px; right: 5px; color: #ff9a8a; font-weight: 700; font-size: 11px; }
.vic-unit span { font-size: 10px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 66px; } .vic-unit.fallen { opacity: .5; filter: grayscale(.8); }
.vic-score { background: rgba(0, 0, 0, .3); border: 1px solid #4a381c; border-radius: 10px; padding: 4px 12px; margin: 8px 0; }
.vic-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 2px; border-bottom: 1px solid rgba(255, 255, 255, .07); font-size: 14px; } .vic-row:last-child { border-bottom: 0; }
.vic-row b { color: var(--gold); font-family: var(--f-head); } .vic-row.mult b { color: #bfe0ff; }
.vic-total { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; margin: 8px 0 12px; border-radius: 12px; background: linear-gradient(#3a2a10, #1d1408); border: 2px solid var(--gold); box-shadow: 0 0 18px rgba(255, 200, 80, .25); }
.vic-total span { font-family: var(--f-head); letter-spacing: 2px; text-transform: uppercase; } .vic-total b { font-family: var(--f-head); font-size: 34px; color: #ffe27a; text-shadow: 0 0 14px rgba(255, 200, 80, .55); }
@keyframes vicSpin { to { transform: rotate(360deg); } } @keyframes vicPop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } } @keyframes vicSlide { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .vic-rays, .vic-crest, .vic-ribbon { animation: none; } }
@media (max-width: 560px) { .vic-ribbon { font-size: 22px; letter-spacing: 3px; padding: 5px 32px 7px; } .vic-crest { width: 68px; height: 68px; } .vic-stats b { font-size: 21px; } .vic-total b { font-size: 28px; } }
button .gi { margin-right: .15em; }
h2 .gi { width: 1.1em; height: 1.1em; }
.eqt .ghost { opacity: .32; display: flex; font-size: 34px; filter: grayscale(.6); } .eqt .ghost .gi { width: 38px; height: 38px; }
#mbox .armyrow .slot { aspect-ratio: auto !important; min-height: 66px; padding: 3px 0 !important; }
#mbox .trow > div { min-width: 0; }
#mbox .trow > div > select, #mbox #mQty { width: 100%; min-width: 0; box-sizing: border-box; }
/* phone landscape: the spell book opens as a panel over the battlefield */
@media (orientation: landscape) and (max-height: 540px) {
  body.inbattle #spells:not(.hide) { position: fixed !important; left: var(--sal); top: auto; right: var(--sar); bottom: calc(42px + var(--sab)); z-index: 60; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 5px; align-content: start; padding: 6px; background: var(--grain), linear-gradient(rgba(30, 20, 12, .97), rgba(12, 8, 4, .98)); border: 2px solid var(--edge); border-radius: 10px; overflow-y: auto; max-height: 112px !important; }
  body.inbattle #spells button { text-align: left !important; white-space: normal !important; font-size: 11px !important; line-height: 1.15; min-height: 40px !important; padding: 4px 6px !important; display: flex; align-items: center; gap: 4px; }
}
#army .slot { touch-action: none; -webkit-user-select: none; user-select: none; }
#army .slot.lifted { opacity: .35; } #army .slot.drop { outline: 2px dashed var(--gold); background: rgba(230, 191, 85, .18); }
#army .slot .pic, #army .slot img { pointer-events: none; }

/* ---------- town buildings as picture cards ---------- */
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 6px; }
.bcard { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 12px; background: var(--grain), linear-gradient(#2a1d12, #1a1209); border: 2px solid #4a381c; box-shadow: inset 0 0 0 1px #000, inset 0 0 0 3px rgba(140, 106, 51, .2), 0 3px 8px rgba(0, 0, 0, .45); }
.bcard.built { border-color: var(--gold-d); }
.bcard.lockedrow { filter: saturate(.45); opacity: .62; }
.bpic { position: relative; height: 134px; border-radius: 9px; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; border: 1px solid #000; box-shadow: inset 0 0 14px rgba(0, 0, 0, .5); background: linear-gradient(#6d93c4 0%, #a9c9de 52%, #5f7a3a 53%, #36481f 100%); }
.bpic img.pic { width: auto !important; height: 126px !important; max-width: 94%; object-fit: contain; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .55)); }
.bpic .mico { font-size: 60px; }
.bcr { position: absolute; right: 4px; top: 4px; } .bcr .pic { width: 34px !important; height: 34px !important; border: 2px solid var(--gold); border-radius: 50%; box-shadow: 0 2px 5px #000; }
.bcard > div:nth-child(2) { flex: 1; font-size: 13px; line-height: 1.35; } .bcard b { font-family: var(--f-head); color: var(--gold); font-size: 15px; }
.bacts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; } .bacts button { flex: 1 1 auto; } .bacts .small { align-self: center; }
@media (orientation: landscape) and (max-height: 540px) { .bgrid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; } .bpic { height: 84px; } .bpic img.pic { height: 78px !important; } .bcard { padding: 5px; gap: 4px; } .bcard > div:nth-child(2) { font-size: 11px; } .bcard b { font-size: 13px; } }
@media (max-width: 420px) { .bgrid { grid-template-columns: 1fr 1fr; gap: 6px; } .bpic { height: 96px; } .bpic img.pic { height: 90px !important; } .bcard { padding: 5px; } .bcard > div:nth-child(2) { font-size: 11px; } }
.bpic .bcr img.pic { width: 34px !important; height: 34px !important; max-width: none; object-fit: cover; filter: none; border-radius: 50%; }

/* ---------- Warriors tab: recruit cards side by side ---------- */
.wgrid { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }
.wpic { height: 128px; background: radial-gradient(ellipse at 50% 40%, rgba(255, 224, 150, .16), transparent 70%), linear-gradient(#241a10, #120c07); }
.wpic img.pic { width: 112px !important; height: 112px !important; border-radius: 12px; object-fit: cover; filter: none; box-shadow: 0 4px 10px rgba(0, 0, 0, .6); }
.wpic .bcr img.pic { width: 44px !important; height: 48px !important; border-radius: 8px; object-fit: contain; background: rgba(0, 0, 0, .55); border: 2px solid var(--gold-d); box-shadow: 0 2px 5px #000; padding: 1px; }
.wav { position: absolute; left: 6px; top: 6px; min-width: 38px; height: 38px; padding: 0 6px; border-radius: 19px; display: flex; align-items: center; justify-content: center; font-family: var(--f-head); font-weight: 700; font-size: 17px; color: #2a1604; background: linear-gradient(var(--gold), color-mix(in srgb, var(--gold) 50%, #000)); border: 2px solid #1a0f05; box-shadow: 0 2px 5px #000; }
.wstats { display: flex; flex-wrap: wrap; gap: 3px 5px; margin: 4px 0 3px; } .wstats > span { font-family: var(--f-head); font-size: 11px; font-weight: 600; background: rgba(0, 0, 0, .38); border: 1px solid #4a381c; border-radius: 10px; padding: 1px 7px; white-space: nowrap; }
.wcard .bacts { display: flex; } .wcard .bacts input { width: 64px; flex: 0 0 64px; text-align: center; font-size: 16px; padding: 6px 2px; } .wcard .bacts button { padding: 8px 10px; }
@media (max-width: 420px) { .wgrid { grid-template-columns: 1fr 1fr; gap: 6px; } .wpic { height: 100px; } .wpic img.pic { width: 86px !important; height: 86px !important; } .wav { height: 30px; min-width: 30px; font-size: 14px; } .wcard .bacts input { width: 100%; flex: 1 1 100%; } .wcard .bacts button { flex: 1 1 100%; } .wstats > span { font-size: 10px; padding: 1px 5px; } }
@media (orientation: landscape) and (max-height: 540px) { .wgrid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 6px; } .wpic { height: 88px; } .wpic img.pic { width: 78px !important; height: 78px !important; } .wcard .bacts button, .wcard .bacts input { padding: 4px 6px !important; font-size: 12px !important; } .wcard .bacts input { width: 48px !important; flex: 0 0 48px; } }

/* ---------- map setup as an aligned form ---------- */
.optpanel { display: grid; gap: 9px; margin: 12px 0 4px; padding: 12px 14px; border-radius: 12px; background: var(--grain), linear-gradient(#251a10, #17100a); border: 2px solid #4a381c; box-shadow: inset 0 0 0 1px #000, inset 0 0 0 3px rgba(140, 106, 51, .18); }
.opt { display: grid; grid-template-columns: 128px 1fr; gap: 12px; align-items: center; padding-bottom: 9px; border-bottom: 1px dashed rgba(140, 106, 51, .35); }
.opt:last-of-type { border-bottom: 0; padding-bottom: 0; }
.opt > label { font-family: var(--f-head); font-size: 12px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); }
.opt .rivlab { display: flex; align-items: center; gap: 6px; }
.optc { min-width: 0; }
.optc small { display: block; margin-top: 4px; font-family: var(--f-flav); font-size: 12px; opacity: .7; }
.opts { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.opts button { width: 100%; min-height: 44px !important; padding: 4px 3px !important; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; white-space: nowrap; }
.opts button b { font-family: var(--f-head); font-size: 13px; }
.opts button small { margin: 0; font-size: 10px; opacity: .75; font-family: var(--f-head); }
.seedrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.seedrow input { width: 100%; min-width: 0; padding: 9px 10px; font-size: 14px; }
.seedrow button { min-height: 38px; }
.flags { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.flags .flagbtn { width: 100% !important; height: 44px !important; min-width: 0; padding: 2px !important; }
.optnote { font-family: var(--f-flav); font-size: 12px; opacity: .7; text-align: center; padding-top: 4px; }
@media (max-width: 620px) { .opt { grid-template-columns: 1fr; gap: 5px; } .opts button b { font-size: 12px; } .opts button { min-height: 40px !important; } .flags .flagbtn { height: 38px !important; } }
@media (orientation: landscape) and (max-height: 540px) { .optpanel { gap: 5px; padding: 6px 10px; } .opt { grid-template-columns: 110px 1fr; gap: 8px; padding-bottom: 5px; } .optc small { display: none; } .opts button { min-height: 32px !important; } .opts button small { display: none; } .flags .flagbtn { height: 34px !important; } .seedrow input { padding: 5px 8px; } }
body.skin .opts button, body.skin .seedrow button { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 8px !important; background: var(--grain), linear-gradient(#3b2d1c, #19110a) !important; box-shadow: inset 0 0 0 1px var(--edge), inset 0 0 0 2px #0d0803, 0 2px 4px rgba(0, 0, 0, .5) !important; color: var(--txt) !important; }
body.skin .opts button:hover { filter: brightness(1.2); }
body.skin .opts button.primary { background: linear-gradient(var(--gold), color-mix(in srgb, var(--gold) 45%, #000)) !important; box-shadow: inset 0 0 0 1px #ffe9a0, inset 0 0 0 2px #3a2506, 0 0 10px rgba(var(--glow, 230, 191, 85), .35) !important; color: #2a1604 !important; text-shadow: 0 1px 0 rgba(255, 235, 170, .6); }
body.skin .opts button.primary small { color: #3a2506; opacity: .85; }
body.skin .flagbtn { border: 2px solid #4a381c !important; background: linear-gradient(#26190d, #130c06) !important; }
.card.dif { display: flex; flex-direction: column; align-items: stretch; text-align: center; }
.card.dif .small { min-height: 3.2em; margin: 3px 0 6px; }
.difstats { display: grid; gap: 2px; padding: 6px 8px; border-radius: 8px; background: rgba(0, 0, 0, .32); border: 1px solid #3a2c18; }
.difstats div { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 1px 0; border-bottom: 1px dotted rgba(140, 106, 51, .3); } .difstats div:last-child { border-bottom: 0; }
.difstats span { font-family: var(--f-flav); opacity: .8; } .difstats b { font-family: var(--f-head); color: var(--gold); font-size: 12px; }

/* aligned picture cards (map types, scenarios): same height, centred title, clamped text */
.setup .grid.two, .scngrid { align-items: stretch; }
.setup .grid.two .card, .card.scn { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; }
.setup .mprev { flex: none; width: 100%; aspect-ratio: 360 / 190 !important; object-fit: cover; }
.setup .grid.two .card > b, .card.scn > b { display: flex; align-items: center; justify-content: center; min-height: 2.5em; line-height: 1.15; font-family: var(--f-head); }
.setup .grid.two .card > .small, .card.scn > .small { flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.25; }
/* ================= beautify-ui: transitions, button feedback, title life, loading bar, frame art ================= */
/* soft modal backdrop */
#modal { background: radial-gradient(ellipse at 50% 40%, rgba(24, 14, 6, .6), rgba(2, 1, 0, .88)); backdrop-filter: blur(3px); animation: modalIn .26s ease-out; }
@keyframes modalIn { from { opacity: 0; backdrop-filter: blur(0); } to { opacity: 1; backdrop-filter: blur(3px); } }

/* menu screens slide and fade in when the screen changes (js/uifx.js adds .scr-in / .scr-back for a moment) */
@keyframes scrIn { from { opacity: 0; transform: translateX(22px); } }
@keyframes scrBack { from { opacity: 0; transform: translateX(-22px); } }
#mbox.scr-in, #mbox.scr-back { overflow-x: hidden; }
#mbox.scr-in > :not(.setup), #mbox.scr-in > .setup > * { animation: scrIn .34s cubic-bezier(.2, .8, .25, 1) backwards; }
#mbox.scr-back > :not(.setup), #mbox.scr-back > .setup > * { animation: scrBack .34s cubic-bezier(.2, .8, .25, 1) backwards; }
#mbox.scr-in > .setup > :nth-child(3), #mbox.scr-back > .setup > :nth-child(3), #mbox.scr-in > :nth-child(3), #mbox.scr-back > :nth-child(3) { animation-delay: .04s; }
#mbox.scr-in > .setup > :nth-child(4), #mbox.scr-back > .setup > :nth-child(4), #mbox.scr-in > :nth-child(4), #mbox.scr-back > :nth-child(4) { animation-delay: .08s; }
#mbox.scr-in > .setup > :nth-child(n+5), #mbox.scr-back > .setup > :nth-child(n+5), #mbox.scr-in > :nth-child(n+5), #mbox.scr-back > :nth-child(n+5) { animation-delay: .12s; }

/* button feedback: lift and glow on hover, pressed-in on press, soft focus ring */
button { transition: border-color .15s, background .15s, box-shadow .15s, transform .12s, filter .12s; }
body:not(.skin) button:hover:not(:disabled):not(.slot):not(.swatch):not(.flagbtn):not(.ttab):not(.eqt):not(.hbtn) { transform: translateY(-1px); box-shadow: 0 0 12px rgba(230, 191, 85, .38), 0 3px 8px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 235, 180, .22); }
body.skin button:hover:not(:disabled):not(.slot):not(.seg button):not(.swatch):not(.flagbtn):not(.eqt) { filter: brightness(1.18) drop-shadow(0 0 6px rgba(230, 191, 85, .45)); }
button:active:not(:disabled):not(.slot) { transform: translateY(1px) scale(.985); filter: brightness(.92); }
body:not(.skin) button:active:not(:disabled):not(.slot) { box-shadow: inset 0 2px 5px rgba(0, 0, 0, .55), 0 0 6px rgba(230, 191, 85, .2); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
body:not(.skin) button:focus-visible { box-shadow: 0 0 0 4px rgba(230, 191, 85, .28); }

/* title screen: drifting art layer, pointer parallax, embers canvas, glowing logo and crest, fade away when the game starts */
#title-fx { position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; transform: translate(calc(var(--px, 0) * -14px), calc(var(--py, 0) * -9px)); transition: transform .5s ease-out; }
.tfx-bg { position: absolute; inset: -6%; background: radial-gradient(40% 35% at 25% 30%, rgba(230, 160, 60, .18), transparent 70%), radial-gradient(45% 40% at 78% 70%, rgba(110, 70, 190, .14), transparent 70%); animation: tfxDrift 46s ease-in-out infinite alternate; }
#title-fx.has-art .tfx-bg { background-size: cover; background-position: center; background-repeat: no-repeat; }
#title-fx::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 55%, rgba(0, 0, 0, 0) 30%, rgba(4, 2, 0, .55) 100%); }
.tfx-cv { position: absolute; left: 0; top: 0; }
#title-fx.still .tfx-cv { display: none; }
@keyframes tfxDrift { from { transform: scale(1.02) translate(-1.2%, -.8%); } to { transform: scale(1.1) translate(1.2%, .8%); } }
.titlebox h1 { animation: logoGlow 4.5s ease-in-out infinite alternate; }
@keyframes logoGlow { from { filter: drop-shadow(0 0 3px rgba(230, 191, 85, .2)); } to { filter: drop-shadow(0 0 16px rgba(255, 214, 110, .7)); } }
.titlebox .crest { animation: crestGlow 6s ease-in-out infinite alternate; }
@keyframes crestGlow { from { filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .8)) drop-shadow(0 0 2px rgba(230, 191, 85, .2)); } to { filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .8)) drop-shadow(0 0 14px rgba(255, 214, 110, .65)); } }
#title { transition: opacity .45s ease; }
#title.hide { display: flex !important; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .45s ease, visibility 0s linear .45s; }
#title.hide::before, #title.hide .tfx-bg, #title.hide .titlebox, #title.hide .titlebox h1, #title.hide .titlebox .crest { animation: none; }

/* loading bar and tips on the title screen */
.loadbar { position: relative; box-sizing: border-box; width: min(320px, 70%); height: 12px; max-height: 40px; margin: 4px auto 6px; border: 1px solid var(--edge); border-radius: 7px; background: #120c06; overflow: hidden; box-shadow: inset 0 1px 3px #000; transition: opacity .5s, max-height .5s, height .5s, margin .5s, border-width .5s; }
.loadbar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #8a5f14, #e6bf55 60%, #fff0b0); box-shadow: 0 0 8px rgba(230, 191, 85, .6); transition: width .25s ease-out; }
.loadbar.indet i { width: 40% !important; animation: loadSlide 1.1s ease-in-out infinite; }
@keyframes loadSlide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.loadbar.done { opacity: 0; max-height: 0; height: 0; margin-top: 0; margin-bottom: 0; border-width: 0; }
.loadtip { max-width: 330px; min-height: 2.7em; max-height: 6em; margin: 4px auto 8px; font-family: var(--f-flav); font-style: italic; font-size: 13.5px; line-height: 1.3; color: var(--mut); opacity: 0; transition: opacity .35s, min-height .5s, max-height .5s, margin .5s; }
.loadtip.on { opacity: .85; }
.loadtip.done { opacity: 0; min-height: 0; max-height: 0; margin: 0; overflow: hidden; }
body.fr-progress .loadbar { height: 36px; border: 9px solid transparent; border-image: url(art/ui/frame_progress.png) 22 58 / 9px 24px stretch; border-radius: 0; background-clip: padding-box; box-shadow: none; }
body.fr-progress .loadbar i { border-radius: 4px; }
body.fr-progress .loadbar.done { height: 0; max-height: 0; border-width: 0; }

/* optional frame art, switched on by js/uifx.js only when the files exist */
body.fr-portrait .hsbig { display: inline-block; padding: 6px; border: 20px solid transparent; border-image: url(art/ui/frame_portrait.png) 56 66 60 66 / 19px 22px 20px 22px stretch; }
body.fr-portrait .hsbig .pic { border: 0; box-shadow: none; }
body.fr-town .facpic::after { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; border: 14px solid transparent; border-image: url(art/ui/frame_town.png) 62 / 14px stretch; }
body.fr-town .facpic .ribbon { z-index: 2; }
@media (max-width: 860px) { body.fr-town .facpic::after { border-width: 9px; border-image-width: 9px; } }
@media (orientation: landscape) and (max-height: 540px) {
  body.fr-town .facpic::after { border-width: 6px; border-image-width: 6px; }
  .titlebox #loadbar, .titlebox #loadtip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #modal { animation: none; }
  #mbox.scr-in > *, #mbox.scr-back > *, #mbox.scr-in > .setup > *, #mbox.scr-back > .setup > * { animation: none !important; }
  .tfx-bg, .titlebox h1, .titlebox .crest, .loadbar.indet i { animation: none !important; }
  #title-fx { transform: none; transition: none; }
  #title, #title.hide { transition: none; }
  button, button:hover:not(:disabled), button:active:not(:disabled) { transform: none !important; }
}
@media (max-width: 620px) { .setup .grid.two { grid-template-columns: 1fr 1fr !important; gap: 8px !important; } .setup .grid.two .card { padding: 6px !important; } .setup .grid.two .card > .small { font-size: 11px; -webkit-line-clamp: 3; } .scngrid { grid-template-columns: 1fr 1fr !important; } }

/* ---------- every remaining button uses the painted button art (normal / selected = pressed / disabled) ---------- */
body.skin .opts button, body.skin .seedrow button, body.skin #mDice, body.skin .seg button, body.skin .ttab {
  border: 11px solid transparent !important; border-image: var(--b-n, url(art/ui/btn_normal.png)) 34 52 fill / 11px 17px stretch !important;
  border-radius: 0 !important; background: none !important; box-shadow: none !important; color: #f3e7c6 !important; text-shadow: 0 1px 2px #000; }
body.skin .opts button.primary, body.skin .opts button.on, body.skin .seg button.on, body.skin .ttab.on, body.skin .seedrow button.on {
  border-image-source: var(--b-p, url(art/ui/btn_pressed.png)) !important; color: #2a1a06 !important; text-shadow: 0 1px 0 rgba(255, 240, 190, .5); font-weight: bold; }
body.skin .opts button:disabled, body.skin .seg button:disabled, body.skin .ttab:disabled, body.skin .seedrow button:disabled { border-image-source: var(--b-d, url(art/ui/btn_disabled.png)) !important; color: #9a9a9a !important; }
body.skin .opts button:hover:not(:disabled), body.skin .seg button:hover:not(:disabled), body.skin .ttab:hover:not(:disabled), body.skin .seedrow button:hover:not(:disabled) { filter: brightness(1.18); }
body.skin .opts button.primary small { color: #3a2506; }

/* ---------- the resource chips in the header are larger and easier to read ---------- */
body #top #res .chip, body #mres .chip { font-size: 18px !important; padding: 4px 12px !important; gap: 6px !important; min-height: 38px; align-items: center; }
body #top #res .chip .gi, body #mres .chip .gi { width: 26px !important; height: 26px !important; font-size: 24px !important; }
body #top #res .chip b, body #mres .chip b { font-size: 18px !important; }
body #top #res .chip small, body #mres .chip small { font-size: 12px !important; }
body #top #res { gap: 8px !important; flex-wrap: wrap !important; overflow: visible !important; flex: 1 1 100% !important; }
@media (max-width: 760px) { body #top #res .chip, body #mres .chip { font-size: 15px !important; padding: 3px 8px !important; min-height: 32px; } body #top #res .chip .gi, body #mres .chip .gi { width: 22px !important; height: 22px !important; } body #top #res .chip b, body #mres .chip b { font-size: 15px !important; } body #top #res { flex-wrap: nowrap !important; overflow-x: auto !important; gap: 5px !important; } }

/* ---------- castle / hero selection: the painted screen is shown whole; the menu lives in its dark left panel ---------- */
@media (min-width: 1000px) and (min-height: 560px) {
  body.skin #mbox.art-split, #mbox.art-split { width: min(96vw, calc(92vh * 16 / 9)); max-width: none; height: auto; aspect-ratio: 16 / 9; max-height: 92vh; padding: 0; border: 0; border-image: none; border-radius: 6px; overflow: hidden; background-color: #0b0704; background-repeat: no-repeat; background-size: 100% 100% !important; box-shadow: 0 14px 50px rgba(0, 0, 0, .85); }
  #mbox.art-split > .setup { position: absolute; left: 5.4%; top: 7%; width: 52.4%; height: 86%; overflow-y: auto; padding: 0 1.2% 0 .6%; scrollbar-width: thin; }
  #mbox.art-split > .setup > [data-bg] { display: none; }
  #mbox.art-split h2 { font-size: clamp(20px, 2.4vw, 34px); margin: 0 0 8px; }
  #mbox.art-split .facgrid { grid-template-columns: repeat(3, 1fr) !important; gap: 10px; }
  #mbox.art-split .facpic { height: clamp(70px, 11vw, 140px); }
  #mbox.art-split > .setup { overflow: hidden; display: flex; flex-direction: column; }
  #mbox.art-split > .setup > .facgrid, #mbox.art-split > .setup > .hsbody { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 6px 6px 2px; scrollbar-width: thin; }
  #mbox.art-split > .setup > .mb { flex: none; margin: 8px 0 0; position: static; }
  #mbox.art-split > .setup > .small { flex: none; font-size: 11px; margin-top: 4px; }
  #mbox.art-split .hsbody { grid-template-columns: 1fr 232px; gap: 10px; align-items: start; }
  #mbox.art-split .hsgrid { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  #mbox.art-split .hspan { position: sticky; top: 0; font-size: 12px; }
}
@media (min-width: 1000px) and (min-height: 560px) { #mbox.art-split .hsgo2 { display: inline-flex !important; } #mbox.art-split .hspan .hsgo { display: none !important; } }

/* ---------- map options on a phone: roomy buttons, three to a row ---------- */
body.skin .opts button.primary b, body.skin .opts button.primary small { color: #2a1a06 !important; opacity: 1; text-shadow: 0 1px 0 rgba(255, 240, 190, .5); }
@media (max-width: 620px) {
  .opts { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  body.skin .opts button, body.skin .seedrow button { border-width: 9px 12px !important; min-height: 58px !important; padding: 2px 2px !important; }
  .opts button b { font-size: 15px; } .opts button small { font-size: 12px; opacity: .9; }
  .opt { gap: 8px; }
}
body.skin .opts button.primary, body.skin .opts button.on, body.skin .seg button.on, body.skin .ttab.on { background: none !important; box-shadow: none !important; }
@media (max-width: 620px) { .opts button b { font-size: 13px; letter-spacing: 0; } }

/* ---------- castle / hero selection on a phone held upright: the painted scene is a banner above the menu ---------- */
@media (max-width: 700px) and (orientation: portrait) {
  #mbox.art-banner > .setup { position: relative; }
  #mbox.art-banner > .setup::before { content: ''; display: block; height: 200px; margin: -4px -4px 8px; border-radius: 8px; background: linear-gradient(180deg, transparent 60%, rgba(14, 9, 4, .95)), var(--scr-art) right 28% / auto 235% no-repeat; box-shadow: inset 0 0 0 1px rgba(230, 191, 85, .35); }
  #mbox.art-banner h2 { margin-top: -34px; position: relative; text-shadow: 0 2px 6px #000, 0 0 14px #000; }
}

/* ---------- quick buttons on the map: castles and heroes ---------- */
#quick { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 8; max-height: calc(100% - 16px); overflow-y: auto; scrollbar-width: none; }
#quick::-webkit-scrollbar { display: none; }
.inbattle #quick { display: none; }
body.skin #quick button, #quick button { width: 50px; height: 50px; min-height: 0; padding: 0; border: 2px solid #6b4f18 !important; border-image: none !important; border-radius: 10px; background: #1a110a center / cover no-repeat; box-shadow: 0 2px 6px rgba(0, 0, 0, .7), inset 0 0 0 1px #000 !important; display: grid; place-items: center; overflow: hidden; font-size: 22px; cursor: pointer; }
#quick .qh { border-radius: 50%; border-color: #8c6a22 !important; }
#quick .qh.on { border-color: #ffd86a !important; box-shadow: 0 0 0 2px rgba(255, 216, 106, .45), 0 0 12px rgba(255, 216, 106, .55), inset 0 0 0 1px #000 !important; }
#quick .qh img { width: 100%; height: 100%; border-radius: 50%; border: 0 !important; }
#quick button:hover { filter: brightness(1.2); transform: translateY(-1px); }
body.lefty #quick { left: auto; right: 8px; }
@media (max-width: 760px) { #quick button, body.skin #quick button { width: 42px; height: 42px; } #quick { gap: 5px; top: 6px; left: 6px; } }
body.skin #quick .qt, #quick .qt { background-size: cover !important; background-position: center !important; background-repeat: no-repeat !important; }
#quick .qx { height: 28px !important; border-radius: 14px !important; font-size: 14px; color: #f3e7c6; line-height: 1; background: rgba(20, 14, 8, .88) !important; }
#quick .qx small { font-size: 10px; margin-left: 2px; }
/* the full painted art, not a round crop: heroes as framed portraits, castles as framed scenes */
body.skin #quick .qh, #quick .qh { width: 62px; height: 62px; border-radius: 8px !important; background-size: cover !important; background-position: center top !important; background-repeat: no-repeat !important; }
body.skin #quick .qt, #quick .qt { width: 92px; height: 54px; border-radius: 8px !important; }
#quick .qh img { border-radius: 0; }
@media (max-width: 760px) { body.skin #quick .qh, #quick .qh { width: 50px; height: 50px; } body.skin #quick .qt, #quick .qt { width: 74px; height: 44px; } }
/* castles run left to right, heroes top to bottom */
#quick { gap: 6px; overflow: visible; max-height: none; }
#quick .qrow { display: flex; flex-direction: row; gap: 6px; align-items: center; }
#quick .qcol { display: flex; flex-direction: column; gap: 6px; max-height: calc(100% - 70px); }
body.skin #quick .qx, #quick .qx { width: 34px; height: 54px; border-radius: 8px !important; }
/* hero selection: the full painted portrait in a framed square */
.hart { display: block; object-fit: cover; border-radius: 8px; border: 2px solid #8c6a22; box-shadow: 0 2px 8px rgba(0, 0, 0, .65), inset 0 0 0 1px #000; background: #120c07; }
.htile .hart { width: 100%; max-width: 96px; height: auto; aspect-ratio: 1; margin: 0 auto; }
.htile.on .hart { border-color: #ffd86a; box-shadow: 0 0 0 2px rgba(255, 216, 106, .45), 0 0 12px rgba(255, 216, 106, .5), inset 0 0 0 1px #000; }
.hsbig .hart { width: 100%; max-width: 190px; height: auto; aspect-ratio: 1; margin: 0 auto; border-radius: 6px; }
@media (max-width: 860px) { .hsbig .hart { width: 110px; } .htile .hart { max-width: 72px; } }
@media (max-width: 860px) { body.fr-portrait .hsbig .hart { border: 0; } }
.garrow .slot { width: 68px; height: 78px; }
.ttab small { background: rgba(0, 0, 0, .35); border-radius: 8px; padding: 0 5px; margin-left: 4px; font-size: 11px; }

/* phone: the three town tabs (Warriors / Garrison / Buildings) always fit on one row */
@media (max-width: 620px) {
  .ttabs { gap: 3px !important; }
  body.skin .ttab { border-width: 7px 8px !important; border-image-width: 7px 8px !important; padding: 2px 0 !important; font-size: 11.5px !important; min-width: 0 !important; white-space: nowrap; overflow: hidden; text-overflow: clip; letter-spacing: 0; }
  .ttab small { margin-left: 2px; padding: 0 3px; font-size: 10px; }
}
@media (max-width: 620px) {
  .garrow { gap: 3px !important; flex-wrap: nowrap; }
  .garrow .slot { width: 11vw; height: 13.2vw; min-width: 0; flex: none; }
  .garrow .slot img { width: 92%; height: auto; max-width: none; }
  .garrow .slot small { font-size: 10px; margin-top: 1px; }
}

/* the menu buttons wait until every asset is loaded, so nothing loads later */
html.assets-loading #title .col { opacity: .0; pointer-events: none; }
#title .col { transition: opacity .4s; }

/* ===== any screen size: the title never gets cut off; short screens scroll or compact ===== */
#title { overflow-x: hidden; overflow-y: auto; align-items: flex-start; -webkit-overflow-scrolling: touch; }
#title > .titlebox { margin: auto; }
@media (max-height: 760px) and (orientation: portrait) {
  #title > .titlebox { padding-top: 24px !important; padding-bottom: 14px !important; }
  .titlebox .crest { width: 56px; height: 56px; margin-top: -42px; }
  .titlebox h1 { font-size: 24px; } .titlebox .sub { margin: 2px 0 8px; font-size: 13px; }
  .titlebox .loadtip { display: none; }
  .col { gap: 6px; } .col button { padding: 9px 24px; font-size: 15px; } .col #tNew { font-size: 17px; }
  .col .sec2 { margin-top: 4px; padding-top: 6px; gap: 5px; } .col .sec2 button { padding: 6px 4px; font-size: 12px; }
}
@media (max-width: 340px) { .titlebox { margin: 6px !important; } .titlebox h1 { font-size: 22px; } .col button { padding-left: 12px; padding-right: 12px; } }
html, body { overflow-x: hidden; max-width: 100vw; }
@media (min-width: 761px) and (max-width: 1100px) { #top .btns, header .btns { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; } header .btns button { padding-left: 8px; padding-right: 8px; } header .btns kbd { display: none; } }
.pg-hide { display: none !important; }
.pgbar { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0; } .pgbar span { min-width: 56px; text-align: center; font-size: 14px; color: var(--mut); }
.pgbar button { width: 52px; height: 38px; font-size: 22px; line-height: 1; padding: 0; } .pgbar button:disabled { opacity: .35; }
@media (max-width: 760px) { .ttabs ~ * { } #mbox .townblurb { display: none; } }

/* the splash in index.html is the single loader now: the title screen carries no second bar */
#loadbar, #loadtip, #loadmsg { display: none !important; }
/* painted hero portraits everywhere share the square frame of the hero selection screen */
img.pic.hart { object-fit: cover; border-radius: 6px; border: 2px solid #8c6a22; box-sizing: border-box; background: #120c07; box-shadow: 0 2px 6px rgba(0, 0, 0, .6), inset 0 0 0 1px #000; }
.hbtn .pic.hart { border-width: 1px; border-radius: 4px; }
.hbtn.on .pic.hart { border-color: #ffd86a; box-shadow: 0 0 8px rgba(255, 216, 106, .55), inset 0 0 0 1px #000; }
.hport .pic.hart { width: 84px; height: 84px; }
#hero .hport .pic.hart { border-radius: 8px; border: 3px solid #e6bf55; object-fit: cover; box-shadow: 0 0 0 2px #0a0603, 0 3px 10px #000, inset 0 0 0 1px #000; }
/* town tabs stay on screen while the town scrolls */
#mbox .ttabs { position: sticky; top: 0; z-index: 6; padding: 4px 0; background: linear-gradient(#1c130b 80%, rgba(28, 19, 11, 0)); }
/* quick buttons: the picture is an <img> (taken from memory, no second download); the castle shows its name */
#quick .qh img, #quick .qt img { position: absolute; inset: 0; width: 100% !important; height: 100% !important; object-fit: cover; object-position: center top; border: 0 !important; border-radius: 0 !important; }
#quick .qh, #quick .qt { position: relative; }
#quick .qt .qname { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 3px 2px; font-style: normal; font-size: 11px; line-height: 1.1; text-align: center; color: #fff3cf; background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .85) 60%); text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--f-head, Georgia, serif); }
@media (max-width: 760px) { body.skin #quick .qt, #quick .qt { width: 96px; height: 46px; } #quick .qt .qname { font-size: 10px; } }
#quick .qa, .hbtn.tnav { width: 26px !important; min-width: 0; height: 46px !important; border-radius: 8px !important; font-size: 22px; line-height: 1; color: #f3e7c6; background: rgba(20, 14, 8, .88) !important; display: grid; place-items: center; }
@media (max-width: 760px) { #quick .qa { width: 24px !important; height: 44px !important; } }
.hbtn.tnav { height: auto !important; min-height: 34px; padding: 2px 10px; }
/* equipment: the hero picture sits inside its own cell, centred, never over the item slots */
.doll { justify-content: center; justify-items: center; }
.eqhero { width: 100%; min-width: 0; box-sizing: border-box; padding: 0 2px; overflow: hidden; justify-self: stretch; }
.eqhero .pic, .eqhero img.pic.hart { width: 100% !important; max-width: 100% !important; height: auto !important; aspect-ratio: 1 / 1; object-fit: cover; margin: 0 auto; display: block; box-sizing: border-box; }
.eqhero b, .eqhero small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* phones: the seven resources sit on two lines (4 + 3), all visible, nothing to scroll sideways */
@media (max-width: 760px) {
  body #top #res, body #mres { flex-wrap: wrap !important; overflow: visible !important; justify-content: center !important; gap: 4px 5px !important; }
  body #top #res .chip, body #mres .chip { flex: 0 1 calc(25% - 6px); min-width: 0; justify-content: center; box-sizing: border-box; }
}
/* the resource bar above every window uses the same stone top bar as the map (day and night), not the old dark bar with dividers */
body.skin #mres { border: 16px solid transparent; border-image: var(--t-d, url(art/ui/topbar_day.png)) 38 fill / 16px stretch; background: none; box-shadow: none; padding: 2px 6px; }
body.skin.night #mres { border-image: var(--t-n, url(art/ui/topbar_night.png)) 38 fill / 16px stretch; }
@media (max-width: 760px) { body.skin #mres { border-width: 12px; border-image-width: 12px; } }

/* ===== phones in portrait: the new-game screens are compact enough to fit one screen ===== */
@media (max-width: 620px) and (orientation: portrait) {
  .facgrid { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  .facpic { height: 84px !important; } .ribbon { font-size: 13px !important; padding: 12px 4px 3px !important; letter-spacing: 0 !important; }
  .card.fac .blurb { display: none !important; }
  .card.fac .crow { gap: 2px !important; margin-top: 3px !important; } .card.fac .crow .pic { width: 26px !important; height: 26px !important; }
  .card.fac { padding-bottom: 4px !important; }
  .hsgrid { grid-template-columns: repeat(4, 1fr) !important; gap: 5px !important; }
  .htile { padding: 3px 2px !important; } .htile .pic, .htile .hart { width: 54px !important; height: 54px !important; max-width: 54px !important; } .htile span { font-size: 11px; } .htile small { display: none; }
  .hsbig .pic, .hsbig .hart { width: 84px !important; height: 84px !important; }
  .hspan { padding: 6px 8px !important; } .hspan h3 { font-size: 16px; margin: 2px 0 0; } .hsstats { margin: 4px 0 !important; } .hsstats b { font-size: 15px; }
  .hspan h4 { margin: 4px 0 2px !important; font-size: 10px; }
  .hsarmy .pic { width: 40px !important; height: 40px !important; }
  .opt { padding-bottom: 4px !important; } .optc small, .opts button small { display: none !important; } .opts button { min-height: 34px !important; }
  .setup .grid.two .card .small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (max-width: 620px) and (orientation: portrait) {
  .hsgrid { grid-template-columns: repeat(6, minmax(0, 1fr)) !important; gap: 4px !important; } .htile { min-width: 0; }
  .htile .pic, .htile .hart { width: 42px !important; height: 42px !important; max-width: 42px !important; } .htile span { font-size: 9px; margin-top: 1px; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #mbox.art-banner > .setup::before { height: 84px; }
  #mbox.art-banner h2 { margin-top: -26px; font-size: 20px; }
  .hspan .hsgo { display: none !important; } .hsgo2 { display: inline-flex !important; }
  .hsbig { display: flex; justify-content: center; } .hsarmy .pic { width: 34px !important; height: 34px !important; } .hsarmy div { width: 56px; font-size: 9px; }
}
@media (max-width: 700px) and (orientation: portrait) {
  .hspan { display: grid !important; grid-template-columns: 92px 1fr; gap: 0 10px; align-items: center; padding: 6px 8px !important; }
  .hspan .hsbig { grid-row: 1 / 4; grid-column: 1; }
  .hspan h3, .hspan .hscls, .hspan .hsstats { grid-column: 2; margin: 0 !important; }
  .hspan h4 { display: none !important; }
  .hspan .hsspells, .hspan .hsarmy { grid-column: 1 / -1; margin-top: 4px; }
  .setup > .small { display: none; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #mbox.art-banner > .setup::before { height: 64px; background: linear-gradient(180deg, transparent 55%, rgba(14, 9, 4, .95)), var(--scr-art) center 30% / cover no-repeat; }
  #mbox.art-banner h2 { margin-top: -22px; }
  .hsgrid .htile span { display: none; } .htile { padding: 2px !important; }
}
@media (max-width: 620px) and (orientation: portrait) {
  .card.fac .crow { display: none !important; }
  .facpic { height: 96px !important; }
}
@media (max-width: 700px) and (orientation: portrait) {
  #mbox.art-banner > .setup::before { display: none; } #mbox.art-banner h2 { margin-top: 0; }
  .setup .grid.two .card .mprev { height: 70px !important; width: 100%; object-fit: cover; }
  .setup .grid.two .card { padding: 5px !important; } .setup .grid.two .card h3, .setup .grid.two .card b { font-size: 13px; }
  .optpanel { padding: 6px 8px !important; gap: 4px !important; }
  .opt { grid-template-columns: 1fr !important; gap: 3px !important; padding-bottom: 3px !important; }
}
/* town: garrison above the picture, hero army below it, two tabs (Warriors, Buildings) */
.glabel { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--mut); margin: 4px 2px 2px; }
#mbox .garrow { justify-content: center; margin: 2px 0 4px; }
.gacts { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 2px 0 4px; } .gacts button { padding: 3px 10px !important; min-height: 28px !important; font-size: 12px !important; }
.gnohero { text-align: center; margin: 4px 0; }
body.skin #mbox .gacts button, #mbox .gacts button { flex: 1 1 0; min-width: 0; border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; background: var(--grain), linear-gradient(#3b2d1c, #19110a) !important; box-shadow: inset 0 0 0 1px var(--edge) !important; min-height: 30px !important; padding: 2px 4px !important; font-size: 11px !important; white-space: nowrap; }
.gacts { flex-wrap: nowrap; }
/* desktop: the town picture leaves room for the hero army and the tabs without scrolling */
@media (min-width: 761px) and (min-height: 541px) { #mbox #tcv { width: auto !important; max-width: 100% !important; height: auto !important; max-height: 36vh; margin: 0 auto; } }
.gacts { max-width: 560px; margin-left: auto; margin-right: auto; }
/* town, Warriors tab: the creature cards sit in one row that slides sideways (swipe, wheel or drag) */
#mbox .bgrid.wgrid { display: flex !important; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; gap: 8px; scroll-snap-type: x proximity; padding: 2px 2px 8px; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scrollbar-width: thin; cursor: grab; }
#mbox .bgrid.wgrid.dragging { cursor: grabbing; scroll-snap-type: none; user-select: none; }
#mbox .bgrid.wgrid > .wcard { flex: 0 0 clamp(150px, 44vw, 210px); scroll-snap-align: start; }
@media (min-width: 761px) { #mbox .bgrid.wgrid > .wcard { flex-basis: 215px; } }
/* dragging a stack between the garrison and the hero army */
.slot[data-gr]:not(.empty) { touch-action: none; cursor: grab; }
.slot.drag-src { opacity: .35; }
.slot.drop { outline: 2px solid #ffd86a; outline-offset: -2px; box-shadow: 0 0 12px rgba(255, 216, 106, .7); }
.slot-ghost { position: fixed !important; z-index: 99999; pointer-events: none; transform: translate(-50%, -50%) scale(1.1); opacity: .92; box-shadow: 0 8px 18px rgba(0, 0, 0, .7); width: 62px; height: 70px; margin: 0; }
.gstack { background: rgba(0, 0, 0, .22); border: 1px solid var(--edge); border-radius: 8px; padding: 2px 6px 4px; margin: 6px 0; }
.gstack .garrow { margin: 1px 0 2px; }

/* ===== town: the picture fills the whole screen; troops, two buttons and a panel sit on top ===== */
#mbox.townfull { position: fixed !important; inset: 0 !important; width: auto !important; max-width: none !important; height: auto !important; max-height: none !important; margin: 0 !important; padding: 0 !important; border: 0 !important; border-image: none !important; border-radius: 0 !important; background: #0b0805 !important; box-shadow: none !important; overflow: hidden !important; z-index: 1; }
#mbox.townfull::before, #mbox.townfull::after { display: none !important; }
#modal:has(#mbox.townfull) { padding: 0 !important; }
#modal:has(#mbox.townfull) #mres { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 6; margin: 0; }
#mbox.townfull > #tcv { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; max-width: none !important; max-height: none !important; aspect-ratio: auto !important; border: 0 !important; border-radius: 0 !important; margin: 0 !important; display: block; }
.tui { position: absolute; inset: 0; display: flex; flex-direction: column; pointer-events: none; box-sizing: border-box; }
.tui > * { pointer-events: auto; }
.tui > .tfill { flex: 1; pointer-events: none; }
.ttop { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 8px 0; }
.ttop h2 { margin: 0; font-size: 18px; padding: 2px 16px; border-radius: 8px; background: rgba(12, 8, 4, .72); border: 1px solid var(--edge); }
.ttop h2 .small { font-size: 11px; }
.ttop .hlist { margin: 0; }
.tui .gstack { align-self: center; width: min(calc(100% - 16px), 640px); box-sizing: border-box; background: rgba(12, 8, 4, .78); }
.tbar { display: flex; gap: 8px; padding: 6px 8px calc(6px + var(--sab, 0px)); background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .7)); }
.tbar button { flex: 1 1 0; min-width: 0; }
.tbar .ttab.on { filter: brightness(1.25); }
.tpanel { position: absolute !important; left: 8px; right: 8px; top: var(--ttopY, 70px); bottom: var(--tbarH, 60px); display: flex; flex-direction: column; background: rgba(16, 11, 6, .97); border: 2px solid var(--edge); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .8); z-index: 4; overflow: hidden; }
.tphead { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--edge); font-family: var(--f-head); color: var(--gold); }
.tpx { min-height: 0 !important; width: 36px; height: 30px; padding: 0 !important; font-size: 16px; }
.tpbody { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 10px; }
.tpanel { top: auto !important; max-height: min(64%, 560px); }
@media (min-width: 761px) { .tpanel { left: 50%; right: auto; transform: translateX(-50%); width: min(calc(100% - 16px), 1100px); } }
#mbox.townfull > #tcv { touch-action: none; }
@media (max-width: 760px) { .ttop h2 { font-size: 15px; padding: 1px 12px; } }
/* hero selection (phone): the painted portrait sits centred inside its frame, which hugs the picture */
@media (max-width: 700px) and (orientation: portrait) {
  .hspan { grid-template-columns: auto 1fr !important; }
  .hspan .hsbig { grid-row: 1 / 4; grid-column: 1; width: max-content; height: max-content; align-self: center; justify-self: start; padding: 6px !important; box-sizing: content-box; }
  .hsbig .pic, .hsbig .hart { width: 64px !important; height: 64px !important; max-width: none !important; display: block; margin: 0; }
}

/* painted garrison panels (a socket for every stack) and painted Warriors / Buildings buttons */
.gpanel { position: relative; width: 100%; max-width: 640px; margin: 2px auto 4px; background-size: 100% 100%; background-repeat: no-repeat; }
.gpanel .slot.gs { position: absolute; margin: 0; padding: 0; min-height: 0; border: 0 !important; border-image: none !important; border-radius: 4px; background: transparent !important; box-shadow: none !important; display: grid; place-items: center; overflow: hidden; }
.gpanel .slot.gs .pic { width: 92% !important; height: auto !important; max-height: 100%; object-fit: contain; }
.gpanel .slot.gs small { position: absolute; right: 2px; bottom: 0; font-size: 11px; font-weight: bold; color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000; line-height: 1; }
.gpanel .slot.gs.sel { outline: 2px solid #ffd86a; outline-offset: -2px; box-shadow: 0 0 10px rgba(255, 216, 106, .7) !important; }
.gpanel .gshero { position: absolute; display: grid; place-items: center; overflow: hidden; border-radius: 40% 40% 4px 4px / 22% 22% 4px 4px; pointer-events: none; }
.gpanel .gshero .pic { width: 100% !important; height: 100% !important; object-fit: cover; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
.tui .gstack { background: transparent !important; border: 0 !important; padding: 0 6px; }
.tvarm { display: inline-flex; align-items: center; gap: 2px; margin: 2px 8px 0 0; } .tvarm small { font-weight: bold; color: #f3e7c6; }
.bigcr { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .78); display: grid; place-items: center; padding: 12px; }
.bigcr .bcbox { max-width: 420px; width: 100%; max-height: 96vh; overflow-y: auto; text-align: center; background: linear-gradient(#2a1d10, #140d07); border: 3px solid var(--gold); border-radius: 12px; padding: 12px 14px; }
.bigcr .bcpic { display: grid; place-items: center; } .bigcr .bcpic img { width: min(80vw, 340px) !important; height: auto !important; aspect-ratio: 1; object-fit: contain; }
.bigcr h3 { margin: 4px 0 2px; color: var(--gold); } .bigcr .wstats.big { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0; } .bigcr .wstats.big span { font-size: 15px; padding: 3px 9px; background: rgba(0, 0, 0, .45); border: 1px solid var(--edge); border-radius: 12px; }
.bigcr button { margin-top: 8px; min-width: 140px; }
.mklbl { margin: 10px 0 4px; font-weight: bold; color: var(--gold); font-size: 14px; }
.mkchips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; } .mkchip { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 8px; background: #17100a; border: 2px solid #4a381c; color: #f3e7c6; font-size: 20px; line-height: 1.1; }
.mkchip small { font-size: 11px; color: #cdbb8a; } .mkchip.on { border-color: #ffd766; background: linear-gradient(#4a3512, #2a1d0a); box-shadow: 0 0 8px rgba(255, 215, 102, .5); }
.mkqty { display: grid; grid-template-columns: 44px 1fr 44px 52px 56px; gap: 5px; } .mkqty input { text-align: center; font-size: 18px; min-width: 0; } .mkqty button { padding: 8px 0; }
.mkcost { margin: 12px 0 4px; font-size: 16px; padding: 8px 10px; background: rgba(0, 0, 0, .35); border-radius: 8px; border: 1px solid var(--edge); }
.mkart { display: grid; gap: 5px; margin-top: 6px; } .mkart .arow { text-align: left; padding: 8px 10px !important; border: 2px solid #4a381c !important; border-image: none !important; background: #17100a !important; color: #f3e7c6 !important; border-radius: 8px; min-width: 0 !important; }
.mkart .arow.on { border-color: #ffd766 !important; background: linear-gradient(#4a3512, #2a1d0a) !important; }
.mkdur { display: grid; grid-template-columns: 1fr 1.6fr; gap: 6px; } body.skin .mkdur button, .mkdur button { border-image: none !important; border: 2px solid #4a381c !important; background: #17100a !important; color: #f3e7c6 !important; padding: 8px 4px !important; min-width: 0 !important; } body.skin .mkdur button.on, .mkdur button.on { border-color: #ffd766 !important; background: linear-gradient(#4a3512, #2a1d0a) !important; }
.gcol { display: block; margin: 2px auto; padding: 3px 12px; font-size: 12px; border-radius: 12px; background: rgba(12, 8, 4, .7); color: #f3e7c6; border: 1px solid var(--edge); }
.tui .gstack .glabel { text-shadow: 0 1px 3px #000, 0 0 6px #000; color: #f3e7c6; margin: 2px 4px 0; }
.tbar .ttab.tbtn { padding: 0 !important; border: 0 !important; border-image: none !important; background: transparent !important; box-shadow: none !important; min-height: 0 !important; height: auto; }
.tbar .ttab.tbtn img { display: block; width: 100%; height: auto; max-height: 64px; object-fit: contain; filter: drop-shadow(0 2px 4px #000); }
.tbar .ttab.tbtn.on img { filter: brightness(1.25) drop-shadow(0 0 8px rgba(255, 216, 106, .8)); }
.tbar .ttab.tbtn:active img { transform: translateY(1px); }
@media (max-width: 760px) { .gpanel { max-width: none; } .gpanel .slot.gs small { font-size: 9px; } }
@media (min-width: 761px) { .gpanel { max-width: 500px; } .tui .gstack { width: min(calc(100% - 16px), 520px); } }
/* Warriors / Buildings popups fill most of the screen */
.tpanel { top: calc(var(--ttopY, 70px) + 8px) !important; bottom: var(--tbarH, 60px) !important; max-height: none !important; }
@media (min-width: 761px) { .tpanel { width: min(calc(100% - 24px), 1500px); } #mbox .bgrid.wgrid > .wcard { flex-basis: clamp(230px, 24vw, 330px); } .tpbody .bgrid:not(.wgrid) { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
.tpbody .bgrid.wgrid { align-items: stretch; min-height: 100%; }
.tpbody .bgrid.wgrid { align-items: flex-start; min-height: 0; }
.tpbody .wcard .wpic { height: auto; padding: 6px 0; } .tpbody .wcard .wpic img.pic { width: min(100%, 190px) !important; height: auto !important; aspect-ratio: 1; }
@media (min-width: 761px) { .tpbody .wcard { font-size: 15px; } .tpbody .wcard b { font-size: 17px; } .tpbody .wstats > span { font-size: 12px; padding: 2px 6px; } .tpbody .wcard .bacts button, .tpbody .wcard .bacts input { font-size: 14px !important; min-height: 38px !important; } }
/* Warriors popup: tall cards, the creature picture takes the free height */
.tpbody { display: flex; flex-direction: column; }
.tpbody .bgrid.wgrid { flex: 1 1 auto; min-height: 0; align-items: stretch; }
.tpbody .wcard { display: flex; flex-direction: column; min-height: 0; }
.tpbody .wcard .bpic.wpic { flex: 1 1 auto; min-height: 120px; display: grid; place-items: center; position: relative; overflow: hidden; padding: 4px 0; }
.tpbody .wcard .wpic img.pic:first-child { width: auto !important; height: 100% !important; max-width: 100%; aspect-ratio: 1; object-fit: contain; }
.tpbody .wcard .wpic .bcr { position: absolute; right: 6px; top: 6px; }
.tpbody .wcard .wpic .bcr { position: absolute !important; right: 6px; top: 6px; width: 52px; height: 52px; z-index: 2; }
.tpbody .wcard .wpic .bcr img.pic { width: 100% !important; height: 100% !important; max-width: none; aspect-ratio: auto; object-fit: contain; }

/* Warriors popup: all seven creatures on one page, no sideways scrolling */
#mbox .tpbody .bgrid.wgrid { display: grid !important; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; overflow: visible !important; scroll-snap-type: none; cursor: default; flex: 1 1 auto; align-items: stretch; }
#mbox .tpbody .bgrid.wgrid > .wcard { flex: none; min-width: 0; }
.tpbody .wcard .bacts { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.tpbody .wcard .bacts input { width: 100% !important; box-sizing: border-box; text-align: center; }
.tpbody .wcard .bacts button { width: 100%; }
.tpbody .wcard .wstats { display: flex; flex-wrap: wrap; gap: 2px; }
@media (min-width: 761px) and (max-width: 1100px) { #mbox .tpbody .bgrid.wgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  #mbox .tpbody .bgrid.wgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .tpbody .wcard { padding: 4px !important; }
  .tpbody .wcard .wstats, .tpbody .wcard .small { display: none; }
  .tpbody .wcard b { font-size: 11px; line-height: 1.1; }
  .tpbody .wcard .wpic .bcr { width: 26px; height: 26px; right: 2px; top: 2px; }
  .tpbody .wcard .wpic .wav { font-size: 11px; min-width: 20px; height: 20px; }
  .tpbody .wcard .bacts button, .tpbody .wcard .bacts input { font-size: 11px !important; min-height: 30px !important; padding: 2px !important; }
  .tpbody .wcard .lockpill { font-size: 10px; }
}
@media (max-width: 760px) {
  body.skin .tpbody .wcard .bacts button { border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; background: var(--grain), linear-gradient(#b8892a, #6f4d10) !important; color: #2a1604 !important; box-shadow: inset 0 0 0 1px var(--edge) !important; min-height: 30px !important; height: 30px; padding: 0 2px !important; font-size: 11px !important; text-shadow: none; }
  .tpbody .wcard .bacts input { height: 28px !important; min-height: 0 !important; padding: 0 !important; font-size: 12px !important; }
  .tpbody .wcard .bacts { margin-top: auto; }
}
.tpbody .wcard .bacts input, .tpbody .wcard .bacts button { flex: 0 0 auto !important; }

/* Warriors popup: the seven creatures stacked on top of each other, one row each (picture, details, recruit) */
#mbox .tpbody .bgrid.wgrid { grid-template-columns: 1fr !important; grid-auto-rows: minmax(0, 1fr); gap: 6px; }
.tpbody .wcard { display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; padding: 4px 10px !important; flex-direction: row; }
.tpbody .wcard .bpic.wpic { flex: none; min-height: 0; padding: 0; width: clamp(56px, 11vh, 92px); height: clamp(56px, 11vh, 92px); aspect-ratio: 1; }
.tpbody .wcard .wpic img.pic:first-child { width: 100% !important; height: 100% !important; }
.tpbody .wcard .wpic .bcr { width: 28px; height: 28px; right: 0; top: 0; }
.tpbody .wcard .wpic .wav { position: absolute; left: 0; top: 0; }
.tpbody .wcard > div:nth-child(2) { min-width: 0; }
.tpbody .wcard .bacts { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: center; margin: 0; gap: 6px; max-width: 360px; }
.tpbody .wcard .bacts input { width: 64px !important; flex: 0 0 auto !important; }
.tpbody .wcard .bacts button { width: auto; min-width: 84px; }
@media (max-width: 760px) {
  .tpbody .wcard { grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 8px; padding: 3px 6px !important; }
  .tpbody .wcard .wstats, .tpbody .wcard .small { display: flex; font-size: 10px; }
  .tpbody .wcard .wstats > span { font-size: 9px; padding: 0 3px; }
  .tpbody .wcard b { font-size: 13px; }
  .tpbody .wcard .bacts { flex-direction: column; align-items: stretch; max-width: 96px; gap: 3px; }
  .tpbody .wcard .bacts input { width: 100% !important; height: 24px !important; }
  .tpbody .wcard .bacts button { width: 100%; min-width: 0; height: 26px; min-height: 26px !important; }
  .tpbody .wcard .wpic .bcr { width: 20px; height: 20px; }
}
/* recruit amount: read-only, set with − / + and Max (no keyboard) */
.qty { display: flex; align-items: center; gap: 4px; }
.qty input { width: 52px !important; text-align: center; pointer-events: none; caret-color: transparent; background: rgba(0, 0, 0, .35); }
.qty .qb { min-width: 30px !important; width: auto !important; padding: 0 8px !important; min-height: 30px !important; height: 30px; font-size: 15px !important; }
.qty .qmax { font-size: 12px !important; }
@media (max-width: 760px) { .tpbody .wcard .bacts .qty { width: 100%; } .tpbody .wcard .bacts .qty input { width: 100% !important; min-width: 0; flex: 1 1 auto !important; } .tpbody .wcard .qty .qb { min-width: 0 !important; padding: 0 !important; height: 24px; min-height: 24px !important; font-size: 13px !important; flex: 0 0 24px !important; } .tpbody .wcard .qty .qmax { flex: 0 0 34px !important; font-size: 10px !important; } .tpbody .wcard .bacts { max-width: 120px; } }
.qty input { color: #fff3cf !important; font-weight: bold; font-size: 15px; border: 1px solid var(--edge); border-radius: 5px; }
.tpr { display: flex; align-items: center; gap: 8px; }
.tpall { min-height: 30px !important; height: 30px; padding: 0 14px !important; font-size: 13px !important; border: 1px solid #0d0803 !important; border-image: none !important; border-radius: 6px !important; background: var(--grain), linear-gradient(#d9a52a, #7d5810) !important; color: #2a1604 !important; text-shadow: none; box-shadow: inset 0 0 0 1px var(--edge) !important; }

/* ---------- desktop / tablet: the same screen as the phone — resources on top, the map filling the window, the action bar at the bottom ---------- */
@media (min-width: 761px) and (min-height: 541px) {
  body:not(.inbattle) { overflow: hidden; padding-bottom: 0; }
  body:not(.inbattle) #app { max-width: none; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 6px; padding: 6px 10px; }
  body:not(.inbattle) #top { margin: 0; flex: none; padding: 4px 14px; gap: 2px 14px; flex-wrap: nowrap; align-items: center; min-height: 0; }
  body:not(.inbattle) #top .btns { display: none; }
  body:not(.inbattle) #top #res { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-start; overflow: visible; gap: 6px; }
  body:not(.inbattle) #top .chip { font-size: 14px; padding: 1px 9px; }
  body:not(.inbattle) #top #date { flex: 0 1 auto; text-align: right; }
  body:not(.inbattle) #game { flex: 1; min-height: 0; display: block; }
  body:not(.inbattle) #stage { height: 100%; min-height: 0; width: 100%; }
  body:not(.inbattle) #stage canvas { aspect-ratio: auto; height: 100%; }
  body:not(.inbattle) #map { width: 100%; }
  body:not(.inbattle) #side { display: none; }
  body:not(.inbattle) #mbar { display: flex; position: static; flex: none; width: min(760px, 100%); align-self: center; gap: 6px; padding: 5px 6px; border: 2px solid var(--edge); border-radius: 10px; }
  body.inbattle #mbar { display: none; }
  body:not(.inbattle) #mbar button { flex: 1 1 0; min-width: 0; min-height: 58px; padding: 4px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 13px; line-height: 1.1; }
  body:not(.inbattle) #mbar button b { font-size: 24px; font-weight: normal; line-height: 1; }
  body:not(.inbattle) #mbar button.primary { flex: 1.4; }
  body:not(.inbattle) #mbar #mMenu { flex: 1 1 0; }
  #sheetBody > * { margin-bottom: 8px; }
  #sheetBody #mini { display: block; }
  #hint { bottom: calc(96px + var(--sab)); top: auto; }
}

/* wide screens: the important things sit in a column on the right (minimap, hero, army, territory), the action bar stays at the bottom */
@media (min-width: 1000px) and (min-height: 541px) {
  body:not(.inbattle) #game { display: flex; flex-direction: row; gap: 8px; }
  body:not(.inbattle) #stage { flex: 1 1 auto; width: auto; min-width: 0; }
  body:not(.inbattle) #side { display: flex; flex-direction: column; gap: 8px; flex: none; width: clamp(280px, 22vw, 340px); overflow-y: auto; overflow-x: hidden; max-height: 100%; scrollbar-width: thin; }
  body:not(.inbattle) #minipanel { max-width: none; width: auto; grid-column: auto; }
  body:not(.inbattle) #emblem { display: none; }
  body:not(.inbattle) #mbar #mHero, body:not(.inbattle) #mbar #mArmy, body:not(.inbattle) #mbar #mLand { display: none !important; }
}

/* phone: the End turn button sits on the map; the bottom bar can be folded away with its handle */
#mapEnd, #mTog { display: none; }
@media (max-width: 760px), (orientation: landscape) and (max-height: 540px) {
  #mapEnd { display: flex; position: absolute; left: 8px; bottom: 8px; z-index: 8; align-items: center; gap: 6px; padding: 8px 14px 8px 10px; min-height: 44px; font-size: 14px; font-weight: bold; border-radius: 10px; box-shadow: 0 2px 8px #000a; }
  #mapEnd svg { width: 24px; height: 24px; fill: currentColor; }
  body.inbattle #mapEnd { display: none; }
  #mbar #mEnd { display: none !important; }
  #mbar #mTog { display: flex; flex: 0 0 30px; min-height: 50px; align-items: center; justify-content: center; font-size: 18px; padding: 0; }
  body.barhid #mbar > button:not(#mTog) { display: none !important; }
  body.barhid #mbar { padding: 0; min-height: 0; background: none; border: 0; box-shadow: none; justify-content: center; }
  body.barhid #mbar #mTog { flex: 0 0 auto; width: 64px; min-height: 22px; height: 22px; border-radius: 10px 10px 0 0; font-size: 14px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body.barhid #app { padding-right: calc(3px + var(--sar)) !important; }
  body.barhid #mbar { width: 26px; background: none; border: 0; }
  body.barhid #mbar #mTog { width: 26px; height: 64px; min-height: 64px; border-radius: 10px 0 0 10px; }
  #mbar #mTog { flex: 0 0 26px; min-height: 0; width: 100%; height: 26px; }
}

/* the bar folds away on the web too */
@media (min-width: 761px) and (min-height: 541px) {
  body:not(.inbattle) #mbar #mTog { display: flex; flex: 0 0 34px; min-height: 58px; align-items: center; justify-content: center; font-size: 16px; padding: 0; }
  body.barhid:not(.inbattle) #mbar > button:not(#mTog) { display: none !important; }
  body.barhid:not(.inbattle) #mbar { padding: 0; width: auto; background: none; border: 0; box-shadow: none; }
  body.barhid:not(.inbattle) #mbar #mTog { width: 72px; flex: 0 0 auto; min-height: 22px; height: 22px; border-radius: 10px 10px 0 0; font-size: 14px; }
}

/* towns list in the right column */
#townsPanel { display: none; }
@media (min-width: 1000px) and (min-height: 541px) {
  body:not(.inbattle) #townsPanel { display: block; padding: 8px 10px; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 2px solid var(--edge); border-radius: 10px; box-shadow: var(--shadow); max-height: 34vh; overflow-y: auto; scrollbar-width: thin; }
  #townsPanel h3 { margin: 0 0 6px; font-size: 14px; }
  #townsPanel .tcard { position: relative; display: block; width: 100%; height: 62px; margin: 0 0 6px; padding: 0; overflow: hidden; border-radius: 8px; border: 2px solid var(--edge); background: #120a04; text-align: left; }
  #townsPanel .tcard img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
  #townsPanel .tcard:hover { border-color: var(--gold); }
  #townsPanel .tcn { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 15px; font-weight: bold; font-size: 13px; color: #fff3cf; text-shadow: 0 1px 2px #000; background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .8)); }
  #townsPanel .tci { position: absolute; left: 8px; right: 8px; bottom: 2px; font-size: 10px; color: #e8d9ac; text-shadow: 0 1px 2px #000; }
}

/* foldable right-hand panels: click the title */
#side > #terr > h3, #side > #townsPanel > h3 { cursor: pointer; user-select: none; display: flex; justify-content: space-between; align-items: center; }
#side > #terr > h3::after, #side > #townsPanel > h3::after { content: '▾'; font-size: 12px; opacity: .8; transition: transform .15s; }
#side > #terr.folded > h3::after, #side > #townsPanel.folded > h3::after { transform: rotate(-90deg); }
#side > #terr.folded > :not(h3), #side > #townsPanel.folded > :not(h3) { display: none !important; }
#side > #terr.folded, #side > #townsPanel.folded { padding-bottom: 6px; }
#side > #terr.folded > h3, #side > #townsPanel.folded > h3 { margin-bottom: 0; }

/* town screen: big arrows at the screen edges switch between your towns */
.tarrow { position: fixed; top: 50%; transform: translateY(-50%); z-index: 45; width: 44px; height: 84px; padding: 0; font-size: 34px; line-height: 1; border-radius: 12px; background: rgba(12, 8, 4, .62); color: #f3d98a; border: 2px solid #8c6a33; }
.tarrow.l { left: 6px; } .tarrow.r { right: 6px; }
.tarrow:hover { background: rgba(60, 40, 10, .85); border-color: var(--gold); }
@media (max-width: 760px) { .tarrow { width: 30px; height: 64px; font-size: 26px; opacity: .85; } .tarrow.l { left: 2px; } .tarrow.r { right: 2px; } }
.townpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 8px 0; }
.townpick .tcard { position: relative; display: block; width: 100%; height: 96px; padding: 0; overflow: hidden; border-radius: 10px; border: 2px solid var(--edge); background: #120a04; text-align: left; }
.townpick .tcard img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
.townpick .tcard:hover { border-color: var(--gold); }
.townpick .tcn { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 18px; font-weight: bold; font-size: 15px; color: #fff3cf; text-shadow: 0 1px 2px #000; background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .82)); }
.townpick .tci { position: absolute; left: 10px; right: 10px; bottom: 4px; font-size: 11px; color: #e8d9ac; text-shadow: 0 1px 2px #000; }
/* phones: the creature rows keep the height their content needs (they used to be squeezed into equal slices and overlapped); the panel scrolls instead */
@media (max-width: 760px) {
  #mbox .tpbody .bgrid.wgrid { grid-auto-rows: auto; flex: 0 0 auto; align-content: start; min-height: 0; }
  .tpbody .wcard { min-height: min-content; overflow: hidden; }
  .tpbody .wcard .bpic.wpic { height: 72px; width: 72px; }
}
@media (max-width: 760px) { .tui:has(.tpanel) .tarrow { display: none; } }   /* the town arrows would sit on top of the open panel */
/* town Warriors: the recruit / − / + / Max buttons were a muddy brown with dark text; brighter gold, crisper label */
body.skin .tpbody .wcard .bacts button, .tpbody .wcard .bacts button { background: linear-gradient(#ffe08a, #e0a82e 55%, #b9801a) !important; color: #1a0c01 !important; font-weight: 800; text-shadow: 0 1px 0 rgba(255, 240, 190, .6); border: 1px solid #5a3a08 !important; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), 0 1px 3px rgba(0, 0, 0, .6) !important; }
.tpbody .wcard .bacts button:disabled { background: linear-gradient(#8a7a55, #5e5236) !important; color: #2a2113 !important; opacity: .75; }
.tpbody .wcard .bacts input { background: #120b05 !important; color: #fff3cf !important; border: 1px solid #c9a24a !important; font-weight: bold; }
.tpbody .wcard.lockedrow { opacity: .8; filter: saturate(.6); }   /* locked creatures stay readable */
/* trade screen on phones: the painted button frames are too fat for seven resource chips in a row */
body.skin .mkchip, .mkchip { border: 2px solid #4a381c !important; border-image: none !important; background: #17100a !important; padding: 5px 0 !important; min-width: 0 !important; min-height: 0 !important; width: 100%; box-sizing: border-box; box-shadow: none; }
body.skin .mkchip.on, .mkchip.on { border-color: #ffd766 !important; background: linear-gradient(#4a3512, #2a1d0a) !important; box-shadow: 0 0 8px rgba(255, 215, 102, .5); }
.mkchip img { width: 26px; height: 26px; }
.mkchips { grid-template-columns: repeat(7, minmax(0, 1fr)); }
body.skin .mkqty button { border-image: none !important; border: 2px solid #8c6a33 !important; background: linear-gradient(#5a4020, #34240f) !important; color: #f3e7c6 !important; padding: 8px 0 !important; min-width: 0 !important; min-height: 0 !important; font-weight: bold; }
.mkqty { grid-template-columns: 40px minmax(0, 1fr) 40px 48px 52px; }
/* diplomacy trade on phones: selects and amounts must stay inside the window */
#mbox .trow select, #mbox .trow input[type=number], #tgD { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
#mbox .trow[style*="90px"] { grid-template-columns: minmax(0, 1fr) 90px !important; }
#tgD { display: block; margin-top: 4px; text-overflow: ellipsis; }

/* ---------- town: Buildings in side tabs (Dwellings / Town / Defense / Services) ---------- */
.tpbody.tsplit { flex-direction: row !important; padding: 0 !important; overflow: hidden !important; gap: 0; }
.tside { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; padding: 8px 6px; overflow-y: auto; border-right: 1px solid var(--edge); background: rgba(0, 0, 0, .25); }
.tside-b { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 74px; padding: 8px 4px; border-radius: 10px; border: 2px solid #4a381c; background: linear-gradient(#2a1d12, #1a1209); color: #d9c79a; font-family: var(--f-head); cursor: pointer; line-height: 1.1; }
.tside-b .ti { font-size: 24px; } .tside-b .tl { font-size: 11px; letter-spacing: .02em; }
.tside-b:hover { border-color: var(--gold-d); }
.tside-b.on { border-color: var(--gold); background: linear-gradient(#5a4220, #35250f); color: #fff1c4; box-shadow: 0 0 10px rgba(212, 168, 74, .35), inset 0 0 0 1px #000; }
.tcontent { flex: 1; min-width: 0; overflow-y: auto; padding: 8px 8px 10px; }
@media (max-width: 760px) { .tside { padding: 6px 4px; gap: 5px; } .tside-b { width: 54px; padding: 6px 2px; } .tside-b .ti { font-size: 21px; } .tside-b .tl { font-size: 9.5px; } .tcontent { padding: 6px; } }
@media (orientation: landscape) and (max-height: 540px) { .tside { flex-direction: column; gap: 4px; } .tside-b { width: 52px; padding: 4px 2px; } .tside-b .ti { font-size: 18px; } .tside-b .tl { font-size: 9px; } }

.tui:has(.tpanel) .tarrow { display: none !important; }   /* the town arrows would sit on top of the side tabs */

/* ---------- phone landscape: all resource chips stay on ONE line in the header ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  body:not(.inbattle) #top #res { flex: 1 1 100% !important; flex-wrap: nowrap !important; overflow: hidden !important; gap: 3px !important; justify-content: space-between !important; min-width: 0; }
  body:not(.inbattle) #top #res .chip { flex: 1 1 0 !important; min-width: 0; min-height: 26px !important; font-size: 12px !important; padding: 1px 4px !important; gap: 3px !important; justify-content: center; }
  body:not(.inbattle) #top #res .chip .gi { width: 17px !important; height: 17px !important; font-size: 15px !important; }
  body:not(.inbattle) #top #res .chip b { font-size: 12px !important; }
  body:not(.inbattle) #top #res .chip small { font-size: 9px !important; }
}

/* ---------- phone landscape: the town screen fits one screen (resources on one line, troops side by side, buttons visible) ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  body #modal #mres, body.skin #modal #mres { flex-wrap: nowrap !important; overflow: hidden !important; gap: 3px !important; padding: 0 !important; width: min(100%, 640px); max-width: none; border-width: 7px !important; border-image-width: 7px !important; transform: none !important; margin: 0 !important; }
  body #modal:has(#mbox.townfull) #mres { transform: translateX(-50%) !important; }
  body #modal #mres .chip { flex: 1 1 0 !important; min-width: 0; min-height: 22px !important; font-size: 12px !important; padding: 0 3px !important; gap: 2px !important; justify-content: center; }
  body #modal #mres .chip .gi { width: 16px !important; height: 16px !important; font-size: 14px !important; }
  body #modal #mres .chip b { font-size: 12px !important; }
  body #modal #mres .chip small { font-size: 9px !important; }
  .ttop h2 { font-size: 14px; padding: 0 12px; }
  .ttop h2 .small { display: none; }
  .tarrow { width: 28px; height: 56px; font-size: 22px; }
  .tui .gstack { width: min(calc(100% - 16px), 660px) !important; display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; align-items: start; padding: 0 4px !important; }
  .tui .gstack > .gcol { grid-column: 1 / -1; grid-row: 1; justify-self: center; margin: 0; padding: 1px 10px; font-size: 11px; min-height: 0 !important; height: 20px; }
  .tui .gstack > .glabel:nth-child(2) { grid-column: 1; grid-row: 2; }
  .tui .gstack > .gpanel:nth-child(3) { grid-column: 1; grid-row: 3; }
  .tui .gstack > .glabel:nth-child(4) { grid-column: 2; grid-row: 2; }
  .tui .gstack > .gpanel:nth-child(5) { grid-column: 2; grid-row: 3; }
  .tui .gstack > .gacts { grid-column: 1 / -1; grid-row: 4; }
  .tui .gstack .glabel { font-size: 10px; margin: 0 2px; }
  .gpanel { max-width: none; width: 100%; margin: 0; }
  .tbar { padding: 2px 8px calc(2px + var(--sab, 0px)); gap: 8px; justify-content: center; }
  .tbar .ttab.tbtn { flex: 0 1 200px; }
  .tbar .ttab.tbtn img { max-height: 36px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body #mbox .tui .gstack > .gcol { min-height: 0 !important; height: 20px !important; padding: 0 10px !important; font-size: 11px !important; line-height: 18px; border-width: 1px !important; border-image: none !important; width: auto; }
  body #mbox .tui .gstack > .gacts { max-width: 480px; width: 100%; justify-self: center; margin: 2px 0 0; gap: 4px; }
  body #mbox .tui .gstack > .gacts button { min-height: 24px !important; height: 24px; padding: 0 4px !important; font-size: 11px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* phone landscape battle: the side margins beside the board are grass-green instead of black */
@media (orientation: landscape) and (max-height: 540px) {
  body.inbattle #stage { background: linear-gradient(90deg, #2c4a1a, #3d5f26 50%, #2c4a1a) !important; }
}

/* ---------- phone landscape: Warriors rows keep their content height (no overlap), compact, panel scrolls ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  #mbox .tpbody .bgrid.wgrid { grid-auto-rows: auto !important; flex: 0 0 auto !important; align-content: start; min-height: 0 !important; gap: 4px; }
  .tpbody .wcard { min-height: min-content; overflow: hidden; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 8px; padding: 2px 6px !important; }
  .tpbody .wcard .bpic.wpic { height: 46px; width: 46px; }
  .tpbody .wcard .wstats, .tpbody .wcard .small { display: flex; font-size: 10px; }
  .tpbody .wcard .wstats > span { font-size: 9px; padding: 0 3px; }
  .tpbody .wcard b { font-size: 13px; }
  .tpbody .wcard .wpic .bcr { width: 18px; height: 18px; }
  .tpbody .wcard .bacts { flex-direction: row; flex-wrap: nowrap; align-items: center; max-width: 230px; gap: 4px; }
  .tpbody .wcard .bacts .qty { width: auto; }
  .tpbody .wcard .bacts button { width: auto; min-width: 60px; height: 26px; min-height: 26px !important; font-size: 11px !important; }
  .tpbody .wcard .bacts .qty input { width: 40px !important; height: 24px !important; }
  .tpbody .wcard .qty .qb { min-width: 0 !important; padding: 0 !important; height: 24px; min-height: 24px !important; font-size: 13px !important; flex: 0 0 24px !important; }
  .tpbody .wcard .qty .qmax { flex: 0 0 32px !important; font-size: 10px !important; }
  .tphead { padding: 3px 10px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .tpbody .bgrid:not(.wgrid) { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 6px; }
  .tpbody .bgrid:not(.wgrid) > .bcard { padding: 4px !important; }
  .tpbody .bgrid:not(.wgrid) > .bcard .bpic { height: 52px !important; }
  .tpbody .bgrid:not(.wgrid) > .bcard .bpic img { max-height: 50px; width: auto; object-fit: contain; }
  .tpbody .bgrid:not(.wgrid) > .bcard { font-size: 11px; }
  .tpbody .bgrid:not(.wgrid) > .bcard b { font-size: 12px; }
}

/* ---------- phone landscape: Territory screen shows the map and its details side by side ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  #sheetBody:has(#mini) { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; }
  #sheetBody #mini { height: 205px !important; width: auto !important; max-width: 46vw; }
  #sheetBody:has(#mini) > :first-child { height: auto !important; }
}

/* ---------- phone portrait: screens opened from the main menu start at the top instead of sliding up from the bottom ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  body:has(#title:not(.hide)) #modal { justify-content: flex-start !important; }
  body:has(#title:not(.hide)) #mbox { border-radius: 0 0 16px 16px; border-width: 0 0 3px 0; max-height: calc(100dvh - var(--sat, 0px)); max-height: calc(100vh - var(--sat, 0px)); animation: sheetDown .22s ease-out; }
}
@keyframes sheetDown { from { transform: translateY(-40%); opacity: .4; } to { transform: none; opacity: 1; } }

/* ---------- narrow phones: button captions stay inside the ornate frame (all skinned buttons) ---------- */
@media (max-width: 480px) {
  body.skin #mbox button, body.skin .opts button, body.skin .seg button, body.skin .ttab, body.skin .seedrow button { letter-spacing: 0 !important; padding-left: 5px !important; padding-right: 5px !important; gap: 3px !important; min-width: 0; }
  body.skin .seg button, body.skin .opts button, body.skin #mbox .grid3 button, body.skin #mbox .seg.three button { font-size: 14px !important; }
  body.skin #mbox button .gi, body.skin #mbox button img.ico { width: 16px !important; height: 16px !important; font-size: 14px !important; }
}
@media (max-width: 380px) {
  body.skin .seg button, body.skin .opts button, body.skin #mbox .grid3 button { font-size: 12.5px !important; padding-left: 3px !important; padding-right: 3px !important; }
  body.skin #mbox button .gi, body.skin #mbox button img.ico { width: 14px !important; height: 14px !important; }
}
#mbar button span { letter-spacing: 0 !important; white-space: nowrap; font-size: 9.5px; }
@media (max-width: 420px) { #mbar button { padding-left: 1px !important; padding-right: 1px !important; min-width: 0; } #mbar button span { font-size: 9px; } }

/* ---------- phone portrait: main-menu screens sit a little lower (not glued to the top); hero select fills the height ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  body:has(#title:not(.hide)) #modal { padding-top: calc(var(--sat, 0px) + 26px) !important; padding-bottom: calc(var(--sab, 0px) + 10px) !important; padding-left: 8px !important; padding-right: 8px !important; box-sizing: border-box; }
  body:has(#title:not(.hide)) #mbox { border-radius: 16px; border-width: 3px; max-height: 100%; width: 100%; box-sizing: border-box; animation: sheetDown .22s ease-out; }
  body:has(#title:not(.hide)) #mbox:has(> .setup .hsbody) { min-height: min(100%, 700px); display: flex; flex-direction: column; }
  body:has(#title:not(.hide)) #mbox:has(> .setup .hsbody) > .setup { flex: 1 1 auto; display: flex; flex-direction: column; }
  body:has(#title:not(.hide)) .setup .hsbody { flex: 0 0 auto; }
  body:has(#title:not(.hide)) .setup:has(.hsbody) > .mb { margin-top: auto; position: static; }
}

/* ---------- phone landscape: hero select = roster on the left (scrolls), hero details fixed on the right ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  #mbox .hsbody { grid-template-columns: minmax(0, 1fr) 290px !important; height: calc(100dvh - 124px); min-height: 0; align-items: stretch; }
  #mbox:has(.hsbody) > .setup > .small { display: none !important; }
  #mbox .hsbody > .hsgrid { overflow-y: auto; align-content: start; min-height: 0; padding-right: 2px; scrollbar-width: thin; }
  #mbox .hspan { display: grid !important; grid-template-columns: 74px minmax(0, 1fr); gap: 0 8px; align-content: start; align-items: center; padding: 6px 8px !important; overflow-y: auto; min-height: 0; }
  #mbox .hspan .hsbig { grid-row: 1 / 3; grid-column: 1; width: max-content; height: max-content; padding: 3px !important; border-width: 12px !important; box-sizing: content-box; justify-self: start; align-self: center; }
  #mbox .hspan .hsbig .pic, #mbox .hspan .hsbig .hart { width: 54px !important; height: 54px !important; max-width: none !important; display: block; margin: 0; }
  #mbox .hspan h3 { grid-column: 2; margin: 0 !important; font-size: 15px; text-align: left; }
  #mbox .hspan .hscls { grid-column: 2; margin: 0 !important; text-align: left; font-size: 11px; }
  #mbox .hspan .hsstats { grid-column: 1 / -1; margin: 5px 0 !important; gap: 4px; }
  #mbox .hspan .hsstats div { padding: 2px 0; } #mbox .hspan .hsstats b { font-size: 14px; } #mbox .hspan .hsstats span { font-size: 9px; }
  #mbox .hspan h4 { display: none !important; }
  #mbox .hspan .hsspells, #mbox .hspan .hsarmy { grid-column: 1 / -1; margin-top: 4px; }
  #mbox .hspan .hsspells > span { font-size: 10px; padding: 1px 6px; }
  #mbox .hspan .hsarmy .pic { width: 34px !important; height: 34px !important; } #mbox .hspan .hsarmy div { width: 60px; font-size: 9px; }
  #mbox .hspan .hsgo { display: none !important; }
}
@media (orientation: landscape) and (max-height: 540px) {
  #mbox .hspan { padding: 4px 8px !important; }
  #mbox .hspan .hsbig .pic, #mbox .hspan .hsbig .hart { width: 44px !important; height: 44px !important; }
  #mbox .hspan .hsbig { border-width: 10px !important; padding: 2px !important; }
  #mbox .hspan .hsstats { margin: 3px 0 !important; }
  #mbox .hspan .hsspells { gap: 3px; margin-top: 2px; } #mbox .hspan .hsspells > span { font-size: 9.5px; padding: 0 5px; }
  #mbox .hspan .hsarmy { margin-top: 2px; gap: 4px; } #mbox .hspan .hsarmy .pic { width: 30px !important; height: 30px !important; } #mbox .hspan .hsarmy div { font-size: 8.5px; width: 62px; }
}

/* ---------- phone landscape: Merchant / market screen is compact ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  .mklbl { margin: 4px 0 2px; font-size: 12px; }
  .mkchips { gap: 4px; } .mkchip { padding: 2px 2px; font-size: 15px; flex-direction: row; justify-content: center; gap: 4px; } .mkchip small { font-size: 10px; }
  .mkqty { grid-template-columns: 38px 1fr 38px 44px 48px; gap: 4px; } .mkqty input { font-size: 15px; padding: 2px; } .mkqty button { padding: 3px 0; }
  .mkcost { margin: 5px 0 2px; font-size: 13px; padding: 3px 8px; }
}


/* =====================================================================
   Victory / Defeat — one centred celebration card for every screen size
   ===================================================================== */
@keyframes vicCard { from { transform: scale(.82) translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }
#modal:has(#mbox > .vic) { align-items: center !important; justify-content: center !important; padding: 12px !important; background: radial-gradient(ellipse at 50% 32%, rgba(90, 60, 14, .55), rgba(0, 0, 0, .92) 72%) !important; }
#modal:has(#mbox > .vic) > #mres { display: none !important; }
#mbox:has(> .vic) { width: min(94vw, 480px) !important; max-width: none !important; max-height: calc(100vh - 24px) !important; max-height: calc(100dvh - 24px) !important; padding: 0 16px 16px !important; border: 3px solid #e6bf55 !important; border-image: none !important; border-radius: 20px !important; background: radial-gradient(ellipse at 50% 0%, #4a3516, #1b130a 68%) !important; box-shadow: 0 0 0 1px #000, 0 0 46px rgba(255, 200, 80, .28), 0 16px 56px #000 !important; animation: vicCard .55s cubic-bezier(.2, 1.35, .4, 1) both !important; overflow-x: hidden; overflow-y: auto; }
#mbox:has(> .vic.lose) { border-color: #9a5a5a !important; background: radial-gradient(ellipse at 50% 0%, #3a1c1c, #150b0b 68%) !important; box-shadow: 0 0 0 1px #000, 0 0 40px rgba(200, 60, 60, .22), 0 16px 56px #000 !important; }
#mbox:has(> .vic)::before, #mbox:has(> .vic)::after { display: none !important; }
#mbox > .vic { margin: 0 -16px 10px !important; padding: 42px 12px 8px !important; }
#mbox > .vic .vic-rays { top: 92px; width: 640px; height: 640px; margin: -320px 0 0 -320px; }
#mbox > .vic .vic-crest { width: 100px; height: 100px; font-size: 52px; }
#mbox > .vic .vic-ribbon { font-size: 34px; letter-spacing: 7px; padding: 7px 54px 9px; margin-top: -14px; }
#mbox > .vic .vic-sub { margin: 12px 0 0; font-size: 16px; color: #f0e2b8; }
#mbox > .vic-hero { padding: 8px 12px; margin: 4px 0 10px !important; background: rgba(0, 0, 0, .32); border: 1px solid #4a381c; border-radius: 14px; }
#mbox > .vic-hero .pic { width: 56px !important; height: 56px !important; border: 2px solid #e6bf55; border-radius: 10px; }
#mbox > .vic-hero b { font-size: 20px; }
#mbox > .vic-stats { gap: 8px; margin: 0 0 10px !important; }
#mbox > .vic-stats > div { padding: 10px 4px 8px; border-radius: 14px; border-color: #5a4422; background: linear-gradient(rgba(255, 255, 255, .06), rgba(0, 0, 0, .35)); text-align: center; }
#mbox > .vic-stats > div::before { font-size: 20px; line-height: 1; margin-bottom: 2px; }
#mbox > .vic-stats > div:nth-child(1)::before { content: "⚔️"; } #mbox > .vic-stats > div:nth-child(2)::before { content: "🛡️"; } #mbox > .vic-stats > div:nth-child(3)::before { content: "⭐"; }
#mbox > .vic-stats b { font-size: 28px; line-height: 1.1; } #mbox > .vic-stats span { font-size: 10px; letter-spacing: .8px; margin-top: 2px; }
#mbox:has(> .vic) > h4 { margin: 4px 0 6px; text-align: center; font-size: 12px; letter-spacing: 2px; color: #e6bf55; text-transform: uppercase; }
#mbox > .vic-army { gap: 8px; margin: 0 0 6px; }
#mbox > .vic-army .vic-unit { width: 86px; padding: 8px 4px 6px; border-radius: 12px; border-color: #6a5026; background: linear-gradient(rgba(255, 255, 255, .06), rgba(0, 0, 0, .35)); }
#mbox > .vic-army .vic-unit .pic { width: 56px !important; height: 56px !important; }
#mbox > .vic-army .vic-unit b { font-size: 17px; } #mbox > .vic-army .vic-unit span { max-width: 78px; }
#mbox:has(> .vic) > .mb { position: static !important; margin-top: 12px !important; padding: 0 !important; background: none !important; justify-content: stretch; }
#mbox:has(> .vic) > .mb button { flex: 1 1 auto; width: 100%; min-height: 46px !important; font-size: 18px !important; }
#mbox:has(> .vic) > p { text-align: center; }

/* phone landscape: two columns (banner + hero | stats + army) so nothing scrolls */
@media (orientation: landscape) and (max-height: 540px) {
  #modal:has(#mbox > .vic) { padding: 6px !important; }
  #mbox:has(> .vic-stats) { width: min(96vw, 780px) !important; padding: 0 14px 10px !important; display: grid !important; grid-template-columns: 1fr 1.15fr; column-gap: 14px; align-content: center; border-radius: 16px !important; }
  #mbox:has(> .vic-stats) > .vic { grid-column: 1; grid-row: 1; margin: 0 -14px 0 -14px !important; padding: 22px 8px 2px !important; }
  #mbox:has(> .vic-stats) > .vic-hero { grid-column: 1; grid-row: 2; margin: 4px 0 !important; padding: 5px 10px; }
  #mbox:has(> .vic-stats) > .vic-stats { grid-column: 2; grid-row: 1; align-self: end; margin: 12px 0 8px !important; }
  #mbox:has(> .vic-stats) > h4 { grid-column: 2; grid-row: 2; align-self: start; margin: 0 0 4px; }
  #mbox:has(> .vic-stats) > .vic-army { grid-column: 2; grid-row: 2; margin: 22px 0 0 !important; align-self: start; }
  #mbox:has(> .vic-stats) > .mb { grid-column: 1 / -1; grid-row: 3; margin-top: 8px !important; }
  #mbox:has(> .vic-stats) > .mb button { min-height: 38px !important; font-size: 16px !important; }
  #mbox > .vic .vic-crest { width: 64px; height: 64px; font-size: 34px; } #mbox > .vic .vic-rays { top: 54px; width: 400px; height: 400px; margin: -200px 0 0 -200px; }
  #mbox > .vic .vic-ribbon { font-size: 24px; letter-spacing: 5px; padding: 4px 34px 6px; margin-top: -8px; } #mbox > .vic .vic-sub { margin: 6px 0 0; font-size: 13px; }
  #mbox > .vic-hero .pic { width: 40px !important; height: 40px !important; } #mbox > .vic-hero b { font-size: 15px; }
  #mbox > .vic-stats > div { padding: 5px 2px 4px; } #mbox > .vic-stats > div::before { font-size: 15px; } #mbox > .vic-stats b { font-size: 20px; } #mbox > .vic-stats span { font-size: 9px; }
  #mbox > .vic-army .vic-unit { width: 64px; padding: 4px 2px; } #mbox > .vic-army .vic-unit .pic { width: 38px !important; height: 38px !important; } #mbox > .vic-army .vic-unit b { font-size: 13px; }
}
/* narrow portrait phones: slightly smaller type so three stat cards and the army always fit */
@media (max-width: 380px) { #mbox > .vic .vic-ribbon { font-size: 28px; padding: 6px 40px 8px; } #mbox > .vic-stats b { font-size: 24px; } #mbox > .vic-army .vic-unit { width: 78px; } }

/* end-of-game victory (score breakdown): fits without scrolling on a landscape phone */
@media (orientation: landscape) and (max-height: 540px) {
  #mbox:has(> .vic-score) { width: min(96vw, 780px) !important; padding: 0 14px 8px !important; display: grid !important; grid-template-columns: 1fr 1.1fr; column-gap: 14px; align-content: center; border-radius: 16px !important; }
  #mbox:has(> .vic-score) > .vic { grid-column: 1; grid-row: 1; margin: 0 -14px !important; padding: 20px 8px 2px !important; }
  #mbox:has(> .vic-score) > .vic-total { grid-column: 1; grid-row: 2; margin: 4px 0 !important; padding: 6px 14px; }
  #mbox:has(> .vic-score) > .vic-total b { font-size: 22px; }
  #mbox:has(> .vic-score) > .vic-score { grid-column: 2; grid-row: 1 / 3; margin: 10px 0 4px !important; padding: 2px 10px; align-self: center; }
  #mbox:has(> .vic-score) .vic-row { padding: 2px 2px; font-size: 12px; }
  #mbox:has(> .vic-score) > .setrow { grid-column: 1 / -1; grid-row: 3; margin: 4px 0 !important; padding: 4px 10px !important; display: flex; align-items: center; justify-content: space-between; }
  #mbox:has(> .vic-score) > .setrow .small { display: none; }
  #mbox:has(> .vic-score) > .setrow input { width: 170px; height: 30px; padding: 2px 8px; }
  #mbox:has(> .vic-score) > .mb { grid-column: 1 / -1; grid-row: 4; margin-top: 4px !important; gap: 10px; }
  #mbox:has(> .vic-score) > .mb button { min-height: 36px !important; width: auto; flex: 1 1 0; }
}
@media (max-width: 340px) { #mbox > .vic-army .vic-unit { width: 70px; } #mbox > .vic-army { gap: 5px; } #mbox > .vic .vic-ribbon { font-size: 24px; padding: 5px 32px 7px; letter-spacing: 5px; } }

/* phone landscape: creature detail card = picture on the left, details on the right */
@media (orientation: landscape) and (max-height: 540px) {
  .bigcr { padding: 6px; }
  .bigcr .bcbox { max-width: 660px; max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 16px; align-content: center; align-items: center; text-align: left; padding: 10px 16px; }
  .bigcr .bcpic { grid-row: 1 / 6; }
  .bigcr .bcpic img { width: min(60vh, 250px) !important; }
  .bigcr h3 { margin: 0; font-size: 22px; }
  .bigcr .wstats.big { justify-content: flex-start; margin: 8px 0; gap: 5px; }
  .bigcr .wstats.big span { font-size: 13px; padding: 2px 8px; }
  .bigcr button { grid-column: 2; margin-top: 6px; }
}

/* PC / tablet: Warriors rows keep the height their content needs (they used to be squeezed into equal slices and overlap); the panel scrolls instead */
@media (min-width: 761px) and (min-height: 541px) {
  #mbox .tpbody .bgrid.wgrid { grid-auto-rows: auto !important; flex: 0 0 auto !important; align-content: start; min-height: 0 !important; }
  .tpbody .wcard { min-height: min-content; overflow: hidden; padding-top: 6px !important; padding-bottom: 6px !important; }
  .tpbody .wcard .bpic.wpic { height: clamp(52px, 9vh, 76px); width: clamp(52px, 9vh, 76px); }
}

/* Warriors: the "ready to recruit" count and the rank icon are small corner badges, so the creature picture stays visible */
.tpbody .wcard .wpic .wav { width: 24px !important; height: 24px !important; min-width: 0 !important; padding: 0 !important; font-size: 12px !important; line-height: 22px; left: -2px !important; top: -2px !important; border-width: 2px; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0, 0, 0, .7); }
.tpbody .wcard .wpic .bcr { width: 20px !important; height: 20px !important; right: -2px !important; top: -2px !important; }
.tpbody .wcard .wpic img.pic:first-child { width: 100% !important; height: 100% !important; }
@media (orientation: landscape) and (max-height: 540px) { .tpbody .wcard .wpic .wav { width: 20px !important; height: 20px !important; font-size: 10px !important; line-height: 18px; } .tpbody .wcard .wpic .bcr { width: 16px !important; height: 16px !important; } }
@media (min-width: 761px) and (min-height: 541px) { .tpbody .wcard .bpic.wpic { height: clamp(62px, 11vh, 88px); width: clamp(62px, 11vh, 88px); } }
@media (orientation: landscape) and (max-height: 540px) { .tpbody .wcard .qty .qmax { flex: 0 0 40px !important; font-size: 10px !important; padding: 0 !important; } .tpbody .wcard .bacts { max-width: 250px; } }

/* =====================================================================
   Phone landscape adventure map — Heroes-3 style layout:
   map on the left, a right column (minimap, hero, army slots, action buttons),
   and one thin strip along the bottom with the resources and the date.
   ===================================================================== */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) { --rail: 176px; --strip: 24px; }
  html body:not(.inbattle) #game { position: fixed !important; left: var(--sal, 0px) !important; top: var(--sat, 0px) !important; right: calc(var(--rail) + var(--sar, 0px)) !important; bottom: calc(var(--strip) + var(--sab, 0px)) !important; width: auto !important; height: auto !important; margin: 0 !important; padding: 0 !important; }
  html body:not(.inbattle) #stage { position: absolute !important; inset: 0 !important; width: auto !important; height: auto !important; max-width: none !important; }
  /* thin bottom strip: resources + date */
  html body:not(.inbattle) #top { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; height: calc(var(--strip) + var(--sab, 0px)) !important; min-height: 0 !important; padding: 0 calc(8px + var(--sar, 0px)) var(--sab, 0px) calc(8px + var(--sal, 0px)) !important; display: flex !important; align-items: center !important; gap: 8px !important; z-index: 20; border-radius: 0 !important; }
  html body:not(.inbattle) #top .btns, html body:not(.inbattle) #top #income, html body:not(.inbattle) #top .sky { display: none !important; }
  html body:not(.inbattle) #top #res { flex: 1 1 auto !important; height: 20px !important; gap: 3px !important; }
  html body:not(.inbattle) #top #res .chip { min-height: 18px !important; height: 20px; font-size: 11px !important; padding: 0 4px !important; }
  html body:not(.inbattle) #top #res .chip .gi { width: 14px !important; height: 14px !important; font-size: 12px !important; }
  html body:not(.inbattle) #top #res .chip b { font-size: 11px !important; }
  html body:not(.inbattle) #top #date { flex: none; font-size: 11px !important; line-height: 1; min-height: 0 !important; padding: 0 !important; }
  /* right column */
  html body:not(.inbattle) #side { display: flex !important; flex-direction: column; gap: 3px; position: fixed !important; top: var(--sat, 0px) !important; right: var(--sar, 0px) !important; bottom: calc(var(--strip) + var(--sab, 0px) + 112px) !important; left: auto !important; width: var(--rail) !important; padding: 4px 6px 0 4px !important; box-sizing: border-box; overflow: hidden !important; z-index: 15; background: linear-gradient(#1c130b, #120c06) !important; border-left: 2px solid #5a4222 !important; }
  html body:not(.inbattle) #side > #townsPanel, html body:not(.inbattle) #side > #terr, html body:not(.inbattle) #side > #emblem, html body:not(.inbattle) #side > #batui { display: none !important; }
  html body:not(.inbattle) #side > #minipanel { flex: none; height: 42px; display: flex; justify-content: center; position: relative; }
  html body:not(.inbattle) #side > #minipanel #mini { height: 100% !important; width: auto !important; max-width: 100%; }
  html body:not(.inbattle) #side > #minipanel .compass { display: none; }
  html body:not(.inbattle) #side > #hero { flex: none; }
  html body:not(.inbattle) #side > #hero .hlist, html body:not(.inbattle) #side > #hero .hmood, html body:not(.inbattle) #side > #hero .hperks, html body:not(.inbattle) #side > #hero .hspells, html body:not(.inbattle) #side > #hero .hacts, html body:not(.inbattle) #side > #hero .hbar { display: none !important; }
  html body:not(.inbattle) #side > #hero .hcard { display: grid !important; grid-template-columns: 36px 1fr; gap: 2px 6px; align-items: center; padding: 0 !important; }
  html body:not(.inbattle) #side > #hero .hport { grid-row: 1; width: 36px; height: 36px; }
  html body:not(.inbattle) #side > #hero .hport img { width: 36px !important; height: 36px !important; }
  html body:not(.inbattle) #side > #hero .hlvl { transform: scale(.6); transform-origin: 100% 100%; }
  html body:not(.inbattle) #side > #hero .hhead { grid-row: 1; min-width: 0; }
  html body:not(.inbattle) #side > #hero .hname { font-size: 13px; display: block; line-height: 1.1; }
  html body:not(.inbattle) #side > #hero .hcls { font-size: 9px; }
  html body:not(.inbattle) #side > #hero .hgrid { grid-column: 1 / -1; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 2px; margin: 0 !important; }
  html body:not(.inbattle) #side > #hero .hst { display: flex !important; align-items: center; justify-content: center; gap: 2px; height: 19px; min-height: 0 !important; padding: 0 2px !important; position: relative; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(n+5) { grid-column: span 2; }
  html body:not(.inbattle) #side > #hero .hst small { display: none !important; }
  html body:not(.inbattle) #side > #hero .hst .hi .gi { width: 11px !important; height: 11px !important; }
  html body:not(.inbattle) #side > #hero .hst b { font-size: 11px !important; line-height: 1; }
  html body:not(.inbattle) #side > #hero .hst b em { font-size: 8px; }
  html body:not(.inbattle) #side > #hero .hst u { position: absolute; left: 2px; right: 2px; bottom: 1px; height: 2px; display: block; }
  html body:not(.inbattle) #side > #army { flex: none; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 0 !important; }
  html body:not(.inbattle) #side > #army .slot { height: 32px !important; min-height: 0 !important; padding: 0 !important; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 22px !important; height: 22px !important; }
  html body:not(.inbattle) #side > #army .sdeco, html body:not(.inbattle) #side > #army > .small { display: none !important; }
  /* action buttons under the column */
  html body:not(.inbattle) #mbar { position: fixed !important; left: auto !important; top: auto !important; right: var(--sar, 0px) !important; bottom: calc(var(--strip) + var(--sab, 0px)) !important; width: var(--rail) !important; height: 112px !important; display: grid !important; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 31px; gap: 3px; padding: 4px 6px 4px 4px !important; box-sizing: border-box; background: linear-gradient(#120c06, #1c130b) !important; border-left: 2px solid #5a4222 !important; z-index: 15; flex-direction: row !important; }
  html body:not(.inbattle) #mbar #mTog, html body:not(.inbattle) #mbar #mArmy { display: none !important; }
  html body:not(.inbattle) #mbar button { width: auto !important; height: 31px !important; min-height: 0 !important; padding: 0 !important; flex-direction: column; }
  html body:not(.inbattle) #mbar button .ic { width: 18px; height: 18px; }
  html body:not(.inbattle) #mbar button span { font-size: 8px; }
  html body:not(.inbattle) #mbar #mEnd { order: 20; display: flex !important; grid-column: 1 / -1; height: 31px !important; flex-direction: row; align-items: center; justify-content: center; gap: 6px; }
  html body:not(.inbattle) #mbar #mEnd span { font-size: 12px; }
  html body:not(.inbattle) #mapEnd { display: none !important; }
}
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #minipanel { order: 1; flex: 1 1 42px; min-height: 42px; max-height: 110px; }
  html body:not(.inbattle) #side > #hero { order: 2; }
  html body:not(.inbattle) #side > #army { order: 3; }
}

/* ---- landscape map, round 2: minimap floats on the map; the column holds town/hero selector, hero card, army and big action buttons ---- */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side { bottom: calc(var(--strip) + var(--sab, 0px) + 83px) !important; justify-content: flex-start; }
  /* minimap on the map, top-right, semi-transparent */
  html body:not(.inbattle) #stage > #minipanel { position: absolute !important; right: 8px; top: 8px; width: 112px; height: auto !important; flex: none; display: block !important; z-index: 9; padding: 2px; background: rgba(12, 8, 4, .72) !important; border: 2px solid #8c6a22 !important; border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, .7); opacity: .92; }
  html body:not(.inbattle) #stage > #minipanel #mini { width: 100% !important; height: auto !important; display: block; border-radius: 3px; }
  html body:not(.inbattle) #stage > #minipanel .compass { display: none; }
  /* town + hero selector */
  html body:not(.inbattle) #side > #quick { order: 1; position: static !important; flex: none; display: flex !important; flex-direction: column; gap: 3px; width: 100%; max-height: none !important; overflow: visible !important; }
  html body:not(.inbattle) #side > #quick .qrow { display: flex; gap: 3px; height: 26px; align-items: stretch; }
  html body:not(.inbattle) #side > #quick .qa { width: 18px !important; height: 26px !important; font-size: 15px !important; border-radius: 6px !important; }
  html body:not(.inbattle) #side > #quick .qt { flex: 1 1 auto; width: auto !important; height: 26px !important; border-radius: 6px !important; position: relative; }
  html body:not(.inbattle) #side > #quick .qt img { width: 100%; height: 100%; object-fit: cover; }
  html body:not(.inbattle) #side > #quick .qt .qname { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; line-height: 12px; padding: 0 2px; background: rgba(0, 0, 0, .55); }
  html body:not(.inbattle) #side > #quick .qx { width: 30px !important; height: 26px !important; }
  html body:not(.inbattle) #side > #quick .qcol { display: flex; flex-direction: row !important; flex-wrap: wrap; gap: 3px; max-height: none !important; }
  html body:not(.inbattle) #side > #quick .qh { width: 31px !important; height: 31px !important; border-radius: 6px !important; }
  /* hero card: portrait, name, stats, xp bar */
  html body:not(.inbattle) #side > #hero { order: 2; }
  html body:not(.inbattle) #side > #hero .hport { display: block !important; }
  html body:not(.inbattle) #side > #hero .hcard { grid-template-columns: 40px 1fr !important; }
  html body:not(.inbattle) #side > #hero .hport, html body:not(.inbattle) #side > #hero .hport img { width: 40px !important; height: 40px !important; }
  html body:not(.inbattle) #side > #hero .hhead { grid-row: 1; white-space: normal; }
  html body:not(.inbattle) #side > #hero .hname { display: block; font-size: 13px; }
  html body:not(.inbattle) #side > #hero .hcls { margin: 0; font-size: 9px; }
  html body:not(.inbattle) #side > #hero .hbar { display: block !important; height: 11px; margin: 2px 0 0; }
  html body:not(.inbattle) #side > #hero .hbar span { font-size: 8px; line-height: 11px; }
  /* army: bigger slots */
  html body:not(.inbattle) #side > #army { order: 3; }
  html body:not(.inbattle) #side > #army .slot { height: 34px !important; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 28px !important; height: 28px !important; }
  /* action buttons: two rows, bigger */
  html body:not(.inbattle) #mbar { height: 83px !important; grid-auto-rows: 36px; }
  html body:not(.inbattle) #mbar button { height: 36px !important; }
  html body:not(.inbattle) #mbar button .ic { width: 20px; height: 20px; }
  html body:not(.inbattle) #mbar button span { font-size: 9px; }
  html body:not(.inbattle) #mbar #mEnd { grid-column: auto !important; height: 36px !important; flex-direction: column; gap: 0; }
  html body:not(.inbattle) #mbar #mEnd span { font-size: 9px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #quick button { min-height: 0 !important; }
  html body:not(.inbattle) #side > #army .slot { min-height: 0 !important; }
}
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #hero .hbar { display: none !important; } }
/* army slots in the right column: creature picture on the left, its count on the side in amber */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #army .slot:not(.empty) { display: flex !important; align-items: center; justify-content: space-between; gap: 2px; padding: 0 4px 0 3px !important; }
  html body:not(.inbattle) #side > #army .slot .pic { flex: none; }
  html body:not(.inbattle) #side > #army .slot small { position: static !important; flex: 1 1 auto; text-align: right; font-size: 12px !important; font-weight: 800; line-height: 1; color: #ffc93c !important; text-shadow: 0 1px 2px #000, 0 0 3px #000; margin: 0 !important; padding: 0 !important; min-width: 0; }
}
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) { --rail: 196px; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 24px !important; height: 24px !important; }
  html body:not(.inbattle) #side > #army .slot:not(.empty) { padding: 0 3px 0 2px !important; }
}
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #army .slot:not(.empty) { flex-direction: row !important; flex-wrap: nowrap !important; overflow: hidden; }
  html body:not(.inbattle) #side > #army .slot small { display: block !important; width: auto; height: auto; bottom: auto !important; right: auto !important; top: auto !important; left: auto !important; }
}
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army { width: 100% !important; max-width: none !important; margin: 0 !important; box-sizing: border-box; } }
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army .slot { width: auto !important; max-width: none !important; min-width: 0 !important; } }
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army .slot { aspect-ratio: auto !important; } }

/* ---- landscape map, round 3: action buttons styled like the rest of the game ---- */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side { bottom: calc(var(--strip) + var(--sab, 0px) + 102px) !important; }
  html body:not(.inbattle) #side > #hero .hport, html body:not(.inbattle) #side > #hero .hport img { width: 38px !important; height: 38px !important; }
  html body:not(.inbattle) #side > #hero .hcard { grid-template-columns: 38px 1fr !important; }
  html body:not(.inbattle) #side > #army .slot { height: 32px !important; }
  /* the panel */
  html body.skin:not(.inbattle) #mbar { height: 102px !important; display: grid !important; grid-template-columns: repeat(12, 1fr); grid-auto-rows: 30px; gap: 3px; padding: 5px 6px 5px 5px !important; border: 0 !important; border-top: 2px solid #8c6a22 !important; border-left: 2px solid #5a4222 !important; border-radius: 0 !important; background: var(--grain), linear-gradient(#2a1d10, #120c06) !important; box-shadow: inset 0 1px 0 rgba(255, 225, 160, .18) !important; }
  html body:not(.inbattle) #mbar #mHero, html body:not(.inbattle) #mbar #mGear, html body:not(.inbattle) #mbar #mLand, html body:not(.inbattle) #mbar #mDip { grid-column: span 3; }
  html body:not(.inbattle) #mbar #mBuild, html body:not(.inbattle) #mbar #mTown, html body:not(.inbattle) #mbar #mMenu { grid-column: span 4; }
  html body:not(.inbattle) #mbar:has(#mBuild[style*="none"]) #mTown, html body:not(.inbattle) #mbar:has(#mBuild[style*="none"]) #mMenu { grid-column: span 6; }
  html body:not(.inbattle) #mbar #mEnd { grid-column: 1 / -1 !important; order: 20; }
  /* plates */
  html body.skin:not(.inbattle) #mbar button { height: 30px !important; min-height: 0 !important; padding: 0 3px !important; display: flex !important; flex-direction: row !important; align-items: center; justify-content: center; gap: 4px; border: 1px solid #0d0803 !important; border-radius: 7px !important; background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .22), transparent 72%), linear-gradient(#4a3822, #1d140a) !important; box-shadow: inset 0 0 0 1px #8c6a22, inset 0 0 0 2px #0d0803, inset 0 1px 0 2px rgba(255, 225, 160, .16), 0 2px 3px rgba(0, 0, 0, .7) !important; }
  html body:not(.inbattle) #mbar button .ic { width: 20px !important; height: 20px !important; flex: none; }
  html body:not(.inbattle) #mbar button span { font-size: 9px !important; letter-spacing: .4px !important; white-space: nowrap; color: #f1dea6; }
  html body.skin:not(.inbattle) #mbar button:active { transform: translateY(1px); background: var(--grain), linear-gradient(#17100a, #33261a) !important; }
  /* the four top tools stack icon over label (they are narrower) */
  html body.skin:not(.inbattle) #mbar #mHero, html body.skin:not(.inbattle) #mbar #mGear, html body.skin:not(.inbattle) #mbar #mLand, html body.skin:not(.inbattle) #mbar #mDip { flex-direction: column !important; gap: 0; padding: 1px 0 !important; }
  html body:not(.inbattle) #mbar #mHero .ic, html body:not(.inbattle) #mbar #mGear .ic, html body:not(.inbattle) #mbar #mLand .ic, html body:not(.inbattle) #mbar #mDip .ic { width: 18px !important; height: 18px !important; }
  html body:not(.inbattle) #mbar #mHero span, html body:not(.inbattle) #mbar #mGear span, html body:not(.inbattle) #mbar #mLand span, html body:not(.inbattle) #mbar #mDip span { font-size: 8px !important; letter-spacing: .2px !important; line-height: 1; }
  /* End turn: a wide gold bar */
  html body.skin:not(.inbattle) #mbar #mEnd { height: 28px !important; grid-column: 1 / -1 !important; gap: 8px; border-radius: 8px !important; background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 245, 190, .55), transparent 75%), linear-gradient(#d9a634, #7a5110) !important; box-shadow: inset 0 0 0 1px #ffe08a, inset 0 0 0 2px #3a2506, 0 0 10px rgba(230, 191, 85, .45), 0 2px 3px rgba(0, 0, 0, .7) !important; animation: endGlow 2.6s ease-in-out infinite; }
  html body:not(.inbattle) #mbar #mEnd span { font-size: 12px !important; letter-spacing: 1.4px !important; color: #2a1604 !important; text-shadow: 0 1px 0 rgba(255, 235, 170, .8) !important; font-weight: 800; }
  html body:not(.inbattle) #mbar #mEnd .ic { width: 20px !important; height: 20px !important; }
}
/* minimap minimise toggle (only on the map in phone landscape) + army fit */
#miniTog { display: none; }
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #army .slot { height: 29px !important; }
  html body:not(.inbattle) #stage > #minipanel #miniTog { display: grid; place-items: center; position: absolute; left: -2px; top: -2px; width: 20px; height: 20px; min-height: 0 !important; padding: 0 !important; font-size: 13px; line-height: 1; font-weight: 800; color: #f1dea6; background: rgba(20, 14, 8, .92) !important; border: 1px solid #8c6a22 !important; border-radius: 5px 0 5px 0 !important; box-shadow: none !important; z-index: 2; cursor: pointer; }
  html body.minihid:not(.inbattle) #stage > #minipanel { width: 30px !important; height: 30px !important; padding: 0 !important; overflow: hidden; }
  html body.minihid:not(.inbattle) #stage > #minipanel #mini { display: none !important; }
  html body.minihid:not(.inbattle) #stage > #minipanel #miniTog { left: 0; top: 0; width: 100%; height: 100%; font-size: 16px; border: 0 !important; border-radius: 4px !important; background: transparent !important; }
}
/* castle / hero selector in the column: roomy castle row (arrows + picture + full name), hero portraits below */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #quick .qrow { height: 32px; gap: 4px; }
  html body:not(.inbattle) #side > #quick .qa { width: 22px !important; height: 32px !important; font-size: 18px !important; }
  html body:not(.inbattle) #side > #quick .qt { height: 32px !important; border-radius: 7px !important; }
  html body:not(.inbattle) #side > #quick .qt .qname { font-size: 11px; line-height: 14px; padding: 0 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: normal; font-weight: 700; letter-spacing: .3px; color: #f6e6b4; text-shadow: 0 1px 2px #000; background: linear-gradient(transparent, rgba(0, 0, 0, .78)); }
  html body:not(.inbattle) #side > #quick .qcol { gap: 4px; }
}
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army .slot { height: 27px !important; } html body:not(.inbattle) #side > #army .slot .pic { width: 22px !important; height: 22px !important; } }
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army .slot { height: 26px !important; } }

/* =====================================================================
   PC / tablet adventure map - the same Heroes-3 layout, larger:
   map on the left; right column with minimap, castle + hero selector, hero card, army slots and the
   action buttons; one thin strip along the bottom with resources and the date.
   ===================================================================== */
@media (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) { --rail: clamp(290px, 24vw, 350px); --strip: 34px; --mbarh: 146px; }
  html body:not(.inbattle) #top, html body:not(.inbattle) #side, html body:not(.inbattle) #mbar { zoom: 1 !important; }
  html body:not(.inbattle) #game { position: fixed !important; left: 0 !important; top: 0 !important; right: var(--rail) !important; bottom: var(--strip) !important; display: block !important; width: auto !important; height: auto !important; margin: 0 !important; padding: 0 !important; }
  html body:not(.inbattle) #stage { position: absolute !important; inset: 8px 0 8px 8px !important; width: auto !important; height: auto !important; max-width: none !important; }
  /* thin bottom strip: resources + date */
  html body:not(.inbattle) #top { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; height: var(--strip) !important; min-height: 0 !important; padding: 0 14px !important; display: flex !important; align-items: center !important; gap: 14px !important; z-index: 20; border-radius: 0 !important; flex-wrap: nowrap !important; }
  html body:not(.inbattle) #top .btns, html body:not(.inbattle) #top #income, html body:not(.inbattle) #top .sky { display: none !important; }
  html body:not(.inbattle) #top #res { flex: 1 1 auto !important; flex-wrap: nowrap !important; overflow: visible !important; height: 26px !important; gap: 8px !important; justify-content: flex-start !important; }
  html body:not(.inbattle) #top #res .chip { height: 26px; min-height: 0 !important; font-size: 14px !important; padding: 0 10px !important; flex: 0 1 auto !important; }
  html body:not(.inbattle) #top #res .chip .gi { width: 18px !important; height: 18px !important; font-size: 16px !important; }
  html body:not(.inbattle) #top #res .chip b { font-size: 14px !important; }
  html body:not(.inbattle) #top #date { flex: none; font-size: 13px !important; line-height: 1; padding: 0 !important; min-height: 0 !important; }
  html body:not(.inbattle) #top #orb { flex: none; }
  /* right column */
  html body:not(.inbattle) #side { display: flex !important; flex-direction: column; gap: 6px; position: fixed !important; top: 0 !important; right: 0 !important; bottom: calc(var(--strip) + var(--mbarh)) !important; left: auto !important; width: var(--rail) !important; max-width: none !important; max-height: none !important; padding: 8px 10px 4px 8px !important; box-sizing: border-box; overflow-x: hidden !important; overflow-y: auto !important; scrollbar-width: thin; z-index: 15; background: var(--grain), linear-gradient(#241a10, #120c06) !important; border-left: 2px solid #5a4222 !important; }
  html body:not(.inbattle) #side > #townsPanel, html body:not(.inbattle) #side > #terr, html body:not(.inbattle) #side > #emblem, html body:not(.inbattle) #side > #batui { display: none !important; }
  html body:not(.inbattle) #side > #minipanel { order: 0; flex: 1 1 130px; min-height: 90px; max-height: 270px; max-width: none !important; width: auto !important; display: flex !important; justify-content: center; align-items: center; position: relative; grid-column: auto; }
  html body:not(.inbattle) #side > #minipanel #mini { height: 100% !important; width: auto !important; max-width: 100%; }
  /* castle + hero selector */
  html body:not(.inbattle) #side > #quick { order: 1; position: static !important; flex: none; display: flex !important; flex-direction: column; gap: 6px; width: 100%; max-height: none !important; overflow: visible !important; }
  html body:not(.inbattle) #side > #quick .qrow { display: flex; gap: 6px; height: 40px; align-items: stretch; }
  html body:not(.inbattle) #side > #quick .qa { width: 28px !important; height: 40px !important; font-size: 22px !important; border-radius: 8px !important; }
  html body:not(.inbattle) #side > #quick .qt { flex: 1 1 auto; width: auto !important; height: 40px !important; border-radius: 8px !important; position: relative; }
  html body:not(.inbattle) #side > #quick .qt img { width: 100%; height: 100%; object-fit: cover; }
  html body:not(.inbattle) #side > #quick .qt .qname { position: absolute; left: 0; right: 0; bottom: 0; font-size: 13px; line-height: 17px; padding: 0 6px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: normal; font-weight: 700; letter-spacing: .3px; color: #f6e6b4; text-shadow: 0 1px 2px #000; background: linear-gradient(transparent, rgba(0, 0, 0, .78)); }
  html body:not(.inbattle) #side > #quick .qx { display: none !important; }
  html body:not(.inbattle) #side > #quick .qcol { display: flex; flex-direction: row !important; flex-wrap: wrap; gap: 6px; max-height: none !important; }
  html body:not(.inbattle) #side > #quick .qh { width: 46px !important; height: 46px !important; border-radius: 8px !important; }
  html body:not(.inbattle) #side > #quick button { min-height: 0 !important; }
  /* hero card */
  html body:not(.inbattle) #side > #hero { order: 2; flex: none; }
  html body:not(.inbattle) #side > #hero .hlist, html body:not(.inbattle) #side > #hero .hmood, html body:not(.inbattle) #side > #hero .hperks, html body:not(.inbattle) #side > #hero .hspells, html body:not(.inbattle) #side > #hero .hacts { display: none !important; }
  html body:not(.inbattle) #side > #hero .hcard { display: grid !important; grid-template-columns: 56px 1fr !important; gap: 6px 10px; align-items: center; padding: 0 !important; }
  html body:not(.inbattle) #side > #hero .hport, html body:not(.inbattle) #side > #hero .hport img { width: 56px !important; height: 56px !important; }
  html body:not(.inbattle) #side > #hero .hhead { grid-row: 1; min-width: 0; }
  html body:not(.inbattle) #side > #hero .hname { display: block; font-size: 17px; line-height: 1.15; }
  html body:not(.inbattle) #side > #hero .hcls { font-size: 12px; }
  html body:not(.inbattle) #side > #hero .hgrid { grid-column: 1 / -1; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 0 !important; }
  html body:not(.inbattle) #side > #hero .hst { display: flex !important; align-items: center; justify-content: center; gap: 4px; height: 26px; min-height: 0 !important; padding: 0 4px !important; position: relative; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(n+5) { grid-column: span 2; }
  html body:not(.inbattle) #side > #hero .hst small { display: none !important; }
  html body:not(.inbattle) #side > #hero .hst .hi .gi { width: 15px !important; height: 15px !important; }
  html body:not(.inbattle) #side > #hero .hst b { font-size: 14px !important; line-height: 1; }
  html body:not(.inbattle) #side > #hero .hst b em { font-size: 10px; }
  html body:not(.inbattle) #side > #hero .hst u { position: absolute; left: 3px; right: 3px; bottom: 2px; height: 3px; display: block; }
  html body:not(.inbattle) #side > #hero .hbar { display: block !important; height: 14px; margin: 2px 0 0; }
  html body:not(.inbattle) #side > #hero .hbar span { font-size: 10px; line-height: 14px; }
  /* army: amber counts beside the creature */
  html body:not(.inbattle) #side > #army { order: 3; flex: none; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 5px; padding: 0 !important; width: 100% !important; max-width: none !important; margin: 0 !important; box-sizing: border-box; }
  html body:not(.inbattle) #side > #army .slot { height: 46px !important; min-height: 0 !important; width: auto !important; max-width: none !important; min-width: 0 !important; aspect-ratio: auto !important; padding: 0 !important; }
  html body:not(.inbattle) #side > #army .slot:not(.empty) { display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center; justify-content: space-between; gap: 3px; padding: 0 6px 0 4px !important; overflow: hidden; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 36px !important; height: 36px !important; flex: none; }
  html body:not(.inbattle) #side > #army .slot small { position: static !important; display: block !important; flex: 1 1 auto; text-align: right; font-size: 15px !important; font-weight: 800; line-height: 1; color: #ffc93c !important; text-shadow: 0 1px 2px #000, 0 0 3px #000; margin: 0 !important; padding: 0 !important; min-width: 0; }
  html body:not(.inbattle) #side > #army .sdeco, html body:not(.inbattle) #side > #army > .small { display: none !important; }
  /* action buttons under the column */
  html body.skin:not(.inbattle) #mbar { position: fixed !important; left: auto !important; top: auto !important; right: 0 !important; bottom: var(--strip) !important; width: var(--rail) !important; height: var(--mbarh) !important; display: grid !important; grid-template-columns: repeat(12, 1fr); grid-auto-rows: 44px; gap: 6px; padding: 8px 10px 8px 8px !important; box-sizing: border-box; flex-direction: row !important; align-content: start; border: 0 !important; border-top: 2px solid #8c6a22 !important; border-left: 2px solid #5a4222 !important; border-radius: 0 !important; background: var(--grain), linear-gradient(#2a1d10, #120c06) !important; box-shadow: inset 0 1px 0 rgba(255, 225, 160, .18) !important; z-index: 15; }
  html body:not(.inbattle) #mbar #mTog, html body:not(.inbattle) #mbar #mArmy { display: none !important; }
  html body:not(.inbattle) #mbar #mHero, html body:not(.inbattle) #mbar #mLand { display: flex !important; }
  html body:not(.inbattle) #mbar #mHero, html body:not(.inbattle) #mbar #mGear, html body:not(.inbattle) #mbar #mLand, html body:not(.inbattle) #mbar #mDip { grid-column: span 3; }
  html body:not(.inbattle) #mbar #mBuild, html body:not(.inbattle) #mbar #mTown, html body:not(.inbattle) #mbar #mMenu { grid-column: span 4; }
  html body:not(.inbattle) #mbar:has(#mBuild[style*="none"]) #mTown, html body:not(.inbattle) #mbar:has(#mBuild[style*="none"]) #mMenu { grid-column: span 6; }
  html body.skin:not(.inbattle) #mbar button { height: 44px !important; min-height: 0 !important; min-width: 0 !important; padding: 0 4px !important; display: flex !important; flex-direction: row !important; align-items: center; justify-content: center; gap: 6px; border: 1px solid #0d0803 !important; border-radius: 9px !important; background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .22), transparent 72%), linear-gradient(#4a3822, #1d140a) !important; box-shadow: inset 0 0 0 1px #8c6a22, inset 0 0 0 2px #0d0803, inset 0 1px 0 2px rgba(255, 225, 160, .16), 0 2px 4px rgba(0, 0, 0, .7) !important; flex: none !important; }
  html body.skin:not(.inbattle) #mbar button:hover { filter: brightness(1.15); }
  html body.skin:not(.inbattle) #mbar button:active { transform: translateY(1px); background: var(--grain), linear-gradient(#17100a, #33261a) !important; }
  html body:not(.inbattle) #mbar button .ic { width: 26px !important; height: 26px !important; flex: none; }
  html body:not(.inbattle) #mbar button span { font-size: 11px !important; letter-spacing: .6px !important; white-space: nowrap; color: #f1dea6; }
  html body.skin:not(.inbattle) #mbar #mHero, html body.skin:not(.inbattle) #mbar #mGear, html body.skin:not(.inbattle) #mbar #mLand, html body.skin:not(.inbattle) #mbar #mDip { flex-direction: column !important; gap: 1px; padding: 2px 0 !important; }
  html body:not(.inbattle) #mbar #mHero .ic, html body:not(.inbattle) #mbar #mGear .ic, html body:not(.inbattle) #mbar #mLand .ic, html body:not(.inbattle) #mbar #mDip .ic { width: 22px !important; height: 22px !important; }
  html body:not(.inbattle) #mbar #mHero span, html body:not(.inbattle) #mbar #mGear span, html body:not(.inbattle) #mbar #mLand span, html body:not(.inbattle) #mbar #mDip span { font-size: 10px !important; letter-spacing: .3px !important; line-height: 1; }
  html body.skin:not(.inbattle) #mbar #mEnd { order: 20; display: flex !important; grid-column: 1 / -1 !important; height: 40px !important; gap: 10px; border-radius: 10px !important; background: var(--grain), radial-gradient(ellipse at 50% 0, rgba(255, 245, 190, .55), transparent 75%), linear-gradient(#d9a634, #7a5110) !important; box-shadow: inset 0 0 0 1px #ffe08a, inset 0 0 0 2px #3a2506, 0 0 12px rgba(230, 191, 85, .45), 0 2px 4px rgba(0, 0, 0, .7) !important; animation: endGlow 2.6s ease-in-out infinite; }
  html body:not(.inbattle) #mbar #mEnd span { font-size: 15px !important; letter-spacing: 1.8px !important; color: #2a1604 !important; text-shadow: 0 1px 0 rgba(255, 235, 170, .8) !important; font-weight: 800; }
  html body:not(.inbattle) #mbar #mEnd .ic { width: 24px !important; height: 24px !important; }
  html body:not(.inbattle) #mapEnd, html body:not(.inbattle) #miniTog { display: none !important; }
  html body:not(.inbattle) #hint { bottom: calc(var(--strip) + 12px); }
}

/* bottom strip: the date reads on one line (Month - Week - Day) */
@media (orientation: landscape) and (max-height: 540px), (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #top #date { display: flex !important; flex-direction: row !important; align-items: center !important; gap: 10px !important; height: auto !important; }
  html body:not(.inbattle) #top #date .dtMain { display: flex !important; flex-direction: row !important; align-items: baseline; gap: 6px; white-space: nowrap; }
  html body:not(.inbattle) #top #date .dtMain small { font-size: 11px !important; letter-spacing: .5px; }
  html body:not(.inbattle) #top #date .dtMain b { font-size: 15px !important; line-height: 1; }
  html body:not(.inbattle) #top #date .dtTurn { display: none !important; }
}

/* the resource/date strip only runs under the map; the right column and its buttons reach the bottom of the screen */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #top { right: calc(var(--rail) + var(--sar, 0px)) !important; gap: 10px !important; }
  html body:not(.inbattle) #top #res { flex: 0 1 auto !important; min-width: 0; }
  html body:not(.inbattle) #top #res .chip { flex: 0 1 auto !important; }
  html body:not(.inbattle) #top #date { margin-right: auto; }
  html body:not(.inbattle) #side { bottom: calc(var(--sab, 0px) + 102px) !important; }
  html body.skin:not(.inbattle) #mbar { bottom: var(--sab, 0px) !important; padding-bottom: 5px !important; }
  html body:not(.inbattle) #side > #army .slot { height: 32px !important; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 26px !important; height: 26px !important; }
}
@media (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #top { right: var(--rail) !important; }
  html body:not(.inbattle) #top #res { flex: 0 1 auto !important; min-width: 0; }
  html body:not(.inbattle) #top #res .chip { flex: 0 1 auto !important; }
  html body:not(.inbattle) #top #date { margin-right: auto; }
  html body:not(.inbattle) #side { bottom: var(--mbarh) !important; }
  html body.skin:not(.inbattle) #mbar { bottom: 0 !important; }
}

/* hero panel in the right column, laid out like Heroes 3: name plaque on top, portrait + stats, move/mana bars, framed army */
@media (orientation: landscape) and (max-height: 540px), (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #side > #hero { background: var(--grain), linear-gradient(#2c2013, #160f08); border: 2px solid #5a4222; border-radius: 8px; padding: 4px !important; box-shadow: inset 0 0 0 1px #0d0803, inset 0 1px 0 2px rgba(255, 225, 160, .12); }
  html body:not(.inbattle) #side > #hero .hcard { display: grid !important; grid-template-columns: var(--hp, 40px) 1fr 1fr !important; grid-template-rows: auto var(--hs, 19px) var(--hs, 19px) var(--hs, 19px); gap: 3px !important; align-items: stretch !important; padding: 0 !important; }
  html body:not(.inbattle) #side > #hero .hhead { grid-column: 1 / -1 !important; grid-row: 1 !important; text-align: center; padding: 2px 6px 3px; border-radius: 6px; background: linear-gradient(#5a4220, #2a1d0d); border: 1px solid #8c6a22; box-shadow: inset 0 1px 0 rgba(255, 225, 160, .25), 0 1px 3px rgba(0, 0, 0, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  html body:not(.inbattle) #side > #hero .hname { display: block; font-size: var(--hn, 13px) !important; line-height: 1.1; letter-spacing: 1px; text-transform: uppercase; color: #f6dd96; text-shadow: 0 1px 2px #000; }
  html body:not(.inbattle) #side > #hero .hcls { display: block; margin: 0 !important; font-size: var(--hc, 9px) !important; color: #d9c48a; letter-spacing: .3px; }
  html body:not(.inbattle) #side > #hero .hport { grid-column: 1 !important; grid-row: 2 / 4 !important; display: block !important; width: var(--hp, 40px) !important; height: calc(var(--hs, 19px) * 2 + 3px) !important; position: relative; }
  html body:not(.inbattle) #side > #hero .hport img { width: 100% !important; height: 100% !important; object-fit: cover; border: 1px solid #8c6a22 !important; border-radius: 6px !important; }
  html body:not(.inbattle) #side > #hero .hgrid { display: contents !important; }
  html body:not(.inbattle) #side > #hero .hst { margin: 0 !important; height: var(--hs, 19px) !important; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(1) { grid-column: 2; grid-row: 2; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(2) { grid-column: 3; grid-row: 2; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(3) { grid-column: 2; grid-row: 3; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(4) { grid-column: 3; grid-row: 3; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(5) { grid-column: 1 / 3 !important; grid-row: 4; }
  html body:not(.inbattle) #side > #hero .hst:nth-child(6) { grid-column: 3 !important; grid-row: 4; }
  html body:not(.inbattle) #side > #hero .hbar { display: none !important; }
  /* army in a frame */
  html body:not(.inbattle) #side > #army { background: var(--grain), linear-gradient(#241a10, #120c06); border: 2px solid #5a4222; border-radius: 8px; padding: 4px !important; box-shadow: inset 0 0 0 1px #0d0803; }
}
@media (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) { --hp: 56px; --hs: 26px; --hn: 16px; --hc: 11px; }
  html body:not(.inbattle) #side > #hero { padding: 6px !important; }
  html body:not(.inbattle) #side > #hero .hcard { gap: 4px !important; }
  html body:not(.inbattle) #side > #hero .hport { height: calc(var(--hs) * 2 + 4px) !important; }
  html body:not(.inbattle) #side > #army { padding: 6px !important; }
}
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army { padding: 3px !important; gap: 3px !important; } html body:not(.inbattle) #side > #army .slot { height: 28px !important; } html body:not(.inbattle) #side > #army .slot .pic { width: 24px !important; height: 24px !important; } }

/* ---- weekly missions ---- */
#msChip { cursor: pointer; font-family: var(--f-head); font-weight: 700; white-space: nowrap; color: #f1dea6; letter-spacing: .3px; }
#msChip:hover { filter: brightness(1.2); }
#msChip.done { color: #a6ecaa; border-color: #4a8a4a; box-shadow: 0 0 8px rgba(110, 220, 120, .35); }
@media (orientation: landscape) and (max-height: 540px), (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #top #msChip { flex: none; display: inline-flex; align-items: center; height: 20px; min-height: 0 !important; font-size: 11px !important; padding: 0 8px !important; }
}
@media (min-width: 761px) and (min-height: 541px) { html body:not(.inbattle) #top #msChip { height: 26px; font-size: 13px !important; padding: 0 12px !important; } }
.msrow { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; margin: 7px 0; padding: 8px 10px; background: linear-gradient(#2a1e12, #17100a); border: 1px solid #4a381c; border-left: 4px solid #8c6a22; border-radius: 10px; }
.msrow.t0 { border-left-color: #6ea86e; } .msrow.t1 { border-left-color: #d1a642; } .msrow.t2 { border-left-color: #d0623f; }
.msrow.bonus { border-left-color: #e6bf55; background: linear-gradient(#3a2a10, #1d1408); }
.msrow.done { opacity: .72; border-left-color: #4a8a4a; }
.msi { font-size: 26px; line-height: 1; text-align: center; }
.msb { min-width: 0; } .msb > b { display: block; font-family: var(--f-head); font-size: 15px; color: #f6e6b4; }
.msbar { position: relative; height: 16px; margin-top: 4px; background: #0f0a05; border: 1px solid #4a381c; border-radius: 8px; overflow: hidden; }
.msbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#e8c25a, #a8761c); border-radius: 8px; }
.msrow.done .msbar i { background: linear-gradient(#7fcf86, #3f8a48); }
.msbar span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 16px; color: #fff; text-shadow: 0 1px 2px #000; font-weight: 700; }
.msr { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 13px; }
.msr small { font-size: 10px; letter-spacing: .6px; text-transform: uppercase; color: var(--mut, #b8a67a); }
.msr b { font-family: var(--f-head); color: #ffd86a; white-space: nowrap; }
@media (orientation: landscape) and (max-height: 540px) {
  .msrow { margin: 4px 0; padding: 5px 8px; gap: 8px; } .msi { font-size: 20px; } .msb > b { font-size: 13px; } .msbar { height: 14px; margin-top: 2px; } .msbar span { font-size: 10px; line-height: 14px; } .msr { font-size: 12px; }
}

/* army slots as tab cards: the whole creature in the card, its count on a plaque underneath; morale + luck in the spare cell */
@media (orientation: landscape) and (max-height: 540px), (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #side > #army { --sh: 40px; --sp: 27px; --sn: 12px; gap: 3px !important; }
  html body:not(.inbattle) #side > #army .slot { height: var(--sh) !important; padding: 0 !important; border-radius: 7px 7px 5px 5px !important; overflow: hidden; background: linear-gradient(#3a2b18, #170f07) !important; border: 1px solid #0d0803 !important; box-shadow: inset 0 0 0 1px #8c6a22, 0 1px 2px rgba(0, 0, 0, .6) !important; }
  html body:not(.inbattle) #side > #army .slot.empty { background: rgba(0, 0, 0, .35) !important; box-shadow: inset 0 0 0 1px #3c2e18 !important; }
  html body:not(.inbattle) #side > #army .slot:not(.empty) { display: flex !important; flex-direction: column !important; flex-wrap: nowrap !important; align-items: center; justify-content: flex-start; gap: 0; padding: 2px 2px 0 !important; }
  html body:not(.inbattle) #side > #army .slot .pic { width: 100% !important; height: var(--sp) !important; max-width: none !important; object-fit: contain; flex: none; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .7)); }
  html body:not(.inbattle) #side > #army .slot small { position: static !important; display: block !important; flex: none !important; width: calc(100% + 4px); margin: auto -2px 0 !important; padding: 0 !important; height: var(--sn); line-height: var(--sn); text-align: center !important; font-size: calc(var(--sn) - 1px) !important; font-weight: 800; letter-spacing: .2px; color: #ffd86a !important; text-shadow: 0 1px 1px #000; background: linear-gradient(#4a3416, #1a1006); border-top: 1px solid #8c6a22; }
  html body:not(.inbattle) #side > #army .sdeco.ml { display: flex !important; flex-direction: column; justify-content: center; gap: 2px; height: var(--sh); padding: 0 4px; border-radius: 7px; background: linear-gradient(#2a1e12, #140d07); border: 1px solid #5a4222; box-shadow: inset 0 0 0 1px #0d0803; }
  html body:not(.inbattle) #side > #army .sdeco .mlr { display: flex; align-items: center; justify-content: space-between; gap: 2px; line-height: 1; }
  html body:not(.inbattle) #side > #army .sdeco .mlr i { font-style: normal; font-size: 11px; }
  html body:not(.inbattle) #side > #army .sdeco .mlr b { font-family: var(--f-head); font-size: 12px; color: #f3e7c6; }
  html body:not(.inbattle) #side > #army .sdeco .mlr b.pos { color: #8fe08f; } html body:not(.inbattle) #side > #army .sdeco .mlr b.neg { color: #ff9a8a; }
}
@media (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #side > #army { --sh: 70px; --sp: 50px; --sn: 17px; gap: 5px !important; }
  html body:not(.inbattle) #side > #army .sdeco .mlr i { font-size: 16px; } html body:not(.inbattle) #side > #army .sdeco .mlr b { font-size: 16px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #side > #army { --sh: 34px; --sp: 22px; --sn: 11px; }
  html body:not(.inbattle) #side > #quick { gap: 2px; }
  html body:not(.inbattle) #side > #quick .qrow { height: 24px; }
  html body:not(.inbattle) #side > #quick .qa { height: 24px !important; width: 20px !important; font-size: 15px !important; }
  html body:not(.inbattle) #side > #quick .qt { height: 24px !important; }
  html body:not(.inbattle) #side > #quick .qt .qname { font-size: 10px; line-height: 12px; }
  html body:not(.inbattle) #side > #quick .qh { width: 27px !important; height: 27px !important; }
  html body:not(.inbattle) #side > #hero .hhead { padding: 1px 6px 2px; }
  html body:not(.inbattle) #side > #hero .hname { font-size: 12px !important; }
  html body:not(.inbattle) #side > #hero .hcls { font-size: 8px !important; }
}
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #side > #army { --sh: 36px; --sp: 22px; --sn: 11px; } html body:not(.inbattle) #side > #army .slot:not(.empty) { padding-top: 1px !important; } }
html body:not(.inbattle) #side > #army .sdeco.ml { background: linear-gradient(#2a1e12, #140d07) !important; background-image: linear-gradient(#2a1e12, #140d07) !important; }

/* main menu in phone landscape: logo centred on top, buttons in a balanced pyramid (1 / 3 / 4) */
@media (orientation: landscape) and (max-height: 540px) {
  html body #title .titlebox { display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 0 !important; width: min(92vw, 660px) !important; max-height: calc(100vh - 12px) !important; padding: 12px 26px 12px !important; margin: auto !important; overflow: hidden; }
  html body #title .titlebox .crest { display: none !important; }
  html body #title .titlebox h1 { margin: 0 !important; line-height: 0; }
  html body #title .titlebox h1 img { width: min(270px, 44vh * 2.4) !important; height: auto !important; max-height: 38vh; object-fit: contain; display: block; margin: 0 auto; filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .7)); }
  html body #title .titlebox .sub { margin: 2px 0 10px !important; font-size: 12px !important; letter-spacing: .4px; opacity: .8; }
  html body #title .titlebox .col { display: grid !important; grid-template-columns: repeat(6, 1fr); gap: 6px !important; width: 100% !important; }
  html body #title .col #tNew { grid-column: 2 / span 4; padding: 0 !important; height: 42px; font-size: 20px !important; letter-spacing: 1px; }
  html body #title .col #tScn, html body #title .col #tCont, html body #title .col #tLoad { grid-column: span 2; padding: 0 6px !important; height: 36px; font-size: 14px !important; }
  html body #title .col .sec2 { grid-column: 1 / -1; display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 6px !important; margin: 4px 0 0 !important; padding-top: 8px !important; border-top: 1px solid #4a381c; }
  html body #title .col .sec2 button { height: 32px; min-height: 0 !important; font-size: 11px !important; padding: 0 4px !important; white-space: nowrap; }
}

/* phone landscape map column: sizes follow the visible height (1u = 1% of it), so the stack fits whatever height the browser leaves (S25 Ultra with bars, short phones, ...).
   Tuned so that at 360px height every value equals the fixed size used before. */
@media (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) { --u: 1vh; --u: 1dvh; --strip: max(20px, calc(var(--u) * 6.4)); --mbarh: calc(var(--u) * 28.3); --hp: calc(var(--u) * 10.5); --hs: calc(var(--u) * 5.2); }
  html body:not(.inbattle) #side { bottom: calc(var(--sab, 0px) + var(--mbarh)) !important; }
  html body.skin:not(.inbattle) #mbar { height: var(--mbarh) !important; grid-auto-rows: calc(var(--u) * 8.3); gap: calc(var(--u) * .8); padding: calc(var(--u) * 1.3) 6px calc(var(--u) * 1.3) 5px !important; }
  html body.skin:not(.inbattle) #mbar button { height: calc(var(--u) * 8.3) !important; }
  html body.skin:not(.inbattle) #mbar #mEnd { height: calc(var(--u) * 7.8) !important; }
  html body:not(.inbattle) #side { gap: calc(var(--u) * .6); padding-top: calc(var(--u) * 1) !important; }
  html body:not(.inbattle) #side > #quick { gap: calc(var(--u) * .5); }
  html body:not(.inbattle) #side > #quick .qrow { height: calc(var(--u) * 6.7); }
  html body:not(.inbattle) #side > #quick .qa, html body:not(.inbattle) #side > #quick .qt { height: calc(var(--u) * 6.7) !important; }
  html body:not(.inbattle) #side > #quick .qh { width: calc(var(--u) * 7.5) !important; height: calc(var(--u) * 7.5) !important; }
  html body:not(.inbattle) #side > #army { --sh: calc(var(--u) * 10); --sp: calc(var(--u) * 6.1); --sn: calc(var(--u) * 3.05); }
  html body:not(.inbattle) #side > #hero .hst { height: var(--hs) !important; }
  html body:not(.inbattle) #side > #hero .hcard { grid-template-rows: auto var(--hs) var(--hs) var(--hs); }
}

/* morale and luck: emblem + signed value + a -3..+3 gauge (green to the right of the centre mark, red to the left) */
@media (orientation: landscape) and (max-height: 540px), (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #side > #army .sdeco.ml { display: flex !important; flex-direction: column; justify-content: space-evenly; gap: 0; padding: 3px 5px; border-radius: 7px; background: radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .16), transparent 70%), linear-gradient(#2e2114, #130c06) !important; border: 1px solid #8c6a22; box-shadow: inset 0 0 0 1px #0d0803, inset 0 1px 0 2px rgba(255, 225, 160, .12), 0 1px 2px rgba(0, 0, 0, .6); }
  html body:not(.inbattle) #side > #army .sdeco .mlr { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 4px; row-gap: 1px; line-height: 1; }
  html body:not(.inbattle) #side > #army .sdeco .mle { font-style: normal; font-size: 12px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .8)); }
  html body:not(.inbattle) #side > #army .sdeco .mlr b { font-family: var(--f-head); font-size: 13px; text-align: right; color: #e9dcb4; text-shadow: 0 1px 1px #000; }
  html body:not(.inbattle) #side > #army .sdeco .mlr.pos b { color: #8fe08f; text-shadow: 0 1px 1px #000, 0 0 6px rgba(120, 230, 130, .55); }
  html body:not(.inbattle) #side > #army .sdeco .mlr.neg b { color: #ff9a8a; text-shadow: 0 1px 1px #000, 0 0 6px rgba(255, 110, 90, .55); }
  html body:not(.inbattle) #side > #army .sdeco .mlbar { grid-column: 1 / -1; position: relative; display: block; height: 3px; border-radius: 2px; background: #0a0603; box-shadow: inset 0 0 0 1px #3c2e18; }
  html body:not(.inbattle) #side > #army .sdeco .mlbar::after { content: ""; position: absolute; left: 50%; top: -1px; bottom: -1px; width: 1px; background: #a98a46; }
  html body:not(.inbattle) #side > #army .sdeco .mlbar s { position: absolute; top: 0; bottom: 0; border-radius: 2px; text-decoration: none; background: #7a6a48; }
  html body:not(.inbattle) #side > #army .sdeco .mlr.pos .mlbar s { background: linear-gradient(#a8f0a8, #3f9a48); box-shadow: 0 0 5px rgba(120, 230, 130, .6); }
  html body:not(.inbattle) #side > #army .sdeco .mlr.neg .mlbar s { background: linear-gradient(#ffb0a0, #b0382a); box-shadow: 0 0 5px rgba(255, 110, 90, .6); }
}
@media (min-width: 761px) and (min-height: 541px) {
  html body:not(.inbattle) #side > #army .sdeco.ml { padding: 6px 8px; }
  html body:not(.inbattle) #side > #army .sdeco .mle { font-size: 18px; } html body:not(.inbattle) #side > #army .sdeco .mlr b { font-size: 18px; } html body:not(.inbattle) #side > #army .sdeco .mlbar { height: 5px; }
}
@media (orientation: landscape) and (max-height: 330px) {
  html body:not(.inbattle) #side > #hero .hcls { display: none !important; }
  html body:not(.inbattle) #side > #hero .hhead { padding: 0 6px !important; }
  html body:not(.inbattle) #side > #hero .hname { font-size: 11px !important; }
  html body:not(.inbattle) #side > #hero .hbar { display: none !important; }
}
/* the map HUD already fits the screen height, so the "Interface size" zoom must not stack on top of it (it made the column taller than its space) */
@media (orientation: landscape) and (max-height: 540px) { html body:not(.inbattle) #top, html body:not(.inbattle) #side, html body:not(.inbattle) #mbar { zoom: 1 !important; } }

/* morale and luck as icons (js/moods.js): 1-3 icons for how strong, tint and shape for good / bad */
.mood { display: inline-flex; align-items: center; gap: 2px; vertical-align: middle; line-height: 1; cursor: help; }
.mood i { display: inline-flex; width: 1.2em; height: 1.2em; font-style: normal; transition: transform .25s, filter .25s; }
.mood i .gi { width: 100%; height: 100%; }
.mood em { margin-left: 4px; font-style: normal; font-size: .9em; letter-spacing: .3px; color: #e9dcb4; }
.mood.lv-n0 i { filter: grayscale(1) brightness(.95); opacity: .6; }
.mood.lv-g1 i { filter: saturate(1.15) drop-shadow(0 0 2px rgba(130, 230, 140, .65)); }
.mood.lv-g2 i { filter: saturate(1.35) drop-shadow(0 0 3px rgba(110, 235, 130, .9)); }
.mood.lv-g3 i { filter: saturate(1.6) brightness(1.12) drop-shadow(0 0 4px rgba(255, 214, 90, 1)); animation: moodGlow 2.6s ease-in-out infinite alternate; }
.mood.lv-b1 i, .mood.lv-b2 i, .mood.lv-b3 i { filter: sepia(1) hue-rotate(-48deg) saturate(3) brightness(.82) drop-shadow(0 0 2px rgba(255, 90, 70, .6)); }
.mood.lv-b3 i { filter: sepia(1) hue-rotate(-55deg) saturate(3.4) brightness(.62) drop-shadow(0 0 4px rgba(255, 70, 50, .9)); }
.mood.k-morale[class*="lv-b"] i { transform: rotate(180deg); }                       /* a frown */
.mood.k-luck[class*="lv-b"] i { transform: rotate(180deg) scaleX(-1); }              /* a wilted, upside-down clover */
.mood.lv-g1 em { color: #a6ecaa; } .mood.lv-g2 em { color: #8fe08f; } .mood.lv-g3 em { color: #ffd86a; }
.mood.lv-b1 em, .mood.lv-b2 em { color: #ffb3a8; } .mood.lv-b3 em { color: #ff8a78; } .mood.lv-n0 em { color: #b8a67a; }
@keyframes moodGlow { from { filter: saturate(1.5) brightness(1.05) drop-shadow(0 0 3px rgba(255, 214, 90, .8)); } to { filter: saturate(1.7) brightness(1.2) drop-shadow(0 0 6px rgba(255, 224, 120, 1)); } }
@media (prefers-reduced-motion: reduce) { .mood.lv-g3 i { animation: none; } }
/* the spare army cell: two rows, one for morale and one for luck */
html body:not(.inbattle) #side > #army .sdeco.ml { display: flex !important; flex-direction: column; align-items: center; justify-content: space-evenly; padding: 2px 3px; }
html body:not(.inbattle) #side > #army .sdeco.ml .mood { font-size: 12px; }
@media (min-width: 761px) and (min-height: 541px) { html body:not(.inbattle) #side > #army .sdeco.ml .mood { font-size: 18px; gap: 3px; } }
.hmood .mood { margin-right: 6px; }
/* the morale / luck cell everywhere (army sheet on phones, town, ...): a dark plate instead of the old shield */
.sdeco.ml { display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; gap: 2px; padding: 4px; border-radius: 9px; background: radial-gradient(ellipse at 50% 0, rgba(255, 224, 150, .16), transparent 70%), linear-gradient(#2e2114, #130c06) !important; border: 1px solid #8c6a22; box-shadow: inset 0 0 0 1px #0d0803, inset 0 1px 0 2px rgba(255, 225, 160, .12); }
.sdeco.ml .mood { font-size: 18px; gap: 3px; }
/* Scenarios reuse the hero-select structure; keep their bottom bar (Back / Choose your castle) pinned on a phone held upright */
@media (max-width: 760px) and (orientation: portrait) {
  body:has(#title:not(.hide)) #mbox:has(.scnpan) { display: block !important; min-height: 0 !important; }
  body:has(#title:not(.hide)) #mbox:has(.scnpan) > .setup { display: block !important; }
  body:has(#title:not(.hide)) .setup:has(.scnpan) > .mb { position: sticky !important; bottom: -12px; margin-top: 12px !important; z-index: 3; }
}

/* resource chips: the "+income" next to an amount stays inside its plate - chips never shrink below their content; on a very narrow strip the small +income is dropped (it is still in the tooltip and the income line) */
@media (min-width: 700px), (orientation: portrait) {
  html body #top #res .chip, html body #modal #mres .chip { flex: 1 0 auto !important; min-width: min-content !important; overflow: hidden; }
  html body #top #res .chip small.inc, html body #modal #mres .chip small.inc { margin-left: 1px !important; letter-spacing: -.2px; }
}
@media (max-width: 699px) and (orientation: landscape) { html body #top #res .chip small.inc { display: none !important; } html body #top #res .chip { overflow: hidden; } }
/* narrow phone landscape (about 560-700px): the resources get the room - sun orb off, date and mission chip smaller, chips tight, so no amount is cut */
@media (max-width: 699px) and (orientation: landscape) and (max-height: 540px) {
  html body:not(.inbattle) #top #orb { display: none !important; }
  html body:not(.inbattle) #top #res { flex: 1 1 auto !important; min-width: 0; }
  html body:not(.inbattle) #top #res .chip { flex: 1 1 auto !important; min-width: min-content !important; padding: 0 3px !important; gap: 1px !important; font-size: 10px !important; }
  html body:not(.inbattle) #top #res .chip b { font-size: 10px !important; }
  html body:not(.inbattle) #top #res .chip .gi { width: 12px !important; height: 12px !important; }
  html body:not(.inbattle) #top #date { transform-origin: left center; font-size: 9px !important; }
  html body:not(.inbattle) #top #date * { font-size: inherit !important; letter-spacing: 0 !important; }
  html body:not(.inbattle) #top #msChip { padding: 0 4px !important; }
  html body:not(.inbattle) #top #date .dtDiff, html body:not(.inbattle) #top #date .dtTurn { display: none !important; }
}
@media (min-width: 700px) { html body:not(.inbattle) #top #res { flex: 1 1 auto !important; min-width: 0; } }
@media (min-width: 700px) and (max-width: 1500px) and (min-height: 541px) { html body:not(.inbattle) #top #res { gap: 3px !important; } html body:not(.inbattle) #top #res .chip { padding: 0 6px !important; gap: 3px !important; font-size: 12px !important; } html body:not(.inbattle) #top #res .chip b { font-size: 12px !important; } html body:not(.inbattle) #top #res .chip small.inc { font-size: 9px !important; } }

/* Melton Games: intro over the loader, and the small studio mark on the title screen (cropped out of the logo picture) */
#studio { position: fixed; inset: 0; z-index: 100000; background: #100b06; display: flex; align-items: center; justify-content: center; transition: opacity .6s; }
#studio video { width: 100%; height: 100%; object-fit: contain; background: #100b06; }
.studio-mark { position: absolute; left: 50%; bottom: calc(var(--sab, 0px) + 8px); width: clamp(120px, 30vmin, 210px); aspect-ratio: 1665 / 949; transform: translateX(-50%); background: url(brand/melton-mark.webp) center / contain no-repeat; filter: drop-shadow(0 0 5px #000) drop-shadow(0 0 9px #000) drop-shadow(0 2px 3px #000); pointer-events: none; }
@media (orientation: landscape) and (max-height: 540px) { .studio-mark { left: calc(var(--sal, 0px) + 10px); bottom: calc(var(--sab, 0px) + 8px); transform: none; width: clamp(96px, 20vw, 140px); } }
