:root {
  --sand: #c4a574;
  --sand-lit: #e0c49a;
  --ink: #12100c;
  --panel: #1c1812;
  --panel-lit: #2a241c;
  --metal: #6b6560;
  --metal-lit: #9a948c;
  --signal: #e8922a;
  --signal-lit: #ffb347;
  --danger: #c44a32;
  --ok: #6a9e4e;
  --us: #d4b06a;
  --ru: #8a9aaa;
  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-ui: "Rajdhani", "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --board-max: min(96vw, calc(100dvh - 140px), 720px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--sand-lit);
  background: var(--ink);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(232, 146, 42, 0.12), transparent 55%),
    radial-gradient(ellipse 70% 50% at 80% 100%, rgba(90, 70, 40, 0.35), transparent 50%),
    linear-gradient(165deg, #1a1510 0%, #0c0a08 45%, #15120e 100%);
}
.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: repeating-linear-gradient(
    -18deg,
    transparent 0 11px,
    rgba(255, 255, 255, 0.015) 11px 12px
  );
  pointer-events: none;
}

button,
select,
a.btn {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  min-height: 46px;
  padding: 0.55em 1.25em;
  border-radius: 2px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.12s var(--ease), background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--signal-lit), var(--signal));
  color: #1a1006;
  box-shadow: 0 2px 0 #8a5510;
}
.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--panel-lit);
  border: 1px solid rgba(196, 165, 116, 0.35);
  color: var(--sand-lit);
}
.btn-secondary:hover {
  border-color: var(--signal);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(196, 165, 116, 0.22);
  color: var(--metal-lit);
}
.btn-ghost:hover {
  border-color: rgba(196, 165, 116, 0.5);
  color: var(--sand-lit);
}

.btn-icon {
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.25rem;
  background: var(--panel-lit);
  border: 1px solid rgba(196, 165, 116, 0.25);
  border-radius: 2px;
}

.back-btn {
  background: var(--panel-lit);
  border: 1px solid rgba(196, 165, 116, 0.25);
  padding-inline: 0.85em;
  font-size: 0.95rem;
}

/* —— Splash —— */
html.is-splash .game-app {
  display: none !important;
}
html.is-playing .splash {
  display: none !important;
}

.splash {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.splash-stage {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.splash-eyebrow {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--signal);
  animation: rise 0.6s var(--ease) both;
}

.splash-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 10vw, 3.6rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 0.95;
  color: #f2e6d0;
  text-shadow: 0 2px 0 #3a2e1c, 0 8px 28px rgba(0, 0, 0, 0.45);
  animation: rise 0.7s var(--ease) 0.05s both;
}

.splash-tag {
  max-width: 34ch;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--metal-lit);
  animation: rise 0.7s var(--ease) 0.1s both;
}

.splash-hero {
  width: min(78%, 280px);
  aspect-ratio: 1;
  margin: 4px 0;
  animation: rise 0.8s var(--ease) 0.12s both;
}
.splash-board {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  animation: floaty 5.5s ease-in-out 0.9s infinite;
}

.splash-cta {
  width: 100%;
  display: grid;
  gap: 10px;
  animation: rise 0.75s var(--ease) 0.18s both;
}
.splash-cta .btn {
  width: 100%;
}

.board-picker {
  width: 100%;
  display: grid;
  gap: 6px;
  text-align: left;
  animation: rise 0.75s var(--ease) 0.22s both;
}
.board-picker-label {
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--metal);
  font-weight: 600;
}
.board-picker select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid rgba(196, 165, 116, 0.3);
  border-radius: 2px;
  color: var(--sand-lit);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes floaty {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* —— Overlays —— */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 6, 4, 0.72);
  backdrop-filter: blur(4px);
}
.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(420px, 100%);
  padding: 22px 20px;
  background: linear-gradient(180deg, var(--panel-lit), var(--panel));
  border: 1px solid rgba(196, 165, 116, 0.28);
  border-radius: 2px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.overlay-card h2 {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 1.55rem;
  color: #f2e6d0;
  margin-bottom: 8px;
}
.overlay-sub {
  color: var(--metal-lit);
  margin-bottom: 18px;
  line-height: 1.4;
}

