:root {
  --felt: #163a31;
  --felt-dark: #0b1d18;
  --felt-line: rgba(201, 168, 102, .28);
  --ivory: #f6efdd;
  --ivory-edge: #ddd0ad;
  --jade: #1f6b55;
  --ink: #18201d;
  --red: #a8291f;
  --gold: #c9a866;
  --mist: #a9c2b8;
  --tw: 40px; /* 手牌宽 */
  --sw: 22px; /* 小牌宽 */
  --ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --face: "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui); color: var(--ivory); background: var(--felt-dark);
  background-image: radial-gradient(ellipse 120% 80% at 50% 35%, var(--felt) 0%, var(--felt-dark) 70%);
  background-attachment: fixed;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ===== 牌 ===== */
.tile {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: var(--w, var(--tw)); height: calc(var(--w, var(--tw)) * 1.36);
  background: linear-gradient(180deg, #fffaf0 0%, var(--ivory) 70%);
  border-radius: calc(var(--w, var(--tw)) * 0.14);
  box-shadow: 0 calc(var(--w, var(--tw)) * 0.1) 0 var(--jade), 0 calc(var(--w, var(--tw)) * 0.1 + 2px) 3px rgba(0,0,0,.35), inset 0 -2px 0 var(--ivory-edge);
  color: var(--ink); font-family: var(--face); line-height: 1; flex: none;
  margin-bottom: calc(var(--w, var(--tw)) * 0.1);
}
.tile .n { font-size: calc(var(--w, var(--tw)) * 0.5); font-weight: 700; }
.tile .s { font-size: calc(var(--w, var(--tw)) * 0.36); margin-top: calc(var(--w, var(--tw)) * 0.06); font-weight: 700; }
.tile.m .s { color: var(--red); }
.tile.p .n, .tile.p .s { color: #1f4f8f; }
.tile.s .n, .tile.s .s { color: #1f7a4a; }
.tile.z .n { font-size: calc(var(--w, var(--tw)) * 0.62); }
.tile.z4 .n { color: var(--red); }
.tile.z5 .n { color: #1f7a4a; }
.tile.z6 .n { color: transparent; width: 62%; height: 52%; border: calc(var(--w, var(--tw)) * 0.06) solid #3b6db0; border-radius: 3px; }
.tile.wild::after {
  content: "财"; position: absolute; top: -6px; right: -5px; font-family: var(--ui); font-size: 10px; font-weight: 700;
  background: var(--gold); color: var(--ink); border-radius: 50%; width: 16px; height: 16px; display: grid; place-items: center;
}
.tile.back { background: linear-gradient(180deg, #2b8a6c, var(--jade)); box-shadow: 0 calc(var(--w, var(--tw)) * 0.1) 0 var(--ivory-edge), 0 calc(var(--w, var(--tw)) * 0.1 + 2px) 3px rgba(0,0,0,.35); }
.tile.small { --w: var(--sw); }
.tile.small .s { font-size: calc(var(--w) * 0.42); margin-top: 1px; }
.tile.small .n { font-size: calc(var(--w) * 0.48); }
.tile.small.wild::after { width: 11px; height: 11px; font-size: 8px; top: -3px; right: -3px; }
.tile.last { outline: 2px solid var(--gold); outline-offset: 1px; }
.tile.dim { filter: brightness(.6); }

/* ===== 大厅 ===== */
.lobby { max-width: 460px; margin: 0 auto; padding: 32px 20px 40px; }
.lobby h1 { font-family: var(--face); font-size: 52px; font-weight: 700; margin: 18px 0 2px; letter-spacing: .3em; color: #f3e6c4; }
.lobby .brand { display: flex; align-items: center; gap: 16px; }
.lobby .brand img { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.lobby .site { color: var(--gold); letter-spacing: .25em; font-size: 13px; }
.lobby .tag { color: var(--mist); margin: 14px 0 28px; line-height: 1.7; }
.lobby .rule b { font-family: var(--face); letter-spacing: .06em; }
.hero-tiles { display: flex; gap: 6px; --w: 46px; margin: 12px 0 24px; }
.hero-tiles .tile:nth-child(2) { transform: translateY(-6px) rotate(-3deg); }
.hero-tiles .tile:nth-child(4) { transform: translateY(-3px) rotate(2deg); }
.field { display: block; margin: 0 0 18px; }
.field span { display: block; color: var(--mist); font-size: 15px; margin-bottom: 6px; }
input[type=text], input[inputmode] {
  width: 100%; font: inherit; font-size: 20px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--felt-line); background: rgba(0,0,0,.28); color: var(--ivory);
}
.rules { display: grid; gap: 10px; margin-bottom: 18px; }
.rule {
  text-align: left; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--felt-line);
  background: rgba(255,255,255,.025); color: var(--ivory);
}
.rule b { font-size: 18px; display: block; }
.rule small { color: var(--mist); font-size: 14px; }
.rule[aria-pressed=true] { border-color: var(--gold); background: linear-gradient(180deg, rgba(201,168,102,.16), rgba(201,168,102,.05)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px; border-radius: 10px; border: 1px solid transparent; font-size: 18px; font-weight: 600; letter-spacing: .04em;
  background: var(--ivory); color: var(--ink); box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 6px 16px rgba(0,0,0,.25);
  transition: transform .08s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.red { background: linear-gradient(180deg, #bd3427, #8e1f17); color: #fff6ea; }
.btn.gold { background: linear-gradient(180deg, #ddc287, #b58f4c); color: #1b1408; }
.btn.ghost { background: rgba(255,255,255,.03); color: var(--ivory); box-shadow: none; border: 1px solid var(--felt-line); }
.btn.wide { width: 100%; }
.btn.sm { padding: 6px 12px; font-size: 15px; border-radius: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.or { text-align: center; color: var(--mist); margin: 22px 0 14px; }

/* ===== 等待房间 ===== */
.wait { max-width: 520px; margin: 0 auto; padding: 24px 18px 40px; }
.code { font-family: var(--face); font-size: 68px; letter-spacing: .25em; margin: 4px 0 10px; color: #f3e6c4; }
.seatlist { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.seatcard { border: 1px solid var(--felt-line); border-radius: 12px; padding: 12px; min-height: 76px; background: rgba(0,0,0,.18); }
.seatcard.me { border-color: var(--gold); }
.seatcard .who { font-size: 19px; font-weight: 700; }
.seatcard .meta { color: var(--mist); font-size: 14px; margin-top: 4px; }
.seatcard.empty { color: var(--mist); display: grid; place-items: center; border-style: dashed; }

/* ===== 牌桌 ===== */
.table { height: 100dvh; display: grid; grid-template-rows: auto auto 1fr auto; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); font-size: 14px; color: var(--mist); background: rgba(0,0,0,.3); border-bottom: 1px solid var(--felt-line); }
.topbar .grow { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.opp-top { padding: 6px 8px 0; }
.mid { display: grid; grid-template-columns: minmax(70px, 22%) 1fr minmax(70px, 22%); gap: 4px; min-height: 0; padding: 0 4px; }
.player { min-width: 0; }
.pname { display: flex; align-items: center; gap: 6px; font-size: 14px; flex-wrap: wrap; }
.pname b { font-size: 15px; color: var(--ivory); }
.pname .score { color: var(--gold); font-weight: 700; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.35); color: var(--mist); }
.badge.dealer { background: var(--gold); color: var(--ink); font-weight: 700; }
.badge.won { background: var(--red); color: #fff; }
.player.turn .pname b { color: var(--gold); }
.player.turn .pname b::before { content: "● "; }
.tilerow { display: flex; flex-wrap: wrap; gap: 2px; align-items: flex-end; }
.melds { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.meld { display: flex; gap: 1px; }
.discards { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 4px; }
.side .discards { max-height: 34vh; overflow: hidden; }
.center {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px;
  border-radius: 18px; background: radial-gradient(ellipse at 50% 50%, rgba(255,255,255,.04), rgba(0,0,0,.2)); border: 1px solid var(--felt-line); padding: 8px; min-height: 0;
  box-shadow: inset 0 0 40px rgba(0,0,0,.35);
}
.center .wall { font-size: 15px; color: var(--mist); }
.center .bignote { font-size: 18px; font-weight: 700; }
.center .timer { font-size: 28px; font-family: var(--face); color: var(--gold); }
.center .lastplay { --w: 46px; }
.center .info { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.center > .discards { justify-content: center; width: 100%; }
.center { justify-content: space-between; }
.log { font-size: 13px; color: var(--mist); max-height: 3.6em; overflow: hidden; }
.me { padding: 4px 6px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(0,0,0,.1), rgba(0,0,0,.35)); border-top: 1px solid var(--felt-line); }
.hand { display: flex; justify-content: center; gap: 2px; align-items: flex-end; padding-top: 12px; min-height: calc(var(--tw) * 1.5 + 14px); }
.hand .tile { transition: transform .12s; border: 0; padding: 0; }
.hand .tile.sel { transform: translateY(-12px); }
.hand .tile.drawn { margin-left: 10px; }
.hand .tile.blocked { filter: brightness(.7); }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 50px; align-items: center; padding: 4px 0; }
.actions .hint { color: var(--mist); font-size: 15px; }
.chi-opt { display: inline-flex; gap: 1px; --w: 26px; }

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; background: rgba(10,25,20,.78); display: grid; place-items: center; z-index: 10; padding: 12px; }
.sheet { background: linear-gradient(180deg, #122c25, #0b1d18); border: 1px solid var(--gold); box-shadow: 0 30px 80px rgba(0,0,0,.6); border-radius: 16px; padding: 18px; width: min(560px, 100%); max-height: 92dvh; overflow: auto; }
.sheet h2 { font-family: var(--face); font-size: 28px; margin: 0 0 10px; }
.winbox { border-top: 1px solid var(--felt-line); padding: 10px 0; }
.fans { color: var(--gold); font-size: 15px; margin: 4px 0; }
.deltas { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin: 12px 0; font-size: 17px; }
.plus { color: #8fe0b0; font-weight: 700; } .minus { color: #ff9d8f; font-weight: 700; }
.revealhand { display: flex; flex-wrap: wrap; gap: 2px; margin: 4px 0 8px; }

#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 16px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.on { opacity: 1; }

@media (min-width: 700px) { :root { --tw: 48px; --sw: 26px; } }
@media (max-width: 420px) { :root { --tw: calc((100vw - 48px) / 14.6); --sw: 18px; } .mid { grid-template-columns: 64px 1fr 64px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.help h3 { font-family: var(--face); font-size: 21px; margin: 18px 0 6px; color: var(--gold); }
.help p, .help li { font-size: 17px; line-height: 1.6; }
.help ul { padding-left: 22px; margin: 6px 0; }
.help .tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.help .revealhand { --sw: 24px; }

.install p, .install li { font-size: 17px; line-height: 1.7; }

/* ===== v4：真实牌面、罗盘、头像、圆形按钮 ===== */
.tile .face { width: 88%; height: 88%; display: block; }
.tile { padding: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  font-family: var(--face); font-weight: 700; font-size: 15px; color: #fff8ea;
  background: radial-gradient(circle at 35% 30%, hsl(var(--h) 45% 48%), hsl(var(--h) 50% 26%));
  border: 1.5px solid var(--gold); box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.phead { display: flex; align-items: center; gap: 6px; }
.pinfo { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.pinfo b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinfo .score { font-size: 13px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin: 3px 0; }
.badge.void { color: #fff; }
.badge.v0 { background: #9e2a22; } .badge.v1 { background: #a8661c; } .badge.v2 { background: #1f7a4a; }
.player.turn .avatar { box-shadow: 0 0 0 3px rgba(201,168,102,.55), 0 0 18px rgba(201,168,102,.7); }
.player.turn .pname b::before { content: none; }
.status {
  font-family: var(--face); font-weight: 700; font-size: 16px; letter-spacing: .08em; margin: 2px 0;
  background: linear-gradient(180deg, #f4dfa6, #c9a050); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: pulse 1.6s ease-in-out infinite;
}
.status.won { background: none; color: #ff9d8f; animation: none; }
@keyframes pulse { 50% { opacity: .55; } }
.side-backs { gap: 0; flex-direction: column; align-items: flex-start; margin: 2px 0; }
.sideback { display: block; width: 22px; height: 6px; border-radius: 2px; background: linear-gradient(90deg, var(--ivory-edge) 0 35%, var(--jade) 35%); margin-bottom: 1px; box-shadow: 0 1px 0 rgba(0,0,0,.3); }

.compass {
  position: relative; width: 112px; height: 112px; border-radius: 16px;
  background: linear-gradient(160deg, #1b3d35, #0c211c); border: 1px solid rgba(201,168,102,.45);
  box-shadow: inset 0 0 18px rgba(0,0,0,.6), 0 8px 22px rgba(0,0,0,.4);
}
.compass .wind { position: absolute; font-family: var(--face); font-weight: 700; font-size: 17px; color: #6f8f84; }
.compass .wind.on { color: #f4dfa6; text-shadow: 0 0 10px rgba(244,223,166,.8); }
.compass .w-b { bottom: 4px; left: 50%; transform: translateX(-50%); }
.compass .w-t { top: 4px; left: 50%; transform: translateX(-50%) rotate(180deg); }
.compass .w-l { left: 6px; top: 50%; transform: translateY(-50%) rotate(90deg); }
.compass .w-r { right: 6px; top: 50%; transform: translateY(-50%) rotate(-90deg); }
.ccore { position: absolute; inset: 28px; border-radius: 8px; background: #08161299; border: 1px solid rgba(201,168,102,.25); display: grid; place-content: center; text-align: center; }
.cnum { font-family: var(--face); font-size: 24px; color: #f3e6c4; line-height: 1; }
.csub { font-size: 10px; color: var(--mist); margin-top: 2px; }
.center .timer { font-size: 22px; min-height: 26px; }
.rulename { font-size: 12px; color: var(--mist); letter-spacing: .06em; }
.lastplay { display: flex; flex-direction: column; align-items: center; gap: 2px; --w: 44px; }
.lpfrom { font-size: 12px; color: var(--mist); }
.wildinfo { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--mist); }

.round-btn {
  width: 66px; height: 66px; border-radius: 50%; border: 0; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--face); color: #fff8ea; box-shadow: inset 0 2px 0 rgba(255,255,255,.35), inset 0 -4px 0 rgba(0,0,0,.25), 0 8px 18px rgba(0,0,0,.45);
}
.round-btn span { font-size: 28px; font-weight: 900; line-height: 1; }
.round-btn small { font-size: 11px; font-family: var(--ui); opacity: .9; margin-top: 2px; }
.round-btn:active { transform: scale(.95); }
.round-btn.hu { background: radial-gradient(circle at 35% 30%, #e0523f, #8e1c14); width: 76px; height: 76px; }
.round-btn.hu span { font-size: 34px; }
.round-btn.pong, .round-btn.gang { background: radial-gradient(circle at 35% 30%, #f1d58f, #a87b2c); color: #2a1a05; }
.round-btn.pass { background: radial-gradient(circle at 35% 30%, #4fb7a3, #1c5f52); }
.round-btn.dq0 { background: radial-gradient(circle at 35% 30%, #e0523f, #8e1c14); }
.round-btn.dq1 { background: radial-gradient(circle at 35% 30%, #efb15a, #a4601a); }
.round-btn.dq2 { background: radial-gradient(circle at 35% 30%, #4fbf8a, #1a6a43); }
.round-btn.dq.best { outline: 3px solid #f4dfa6; outline-offset: 3px; }
.dq-hint { width: 100%; text-align: center; color: var(--mist); font-size: 14px; }
.chi-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--gold); background: rgba(0,0,0,.35); color: var(--ivory); }
.chi-btn b { font-family: var(--face); font-size: 20px; }
.actions { gap: 12px; min-height: 84px; }

/* 横屏：手机横过来更像真牌桌 */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --tw: min(calc((100vw - 80px) / 15.5), 13vh); --sw: min(22px, 5.5vh); }
  .table { grid-template-rows: auto auto 1fr auto; }
  .topbar { padding-top: 4px; }
  .opp-top { display: flex; justify-content: center; padding-top: 2px; }
  .opp-top .player { display: flex; align-items: center; gap: 10px; }
  .opp-top .tilerow { flex-wrap: nowrap; }
  .mid { grid-template-columns: 16% 1fr 16%; }
  .center { flex-direction: column; }
  .compass { width: 92px; height: 92px; }
  .ccore { inset: 23px; }
  .me { display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 8px; padding: 2px 10px 6px; }
  .me .pname { grid-column: 1 / -1; }
  .me .melds { grid-column: 3; grid-row: 2; margin: 0; }
  .me .hand { grid-column: 1 / 3; grid-row: 2; justify-content: flex-start; padding-top: 14px; }
  .me .actions { position: fixed; right: 14px; bottom: calc(var(--tw) * 1.5 + 24px); min-height: 0; z-index: 5; }
  .dq-hint { display: none; }
}
.compass .w-t, .compass .w-l, .compass .w-r { transform: none; }
.compass .w-t { left: 50%; translate: -50% 0; }
.compass .w-l, .compass .w-r { top: 50%; translate: 0 -50%; }
.mid { min-height: 0; overflow: hidden; }
.side { min-height: 0; overflow: hidden; }
.center { overflow: hidden; }
.side .phead { flex-direction: column; align-items: flex-start; gap: 2px; }
.side .pinfo b { max-width: 100%; font-size: 13px; }
.side .status { font-size: 13px; white-space: nowrap; letter-spacing: 0; }
@media (orientation: landscape) and (max-height: 560px) {
  .side .phead { flex-direction: row; align-items: center; gap: 6px; }
  .me .pname { margin-bottom: -6px; }
}
