:root{
  --mj-bg:#0b1020; --mj-panel:#111a33; --mj-text:#e8ecff; --mj-muted:#aab4e6;
  --mj-tile:#f4f6ff; --mj-tile2:#e8ecff; --mj-shadow:rgba(0,0,0,.35);
  --mj-accent:#7aa2ff; --mj-danger:#ff6b8a; --mj-ok:#67e8a2;
}

.mahjong-app *{ box-sizing:border-box; }

.mahjong-app{
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;
  color:var(--mj-text);
  background:radial-gradient(1200px 700px at 20% 10%, #1a2a66 0%, var(--mj-bg) 55%, #070a14 100%);
  border:1px solid rgba(255,255,255,.09);
  border-radius:18px;
  box-shadow:0 20px 70px var(--mj-shadow);
  overflow:hidden;
  width:min(1100px,100%);
  margin:16px auto;
}

.mahjong-header{
  display:flex; gap:12px; align-items:center; justify-content:space-between;
  padding:14px 16px;
  background:linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border-bottom:1px solid rgba(255,255,255,.08);
  flex-wrap:wrap;
}

.mahjong-title{
  margin:0;
  font-size:16px;
  letter-spacing:.4px;
  font-weight:800;
  display:flex;
  align-items:center;
  gap:10px;
}

.mj-pill{
  display:inline-flex; align-items:center; gap:8px;
  padding:6px 10px; border-radius:999px;
  background:rgba(122,162,255,.14);
  border:1px solid rgba(122,162,255,.25);
  font-weight:800; font-size:12px;
}

.mj-toolbar{
  display:flex; gap:8px; align-items:center; flex-wrap:wrap;
}

.mj-btn{
  appearance:none; border:1px solid rgba(255,255,255,.12);
  background:rgba(17,26,51,.55);
  color:var(--mj-text);
  padding:9px 11px;
  border-radius:12px;
  font-weight:800; font-size:12px;
  cursor:pointer;
  transition:transform .06s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
  user-select:none;
}
.mj-btn:hover{ background:rgba(17,26,51,.75); border-color:rgba(255,255,255,.18) }
.mj-btn:active{ transform:translateY(1px) }
.mj-btn:disabled{ opacity:.45; cursor:not-allowed }
.mj-primary{ background:rgba(122,162,255,.22); border-color:rgba(122,162,255,.35); }
.mj-danger{ background:rgba(255,107,138,.16); border-color:rgba(255,107,138,.28); }
.mj-ok{ background:rgba(103,232,162,.14); border-color:rgba(103,232,162,.28); }

.mahjong-main{
  display:grid;
  grid-template-columns: 1fr 300px;
  gap:14px;
  padding:14px;
}
@media (max-width: 920px){
  .mahjong-main{ grid-template-columns: 1fr; }
}

.mj-board-wrap{
  background:rgba(17,26,51,.35);
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  padding:14px;
  position:relative;
  min-height:540px;
  overflow:auto;
}

.mj-board{
  position:relative;
  width:980px;
  height:600px;
  margin:auto;
  padding:12px;
}

.mj-side{
  background:rgba(17,26,51,.35);
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:540px;
}

.mj-card{
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.08);
  border-radius:14px;
  padding:12px;
}

.mj-row{ display:flex; justify-content:space-between; gap:10px; align-items:center; }
.mj-label{ color:var(--mj-muted); font-weight:800; font-size:12px; }
.mj-value{ font-weight:900; font-size:14px; }

.mj-msg{
  font-size:13px;
  color:var(--mj-text);
  line-height:1.35;
  min-height:44px;
}

.mj-rules{
  font-size:12px;
  color:var(--mj-muted);
  line-height:1.45;
}
.mj-kbd{
  display:inline-block;
  padding:2px 6px;
  border-radius:7px;
  background:rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.10);
  font-weight:900;
  font-size:11px;
  color:var(--mj-text);
}

.mj-footer-note{
  margin-top:auto;
  font-size:11px;
  color:rgba(232,236,255,.65);
  line-height:1.35;
}

