:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --panel: #241f1a;
  --ink: #f1e9dc;
  --ink-dim: #b5a996;
  --accent: #c44436;
  --accent-2: #4f8a5b;
  --gold: #d3a648;
  --light-sq: #ecdfc4;
  --dark-sq: #7d5a43;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px)
    calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 12px);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* ---------- Landing page ---------- */

.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.brand {
  text-align: center;
  margin-bottom: 4px;
}

.brand .glyphs {
  font-size: clamp(20px, 7vw, 34px);
  line-height: 1;
  letter-spacing: 1px;
  margin-bottom: 8px;
  white-space: nowrap;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 6px 0 0;
  color: var(--ink-dim);
  font-size: 14px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  transition: transform 0.12s ease, background 0.12s ease;
}

.mode-card:active { transform: scale(0.98); background: #2b241d; }

.mode-card .icon {
  font-size: 34px;
  width: 56px;
  height: 56px;
  min-width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
}

.mode-card.bomb .icon { background: rgba(196,68,54,0.18); }
.mode-card.classic .icon { background: rgba(211,166,72,0.18); }

.mode-card .text h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.mode-card .text p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.35;
}

.footnote {
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- Game page ---------- */

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar .back {
  font-size: 22px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--panel);
}

.topbar h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
  color: var(--ink-dim);
  letter-spacing: 0.3px;
}

.topbar .variant-tag {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(196,68,54,0.16);
  color: #e79087;
  font-weight: 600;
}

.topbar .variant-tag.classic {
  background: rgba(211,166,72,0.16);
  color: var(--gold);
}

.status-bar {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--panel);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 600;
  gap: 8px;
}

.status-bar .turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.4);
  flex: none;
}

.status-bar .turn-dot.b { background: #2a2622; border-color: rgba(255,255,255,0.3); }

.status-bar.check { color: #ffb3a8; }
.status-bar.over { color: var(--gold); }

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  perspective: 800px;
}

.board {
  width: min(100%, 92vh - 220px, 560px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  border: 4px solid #2b241c;
  position: relative;
  transition: transform 0.35s ease;
}

.board.flipped { transform: rotate(180deg); }

.board.shake { animation: shake 0.4s ease; }

@keyframes shake {
  0% { transform: translate(0,0); }
  15% { transform: translate(-6px,3px) rotate(-0.5deg); }
  30% { transform: translate(5px,-4px) rotate(0.5deg); }
  45% { transform: translate(-4px,4px) rotate(-0.4deg); }
  60% { transform: translate(4px,-2px) rotate(0.3deg); }
  75% { transform: translate(-2px,2px); }
  100% { transform: translate(0,0); }
}

.board.flipped.shake { animation: shake-flipped 0.4s ease; }
@keyframes shake-flipped {
  0% { transform: rotate(180deg) translate(0,0); }
  15% { transform: rotate(180deg) translate(-6px,3px); }
  30% { transform: rotate(180deg) translate(5px,-4px); }
  45% { transform: rotate(180deg) translate(-4px,4px); }
  60% { transform: rotate(180deg) translate(4px,-2px); }
  75% { transform: rotate(180deg) translate(-2px,2px); }
  100% { transform: rotate(180deg) translate(0,0); }
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--light-sq);
}

.square.dark { background: var(--dark-sq); }

.square .piece {
  font-size: min(9vw, 52px);
  line-height: 1;
  user-select: none;
  transition: transform 0.12s ease;
  will-change: transform;
}

.board.flipped .piece { transform: rotate(180deg); }

.square.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(211,166,72,0.45);
  box-shadow: inset 0 0 0 3px var(--gold);
}

.square.last-from::after, .square.last-to::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255,214,110,0.25);
}

.square.check-king::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,60,40,0.75) 0%, rgba(255,60,40,0.15) 70%);
  animation: pulse-check 0.9s ease-in-out infinite;
}

@keyframes pulse-check {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.square .move-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(60,50,40,0.35);
  pointer-events: none;
}

.square .capture-ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px rgba(196,68,54,0.75);
  pointer-events: none;
}

.square.piece-white .piece {
  color: #fdf6e8;
  text-shadow: 0 1px 0 #8a7654, 0 -1px 1px rgba(0,0,0,0.5), 0 2px 3px rgba(0,0,0,0.45);
}

.square.piece-black .piece {
  color: #1b1712;
  text-shadow: 0 1px 0 rgba(255,255,255,0.18), 0 2px 3px rgba(0,0,0,0.5);
}

/* explosion */
.square .boom {
  position: absolute;
  inset: -60%;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255,238,180,0.95) 0%, rgba(255,140,50,0.85) 30%, rgba(196,68,54,0.7) 55%, rgba(196,68,54,0) 75%);
  transform: scale(0.1);
  opacity: 0;
  animation: boom 0.46s ease-out forwards;
  z-index: 5;
}

@keyframes boom {
  0% { transform: scale(0.1); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

.square .smoke {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70,65,60,0.55), rgba(70,65,60,0));
  opacity: 0;
  animation: smoke 0.7s ease-out forwards;
  animation-delay: 0.1s;
  z-index: 4;
}

@keyframes smoke {
  0% { opacity: 0; transform: scale(0.4); }
  40% { opacity: 0.8; }
  100% { opacity: 0; transform: scale(1.8) translateY(-15%); }
}

.controls {
  width: 100%;
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  padding: 11px 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.btn:active { background: #2b241d; }

.btn .emoji { font-size: 17px; }

.btn.toggle-on {
  background: rgba(79,138,91,0.18);
  border-color: rgba(79,138,91,0.4);
  color: #b7e2bf;
}

.captured-row {
  width: 100%;
  min-height: 22px;
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  color: var(--ink-dim);
  padding: 0 4px;
}

.captured-row span { letter-spacing: 1px; }

/* promotion modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.modal h3 { margin: 0 0 14px; font-size: 15px; color: var(--ink-dim); }

.promo-choices {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.promo-choices button {
  flex: 1;
  font-size: 34px;
  padding: 10px 0;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--bg-2);
  color: var(--ink);
}

.promo-choices button:active { background: #33291f; }

/* game-over modal */
.modal.gameover .big {
  font-size: 40px;
  margin-bottom: 6px;
}

.modal.gameover h3 {
  color: var(--ink);
  font-size: 19px;
  margin-bottom: 4px;
}

.modal.gameover p {
  color: var(--ink-dim);
  font-size: 13px;
  margin: 0 0 16px;
}

.modal.gameover .btn {
  background: var(--accent-2);
  border-color: transparent;
  color: #f4fff5;
}
