/* 2048 网站 · 完整样式 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --pad: 10px; --gap: 10px; }

body {
  font-family: "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #faf8ef;
  color: #776e65;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}
.container { width: 100%; max-width: 640px; }

/* ========== 头部 ========== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 8px;
}
header .left { display: flex; align-items: center; gap: 12px; }
h1 { font-size: 44px; font-weight: 700; color: #776e65; }

.scores { display: flex; gap: 10px; }
.score-box {
  background: #bbada0;
  color: #eee4da;
  border-radius: 6px;
  padding: 6px 12px;
  text-align: center;
  min-width: 70px;
}
.score-box .label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .8; }
.score-box .value { font-size: 22px; font-weight: 700; display: inline-block; }
.score-bump { animation: bump .22s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: #fff; }
  100% { transform: scale(1); }
}

/* ========== 认证 ========== */
.auth { display: flex; align-items: center; gap: 8px; }
#user-name { font-size: 14px; font-weight: 700; color: #8f7a66; }
.btn-login, .btn-logout { padding: 6px 14px; font-size: 13px; }
.btn-login { background: #edc22e; color: #fff; }
.btn-login:hover { background: #f0cf4a; }

/* ========== 按钮通用 ========== */
button {
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
button:hover { background: #9f8b77; }

/* ========== 控制栏 ========== */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 8px;
}
.hint { font-size: 13px; color: #a0948a; }
.right { display: flex; gap: 8px; align-items: center; }

.mode-switch { display: inline-flex; border-radius: 6px; overflow: hidden; border: 2px solid #8f7a66; }
.mode-switch button { border-radius: 0; background: #faf8ef; color: #8f7a66; padding: 7px 14px; }
.mode-switch button:hover { background: #eee4da; }
.mode-switch button.active { background: #8f7a66; color: #f9f6f2; }

/* ========== P2P 面板 ========== */
#p2p-panel { background: #eee4da; border-radius: 10px; padding: 12px; margin-bottom: 15px; }
.p2p-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.p2p-row button { padding: 7px 12px; font-size: 13px; }
#p2p-code {
  width: 100%;
  resize: vertical;
  border: 2px solid #d8cdbb;
  border-radius: 6px;
  padding: 8px;
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  background: #fff;
  color: #555;
}
.p2p-status { font-size: 14px; color: #8f7a66; margin-top: 6px; font-weight: 700; }
.p2p-status.ok { color: #27ae60; }
.p2p-status.err { color: #c0392b; }
.p2p-help { font-size: 12px; color: #a0948a; margin-top: 4px; line-height: 1.6; }

/* ========== 棋盘 ========== */
.boards { display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; }
.board-col { flex: 1 1 250px; max-width: 500px; min-width: 240px; }
.board-label { text-align: center; margin-bottom: 8px; font-size: 14px; color: #a0948a; font-weight: 700; }
.board-label b { color: #8f7a66; }
.game-wrap { position: relative; }
.board {
  position: relative;
  background: #bbada0;
  border-radius: 10px;
  padding: var(--pad);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell { background: rgba(238, 228, 218, .35); border-radius: 6px; }
.tile {
  position: absolute;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 45px;
  font-weight: 700;
  z-index: 5;
  width: calc((100% - 2*var(--pad) - 3*var(--gap)) / 4);
  height: calc((100% - 2*var(--pad) - 3*var(--gap)) / 4);
  transition: left .12s ease, top .12s ease;
  will-change: left, top;
}
.tile.no-anim { transition: none !important; }
.tile.pop { animation: pop .18s ease; }
@keyframes pop {
  0% { transform: scale(0); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.t-2    { background: #eee4da; color: #776e65; }
.t-4    { background: #ede0c8; color: #776e65; }
.t-8    { background: #f2b179; color: #f9f6f2; }
.t-16   { background: #f59563; color: #f9f6f2; }
.t-32   { background: #f67c5f; color: #f9f6f2; }
.t-64   { background: #f65e3b; color: #f9f6f2; }
.t-128  { background: #edcf72; color: #f9f6f2; }
.t-256  { background: #edcc61; color: #f9f6f2; }
.t-512  { background: #edc850; color: #f9f6f2; }
.t-1024 { background: #edc53f; color: #f9f6f2; }
.t-2048 { background: #edc22e; color: #f9f6f2; }
.t-4096 { background: #3c3a32; color: #f9f6f2; }
.t-8192 { background: #2d2b24; color: #f9f6f2; }
.t-super{ background: #1f1e19; color: #f9f6f2; }
.tile.small { font-size: 32px; }
.tile.tiny  { font-size: 24px; }
.board-mini .tile { font-size: 26px; }
.board-mini .tile.small { font-size: 18px; }
.board-mini .tile.tiny { font-size: 14px; }

/* ========== 游戏结束遮罩 ========== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, .78);
  border-radius: 10px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 10;
  text-align: center;
}
.overlay.show { display: flex; }
.overlay h2 { font-size: 40px; color: #776e65; }
.overlay p { font-size: 15px; color: #a0948a; }
.overlay .sub { font-size: 12px; color: #a0948a; margin-top: -8px; }

/* ========== 通用弹窗(mask) ========== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #faf8ef;
  border-radius: 12px;
  padding: 20px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.modal h3 { color: #776e65; margin-bottom: 12px; text-align: center; font-size: 20px; }
.modal-body { overflow-y: auto; flex: 1; font-size: 14px; color: #776e65; line-height: 1.7; }
.modal-err { color: #c0392b; font-size: 13px; text-align: center; margin-top: 6px; }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 15px; flex-wrap: wrap; }
.modal-btns button.primary { background: #edc22e; color: #fff; }
.modal-btns button.primary:hover { background: #f0cf4a; }

/* ========== 登录表单 ========== */
.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.auth-form input {
  padding: 10px 12px;
  border: 2px solid #d8cdbb;
  border-radius: 6px;
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
}
.auth-form input:focus { border-color: #8f7a66; }
.auth-form .switch-text {
  text-align: center;
  font-size: 13px;
  color: #a0948a;
  cursor: pointer;
}
.auth-form .switch-text:hover { color: #8f7a66; text-decoration: underline; }

/* ========== 排行榜表格 ========== */
.rec-table { width: 100%; border-collapse: collapse; }
.rec-table th, .rec-table td { padding: 6px 8px; text-align: center; border-bottom: 1px solid #eee4da; }
.rec-table th { color: #a0948a; font-size: 12px; font-weight: 700; }
.rec-empty { text-align: center; color: #a0948a; padding: 20px 0; }
.rank-gold { color: #f1c40f; }
.rank-silver { color: #95a5a6; }
.rank-bronze { color: #d35400; }
.rec-table .me { background: #fdf6e3; font-weight: 700; }

/* ========== 页脚 ========== */
footer { margin-top: 15px; text-align: center; font-size: 12px; color: #a0948a; line-height: 1.6; }
.hidden { display: none !important; }

/* ========== 响应式 ========== */
@media (max-width: 420px) {
  h1 { font-size: 34px; }
  .tile { font-size: 32px; }
  .tile.small { font-size: 24px; }
  .tile.tiny  { font-size: 18px; }
  .board { --pad: 8px; --gap: 8px; }
}