/* ============ SURVIVAL CHESS — deep night / ember / fog ============ */

:root {
  --night-0: #07080d;
  --night-1: #0c0f17;
  --night-2: #141926;
  --tile-dark: #10141f;
  --tile-light: #1b2233;
  --fog-tile: #0a0c12;
  --ember: #ff9d3c;
  --ember-hot: #ffd08a;
  --ember-dim: #8a5a2a;
  --blood: #c33b3b;
  --fallen: #6fdcae;
  --fallen-dim: #2a5f4a;
  --ink: #d8d2c4;
  --ink-dim: #7d7869;
  --hairline: rgba(255, 157, 60, 0.16);
}

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

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 70% 20%, #131a2b 0%, transparent 60%),
    radial-gradient(900px 600px at 20% 90%, #16110f 0%, transparent 55%),
    var(--night-0);
  color: var(--ink);
  font-family: "IM Fell English", Georgia, serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
}

/* ---------- ambient layers ---------- */

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
}

#embers { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }

.ember-mote {
  position: absolute;
  bottom: -10px;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 6px 2px rgba(255, 157, 60, 0.5);
  opacity: 0;
  animation: ember-rise linear infinite;
}

@keyframes ember-rise {
  0%   { transform: translate(0, 0) scale(1); opacity: 0; }
  8%   { opacity: 0.85; }
  60%  { opacity: 0.5; }
  100% { transform: translate(var(--drift, 30px), -110vh) scale(0.3); opacity: 0; }
}

/* ---------- floating HUD ---------- */

#hud-top {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(18px, 2.4vh, 34px) clamp(28px, 3vw, 60px) 0;
  height: clamp(68px, 9vh, 118px);
}

#hud-brand {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: clamp(16px, 1.4vw, 24px);
  letter-spacing: 0.28em;
  color: var(--ink-dim);
  width: clamp(220px, 24vw, 380px);
}
#hud-brand span {
  color: var(--ember);
  text-shadow: 0 0 14px rgba(255,157,60,0.45);
}

#hud-wave {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: clamp(12px, 1.1vw, 20px);
  font-family: "Cinzel", serif;
}
#hud-wave .diamond {
  color: var(--ember-dim);
  font-size: clamp(9px, 0.8vw, 14px);
  transform: translateY(-0.35em);
}
#hud-wave .wave-word {
  font-size: clamp(14px, 1.2vw, 21px);
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#stat-wave {
  font-weight: 900;
  font-size: clamp(36px, 3.2vw, 58px);
  line-height: 1;
  color: var(--ember-hot);
  text-shadow: 0 0 18px rgba(255,157,60,0.45);
}

#hud-actions {
  display: flex;
  align-items: center;
  gap: clamp(10px, 0.9vw, 16px);
  width: clamp(220px, 24vw, 380px);
  justify-content: flex-end;
}

.icon-btn {
  width: clamp(42px, 3.4vw, 62px);
  height: clamp(42px, 3.4vw, 62px);
  border-radius: 50%;
  border: 1px solid #46527a;
  background: rgba(20, 25, 40, 0.9);
  color: var(--ink);
  font-family: "Cinzel", serif;
  font-size: clamp(17px, 1.4vw, 26px);
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  border-color: var(--ember);
  color: var(--ember-hot);
  box-shadow: 0 0 14px rgba(255,157,60,0.3);
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  border-color: #46527a;
  color: var(--ink);
  box-shadow: none;
}
.icon-btn.sm {
  width: clamp(36px, 2.8vw, 52px);
  height: clamp(36px, 2.8vw, 52px);
  font-size: clamp(13px, 1vw, 19px);
}
.icon-btn.muted { color: #4a463d; text-decoration: line-through; }

/* ---------- board ---------- */

#board-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  position: relative;
  z-index: 5;
}

#board-frame {
  position: relative;
  height: min(100%, 92vw, 1100px);
  aspect-ratio: 1;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #232c42,
    0 0 60px rgba(0,0,0,0.8),
    0 0 120px rgba(20,30,55,0.35);
}

#board {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border-radius: 6px;
  overflow: hidden;
}

.tile { position: relative; }
.tile.light { background: var(--tile-light); }
.tile.dark  { background: var(--tile-dark); }

.tile.light::after, .tile.dark::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.02), transparent 70%);
}

/* --- The Fog (spawn ring) --- */

.tile.fog {
  background: var(--fog-tile);
  overflow: hidden;
}
.tile.fog::before, .tile.fog::after {
  content: "";
  position: absolute;
  inset: -60%;
  background:
    radial-gradient(ellipse 60% 45% at 30% 40%, rgba(140,165,190,0.10), transparent 70%),
    radial-gradient(ellipse 50% 40% at 70% 65%, rgba(110,140,170,0.08), transparent 70%);
  animation: fog-drift 14s ease-in-out infinite alternate;
}
.tile.fog::after {
  background:
    radial-gradient(ellipse 55% 40% at 60% 30%, rgba(120,150,180,0.07), transparent 70%),
    radial-gradient(ellipse 45% 50% at 25% 70%, rgba(150,175,200,0.09), transparent 70%);
  animation: fog-drift 19s ease-in-out infinite alternate-reverse;
}

