/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { background: #0d3010; color: #e8e8e8; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ===== Buttons ===== */
.btn-primary {
  padding: 12px 28px; font-size: 17px;
  background: linear-gradient(135deg, #d4a017, #b8860b);
  color: #fff; border: none; border-radius: 8px; cursor: pointer;
  font-weight: bold; transition: transform .15s, box-shadow .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
  padding: 10px 20px; font-size: 15px;
  background: rgba(255,255,255,.12); color: #eee;
  border: 1px solid rgba(255,255,255,.22); border-radius: 8px;
  cursor: pointer; transition: background .15s;
}
.btn-secondary:active { background: rgba(255,255,255,.25); }
.btn-block { display: block; width: 100%; margin-top: 14px; }
.btn-back {
  background: none; border: none; color: #ffd700;
  font-size: 16px; cursor: pointer; padding: 4px 8px;
}
.btn-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(0,0,0,.5); color: #fff;
  border: 1px solid rgba(255,255,255,.3); font-size: 17px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-close { background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; }
.btn-close-inline {
  background: none; border: none; color: #999; font-size: 22px;
  cursor: pointer; line-height: 1;
}

.text-input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  background: rgba(0,0,0,.35); color: #fff;
  border: 1px solid rgba(255,255,255,.2); border-radius: 8px; outline: none;
}
.text-input:focus { border-color: rgba(255,215,0,.6); }
.field-label {
  display: block; font-size: 13px; color: rgba(255,255,255,.65);
  margin: 18px 0 6px; text-align: left;
}

/* ===== Lobby ===== */
#lobby {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1b5e20 0%, #0d3010 60%, #071a08 100%);
  padding: 20px;
}
.lobby-card {
  width: 100%; max-width: 380px;
  background: rgba(0,0,0,.28);
  border: 1px solid rgba(255,215,0,.2);
  border-radius: 18px; padding: 28px 24px; text-align: center;
}
.game-title {
  font-size: 56px; color: #ffd700; letter-spacing: 14px;
  text-shadow: 0 0 26px rgba(255,215,0,.45), 0 4px 8px rgba(0,0,0,.5);
  margin-bottom: 10px;
}
.game-subtitle { font-size: 15px; color: rgba(255,255,255,.65); margin-bottom: 8px; }
.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 20px 0 4px; color: rgba(255,255,255,.4); font-size: 13px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: rgba(255,255,255,.15);
}
.join-row { display: flex; gap: 8px; }
.join-row .text-input { flex: 1; }
.join-row .btn-primary { padding: 12px 18px; }
.lobby-status { margin-top: 14px; font-size: 13px; color: #ff8a80; min-height: 18px; }

/* ===== Room ===== */
#room {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1b5e20 0%, #0d3010 60%, #071a08 100%);
  padding: 16px;
}
.room-card {
  width: 100%; max-width: 440px;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,215,0,.22);
  border-radius: 18px; padding: 18px 20px;
}
.room-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.room-title { font-size: 15px; color: rgba(255,255,255,.7); }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: #4caf50; }
.conn-dot.off { background: #f44336; }
.room-code-box { text-align: center; margin: 10px 0 16px; }
.room-code-label { font-size: 13px; color: rgba(255,255,255,.6); margin-right: 8px; }
.room-code {
  font-size: 34px; font-weight: bold; letter-spacing: 8px; color: #ffd700;
}
.seat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.seat-cell {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px; padding: 14px 12px; text-align: center; min-height: 78px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
.seat-cell.occupied { border-color: rgba(255,215,0,.45); background: rgba(255,215,0,.08); }
.seat-cell.me { box-shadow: inset 0 0 0 2px rgba(78,205,196,.55); }
.seat-cell .sc-name { font-size: 16px; font-weight: bold; }
.seat-cell .sc-sub { font-size: 12px; color: rgba(255,255,255,.55); }
.seat-cell .sc-empty { color: rgba(255,255,255,.35); font-size: 15px; }
.seat-cell .sc-off { color: #ff8a80; font-size: 12px; }
.room-tip { font-size: 13px; color: rgba(255,255,255,.6); text-align: center; margin: 14px 0 6px; }
.invite-box { display: flex; gap: 8px; margin-bottom: 4px; }
.invite-input { flex: 1; font-size: 12px; }

/* ===== Game table ===== */
#game-table {
  width: 100%; height: 100%; position: relative; overflow: hidden;
  background: radial-gradient(ellipse at center, #2e7d32 0%, #1b5e20 40%, #0d3010 80%, #071a08 100%);
}
#game-table::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 70%; height: 62%;
  border: 3px solid rgba(255,215,0,.12); border-radius: 50%;
  pointer-events: none;
}

/* top bar */
#top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  min-height: 46px; display: flex; align-items: center;
  justify-content: space-between; padding: 4px 14px;
  background: rgba(0,0,0,.42); z-index: 10; gap: 8px;
}
.score-box { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.team-label { font-weight: bold; font-size: 13px; }
.team-a-color { color: #ff6b6b; }
.team-b-color { color: #4ecdc4; }
.score-value { font-size: 20px; font-weight: bold; color: #ffd700; }
.score-sub { font-size: 11px; color: rgba(255,255,255,.5); }
#game-info {
  display: flex; gap: 10px; font-size: 12px;
  color: rgba(255,255,255,.78); flex-wrap: wrap; justify-content: center;
}
#round-score-bar {
  position: absolute; top: 46px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.3); padding: 3px 14px;
  border-radius: 0 0 8px 8px; font-size: 12px; z-index: 10; white-space: nowrap;
}

/* seats */
.seat { position: absolute; display: flex; flex-direction: column; align-items: center; z-index: 5; }
#seat-top { top: 64px; left: 50%; transform: translateX(-50%); }
#seat-left { left: 8px; top: 50%; transform: translateY(-50%); }
#seat-right { right: 8px; top: 50%; transform: translateY(-50%); }
#seat-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
}
.seat-info {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  background: rgba(0,0,0,.5); padding: 4px 10px;
  border-radius: 12px; font-size: 12px; margin-bottom: 4px; max-width: 170px;
}
.seat-info-self { max-width: none; }
.seat-info.active { box-shadow: 0 0 0 2px rgba(255,215,0,.7); }
.seat-info .si-name { font-weight: bold; font-size: 13px; }
.seat-info .si-team { font-size: 10px; padding: 1px 5px; border-radius: 4px; }
.si-team.team-a { background: rgba(255,107,107,.3); color: #ff6b6b; }
.si-team.team-b { background: rgba(78,205,196,.3); color: #4ecdc4; }
.seat-info .si-count { color: rgba(255,255,255,.6); font-size: 11px; }
.seat-info .si-flag { font-size: 11px; }
.si-flag.offline { color: #ff8a80; }
.si-flag.takeover { color: #ffd180; }

.dealer-badge {
  background: linear-gradient(135deg, #ffd700, #ffaa00);
  color: #8b4513; font-size: 10px; font-weight: bold;
  padding: 1px 6px; border-radius: 9px;
}

/* card backs */
.card-backs { display: flex; justify-content: center; }
.card-back {
  width: 28px; height: 40px;
  background: linear-gradient(135deg, #1a237e, #283593);
  border: 1px solid rgba(255,255,255,.2); border-radius: 4px;
  margin-left: -15px;
}
.card-back:first-child { margin-left: 0; }
#seat-left .card-backs, #seat-right .card-backs { flex-direction: column; }
#seat-left .card-back, #seat-right .card-back { margin-left: 0; margin-top: -29px; }
#seat-left .card-back:first-child, #seat-right .card-back:first-child { margin-top: 0; }

/* center */
#center-area {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 330px; height: 250px;
}
#played-cards { width: 100%; height: 100%; position: relative; }
.played-slot {
  position: absolute; display: flex; justify-content: center;
  min-width: 56px; max-width: 150px; flex-wrap: nowrap;
}
#played-bottom { bottom: 8px; left: 50%; transform: translateX(-50%); }
#played-top { top: 8px; left: 50%; transform: translateX(-50%); }
#played-left { left: 8px; top: 50%; transform: translateY(-50%); }
#played-right { right: 8px; top: 50%; transform: translateY(-50%); }
#trick-result-text {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 15px; font-weight: bold; color: #ffd700;
  text-shadow: 0 0 10px rgba(255,215,0,.5); text-align: center;
  pointer-events: none; white-space: nowrap;
}
#table-status {
  position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: rgba(255,255,255,.75); white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
#bottom-cards-area {
  position: absolute; bottom: -34px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
#bottom-cards-area .label { font-size: 11px; color: rgba(255,255,255,.6); }
#bottom-cards-display { display: flex; }

/* hand */
#hand-cards {
  display: flex; justify-content: center; align-items: flex-end;
  padding: 6px 16px 10px; min-height: 96px;
  flex-wrap: nowrap; position: relative; z-index: 45;
  max-width: 100%;
}

/* cards */
.card {
  width: 50px; height: 71px; background: #fff; border-radius: 6px;
  border: 1px solid #bbb; position: relative; cursor: pointer;
  transition: transform .12s, box-shadow .12s; flex-shrink: 0;
  user-select: none; display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.card.selected {
  transform: translateY(-15px);
  box-shadow: 0 6px 16px rgba(255,215,0,.45); border-color: #ffd700;
  z-index: 8;
}
.card.red { color: #d32f2f; }
.card.black { color: #212121; }
.card .card-rank { font-size: 13px; font-weight: bold; position: absolute; top: 3px; left: 5px; }
.card .card-suit-small { font-size: 10px; position: absolute; top: 17px; left: 5px; }
.card .card-suit-center { font-size: 23px; }
.card .card-rank-bottom {
  font-size: 13px; font-weight: bold; position: absolute;
  bottom: 3px; right: 5px; transform: rotate(180deg);
}
.card.joker-small { background: linear-gradient(135deg, #fff 60%, #e0e0e0); }
.card.joker-big { background: linear-gradient(135deg, #fff 60%, #ffcdd2); }
.card.card-mini { width: 34px; height: 48px; cursor: default; }
.card.card-mini .card-rank { font-size: 10px; top: 2px; left: 3px; }
.card.card-mini .card-suit-small { font-size: 8px; top: 13px; left: 3px; }
.card.card-mini .card-suit-center { font-size: 15px; }
.card.card-mini .card-rank-bottom { font-size: 10px; bottom: 2px; right: 3px; }
.card.card-xs { width: 26px; height: 37px; }
.card.card-xs .card-rank { font-size: 9px; top: 1px; left: 2px; }
.card.card-xs .card-suit-small { display: none; }
.card.card-xs .card-suit-center { font-size: 11px; }
.card.card-xs .card-rank-bottom { display: none; }
.card.highlight-win { border: 2px solid #ffd700; box-shadow: 0 0 12px rgba(255,215,0,.6); }

#hand-cards .card { margin-left: -13px; }
#hand-cards .card:first-child { margin-left: 0; }
#hand-cards .suit-separator { width: 7px; flex-shrink: 0; }
.played-slot .card { margin-left: -9px; }
.played-slot .card:first-child { margin-left: 0; }
#bottom-cards-display .card { margin-left: -10px; }
#bottom-cards-display .card:first-child { margin-left: 0; }

/* trump badge */
.card-trump-badge {
  position: absolute; bottom: 2px; left: 2px;
  width: 15px; height: 15px;
  background: linear-gradient(135deg, #ff4444, #cc0000);
  color: #ffd700; font-size: 9px; font-weight: bold;
  border-radius: 50%; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,215,0,.6);
}
.card-mini .card-trump-badge { width: 12px; height: 12px; font-size: 8px; }

/* timer */
#timer-container {
  position: absolute; bottom: 108px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; z-index: 20;
}
#timer-bar { width: 150px; height: 8px; background: rgba(0,0,0,.45); border-radius: 4px; overflow: hidden; }
#timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #4caf50, #ffeb3b, #f44336);
  width: 100%;
}
#timer-text { font-size: 16px; font-weight: bold; color: #fff; min-width: 22px; text-align: center; }

/* action bars */
#action-bar, #bid-bar {
  position: absolute; bottom: 106px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 20;
}
#action-bar button, #bid-bar button { padding: 10px 22px; }

/* discard overlay */
#discard-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 14px;
}
#discard-content {
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  padding: 22px; border-radius: 16px; text-align: center;
  border: 2px solid rgba(255,215,0,.3);
  width: 100%; max-width: 640px; max-height: 96%; overflow-y: auto;
}
#discard-content h3 { color: #ffd700; margin-bottom: 8px; }
#discard-info, #discard-select-info { color: rgba(255,255,255,.85); font-size: 14px; margin-bottom: 4px; }
#discard-hand {
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  margin: 14px 0;
}
#discard-hand .card { width: 42px; height: 60px; margin: 0 !important; }
#discard-hand .card .card-rank { font-size: 10px; }
#discard-hand .card .card-suit-small { font-size: 8px; top: 14px; }
#discard-hand .card .card-suit-center { font-size: 17px; }
#discard-hand .card.selected { transform: translateY(-9px); border-color: #ff5722; }

/* conn banner */
#conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  background: #c62828; color: #fff; text-align: center;
  padding: 7px 10px; font-size: 14px;
}

/* reconnect overlay */
#reconnect-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; z-index: 600;
}
.reconnect-card {
  background: #1b3a24; border: 1px solid rgba(255,215,0,.3);
  border-radius: 14px; padding: 28px; text-align: center;
}
.spinner {
  width: 38px; height: 38px; margin: 0 auto 14px;
  border: 4px solid rgba(255,255,255,.2); border-top-color: #ffd700;
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* modals */
#round-modal, #game-end-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; z-index: 90; padding: 20px;
}
/* 遮罩背景不拦截点击，仅内容卡片可点，避免遮挡牌桌操作 */
#round-modal, #game-end-modal { pointer-events: none; }
#round-modal .modal-content, #game-end-modal .modal-content { pointer-events: auto; }
.modal-content {
  background: linear-gradient(135deg, #1b5e20, #0d3010);
  padding: 26px 30px; border-radius: 16px; text-align: center;
  border: 2px solid rgba(255,215,0,.3);
  width: 100%; max-width: 400px;
}
.modal-content h1, .modal-content h2 { color: #ffd700; margin-bottom: 14px; }
#round-result-detail, #game-end-detail {
  color: #fff; font-size: 14px; line-height: 1.9;
  margin-bottom: 18px; text-align: left;
}
#round-result-detail .rd-line { display: flex; justify-content: space-between; }

/* chat */
#chat-panel {
  position: fixed; left: 8px; bottom: 8px;
  width: min(300px, calc(100vw - 16px)); max-height: 55vh;
  background: rgba(10,30,16,.95);
  border: 1px solid rgba(255,215,0,.3); border-radius: 12px;
  z-index: 120; display: flex; flex-direction: column; overflow: hidden;
}
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; color: #ffd700; font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
#chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; font-size: 13px; min-height: 60px; max-height: 160px; }
.chat-msg { margin-bottom: 6px; line-height: 1.4; }
.chat-msg .cm-name { color: #4ecdc4; }
.chat-msg.local-note { color: rgba(255,255,255,.45); font-size: 12px; }
#phrases {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 10px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.phrase-btn {
  font-size: 13px; padding: 6px 12px; border-radius: 16px;
  background: rgba(255,255,255,.1); color: #eee;
  border: 1px solid rgba(255,255,255,.2); cursor: pointer;
}
.phrase-btn:active { background: rgba(255,215,0,.25); }

/* rules panel */
#rules-panel {
  position: fixed; top: 0; right: 0; width: 380px; max-width: 100%;
  height: 100%; background: rgba(6,20,10,.96); z-index: 200;
  overflow-y: auto; padding: 18px;
  border-left: 2px solid rgba(255,215,0,.3);
}
.rules-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.rules-header h2 { color: #ffd700; font-size: 20px; }
.rules-body h3 { color: #4ecdc4; margin: 12px 0 4px; font-size: 14px; }
.rules-body p { color: rgba(255,255,255,.82); font-size: 13px; line-height: 1.65; }

/* float buttons */
#float-buttons {
  position: fixed; top: 54px; right: 10px;
  display: flex; flex-direction: column; gap: 8px; z-index: 30;
}

/* toast */
#toast {
  position: fixed; top: 46%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.87); color: #fff;
  padding: 13px 26px; border-radius: 10px; font-size: 16px;
  z-index: 700; border: 1px solid rgba(255,255,255,.2);
  max-width: 84vw; text-align: center; pointer-events: none;
}

/* ===== Responsive: phones ===== */
@media (max-width: 768px) {
  .game-title { font-size: 44px; letter-spacing: 10px; }
  #top-bar { padding: 4px 8px; }
  #game-info { gap: 6px; font-size: 11px; }
  #game-info span { white-space: nowrap; }
  .card { width: 40px; height: 57px; }
  .card .card-rank { font-size: 11px; }
  .card .card-suit-small { font-size: 8px; top: 15px; }
  .card .card-suit-center { font-size: 18px; }
  .card .card-rank-bottom { font-size: 11px; }
  #hand-cards .card { margin-left: -20px; }
  #hand-cards { min-height: 84px; padding: 4px 6px 8px; }
  #center-area { width: 248px; height: 196px; }
  .card.card-mini { width: 27px; height: 39px; }
  .card.card-mini .card-rank { font-size: 8px; }
  .card.card-mini .card-suit-small { font-size: 7px; top: 11px; }
  .card.card-mini .card-suit-center { font-size: 12px; }
  .card.card-mini .card-rank-bottom { font-size: 8px; }
  #action-bar, #bid-bar { bottom: 94px; }
  #timer-container { bottom: 96px; }
  #action-bar button, #bid-bar button { padding: 9px 18px; font-size: 15px; }
  #seat-top { top: 70px; }
  #round-score-bar { font-size: 11px; }
  #effect-text, .effect-text { font-size: 44px; }
}

/* very narrow screens: shrink hands more aggressively */
@media (max-width: 380px) {
  #hand-cards .card { margin-left: -20px; }
  .card { width: 37px; height: 53px; }
}