.diff-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.tutorial-card {
  text-align: left;
  max-height: min(84dvh, 640px);
  display: flex;
  flex-direction: column;
}
.tut-body {
  flex: 1;
  overflow: auto;
  padding: 4px 2px 12px;
  color: var(--sand-lit);
  line-height: 1.45;
}
.tut-body h3 {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 1.15rem;
  color: var(--signal-lit);
  margin: 0 0 8px;
}
.tut-body p + p,
.tut-body ul {
  margin-top: 10px;
}
.tut-body ul {
  padding-left: 1.2em;
}
.tut-body li {
  margin: 0.35em 0;
}
.tut-body .piece-name {
  color: var(--signal-lit);
  font-weight: 700;
}
.tut-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid rgba(196, 165, 116, 0.18);
  padding-top: 12px;
}
.tut-page {
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--metal);
  font-weight: 600;
}

.promo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.promo-choice {
  display: grid;
  gap: 6px;
  padding: 10px 6px;
  background: var(--ink);
  border: 1px solid rgba(196, 165, 116, 0.28);
  border-radius: 2px;
}
.promo-choice img {
  width: 100%;
  max-width: 64px;
  margin: 0 auto;
  image-rendering: auto;
}
.promo-choice span {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--metal-lit);
}

/* —— Game —— */
.game-app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding:
    max(8px, env(safe-area-inset-top))
    10px
    max(10px, env(safe-area-inset-bottom));
}

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.hud-center {
  text-align: center;
  min-width: 0;
}
.turn-label {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 1.05rem;
  color: #f2e6d0;
}
.status-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--signal);
  min-height: 1.2em;
}
.hud-actions {
  display: flex;
  gap: 6px;
}

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

.board-stage {
  position: relative;
  width: var(--board-max);
  aspect-ratio: 1;
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
}
.board-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  border-radius: 2px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}

.highlight-layer,
.piece-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Captured units — zebra-crossing strip just below the board frame */
.graveyard {
  position: absolute;
  left: 28%;
  width: 48%;
  bottom: 6.5%;
  height: 16%;
  pointer-events: none;
  z-index: 6;
}
.graveyard .captive {
  position: absolute;
  width: 9%;
  transform: translate(-50%, 0);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.75));
  transform-origin: bottom center;
}
.graveyard .captive img {
  display: block;
  width: 100%;
  height: auto;
}
.graveyard .captive.landing {
  animation: captive-land 0.38s var(--ease) both;
}
@keyframes captive-land {
  from {
    opacity: 0;
    transform: translate(-50%, -14px) scale(0.65);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

/* Move markers — perspective quads lying on the board plane (SVG). */
.hl-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.hl {
  stroke-width: 3;
  stroke-linejoin: round;
}
.hl.sel {
  fill: rgba(232, 146, 42, 0.3);
  stroke: rgba(232, 146, 42, 0.9);
}
.hl.move {
  fill: rgba(106, 158, 78, 0.38);
  stroke: rgba(106, 158, 78, 0.95);
}
.hl.capture {
  fill: rgba(196, 74, 50, 0.34);
  stroke: rgba(196, 74, 50, 0.95);
}
.hl.last {
  fill: rgba(255, 220, 120, 0.14);
  stroke: rgba(255, 220, 120, 0.55);
}

.piece {
  position: absolute;
  transform: translate(-50%, 0);
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.65));
  transition:
    left 0.28s var(--ease),
    bottom 0.28s var(--ease),
    width 0.28s var(--ease),
    opacity 0.2s ease;
  will-change: left, bottom;
}
.piece.no-anim {
  transition: none !important;
}
.piece.entering {
  animation: piece-enter 0.45s var(--ease) both;
}
.piece.capturing {
  transition: left 0.32s var(--ease), bottom 0.32s var(--ease), opacity 0.32s ease, width 0.32s ease !important;
  z-index: 40 !important;
}
@keyframes piece-enter {
  from {
    opacity: 0;
    transform: translate(-50%, 18px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}
.piece img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}
.piece.selected {
  filter: drop-shadow(0 0 8px rgba(232, 146, 42, 0.9)) drop-shadow(0 3px 4px rgba(0, 0, 0, 0.65));
}

.board-hit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

@media (min-width: 720px) {
  .splash-stage {
    width: min(480px, 100%);
  }
  .splash-hero {
    width: min(70%, 320px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .splash-board,
  .splash-eyebrow,
  .splash-brand,
  .splash-tag,
  .splash-hero,
  .splash-cta,
  .board-picker,
  .piece,
  .graveyard .captive {
    animation: none !important;
    transition: none !important;
  }
}
