<!DOCTYPE html>
<html lang="vi">
<meta charset="utf-8">
<title>Rìu chéo 16×16</title>

<style>
  body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 20px;
    background: #202530;
  }

  canvas {
    width: 256px;
    height: 256px;
    image-rendering: pixelated;
  }

  button {
    padding: 10px 18px;
    cursor: pointer;
  }
</style>

<canvas id="icon" width="16" height="16"></canvas>
<button id="download">Tải PNG 16×16</button>

<script>
  const canvas = document.getElementById("icon");
  const ctx = canvas.getContext("2d");

  const colors = {
    "#": "#161b26", // Viền
    W: "#effaff",   // Lưỡi sáng
    S: "#a4b9cb",   // Thép
    M: "#64798e",   // Đai kim loại
    H: "#d69a52",   // Cán sáng
    h: "#875030"    // Cán tối
  };

  // Nửa trái; phản chiếu để tạo chiếc rìu thứ hai.
  const half = [
    ".##.....",
    "#SS#....",
    "#WSS#...",
    "#WSS##..",
    "#SSS#M#.",
    ".#S#hH#.",
    "..#.#hH#",
    ".....#hH",
    "......#h",
    ".....#hH",
    "....#hH#",
    "...#hH#.",
    "..#hH#..",
    ".#hH#...",
    ".###....",
    "........"
  ];

  half.forEach((left, y) => {
    const row = left + [...left].reverse().join("");

    [...row].forEach((pixel, x) => {
      if (!colors[pixel]) return;
      ctx.fillStyle = colors[pixel];
      ctx.fillRect(x, y, 1, 1);
    });
  });

  // Điểm sáng tại chỗ hai cán giao nhau.
  ctx.fillStyle = colors.H;
  ctx.fillRect(8, 8, 1, 1);

  document.getElementById("download").onclick = () => {
    const link = document.createElement("a");
    link.download = "riu-cheo-16x16.png";
    link.href = canvas.toDataURL("image/png");
    link.click();
  };
</script>
</html>
