.mahjong-tile {
  --tile-ink: #215544;
  --tile-body-light: #548170;
  --tile-body-dark: #203e32;
  --tile-ceramic-light: #fff9e5;
  --tile-ceramic-dark: #ebdbb5;
  --tile-rim: #d5bd86;
  display: block;
  position: relative;
  isolation: isolate;
  container-type: inline-size;
  width: var(--tile-size, 79%);
  aspect-ratio: .88;
  flex: none;
  box-sizing: border-box;
  border: 1px solid var(--tile-body-dark);
  border-radius: 15% / 13%;
  background: linear-gradient(120deg, var(--tile-body-light), var(--tile-body-dark) 92%);
  box-shadow: inset 0 -1px #08120993, 0 2px 3px #080e0da6;
  pointer-events: none;
  user-select: none;
}

.mahjong-tile__face {
  display: grid;
  place-content: center;
  place-items: center;
  position: absolute;
  inset: 1% 0 12%;
  overflow: hidden;
  box-sizing: border-box;
  border: 1px solid var(--tile-rim);
  border-radius: 14%;
  background:
    radial-gradient(ellipse at 15% 6%, #ffffffb8, transparent 69%),
    linear-gradient(154deg, var(--tile-ceramic-light) 21%, var(--tile-ceramic-dark));
  box-shadow: inset 0 0 3px #fff0ce, inset 0 -1px 1px #9e7b433f, 0 1px #10231f65;
  color: var(--tile-ink);
  font-family: 'Kaiti SC', 'STKaiti', KaiTi, 'Songti SC', 'Noto Serif CJK SC', 'Noto Serif SC', serif;
  font-weight: 800;
  line-height: .88;
  text-align: center;
}

.mahjong-tile__mark {
  display: block;
  font-size: 58cqi;
  text-shadow: 0 .8px #ffffffac, 0 -.35px #17110b75;
}

.mahjong-tile[data-tile='flame'] { --tile-ink: #a1261d; }
.mahjong-tile[data-tile='ghost'] { --tile-ink: #1a6249; }
.mahjong-tile[data-tile='planet'] { --tile-ink: #253e55; }
.mahjong-tile[data-tile='planet'] .mahjong-tile__mark { font-size: 48cqi; }

.mahjong-tile__stamp {
  margin-block-start: 3cqi;
  color: #a53724;
  font-size: 30cqi;
  text-shadow: 0 .65px #ffffff91;
}

.mahjong-tile__dots {
  position: relative;
  width: 71cqi;
  aspect-ratio: 1;
}

.mahjong-tile__dot {
  --pip-ink: #1c5e46;
  position: absolute;
  border-radius: 50%;
  color: var(--pip-ink);
}

.mahjong-tile__dots--1 .mahjong-tile__dot {
  inset: 5%;
  background: radial-gradient(circle,
    #a52c22 0 13%, #ffefcb 15% 22%,
    #326449 24% 37%, #f4e4b6 39% 44%,
    #a3291e 46% 56%, #fef0c8 58% 62%,
    #245842 64% 68%, transparent 70%);
  filter: drop-shadow(0 .7px #71513e82);
}

.mahjong-tile__dots--5 .mahjong-tile__dot {
  width: 32%;
  aspect-ratio: 1;
  background: radial-gradient(circle, currentColor 20%, #fff3cf 23% 36%, currentColor 41% 66%, transparent 71%);
  filter: drop-shadow(0 .5px #71453568);
}

.mahjong-tile__dots--5 .mahjong-tile__dot:nth-child(1) { top: 0; left: 0; }
.mahjong-tile__dots--5 .mahjong-tile__dot:nth-child(2) { top: 0; right: 0; }
.mahjong-tile__dots--5 .mahjong-tile__dot:nth-child(3) { --pip-ink: #a92920; top: 34%; left: 34%; }
.mahjong-tile__dots--5 .mahjong-tile__dot:nth-child(4) { bottom: 0; left: 0; }
.mahjong-tile__dots--5 .mahjong-tile__dot:nth-child(5) { right: 0; bottom: 0; }

.mahjong-tile__grove {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7cqi;
  width: 77cqi;
  height: 65cqi;
}

.mahjong-tile__bamboo {
  --bamboo-ink: #285c3a;
  width: 12cqi;
  height: 87%;
  border: 1px solid var(--bamboo-ink);
  border-radius: 35%;
  background:
    repeating-linear-gradient(to bottom, transparent 0 24%, #eee3b1 26% 30%, transparent 32% 45%),
    linear-gradient(to right, var(--bamboo-ink), #60935f 46%, var(--bamboo-ink) 87%);
  box-shadow: 0 .6px #87644056;
}

.mahjong-tile__bamboo:nth-child(2) { --bamboo-ink: #164932; height: 100%; }
.mahjong-tile__bamboo:nth-child(3) { height: 80%; }

.mahjong-tile[data-tile='wild'] {
  --tile-ink: #79500e;
  --tile-body-light: #c1843b;
  --tile-body-dark: #754f20;
  --tile-ceramic-light: #ffe6a8;
  --tile-ceramic-dark: #dc9b3d;
  --tile-rim: #e2ad50;
}

.mahjong-tile[data-tile='prism'] {
  --tile-ink: #174f48;
  --tile-body-light: #52a58b;
  --tile-body-dark: #216350;
  --tile-ceramic-light: #d8f3c3;
  --tile-ceramic-dark: #6ab89f;
  --tile-rim: #77a87f;
}

.mahjong-tile[data-tile='beat'] {
  --tile-ink: #ffe0a0;
  --tile-body-light: #8f4840;
  --tile-body-dark: #6b2e21;
  --tile-ceramic-light: #c85f40;
  --tile-ceramic-dark: #953521;
  --tile-rim: #c58555;
}

.mahjong-tile[data-tile='beat'] .mahjong-tile__face {
  background:
    radial-gradient(ellipse at 16% 7%, #ffebc85c, transparent 66%),
    linear-gradient(154deg, var(--tile-ceramic-light), var(--tile-ceramic-dark));
  box-shadow: inset 0 0 3px #f4a876, inset 0 -1px 1px #742411, 0 1px #5f2b24;
}

.mahjong-tile__seal {
  display: grid;
  place-items: center;
  width: 67cqi;
  height: 68cqi;
  box-sizing: border-box;
  border: 1px solid currentColor;
  border-radius: 16%;
  box-shadow: inset 0 0 0 1px #fff2c783;
}

.mahjong-tile__seal .mahjong-tile__mark { font-size: 48cqi; }
.mahjong-tile[data-tile='beat'] .mahjong-tile__mark { text-shadow: 0 .7px #6b2813; }
.piece.is-matched .mahjong-tile { filter: brightness(1.12) drop-shadow(0 0 5px #f7d089cb); }

.mahjong-tile[data-tile='fortune'] {
  --tile-ink: #ffdc86;
  --tile-body-light: #e1a342;
  --tile-body-dark: #5c2513;
  --tile-rim: #f6c875;
  --tile-entry-glow: #ffd076;
  background: linear-gradient(160deg, #ffde90 10%, #b66e2c 70%, #632511);
  box-shadow: inset 0 -1px #5b2a11, 0 2px 3px #190b09a6, 0 0 6px #f5a74445;
}

.mahjong-tile[data-tile='fortune'] .mahjong-tile__face {
  background:
    radial-gradient(ellipse at 20% 3%, #ffa97784, transparent 55%),
    radial-gradient(ellipse at 78% 91%, #f74b562b, transparent 70%),
    linear-gradient(151deg, #c02330 4%, #8b1425 53%, #480b20 100%);
  box-shadow: inset 0 0 0 1px #c46b45, inset 0 -2px 3px #470a1b, 0 1px 1px #461a0a;
}

.mahjong-tile[data-tile='fortune'] .mahjong-tile__seal {
  position: relative;
  width: 75cqi;
  height: 75cqi;
  border: 0;
  box-shadow: none;
}

.mahjong-tile[data-tile='fortune'] .mahjong-tile__seal::before {
  content: '';
  position: absolute;
  inset: 10%;
  transform: rotate(45deg);
  border: 1px solid #ffd4829e;
  border-radius: 24% 15%;
  box-shadow: inset 0 0 0 1px #1b010d38, 0 0 0 1px #5f150d63;
  background: radial-gradient(ellipse, #5d0926b3, #b0233c6b);
}

.mahjong-tile[data-tile='fortune'] .mahjong-tile__seal::after {
  content: '';
  position: absolute;
  inset: -6%;
  background:
    radial-gradient(circle at 50% 3%, #ffc667 1.1cqi, transparent 1.5cqi),
    radial-gradient(circle at 97% 50%, #ffc667 1.1cqi, transparent 1.5cqi),
    radial-gradient(circle at 50% 97%, #ffc667 1.1cqi, transparent 1.5cqi),
    radial-gradient(circle at 3% 50%, #ffc667 1.1cqi, transparent 1.5cqi);
}

.mahjong-tile[data-tile='fortune'] .mahjong-tile__mark {
  position: relative;
  z-index: 1;
  font-size: 55cqi;
  text-shadow: 0 1px #5b1c0d, 0 0 4px #e88a4944;
}

.mahjong-tile[data-tile='bridge'] {
  --tile-ink: #ffe5ac;
  --tile-body-light: #4683aa;
  --tile-body-dark: #12344d;
  --tile-rim: #a29063;
  --tile-entry-glow: #94dcff;
}

.mahjong-tile[data-tile='bridge'] .mahjong-tile__face {
  background: radial-gradient(ellipse at 12% 7%, #71c6ec72, transparent 56%), linear-gradient(145deg, #24729b, #163e67 65%, #102740);
  box-shadow: inset 0 0 0 1px #5388a77a, inset 0 -2px 3px #102833, 0 1px 1px #142035;
}

.mahjong-tile[data-tile='echo'] {
  --tile-ink: #f8d6b0;
  --tile-body-light: #936b9c;
  --tile-body-dark: #402650;
  --tile-rim: #b68a77;
  --tile-entry-glow: #edbafa;
}

.mahjong-tile[data-tile='echo'] .mahjong-tile__face {
  background: radial-gradient(ellipse at 17% 5%, #d296d378, transparent 54%), linear-gradient(147deg, #9362a7, #603977 58%, #3a244d);
  box-shadow: inset 0 0 0 1px #bd80bc62, inset 0 -2px 3px #2e1840, 0 1px 1px #2b1c36;
}

.mahjong-tile:is([data-tile='bridge'], [data-tile='echo']) .mahjong-tile__seal {
  position: relative;
  width: 76cqi;
  height: 76cqi;
  border-color: #f2dba97d;
  border-radius: 23%;
  box-shadow: inset 0 0 0 1px #0c142d35;
}

.mahjong-tile:is([data-tile='bridge'], [data-tile='echo']) .mahjong-tile__mark {
  position: relative;
  font-size: 52cqi;
  text-shadow: 0 1px #171224;
}

.mahjong-tile[data-tile='bridge'] .mahjong-tile__mark { margin-bottom: 10cqi; }

.mahjong-tile[data-tile='bridge'] .mahjong-tile__seal::before {
  content: '';
  position: absolute;
  right: 14%;
  bottom: 8%;
  left: 14%;
  height: 19%;
  border: 1px solid #ffd994b8;
  border-bottom-color: #ffd9944d;
  border-radius: 50% 50% 1px 1px;
  background: linear-gradient(180deg, #70cced63, transparent 48%);
}

.mahjong-tile[data-tile='echo'] .mahjong-tile__seal::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle, transparent 35%, #f1b5b241 37% 40%, transparent 42% 52%, #f1b5b22a 54% 57%, transparent 59%);
}

@media (prefers-reduced-motion: no-preference) {
  .mahjong-tile[data-tile='prism'] { --tile-entry-glow: #c5ffd7; }
  .mahjong-tile[data-tile='beat'] { --tile-entry-glow: #ffba8e; }

  .piece.is-special-entry .mahjong-tile__face {
    animation: mahjong-special-land .48s cubic-bezier(.24,.75,.25,1) both;
  }

  .mahjong-tile[data-tile='fortune'] .mahjong-tile__face::after {
    content: '';
    position: absolute;
    inset: -38%;
    pointer-events: none;
    background: linear-gradient(114deg, transparent 42%, #fff4c58c 50%, transparent 58%);
    opacity: 0;
    animation: mahjong-fortune-glint 1.06s .29s ease-out both;
  }

  @keyframes mahjong-special-land {
    0% { transform: scale(.84) rotate(-5deg); }
    32% { transform: scale(1.12, 1.16) rotate(3deg); filter: brightness(1.48) drop-shadow(0 0 6px var(--tile-entry-glow, #ffd48c)); }
    62% { transform: scale(.98, .94) rotate(-1deg); filter: brightness(1.12); }
    100% { transform: scale(1); filter: brightness(1); }
  }

  @keyframes mahjong-fortune-glint {
    0% { transform: translateX(-52%); opacity: 0; }
    17% { opacity: .82; }
    80%, 100% { transform: translateX(54%); opacity: 0; }
  }
}