@keyframes fog-drift {
  0%   { transform: translate(-6%, -3%) rotate(0deg); }
  100% { transform: translate(6%, 4%) rotate(6deg); }
}

/* inner glow separating board from fog */
#board::after {
  content: "";
  position: absolute;
  left: 10%; top: 10%; width: 80%; height: 80%;
  pointer-events: none;
  box-shadow:
    0 0 0 1px var(--hairline),
    0 0 30px rgba(0,0,0,0.9),
    inset 0 0 40px rgba(0,0,0,0.4);
}

/* --- tile interaction states --- */

.tile.sel { box-shadow: inset 0 0 0 2px var(--ember), inset 0 0 24px rgba(255,157,60,0.25); }

.tile.move-hint::before {
  content: "";
  position: absolute; z-index: 2;
  left: 50%; top: 50%;
  width: 22%; height: 22%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255,157,60,0.7);
  box-shadow: 0 0 12px rgba(255,157,60,0.7);
  animation: hint-pulse 1.4s ease-in-out infinite;
}
.tile.capture-hint {
  box-shadow: inset 0 0 0 2px var(--blood), inset 0 0 22px rgba(195,59,59,0.35);
  animation: none;
}
@keyframes hint-pulse {
  0%, 100% { opacity: 0.6; transform: translate(-50%,-50%) scale(0.85); }
  50%       { opacity: 1;   transform: translate(-50%,-50%) scale(1.05); }
}

.tile.last-enemy { box-shadow: inset 0 0 0 1px rgba(111,220,174,0.35); }

/* ---------- pieces ---------- */

#pieces-layer, #fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

.piece {
  position: absolute;
  width: 10%; height: 10%;
  pointer-events: auto;
  cursor: pointer;
  transition: left 0.32s cubic-bezier(0.5, 0, 0.2, 1.2), top 0.32s cubic-bezier(0.5, 0, 0.2, 1.2);
  z-index: 10;
}
.piece svg { width: 100%; height: 100%; display: block; }

.piece.player svg { filter: drop-shadow(0 0 6px rgba(255,157,60,0.45)) drop-shadow(0 3px 3px rgba(0,0,0,0.6)); }
.piece.enemy  svg { filter: drop-shadow(0 0 7px rgba(111,220,174,0.4)) drop-shadow(0 3px 3px rgba(0,0,0,0.6)); }
.piece.enemy { cursor: default; }

.piece.player:hover { transform: translateY(-2%) scale(1.05); }
.piece.selected { transform: translateY(-4%) scale(1.08); z-index: 12; }
.piece.selected svg { filter: drop-shadow(0 0 12px rgba(255,208,138,0.8)) drop-shadow(0 4px 4px rgba(0,0,0,0.6)); }

.piece.spawning { animation: spawn-in 0.7s ease-out; }
@keyframes spawn-in {
  0%   { opacity: 0; transform: translateY(18%) scale(0.6); filter: blur(6px); }
  60%  { opacity: 0.8; filter: blur(1px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.piece.dying { animation: die-out 0.45s ease-in forwards; z-index: 14; }
@keyframes die-out {
  0%   { opacity: 1; transform: scale(1) rotate(0deg); }
  100% { opacity: 0; transform: scale(0.3) rotate(18deg); filter: blur(4px); }
}

.piece.king-danger { animation: king-danger 0.9s ease-in-out infinite; }
@keyframes king-danger {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 14px rgba(195,59,59,0.9)); }
}

/* the fallen sway slightly, like something not quite alive */
.piece.enemy .bob { animation: enemy-sway 3.2s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes enemy-sway {
  0%, 100% { transform: rotate(-1.6deg); }
  50%      { transform: rotate(1.6deg); }
}

/* ---------- annotations (right-click arrows & circles) ---------- */

#annot-layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 22;
}
#annot-layer .a-circle {
  fill: none;
  stroke: rgba(255, 157, 60, 0.85);
  stroke-width: 0.8;
}
#annot-layer .a-arrow {
  stroke: rgba(255, 157, 60, 0.75);
  stroke-width: 2.1;
  stroke-linecap: round;
}
#annot-layer .a-head { fill: rgba(255, 157, 60, 0.75); }

/* ---------- history replay ---------- */

#history-layer { position: absolute; inset: 0; pointer-events: none; z-index: 11; }
#history-layer .piece { transition: none; pointer-events: none; }

#pieces-layer.off { visibility: hidden; }
#history-layer.off { display: none; }

#board-frame.viewing #board { filter: saturate(0.5) brightness(0.75); }

#history-note {
  position: absolute;
  left: 50%; bottom: 3%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 6px 16px;
  font-style: italic;
  font-size: 14px;
  color: var(--ember-hot);
  background: rgba(7, 8, 13, 0.85);
  border: 1px solid var(--ember-dim);
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}
#history-note.off { display: none; }

/* ---------- bottom strip: graveyard · replay · hint ---------- */

