:root {
  --ink: #20160f;
  --paper: #f3dfb6;
  --paper-2: #d7b982;
  --wood: #4b2f20;
  --wood-2: #2a1b15;
  --blue: #2d75bb;
  --blue-light: #8bd4ff;
  --red: #b9473e;
  --red-light: #ffaaa0;
  --gold: #d8ad4a;
  --brick: #b9684b;
  --shadow: rgba(9, 7, 5, .42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 15%, rgba(234, 198, 116, .26), transparent 36rem),
    linear-gradient(145deg, #17262e 0%, #203427 48%, #201722 100%);
  color: #f8edcf;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
}

button {
  font: inherit;
}

.app {
  width: min(100vw, 980px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 7px;
}

.app:has(.lobby) {
  grid-template-rows: 1fr;
}

.topbar,
.command-panel,
.board-shell {
  border: 1px solid rgba(245, 218, 150, .32);
  box-shadow: 0 16px 40px var(--shadow), inset 0 1px rgba(255, 255, 255, .08);
}

.topbar {
  display: grid;
  grid-template-columns: auto auto 1fr 1.35fr 1fr;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 6px 8px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(23, 16, 12, .92), rgba(61, 39, 26, .88));
}

.top-stat {
  min-width: 0;
  padding: 6px 5px;
  border-radius: 999px;
  text-align: center;
  color: #ffe8a8;
  background: rgba(15, 10, 7, .42);
  border: 1px solid rgba(255, 231, 163, .2);
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 900;
  white-space: nowrap;
}

.top-icon-button,
.top-restart {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #ffe8a8;
  background: rgba(15, 10, 7, .54);
  border: 1px solid rgba(255, 231, 163, .24);
  box-shadow: inset 0 1px rgba(255,255,255,.08), 0 2px 8px rgba(0,0,0,.18);
  cursor: pointer;
}

.top-icon-button .action-icon,
.top-restart .action-icon {
  width: 18px;
  height: 18px;
  color: currentColor;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.45));
}

.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(10px, 4vw, 22px);
}

.lobby-panel {
  position: relative;
  width: min(100%, 560px);
  padding: clamp(30px, 7vw, 48px) clamp(16px, 6vw, 42px) clamp(34px, 7vw, 46px);
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgba(245, 218, 150, .38);
  background:
    linear-gradient(180deg, rgba(32, 21, 14, .94), rgba(22, 15, 12, .96)) padding-box,
    linear-gradient(135deg, rgba(133, 95, 47, .92), rgba(53, 32, 22, .96)) border-box;
  box-shadow: 0 18px 46px var(--shadow), inset 0 1px rgba(255,255,255,.08);
  text-align: center;
}

.lobby-panel::before,
.lobby-panel::after {
  content: "";
  position: absolute;
  left: clamp(14px, 4vw, 28px);
  right: clamp(14px, 4vw, 28px);
  height: 18px;
  border: 1px solid rgba(255, 231, 163, .2);
  border-radius: 999px;
  background: rgba(15, 10, 7, .42);
  pointer-events: none;
}

.lobby-panel::before {
  top: 14px;
}

.lobby-panel::after {
  bottom: 14px;
}

.lobby-kicker {
  color: #8bd4ff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.lobby h1 {
  margin: 10px 0 8px;
  font-size: clamp(42px, 12vw, 78px);
  line-height: 1;
  color: transparent;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 6px 18px rgba(0,0,0,.36);
  font-weight: 950;
}

.lobby p {
  margin: 0 0 24px;
  color: #fff0c4;
  font-size: clamp(13px, 3.6vw, 18px);
  font-weight: 850;
}

.mode-list {
  display: grid;
  gap: 10px;
}

.mode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 112px);
  gap: 10px;
}

.lobby-action,
.difficulty-select {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 240, 180, .42);
  font-weight: 950;
}

.lobby-action {
  color: #21160d;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  box-shadow: inset 0 1px rgba(255,255,255,.42), 0 4px 10px rgba(0,0,0,.2);
  cursor: pointer;
}

