* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1f2120;
  color: #fbf3e4;
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(120% 70% at 50% 0%, #3a1430 0%, #1f2120 62%);
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Layout: the board scales with the iframe ---------- */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px 12px;
  /* One square; the framed board is 8.36 squares across. */
  --cell: min(calc((100vw - 24px) / 8.4), calc((100vh - 128px) / 8.4), 84px);
}

.hud {
  flex: none;
  width: 100%;
  max-width: max(296px, calc(var(--cell) * 8.36));
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "scores tools"
    "status status";
  align-items: center;
  gap: 4px 8px;
}

.scores {
  grid-area: scores;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.chip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 4px 12px 4px 7px;
  border: 2px solid #46443e;
  border-radius: 999px;
  background: #2a2c2a;
  font-weight: 800;
  font-size: clamp(15px, 3.4vmin, 19px);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chip.p1.active {
  border-color: #ffc857;
  box-shadow: 0 0 0 3px rgb(255 200 87 / 0.22);
}

.chip.p2.active {
  border-color: #ff6b8e;
  box-shadow: 0 0 0 3px rgb(255 107 142 / 0.22);
}

.chip-score {
  min-width: 1.2em;
  text-align: right;
  font-size: 1.1em;
}

.tools {
  grid-area: tools;
  display: flex;
  gap: 6px;
}

.status {
  grid-area: status;
  margin: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  font-size: clamp(15px, 3.4vmin, 20px);
  color: #f1e8d6;
  text-align: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: #2a2c2a;
  color: #d9cfbd;
  cursor: pointer;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:hover {
  background: #363836;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-btn:focus-visible,
.btn:focus-visible,
.seg:focus-visible {
  outline: 3px solid #c6f432;
  outline-offset: 3px;
}

.stage {
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Board ---------- */

.board-wrap {
  position: relative;
  width: calc(var(--cell) * 8.36);
  height: calc(var(--cell) * 8.36);
  padding: 0.18em;
  font-size: var(--cell); /* 1em = one square inside the board */
  border-radius: 0.26em;
  background: radial-gradient(circle at 50% 30%, #5d34c7, #361b78);
  border: 1px solid rgba(255, 200, 87, 0.35);
  box-shadow:
    0 0.1em 0 #281259,
    0 0.3em 0.8em rgb(0 0 0 / 0.55),
    inset 0 0.04em 0.08em rgba(255, 255, 255, 0.2);
  touch-action: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 8em;
  height: 8em;
  border-radius: 0.1em;
  overflow: hidden;
}

.sq {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  font: inherit;
  color: inherit;
  cursor: default;
}

.sq.light {
  background: #e4dafc;
}

.sq.dark {
  background: #3c2a86;
}

.app.can-act .sq.dark {
  cursor: pointer;
}

.sq:focus-visible {
  z-index: 3;
  outline: 3px solid #c6f432;
  outline-offset: -3px;
}

.sq.last {
  background: #55389e;
}

/* Legal destinations: a mint dot (step) or a mint ring (jump). */
.sq.target::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.3em;
  height: 0.3em;
  margin: -0.15em 0 0 -0.15em;
  border-radius: 50%;
  background: #27d6c1;
  box-shadow: 0 0 0 0.05em #1f2120;
  animation: beckon 0.9s ease-in-out infinite alternate;
}

.sq.target.jump::after {
  width: 0.56em;
  height: 0.56em;
  margin: -0.28em 0 0 -0.28em;
  background: transparent;
  border: 0.08em solid #27d6c1;
  box-shadow:
    0 0 0 0.04em #1f2120,
    inset 0 0 0 0.04em #1f2120;
}

.sq.selected {
  background: #4e3aa8;
}

/* Pieces that must jump: a dashed ring around the square. */
.sq.must::before {
  content: "";
  position: absolute;
  inset: 0.05em;
  border: 0.05em dashed #fbf3e4;
  border-radius: 50%;
}

.sq.nope {
  animation: nope 0.32s ease;
}

.app.cpu-turn .sq.dark {
  cursor: progress;
}

/* ---------- Pieces ---------- */

.pieces {
  position: absolute;
  left: 0.18em;
  top: 0.18em;
  width: 8em;
  height: 8em;
  pointer-events: none;
}

.piece {
  position: absolute;
  width: 0.8em;
  height: 0.8em;
  left: calc(var(--c, 0) * 1em + 0.1em);
  top: calc(var(--r, 0) * 1em + 0.1em);
  border-radius: 50%;
  transition: transform 0.14s ease, filter 0.3s ease;
}

.piece svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.piece.p1 {
  background: radial-gradient(circle at 50% 36%, #fff0c2 0 14%, #ffc857 52%, #e09a1f 100%);
  box-shadow:
    0 0.07em 0 #a56508,
    0 0.12em 0.14em rgb(0 0 0 / 0.35),
    inset 0 0.03em 0 rgb(255 255 255 / 0.5);
}

.piece.p2 {
  background: radial-gradient(circle at 50% 36%, #ffd5df 0 12%, #ff6b8e 52%, #d93462 100%);
  box-shadow:
    0 0.07em 0 #9b1c45,
    0 0.12em 0.14em rgb(0 0 0 / 0.35),
    inset 0 0.03em 0 rgb(255 255 255 / 0.45);
}

.piece .mark {
  stroke: rgb(120 60 0 / 0.55);
}

.piece.p2 .mark {
  stroke: rgb(110 14 50 / 0.6);
}

.piece .crown {
  display: none;
  fill: #fffbea;
  stroke: rgb(40 20 0 / 0.6);
  stroke-width: 0.7;
  stroke-linejoin: round;
}

.piece.king .crown {
  display: block;
}

.piece.king {
  outline: 0.04em solid rgb(255 255 255 / 0.85);
  outline-offset: -0.04em;
}

.piece.lifted {
  z-index: 4;
  transform: translateY(-0.05em) scale(1.08);
  outline: 0.05em solid #27d6c1;
  outline-offset: 0.03em;
}

.piece.moving,
.piece.dragging {
  z-index: 5;
}

.piece.dragging {
  transition: none;
  filter: drop-shadow(0 0.12em 0.12em rgb(0 0 0 / 0.45));
}

.board.ended ~ .pieces .piece {
  filter: saturate(0.8);
}

.piece.mini {
  position: relative;
  left: auto;
  top: auto;
  display: inline-block;
  flex: none;
  width: 0.8em;
  height: 0.8em;
  font-size: 26px;
  box-shadow: inset 0 -0.06em 0 rgb(0 0 0 / 0.2);
}

.piece.mini::after {
  content: "";
  position: absolute;
  inset: 26%;
  border: 0.06em solid rgb(120 60 0 / 0.55);
  border-radius: 50%;
}

.piece.mini.p2::after {
  inset: 24%;
  border: 0;
  background: rgb(110 14 50 / 0.5);
  border-radius: 0;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.piece.mini.king::after {
  inset: 22%;
  border: 0;
  border-radius: 0;
  background: #fffbea;
  clip-path: polygon(5% 90%, 0 25%, 30% 50%, 50% 5%, 70% 50%, 100% 25%, 95% 90%);
}

.status .piece.mini {
  font-size: 22px;
}

.app.cpu-turn .status .piece.mini {
  animation: think 0.55s ease-in-out infinite alternate;
}

/* ---------- Screens ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 16px;
  text-align: center;
  background: rgb(31 33 32 / 0.9);
  overflow-y: auto;
}

.overlay h1,
.overlay h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.overlay h1 {
  font-size: clamp(34px, 9vmin, 64px);
}

.overlay h2 {
  font-size: clamp(28px, 7vmin, 48px);
}

.goal {
  margin: 0;
  max-width: 36ch;
  color: #d9cfbd;
  font-size: clamp(15px, 2.8vmin, 19px);
  text-wrap: balance;
}

.hint {
  margin: 0;
  max-width: 40ch;
  color: #b3a995;
  font-size: 14px;
}

.record {
  margin: -2px 0 0;
  color: #d9cfbd;
  font-size: 14px;
  font-weight: 600;
}

.logo-pieces {
  display: flex;
  gap: 8px;
}

.logo-pieces .piece.mini {
  font-size: clamp(30px, 6vmin, 44px);
}

.menu {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(100%, 320px);
}

.btn {
  min-width: 160px;
  min-height: 52px;
  padding: 12px 24px;
  border: 0;
  border-radius: 999px;
  background: #ee5e24;
  color: #15130f;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8400f;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #b8400f;
}

.btn.alt {
  background: #27d6c1;
  color: #1f2120;
  box-shadow: 0 6px 0 #138f81;
}

.btn.alt:active {
  box-shadow: 0 3px 0 #138f81;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: #2a2c2a;
  border: 1px solid #46443e;
}

.seg {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #d9cfbd;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.seg[aria-pressed="true"] {
  background: #ffc857;
  color: #1f2120;
}

.seg[aria-pressed="true"]::before {
  content: "\2713\00a0";
}

.overlay.result {
  justify-content: flex-start;
  padding-top: 12px;
  background: rgb(31 33 32 / 0.35);
}

.card {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 18px 18px;
  border: 2px solid #46443e;
  border-radius: 24px;
  background: #2a2c2a;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.55);
  animation: card-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.card h2 {
  font-size: clamp(24px, 4.6vmin, 34px);
}

.sub {
  margin: 0;
  color: #d9cfbd;
  font-size: 15px;
  text-wrap: balance;
}

.near-miss {
  margin: 4px 0 6px;
  padding: 6px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffb86c;
  background: rgba(255, 184, 108, 0.12);
  border: 1px solid rgba(255, 184, 108, 0.35);
  border-radius: 999px;
  text-align: center;
  animation: pulse-near-miss 1.8s ease-in-out infinite;
}

@keyframes pulse-near-miss {
  0%, 100% {
    transform: scale(1);
    opacity: 0.95;
  }
  50% {
    transform: scale(1.02);
    opacity: 1;
  }
}

.match {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.tally {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #1f2120;
  font-size: 15px;
  font-weight: 700;
}

.next {
  margin: 0;
  color: #b3a995;
  font-size: 13px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.btn.small {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 10px;
  font-size: 16px;
  white-space: nowrap;
}

@media (max-width: 360px) {
  .chip {
    padding-right: 9px;
    gap: 5px;
  }

  .card {
    padding: 14px 14px 16px;
  }
}

/* Landscape phones: the HUD moves to a side column so the board can grow. */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    flex-direction: row;
    gap: 16px;
    padding: 8px 12px;
    --cell: min(calc((100vw - 250px) / 8.4), calc((100vh - 16px) / 8.4), 84px);
  }

  .hud {
    width: 200px;
    max-width: none;
    grid-template-columns: 1fr;
    grid-template-areas:
      "scores"
      "status"
      "tools";
    justify-items: center;
    row-gap: 12px;
  }

  .scores {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .chip-score {
    margin-left: auto;
  }

  .status {
    flex-wrap: wrap;
  }
}

@media (orientation: landscape) {
  .overlay.result {
    justify-content: center;
    align-items: flex-start;
    padding: 12px;
  }

  .card {
    width: min(100%, 280px);
  }

  .row {
    flex-direction: column;
  }

  .btn.small {
    flex: none;
  }
}

@media (max-height: 460px) {
  .overlay {
    gap: 8px;
    padding: 10px 16px;
  }

  .logo-pieces,
  .goal {
    display: none;
  }

  .btn {
    min-height: 46px;
    padding: 8px 20px;
  }
}

/* Pause freezes every running CSS animation. */
.is-paused *,
.is-paused *::before,
.is-paused *::after {
  animation-play-state: paused !important;
}

/* ---------- Animations ---------- */

@keyframes beckon {
  from {
    transform: scale(0.85);
  }
  to {
    transform: scale(1.1);
  }
}

@keyframes think {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-4px);
  }
}

@keyframes nope {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sq.target::after,
  .app.cpu-turn .status .piece.mini,
  .card,
  .sq.nope {
    animation: none;
  }

  .piece {
    transition: none;
  }
}

/* ---------- Canvas and Campaign Additions ---------- */
.board-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 128px);
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  touch-action: none;
  cursor: pointer;
}

.primary-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706) !important;
  color: #1a1005 !important;
  font-weight: 800 !important;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35) !important;
}

.primary-accent:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
  transform: translateY(-2px);
}

.campaign-card {
  max-width: 480px;
  width: 95%;
  max-height: 88vh;
  overflow-y: auto;
}

.campaign-tier-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  justify-content: center;
  flex-wrap: wrap;
}

.tier-tab {
  padding: 6px 12px;
  border: 1px solid #3b3f58;
  border-radius: 8px;
  background: #1a1d2b;
  color: #c5ccdc;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.tier-tab.active {
  background: #ffc857;
  color: #1a1005;
  border-color: #ffd885;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0 16px;
}

.stage-node {
  padding: 8px 4px;
  background: #1a1d2b;
  border: 2px solid #2e334d;
  border-radius: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.2s;
}

.stage-node.locked {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(1);
}

.stage-node:not(.locked):hover {
  border-color: #ffc857;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(255, 200, 87, 0.25);
}

.stage-node.current {
  border-color: #38bdf8;
  background: #1e293b;
}

.stage-stars {
  font-size: 10px;
  color: #ffc857;
}

.stars-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 28px;
  color: #ffc857;
  margin: 8px 0;
}

