:root {
  color-scheme: light;
  --wood-base: #6b4423;
  --wood-mid: #8b5a2b;
  --wood-light: #a67c52;
  --wood-dark: #4a2f18;
  --grid-line: rgba(42, 24, 12, 0.55);
  --text: #2c1810;
  --panel: #f5ebe0;
  --accent: #1a4d2e;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #5c4030 0%, #3d2914 50%, #2a1c12 100%);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#app {
  width: 100%;
  max-width: 52rem;
}

.shell {
  background: var(--panel);
  border-radius: 14px;
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

header {
  text-align: center;
  margin-bottom: 1rem;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.sub {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

select,
button {
  font: inherit;
  cursor: pointer;
}

select {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #c4b5a5;
  background: #fff;
  color: var(--text);
}

.btn {
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn.secondary {
  background: #6b5b4f;
}

.btn.nuke-btn {
  background: linear-gradient(180deg, #e85d04 0%, #9d0208 55%, #6a0404 100%);
  box-shadow: 0 2px 8px rgba(157, 2, 8, 0.45);
}

.btn.nuke-btn:hover {
  filter: brightness(1.12);
}

.stats {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.stats span {
  font-variant-numeric: tabular-nums;
}

.status {
  text-align: center;
  min-height: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.status.win {
  color: #1a5c1a;
}

.status.lose {
  color: #8b2323;
}

.status.draw {
  color: #5c4a3a;
}

.board-wrap {
  display: flex;
  justify-content: center;
  padding: 0.5rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 0;
  width: min(92vw, 28rem);
  aspect-ratio: 1;
  padding: 0.5rem;
  border-radius: 6px;
  border: 6px solid var(--wood-dark);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    0 8px 28px rgba(0, 0, 0, 0.45);
  background-color: var(--wood-base);
  background-image:
    url("wood.jpg"),
    repeating-linear-gradient(
      92deg,
      transparent,
      transparent 2px,
      rgba(62, 38, 20, 0.12) 2px,
      rgba(62, 38, 20, 0.12) 3px
    ),
    repeating-linear-gradient(
      4deg,
      transparent,
      transparent 6px,
      rgba(40, 22, 10, 0.08) 6px,
      rgba(40, 22, 10, 0.08) 7px
    ),
    linear-gradient(
      145deg,
      var(--wood-light) 0%,
      var(--wood-mid) 38%,
      var(--wood-base) 62%,
      var(--wood-dark) 100%
    );
  background-size: cover, auto, auto, auto;
  background-position: center;
  background-blend-mode: multiply, multiply, soft-light, normal;
}

.cell {
  position: relative;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--grid-line), var(--grid-line)) center/100% 1px no-repeat,
    linear-gradient(var(--grid-line), var(--grid-line)) center/1px 100% no-repeat;
  pointer-events: none;
  opacity: 0.9;
}

.cell:focus-visible {
  outline: 2px solid #2d6a4f;
  outline-offset: -2px;
  z-index: 1;
}

.cell:disabled {
  cursor: default;
}

.stone {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  pointer-events: none;
  box-shadow:
    inset 0 -3px 6px rgba(0, 0, 0, 0.45),
    inset 0 2px 4px rgba(255, 255, 255, 0.15),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.stone.black {
  background: radial-gradient(
    circle at 32% 28%,
    #4a4a4a 0%,
    #0a0a0a 55%,
    #000 100%
  );
  border: 1px solid #222;
}

.stone.white {
  background: radial-gradient(
    circle at 32% 28%,
    #ffffff 0%,
    #e8e4dc 45%,
    #c8c2b8 100%
  );
  border: 1px solid #9a948a;
}

/* Nuke system */
.nuke-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483640;
  background: #120308;
  overflow: hidden;
  pointer-events: none;
}

.nuke-overlay.nuke-active {
  pointer-events: all;
}

.nuke-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  animation: nuke-flash-seq 2.9s ease-out forwards;
}

@keyframes nuke-flash-seq {
  0% {
    opacity: 0;
  }
  6% {
    opacity: 1;
  }
  18% {
    opacity: 0.92;
  }
  35% {
    opacity: 0.35;
  }
  100% {
    opacity: 0;
  }
}

.nuke-fireball {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 32px;
  height: 32px;
  margin: -16px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    #fff9c4 0%,
    #ff9800 35%,
    #e65100 55%,
    #bf360c 100%
  );
  box-shadow:
    0 0 60px 30px rgba(255, 152, 0, 0.9),
    0 0 100px 50px rgba(255, 87, 34, 0.6);
  animation: nuke-fireball-expand 2.85s cubic-bezier(0.25, 0.46, 0.45, 0.94)
    forwards;
}

@keyframes nuke-fireball-expand {
  0% {
    transform: scale(0.2);
    opacity: 1;
  }
  25% {
    transform: scale(25);
    opacity: 1;
  }
  100% {
    transform: scale(95);
    opacity: 0;
  }
}

.nuke-shockwave {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 48px;
  height: 48px;
  margin: -24px;
  border-radius: 50%;
  border: 3px solid rgba(255, 235, 180, 0.95);
  animation: nuke-shockwave-out 2.6s ease-out forwards;
}

@keyframes nuke-shockwave-out {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(120);
    opacity: 0;
  }
}

.nuke-smoke {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 200px;
  height: 240px;
  margin: -120px -100px;
  background: radial-gradient(
    ellipse at 50% 100%,
    rgba(40, 20, 10, 0.95) 0%,
    rgba(20, 10, 5, 0.7) 45%,
    transparent 70%
  );
  animation: nuke-mushroom-rise 2.8s ease-out forwards;
  opacity: 0;
}

@keyframes nuke-mushroom-rise {
  0% {
    transform: scale(0.3) translateY(20%);
    opacity: 0;
  }
  30% {
    opacity: 0.85;
  }
  100% {
    transform: scale(4) translateY(-25%);
    opacity: 0;
  }
}

body.nuke-shaking {
  animation: nuke-screen-shake 0.45s ease-in-out 6;
}

@keyframes nuke-screen-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-6px, 3px);
  }
  40% {
    transform: translate(8px, -4px);
  }
  60% {
    transform: translate(-5px, -3px);
  }
  80% {
    transform: translate(5px, 2px);
  }
}

