:root {
  --felt-1: #0f5132;
  --felt-2: #07291d;
  --gold: #f2c14e;
  --card-w: clamp(38px, 11vw, 54px);
  --card-h: calc(var(--card-w) * 1.4);
  --red: #d0342c;
  --black: #1c1c1c;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: #f4f4f4;
  background: radial-gradient(circle at 50% 0%, var(--felt-1), var(--felt-2) 72%);
  overflow: hidden;
  overscroll-behavior: none;
}

#app { height: 100%; position: relative; }
.screen { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ============ 首页 ============ */
#screen-home {
  align-items: center; justify-content: center;
  padding: 24px 20px; gap: 14px; text-align: center; overflow-y: auto;
}
#screen-home h1 { font-size: 30px; margin: 0; letter-spacing: 2px; }
#screen-home h1 span { color: var(--gold); }
.tagline { color: #cfe8dd; font-size: 14px; line-height: 1.6; margin: 0; }

.panel {
  width: 100%; max-width: 360px; background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 16px;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.field-label { text-align: left; font-size: 13px; color: #b9d6c9; }
input {
  width: 100%; padding: 13px 14px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08); color: #fff; font-size: 16px; outline: none;
}
input::placeholder { color: #8fb2a3; }
input:focus { border-color: var(--gold); }

.btn {
  padding: 13px 16px; border-radius: 10px; border: none; font-size: 16px;
  font-weight: 600; cursor: pointer; color: #fff; background: rgba(255,255,255,0.14);
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, #22a06b, #167a4f); box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
.btn.ghost { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2); }
.btn.tiny { padding: 7px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.divider { position: relative; text-align: center; color: #9ab8ab; font-size: 12px; margin: 2px 0; }
.divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: rgba(255,255,255,0.15); }
.divider span { position: relative; padding: 0 10px; }

.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 700; }
.join-row .btn { flex: 0 0 84px; }

.error { color: #ff9a8f; font-size: 13px; min-height: 18px; }
.rules { max-width: 360px; text-align: left; color: #cfe8dd; font-size: 13px; width: 100%; }
.rules summary { cursor: pointer; color: var(--gold); font-weight: 600; }
.rules ul { padding-left: 18px; line-height: 1.7; }

/* ============ 游戏布局 ============ */
#screen-game {
  height: 100vh;
  height: 100dvh;
  padding: calc(var(--safe-t) + 6px) 8px calc(var(--safe-b) + 8px);
  gap: 6px;
  overflow: hidden;
  position: relative;
}

.topbar { display: flex; align-items: center; justify-content: space-between; flex: none; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.btn.icon { padding: 7px 10px; font-size: 15px; line-height: 1; }
.room-code { font-size: 13px; color: #cfe8dd; }
.room-code b { color: var(--gold); letter-spacing: 2px; font-size: 16px; }

/* 对手区 */
.opp-zone { flex: none; display: flex; flex-direction: column; gap: 4px; }
.opp-strip {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.25); border-radius: 12px; padding: 6px 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px;
  background: linear-gradient(180deg, #3a6ea5, #2b527b);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.opp-info { flex: 1; min-width: 0; }
.opp-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-count { font-size: 12px; color: #a9cbbd; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; }
.status-dot.on { background: #43d17a; box-shadow: 0 0 8px #43d17a; }
.status-dot.off { background: #6b6b6b; }

.opp-backs { display: flex; justify-content: center; height: calc(var(--card-h) * 0.62); align-items: center; }
.card-back {
  width: calc(var(--card-w) * 0.58); height: calc(var(--card-h) * 0.58);
  border-radius: 4px; margin-left: -10px; flex: 0 0 auto;
  background: repeating-linear-gradient(45deg, #1f4f8f 0 5px, #17406f 5px 10px);
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.card-back:first-child { margin-left: 0; }

/* 中间桌区 */
.center-zone {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; gap: 10px;
  overflow: hidden;
}
.fog-pile {
  flex: 0 0 66px; text-align: center; padding: 8px 4px; border-radius: 12px;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 8px, rgba(0,0,0,0.12) 8px 16px);
  border: 1px dashed rgba(255,255,255,0.3);
}
.fog-label { font-size: 11px; color: #cfe8dd; }
.fog-count b { font-size: 22px; color: var(--gold); }
.fog-hint { font-size: 9px; color: #8fb2a3; margin-top: 2px; }

.play-area {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  overflow: hidden;
}
.play-owner { font-size: 12px; color: #a9cbbd; min-height: 16px; }
.play-cards {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  gap: 2px; max-width: 100%;
}
.play-cards .card { transform: scale(0.92); }

.turn-tip { flex: none; text-align: center; font-size: 14px; min-height: 20px; color: var(--gold); font-weight: 600; }

/* 我方区 */
.my-zone { flex: none; display: flex; flex-direction: column; gap: 6px; }
.hand-area {
  height: calc(var(--card-h) + 20px);
  display: flex; align-items: flex-end; justify-content: center;
  padding-top: 18px; /* 给抬起的选中牌留空间 */
}
.hand {
  display: flex; align-items: flex-end; justify-content: center;
  width: 100%; height: 100%;
  overflow: visible;
}

/* ============ 牌 ============ */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 6px;
  background: #fff; color: var(--black); position: relative;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start;
  padding: 3px 0 0 4px; font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  user-select: none; flex: 0 0 auto;
}
.card.red { color: var(--red); }
.card .rank { font-size: calc(var(--card-w) * 0.32); line-height: 1; }
.card .suit { font-size: calc(var(--card-w) * 0.3); line-height: 1; }

.hand .card { cursor: pointer; transition: transform .08s ease; z-index: 1; }
.hand .card.selected { transform: translateY(-16px); z-index: 20; box-shadow: 0 6px 12px rgba(0,0,0,0.55); }

.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; padding: 13px; }

/* ============ 提示 / 弹层 ============ */
.toast {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(0.9);
  background: rgba(0,0,0,0.82); padding: 12px 20px; border-radius: 10px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: all .18s ease; z-index: 60;
  max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.65); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay-box {
  background: linear-gradient(180deg, #14553c, #0c3a29); border-radius: 18px;
  padding: 24px; text-align: center; width: 100%; max-width: 320px;
  border: 1px solid rgba(255,255,255,0.15);
}
.overlay-box h2 { margin: 0 0 8px; color: var(--gold); font-size: 24px; }
.overlay-box p { color: #cfe8dd; font-size: 14px; line-height: 1.6; margin: 0 0 18px; }
.overlay-actions .btn { width: 100%; }

/* ============ 特效层 ============ */
.fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 55; }

/* ============ 聊天 ============ */
.chat-panel {
  position: absolute; left: 8px; right: 8px; bottom: calc(var(--safe-b) + 8px);
  height: 62%; max-height: 460px; z-index: 65;
  display: flex; flex-direction: column;
  background: rgba(8, 32, 24, 0.96);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,0.5);
}
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.1); flex: none;
}
.chat-title { flex: 1; font-size: 14px; font-weight: 600; color: var(--gold); }
#btn-voice.on { background: linear-gradient(180deg, #22a06b, #167a4f); border-color: transparent; }
#remote-audio { display: none; }

.chat-log {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.chat-empty { color: #7fa392; font-size: 13px; text-align: center; margin: auto; }
.chat-msg { max-width: 82%; display: flex; flex-direction: column; gap: 2px; }
.chat-msg .who { font-size: 11px; color: #8fb2a3; }
.chat-msg .bubble {
  padding: 8px 11px; border-radius: 12px; font-size: 14px; line-height: 1.45;
  word-break: break-word; white-space: pre-wrap;
  background: rgba(255,255,255,0.14); align-self: flex-start;
}
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.mine .bubble { background: linear-gradient(180deg, #22a06b, #167a4f); }
.chat-msg.mine .who { text-align: right; }
.chat-msg.sys { align-self: center; }
.chat-msg.sys .bubble { background: rgba(255,255,255,0.08); color: #cfe8dd; font-size: 12px; }

.chat-input-row {
  display: flex; gap: 8px; padding: 8px 10px; flex: none;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.chat-input-row input { flex: 1; padding: 10px 12px; font-size: 15px; }
.chat-input-row .btn { flex: 0 0 auto; padding: 10px 16px; }

/* ============ 弹幕 ============ */
.danmaku-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 58; }
.danmaku-item {
  position: absolute; left: 100%; top: 0; white-space: nowrap;
  padding: 5px 13px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: #fff; background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255,255,255,0.28);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  will-change: transform;
  animation-name: danmaku-move; animation-timing-function: linear; animation-fill-mode: forwards;
}
.danmaku-item .who { color: var(--gold); margin-right: 6px; font-size: 12px; }
.danmaku-item.mine { background: linear-gradient(180deg, #22a06b, #167a4f); border-color: transparent; }
@keyframes danmaku-move {
  from { transform: translateX(0); }
  to { transform: translateX(calc(-100% - 100vw)); }
}

@keyframes shake {
  0%,100% { transform: translate(0,0); }
  15% { transform: translate(-8px,3px); }
  30% { transform: translate(7px,-3px); }
  45% { transform: translate(-6px,2px); }
  60% { transform: translate(5px,-2px); }
  75% { transform: translate(-3px,1px); }
}
.shake { animation: shake .42s ease-in-out; }
.shake-hard { animation: shake .55s ease-in-out; }

.fx-blast {
  position: absolute; left: 50%; top: 38%; width: 24px; height: 24px; margin: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #ffe08a 28%, #ff7a1a 55%, #d23a10 70%, transparent 72%);
  animation: blast .62s ease-out forwards;
}
@keyframes blast { from { transform: scale(.2); opacity: 1; } to { transform: scale(16); opacity: 0; } }

.fx-ring {
  position: absolute; left: 50%; top: 38%; width: 40px; height: 40px; margin: -20px;
  border-radius: 50%; border: 4px solid rgba(255,255,255,0.85);
  animation: ring .6s ease-out forwards;
}
@keyframes ring { from { transform: scale(.3); opacity: .9; } to { transform: scale(9); opacity: 0; } }

.fx-emoji {
  position: absolute; left: 50%; top: 34%; font-size: 54px;
  animation: pop .95s ease-out forwards; filter: drop-shadow(0 4px 10px rgba(0,0,0,0.6));
}
@keyframes pop {
  0% { transform: translate(-50%,-50%) scale(.3); opacity: 0; }
  30% { transform: translate(-50%,-50%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1.7); opacity: 0; }
}

.fx-plane {
  position: absolute; top: 30%; font-size: 42px;
  animation: fly 1s linear forwards; filter: drop-shadow(0 3px 8px rgba(0,0,0,0.6));
}
@keyframes fly { from { left: -60px; } to { left: 108%; } }

.fx-text {
  position: absolute; left: 50%; top: 40%; font-size: 26px; font-weight: 800;
  color: var(--gold); text-shadow: 0 2px 10px #000, 0 0 18px rgba(242,193,78,0.7);
  animation: floatUp 1s ease-out forwards; white-space: nowrap;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.6); }
  25% { opacity: 1; transform: translate(-50%,-50%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%,-150%) scale(1); }
}

.fx-flash { position: absolute; inset: 0; background: #fff; opacity: 0; animation: flash .32s ease-out forwards; }
.fx-flash.gold { background: radial-gradient(circle, #fff3c4, #ffb300 60%, transparent); }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }

.fx-spark {
  position: absolute; width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold); animation: spark .6s ease-out forwards;
}
@keyframes spark {
  from { transform: translate(0,0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* 窄屏微调 */
@media (max-width: 360px) {
  :root { --card-w: clamp(34px, 10.5vw, 46px); }
  .avatar { width: 30px; height: 30px; flex-basis: 30px; }
}
