:root {
  --bg-deep: #101826;
  --bg-mid: #1b2c3c;
  --panel: rgba(10, 20, 31, 0.8);
  --border: rgba(144, 181, 205, 0.4);
  --text: #eff7fd;
  --muted: #a8bdca;
  --accent: #ffb86c;
  --accent-2: #79ddc9;
  --danger: #f27777;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, #2c4b63 0%, transparent 38%),
    radial-gradient(circle at 95% 100%, #434a6d 0%, transparent 28%),
    linear-gradient(155deg, #0f1722, #122335 58%, #12172a);
}

.war-page {
  width: min(1060px, 94vw);
  margin: 0 auto;
  padding: 1.6rem 0 2rem;
}

.topbar {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  background: var(--panel);
  backdrop-filter: blur(8px);
}

.back-link {
  display: inline-block;
  color: var(--accent-2);
  text-decoration: none;
  margin-bottom: 0.55rem;
  font-size: 0.92rem;
}

.back-link:hover,
.back-link:focus-visible {
  text-decoration: underline;
}

.topbar h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  margin: 0;
}

.topbar p {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.hud {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 0.85rem;
}

.player-box,
.battle-board,
.controls,
.status-wrap,
.log-wrap {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel);
}

.player-box {
  padding: 0.95rem;
}

.player-box h2 {
  margin: 0;
  font-size: 1rem;
}

.pile-row {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.pile {
  border: 1px solid rgba(137, 174, 197, 0.3);
  border-radius: 0.72rem;
  min-height: 98px;
  padding: 0.45rem;
  background: linear-gradient(155deg, rgba(15, 30, 45, 0.95), rgba(9, 16, 24, 0.9));
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.pile::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 10px;
  width: 52px;
  height: 74px;
  border-radius: 0.42rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background:
    repeating-linear-gradient(
      45deg,
      rgba(123, 145, 166, 0.45),
      rgba(123, 145, 166, 0.45) 6px,
      rgba(93, 113, 132, 0.45) 6px,
      rgba(93, 113, 132, 0.45) 12px
    );
}

.pile.won::before {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(236, 179, 110, 0.45),
      rgba(236, 179, 110, 0.45) 6px,
      rgba(165, 119, 69, 0.48) 6px,
      rgba(165, 119, 69, 0.48) 12px
    );
}

.pile-label {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  margin-left: 62px;
}

.pile-count {
  margin-left: 62px;
  font-size: 1.45rem;
  font-weight: 700;
}

.battle-board {
  padding: 0.85rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.battle-side {
  text-align: center;
}

.battle-title,
.stack-count {
  margin: 0;
}

.battle-title {
  font-size: 0.85rem;
  color: var(--muted);
}

.battle-slot {
  margin: 0.45rem auto 0.28rem;
  width: min(100%, 128px);
  min-height: 170px;
  border: 1px dashed rgba(146, 179, 201, 0.5);
  border-radius: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: rgba(9, 16, 24, 0.68);
}

.battle-hint {
  color: #91a8b8;
  font-size: 0.82rem;
}

.stack-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.versus {
  font-family: "Fraunces", Georgia, serif;
  color: var(--accent);
  font-size: 1.2rem;
  letter-spacing: 0.05em;
}

.controls {
  margin-top: 0.9rem;
  padding: 0.95rem;
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 0.62rem;
  color: #08121c;
  font-weight: 700;
  padding: 0.58rem 0.9rem;
  cursor: pointer;
  background: linear-gradient(135deg, #f6bf7f, #f7a75e);
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  color: #d4e4ef;
  background: linear-gradient(130deg, #344d61, #2a3f51);
}

.round-label {
  margin-left: auto;
  color: var(--muted);
}

.status-wrap {
  margin-top: 0.8rem;
  padding: 0.75rem 0.9rem;
}

#status-line {
  margin: 0;
}

.log-wrap {
  margin-top: 0.8rem;
  padding: 0.9rem;
}

.log-wrap h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
}

#battle-log {
  margin: 0;
  padding-left: 1rem;
  color: var(--muted);
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.35;
}

.card {
  width: 84px;
  height: 116px;
  border-radius: 0.58rem;
  border: 1px solid rgba(12, 18, 24, 0.28);
  background: #fcf3e8;
  color: #1b1f29;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 9px 14px rgba(0, 0, 0, 0.28);
}

.card.back {
  border-color: rgba(138, 166, 186, 0.42);
  background:
    repeating-linear-gradient(
      45deg,
      #31495d,
      #31495d 7px,
      #1f3242 7px,
      #1f3242 14px
    );
}

.card-face {
  display: grid;
  place-items: center;
  line-height: 1;
  gap: 0.2rem;
}

.rank {
  font-size: 1.35rem;
  font-weight: 700;
}

.suit {
  font-size: 1.35rem;
}

.suit.red {
  color: var(--danger);
}

.flying-card {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.98;
  will-change: transform, opacity;
  transition: transform 340ms ease, opacity 340ms ease;
}

.pile.flash,
.battle-slot.flash {
  animation: flash 340ms ease;
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 0 rgba(123, 227, 205, 0.35);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(123, 227, 205, 0);
  }
}

@media (max-width: 860px) {
  .hud {
    grid-template-columns: 1fr;
  }

  .battle-board {
    order: -1;
  }

  .round-label {
    margin-left: 0;
  }
}
