* {
  box-sizing: border-box;
}

:root {
  --tile-size: 46px;
  --gap: 6px;
  --cols: 8;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Microsoft YaHei", Arial, sans-serif;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  color: #333;
  min-height: 100vh;
  overscroll-behavior: none;
}

.app {
  width: min(1100px, 96vw);
  margin: 0 auto;
  padding: 14px 0 30px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  gap: 12px;
  margin-bottom: 12px;
}

.header h1 {
  margin: 0;
  font-size: 28px;
  text-shadow: 0 2px 8px rgba(0,0,0,.24);
}

.header p {
  margin: 4px 0 0;
  opacity: .95;
}

.user-box {
  text-align: right;
  font-weight: 800;
}

.card {
  background: rgba(255,255,255,.94);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 10px 28px rgba(0,0,0,.18);
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}

.auth-card {
  max-width: 430px;
  margin: 50px auto;
}

.auth-card h2 {
  margin-top: 0;
  color: #ff5a5f;
}

.form {
  display: grid;
  gap: 10px;
}

input {
  width: 100%;
  border: 2px solid #ffe0e0;
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
  outline: none;
}

input:focus {
  border-color: #ff6b6b;
}

.row,
.actions,
.stats,
.tips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  color: #fff;
  background: #ff6b6b;
  font-weight: 800;
  cursor: pointer;
  transition: .18s;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(.96);
}

button.secondary {
  background: #339af0;
}

button.success {
  background: #51cf66;
}

button.dark {
  background: #495057;
}

button.danger {
  background: #e03131;
}

.msg,
.message {
  min-height: 24px;
  color: #e03131;
  font-weight: 800;
}

.stats span {
  background: #fff4d6;
  border: 1px solid #ffd43b;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 14px;
}

.board-card {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.board {
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  gap: var(--gap);
  justify-content: center;
  padding: 10px;
  user-select: none;
  position: relative;
  z-index: 2;
}

.line-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.link-line {
  fill: none;
  stroke: #ff4d4f;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(255, 77, 79, .45));
  animation: dashMove .28s ease-out forwards;
}

@keyframes dashMove {
  from {
    stroke-dashoffset: 260;
    opacity: .3;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: calc(var(--tile-size) * .52);
  cursor: pointer;
  border: 3px solid transparent;
  box-shadow: 0 4px 0 #ddd, 0 7px 12px rgba(0,0,0,.12);
  position: relative;
  transition: .12s;
  touch-action: manipulation;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile.selected {
  border-color: #ff4d4f;
  background: #fff0f0;
  transform: scale(1.05);
}

.tile.hint {
  border-color: #228be6;
  background: #e7f5ff;
  animation: pulse .65s infinite alternate;
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
}

.tile.blocker {
  cursor: default;
  background: #dee2e6;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.08);
}

.tile.ice {
  background: #e7f5ff;
  border-color: #74c0fc;
}

.tile.hidden-tile {
  background: #fff9db;
}

.tile.chameleon {
  background: #ebfbee;
}

.tile.wild {
  background: linear-gradient(135deg,#ffd43b,#69db7c,#74c0fc,#da77f2);
}

.tile.rotate::after {
  content: "🌪️";
  position: absolute;
  right: -5px;
  top: -9px;
  font-size: calc(var(--tile-size) * .32);
}

.tile.shift-row {
  box-shadow: 0 0 0 3px rgba(255, 193, 7, .45), 0 4px 0 #ddd;
}

.tile.shift-col {
  box-shadow: 0 0 0 3px rgba(51, 154, 240, .45), 0 4px 0 #ddd;
}

.tile .hp {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 11px;
  font-weight: 900;
  color: #c92a2a;
}

.tips {
  font-size: 14px;
}

.leaderboard {
  max-width: 760px;
  margin: 20px auto;
}

.leader-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rank-row {
  display: grid;
  grid-template-columns: 60px 1fr 110px 110px;
  gap: 8px;
  padding: 9px 6px;
  border-bottom: 1px solid #eee;
}

.rank-row.head {
  font-weight: 900;
  color: #ff5a5f;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

@media (max-width: 768px) {
  .app {
    width: 100vw;
    padding: 8px 6px 20px;
  }

  .header h1 {
    font-size: 23px;
  }

  .header p {
    font-size: 12px;
  }

  .card {
    border-radius: 14px;
    padding: 10px;
  }

  .stats span {
    font-size: 12px;
    padding: 6px 8px;
  }

  button {
    padding: 9px 12px;
    font-size: 13px;
  }

  .tile {
    border-radius: 9px;
    border-width: 2px;
  }

  .rank-row {
    grid-template-columns: 46px 1fr 74px 82px;
    font-size: 13px;
  }
}