#hud-bottom {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  height: clamp(60px, 8vh, 104px);
  padding: 0 clamp(28px, 3vw, 60px) clamp(14px, 2vh, 28px);
}

#graveyard-pieces {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 30px;
  overflow: hidden;
}
#graveyard-pieces svg {
  width: clamp(30px, 2.6vw, 46px);
  height: clamp(30px, 2.6vw, 46px);
  opacity: 0.7;
  filter: grayscale(0.6);
}

#replay-nav { display: flex; gap: clamp(8px, 0.8vw, 14px); }

#hud-hint {
  justify-self: end;
  font-style: italic;
  font-size: clamp(15px, 1.2vw, 21px);
  color: var(--ink-dim);
  letter-spacing: 0.5px;
}

/* ---------- fx ---------- */

.spark {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  pointer-events: none;
  animation: spark-fly 0.6s ease-out forwards;
}
@keyframes spark-fly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0.2); opacity: 0; }
}

#board-frame.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translate(0,0); }
  25% { transform: translate(-5px, 3px); }
  50% { transform: translate(4px, -3px); }
  75% { transform: translate(-3px, -2px); }
}

/* ---------- banner ---------- */

#banner {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(7,8,13,0.65), transparent 70%);
  opacity: 1;
  transition: opacity 0.5s;
}
#banner.hidden { opacity: 0; }
#banner-text {
  font-family: "Cinzel", serif;
  font-weight: 900;
  font-size: clamp(36px, 6vw, 72px);
  letter-spacing: 10px;
  color: var(--ember-hot);
  text-shadow: 0 0 30px rgba(255,157,60,0.8), 0 0 80px rgba(255,157,60,0.4);
  animation: banner-in 0.6s ease-out;
}
#banner-sub {
  margin-top: 10px;
  font-style: italic;
  font-size: clamp(14px, 2vw, 22px);
  letter-spacing: 3px;
  color: var(--ink-dim);
  animation: banner-in 0.8s ease-out;
}
@keyframes banner-in {
  0% { opacity: 0; transform: scale(1.3); letter-spacing: 24px; }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- help overlay ---------- */

#help {
  position: fixed; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,5,8,0.85);
  backdrop-filter: blur(4px);
  transition: opacity 0.4s;
  cursor: pointer;
}
#help.hidden { opacity: 0; pointer-events: none; }

.help-inner {
  max-width: 520px;
  padding: 40px 48px;
  text-align: center;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: rgba(10, 12, 19, 0.9);
  box-shadow: 0 0 80px rgba(0,0,0,0.7);
}
.help-inner h3 {
  font-family: "Cinzel", serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 5px;
  color: var(--ember-hot);
  text-shadow: 0 0 20px rgba(255,157,60,0.4);
  margin-bottom: 20px;
}
.help-inner p {
  font-style: italic;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-dim);
}
.help-inner p + p { margin-top: 10px; }

.help-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  margin: 26px 0 8px;
  text-align: left;
}
.help-controls div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.help-controls b {
  font-family: "Cinzel", serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ember);
  white-space: nowrap;
}
.help-controls span { font-size: 14px; color: var(--ink-dim); font-style: italic; }

.help-close-hint {
  margin-top: 22px;
  font-size: 12px !important;
  color: #45423a !important;
}

/* ---------- game over ---------- */

#gameover {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,5,8,0.88);
  backdrop-filter: blur(4px);
  transition: opacity 0.8s;
}
#gameover.hidden { opacity: 0; pointer-events: none; }

.go-inner { text-align: center; padding: 40px; }
.go-inner h2 {
  font-family: "Cinzel", serif;
  font-weight: 900;
  font-size: clamp(32px, 5vw, 60px);
  letter-spacing: 8px;
  color: var(--blood);
  text-shadow: 0 0 40px rgba(195,59,59,0.6);
}
.go-line { margin-top: 12px; font-style: italic; color: var(--ink-dim); font-size: 18px; }

.go-stats {
  display: flex; gap: 44px; justify-content: center; margin: 36px 0;
}
.go-stats div { display: flex; flex-direction: column; gap: 6px; }
.go-stats b {
  font-family: "Cinzel", serif;
  font-size: 44px;
  color: var(--ember-hot);
  text-shadow: 0 0 16px rgba(255,157,60,0.4);
}
.go-stats span {
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  font-family: "Cinzel", serif; color: var(--ink-dim);
}

#btn-again {
  font-family: "Cinzel", serif;
  font-size: 16px;
  padding: 14px 36px;
  letter-spacing: 4px;
  background: #141926;
  border: 1px solid var(--ember-dim);
  border-radius: 4px;
  color: var(--ember-hot);
  cursor: pointer;
  transition: all 0.2s;
}
#btn-again:hover {
  border-color: var(--ember);
  box-shadow: 0 0 18px rgba(255,157,60,0.3);
}

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  #hud-brand { display: none; }
  #hud-wave { position: static; transform: none; }
  #hud-top { justify-content: space-between; }
  #hud-hint { display: none; }
  #hud-bottom { grid-template-columns: 1fr auto; }
}