/* Tiles */
.mj-tile{
  position:absolute;
  width:64px; height:80px;
  border-radius:14px;
  background:linear-gradient(180deg, var(--mj-tile), var(--mj-tile2));
  border:3px solid rgba(40,40,60,.5);
  box-shadow: 0 8px 14px rgba(0,0,0,.22), 0 3px 0 rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.4);
  display:flex; align-items:center; justify-content:center;
  font-size:22px;
  color:#17224d;
  font-weight:900;
  cursor:pointer;
  transform: translate(var(--x), var(--y));
  transition: transform .08s ease, box-shadow .15s ease, filter .15s ease, opacity .15s ease, background .15s ease;
  user-select:none;
}
.mj-tile::before{
  content:"";
  position:absolute;
  inset:6px 6px 10px 6px;
  border-radius:12px;
  border:1px solid rgba(23,34,77,.14);
  pointer-events:none;
}
.mj-tile.selected{
  background:linear-gradient(180deg, #e8d4f8, #d8b8f0);
  outline:4px solid rgba(180,100,220,.85);
  box-shadow:0 12px 20px rgba(0,0,0,.22), 0 0 0 8px rgba(180,100,220,.25);
}
.mj-tile.locked{
  opacity:.35;
  cursor:not-allowed;
  filter:grayscale(.2);
}
.mj-tile.hint{
  outline:3px solid rgba(103,232,162,.55);
  box-shadow:0 12px 20px rgba(0,0,0,.22), 0 0 0 6px rgba(103,232,162,.12);
}
.mj-tile.removing{
  animation: mj-pop .18s ease forwards;
}
@keyframes mj-pop{
  to{ transform:translate(var(--x), var(--y)) scale(.88); opacity:0; }
}

/* Layer depth */
.mj-layer-0{ z-index:10; }
.mj-layer-1{ z-index:20; filter:drop-shadow(3px 3px 0 rgba(0,0,0,.22)); }
.mj-layer-2{ z-index:30; filter:drop-shadow(6px 6px 0 rgba(0,0,0,.22)); }

/* Modal */
.mj-modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:999999;
}
.mj-modal{
  width:min(520px, 100%);
  background:rgba(17,26,51,.95);
  border:1px solid rgba(255,255,255,.12);
  border-radius:16px;
  box-shadow:0 20px 70px rgba(0,0,0,.45);
  padding:14px;
}
.mj-modal h2{
  margin:0 0 10px 0;
  font-size:16px;
}
.mj-form{
  display:grid;
  gap:10px;
}
.mj-input{
  width:100%;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.06);
  color:var(--mj-text);
  font-weight:800;
}
.mj-small{
  font-size:12px;
  color:var(--mj-muted);
  line-height:1.4;
}
.mj-score-list{
  margin:0;
  padding-left:18px;
  color:var(--mj-text);
  font-size:12px;
  line-height:1.45;
}
.mj-tile .face-main{
  font-size:58px;
  line-height:1;
}

.mj-tile{ font-size:16px; }

.mj-board{
  position:relative;
  width:980px;
  height:600px;
  margin:auto;
  padding:12px;
  transform-origin: top left;

  /* ✅ smooth zoom + pan */
  transition:
    transform 220ms ease,
    left 220ms ease,
    top 220ms ease;
}
/* ===== Leaderboard readability ===== */
.mj-modal{
  color: #e9ecff;
}

.mj-modal h2{
  color:#ffffff;
}

.mj-modal .mj-table{
  background: rgba(10,14,30,.35);
}

.mj-modal .mj-table thead th{
  color:#ffffff;
  font-weight:900;
  text-shadow: 0 2px 6px rgba(0,0,0,.4);
}

.mj-modal .mj-table tbody td{
  color:#f2f4ff;
}

.mj-modal .mj-table tbody tr:nth-child(odd){
  background: rgba(255,255,255,.03);
}