.lobby-action:active {
  transform: translateY(1px);
}

.lobby-action.primary {
  background: linear-gradient(180deg, #ffe59a, #c99137);
}

.difficulty-select {
  padding: 0 10px;
  color: #ffe8a8;
  background: rgba(15, 10, 7, .62);
  cursor: pointer;
}

.dice-stat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.dice-stat b {
  min-width: 16px;
  font-size: 1.08em;
}

.top-die {
  width: 22px;
  height: 22px;
  gap: 1px;
  padding: 4px;
  border-radius: 6px;
  border-width: 1px;
  box-shadow: inset 0 1px rgba(255,255,255,.65), 0 1px 3px rgba(0,0,0,.32);
}

.top-die span {
  width: 3px;
  height: 3px;
}

.battlefield {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.board-shell {
  position: relative;
  width: min(calc(100vw - 12px), 680px, calc((100dvh - 220px) * 5 / 7));
  min-width: 238px;
  padding: clamp(4px, 1vw, 8px);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(133, 95, 47, .92), rgba(53, 32, 22, .96)),
    repeating-linear-gradient(90deg, transparent 0 28px, rgba(255,255,255,.04) 28px 30px);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: clamp(3px, 1vw, 6px);
  aspect-ratio: 5 / 7;
  border-radius: 13px;
  padding: clamp(3px, .8vw, 6px);
  background: linear-gradient(180deg, #28321f, #171d17);
  border: 1px solid rgba(255, 238, 176, .18);
}

.resource-strip {
  height: 28px;
  margin: 0 2px 4px;
  padding: 3px 8px;
  display: grid;
  grid-template-columns: 1fr repeat(2, auto);
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  color: #fff3c8;
  background: rgba(15, 11, 8, .62);
  border: 1px solid rgba(255, 232, 170, .16);
  font-size: clamp(10px, 2.6vw, 13px);
  font-weight: 900;
}

.summary-item {
  display: inline-grid;
  grid-template-columns: 14px auto;
  align-items: center;
  gap: 2px;
}

.mini-unit {
  width: 15px;
  height: 15px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #f2d47c;
  box-shadow: inset 0 1px rgba(255,255,255,.35);
  overflow: hidden;
}

.mini-unit.cavalry { background: #e8c06a; }
.mini-unit.infantry { background: #c8e5ef; }
.mini-unit.archer { background: #cfe6a2; }

.summary-item .res-icon,
.mini-unit svg {
  width: 14px;
  height: 14px;
}

.resource-strip.ai {
  margin: 4px 2px 0;
}

.resource-strip.player span {
  color: var(--blue-light);
}

.resource-strip.ai span {
  color: var(--red-light);
}

.pvp-board .reverse-view {
  transform: rotate(180deg);
}

.pvp-board .move-ghost.ai .piece-card {
  transform: rotate(180deg);
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 10px;
  color: var(--ink);
  background: linear-gradient(145deg, #6f895c, #445f45);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .14),
    inset 0 -12px rgba(20, 17, 9, .22),
    0 2px 6px rgba(0,0,0,.28);
  cursor: pointer;
  overflow: hidden;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(rgba(0,0,0,.18), rgba(0,0,0,.18)),
    linear-gradient(135deg, rgba(255,255,255,.07), transparent 34%),
    radial-gradient(circle at 18% 80%, rgba(255,255,255,.045), transparent 28%);
  pointer-events: none;
}

.tile.empty {
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 7px, transparent 7px 14px),
    linear-gradient(145deg, #334038, #202822);
}

.tile.base-tile {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 236, 167, .16), transparent 48%),
    linear-gradient(145deg, #334038, #202822);
}

.tile.wall {
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), transparent 38%),
    repeating-linear-gradient(90deg, #7d7667 0 18%, #5e584c 18% 20%),
    linear-gradient(145deg, #746d5f, #403b34);
}
.tile.wall.collapsed {
  background:
    radial-gradient(circle at 42% 58%, rgba(20,18,14,.52), transparent 36%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.05) 0 8px, transparent 8px 16px),
    linear-gradient(145deg, #4b5045, #262b25);
}
.tile.probable { background: linear-gradient(145deg, #8eae64, #4f7645); }
.tile.possible { background: linear-gradient(145deg, #d2ad4e, #735a25); }
.tile.unlikely { background: linear-gradient(145deg, #bd704f, #6b3d31); }
.tile.hot {
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .34),
    inset 0 -8px rgba(20, 17, 9, .1),
    0 2px 8px rgba(0,0,0,.22);
}

.tile.hot::after {
  background:
    linear-gradient(135deg, rgba(255,255,255,.2), transparent 34%),
    radial-gradient(circle at 48% 44%, rgba(255,255,190,.18), transparent 52%);
}

.tile.move {
  outline: none;
  overflow: visible;
}

.tile.move::before {
  content: "";
  position: absolute;
  inset: -3px;
  z-index: 24;
  border: 3px solid rgba(117, 255, 154, .96);
  border-radius: 13px;
  box-shadow: 0 0 14px rgba(117, 255, 154, .5);
  pointer-events: none;
}
.tile.attack {
  outline: 3px solid rgba(255, 118, 105, .9);
}
.tile.selected {
  outline: 3px solid #fff176;
}

.tile-num {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 8;
  min-width: 24px;
  min-height: 22px;
  padding: 0 7px;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 239, 178, .82);
  border: 1px solid rgba(52, 35, 18, .35);
  font-size: clamp(12px, 3.2vw, 17px);
  font-weight: 950;
  line-height: 1;
  color: rgba(24, 17, 10, .88);
  box-shadow: 0 2px 5px rgba(0,0,0,.18);
}

.tile.occupied .tile-num,
.tile.occupied .yield-tray,
.tile.fortified .tile-num,
.tile.fortified .yield-tray {
  opacity: .52;
  filter: blur(.7px) saturate(.76);
}

.yield-tray {
  position: absolute;
  right: 5%;
  bottom: 5%;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  width: auto;
  max-width: none;
  padding: 0;
}

.yield-token {
  min-height: clamp(12px, 3.25vw, 18px);
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 1px;
  padding: 0;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.55));
}

.yield-token .res-icon {
  width: 15px;
  height: 15px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.32));
}

.res-icon {
  display: block;
}

.res-emoji {
  display: block;
  font-size: clamp(8px, 2.5vw, 13px);
  line-height: 1;
  transform: translateY(-1px);
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.35)) drop-shadow(0 1px 1px rgba(0,0,0,.35));
}

.yield-token b {
  color: #fff6d5;
  font-size: clamp(7px, 2.1vw, 10px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}

.tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8%;
  z-index: 2;
  text-align: center;
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 900;
  color: rgba(33, 22, 12, .78);
}

.tile-label.muted {
  color: rgba(245, 230, 195, .42);
}

.piece,
.base,
.fort {
  position: absolute;
  z-index: 12;
  left: 50%;
  top: 50%;
  width: 66%;
  height: 64%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.piece {
  will-change: transform;
}

.piece-hidden-during-move {
  visibility: hidden;
}

.move-overlay {
  position: absolute;
  inset: 0;
  z-index: 28;
  pointer-events: none;
}

.move-ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: calc((100% - 16px) / 5 * .66);
  aspect-ratio: 1 / .97;
  color: var(--blue-light);
  transform: translate(-50%, -50%);
  opacity: 0;
  will-change: transform;
}

.move-ghost.ai {
  color: var(--red-light);
}

.move-ghost.move-ghost-running {
  animation: pieceTravel .52s cubic-bezier(.45, 0, .2, 1) .32s both;
}

.move-ghost.move-ghost-ready {
  transform: translate(calc(var(--move-start-x) - 50%), calc(var(--move-start-y) - 50%)) scale(.96);
  opacity: 1;
}

.action-cue {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.cue-arrow {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.52));
  animation: cueFlash .32s ease both;
}

.cue-arrow-head {
  fill: none;
}

.move-arrow {
  stroke: rgba(128, 255, 166, .96);
}

.attack-arrow {
  stroke: rgba(255, 96, 82, .96);
}

.cue-start {
  fill: #dfff9a;
  stroke: rgba(47, 122, 71, .95);
  stroke-width: 2;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.48));
  animation: cueFade .32s ease both;
}

