* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e3f2a;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
}

/* --app-w / --app-h：牌桌的逻辑宽高（竖屏横过来时互换），由 main.js 设置 */
:root { --app-w: 100vw; --app-h: 100vh; }

#stage { position: fixed; inset: 0; touch-action: none; }

/* 对局界面层：平时铺满屏幕；手机竖屏时顺时针转 90° 横过来，和牌桌方向一致 */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
body.rotated #hud {
  inset: auto;
  top: 0;
  left: 0;
  width: var(--app-w);
  height: var(--app-h);
  transform-origin: 0 0;
  transform: translateX(var(--app-h)) rotate(90deg);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 16px;
}
.overlay[hidden] { display: none; }

.panel {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: #1d2b24;
  border: 1px solid #3a5a4a;
  border-radius: 14px;
  padding: 24px;
  text-align: center;
}

h1 { margin: 0 0 20px; font-size: 36px; letter-spacing: 8px; color: #ffd23f; }
h2 { margin: 0 0 12px; }

section { display: flex; flex-direction: column; gap: 12px; }
section[hidden] { display: none; }

label { display: flex; align-items: center; gap: 8px; text-align: left; }
.row { display: flex; gap: 8px; }

input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #4a6a5a;
  background: #0f1d16;
  color: #fff;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

button {
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: #3b5a4b;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
button:hover { filter: brightness(1.15); }
button.primary { background: #e07b24; font-weight: bold; }
button:disabled { opacity: 0.5; cursor: default; }

#seat-list { list-style: none; margin: 0; padding: 0; text-align: left; }
#seat-list li {
  padding: 8px 10px;
  border-bottom: 1px solid #2c4238;
  display: flex;
  justify-content: space-between;
}
#seat-list .ready { color: #7ee2a8; }
#seat-list .empty { color: #7a8f84; }

.hint { color: #9fb8aa; font-size: 13px; margin: 0; }
.msg { min-height: 1.2em; color: #ff9b8a; margin: 12px 0 0; font-size: 14px; }
#result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* 结算：两队级数、名次、本局战绩 */
.result-panel { max-width: 440px; max-height: calc(var(--app-h) - 32px); overflow-y: auto; }
.rs-levels { display: flex; gap: 10px; }
.rs-team { flex: 1; display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 12px; border-radius: 10px; background: #14211b; color: #cfe0d6; }
.rs-team.mine { background: #2a3f22; outline: 1px solid #7fa860; }
.rs-team b { font-size: 22px; color: #fff; }
.rs-up { margin-left: 6px; color: #ffd23f; font-weight: bold; }
.rs-note { margin: 10px 0 0; color: #e8efe9; }
.rs-note.sub { margin-top: 2px; color: #9fb8aa; font-size: 13px; }
.rs-order { list-style: none; margin: 12px 0 0; padding: 0; text-align: left; }
.rs-order li { display: flex; gap: 12px; padding: 4px 8px; border-radius: 6px; color: #cfe0d6; }
.rs-order li span:first-child { width: 3em; color: #9fb8aa; }
.rs-order li.mine { color: #fff; background: rgba(127, 168, 96, 0.15); }
.rs-history { margin-top: 14px; text-align: left; }
.rs-sum { font-size: 14px; color: #cfe0d6; margin-bottom: 6px; }
.rs-scroll { max-height: 150px; overflow-y: auto; border: 1px solid #2c4238; border-radius: 8px; }
.rs-history table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rs-history th { position: sticky; top: 0; background: #1d2b24; color: #9fb8aa; font-weight: normal; }
.rs-history th, .rs-history td { padding: 4px 6px; text-align: center; border-bottom: 1px solid #24362d; }
.rs-history tr.win td:nth-child(3) { color: #7ee2a8; }
.rs-history tr.lose td:nth-child(3) { color: #ff9b8a; }
.result-panel .hint { margin-top: 12px; }

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
}
.icon-btn img { width: 100%; height: 100%; }

.chat-btn {
  padding: 0;
  background: none;
}
.chat-btn img { display: block; height: 40px; }
.chat-btn[hidden] { display: none; }

/* 右上角按钮一排 */
#top-bar { position: fixed; top: 10px; right: 12px; z-index: 10; display: flex; align-items: center; gap: 8px; }
#top-bar > [hidden] { display: none; }

/* 托管：右上角开关 + 托管中底部提示条 */
.auto-btn {
  height: 38px;
  white-space: nowrap;
  padding: 0 16px;
  font-size: 14px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid #5d7d6c;
}
.auto-btn[hidden] { display: none; }
.auto-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px 10px 20px;
  border-radius: 28px;
  background: rgba(10, 20, 15, 0.85);
  border: 1px solid #e07b24;
  white-space: nowrap;
}
.auto-bar[hidden] { display: none; }
.auto-bar button { padding: 8px 18px; border-radius: 20px; }

#chat-panel {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 20;
  width: min(320px, calc(var(--app-w) - 24px));
  max-height: calc(var(--app-h) - 80px);
  display: flex;
  flex-direction: column;
  background: #f4ead0;
  color: #5a3a17;
  border: 2px solid #c99a4a;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
#chat-panel[hidden] { display: none; }

.chat-tabs { display: flex; }
.chat-tabs button {
  flex: 1;
  border-radius: 0;
  background: #e2cfa0;
  color: #7a5427;
  font-weight: bold;
}
.chat-tabs button.active { background: #e9a53f; color: #fff; }

#chat-phrases {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
}
#chat-phrases[hidden] { display: none; }
#chat-phrases button {
  width: 100%;
  text-align: left;
  background: none;
  color: #5a3a17;
  font-size: 15px;
  padding: 9px 10px;
  border-bottom: 1px dashed #d9c08d;
  border-radius: 0;
}
#chat-phrases button:hover { background: #ecdcb2; }

#chat-emojis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  overflow-y: auto;
}
#chat-emojis[hidden] { display: none; }
#chat-emojis button { padding: 4px; background: none; }
#chat-emojis button:hover { background: #ecdcb2; }
#chat-emojis img { width: 100%; max-width: 60px; aspect-ratio: 1; object-fit: contain; }

#chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #d9c08d; }
#chat-form input { background: #fffaf0; color: #3a2a10; border-color: #c99a4a; }
#chat-form button { background: #e9a53f; }

/* 矮屏（手机横屏 / 竖屏横过来）：结算弹窗紧凑排版，名次两列 */
body.compact .result-panel { max-width: 560px; padding: 14px 18px; }
body.compact .result-panel h2 { font-size: 20px; margin-bottom: 8px; }
body.compact .rs-team { padding: 6px 10px; }
body.compact .rs-team b { font-size: 18px; }
body.compact .rs-note { margin-top: 6px; font-size: 14px; }
body.compact .rs-order { display: grid; grid-template-columns: 1fr 1fr; margin-top: 8px; font-size: 14px; }
body.compact .rs-history { margin-top: 8px; }
body.compact .rs-scroll { max-height: 96px; }
body.compact #result-actions { margin-top: 10px; }
body.compact #result-actions button { padding: 8px 16px; }
body.compact .auto-bar { bottom: 12px; padding: 6px 8px 6px 14px; font-size: 13px; }

/* 大厅：账号栏、登录注册 */
.account { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: #14211b; text-align: left; min-height: 52px; }
.account img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.account .who { flex: 1; min-width: 0; }
.account .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .who span { font-size: 12px; color: #9fb8aa; }
.account button { padding: 6px 12px; font-size: 14px; }
#name-row[hidden] { display: none; }
.auth-tabs { display: flex; gap: 6px; }
.auth-tabs button { flex: 1; background: #14211b; color: #9fb8aa; }
.auth-tabs button.active { background: #3b5a4b; color: #fff; }
#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input[hidden] { display: none; }

/* 断线 / 服务器更新提示（在最上层，横竖屏都在屏幕顶部居中） */
.net-banner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 50;
  padding: 8px 18px; border-radius: 18px; background: rgba(160, 60, 30, 0.92); font-size: 14px; white-space: nowrap; }
.net-banner[hidden] { display: none; }

/* 玩法说明：左侧章节、右侧内容；窄屏时章节在上面横向滚动 */
#guide { z-index: 30; }
.guide-panel {
  width: 100%; max-width: 760px; height: min(640px, calc(var(--app-h) - 32px));
  display: grid; grid-template-columns: 150px 1fr; grid-template-rows: auto 1fr auto;
  background: #1d2b24; border: 1px solid #3a5a4a; border-radius: 14px; overflow: hidden; text-align: left;
}
.guide-panel header { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #2c4238; }
.guide-panel header h2 { flex: 1; margin: 0; font-size: 20px; color: #ffd23f; }
.guide-panel header button { padding: 6px 12px; font-size: 14px; }
.g-x { background: none !important; font-size: 18px !important; }
.g-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; border-right: 1px solid #2c4238; overflow-y: auto; }
.g-nav button { background: none; text-align: left; padding: 9px 10px; font-size: 14px; color: #cfe0d6; border-radius: 6px; }
.g-nav button.active { background: #3b5a4b; color: #fff; }
.g-body { padding: 4px 20px 16px; overflow-y: auto; font-size: 15px; line-height: 1.65; color: #e3ece6; -webkit-user-select: text; user-select: text; }
.g-body h3 { margin: 14px 0 6px; font-size: 18px; }
.g-body h4 { margin: 16px 0 4px; font-size: 15px; color: #ffd23f; }
.g-body p { margin: 6px 0; }
.g-body ul { margin: 6px 0; padding-left: 20px; }
.g-body li { margin: 4px 0; }
.g-order { padding: 8px 12px; border-radius: 8px; background: #14211b; font-size: 14px; }
.g-note { color: #9fb8aa; font-size: 13px; }
.g-cards { display: inline-block; margin: 6px 14px 6px 0; vertical-align: top; }
.g-cards div { display: flex; }
.g-cards img { width: 44px; height: 56px; margin-right: -22px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.g-cards img:last-child { margin-right: 0; }
.g-cards img.wild { outline: 3px solid #ffd23f; outline-offset: -3px; }
.g-cards figcaption { font-size: 12px; color: #9fb8aa; margin-top: 3px; }
.g-pager { display: flex; justify-content: space-between; margin-top: 20px; }
.g-pager button { font-size: 14px; padding: 8px 14px; }
.guide-panel footer { grid-column: 1 / -1; padding: 10px 16px; border-top: 1px solid #2c4238; text-align: center; }
@media (max-width: 600px) {
  .guide-panel { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; }
  .g-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid #2c4238; }
  .g-nav button { white-space: nowrap; }
}
body.compact .guide-panel { grid-template-columns: 130px 1fr; }
body.compact .guide-panel footer { display: none; }

/* 大厅右上角的语言切换 */
.lang-btn { position: absolute; top: 12px; right: 12px; padding: 5px 10px; font-size: 13px; background: #14211b; border: 1px solid #3a5a4a; }

/* 回放页：上方选项、下方播放控制 */
/* 牌桌只占中间，控制条在上下，不挡牌 */
.replay-page #stage { top: 46px; bottom: 92px; }
.replay-page #rp-top, .replay-page #rp-bar {
  position: fixed; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 6px 12px; background: #0a1a12;
}
.replay-page #rp-top { top: 0; height: 46px; font-size: 13px; }
.replay-page #rp-bar { bottom: 0; height: 92px; flex-direction: column; flex-wrap: nowrap; gap: 6px; }
.replay-page #rp-bar[hidden] { display: none; }
.replay-page .rp-buttons { display: flex; gap: 6px; align-items: center; }
.replay-page button, .replay-page select { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.replay-page select { background: #3b5a4b; color: #fff; border: 0; }
.replay-page .rp-home { color: #ffd23f; text-decoration: none; padding: 4px 6px; }
.replay-page .rp-check { font-size: 13px; }
.replay-page #rp-status { font-size: 13px; color: #cfe0d6; }
.replay-page #rp-progress { width: min(520px, 80vw); }
.rp-msg { position: fixed; top: 40%; left: 0; right: 0; text-align: center; font-size: 18px; }
.rp-msg[hidden] { display: none; }

/* 大厅：我的回放列表 */
#replay-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; text-align: left; }
#replay-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid #2c4238; font-size: 14px; }
#replay-list li span { color: #9fb8aa; font-size: 12px; }
#replay-list a { color: #ffd23f; white-space: nowrap; }

/* 加载画面 */
#loading { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #17563b 0%, #0e3f2a 55%, #07251a 100%); }
#loading[hidden] { display: none; }
.loading-box { width: min(360px, 80vw); text-align: center; }
.loading-title { font-size: 44px; font-weight: bold; letter-spacing: 10px; color: #ffd23f; margin-bottom: 22px; text-shadow: 0 3px 8px rgba(0,0,0,.5); }
.loading-bar { height: 10px; border-radius: 5px; background: rgba(0,0,0,.35); overflow: hidden; }
.loading-bar i { display: block; height: 100%; width: 0; border-radius: 5px; background: linear-gradient(90deg, #ffd23f, #e07b24); transition: width .2s; }
#loading-text { margin: 12px 0 0; color: #cfe0d6; font-size: 14px; }
.loading-tip { margin: 18px 0 0; color: #9fb8aa; font-size: 13px; line-height: 1.5; }
#loading-retry { margin-top: 16px; }
#loading-retry[hidden] { display: none; }

/* 全屏按钮 / iPhone 安装提示 */
.fs-btn { width: 38px; padding: 0; font-size: 20px; line-height: 1; }
#ios-install { margin-top: 2px; }
#ios-install a { color: #ffd23f; margin-left: 4px; }
#ios-install[hidden], #btn-install[hidden] { display: none; }

/* 设置面板 */
#settings { z-index: 30; }
.settings-panel { max-width: 420px; max-height: calc(var(--app-h) - 32px); overflow-y: auto; text-align: left; padding: 16px 20px; }
.settings-panel header { display: flex; align-items: center; justify-content: space-between; }
.settings-panel header h2 { margin: 0; color: #ffd23f; font-size: 20px; }
.set-sec { gap: 8px; padding: 12px 0; border-bottom: 1px solid #2c4238; }
.set-sec:last-child { border-bottom: 0; }
.set-sec h3 { margin: 0; font-size: 14px; color: #9fb8aa; font-weight: normal; }
.set-switch { justify-content: space-between; font-size: 15px; }
.set-switch input { width: 20px; height: 20px; flex: none; accent-color: #e07b24; }
.set-lang { display: flex; gap: 8px; }
.set-lang button { flex: 1; }
.set-lang button.active { background: #e07b24; font-weight: bold; }
.set-avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.set-avatars button { padding: 0; border-radius: 8px; overflow: hidden; border: 2px solid transparent; background: none; aspect-ratio: 1; }
.set-avatars button.active { border-color: #ffd23f; }
.set-avatars img { width: 100%; height: 100%; object-fit: cover; display: block; }
.set-msg { margin: 0; min-height: 1em; font-size: 13px; color: #ff9b8a; }
.set-msg.ok { color: #7ee2a8; }

/* 记牌器：左上角级数下面一排小格子 */
.counter { position: fixed; top: 52px; left: 12px; z-index: 9; display: flex; gap: 2px; padding: 4px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.45); pointer-events: none; }
.counter[hidden] { display: none; }
.counter div { display: flex; flex-direction: column; align-items: center; min-width: 24px; padding: 2px 0; border-radius: 6px; }
.counter b { font-size: 12px; color: #cfe0d6; font-weight: normal; }
.counter span { font-size: 15px; font-weight: bold; color: #fff; }
.counter .lv b { color: #ffd23f; }
.counter .many span { color: #ff9b5e; }
.counter .none { opacity: 0.35; }
#btn-counter.active { border-color: #ffd23f; color: #ffd23f; }
body.compact .counter { top: 44px; left: 8px; }
body.compact .counter div { min-width: 20px; }
body.compact .counter b { font-size: 10px; }
body.compact .counter span { font-size: 13px; }
