/* Cross-Slash: castle wall, meadow field, parchment tiles, blue = move, red = attack. */

:root {
  --ink: #2a1c12;
  --stone: #5d6169;
  --stone-deep: #34373e;
  --meadow: #74a544;
  --meadow-deep: #3c6620;
  --parchment: #f6e6bd;
  --parchment-deep: #e2c487;
  --move: #3f56b5;
  --move-hi: #6b82e0;
  --move-lo: #2c3d8a;
  --attack: #c93f37;
  --attack-hi: #f06a5f;
  --attack-lo: #8f2722;
  --gold: #f0bd3e;
  --gold-deep: #b07a17;
  --cream: #fff4d6;
  --phase: var(--move);
  --phase-hi: var(--move-hi);
  --phase-lo: var(--move-lo);
  --font-display: 'Grenze Gotisch', 'UnifrakturMaguntia', Georgia, serif;
  --font-ui: 'Alegreya Sans', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  --outline-text: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink),
    1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink),
    0 4px 0 var(--ink);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background-color: #45484f;
  background-image: var(--tex-wall);
  background-size: 448px 336px;
  color: var(--cream);
  font-family: var(--font-ui);
  font-weight: 700;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(130% 95% at 50% 38%, rgba(0, 0, 0, 0) 35%, rgba(12, 9, 7, .62) 100%);
}

#app { position: relative; height: 100%; }
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: stretch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* ------------------------------------------------------------- buttons */
.btn {
  --b-top: #fff6dd;
  --b-bot: #f1d792;
  --b-text: var(--ink);
  --b-ledge: var(--ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45em;
  min-height: 46px;
  padding: .55em 1.05em;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(var(--b-top), var(--b-bot));
  color: var(--b-text);
  font: 800 1.05rem/1 var(--font-ui);
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--b-ledge), inset 0 2px 0 rgba(255, 255, 255, .65), inset 0 -3px 0 rgba(0, 0, 0, .12);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease, opacity .2s;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--b-ledge), inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -2px 0 rgba(0, 0, 0, .12); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn:disabled { opacity: .45; cursor: default; filter: saturate(.4); transform: none; box-shadow: 0 4px 0 var(--b-ledge); }
.btn .ico { width: 1.25em; height: 1.25em; flex: none; }
.btn-ico { display: inline-flex; }

.btn-primary { --b-top: #6c84e4; --b-bot: #3a50ad; --b-text: var(--cream); text-shadow: 0 2px 0 rgba(20, 20, 60, .55); }
.btn-attack { --b-top: #f2766b; --b-bot: #b8342d; --b-text: var(--cream); text-shadow: 0 2px 0 rgba(60, 10, 10, .55); }
.btn-dark { --b-top: #4e525b; --b-bot: #34373e; --b-text: var(--cream); box-shadow: 0 4px 0 var(--ink), inset 0 2px 0 rgba(255, 255, 255, .14), inset 0 -3px 0 rgba(0, 0, 0, .2); }
.btn-lg { min-height: 56px; font-size: 1.2rem; padding: .6em 1.4em; border-radius: 16px; }
.btn-sm { min-height: 40px; font-size: .98rem; padding: .45em .9em; border-radius: 12px; }
.btn-icon { width: 46px; padding: 0; border-radius: 50%; }
.btn-icon .ico { width: 24px; height: 24px; }

/* ------------------------------------------------------------- topbar + ribbon */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 0;
  position: relative;
  z-index: 3;
}
.topbar > :first-child { justify-self: start; }
.topbar-right { justify-self: end; display: flex; gap: 8px; }

.ribbon {
  position: relative;
  width: clamp(200px, 36vw, 340px);
  aspect-ratio: 420 / 96;
  display: grid;
  place-items: center;
  color: var(--phase);
  transition: color .5s ease;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, .28));
}
.ribbon .ribbon-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ribbon > span {
  position: relative;
  margin-top: -5%;
  font: 900 clamp(1.35rem, 3.4vw, 2.05rem)/1 var(--font-display);
  color: var(--cream);
  text-shadow: var(--outline-text);
  white-space: nowrap;
}

/* ------------------------------------------------------------- title screen */
#screen-title { align-items: center; justify-content: center; overflow: hidden; }
.title-top { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); right: 14px; z-index: 3; }
.flag { position: absolute; top: 3vh; width: clamp(110px, 13vw, 190px); pointer-events: none; }
.flag svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .4)); }
.flag-left { left: clamp(8px, 3vw, 60px); }
.flag-right { right: clamp(8px, 3vw, 60px); transform: scaleX(-1); }
@media (max-width: 760px) { .flag { width: 84px; top: 1vh; opacity: .9; } }
@media (max-width: 520px) { .flag { display: none; } }

