/* Realm & Province */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --parch: #d8a05c;
  --parch-dark: #8a5a28;
  --ink: #2a1c10;
  --bg: #100c14;
  --panel: #1c1622;
  --panel-edge: #3a2e4a;
  --text: #e8dcc8;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Courier New", ui-monospace, monospace;
  overflow: hidden;
}
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }
.dim { color: #9a8fa8; font-style: normal; }
button { font-family: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

.title-bg {
  position: absolute; inset: 0;
  background: url("../assets/ui/title_bg.png") center/cover no-repeat;
  image-rendering: pixelated;
  filter: saturate(1.05);
}
.title-bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(10,6,16,.25) 40%, rgba(10,6,16,.88) 100%);
}
.title-bg.dim::after { background: rgba(10,6,16,.82); }

.title-inner, .fs-inner, .credits-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 26px; padding: 24px;
}

.game-title { text-align: center; }
.gt-small { letter-spacing: 4px; font-size: 13px; color: #cdbf9a; text-transform: uppercase; }
.game-title h1 {
  font-size: clamp(40px, 7vw, 84px);
  color: #f4e3b2;
  text-shadow: 0 4px 0 #4a2c10, 0 8px 24px rgba(0,0,0,.8);
  letter-spacing: 2px;
}
.game-title .amp { color: #d04a32; }

.title-menu { display: flex; flex-direction: column; gap: 12px; min-width: 300px; }
.title-foot { position: absolute; bottom: 16px; font-size: 12px; color: #b8a888; }

.mbtn {
  background: linear-gradient(#caa05a, #a87838);
  border: 2px solid #5a3a14;
  border-bottom-width: 4px;
  border-radius: 6px;
  color: #2a1804;
  font-weight: bold;
  font-size: 17px;
  padding: 11px 26px;
  text-shadow: 0 1px 0 rgba(255,255,255,.25);
}
.mbtn:hover:not(:disabled) { filter: brightness(1.12); }
.mbtn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.mbtn.ghost { background: transparent; color: #d8c8a0; border-color: #8a7448; }
.mbtn.danger { background: linear-gradient(#c05a4a, #8c3424); color: #ffe; border-color: #4a1408; }

.screen-head {
  font-size: 30px; color: #f4e3b2; letter-spacing: 2px;
  text-shadow: 0 3px 0 #3a2208, 0 6px 16px rgba(0,0,0,.7);
}

/* faction select */
.faction-cards { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.fcard {
  width: 250px; padding: 16px 14px 14px;
  background: rgba(26,20,34,.92);
  border: 2px solid #4a3c5a; border-radius: 10px;
  text-align: center; cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  display: flex; flex-direction: column; gap: 9px; align-items: center;
}
.fcard:hover { transform: translateY(-4px); }
.fcard.sel { border-color: var(--fc); box-shadow: 0 0 18px -2px var(--fc); }
.fc-ribbon {
  width: 192px; height: 56px;
  background-size: 100% 100%; image-rendering: pixelated;
  display: flex; align-items: center; justify-content: center;
}
.fc-ribbon span { font-weight: bold; font-size: 16px; color: #fff; text-shadow: 0 2px 2px rgba(0,0,0,.6); margin-top: -6px; }
.fc-castle { height: 84px; }
.fc-name { font-size: 17px; font-weight: bold; color: var(--fc); }
.fc-units { display: flex; gap: 6px; justify-content: center; }
.fc-blurb { font-size: 12.5px; color: #cabfae; line-height: 1.45; min-height: 54px; }
.fc-perk { font-size: 12.5px; color: #ffd34d; }

.usprite { display: inline-block; overflow: hidden; position: relative; }
.usprite img { position: absolute; left: 0; top: 0; }

.diff-row { display: flex; align-items: center; gap: 14px; }
.diff-label { color: #cdbf9a; letter-spacing: 2px; }
.dbtn {
  background: #241c30; color: #c8bcd8; border: 2px solid #4a3c5a;
  border-radius: 6px; padding: 7px 16px; font-size: 14px;
}
.dbtn.sel { background: #caa05a; color: #241404; border-color: #f4e3b2; font-weight: bold; }
.fs-actions { display: flex; gap: 14px; }

.credits-box {
  max-width: 560px; background: rgba(26,20,34,.92);
  border: 2px solid #4a3c5a; border-radius: 10px;
  padding: 26px 30px; line-height: 1.7; font-size: 15px;
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------------------------------------------------------------- game */
#screen-game { background: #0d0a12; }
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px;
  background: linear-gradient(#241c30, #18121f);
  border-bottom: 2px solid #3a2e4a;
  flex: 0 0 auto;
}
.tb-left { display: flex; gap: 18px; align-items: center; font-size: 15px; }
.tb-item b { color: #ffd34d; }
.tb-item.gold b { color: #ffd34d; }
.tb-chip {
  padding: 4px 12px; border-radius: 5px; border: 2px solid;
  font-weight: bold; font-size: 14px; color: #fff;
}
.tb-right { display: flex; gap: 10px; }

.sbtn {
  background: #2e2440; color: #d8cce8; border: 2px solid #4e3e66;
  border-radius: 5px; padding: 6px 14px; font-size: 14px;
}
.sbtn:hover:not(:disabled) { background: #3a2e52; }
.sbtn.primary {
  background: linear-gradient(#caa05a, #a87838);
  color: #241404; border-color: #5a3a14; font-weight: bold;
}
.sbtn.primary:hover:not(:disabled) { filter: brightness(1.1); background: linear-gradient(#caa05a, #a87838); }

#gamebody { display: flex; flex: 1 1 auto; min-height: 0; }
#mapwrap {
  position: relative; flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at center, #1a2c4e 0%, #11203c 60%, #0c1830 100%);
  overflow: hidden;
  padding: 6px;
}
#map {
  max-width: 100%; max-height: 100%;
  aspect-ratio: 16/9;
  border: 3px solid #3a2e4a; border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
  cursor: pointer;
}
#army-layer {
  position: absolute; inset: 0; pointer-events: none;
}
.army-marker {
  position: absolute; width: 34px; height: 34px;
  margin-left: -34px; margin-top: -8px;
  overflow: hidden; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.7));
}
.army-marker img { position: absolute; left: 0; top: 0; }

#tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  background: rgba(16,12,22,.94); border: 1px solid #5a4a74;
  border-radius: 6px; padding: 8px 11px; font-size: 13px; line-height: 1.5;
  max-width: 220px;
}
#phase-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(16,12,22,.92); border: 2px solid; border-radius: 8px;
  padding: 8px 22px; font-size: 16px; font-weight: bold; z-index: 6;
}

#sidepanel {
  flex: 0 0 330px; display: flex; flex-direction: column;
  background: var(--panel); border-left: 2px solid var(--panel-edge);
  min-height: 0;
}
#sp-content { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
.sp-hint h3 { color: #f4e3b2; margin-bottom: 10px; }
.sp-hint p { font-size: 13.5px; line-height: 1.6; margin-bottom: 10px; }
.sp-head { border-left: 4px solid var(--fc); padding-left: 10px; margin-bottom: 12px; }
.sp-head h3 { color: #f4e3b2; font-size: 19px; }
.sp-sub { font-size: 13px; margin-top: 3px; }
.sp-sec {
  margin: 13px 0 7px; font-size: 12px; letter-spacing: 2px;
  text-transform: uppercase; color: #b8a888;
  border-bottom: 1px solid #3a2e4a; padding-bottom: 3px;
}
.sp-row { font-size: 13.5px; padding: 3px 0; }
.unit-row { display: flex; align-items: center; gap: 8px; }
.ur-name { flex: 1 1 auto; line-height: 1.3; }
.ur-stat { color: #c8a8ff; font-size: 12.5px; }
.ur-count { font-weight: bold; }
.sp-actions { margin-top: 12px; display: flex; flex-direction: column; gap: 9px; }
.sp-hintline { font-size: 12.5px; color: #b8acc8; line-height: 1.5; }
.buy { padding: 4px 10px; font-weight: bold; color: #ffd34d; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper b { min-width: 16px; text-align: center; }
.step {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid #5a4a74;
  background: #2e2440; color: #fff; font-size: 14px; line-height: 1;
}

#logfeed {
  flex: 0 0 168px; overflow-y: auto;
  border-top: 2px solid var(--panel-edge);
  padding: 9px 12px; font-size: 12.5px; line-height: 1.55;
  background: #161020;
}
.logline { margin-bottom: 3px; }
.logline .lt { color: #7a6f8a; margin-right: 5px; }

/* ---------------------------------------------------------------- battle */
#battle-modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(6,4,10,.86);
  display: flex; align-items: center; justify-content: center;
}
#battle-frame {
  background: var(--panel); border: 3px solid #4e3e66; border-radius: 10px;
  padding: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.8);
  max-width: 1010px; width: 96vw;
}
#battle-head {
  display: flex; align-items: center; gap: 16px;
  padding: 2px 4px 10px;
}
#bt-title { font-weight: bold; font-size: 17px; color: #f4e3b2; }
#bt-mod { font-size: 12.5px; color: #c8a8ff; flex: 1 1 auto; }
.bt-controls { display: flex; gap: 8px; }
#battle-stage {
  position: relative; width: 100%; aspect-ratio: 16/9;
  border: 2px solid #3a2e4a; border-radius: 6px; overflow: hidden;
  background: #000;
}
#battle-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#battle-units, #battle-fx { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; }

.bunit { position: absolute; width: 60px; height: 60px; transition: left .3s linear, top .3s linear; }
.bunit-gfx { position: absolute; inset: 0; overflow: hidden; }
.bunit-gfx.flip { transform: scaleX(-1); }
.bunit-img { position: absolute; left: 0; }
.bunit.hurt { filter: brightness(2.4) saturate(.4); }
.bunit.dying { opacity: 0; transition: opacity .6s; }
.hpbar {
  position: absolute; left: 9px; right: 9px; bottom: -5px; height: 5px;
  background: rgba(0,0,0,.72); border-radius: 2px; overflow: hidden;
}
.hpfill { height: 100%; transition: width .2s; }
.hpfill.att { background: #5ad05a; }
.hpfill.def { background: #e0b03a; }

.float {
  position: absolute; font-weight: bold; font-size: 17px;
  color: #ff6a5a; text-shadow: 0 2px 2px #000;
  animation: floatup .85s ease-out forwards; pointer-events: none;
}
.float.heal { color: #6ae07a; }
@keyframes floatup { to { transform: translateY(-30px); opacity: 0; } }

.projectile {
  position: absolute; width: 9px; height: 4px; border-radius: 2px;
  background: #ffe9a0; box-shadow: 0 0 6px #ffd34d;
  transition: left .22s linear, top .22s linear;
}

#battle-result {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(8,5,12,.72);
  display: flex; flex-direction: column; gap: 18px;
  align-items: center; justify-content: center;
}
#br-text {
  font-size: 26px; font-weight: bold; color: #f4e3b2;
  text-shadow: 0 3px 0 #000, 0 6px 18px #000;
}
#battle-rosters {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 9px 4px 2px; font-size: 12.5px; color: #b8acc8;
}
.br-side { max-width: 48%; }

/* menus */
#menu-modal, #end-modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(6,4,10,.8);
  display: flex; align-items: center; justify-content: center;
}
.menu-box {
  background: var(--panel); border: 3px solid #4e3e66; border-radius: 10px;
  padding: 30px 36px; display: flex; flex-direction: column; gap: 13px;
  min-width: 360px; max-width: 460px; text-align: center;
}
.menu-box h3 { color: #f4e3b2; font-size: 22px; margin-bottom: 6px; }
.menu-box p { font-size: 14.5px; line-height: 1.6; color: #cabfae; }

@media (max-width: 980px) {
  #sidepanel { flex-basis: 270px; }
  .tb-left { gap: 10px; font-size: 13px; }
}
