:root {
  --bg: #eef3f8;
  --card: #ffffff;
  --ink: #22303f;
  --sub: #6b7a8c;
  --blue: #1e88e5;
  --cyan: #00b8d4;
  --pipe: #90a4ae;
  --pipe-dark: #607d8b;
  --win: #2e7d32;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(30, 60, 100, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #dfe9f5 0%, #eef3f8 40%, #e3f2f9 100%);
  min-height: 100vh;
  color: var(--ink);
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ============ 大厅 ============ */
#lobby { display: flex; align-items: center; justify-content: center; padding: 24px; }

.lobby-card {
  width: 430px; max-width: 94vw;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 36px 34px;
  text-align: center;
}

.logo { font-size: 32px; letter-spacing: 1px; }
.slogan { color: var(--sub); margin: 8px 0 24px; font-size: 14px; }

.field { margin-bottom: 18px; text-align: left; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 8px; font-weight: 600; }

input[type=text] {
  width: 100%; padding: 11px 14px;
  border: 2px solid #dfe7ef; border-radius: 10px;
  font-size: 15px; outline: none; transition: border .15s;
}
input[type=text]:focus { border-color: var(--blue); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; border: 2px solid #dfe7ef; background: #f6f9fc;
  border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--sub);
}
.tab.active { border-color: var(--blue); color: var(--blue); background: #e8f2fd; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 10px 6px; border: 2px solid #dfe7ef; background: #f6f9fc;
  border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--sub);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.seg button small { font-size: 11px; font-weight: 400; }
.seg button.active { border-color: var(--blue); color: var(--blue); background: #e8f2fd; }

.btn {
  border: none; border-radius: 12px; cursor: pointer;
  padding: 12px 22px; font-size: 15px; font-weight: 600;
  background: #eceff3; color: var(--ink); transition: transform .1s, box-shadow .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, #1e88e5, #00acc1); color: #fff; box-shadow: 0 6px 16px rgba(30,136,229,.35); }
.btn.ghost { background: transparent; border: 2px solid #dfe7ef; color: var(--sub); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }

.divider { color: var(--sub); font-size: 12px; margin: 18px 0 12px; }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-align: center; letter-spacing: 6px; font-weight: 700; text-transform: uppercase; }
.join-row .btn { flex: none; }

.msg { margin-top: 14px; padding: 10px; border-radius: 10px; font-size: 13px; background: #fdecea; color: #c62828; }
.msg.info { background: #e8f2fd; color: var(--blue); }

#btnResume { margin-top: 16px; width: 100%; }

/* ============ 游戏页 ============ */
#game { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--card); padding: 12px 22px; box-shadow: 0 2px 12px rgba(30,60,100,.08);
}
.brand { font-weight: 800; font-size: 18px; }
.room-info { display: flex; gap: 8px; align-items: center; }
.tag { background: #f1f5f9; border-radius: 20px; padding: 5px 14px; font-size: 13px; color: var(--sub); }
.tag.code { font-weight: 800; letter-spacing: 3px; color: var(--blue); cursor: pointer; background: #e8f2fd; }
.stats { display: flex; gap: 18px; font-size: 14px; color: var(--sub); }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

.game-main {
  flex: 1; display: flex; gap: 22px; padding: 22px;
  align-items: flex-start; justify-content: center; flex-wrap: wrap;
}

/* 棋盘 */
.board-wrap { position: relative; }
.board {
  display: grid; gap: 0;
  background: #f8fafc; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px;
  width: max-content; max-width: 100%;
}
.cell { position: relative; width: 64px; height: 64px; cursor: pointer; }
.cell.fixed { cursor: default; }
.cell svg { position: absolute; inset: 0; transition: transform .18s ease; }
.cell .icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; pointer-events: none; z-index: 2; text-shadow: 0 1px 2px #fff;
}

/* 迷你棋盘 (AI) */
.board.mini .cell { width: 30px; height: 30px; cursor: default; }
.board.mini .cell .icon { font-size: 12px; }

/* 水流样式 */
.cell .pipe { stroke: var(--pipe); }
.cell.connected .pipe { stroke: var(--blue); filter: drop-shadow(0 0 3px rgba(30,136,229,.8)); }
.cell.connected.water-end .icon { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.18); } }

.flow-demo { color: var(--blue); font-weight: 700; }

/* 侧栏 */
.side { width: 280px; display: flex; flex-direction: column; gap: 16px; }
.side h3 { font-size: 15px; margin-bottom: 10px; }
.player-list { display: flex; flex-direction: column; gap: 10px; }

.pcard {
  background: var(--card); border-radius: 12px; padding: 10px 14px;
  box-shadow: 0 3px 10px rgba(30,60,100,.08);
}
.pcard.me { outline: 2px solid var(--blue); }
.pcard .prow { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.pcard .prow .badge { font-size: 11px; background: #f1f5f9; color: var(--sub); padding: 2px 8px; border-radius: 10px; }
.pcard.won { background: #e8f5e9; }
.pcard.won .prow { color: var(--win); }
.pbar { height: 8px; background: #eceff3; border-radius: 6px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #1e88e5, #00b8d4); border-radius: 6px; transition: width .4s; }
.pcard.won .pbar i { background: var(--win); }
.pmeta { font-size: 11px; color: var(--sub); margin-top: 4px; }

.tips { background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: 0 3px 10px rgba(30,60,100,.08); }
.tips h4 { font-size: 13px; margin-bottom: 6px; }
.tips p { font-size: 12px; color: var(--sub); line-height: 1.7; }

/* 胜利弹层 */
.overlay {
  position: absolute; inset: 0; border-radius: var(--radius);
  background: rgba(255,255,255,.72); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.overlay-card {
  background: var(--card); border-radius: 18px; padding: 30px 40px; text-align: center;
  box-shadow: var(--shadow); animation: pop .35s ease;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.winner-icon { font-size: 52px; margin-bottom: 8px; }
#winnerText { font-size: 22px; margin-bottom: 6px; }
#winnerDetail { color: var(--sub); font-size: 14px; margin-bottom: 18px; }
.overlay-card .btn { margin: 0 5px; }

@media (max-width: 900px) {
  .cell { width: 46px; height: 46px; }
  .side { width: 100%; }
}