.title-wrap {
  position: relative;
  z-index: 2;
  width: min(760px, 94vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.2vh, 20px);
}
.logo { position: relative; width: 100%; display: grid; place-items: center; }
.logo-text { margin: 0; width: 100%; line-height: 0; position: relative; z-index: 2; }
.logo-text svg { width: 100%; height: auto; overflow: visible; }
.logo-text text { font-family: var(--font-display); font-weight: 900; font-size: 190px; letter-spacing: -2px; }
.logo-face { fill: url(#logo-fill); stroke: var(--ink); stroke-width: 15px; paint-order: stroke; stroke-linejoin: round; }
.logo-shadow { fill: var(--attack-lo); stroke: var(--ink); stroke-width: 15px; paint-order: stroke; stroke-linejoin: round; }
.logo { margin-bottom: clamp(18px, 4vh, 40px); }
.logo-swords { position: absolute; inset: -14% 0 -8%; display: grid; place-items: center; z-index: 1; pointer-events: none; }
.logo-swords svg { position: absolute; height: 128%; width: auto; filter: drop-shadow(0 8px 0 rgba(0, 0, 0, .3)); }
.logo-swords .sword-a { transform: rotate(-48deg); }
.logo-swords .sword-b { transform: rotate(48deg); }

.tagline {
  margin: 0;
  font: 800 clamp(1.1rem, 2.6vw, 1.45rem)/1.2 var(--font-ui);
  color: var(--cream);
  text-shadow: 0 2px 0 var(--ink), 0 0 12px rgba(0, 0, 0, .6);
}
.parade { margin: 0 0 8px; }
.parade .field { --t: clamp(56px, 10vw, 80px); padding: calc(var(--t) * .5) calc(var(--t) * .4) calc(var(--t) * .4); border-radius: calc(var(--t) * .3); }
.menu { display: flex; flex-direction: column; align-items: stretch; gap: 12px; width: min(300px, 80vw); }
.menu .btn { width: 100%; }
#btn-play { flex-direction: column; gap: 2px; }
#btn-play .sub { font-size: .8rem; font-weight: 700; opacity: .85; }
#btn-play .sub:empty { display: none; }

/* ------------------------------------------------------------- level select */
#screen-levels { overflow-y: auto; }
.levels-sub {
  margin: 14px auto 4px;
  font: 700 1.05rem/1.3 var(--font-ui);
  text-align: center;
  color: var(--cream);
  text-shadow: 0 2px 0 var(--ink);
  max-width: 34ch;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 128px));
  justify-content: center;
  gap: 18px 22px;
  padding: 18px 16px 40px;
}
@media (max-width: 720px) { .level-grid { grid-template-columns: repeat(3, minmax(0, 120px)); gap: 14px 16px; } }
@media (max-width: 380px) { .level-grid { grid-template-columns: repeat(2, minmax(0, 132px)); } }