.cue-landing {
  fill: rgba(31, 55, 31, .46);
  stroke: rgba(128, 255, 166, .98);
  stroke-width: 3;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.48)) drop-shadow(0 0 8px rgba(105,255,150,.62));
  animation: cueFade .32s ease both;
}

.cue-crosshair {
  fill: none;
  stroke: #ff5c50;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.58));
  animation: cueFade .34s ease both;
}

.cue-crosshair circle:last-child {
  fill: #ff5c50;
}

.targeting-overlay {
  position: absolute;
  inset: 0;
  z-index: 27;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.target-line {
  stroke: rgba(205, 245, 255, .88);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 5 5;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.55));
}

.targeting-overlay.move .target-line {
  stroke: rgba(128, 255, 166, .92);
  stroke-dasharray: none;
}

.targeting-overlay.attack .target-line {
  stroke: rgba(255, 102, 88, .92);
  stroke-dasharray: none;
}

.targeting-overlay.blocked .target-line {
  stroke: rgba(190, 190, 184, .7);
}

.target-move-dot {
  fill: #dfff9a;
  stroke: rgba(84, 255, 138, .98);
  stroke-width: 3;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)) drop-shadow(0 0 7px rgba(105,255,150,.65));
}

.target-crosshair,
.target-blocked {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.58));
}

