* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #fef6e4 0%, #e8f4fd 100%);
  color: #2c3e50;
  user-select: none;
}
.hidden { display: none !important; }

/* 遮罩卡片 */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(44,62,80,0.35); padding: 16px; z-index: 50;
}
.card {
  background: #fff; border-radius: 24px; padding: 28px 26px; max-width: 460px; width: 100%;
  box-shadow: 0 18px 50px rgba(0,0,0,0.18); text-align: center;
}
.card h1 { margin: 0 0 6px; font-size: 30px; }
.sub { margin: 0 0 14px; color: #7f8c8d; }
.ask { font-size: 18px; font-weight: 700; margin: 10px 0 14px; }
.choices { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.choices button {
  flex: 1 1 120px; min-width: 120px; padding: 18px 10px; font-size: 18px; font-weight: 800;
  border: none; border-radius: 18px; background: #ffd166; color: #5b4700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; transition: transform .08s;
}
.choices button small { font-size: 13px; font-weight: 600; opacity: .8; }
.choices button:active { transform: scale(0.96); }
.rules { margin-top: 18px; text-align: left; font-size: 14px; color: #34495e; }
.rules summary { cursor: pointer; font-weight: 700; }
.rules ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.7; }
.rules b { color: #e67e22; }

/* 主界面 */
#game { max-width: 1000px; margin: 0 auto; padding: 10px 12px 16px; }
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; border-radius: 16px; padding: 10px 16px; box-shadow: 0 4px 14px rgba(0,0,0,.08);
}
#turnInfo { font-size: 19px; font-weight: 800; }
#poolInfo { font-size: 15px; color: #7f8c8d; font-weight: 700; }

#aiArea { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.ai-card {
  background: #fff; border-radius: 14px; padding: 8px 12px; min-width: 120px;
  box-shadow: 0 3px 10px rgba(0,0,0,.08); border: 3px solid transparent;
}
.ai-card.active { border-color: #ffd166; background: #fffbe9; }
.ai-card .nm { font-weight: 800; font-size: 15px; }
.ai-card .cnt { font-size: 13px; color: #7f8c8d; }
.ai-fan { display: flex; margin-top: 4px; }
.ai-fan .back {
  width: 14px; height: 20px; border-radius: 3px; background: #5b6b7b; margin-left: -6px;
  border: 1px solid #fff;
}

#tableArea {
  min-height: 150px; background: rgba(255,255,255,.6); border-radius: 16px; padding: 12px;
  display: flex; flex-wrap: wrap; gap: 10px; align-content: flex-start; box-shadow: inset 0 0 0 2px rgba(255,255,255,.5);
}
.meld {
  display: flex; align-items: center; gap: 4px; background: #fff; border-radius: 12px; padding: 6px;
  box-shadow: 0 3px 8px rgba(0,0,0,.08); position: relative;
}
.meld.empty { border: 2px dashed #bdc3c7; background: transparent; min-width: 90px; justify-content: center; color: #95a5a6; font-size: 13px; }
.meld .add-btn {
  margin-left: 4px; border: none; background: #2ecc71; color: #fff; border-radius: 10px;
  width: 30px; height: 38px; font-size: 20px; font-weight: 800; cursor: pointer;
}
.meld.empty .add-btn { width: auto; padding: 0 10px; }

/* 暂存区 */
#stagingArea {
  margin: 10px 0; background: #fff7e6; border-radius: 14px; padding: 8px 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 56px;
}
#stagingArea .label { font-weight: 800; }
#stagingArea .hint-txt { font-size: 12px; color: #a08a4f; }
#stagingTiles { display: flex; gap: 4px; }

/* 你的牌 */
#rackWrap { background: #fff; border-radius: 16px; padding: 10px 12px; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.rack-label { font-weight: 800; margin-bottom: 8px; font-size: 15px; }
#rackTiles { display: flex; flex-wrap: wrap; gap: 6px; }

/* 牌 */
.tile {
  width: 50px; height: 68px; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 900; font-size: 26px;
  color: #fff; cursor: pointer; box-shadow: 0 3px 6px rgba(0,0,0,.2); position: relative;
  border: 2px solid rgba(0,0,0,.08); transition: transform .08s;
}
.tile:active { transform: translateY(2px); }
.tile .num { line-height: 1; }
.tile.red { background: #e74c3c; }
.tile.blue { background: #3498db; }
.tile.yellow { background: #f1c40f; color: #6b5500; }
.tile.black { background: #2c3e50; }
.tile.joker {
  background: linear-gradient(135deg, #ff6b6b, #feca57, #48dbfb, #1dd1a1);
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.tile.joker .joker-star { font-size: 22px; line-height: 1; }
.tile.joker .joker-txt { font-size: 12px; font-weight: 800; }
.tile.small { width: 34px; height: 46px; font-size: 18px; cursor: default; }
.tile.pullable:hover { outline: 3px solid #ffd166; }

/* 控制按钮 */
#controls { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 6px; }
#controls button {
  flex: 1 1 auto; padding: 14px 10px; font-size: 16px; font-weight: 800; border: none;
  border-radius: 14px; background: #fff; color: #2c3e50; cursor: pointer; box-shadow: 0 3px 8px rgba(0,0,0,.1);
}
#controls button:active { transform: scale(0.97); }
#controls button.primary { background: #2ecc71; color: #fff; }
#controls button:disabled { opacity: .45; cursor: not-allowed; }

#msg { min-height: 26px; text-align: center; font-weight: 800; font-size: 16px; color: #2c3e50; margin-top: 6px; }
#msg.err { color: #e74c3c; }

#endBody .endRow { font-size: 17px; padding: 6px 0; border-bottom: 1px dashed #eee; }

/* 联机模式 UI */
.mode-tabs { display: flex; gap: 8px; margin: 6px 0 14px; }
.tab {
  flex: 1; padding: 12px 8px; font-size: 16px; font-weight: 800; border: none; border-radius: 14px;
  background: #ecf0f1; color: #7f8c8d; cursor: pointer;
}
.tab.active { background: #3498db; color: #fff; }
.online-cols { display: flex; gap: 14px; text-align: left; }
.ocol { flex: 1; background: #f7fbfe; border-radius: 14px; padding: 14px; }
.ocol h3 { margin: 0 0 10px; font-size: 16px; }
.ocol input, .ocol select {
  width: 100%; padding: 10px; margin-bottom: 10px; border: 2px solid #dfe6e9; border-radius: 10px;
  font-size: 15px; font-family: inherit;
}
.ocol label { display: block; font-size: 13px; font-weight: 700; color: #636e72; margin-bottom: 4px; }
.ocol .primary { width: 100%; padding: 12px; font-size: 16px; font-weight: 800; border: none;
  border-radius: 12px; background: #2ecc71; color: #fff; cursor: pointer; }
.ocol .primary:active { transform: scale(0.97); }
#onlineStatus { margin-top: 12px; min-height: 22px; }
.hint-txt.err { color: #e74c3c; font-weight: 800; }

#roomInfo { font-size: 14px; font-weight: 800; color: #2980b9; }

@media (max-width: 560px) {
  .tile { width: 42px; height: 58px; font-size: 22px; }
  #controls button { font-size: 14px; padding: 12px 6px; }
  .online-cols { flex-direction: column; }
}
