/* ============ 欢乐麻将 - 自适应样式 ============ */
:root {
  --bg: #0d1f16;
  --bg2: #12291d;
  --felt: #1d6a45;
  --felt-dark: #145236;
  --line: rgba(255, 255, 255, .09);
  --gold: #e8c35a;
  --gold-dark: #b8943a;
  --text: #ece9df;
  --dim: #9fb3a6;
  --red: #d24b3e;
  --green: #2e9e63;
  --blue: #4a90d9;
  --tile-w: 46px;
  --tile-h: 62px;
  --tile-fs: 19px;
  --radius: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg2), var(--bg) 70%);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}
#app, .view { height: 100%; }
.hidden { display: none !important; }

/* ---------- 通用 ---------- */
.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 15px;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #2e9e63, #238451); border-color: rgba(255,255,255,.14); font-weight: 600; }
.btn.danger { background: linear-gradient(180deg, #d24b3e, #b0392e); }
.btn.gold { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #201a05; font-weight: 700; }
.btn.ghost { background: rgba(255,255,255,.06); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 麻将牌 ---------- */
.mj {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--tile-w);
  height: var(--tile-h);
  background: linear-gradient(160deg, #fdfaf1, #ece5d2);
  border-radius: 7px;
  border: 1px solid #c9c0a8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35), inset 0 1px 0 #fff;
  flex: none;
}
.mj b { font-size: var(--tile-fs); line-height: 1; font-weight: 700; }
.mj i { font-style: normal; font-size: calc(var(--tile-fs) * .52); line-height: 1.15; }
.s-m { color: var(--red); }
.s-t { color: var(--green); }
.s-d { color: var(--blue); }
.mj.back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.10) 0 4px, transparent 4px 8px),
    linear-gradient(160deg, #2c9b68, #1e7147);
  border-color: #155c39;
}
.mj.back b, .mj.back i { visibility: hidden; }
.mj.demo { width: 34px; height: 46px; --tile-fs: 15px; }

/* ---------- Toast ---------- */
#toast-wrap {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 1000; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: rgba(10, 22, 15, .92);
  border: 1px solid rgba(232, 195, 90, .4);
  color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toastIn .18s ease-out;
  max-width: 92vw;
}
.toast.err { border-color: rgba(210, 75, 62, .6); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- 弹窗 ---------- */
#modal-wrap {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(4, 10, 7, .66);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: linear-gradient(180deg, #16301f, #10251a);
  border: 1px solid rgba(232, 195, 90, .35);
  border-radius: 16px;
  width: min(520px, 94vw);
  max-height: 82vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: toastIn .18s ease-out;
}
.modal-h { padding: 14px 18px; font-size: 16px; font-weight: 700; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 14px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- 登录页 ---------- */
#view-auth { display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: min(400px, 94vw);
  background: linear-gradient(180deg, #16301f, #0f2418);
  border: 1px solid rgba(232, 195, 90, .3);
  border-radius: 18px;
  padding: 30px 26px;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-tiles { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.brand-tiles .mj:nth-child(2) { transform: translateY(-6px) rotate(-4deg); }
.brand h1 { font-size: 26px; letter-spacing: 6px; color: var(--gold); }
.brand p { color: var(--dim); font-size: 13px; margin-top: 6px; }
.tabs { display: flex; background: rgba(255,255,255,.06); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab { flex: 1; padding: 9px; border: 0; background: transparent; color: var(--dim); border-radius: 8px; font-size: 15px; cursor: pointer; }
.tab.active { background: rgba(232, 195, 90, .18); color: var(--gold); font-weight: 600; }
#auth-form input {
  width: 100%; margin-bottom: 12px; padding: 12px 14px;
  background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 15px; outline: none;
}
#auth-form input:focus { border-color: rgba(232, 195, 90, .5); }
.auth-tip { text-align: center; color: var(--dim); font-size: 12px; margin-top: 14px; }

/* ---------- 大厅 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.18);
}
.tb-name { font-weight: 700; font-size: 16px; }
.coin { color: var(--gold); font-weight: 700; font-size: 18px; }
.coin::before { content: "◆ "; font-size: 13px; }
.card-chip {
  margin-left: 10px; color: #fff; font-size: 13px; font-weight: 600;
  background: linear-gradient(180deg, #d24b3e, #a93529);
  border-radius: 12px; padding: 3px 10px;
}
.tb-mid { display: flex; align-items: center; }
.tb-right { display: flex; gap: 8px; }
.contact-bar {
  text-align: center; font-size: 14px; color: var(--text);
  background: linear-gradient(90deg, rgba(210,75,62,.22), rgba(232,195,90,.16));
  border: 1px solid rgba(210,75,62,.4);
  border-radius: 10px; padding: 9px 12px;
}
.contact-bar b { color: var(--gold); font-size: 16px; letter-spacing: 1px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; }
.admin-table th { color: var(--dim); font-weight: 600; }
.admin-input {
  width: 62px; padding: 5px 7px; background: rgba(0,0,0,.3);
  border: 1px solid var(--line); border-radius: 7px; color: var(--text);
  font-size: 13px; outline: none; margin-right: 6px;
}
.lobby-body {
  height: calc(100% - 58px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 16px; align-content: start;
  max-width: 760px; margin: 0 auto; width: 100%;
}
.panel { background: rgba(255,255,255,.045); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h2 { font-size: 16px; margin-bottom: 14px; color: var(--gold); }
.opt-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.opt-row label { color: var(--dim); font-size: 14px; flex: none; }
.seg { display: flex; flex: 1; background: rgba(0,0,0,.25); border-radius: 10px; padding: 4px; gap: 4px; }
.seg-i { flex: 1; padding: 8px 4px; border: 0; background: transparent; color: var(--dim); border-radius: 8px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.seg-i.active { background: rgba(232, 195, 90, .2); color: var(--gold); font-weight: 600; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; padding: 12px 14px; background: rgba(0,0,0,.25);
  border: 1px solid var(--line); border-radius: 10px; color: var(--text);
  font-size: 18px; letter-spacing: 4px; outline: none; text-align: center;
}
.hint { color: var(--dim); font-size: 12px; margin-top: 10px; line-height: 1.6; }

/* ---------- 对局页布局 ---------- */
#view-game { display: flex; flex-direction: column; }
.game-bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  background: rgba(0,0,0,.25); border-bottom: 1px solid var(--line);
  flex: none;
}
.gb-mid { flex: 1; display: flex; align-items: center; gap: 10px; justify-content: center; min-width: 0; }
.gb-room { color: var(--gold); font-weight: 700; letter-spacing: 2px; }
.gb-info { color: var(--dim); font-size: 13px; }
.gb-wall { color: var(--dim); font-size: 13px; }

.table {
  flex: 1; position: relative; min-height: 0;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255,255,255,.05), transparent 60%),
    repeating-linear-gradient(38deg, rgba(0,0,0,.045) 0 3px, transparent 3px 9px),
    linear-gradient(180deg, var(--felt), var(--felt-dark));
  border-left: 10px solid #3a2a18;
  border-right: 10px solid #3a2a18;
}
.center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.pool {
  display: flex; flex-wrap: wrap; gap: 5px; justify-content: center;
  max-width: min(560px, 86%);
  --tile-w: 30px; --tile-h: 40px; --tile-fs: 12px;
}
.pool .mj { opacity: .92; }
.pool .mj.claim { outline: 2px solid var(--gold); outline-offset: 1px; opacity: 1; transform: scale(1.12); }
.hint-line { margin-top: 10px; font-size: 13px; color: rgba(255,255,255,.75); text-shadow: 0 1px 3px rgba(0,0,0,.5); min-height: 18px; }

/* 座位卡 */
.seat { position: absolute; z-index: 5; }
.seat-top { top: 10px; left: 50%; transform: translateX(-50%); }
.seat-left { top: 42%; left: 10px; transform: translateY(-50%); }
.seat-right { top: 42%; right: 10px; transform: translateY(-50%); }
.seat-card {
  background: rgba(8, 20, 13, .82);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 128px;
  max-width: 190px;
  backdrop-filter: blur(3px);
  transition: box-shadow .2s, border-color .2s;
}
.seat-card.turn { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(232,195,90,.35); }
.sc-row1 { display: flex; align-items: center; gap: 6px; }
.sc-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 96px; }
.sc-dot { width: 7px; height: 7px; border-radius: 50%; background: #666; flex: none; }
.sc-dot.on { background: var(--green); }
.sc-pts { margin-left: auto; color: var(--gold); font-size: 12px; font-weight: 600; }
.sc-row2 { display: flex; align-items: center; gap: 4px; margin-top: 6px; --tile-w: 15px; --tile-h: 20px; flex-wrap: wrap; }
.sc-row2 .mj { border-radius: 3px; }
.sc-count { color: var(--dim); font-size: 12px; }
.sc-badge { font-size: 11px; color: var(--gold); border: 1px solid rgba(232,195,90,.4); padding: 1px 6px; border-radius: 8px; margin-left: 4px; }
.sc-badge.hu { color: var(--red); border-color: rgba(210,75,62,.6); }
.sc-melds { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; --tile-w: 14px; --tile-h: 19px; --tile-fs: 8px; }
.sc-melds .mj { border-radius: 2px; }
.sc-melds .meld { display: flex; gap: 1px; padding: 2px; background: rgba(0,0,0,.3); border-radius: 4px; }

/* 等待区 */
.wait-box { text-align: center; z-index: 6; }
.wait-room { font-size: 34px; letter-spacing: 8px; color: var(--gold); font-weight: 800; text-shadow: 0 2px 10px rgba(0,0,0,.4); }
.wait-mode { color: rgba(255,255,255,.85); margin: 8px 0 16px; font-size: 14px; }
.wait-btns { display: flex; gap: 12px; justify-content: center; }
.wait-seats { margin-top: 16px; color: rgba(255,255,255,.8); font-size: 13px; line-height: 1.9; }
.countdown { color: var(--gold); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* 我的区域 */
.my-area {
  flex: none;
  background: linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,.55));
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.my-top { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.my-info { flex: none; }
.my-info.turn .mi-name { color: var(--gold); }
.mi-name { font-weight: 700; font-size: 15px; }
.mi-sub { color: var(--dim); font-size: 12px; margin-top: 2px; }
.my-melds { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; --tile-w: 26px; --tile-h: 35px; --tile-fs: 11px; }
.my-melds .meld { display: flex; gap: 1px; padding: 2px 3px; background: rgba(0,0,0,.35); border-radius: 5px; }
.my-melds .meld.an { outline: 1px dashed rgba(232,195,90,.5); }
.my-hand {
  display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 2px 4px; min-height: calc(var(--tile-h) + 14px);
  scrollbar-width: none;
}
.my-hand::-webkit-scrollbar { display: none; }
.my-hand .mj { cursor: pointer; transition: transform .12s; }
.my-hand .mj:active { transform: translateY(4px); }
.my-hand .mj.drawn { transform: translateY(-8px); }
.my-hand .mj.drawn::after {
  content: ""; position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  width: 8px; height: 4px; border-radius: 4px; background: var(--gold);
}
.my-hand .mj { position: relative; }
.my-hand.locked .mj { cursor: default; }

/* 操作条 */
.action-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tile-h) + 76px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; align-items: center;
  background: rgba(8, 20, 13, .9);
  border: 1px solid rgba(232,195,90,.4);
  padding: 8px 12px; border-radius: 14px;
  z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: 96vw; flex-wrap: wrap; justify-content: center;
}
.act-btn {
  border: 0; border-radius: 12px; padding: 10px 16px;
  font-size: 16px; font-weight: 700; cursor: pointer; color: #fff;
  display: inline-flex; align-items: center; gap: 5px;
}
.act-hu { background: linear-gradient(180deg, #e04b3c, #b83326); box-shadow: 0 3px 0 #7e2015; }
.act-gang { background: linear-gradient(180deg, #8e6fe0, #6a4fc0); box-shadow: 0 3px 0 #4a338a; }
.act-peng { background: linear-gradient(180deg, #2e9e63, #22854f); box-shadow: 0 3px 0 #155c35; }
.act-chi { background: linear-gradient(180deg, #4a90d9, #3a76b8); box-shadow: 0 3px 0 #255180; }
.act-pass { background: rgba(255,255,255,.14); box-shadow: 0 3px 0 rgba(0,0,0,.3); }
.act-btn:active { transform: translateY(2px); box-shadow: none; }
.act-btn .mini { --tile-w: 20px; --tile-h: 27px; --tile-fs: 10px; display: inline-flex; gap: 1px; }
.act-btn .mini .mj { border-radius: 3px; }

/* ---------- 战绩 / 排行 ---------- */
.rec-item { border-bottom: 1px solid var(--line); padding: 10px 2px; }
.rec-line1 { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--dim); }
.rec-delta { font-size: 20px; font-weight: 800; }
.rec-delta.pos { color: var(--green); }
.rec-delta.neg { color: var(--red); }
.rec-delta.zero { color: var(--dim); }
.rec-line2 { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; font-size: 12px; }
.rec-line2 span { color: var(--dim); }
.rec-line2 b { font-weight: 600; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.rank-no { width: 26px; color: var(--gold); font-weight: 800; text-align: center; }
.rank-name { flex: 1; }
.rank-pts { color: var(--gold); font-weight: 700; }

/* ============ 响应式 ============ */
@media (max-width: 760px) {
  :root { --tile-w: 40px; --tile-h: 54px; --tile-fs: 17px; }
  .seat-card { min-width: 104px; padding: 6px 8px; }
  .sc-name { max-width: 70px; font-size: 13px; }
  .sc-row2, .sc-melds { --tile-w: 13px; --tile-h: 17px; }
  .pool { --tile-w: 26px; --tile-h: 35px; --tile-fs: 11px; max-width: 92%; }
  .wait-room { font-size: 26px; }
}
@media (max-width: 420px) {
  :root { --tile-w: 36px; --tile-h: 49px; --tile-fs: 15px; }
  .seat-left, .seat-right { top: 34%; }
  .sc-melds, .sc-row2 { display: none; }
  .seat-card { min-width: 88px; }
  .pool { --tile-w: 23px; --tile-h: 31px; --tile-fs: 10px; gap: 4px; }
  .gb-info { display: none; }
  .act-btn { padding: 9px 13px; font-size: 15px; }
  .lobby-body { padding: 12px 10px 16px; gap: 12px; }
  .panel { padding: 14px; }
}
@media (min-width: 761px) and (orientation: landscape) {
  .lobby-body { align-content: center; justify-items: stretch; }
}
/* 手机横屏：压缩上下留白 */
@media (orientation: landscape) and (max-height: 460px) {
  :root { --tile-w: 38px; --tile-h: 52px; --tile-fs: 16px; }
  .game-bar { padding-top: 4px; }
  .my-top { min-height: 34px; }
  .seat-top { top: 6px; }
  .seat-left, .seat-right { top: 38%; }
}