.mj-modal .mj-table tbody tr:hover{
  background: rgba(122,162,255,.12);
}
.mj-win-score{
  font-size:32px;
  font-weight:900;
  letter-spacing:.4px;
}
/* Suit colors */
.mj-tile.suit-dots{
  background:linear-gradient(180deg, #d4e8f8, #b8d4f0);
}
.mj-tile.suit-bamboo{
  background:linear-gradient(180deg, #d4f0d8, #b8e0bc);
}
.mj-tile.suit-characters{
  background:linear-gradient(180deg, #f8e4d4, #f0d0b8);
}
.mj-tile.suit-winds{
  background:linear-gradient(180deg, #f8f4d4, #f0e8b8);
}
.mj-tile.suit-dragons{
  background:linear-gradient(180deg, #f8d4dc, #f0b8c4);
}
/* Tile-styled buttons */
.mj-tile-btn{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  width:100px;
  height:120px;
  border-radius:14px;
  background:linear-gradient(180deg, #f4f6ff, #e8ecff);
  border:3px solid rgba(40,40,60,.5);
  box-shadow: 0 8px 14px rgba(0,0,0,.22), 0 3px 0 rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.6);
  cursor:pointer;
  transition: transform .1s ease, box-shadow .15s ease;
  color:#17224d;
  padding:8px;
}
.mj-tile-btn:hover{
  transform:translateY(-2px);
  box-shadow: 0 12px 20px rgba(0,0,0,.25), 0 4px 0 rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.6);
}
.mj-tile-btn:active{
  transform:translateY(1px);
}
.mj-tile-btn-icon{
  font-size:32px;
  line-height:1;
}
.mj-tile-btn-text{
  font-size:16px;
  font-weight:900;
  margin-top:4px;
}
.mj-tile-btn-sub{
  font-size:11px;
  font-weight:600;
  opacity:.7;
  margin-top:2px;
}

/* Smaller tile buttons for level grid */
.mj-tile-btn-sm{
  width:80px;
  height:85px;
  padding:6px;
}
.mj-tile-btn-sm .mj-tile-btn-text{
  font-size:16px;
  white-space: nowrap;
}
/* Level indicator in corner */
.mj-level-indicator {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 18px;
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0 0 8px rgba(100, 180, 255, 0.9),
    0 0 16px rgba(100, 180, 255, 0.6),
    0 0 24px rgba(100, 180, 255, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.5);
  z-index: 100;
  letter-spacing: 1px;
  pointer-events: none;
}

/* Collected suits box: transparent so board shows through */
.mj-suit-stack{
  background: transparent;
  border: none;
  padding: 0;
}

/* Two-column special button grid for Random + Latest Record */
.mj-special-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Make these special buttons adapt to the grid */
.mj-special-grid .mj-tile-btn{
  width: 100%;
}

/* Responsive: stack on smaller screens */
@media (max-width: 600px){
  .mj-special-grid{
    grid-template-columns: 1fr;
  }
}

@keyframes mj-pulse-collect {
  0%, 100% {
    transform: scale(0.45);
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
  }
  50% {
    transform: scale(0.52);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.4);
  }
}

.mj-tile.pulse-collect {
  animation: mj-pulse-collect 1.2s ease-in-out infinite;
  z-index: 10 !important;
}
@keyframes mj-pulse-next {
  0%, 100% {
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4), 0 0 16px rgba(255, 215, 0, 0.2);
  }
  50% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.9), 0 0 40px rgba(255, 215, 0, 0.5), 0 0 60px rgba(255, 215, 0, 0.3);
  }
}

.mj-btn.mj-next-level {
  background: linear-gradient(135deg, #f0ad4e 0%, #ec971f 100%);
  border-color: #d58512;
  color: #fff;
  font-weight: 900;
  animation: mj-pulse-next 1.5s ease-in-out infinite;
}

.mj-btn.mj-next-level:hover {
  background: linear-gradient(135deg, #ec971f 0%, #d58512 100%);
  box-shadow: 0 0 30px rgba(255, 215, 0, 1), 0 0 50px rgba(255, 215, 0, 0.6);
}
/* Pulse animation for 3rd, 7th, 11th, 15th cards in collection */
@keyframes mj-pulse-collect {
  0%, 100% {
    transform: scale(0.45);
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
  }
  50% {
    transform: scale(0.52);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.4);
  }
}

.mj-tile.pulse-collect {
  animation: mj-pulse-collect 1.2s ease-in-out infinite;
  z-index: 10 !important;
}

/* Next Level button with pulsing glow */
@keyframes mj-pulse-next {
  0%, 100% {
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.4), 0 0 16px rgba(255, 215, 0, 0.2);
  }
  50% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.9), 0 0 40px rgba(255, 215, 0, 0.5), 0 0 60px rgba(255, 215, 0, 0.3);
  }
}