.shield-btn {
  --sh-rim: #c9d1d9;
  --sh-main: var(--move);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  background: none;
  border: none;
  border-radius: 16px;
  color: var(--cream);
  font: inherit;
  cursor: pointer;
}
.shield-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.shield { position: relative; display: block; width: min(104px, 100%); aspect-ratio: 100 / 120; transition: transform .18s cubic-bezier(.3, 1.6, .5, 1); filter: drop-shadow(0 7px 0 rgba(0, 0, 0, .35)); }
.shield svg { width: 100%; height: 100%; display: block; }
.shield-num {
  position: absolute;
  inset: 0 0 12% 0;
  display: grid;
  place-items: center;
  font: 900 2rem/1 var(--font-display);
  color: var(--cream);
  text-shadow: var(--outline-text);
}
.shield-badge, .shield-lock { position: absolute; display: grid; place-items: center; }
.shield-badge { right: -4px; top: -6px; width: 34px; height: 34px; }
.shield-badge .ico { width: 100%; height: 100%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .35)); }
.shield-lock { inset: 0 0 12% 0; color: #c8ccd2; }
.shield-lock .ico { width: 40%; height: auto; }
.shield-btn:not(:disabled):hover .shield { transform: translateY(-5px) rotate(-3deg); }
.shield-btn.done { --sh-rim: var(--gold); }
.shield-btn.next .shield { animation: shieldGlow 1.8s ease-in-out infinite; }
.shield-btn.locked { --sh-rim: #6a6e76; --sh-main: #3e4148; cursor: not-allowed; }
.shield-btn.locked .shield-num { display: none; }
.shield-btn.locked .shield-stats { opacity: .45; }
@keyframes shieldGlow {
  0%, 100% { filter: drop-shadow(0 7px 0 rgba(0, 0, 0, .35)) drop-shadow(0 0 0 rgba(240, 189, 62, 0)); }
  50% { filter: drop-shadow(0 7px 0 rgba(0, 0, 0, .35)) drop-shadow(0 0 14px rgba(255, 210, 90, .85)); }
}
.shield-stats { display: flex; gap: 6px; }
.st {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px 3px 5px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font: 800 .95rem/1 var(--font-ui);
  color: var(--cream);
  box-shadow: 0 2px 0 var(--ink);
}
.st .ico { width: 18px; height: 18px; }
.st-move { background: linear-gradient(#5b72d1, #3346a0); }
.st-attack { background: linear-gradient(#e05a50, #a8302a); }

/* ------------------------------------------------------------- game screen */
#screen-game { overflow: hidden; }
.phase-glow { position: absolute; inset: 0; pointer-events: none; }
.phase-glow::before, .phase-glow::after {
  content: '';
  position: absolute;
  inset: 0;
  transition: opacity .7s ease;
}
.phase-glow::before { background: radial-gradient(70% 55% at 50% 48%, rgba(80, 110, 230, .28), rgba(0, 0, 0, 0) 70%); }
.phase-glow::after { background: radial-gradient(70% 55% at 50% 48%, rgba(240, 70, 50, .3), rgba(0, 0, 0, 0) 70%); opacity: 0; }
#screen-game[data-phase="attack"], #screen-game[data-phase="won"], #screen-game[data-phase="lost"] {
  --phase: var(--attack); --phase-hi: var(--attack-hi); --phase-lo: var(--attack-lo);
}
#screen-game[data-phase="attack"] .phase-glow::before, #screen-game[data-phase="won"] .phase-glow::before, #screen-game[data-phase="lost"] .phase-glow::before { opacity: 0; }
#screen-game[data-phase="attack"] .phase-glow::after, #screen-game[data-phase="won"] .phase-glow::after, #screen-game[data-phase="lost"] .phase-glow::after { opacity: 1; }

.hud { display: flex; justify-content: center; gap: 14px; padding: 8px 12px 0; position: relative; z-index: 2; }
.plate {
  --p-top: #5b72d1;
  --p-bot: #3346a0;
  display: flex;
  align-items: center;
  gap: .4em;
  padding: .3em .95em .3em .55em;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(var(--p-top), var(--p-bot));
  color: var(--cream);
  box-shadow: 0 4px 0 var(--ink), inset 0 2px 0 rgba(255, 255, 255, .3);
  transition: transform .35s cubic-bezier(.3, 1.5, .5, 1), filter .35s ease, opacity .35s ease;
}
.plate-attack { --p-top: #e05a50; --p-bot: #a8302a; }
.plate-ico .ico { width: 30px; height: 30px; display: block; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .3)); }
.plate-num { font: 900 2.1rem/1 var(--font-display); min-width: 1.1ch; text-align: center; text-shadow: var(--outline-text); display: inline-block; }
.plate-label { display: flex; flex-direction: column; font: 800 1rem/1.05 var(--font-ui); }
.plate-label small { font: 700 .74rem/1.1 var(--font-ui); opacity: .85; }
#screen-game[data-phase="move"] .plate-attack,
#screen-game[data-phase="ready"] .plate-attack,
#screen-game[data-phase="attack"] .plate-move,
#screen-game[data-phase="won"] .plate-move,
#screen-game[data-phase="lost"] .plate-move { filter: saturate(.25) brightness(.72); transform: scale(.9); }
#screen-game[data-phase="move"] .plate-move,
#screen-game[data-phase="attack"] .plate-attack { transform: scale(1.04); }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 10px 6px;
  position: relative;
  z-index: 1;
}

/* the meadow */
.field {
  --t: 72px;
  position: relative;
  padding: calc(var(--t) * .74) calc(var(--t) * .55) calc(var(--t) * .55);
  border: 4px solid var(--ink);
  border-radius: calc(var(--t) * .34);
  background-color: var(--meadow);
  background-image: radial-gradient(120% 110% at 50% 40%, rgba(255, 255, 220, .12), rgba(20, 50, 10, .22) 80%), var(--tex-grass);
  background-size: auto, 256px 256px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .22),
    inset 0 -14px 30px rgba(20, 50, 10, .3),
    0 10px 0 -2px #2f4d1a,
    0 10px 0 2px var(--ink),
    0 28px 44px rgba(0, 0, 0, .5);
  overflow: hidden;
}

.board {
  --b: 3px;
  position: relative;
  width: calc(var(--W) * var(--t));
  height: calc(var(--H) * var(--t));
  touch-action: none;
  outline: none;
}
#board { cursor: default; }
#board:focus-visible { outline: none; }
#board.kb:focus-visible { outline: 3px dashed rgba(255, 230, 150, .8); outline-offset: calc(var(--t) * .2); border-radius: 8px; }
.layer { position: absolute; inset: 0; }
svg.layer { width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.decor { z-index: 0; pointer-events: none; }
.cliffs { z-index: 1; }
.tiles { z-index: 2; }
.decals { z-index: 3; }
.marks { z-index: 4; pointer-events: none; }
.units { z-index: 5; pointer-events: none; }
.slashes { z-index: 6; }
.floaters { z-index: 7; pointer-events: none; }

.deco {
  position: absolute;
  left: calc(var(--x) * var(--t));
  top: calc(var(--y) * var(--t));
  width: calc(var(--t) * .3 * var(--s));
  transform: translate(-50%, -100%);
}
.deco svg { width: 100%; height: auto; display: block; }
.deco-pebble { width: calc(var(--t) * .26 * var(--s)); }
.deco-mushroom { width: calc(var(--t) * .22 * var(--s)); }

/* tiles */
.tile {
  position: absolute;
  left: calc(var(--c) * var(--t) - var(--b) / 2);
  top: calc(var(--r) * var(--t) - var(--b) / 2);
  width: calc(var(--t) + var(--b));
  height: calc(var(--t) + var(--b));
}
.tile .top {
  position: absolute;
  inset: 0;
  border: var(--b) solid var(--ink);
  background: radial-gradient(130% 100% at 30% 16%, #fff7d9 0%, #f5e0ab 50%, #e5c584 100%);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .6), inset 0 -6px 0 rgba(160, 110, 40, .25), inset 0 0 0 1px rgba(255, 255, 255, .25);
  overflow: hidden;
}
.tile .top::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--tex-paper);
  background-size: 160px 160px;
  mix-blend-mode: multiply;
  opacity: .7;
}
.tile.cross .top {
  background: radial-gradient(130% 100% at 30% 16%, #a3a9b2 0%, #737882 55%, #555962 100%);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .28), inset 0 -6px 0 rgba(0, 0, 0, .25);
}
.tile.cross .top::after { background-image: var(--tex-stone); mix-blend-mode: normal; opacity: .9; }
.tile .x { position: absolute; inset: 6%; transition: filter .3s; }
.tile .x svg { width: 100%; height: 100%; display: block; }
.tile.cross.occupied .x { animation: xPulse 1.3s ease-in-out infinite; }
.tile.flare .x { animation: xFlare .28s ease-in-out 4; }
@keyframes xPulse { 50% { filter: drop-shadow(0 0 calc(var(--t) * .08) #ff4a3a) brightness(1.25); } }
@keyframes xFlare { 50% { filter: drop-shadow(0 0 calc(var(--t) * .2) #ff2a1a) brightness(1.7); transform: scale(1.06); } }

.cliff {
  position: absolute;
  left: calc(var(--c) * var(--t) - var(--b) / 2);
  top: calc((var(--r) + 1) * var(--t) - var(--b) / 2);
  width: calc(var(--t) + var(--b));
  height: calc(var(--t) * .2);
  background: linear-gradient(#b08048, #7d5428 70%, #6a4520);
  border: var(--b) solid var(--ink);
  border-top: none;
  box-shadow: 0 calc(var(--t) * .08) calc(var(--t) * .12) rgba(20, 40, 10, .35);
}
.cliff::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  top: 30%;
  height: 2px;
  background: rgba(0, 0, 0, .18);
  border-radius: 2px;
}
.cliff.cap-l { border-bottom-left-radius: calc(var(--t) * .1); }
.cliff.cap-r { border-bottom-right-radius: calc(var(--t) * .1); }

/* monsters */
.unit {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--t);
  height: var(--t);
  transform: translate(calc(var(--c) * var(--t)), calc(var(--r) * var(--t)));
  pointer-events: none;
}
.unit .shadow {
  position: absolute;
  left: 20%;
  width: 60%;
  bottom: 14%;
  height: 13%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(40, 25, 10, .45), rgba(40, 25, 10, 0));
}
.unit .ring {
  position: absolute;
  left: 10%;
  width: 80%;
  bottom: 9%;
  height: 24%;
  border-radius: 50%;
  border: max(2.5px, calc(var(--t) * .035)) solid #ffd54a;
  box-shadow: 0 0 calc(var(--t) * .12) #ffcf3a, inset 0 0 calc(var(--t) * .08) rgba(255, 213, 74, .7);
  opacity: 0;
  transform: scale(.5);
  transition: opacity .15s ease, transform .25s cubic-bezier(.3, 1.7, .5, 1);
}
.unit.selected .ring { opacity: 1; transform: scale(1); animation: ringPulse 1.1s ease-in-out infinite; }
.unit.kb-target .ring { opacity: .75; transform: scale(.9); border-style: dashed; }
@keyframes ringPulse { 50% { box-shadow: 0 0 calc(var(--t) * .22) #ffd54a, inset 0 0 calc(var(--t) * .1) rgba(255, 213, 74, .9); } }
.unit .sprite { position: absolute; left: 3%; width: 94%; bottom: 17%; height: 94%; transform-origin: 50% 100%; }
.unit.orc .sprite { left: -3%; width: 106%; height: 100%; bottom: 16%; }
.unit .bob { width: 100%; height: 100%; transform-origin: 50% 100%; animation: breathe 2.8s ease-in-out infinite; animation-delay: var(--delay, 0s); }
.unit.selected .bob { animation: hop .62s ease-in-out infinite; }
.unit svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mon .lids { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); animation: blink 5s infinite; animation-delay: var(--blink, 0s); }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(.985, 1.03); } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 40% { transform: translateY(-9%) scale(.96, 1.05); } 70% { transform: translateY(0) scale(1.06, .94); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(0); } 95.5% { transform: scaleY(1); } }

.unit .hp {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  display: flex;
  gap: max(2px, calc(var(--t) * .03));
  padding: max(2px, calc(var(--t) * .028));
  background: var(--ink);
  border-radius: max(4px, calc(var(--t) * .06));
}
.pip {
  display: block;
  width: calc(var(--t) * .17);
  height: max(5px, calc(var(--t) * .075));
  border-radius: 2px;
  background: linear-gradient(#ff8a7d, #e0372d 60%, #b5241c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6);
}
.pip.lost { background: #4b2320; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6); }

/* move markers */
.mark {
  position: absolute;
  left: calc(var(--c) * var(--t));
  top: calc(var(--r) * var(--t));
  width: var(--t);
  height: var(--t);
}
.arrow { display: grid; place-items: center; background: rgba(255, 255, 255, .2); box-shadow: inset 0 0 0 max(2px, calc(var(--t) * .03)) rgba(255, 255, 255, .55); }
.arrow .inner { width: 52%; height: 52%; animation: nudge .9s ease-in-out infinite; }
.arrow svg { width: 100%; height: 100%; display: block; transform: rotate(var(--rot)); filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .25)); }
.arrow.hinted { background: rgba(255, 213, 74, .35); box-shadow: inset 0 0 0 max(3px, calc(var(--t) * .04)) #ffd54a, 0 0 calc(var(--t) * .2) rgba(255, 210, 80, .7); }
.arrow.hinted svg path:first-child { fill: #ffe27a; }
@keyframes nudge { 50% { transform: translate(calc(var(--dx) * var(--t) * .07), calc(var(--dy) * var(--t) * .07)); } }

.ghost { opacity: .5; filter: saturate(.3) brightness(1.25); }
.ghost .sprite { position: absolute; left: 3%; width: 94%; bottom: 17%; height: 94%; }
.ghost.orc .sprite { left: -3%; width: 106%; height: 100%; bottom: 16%; }
.ghost svg { width: 100%; height: 100%; display: block; overflow: visible; }
.ghost .mon .lids { animation: none; }

.kbcursor { border: max(3px, calc(var(--t) * .04)) dashed #ffe27a; border-radius: 6px; box-shadow: 0 0 calc(var(--t) * .14) rgba(255, 220, 110, .7); }
.pending { box-shadow: inset 0 0 0 max(3px, calc(var(--t) * .045)) #ffd54a, 0 0 calc(var(--t) * .18) rgba(255, 210, 80, .8); background: rgba(255, 213, 74, .25); animation: pendingPulse 1s ease-in-out infinite; }
@keyframes pendingPulse { 50% { background: rgba(255, 213, 74, .4); } }
.preview { background: rgba(235, 55, 40, .3); box-shadow: inset 0 0 0 max(3px, calc(var(--t) * .04)) rgba(255, 110, 90, .95); }
.preview.bad { background: rgba(30, 30, 30, .3); box-shadow: inset 0 0 0 max(3px, calc(var(--t) * .04)) rgba(255, 255, 255, .55); }
.preview.gap { background: rgba(30, 30, 30, .35); border: max(3px, calc(var(--t) * .04)) dashed rgba(255, 255, 255, .8); box-shadow: none; display: grid; place-items: center; }
.preview.gap::after { content: ''; width: 46%; height: 46%; border-radius: 50%; border: max(4px, calc(var(--t) * .07)) solid #ff4a3a; background: linear-gradient(45deg, transparent 43%, #ff4a3a 43%, #ff4a3a 57%, transparent 57%); }
.preview.hint { background: rgba(255, 213, 74, .3); box-shadow: inset 0 0 0 max(3px, calc(var(--t) * .045)) #ffd54a, 0 0 calc(var(--t) * .2) rgba(255, 210, 80, .7); animation: pendingPulse .9s ease-in-out infinite; }

.dmg {
  position: absolute;
  font: 900 calc(var(--t) * .36)/1 var(--font-display);
  color: #ff6a5c;
  text-shadow: var(--outline-text);
  white-space: nowrap;
  will-change: transform, opacity;
}

.alert-mark {
  position: absolute;
  display: grid;
  place-items: center;
  width: calc(var(--t) * .46);
  height: calc(var(--t) * .46);
  border: max(3px, calc(var(--t) * .04)) solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #ffcf3a 60%, #e09a12);
  font: 900 calc(var(--t) * .36)/1 var(--font-ui);
  color: var(--attack-lo);
  box-shadow: 0 3px 0 var(--ink), 0 0 calc(var(--t) * .2) rgba(255, 80, 50, .8);
}

/* phase / result banner */
.phase-banner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 20; }
.phase-banner .band {
  width: 100%;
  min-height: clamp(76px, 15vh, 128px);
  display: grid;
  place-items: center;
  background: linear-gradient(#e85d52, #b3302a);
  border-block: 4px solid var(--ink);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .25), inset 0 3px 0 rgba(255, 255, 255, .3);
  overflow: hidden;
}
.phase-banner.gold .band { background: linear-gradient(#ffd866, #e0a024); }
.phase-banner.dark .band { background: linear-gradient(#55585f, #2f3137); }
.phase-banner .txt {
  display: flex;
  align-items: center;
  gap: .35em;
  font: 900 clamp(2.6rem, 8vw, 4.8rem)/1 var(--font-display);
  color: var(--cream);
  text-shadow: var(--outline-text), 0 6px 0 var(--ink);
  white-space: nowrap;
}
.phase-banner .txt .ico { width: .8em; height: .8em; filter: drop-shadow(0 3px 0 var(--ink)); }
.phase-banner .txt .flip { transform: scaleX(-1); }

/* legend chips */
.legend { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 4px 12px 0; position: relative; z-index: 2; min-height: 40px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px 0 4px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(#fff4d3, #ead08f);
  color: var(--ink);
  font: 800 .92rem/1 var(--font-ui);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
.chip:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.chip-art { width: 30px; height: 30px; display: grid; place-items: center; }
.chip-art svg { width: 100%; height: 100%; overflow: visible; }
.chip-x { width: 24px; height: 24px; background: #6c717b; border: 2px solid var(--ink); border-radius: 4px; padding: 2px; }
.chip-pips { display: inline-flex; gap: 2px; padding: 2px; background: var(--ink); border-radius: 4px; }
.chip-pips .pip { width: 11px; height: 6px; }

/* message bar + controls */
.msgbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 62px;
  padding: 6px 12px 0;
  position: relative;
  z-index: 2;
}
.status {
  margin: 0;
  padding: .5em 1.1em;
  max-width: 44ch;
  border-radius: 999px;
  background: rgba(22, 16, 12, .62);
  box-shadow: inset 0 0 0 2px rgba(255, 244, 214, .12);
  font: 700 1.02rem/1.25 var(--font-ui);
  text-align: center;
  color: var(--cream);
  text-shadow: 0 1px 0 var(--ink);
}
.status:empty { display: none; }
.status[data-tone="warn"] { background: rgba(120, 28, 22, .78); }
.status[data-tone="hint"] { background: rgba(120, 88, 12, .78); }
#btn-attack { min-height: 52px; font-size: 1.15rem; animation: ctaGlow 1.3s ease-in-out infinite; }
@keyframes ctaGlow {
  50% { box-shadow: 0 4px 0 var(--ink), 0 0 22px rgba(255, 90, 60, .85), inset 0 2px 0 rgba(255, 255, 255, .65); }
}
.controls { display: flex; justify-content: center; gap: 10px; padding: 8px 12px calc(16px + env(safe-area-inset-bottom)); position: relative; z-index: 2; }

@media (max-width: 560px) {
  .topbar { padding: 8px 10px 0; }
  .btn-back .lbl { display: none; }
  .btn-back { width: 46px; padding: 0; border-radius: 50%; }
  .ribbon { width: clamp(170px, 50vw, 240px); }
  .hud { gap: 10px; }
  .plate { padding: .25em .7em .25em .45em; }
  .plate-num { font-size: 1.8rem; }
  .plate-ico .ico { width: 24px; height: 24px; }
  .plate-label small { display: none; }
  .msgbar { flex-direction: column; gap: 8px; }
  .status { font-size: .95rem; }
  .controls .btn { flex: 1; padding-inline: .5em; max-width: 130px; }
}
@media (max-height: 640px) {
  .legend { display: none; }
  .msgbar { min-height: 50px; }
  .hud { padding-top: 4px; }
  .plate-label small { display: none; }
  .controls { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* Landscape screens without much height (laptops, phones on their side):
   board on the left, counters and controls in a side panel. */
@media (orientation: landscape) and (max-height: 760px) and (min-width: 640px) {
  #screen-game.active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(236px, 28vw, 330px);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "stage hud" "stage legend" "stage msg" "stage ctrl";
  }
  #screen-game .topbar { grid-area: top; }
  #screen-game .stage { grid-area: stage; padding: 6px 8px 12px 16px; }
  #screen-game .hud { grid-area: hud; flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 18px 0 4px; }
  #screen-game .plate { justify-content: flex-start; }
  #screen-game[data-phase] .plate { transform: none; }
  #screen-game .legend { grid-area: legend; justify-content: flex-start; padding: 14px 18px 0 4px; min-height: 0; }
  #screen-game .msgbar { grid-area: msg; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 10px; padding: 14px 18px 10px 4px; }
  #screen-game .status { border-radius: 14px; max-width: none; }
  #screen-game .controls { grid-area: ctrl; padding: 0 18px calc(14px + env(safe-area-inset-bottom)) 4px; gap: 8px; }
  #screen-game .controls .btn { flex: 1 1 0; flex-direction: column; gap: 3px; min-height: 58px; padding: .4em .3em; font-size: .9rem; }
}
@media (orientation: landscape) and (max-height: 480px) {
  .topbar { padding-top: 6px; }
  .ribbon { width: clamp(170px, 30vw, 250px); }
  .btn-icon, .btn-back { min-height: 40px; }
  .btn-icon { width: 40px; }
  #screen-game .plate-num { font-size: 1.6rem; }
  #screen-game .hud { padding-top: 8px; gap: 6px; }
}

/* Title on short screens */
#screen-title { justify-content: flex-start; overflow-y: auto; }
.title-wrap { margin: auto; padding: 16px 0; }
@media (max-height: 600px) {
  .title-wrap { width: min(560px, 82vw); gap: 8px; }
  .logo { margin-bottom: 6px; }
  .parade { display: none; }
  .menu { flex-direction: row; flex-wrap: wrap; justify-content: center; width: auto; }
  .menu .btn { width: auto; }
  .tagline { font-size: 1.05rem; }
}

/* ------------------------------------------------------------- dialogs */
dialog {
  border: none;
  padding: 40px 4px 14px;
  background: transparent;
  color: var(--ink);
  width: fit-content;
  max-width: 96vw;
  max-height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(14, 10, 8, .64); }
dialog[open] .card { animation: cardIn .38s cubic-bezier(.25, 1.45, .45, 1); }
@keyframes cardIn { from { transform: translateY(24px) scale(.88); opacity: 0; } to { transform: none; opacity: 1; } }

.card {
  position: relative;
  width: min(440px, 92vw);
  padding: 2.6rem 1.5rem 1.4rem;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background-color: var(--parchment);
  background-image: radial-gradient(120% 90% at 30% 10%, rgba(255, 255, 240, .7), rgba(220, 180, 110, .25)), var(--tex-paper);
  background-size: auto, 160px 160px;
  box-shadow: 0 8px 0 var(--ink), inset 0 0 0 3px rgba(255, 255, 255, .45), 0 30px 60px rgba(0, 0, 0, .5);
  text-align: center;
  color: var(--ink);
}
.card-ribbon {
  position: absolute;
  top: -32px;
  left: 50%;
  width: min(330px, 86%);
  aspect-ratio: 420 / 96;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  color: var(--move);
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .25));
}
.card-ribbon svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.card-ribbon > span { position: relative; margin-top: -5%; font: 900 clamp(1.3rem, 5vw, 1.75rem)/1 var(--font-display); color: var(--cream); text-shadow: var(--outline-text); white-space: nowrap; }
.card.tone-win .card-ribbon, .card.tone-lose .card-ribbon { color: var(--attack); }
.card.tone-win .card-ribbon { color: var(--gold-deep); }
.card h2 { margin: .5rem 0 .35rem; font: 900 2.2rem/1 var(--font-display); color: var(--ink); }
.card p { margin: .35rem auto; max-width: 36ch; font: 700 1.08rem/1.4 var(--font-ui); color: #3b2a1d; }
.card .card-note { font-size: .98rem; color: #5a4430; }
.card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 1.1rem; }
.card-actions .btn { min-width: 128px; }
.btn-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: #efd9a3;
  color: var(--ink);
  cursor: pointer;
  z-index: 2;
}
.btn-close .ico { width: 18px; height: 18px; }
.btn-close:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.portrait {
  position: relative;
  width: 150px;
  height: 150px;
  margin: .4rem auto .2rem;
  border: 4px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
  background: #d6ebac;
  box-shadow: inset 0 0 0 5px #f0c75c, inset 0 0 0 8px var(--ink), 0 5px 0 var(--ink);
}
.portrait .forest { position: absolute; inset: 0; width: 100%; height: 100%; }
.portrait > .mon { position: absolute; left: 8%; top: 6%; width: 84%; height: 84%; overflow: visible; }
.portrait .mon .lids { animation: blink 4s infinite 1s; }
.portrait-tile { background: #5f9534; display: grid; place-items: center; box-shadow: 0 5px 0 var(--ink); }
.portrait-tile .board { --t: 96px; }
.card-pips { display: inline-flex; gap: 4px; padding: 4px; background: var(--ink); border-radius: 6px; }
.card-pips .pip { width: 26px; height: 11px; }
.card-art { margin: .3rem auto 0; width: 92px; height: 92px; }
.card-art .ico { width: 100%; height: 100%; }

/* help */
.help-card { width: min(560px, 94vw); padding-bottom: 1.1rem; padding-inline: 1.2rem; }
.help-page h2 { font-size: 2rem; }
.help-demo { display: flex; justify-content: center; align-items: center; gap: 14px; min-height: 186px; padding: 10px 0 2px; flex-wrap: wrap; }
.help-demo .field { --t: 50px; border-radius: 14px; padding: calc(var(--t) * .55) calc(var(--t) * .45) calc(var(--t) * .45); box-shadow: inset 0 3px 0 rgba(255, 255, 255, .22), 0 6px 0 -1px #2f4d1a, 0 6px 0 2px var(--ink); }
.help-demo .field.small { --t: 38px; padding: calc(var(--t) * .45) calc(var(--t) * .3) calc(var(--t) * .35); }
@media (max-width: 560px) { .help-demo .field.small { --t: 28px; } .help-demo { gap: 8px; } }
.help-demo:has(.demo-col) { align-items: flex-start; }
.demo-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.demo-col .verdict { width: 30px; height: 30px; }
.demo-col span { font: 800 .86rem/1.15 var(--font-ui); color: #3b2a1d; max-width: 12ch; }
.verdict-yes { color: #2f8f3a; }
.verdict-no { color: #c93f37; }
.demo-slash { stroke-dasharray: 1 3; stroke-dashoffset: 0; }
.demo-slash-anim { animation: demoSlash 2.8s ease-in infinite; }
@keyframes demoSlash { 0%, 28% { stroke-dashoffset: 1; opacity: 1; } 38% { stroke-dashoffset: 0; opacity: 1; } 55%, 100% { stroke-dashoffset: 0; opacity: 0; } }
.demo-die .sprite { animation: demoDie 2.8s ease-in infinite; }
.demo-die .hp { animation: demoHp 2.8s ease-in infinite; }
@keyframes demoDie { 0%, 34% { transform: none; opacity: 1; filter: none; } 37% { filter: brightness(3); } 44% { transform: scale(1.15, .85); opacity: 1; } 60% { transform: translateY(-20%) scale(.2) rotate(20deg); opacity: 0; } 92% { opacity: 0; transform: none; } 100% { opacity: 1; } }
@keyframes demoHp { 0%, 40% { opacity: 1; } 50%, 92% { opacity: 0; } 100% { opacity: 1; } }
.demo-push { animation: demoPush 3s cubic-bezier(.3, 1.3, .5, 1) infinite; }
@keyframes demoPush {
  0%, 30% { transform: translate(calc(var(--c) * var(--t)), calc(var(--r) * var(--t))); opacity: 1; }
  42%, 86% { transform: translate(calc((var(--c) + 1) * var(--t)), calc(var(--r) * var(--t))); opacity: 1; }
  92% { transform: translate(calc((var(--c) + 1) * var(--t)), calc(var(--r) * var(--t))); opacity: 0; }
  93% { transform: translate(calc(var(--c) * var(--t)), calc(var(--r) * var(--t))); opacity: 0; }
  100% { transform: translate(calc(var(--c) * var(--t)), calc(var(--r) * var(--t))); opacity: 1; }
}
.demo-arrow { animation: demoArrow 3s linear infinite; }
@keyframes demoArrow { 0%, 30% { opacity: 1; } 36%, 94% { opacity: 0; } 100% { opacity: 1; } }
.gap-ghost { position: absolute; border: 2px dashed rgba(255, 255, 255, .85); background: rgba(255, 255, 255, .12); }
.help-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 1rem; }
.help-nav .btn { min-width: 96px; }
.dots { display: flex; gap: 7px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; }
.dot.on { background: var(--move); }
.keys { margin-top: .6rem; font: 700 .86rem/1.45 var(--font-ui); color: #5a4430; }
kbd { display: inline-block; min-width: 1.6em; padding: 0 .35em; border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 5px; background: #fff7df; font: 800 .8rem/1.4 var(--font-ui); color: var(--ink); }
.hp-row { display: flex; justify-content: center; gap: 22px; }
.hp-row .demo-col .board { --t: 70px; }

/* ------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .unit .bob, .unit.selected .bob, .mon .lids, .arrow .inner, .shield-btn.next .shield, #btn-attack,
  .tile.cross.occupied .x, .unit.selected .ring, .pending, .preview.hint { animation: none !important; }
  .demo-push, .demo-arrow, .demo-slash-anim, .demo-die .sprite, .demo-die .hp { animation-duration: 6s; }
}