.target-crosshair {
  stroke: #ff5c50;
  stroke-width: 3;
}

.target-crosshair circle:last-child {
  fill: #ff5c50;
}

.target-blocked {
  stroke: rgba(218, 218, 208, .82);
  stroke-width: 3.4;
}

.target-blocked circle {
  fill: rgba(45, 45, 42, .36);
}

.base {
  width: 88%;
  height: 88%;
  z-index: 10;
}

.fort {
  width: 54%;
  height: 50%;
  z-index: 9;
  color: #ffe2a2;
  opacity: .92;
}

.fort.player { color: var(--blue-light); }
.fort.ai { color: var(--red-light); }

.fort svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.42));
}

.fort-shadow {
  fill: rgba(25, 16, 10, .34);
}

.fort-body,
.fort-top {
  fill: currentColor;
}

.fort-roof {
  fill: #ffe3a3;
  opacity: .82;
}

.fort-gate {
  fill: rgba(28, 18, 12, .58);
}

.fort-highlight {
  fill: rgba(255, 248, 214, .56);
}

.fort b {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -2px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
}

.fort i {
  height: 4px;
  border-radius: 999px;
  background: rgba(25, 17, 10, .45);
}

.fort i.full {
  background: currentColor;
}

.piece-card {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,.18), transparent 44%),
    rgba(18, 16, 12, .32);
  border: 2px solid currentColor;
  box-shadow: 0 9px 16px rgba(0,0,0,.34), 0 0 0 2px rgba(22,16,10,.34);
  backdrop-filter: blur(1px);
}

.piece.player { color: var(--blue-light); }
.piece.ai { color: var(--red-light); }

.piece.can-act .piece-card {
  filter: brightness(1.2) saturate(1.16);
  box-shadow: 0 10px 18px rgba(0,0,0,.36), 0 0 0 2px rgba(255, 238, 170, .38), 0 0 18px color-mix(in srgb, currentColor 58%, transparent);
}

.piece.can-act .piece-aura {
  opacity: .34;
}

.piece.spent .piece-card {
  filter: brightness(.58) saturate(.68);
  opacity: .72;
}