.mj-btn.mj-next-level {
  background: linear-gradient(135deg, #f0ad4e 0%, #ec971f 100%);
  border-color: #d58512;
  color: #fff;
  font-weight: 900;
  animation: mj-pulse-next 1.5s ease-in-out infinite;
}

.mj-btn.mj-next-level:hover {
  background: linear-gradient(135deg, #ec971f 0%, #d58512 100%);
  box-shadow: 0 0 30px rgba(255, 215, 0, 1), 0 0 50px rgba(255, 215, 0, 0.6);
}
.mj-score-indicator {
  position: absolute;
  left: 20px;
  top: 46px;
  font-size: 18px;
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 8px rgba(100, 180, 255, 0.9),
    0 0 16px rgba(100, 180, 255, 0.6),
    0 0 24px rgba(100, 180, 255, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.5);
  letter-spacing: 1px;
  z-index: 100;
  pointer-events: none;
}


/* ===== PvP ===== */
.mj-btn.mj-pvp{
  border-color: rgba(255, 185, 90, .35);
}
.mj-pvp-card .mj-emotes{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  margin-top:6px;
}
.mj-btn.mj-emote{
  padding:8px 10px;
  min-width:44px;
  font-size:16px;
}
.mj-pvp-wait{
  position:absolute;
  left:50%;
  top:18px;
  transform:translateX(-50%);
  padding:10px 14px;
  background: rgba(0,0,0,.55);
  border:1px solid rgba(255,255,255,.12);
  border-radius:12px;
  font-weight:900;
  z-index:50;
  pointer-events:none;
  backdrop-filter: blur(8px);
}
.mj-board-wrap{ position:relative; }
/* PvP Turn Indicator */
.mj-turn-indicator {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 1px;
  z-index: 100;
  pointer-events: none;
  text-transform: uppercase;
}

.mj-turn-indicator.your-turn {
  background: rgba(103, 232, 162, 0.25);
  border: 2px solid rgba(103, 232, 162, 0.6);
  color: #67e8a2;
  text-shadow: 0 0 10px rgba(103, 232, 162, 0.8);
  animation: mj-pulse-your-turn 1.5s ease-in-out infinite;
}

.mj-turn-indicator.other-turn {
  background: rgba(255, 170, 100, 0.2);
  border: 2px solid rgba(255, 170, 100, 0.5);
  color: #ffaa64;
  text-shadow: 0 0 10px rgba(255, 170, 100, 0.6);
  animation: mj-pulse-other-turn 2s ease-in-out infinite;
}

@keyframes mj-pulse-your-turn {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(103, 232, 162, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(103, 232, 162, 0.7), 0 0 40px rgba(103, 232, 162, 0.4);
  }
}

@keyframes mj-pulse-other-turn {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 8px rgba(255, 170, 100, 0.3);
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 20px rgba(255, 170, 100, 0.5), 0 0 35px rgba(255, 170, 100, 0.3);
  }
}

/* Shake animation for the waiting indicator when board is touched */
.mj-pvp-wait.shake {
  animation: mj-shake-grow 0.5s ease-in-out;
}

@keyframes mj-shake-grow {
  0% { transform: translateX(-50%) scale(1); }
  10% { transform: translateX(-50%) scale(1.15) rotate(-3deg); }
  20% { transform: translateX(-50%) scale(1.2) rotate(3deg); }
  30% { transform: translateX(-50%) scale(1.2) rotate(-3deg); }
  40% { transform: translateX(-50%) scale(1.15) rotate(3deg); }
  50% { transform: translateX(-50%) scale(1.1) rotate(-2deg); }
  60% { transform: translateX(-50%) scale(1.05) rotate(2deg); }
  70% { transform: translateX(-50%) scale(1.02) rotate(-1deg); }
  80% { transform: translateX(-50%) scale(1.01) rotate(1deg); }
  100% { transform: translateX(-50%) scale(1) rotate(0deg); }
}

/* PvP Round Over Modal Styling */
.mj-round-win {
  animation: mj-bounce-in 0.5s ease-out;
}

.mj-round-lose {
  animation: mj-shake-sad 0.5s ease-out;
}

.mj-round-draw {
  animation: mj-pulse-draw 1s ease-in-out infinite;
}

@keyframes mj-bounce-in {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes mj-shake-sad {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-10px); }
  80% { transform: translateX(10px); }
}

@keyframes mj-pulse-draw {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* PvP remote selection highlight */
.mj-tile.remote-selected {
  outline: 4px solid rgba(255, 170, 100, 0.85);
  box-shadow: 0 12px 20px rgba(0,0,0,.22), 0 0 0 8px rgba(255, 170, 100, 0.25);
  animation: mj-pulse-remote 1.5s ease-in-out infinite;
}

@keyframes mj-pulse-remote {
  0%, 100% {
    outline-color: rgba(255, 170, 100, 0.85);
    box-shadow: 0 12px 20px rgba(0,0,0,.22), 0 0 0 8px rgba(255, 170, 100, 0.25);
  }
  50% {
    outline-color: rgba(255, 200, 100, 1);
    box-shadow: 0 12px 20px rgba(0,0,0,.22), 0 0 0 12px rgba(255, 170, 100, 0.4);
  }
}

/* Match explosion animation */
@keyframes mj-match-explode {
  0% {
    transform: translate(var(--x), var(--y)) scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  40% {
    transform: translate(var(--x), var(--y)) scale(1.5);
    filter: brightness(1.8) saturate(1.5);
  }
  70% {
    transform: translate(var(--x), var(--y)) scale(1.8);
    opacity: 0.6;
    filter: brightness(2.5) saturate(2);
  }
  100% {
    transform: translate(var(--x), var(--y)) scale(2.2);
    opacity: 0;
    filter: brightness(3) saturate(0);
  }
}

.mj-tile.match-exploding {
  animation: mj-match-explode 0.4s ease-out forwards;
  z-index: 9999 !important;
}