/* March salute (canvas sits inside) */
.march-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483641;
  background: linear-gradient(180deg, #2d4a6f 0%, #1a2744 40%, #0d1520 100%);
  cursor: pointer;
}

.march-overlay canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.march-hint {
  position: absolute;
  bottom: 1rem;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;
}

.march-label {
  position: absolute;
  top: 0.75rem;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 220, 150, 0.9);
  font-size: clamp(0.8rem, 2vw, 1rem);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  pointer-events: none;
  text-shadow: 0 0 12px rgba(255, 100, 50, 0.5);
}

/* Star Wars–style win crawl */
.sw-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  background: #000;
  cursor: pointer;
  overflow: hidden;
  font-family: "Segoe UI", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
}

.sw-overlay * {
  cursor: pointer;
}

.sw-stars {
  position: absolute;
  inset: 0;
  background-color: #000;
  background-image:
    radial-gradient(1px 1px at 8% 12%, rgba(255, 255, 255, 0.95), transparent),
    radial-gradient(1px 1px at 22% 35%, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(1px 1px at 41% 8%, rgba(255, 255, 255, 0.85), transparent),
    radial-gradient(1px 1px at 55% 62%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 73% 18%, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1px 1px at 88% 44%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1px 1px at 15% 78%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1px 1px at 67% 88%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 92% 12%, rgba(255, 255, 255, 0.65), transparent),
    radial-gradient(1px 1px at 33% 52%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 48% 91%, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(1px 1px at 6% 48%, rgba(255, 255, 255, 0.45), transparent),
    radial-gradient(2px 2px at 28% 22%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(1px 1px at 61% 33%, rgba(255, 255, 255, 0.85), transparent),
    radial-gradient(1px 1px at 79% 71%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1px 1px at 95% 56%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1px 1px at 12% 91%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 44% 15%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 52% 48%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 84% 29%, rgba(255, 255, 255, 0.9), transparent);
  background-size: 100% 100%;
}

.sw-crawl-hint {
  position: absolute;
  bottom: 1rem;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 2;
  pointer-events: none;
}

.sw-crawl-stage {
  position: absolute;
  inset: 0;
  perspective: 380px;
  overflow: hidden;
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 8%,
    black 72%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 8%,
    black 72%,
    transparent 100%
  );
}

.sw-crawl-tilt {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5%;
  height: 85%;
  transform-origin: 50% 100%;
  transform: rotateX(28deg) scale(0.92);
}

.sw-crawl-track {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0;
  animation: sw-crawl-scroll 55s linear infinite;
  will-change: transform;
}

@keyframes sw-crawl-scroll {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(0, -50%, 0);
  }
}

.sw-crawl-block {
  color: #ffe81f;
  text-align: justify;
  font-size: clamp(1rem, 3.2vw, 1.35rem);
  line-height: 1.65;
  font-weight: 500;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.9);
  margin: 0 0 4rem;
}

.sw-crawl-title {
  text-align: center;
  font-size: clamp(1.15rem, 4.5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 2.5rem 0 0;
  line-height: 1.25;
}

.sw-crawl-body {
  margin: 0;
  word-spacing: 0.35em;
  letter-spacing: 0.06em;
  min-height: 2rem;
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.35rem;
  }

  .stats {
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
  }
}