.piece.spent .piece-aura {
  opacity: .08;
}

.piece svg,
.base svg {
  width: 100%;
  height: 100%;
  display: block;
}

.unit-svg {
  position: relative;
  z-index: 2;
  width: 92%;
  height: 92%;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.45));
}

.piece-aura {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: currentColor;
  opacity: .18;
  filter: blur(8px);
}

.wall-art {
  position: absolute;
  inset: 16% 9%;
  z-index: 4;
  display: grid;
  place-items: center;
  color: #8d8576;
  filter: drop-shadow(0 5px 2px rgba(0,0,0,.38));
}

.wall-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.wall-fill {
  fill: currentColor;
}

.wall-light {
  fill: rgba(255, 244, 206, .26);
}

.tile.collapsed .wall-art {
  color: rgba(119, 112, 98, .56);
  opacity: .72;
  transform: rotate(-7deg) scale(.92);
  filter: drop-shadow(0 4px 2px rgba(0,0,0,.24));
}

.piece-pips {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  z-index: 4;
}

.piece-pips span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffe08a;
  box-shadow: 0 1px 2px #000;
}

.unit-hp {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 7px;
  z-index: 5;
  display: grid;
  gap: 1px;
  height: 2px;
  padding: 1px;
  border-radius: 999px;
  background: rgba(16, 11, 8, .58);
  box-shadow: 0 1px 2px rgba(0,0,0,.58);
}

.unit-hp i {
  min-width: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
}

.unit-hp i.full {
  background: linear-gradient(180deg, #9ff2a5, #43c76d);
  box-shadow: 0 0 3px rgba(105, 255, 137, .45);
}

.base-frame {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 5px 5px rgba(0,0,0,.38));
}

.base.player { color: var(--blue-light); }
.base.ai { color: var(--red-light); }

.base-hp {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 5%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.base-hp span {
  height: 5px;
  border-radius: 4px;
  background: rgba(17, 11, 7, .45);
}

.base-hp span.full {
  background: currentColor;
}

.command-panel {
  border-radius: 16px 16px 12px 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(21, 16, 13, .94), rgba(48, 30, 22, .95));
}

