@font-face { font-family: "Inscribe"; src: url("assets/fonts/Cinzel.ttf") format("truetype"); font-weight: 400 900; font-display: swap; }
@font-face { font-family: "Round"; src: url("assets/fonts/Nunito.ttf") format("truetype"); font-weight: 200 1000; font-display: swap; }

:root {
  --cream: #EFE3C8;
  --line: #6B4A2E;
  --ink: #3A2718;
  --red: #B23A2E;
  --s: 1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9b98a; color: var(--ink); font-family: "Round", "Nunito", system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.tile {
  background: var(--cream) url("assets/img/tablet.webp");
  background-size: 256px;
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: 3px 4px 0 rgba(58, 39, 24, .45), inset 0 0 0 2px rgba(255, 250, 235, .55), inset 0 0 0 3px rgba(107, 74, 46, .25);
  color: var(--ink);
}
button { font: inherit; color: inherit; cursor: pointer; }

#vignette { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(150, 92, 40, .75) 100%); }
#vignette.on { opacity: 1; animation: dry 2.4s ease-in-out infinite; }
@keyframes dry { 50% { opacity: .6; } }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

/* bars */
#bars { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 7px; width: min(330px, 46vw); }
.bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; height: 42px; }
.bar img { width: 30px; height: 30px; object-fit: contain; flex: none; }
.groove { position: relative; flex: 1; height: 16px; border-radius: 8px; background: #d9c8a3; box-shadow: inset 1px 2px 2px rgba(58,39,24,.45); border: 1px solid #8a6a48; overflow: hidden; }
.groove .fill, .groove .ghost { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; border-radius: 7px; }
#hpbar .fill { background: linear-gradient(#cf463a, #B8322A 60%, #93251e); }
#hpbar .ghost { background: #e9a08f; transition: width 1.2s ease-in .25s; }
#hgbar .fill { background: linear-gradient(#e7a94a, #D9922B 60%, #b8761b); }
.num { font-weight: 800; font-size: 16px; min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
#hpbar.flash { animation: flash .35s 2; }
@keyframes flash { 50% { background-color: #f3b3a0; transform: translateX(2px); } }
#hgbar.low .fill { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.35); } }

/* resources */
#res { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: max(calc(50% - 175px), 356px); display: flex; gap: 8px; }
.chip { display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; height: 40px; font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; min-width: 84px; }
.chip img { width: 28px; height: 28px; object-fit: contain; }
.chip.bump { animation: bump .3s; }
@keyframes bump { 50% { transform: translateY(-3px) scale(1.06); } }

.round { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-family: "Inscribe", serif; font-weight: 800; font-size: 20px; padding: 0; }
#helpbtn { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }

/* minimap */
#minimap { position: absolute; left: calc(8px + env(safe-area-inset-left)); bottom: calc(8px + env(safe-area-inset-bottom)); width: 200px; height: 200px; }
#mm { position: absolute; left: 9%; top: 9%; width: 82%; height: 82%; border-radius: 50%; }
#minimap .rim { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#overbtn { position: absolute; right: -4px; bottom: 6px; }
#overbtn.on { background-color: #e6b8a6; }

/* notes */
#notes { position: absolute; left: calc(210px + (100% - 580px) / 2); bottom: calc(122px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.note { display: flex; align-items: center; gap: 10px; padding: 8px 18px 8px 10px; font-weight: 800; font-size: 16px; border-left: 8px solid var(--red); border-right: 8px solid var(--red); animation: slide .35s ease-out; white-space: nowrap; }
.note img { width: 30px; height: 30px; object-fit: contain; }
.note.out { animation: fade .5s forwards; }
@keyframes slide { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { to { transform: translateY(-10px); opacity: 0; } }

#prompt { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); padding: 6px 14px; font-weight: 800; font-size: 15px; pointer-events: none; opacity: .92; }

/* actions */
#actions { position: absolute; right: calc(372px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: flex-end; }
.act { width: 76px; height: 76px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; font-weight: 900; font-size: 13px; position: relative; transition: transform .06s, box-shadow .06s; }
.act img { width: 34px; height: 34px; object-fit: contain; }
.act kbd { position: absolute; top: -6px; right: -4px; background: var(--line); color: var(--cream); font: 700 10px "Round", sans-serif; padding: 2px 5px; border-radius: 6px; }
.act:active, .act.down, .cbtn:active, .cbtn.down { transform: translate(2px, 3px); box-shadow: 1px 1px 0 rgba(58,39,24,.45), inset 0 2px 4px rgba(58,39,24,.35); }
#b-act { width: 92px; height: 92px; }
#b-act img { width: 44px; height: 44px; }

/* panel */
#panelbtn { position: absolute; right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); font-family: "Inscribe", serif; font-weight: 800; letter-spacing: .18em; padding: 10px 16px; display: none; }
#panel { position: absolute; right: calc(10px + env(safe-area-inset-right)); top: 64px; bottom: calc(10px + env(safe-area-inset-bottom)); width: 350px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.ptitle { display: flex; justify-content: center; position: relative; }
h1, h2, h3, h4 { font-family: "Inscribe", "Trajan Pro", Georgia, serif; text-transform: uppercase; letter-spacing: .14em; margin: 0; font-weight: 800; }
h2 { font-size: 24px; letter-spacing: .22em; }
#panelclose { position: absolute; right: 0; top: -4px; background: none; border: 0; font-size: 28px; line-height: 1; display: none; }
.tabs { display: flex; gap: 4px; }
.tab { flex: 1; padding: 8px 2px; border: 2px solid var(--line); border-radius: 7px; background: rgba(255,250,235,.5); font: 800 12px "Round", sans-serif; letter-spacing: .05em; }
.tab.on { background: var(--red); color: #f7e9d2; box-shadow: inset 0 2px 3px rgba(0,0,0,.3); }
.pane { display: flex; flex-direction: column; gap: 7px; overflow-y: auto; min-height: 0; flex: 1; padding: 2px 4px 4px 0; }
.card { display: flex; gap: 10px; align-items: center; border: 1.5px solid #a98a63; border-radius: 8px; padding: 8px; background: rgba(255,250,235,.45); }
.card > img { width: 96px; object-fit: contain; }
.card h3 { font-size: 16px; margin-bottom: 2px; }
.stat { display: flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 700; }
.stat img { width: 16px; height: 16px; object-fit: contain; }
.stat b { margin-left: auto; font-weight: 900; }
.cbtn { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; border: 2px solid var(--line); border-radius: 10px; background: #f4ead4; box-shadow: 2px 3px 0 rgba(58,39,24,.45); transition: transform .06s, box-shadow .06s, opacity .2s; min-height: 58px; }
.cbtn > img { width: 40px; height: 40px; object-fit: contain; flex: none; }
.cbtn h4 { font-size: 15px; letter-spacing: .1em; }
.cbtn .sub { font-size: 13px; font-weight: 700; opacity: .85; }
.cost { display: flex; gap: 10px; font-size: 14px; font-weight: 800; }
.cost span { display: inline-flex; align-items: center; gap: 3px; }
.cost img { width: 16px; height: 16px; object-fit: contain; }
.cost .short { color: #a3291f; }
.cbtn.poor { opacity: .62; }
.rival { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1.5px solid #a98a63; border-radius: 8px; background: rgba(255,250,235,.45); border-left-width: 8px; }
.rival.sel { outline: 2px solid var(--ink); background: rgba(255,250,235,.85); }
.rival h4 { font-size: 14px; }
.rival .sub { font-size: 13px; font-weight: 700; }
.rival button { margin-left: auto; padding: 6px 10px; border: 2px solid var(--line); border-radius: 8px; background: #f4ead4; font-weight: 800; font-size: 12px; }

/* overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(90, 50, 20, .25); padding: 12px; z-index: 5; }
.big { max-width: 560px; width: 100%; padding: 22px 24px; text-align: center; max-height: 100%; overflow-y: auto; }
.big h1 { font-size: clamp(26px, 6vw, 42px); letter-spacing: .2em; color: var(--red); text-shadow: 1px 1px 0 #6B4A2E44; }
.lead { font-size: 16px; font-weight: 700; margin: 10px 0 12px; }
.how { list-style: none; padding: 0; margin: 0 0 14px; text-align: left; display: grid; gap: 6px; }
.how li { display: grid; grid-template-columns: 74px 1fr; gap: 8px; font-size: 14px; font-weight: 600; }
.how b { font-family: "Inscribe", serif; letter-spacing: .08em; text-transform: uppercase; }
.k-touch { display: none; }
body.touch .k-touch { display: inline; } body.touch .k-desk { display: none; }
.start { margin: 0 auto; justify-content: center; min-width: 220px; background: var(--red); color: #f7e9d2; }
.start h4 { font-size: 18px; }
#board { text-align: left; font-weight: 700; font-size: 14px; max-height: 160px; overflow: auto; }
#board a { color: var(--ink); }

/* touch: no key hints */
body.touch .act kbd { display: none; }

/* -------- adaptive layouts -------- */
/* short or narrow screens: panel becomes a drawer */
@media (max-width: 980px), (max-height: 640px) {
  #panelbtn { display: block; }
  #panel { display: none; }
  #panel.open { display: flex; z-index: 3; }
  #panelclose { display: block; }
  #actions { right: calc(12px + env(safe-area-inset-right)); bottom: calc(64px + env(safe-area-inset-bottom)); }
  #notes { left: calc(50% - 50px); bottom: calc(14px + env(safe-area-inset-bottom)); }
}
@media (max-height: 640px) {
  #panel { top: 8px; width: min(350px, 60vw); }
  .bar { height: 34px; padding: 3px 10px 3px 6px; } .bar img { width: 24px; height: 24px; }
  .chip { height: 34px; font-size: 15px; min-width: 70px; } .chip img { width: 22px; height: 22px; }
  #minimap { width: 140px; height: 140px; }
  .act { width: 62px; height: 62px; font-size: 11px; } .act img { width: 28px; height: 28px; }
  #b-act { width: 76px; height: 76px; }
  #notes { top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .note { font-size: 14px; padding: 5px 14px 5px 8px; }
}
/* portrait phones */
@media (max-width: 640px) {
  #bars { width: calc(100vw - 72px); }
  #res { top: calc(102px + env(safe-area-inset-top)); left: 10px; transform: none; right: 10px; gap: 5px; }
  .chip { min-width: 0; flex: 1; padding: 3px 8px 3px 4px; height: 34px; font-size: 15px; } .chip img { width: 22px; height: 22px; }
  #minimap { width: 132px; height: 132px; bottom: calc(66px + env(safe-area-inset-bottom)); }
  #panel { left: 8px; right: 8px; width: auto; top: auto; height: 68%; bottom: 8px; }
  #panelbtn { left: 10px; right: auto; }
  #actions { flex-direction: column-reverse; align-items: flex-end; bottom: calc(66px + env(safe-area-inset-bottom)); }
  .act { width: 64px; height: 64px; } #b-act { width: 84px; height: 84px; }
  #notes { top: calc(146px + env(safe-area-inset-top)); bottom: auto; left: 10px; right: 10px; transform: none; align-items: center; }
  .note { white-space: normal; font-size: 14px; }
  #prompt { top: 40%; }
}
@media (max-height: 640px) and (min-width: 641px) {
  #bars { width: min(290px, 31vw); }
  #res { left: calc(min(290px, 31vw) + 22px + env(safe-area-inset-left)); transform: none; }
  .num { font-size: 14px; min-width: 54px; }
}

.act.dim { opacity: .55; }

/* the begin button never scrolls out of reach */
.big .start { position: sticky; bottom: 0; z-index: 1; }
@media (max-height: 520px) {
  .big { padding: 12px 18px; }
  .big h1 { font-size: 26px; }
  .lead { font-size: 14px; margin: 4px 0 6px; }
  .how { gap: 2px; margin-bottom: 8px; }
  .how li { font-size: 13px; }
  .start { min-height: 44px; }
}

/* five action buttons: wrap into two rows on small screens */
.card.small > img { width: 56px; }
@media (max-height: 640px) {
  #actions { flex-wrap: wrap-reverse; justify-content: flex-end; width: 230px; gap: 8px; }
}
@media (max-width: 640px) {
  #actions { flex-direction: row; flex-wrap: wrap-reverse; justify-content: flex-end; width: 150px; gap: 8px; }
  .act { width: 62px; height: 62px; } #b-act { width: 76px; height: 76px; }
}
.act.on { background: #f3d7a0; outline: 3px solid var(--red); }

/* selection and orders */
#selbox { position: fixed; border: 2px solid #fff6dc; background: rgba(255,246,220,.16); box-shadow: 0 0 0 1px rgba(58,39,24,.55); pointer-events: none; z-index: 2; }
#selbar { position: absolute; top: calc(58px + env(safe-area-inset-top)); left: max(calc(50% - 175px), 356px); display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-weight: 800; font-size: 14px; max-width: calc(50vw - 200px); min-width: 0; }
#seltxt { flex: 1; min-width: 0; padding: 0 4px; line-height: 1.15; }
.sbtn { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 9px 0 5px; border: 2px solid var(--line); border-radius: 8px; background: #f4ead4; font: 800 13px "Round", sans-serif; letter-spacing: .04em; text-transform: uppercase; box-shadow: 1px 2px 0 rgba(58,39,24,.4); position: relative; flex: none; }
.sbtn img { width: 24px; height: 24px; object-fit: contain; }
.sbtn kbd { background: var(--line); color: var(--cream); font: 700 10px "Round", sans-serif; padding: 1px 4px; border-radius: 5px; margin-left: 2px; }
body.touch .sbtn kbd { display: none; }
.sbtn:active { transform: translate(1px, 2px); box-shadow: none; }
.sbtn.x { padding: 0 9px; font-size: 20px; display: none; }
#selbar.has .sbtn.x { display: inline-flex; }
#selbar.has #seltxt { color: var(--red); }
@media (max-width: 980px), (max-height: 640px) { #selbar { max-width: calc(100vw - 380px); } }
@media (max-height: 640px) and (min-width: 641px) {
  #selbar { top: calc(56px + env(safe-area-inset-top)); left: calc(min(290px, 31vw) + 22px + env(safe-area-inset-left)); font-size: 13px; }
  .sbtn { height: 30px; } .sbtn img { width: 20px; height: 20px; }
}
@media (max-width: 640px) {
  #selbar { top: calc(142px + env(safe-area-inset-top)); left: 10px; right: 10px; min-width: 0; max-width: none; font-size: 12px; }
  .sbtn { height: 30px; } .sbtn img { width: 20px; height: 20px; }
  #notes { top: calc(186px + env(safe-area-inset-top)); }
}

/* the map pops up big while soldiers or the hero are selected; tap it to send them */
#minimap { transition: width .25s ease, height .25s ease; z-index: 2; }
body.mapbig #minimap { width: min(360px, 52vh, 62vw) !important; height: min(360px, 52vh, 62vw) !important; }
body.mapbig #mm { cursor: crosshair; }
@media (max-width: 640px) { body.mapbig #minimap { width: min(52vw, 300px) !important; height: min(52vw, 300px) !important; } }
