Files
rong cb28bbb49e feat: 围棋在线对战(Rust 服务端 + 零构建前端)
- 规则引擎:提子、禁自杀、全局同形(超级劫)、中国规则数子(白贴 7.5 目)、停一手终局
- 服务端:axum + tokio,房间/观战/包干计时/断线重连/语音中继,前端资源内嵌单文件
- 前端:Canvas 木纹棋盘(9/13/19 路、星位、四边坐标、翻转视角)、WebAudio 合成落子声、
  本机双人模式、终局数子面板
- 测试:16 组规则断言 + 5 组 e2e(提子/劫/数子/观战/语音/静态资源)
- 构建缓存遵循 dev-cache-layout:target/ 留项目内并忽略,前端零构建不产生包缓存
2026-10-23 10:12:55 +08:00

1165 lines
20 KiB
CSS

:root {
--bg: #0e1116;
--bg-2: #141a21;
--card: rgba(255, 255, 255, 0.055);
--card-2: rgba(255, 255, 255, 0.085);
--line: rgba(255, 255, 255, 0.1);
--line-soft: rgba(255, 255, 255, 0.06);
--text: #e9edf3;
--muted: #94a1b2;
--jade: #57c08c;
--jade-deep: #2f7f5a;
--gold: #e2b355;
--red: #d9554c;
--shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
--r-lg: 20px;
--r-md: 14px;
--r-sm: 10px;
}
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
[hidden] {
display: none !important;
}
html,
body {
margin: 0;
padding: 0;
min-height: 100%;
}
body {
background:
radial-gradient(1200px 620px at 8% -12%, rgba(47, 127, 90, 0.22), transparent 62%),
radial-gradient(900px 520px at 100% 0%, rgba(226, 179, 85, 0.1), transparent 55%),
linear-gradient(180deg, #10151b 0%, #0b0e12 100%);
background-attachment: fixed;
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
'Microsoft YaHei', system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
min-height: 100dvh;
}
.app {
min-height: 100dvh;
display: flex;
flex-direction: column;
}
/* ------------------------------- 顶栏 ------------------------------- */
.topbar {
display: flex;
align-items: center;
gap: 16px;
padding: 16px 22px 12px;
max-width: 1200px;
width: 100%;
margin: 0 auto;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.seal {
display: grid;
place-items: center;
width: 40px;
height: 40px;
border-radius: 11px;
background: linear-gradient(155deg, #3d9c72, #22614a);
color: #eafaf1;
font-family: 'Songti SC', 'STSong', serif;
font-size: 23px;
font-weight: 700;
box-shadow: 0 6px 18px rgba(47, 127, 90, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.22);
flex: none;
}
.seal.big {
width: 58px;
height: 58px;
font-size: 33px;
border-radius: 16px;
}
.brand-text h1 {
font-size: 17px;
margin: 0;
letter-spacing: 0.5px;
font-weight: 650;
}
.brand-text p {
margin: 2px 0 0;
font-size: 11.5px;
color: var(--muted);
letter-spacing: 0.4px;
}
.roomline {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
}
.tag {
font-size: 12.5px;
letter-spacing: 1.5px;
padding: 7px 12px;
border-radius: 999px;
background: rgba(226, 179, 85, 0.12);
border: 1px solid rgba(226, 179, 85, 0.28);
color: #f0cf8d;
font-variant-numeric: tabular-nums;
}
.status {
display: flex;
align-items: center;
gap: 7px;
font-size: 12px;
color: var(--muted);
margin-left: auto;
flex: none;
}
.roomline:not([hidden]) ~ .status {
margin-left: 14px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #5b6472;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.03);
transition: background 0.25s;
}
.dot.open {
background: var(--jade);
box-shadow: 0 0 10px rgba(87, 192, 140, 0.7);
}
.dot.connecting {
background: var(--gold);
animation: blink 1s infinite;
}
.dot.closed {
background: var(--red);
}
@keyframes blink {
50% {
opacity: 0.35;
}
}
/* ------------------------------- 主区域 ------------------------------- */
.stage {
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 300px;
gap: 18px;
align-items: start;
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 0 22px 24px;
}
.board-wrap {
position: relative;
padding: 12px;
border-radius: var(--r-lg);
background: linear-gradient(165deg, #1c232b, #141920);
border: 1px solid var(--line);
box-shadow: var(--shadow);
width: min(100%, calc(100dvh - 168px));
justify-self: center;
}
.canvas-holder {
position: relative;
width: 100%;
aspect-ratio: 1 / 1;
border-radius: 12px;
overflow: hidden;
}
canvas#board {
display: block;
width: 100%;
height: 100%;
border-radius: 12px;
touch-action: none;
cursor: pointer;
}
/* ------------------------------- 面板 ------------------------------- */
.panel {
display: flex;
flex-direction: column;
gap: 10px;
padding-top: 12px;
}
.players {
display: flex;
flex-direction: column;
gap: 8px;
}
.pcard {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: var(--r-md);
background: var(--card);
border: 1px solid var(--line-soft);
transition: border-color 0.2s, background 0.2s, transform 0.2s;
}
.pcard .pdot {
width: 14px;
height: 14px;
border-radius: 50%;
flex: none;
}
.pcard.black .pdot {
background: radial-gradient(circle at 34% 32%, #6b6b6b, #0b0b0d 72%);
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}
.pcard.white .pdot {
background: radial-gradient(circle at 34% 32%, #ffffff, #cfc6b4 78%);
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}
.pinfo {
min-width: 0;
}
.pname {
font-size: 13.5px;
font-weight: 600;
}
.pstate {
font-size: 11.5px;
color: var(--muted);
margin-top: 2px;
}
.pcap {
margin-left: auto;
font-size: 11.5px;
color: #8b97a7;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.pcard.active {
border-color: rgba(226, 179, 85, 0.5);
background: linear-gradient(100deg, rgba(226, 179, 85, 0.14), rgba(226, 179, 85, 0.03));
}
.pcard.active .pstate {
color: #f0cf8d;
}
.pcard.offline {
opacity: 0.55;
}
.ptime {
font-family: 'SF Mono', ui-monospace, Menlo, monospace;
font-size: 15px;
font-variant-numeric: tabular-nums;
color: #cfd8e4;
letter-spacing: 0.5px;
padding-left: 6px;
min-width: 52px;
text-align: right;
}
.ptime.low {
color: #ff8d84;
animation: tickpulse 1s ease-in-out infinite;
}
@keyframes tickpulse {
50% {
opacity: 0.55;
}
}
.turnbar {
padding: 10px 12px;
border-radius: var(--r-sm);
font-size: 13px;
font-weight: 600;
text-align: center;
background: var(--card);
border: 1px solid var(--line-soft);
color: var(--muted);
transition: all 0.2s;
}
.turnbar.mine {
color: #d7f5e5;
background: linear-gradient(100deg, rgba(87, 192, 140, 0.24), rgba(87, 192, 140, 0.07));
border-color: rgba(87, 192, 140, 0.45);
}
.turnbar.done {
color: #f0cf8d;
background: rgba(226, 179, 85, 0.12);
border-color: rgba(226, 179, 85, 0.3);
}
.moves {
flex: 1;
min-height: 150px;
max-height: min(40dvh, 320px);
overflow-y: auto;
border-radius: var(--r-md);
background: rgba(0, 0, 0, 0.22);
border: 1px solid var(--line-soft);
padding: 6px;
font-size: 13px;
scrollbar-width: thin;
}
.moves::-webkit-scrollbar {
width: 6px;
}
.moves::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.14);
border-radius: 99px;
}
.moves .empty {
color: var(--muted);
font-size: 12px;
text-align: center;
padding: 22px 0;
}
.mvrow {
display: grid;
grid-template-columns: 30px 1fr 1fr;
align-items: center;
padding: 4px 6px;
border-radius: 7px;
font-variant-numeric: tabular-nums;
}
.mvrow:nth-child(odd) {
background: rgba(255, 255, 255, 0.028);
}
.mvrow .no {
color: #5f6b7a;
font-size: 11.5px;
}
.mvb,
.mvw {
font-size: 12.5px;
letter-spacing: 0.4px;
color: #c9d2de;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.mvb.hl {
color: #e9edf3;
font-weight: 600;
}
.mvw.hl {
color: #f3e7c9;
font-weight: 600;
}
.mvb em,
.mvw em {
font-style: normal;
font-size: 10.5px;
color: #d98a5a;
margin-left: 3px;
}
.actions {
display: flex;
gap: 8px;
}
.actions .btn {
flex: 1;
padding-left: 6px;
padding-right: 6px;
}
/* ------------------------------- 按钮 ------------------------------- */
.btn {
appearance: none;
border: 1px solid var(--line);
background: var(--card);
color: var(--text);
font-family: inherit;
font-size: 13.5px;
font-weight: 600;
padding: 10px 16px;
border-radius: var(--r-sm);
cursor: pointer;
transition: transform 0.12s, background 0.18s, border-color 0.18s, opacity 0.18s;
letter-spacing: 0.3px;
}
.btn:hover {
background: var(--card-2);
}
.btn:active {
transform: scale(0.975);
}
.btn:disabled {
opacity: 0.45;
cursor: default;
}
.btn.primary {
background: linear-gradient(160deg, #3fa87a, #256b4f);
border-color: rgba(255, 255, 255, 0.14);
color: #f0fdf6;
box-shadow: 0 8px 22px rgba(37, 107, 79, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn.primary:hover {
background: linear-gradient(160deg, #47b886, #2a7a59);
}
.btn.ghost {
background: transparent;
border-color: var(--line);
color: #cfd8e4;
}
.btn.ghost:hover {
background: rgba(255, 255, 255, 0.05);
}
.btn.text {
background: none;
border: none;
color: var(--muted);
font-weight: 500;
text-decoration: underline;
text-decoration-color: rgba(255, 255, 255, 0.2);
text-underline-offset: 4px;
}
.btn.text:hover {
color: #cfd8e4;
}
.btn.sm {
padding: 7px 12px;
font-size: 12px;
}
.btn.block {
width: 100%;
display: block;
}
/* ------------------------------- 遮罩 ------------------------------- */
.overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 18px;
border-radius: var(--r-lg);
background: rgba(8, 10, 13, 0.62);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
z-index: 5;
animation: fade 0.22s ease;
}
@keyframes fade {
from {
opacity: 0;
}
}
.overlay-card {
width: 100%;
max-width: 330px;
padding: 24px 22px;
border-radius: 18px;
background: linear-gradient(170deg, #1b2229, #12161c);
border: 1px solid var(--line);
box-shadow: 0 26px 60px rgba(0, 0, 0, 0.55);
text-align: center;
}
.kicker {
margin: 0 0 10px;
font-size: 11.5px;
letter-spacing: 2px;
color: var(--muted);
text-transform: uppercase;
}
.code-big {
font-family: 'SF Mono', ui-monospace, Menlo, monospace;
font-size: 34px;
letter-spacing: 10px;
margin: 4px 0 14px 0;
padding-left: 10px;
color: #f2d391;
text-shadow: 0 0 26px rgba(226, 179, 85, 0.35);
}
.hint {
margin: 0 0 18px;
font-size: 12.5px;
line-height: 1.75;
color: var(--muted);
}
.overlay-card h2 {
margin: 0 0 8px;
font-size: 25px;
letter-spacing: 1px;
}
.overlay-card h2.win-b {
color: #dfe7f2;
}
.overlay-card h2.win-w {
color: #f6ecd8;
}
.overlay-card h2.win-draw {
color: #f0cf8d;
}
.scoreline {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: baseline;
gap: 6px;
margin: 0 0 16px;
padding: 10px 12px;
border-radius: var(--r-sm);
background: rgba(226, 179, 85, 0.08);
border: 1px solid rgba(226, 179, 85, 0.2);
}
.scoreline .sc {
font-variant-numeric: tabular-nums;
font-size: 15px;
font-weight: 600;
}
.scoreline .sc.black {
color: #e6ebf2;
}
.scoreline .sc.white {
color: #f3e7c9;
}
.scoreline .sc.vs {
color: #6d7887;
}
.scoreline .sc.note {
flex-basis: 100%;
font-size: 11.5px;
font-weight: 500;
color: #a6b1c0;
margin-top: 2px;
}
.ov-actions {
display: flex;
flex-direction: column;
gap: 8px;
}
.waiting {
display: flex;
justify-content: center;
gap: 6px;
margin-top: 16px;
}
.waiting span {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gold);
opacity: 0.35;
animation: bounce 1.3s infinite;
}
.waiting span:nth-child(2) {
animation-delay: 0.18s;
}
.waiting span:nth-child(3) {
animation-delay: 0.36s;
}
@keyframes bounce {
0%,
60%,
100% {
transform: translateY(0);
opacity: 0.3;
}
30% {
transform: translateY(-6px);
opacity: 1;
}
}
/* ------------------------------- 大厅 ------------------------------- */
.lobby {
position: fixed;
inset: 0;
z-index: 30;
display: flex;
align-items: center;
justify-content: center;
padding: 22px;
overflow-y: auto;
background: rgba(7, 9, 12, 0.72);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
animation: fade 0.25s ease;
}
.lobby-card {
width: 100%;
max-width: 440px;
padding: 30px 28px 24px;
border-radius: 24px;
background: linear-gradient(170deg, #1a2128, #111519);
border: 1px solid var(--line);
box-shadow: 0 34px 80px rgba(0, 0, 0, 0.6);
margin: auto;
}
.lobby-head {
text-align: center;
margin-bottom: 18px;
}
.lobby-head .seal {
margin: 0 auto 14px;
}
.lobby-head h2 {
margin: 0 0 8px;
font-size: 21px;
letter-spacing: 0.5px;
}
.lobby-head p {
margin: 0;
font-size: 12.5px;
color: var(--muted);
line-height: 1.7;
}
.or {
display: flex;
align-items: center;
gap: 12px;
margin: 18px 0 14px;
color: #6d7887;
font-size: 11.5px;
}
.or::before,
.or::after {
content: '';
flex: 1;
height: 1px;
background: var(--line-soft);
}
.join-row {
display: flex;
gap: 8px;
}
.code-input {
flex: 1;
min-width: 0;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--line);
border-radius: var(--r-sm);
color: #f2d391;
font-family: 'SF Mono', ui-monospace, Menlo, monospace;
font-size: 19px;
letter-spacing: 8px;
text-align: center;
text-transform: uppercase;
padding: 10px 8px 10px 16px;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.code-input::placeholder {
color: #4d5766;
letter-spacing: 2px;
font-size: 14px;
}
.code-input:focus {
border-color: rgba(226, 179, 85, 0.55);
box-shadow: 0 0 0 3px rgba(226, 179, 85, 0.12);
}
.tips {
margin: 20px 0 0;
padding: 16px 18px 16px 30px;
border-radius: var(--r-md);
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--line-soft);
color: #8b97a7;
font-size: 12px;
line-height: 1.8;
}
.tips li + li {
margin-top: 4px;
}
/* ------------------------------- Toast ------------------------------- */
.toast {
position: fixed;
left: 50%;
bottom: 26px;
transform: translate(-50%, 14px);
padding: 11px 20px;
border-radius: 999px;
background: rgba(24, 30, 38, 0.96);
border: 1px solid var(--line);
color: #e6ecf4;
font-size: 13px;
box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
opacity: 0;
pointer-events: none;
transition: opacity 0.22s, transform 0.22s;
z-index: 60;
max-width: min(86vw, 420px);
text-align: center;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
/* ------------------------------- 计时 / 观战 ------------------------------- */
.badge {
font-size: 11.5px;
padding: 5px 10px;
border-radius: 999px;
background: rgba(87, 192, 140, 0.14);
border: 1px solid rgba(87, 192, 140, 0.35);
color: #8fe0b8;
letter-spacing: 0.5px;
white-space: nowrap;
}
.notice {
padding: 8px 11px;
border-radius: var(--r-sm);
font-size: 12px;
line-height: 1.6;
color: #f3d79a;
background: rgba(226, 179, 85, 0.1);
border: 1px solid rgba(226, 179, 85, 0.28);
}
.tc {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.tc-label {
font-size: 12px;
color: var(--muted);
flex: none;
width: 56px;
}
.chips {
display: flex;
gap: 6px;
flex: 1;
}
.chip {
flex: 1;
appearance: none;
font-family: inherit;
font-size: 12px;
padding: 7px 4px;
border-radius: 9px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.03);
color: #b6c0cd;
cursor: pointer;
transition: all 0.16s;
white-space: nowrap;
}
.chip:hover {
background: rgba(255, 255, 255, 0.07);
}
.chip.on {
background: rgba(87, 192, 140, 0.16);
border-color: rgba(87, 192, 140, 0.5);
color: #a9e8c6;
font-weight: 600;
}
.join-row .btn {
flex: none;
padding-left: 12px;
padding-right: 12px;
}
.tiny {
margin: 10px 2px 0;
font-size: 11.5px;
color: #6d7887;
line-height: 1.6;
}
/* ------------------------------- 语音互动 ------------------------------- */
.voice {
display: flex;
flex-direction: column;
gap: 8px;
}
.voice-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
padding: 0 2px;
}
.voice-title {
font-size: 12px;
letter-spacing: 0.6px;
color: #aab6c6;
}
.voice-hint {
font-size: 11px;
color: #6d7887;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.ptt {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
width: 100%;
padding: 12px 14px;
border-radius: 12px;
border: 1px solid rgba(87, 192, 140, 0.38);
background: linear-gradient(180deg, rgba(87, 192, 140, 0.18), rgba(87, 192, 140, 0.06));
color: #a9e8c6;
font: inherit;
font-size: 13.5px;
font-weight: 600;
letter-spacing: 0.5px;
cursor: pointer;
user-select: none;
-webkit-user-select: none;
touch-action: none;
transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.1s;
}
.ptt:hover {
background: linear-gradient(180deg, rgba(87, 192, 140, 0.26), rgba(87, 192, 140, 0.1));
}
.ptt:active {
transform: scale(0.99);
}
.ptt:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.ptt .ptt-ico {
width: 9px;
height: 9px;
border-radius: 50%;
background: #57c08c;
box-shadow: 0 0 0 3px rgba(87, 192, 140, 0.16);
flex: none;
}
.ptt.rec {
border-color: rgba(217, 85, 76, 0.7);
background: linear-gradient(180deg, rgba(217, 85, 76, 0.36), rgba(217, 85, 76, 0.12));
color: #ffd9d4;
}
.ptt.rec .ptt-ico {
background: #ff6f63;
animation: recpulse 1s ease-in-out infinite;
}
@keyframes recpulse {
50% {
box-shadow: 0 0 0 9px rgba(255, 111, 99, 0.1);
}
}
.voice-list {
max-height: 126px;
overflow-y: auto;
border-radius: 12px;
background: rgba(0, 0, 0, 0.22);
border: 1px solid var(--line-soft);
padding: 5px;
display: flex;
flex-direction: column;
gap: 4px;
scrollbar-width: thin;
}
.voice-list::-webkit-scrollbar {
width: 6px;
}
.voice-list::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.14);
border-radius: 99px;
}
.voice-list .empty {
color: var(--muted);
font-size: 12px;
text-align: center;
padding: 14px 0;
}
.vitem {
display: grid;
grid-template-columns: 20px 1fr auto auto;
align-items: center;
gap: 8px;
width: 100%;
padding: 7px 9px;
border-radius: 8px;
border: 1px solid transparent;
background: rgba(255, 255, 255, 0.03);
color: #c9d2de;
font: inherit;
font-size: 12.5px;
text-align: left;
cursor: pointer;
transition: background 0.14s, border-color 0.14s, color 0.14s;
}
.vitem:hover {
background: rgba(255, 255, 255, 0.075);
}
.vitem.mine {
background: rgba(87, 192, 140, 0.08);
border-color: rgba(87, 192, 140, 0.18);
}
.vitem.playing {
border-color: rgba(226, 179, 85, 0.55);
color: #f3d79a;
}
.vitem .vico {
font-size: 10.5px;
line-height: 1;
text-align: center;
color: #8fe0b8;
}
.vitem.playing .vico {
color: #f0cf8d;
}
.vitem .vwho {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.vitem .vdur {
font-variant-numeric: tabular-nums;
font-size: 11.5px;
color: #9aa7b7;
}
.vitem .vtime {
font-variant-numeric: tabular-nums;
font-size: 11px;
color: #5f6b7a;
}
/* ------------------------------- 响应式 ------------------------------- */
@media (max-width: 980px) {
.stage {
grid-template-columns: minmax(0, 1fr);
padding: 0 14px 18px;
gap: 12px;
}
.board-wrap {
width: min(100%, calc(100dvh - 210px));
padding: 9px;
border-radius: 16px;
}
.panel {
padding-top: 0;
}
.moves {
min-height: 96px;
max-height: 24dvh;
}
.topbar {
padding: 12px 14px 8px;
gap: 10px;
}
.brand-text p {
display: none;
}
.roomline {
gap: 6px;
}
.tag {
letter-spacing: 1px;
font-size: 11.5px;
padding: 6px 10px;
}
}
@media (max-width: 560px) {
.brand-text h1 {
font-size: 15px;
}
.seal {
width: 34px;
height: 34px;
font-size: 20px;
}
.board-wrap {
width: 100%;
}
.status span:last-child {
display: none;
}
.lobby-card {
padding: 24px 20px 18px;
}
.code-big {
font-size: 28px;
letter-spacing: 8px;
}
.tc {
flex-direction: column;
align-items: stretch;
gap: 8px;
}
.tc-label {
width: auto;
text-align: center;
}
.ptime {
font-size: 13.5px;
min-width: 44px;
}
.voice-list {
max-height: 112px;
}
}
@media (min-width: 981px) and (max-height: 760px) {
.moves {
max-height: 190px;
}
.voice-list {
max-height: 90px;
}
}