.message {
  min-height: 28px;
  margin: 0;
  color: #fff0c4;
  font-weight: 850;
  line-height: 1.35;
  font-size: clamp(13px, 3.4vw, 16px);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.action {
  min-height: 38px;
  border: 1px solid rgba(255, 240, 180, .42);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #21160d;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  font-weight: 950;
  box-shadow: inset 0 1px rgba(255,255,255,.42), 0 4px 10px rgba(0,0,0,.2);
  cursor: pointer;
}

.end-action {
  min-width: 112px;
  padding: 0 14px;
}

.action-icon {
  width: 18px;
  height: 18px;
  display: block;
  flex: 0 0 auto;
  color: #5a3519;
  filter: drop-shadow(0 1px rgba(255,255,255,.38));
}

.context-popover {
  position: absolute;
  left: 50%;
  bottom: 38px;
  z-index: 15;
  width: min(92%, 330px);
  transform: translateX(-50%);
  padding: 8px;
  border-radius: 12px;
  color: #fff0c4;
  background: rgba(22, 15, 11, .9);
  border: 1px solid rgba(255, 222, 143, .36);
  box-shadow: 0 10px 26px rgba(0,0,0,.42);
  backdrop-filter: blur(5px);
}

.context-title {
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 950;
  color: #ffe39a;
}

.base-menu {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.base-menu .context-title,
.unit-menu .context-title,
.unit-menu .unit-stats {
  grid-column: 1 / -1;
}

.context-popover button {
  min-height: 32px;
  border: 1px solid rgba(255, 240, 180, .42);
  border-radius: 9px;
  color: #21160d;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  font-weight: 950;
}

.cost-button {
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 5px 3px;
}

.cost-button small {
  min-height: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: rgba(38, 24, 12, .86);
  font-size: 10px;
  font-weight: 950;
  white-space: nowrap;
}

.cost-button .res-icon {
  width: 13px;
  height: 13px;
}

.context-popover button:disabled {
  color: rgba(255,255,255,.42);
  background: linear-gradient(180deg, #5e6466, #3c4245);
}

.unit-menu {
  display: grid;
  gap: 6px;
}

.unit-stats {
  color: #e7d6aa;
  font-size: 12px;
  font-weight: 800;
}

.dice-overlay {
  position: absolute;
  inset: 34px 0 34px;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.dice-pair {
  display: flex;
  gap: 14px;
  animation: diceDrop .98s cubic-bezier(.16, .9, .25, 1) both;
}

.die {
  width: clamp(44px, 13vw, 66px);
  height: clamp(44px, 13vw, 66px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 13px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.92), transparent 18%),
    linear-gradient(145deg, #fff8df, #c89b49);
  border: 2px solid #4a2f1d;
  box-shadow: 0 14px 28px rgba(0,0,0,.42), inset 0 2px rgba(255,255,255,.65);
}

.die span {
  width: 8px;
  height: 8px;
  align-self: center;
  justify-self: center;
  border-radius: 50%;
  background: #2a1a12;
  box-shadow: inset 0 1px rgba(255,255,255,.18);
}

.die.top-die {
  width: 22px;
  height: 22px;
  gap: 1px;
  padding: 4px;
  border-radius: 6px;
  border-width: 1px;
  box-shadow: inset 0 1px rgba(255,255,255,.65), 0 1px 3px rgba(0,0,0,.32);
}

.die.top-die span {
  width: 3px;
  height: 3px;
}

.pip.p1 { grid-column: 1; grid-row: 1; }
.pip.p2 { grid-column: 2; grid-row: 1; }
.pip.p3 { grid-column: 3; grid-row: 1; }
.pip.p4 { grid-column: 1; grid-row: 2; }
.pip.p5 { grid-column: 2; grid-row: 2; }
.pip.p6 { grid-column: 3; grid-row: 2; }
.pip.p7 { grid-column: 1; grid-row: 3; }
.pip.p8 { grid-column: 2; grid-row: 3; }
.pip.p9 { grid-column: 3; grid-row: 3; }

.harvest-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 31;
  transform: translate(-50%, -50%);
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 999px;
  color: #20150d;
  background: linear-gradient(180deg, #ffe7a0, #d59d38);
  border: 1px solid rgba(255,255,255,.5);
  font-weight: 950;
  box-shadow: 0 12px 24px rgba(0,0,0,.35);
  animation: harvestPop 2.6s ease both;
  pointer-events: none;
}

.gain-flash {
  display: grid;
  gap: 5px;
}

.gain-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.gain-row b {
  min-width: 36px;
  text-align: right;
}

.gain-token {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.gain-token .res-icon {
  width: 18px;
  height: 18px;
}

.gain-token span {
  font-weight: 950;
}

.gain-none {
  color: rgba(32, 21, 13, .62);
}

.victory-overlay {
  position: absolute;
  inset: 34px 0 34px;
  z-index: 34;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at 50% 46%, rgba(255, 229, 143, .26), transparent 38%);
  animation: victoryGlow 1.2s ease both;
}

.victory-card {
  min-width: min(78%, 340px);
  padding: 18px 20px;
  border-radius: 16px;
  color: #21150d;
  text-align: center;
  background: linear-gradient(180deg, #fff0b8, #d8a139);
  border: 2px solid rgba(255,255,255,.62);
  box-shadow: 0 18px 40px rgba(0,0,0,.45), 0 0 35px rgba(255, 218, 107, .7);
  animation: victoryPop 1.1s cubic-bezier(.16, .9, .26, 1) both;
}

.victory-overlay.lose .victory-card {
  color: #fff0d2;
  background: linear-gradient(180deg, #9c433e, #3a201e);
}

.victory-card span {
  display: block;
  font-size: clamp(32px, 11vw, 58px);
  font-weight: 950;
  line-height: 1;
}

.victory-card b {
  display: block;
  margin-top: 6px;
  font-size: clamp(13px, 3.5vw, 18px);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 6, 5, .54);
  backdrop-filter: blur(2px);
}

.confirm-card {
  width: min(100%, 360px);
  padding: 20px;
  border-radius: 18px;
  text-align: center;
  color: #fff0c4;
  border: 1px solid rgba(245, 218, 150, .42);
  background:
    linear-gradient(180deg, rgba(32, 21, 14, .98), rgba(22, 15, 12, .98)) padding-box,
    linear-gradient(135deg, rgba(133, 95, 47, .92), rgba(53, 32, 22, .96)) border-box;
  box-shadow: 0 18px 46px rgba(7, 5, 4, .58), inset 0 1px rgba(255,255,255,.08);
}

.confirm-card span {
  display: block;
  color: transparent;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: 30px;
  font-weight: 950;
}

.confirm-card b {
  display: block;
  margin: 8px 0 18px;
  font-size: 14px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.confirm-actions button {
  min-height: 42px;
  border-radius: 10px;
  font-weight: 950;
  cursor: pointer;
}

.confirm-secondary {
  color: #ffe8a8;
  background: rgba(15, 10, 7, .62);
  border: 1px solid rgba(255, 240, 180, .3);
}

.confirm-primary {
  color: #21160d;
  background: linear-gradient(180deg, #f3d47b, #c99137);
  border: 1px solid rgba(255, 240, 180, .48);
  box-shadow: inset 0 1px rgba(255,255,255,.42), 0 4px 10px rgba(0,0,0,.2);
}

.attack-overlay {
  position: absolute;
  inset: 0;
  z-index: 32;
  pointer-events: none;
}

.attack-effect {
  position: absolute;
  left: var(--attack-x);
  top: var(--attack-y);
  width: clamp(92px, 28vw, 150px);
  height: clamp(92px, 28vw, 150px);
  transform: translate(-50%, -50%) rotate(-45deg);
  transform-origin: center;
  animation: attackEffectDelay .2s linear both;
}

.attack-effect.ai {
  transform: translate(-50%, -50%) rotate(-135deg);
}

.charge-effect {
  position: relative;
  width: 100%;
  height: 100%;
  color: #ffe6a3;
  animation: cavalryCharge .72s cubic-bezier(.2, .9, .25, 1) .24s both;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.45));
}

.charge-effect .unit-svg {
  width: 100%;
  height: 100%;
}

.charge-effect span {
  position: absolute;
  left: -34%;
  right: 70%;
  top: 54%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #ffe39a);
  box-shadow: 0 0 16px #ffe39a;
}

.slash-effect {
  position: relative;
  width: 100%;
  height: 100%;
  animation: shieldImpact .72s ease .24s both;
}

.slash-effect span {
  position: absolute;
  left: 17%;
  top: 48%;
  width: 70%;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fff7d6 45%, #ffd36d);
  transform: rotate(-38deg);
  box-shadow: 0 0 18px #ffe39a;
}

.slash-effect i {
  position: absolute;
  left: 33%;
  top: 30%;
  width: 38%;
  height: 38%;
  border-radius: 50%;
  border: 7px solid rgba(194, 232, 246, .9);
  box-shadow: 0 0 18px rgba(142, 218, 255, .8);
}

.arrow-effect {
  position: relative;
  width: 100%;
  height: 100%;
}

.arrow-effect span {
  position: absolute;
  left: 12%;
  top: 44%;
  width: 22%;
  height: 7px;
  border-radius: 999px;
  background: #f8f1d0;
  box-shadow: 0 0 16px #ffe39a;
  animation: arrowShot .68s cubic-bezier(.2, .85, .2, 1) .24s both;
}

.arrow-effect span::after {
  content: "";
  position: absolute;
  right: -12px;
  top: -6px;
  border-left: 15px solid #f8f1d0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

@keyframes diceDrop {
  0% {
    transform: translateY(-48%) scale(.72) rotate(-28deg);
    opacity: 0;
  }
  48% {
    transform: translateY(6%) scale(1.08) rotate(24deg);
    opacity: 1;
  }
  70% {
    transform: translateY(-4%) scale(.98) rotate(-9deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes harvestPop {
  0% {
    transform: translate(-50%, -44%) scale(.86);
    opacity: 0;
  }
  18%, 78% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -58%) scale(.98);
    opacity: 0;
  }
}

@keyframes cavalryCharge {
  0% {
    transform: translateX(-115%) scale(.72);
    opacity: 0;
  }
  45% {
    transform: translateX(6%) scale(1.08);
    opacity: 1;
  }
  72% {
    transform: translateX(-2%) scale(1);
  }
  100% {
    transform: translateX(78%) scale(.9);
    opacity: 0;
  }
}

@keyframes cueFlash {
  0% {
    opacity: 0;
    transform: scale(.94);
  }
  24%, 78% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.04);
  }
}

@keyframes cueFade {
  0% { opacity: 0; }
  24%, 78% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes attackEffectDelay {
  from { opacity: 1; }
  to { opacity: 1; }
}

@keyframes shieldImpact {
  0% {
    transform: scale(.75) rotate(-22deg);
    opacity: 0;
  }
  40% {
    transform: scale(1.08) rotate(5deg);
    opacity: 1;
  }
  100% {
    transform: scale(1.2) rotate(0);
    opacity: 0;
  }
}

@keyframes arrowShot {
  0% {
    transform: translateX(-18%) rotate(-10deg);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    transform: translateX(310%) rotate(-10deg);
    opacity: 0;
  }
}

@keyframes pieceTravel {
  from {
    transform: translate(calc(var(--move-start-x) - 50%), calc(var(--move-start-y) - 50%)) scale(.96);
    opacity: 1;
  }
  to {
    transform: translate(calc(var(--move-end-x) - 50%), calc(var(--move-end-y) - 50%)) scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .move-ghost.move-ghost-running {
    animation: none;
  }
}

@keyframes victoryGlow {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes victoryPop {
  0% {
    transform: translateY(18px) scale(.84);
    opacity: 0;
  }
  55% {
    transform: translateY(-4px) scale(1.04);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.action:disabled {
  color: rgba(255,255,255,.42);
  background: linear-gradient(180deg, #5e6466, #3c4245);
  border-color: rgba(255,255,255,.08);
  cursor: default;
}

.selected-info {
  margin-top: 8px;
  color: #d7c59a;
  font-size: 13px;
  font-weight: 750;
}

.error {
  position: fixed;
  inset: 16px;
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 22px;
  color: #fff1c6;
  background: rgba(20, 15, 12, .95);
  border: 2px solid #f0c36d;
  border-radius: 16px;
  text-align: center;
  font-size: 18px;
}

.error[hidden] {
  display: none;
}

@media (orientation: landscape) and (max-height: 760px) {
  .app {
    max-width: none;
    grid-template-columns: 1fr minmax(260px, 34vw);
    grid-template-rows: auto 1fr;
  }

  .app:has(.lobby) {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    max-width: 980px;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .command-panel {
    align-self: stretch;
  }

  .board-shell {
    width: min(100%, 620px, calc((100dvh - 110px) * 5 / 7));
  }
}

@media (max-width: 420px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .app:has(.lobby) {
    min-height: 100dvh;
  }

  .lobby-panel {
    padding-top: 28px;
  }

  .mode-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: auto auto 1fr 1.25fr;
  }

  .topbar .top-stat:last-child {
    grid-column: 3 / -1;
  }

  .resource-strip {
    gap: 4px;
    padding-left: 6px;
    padding-right: 6px;
    font-size: 10px;
  }

  .mini-unit {
    width: 13px;
    height: 13px;
    font-size: 9px;
  }
}
