:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --txt: #e2e8f0;
  --dim: #94a3b8;
  --acc: #38bdf8;
  --warn: #f87171;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
}
h1 { font-size: 26px; text-align: center; margin-bottom: 4px; }
.sub { text-align: center; color: var(--dim); font-size: 13px; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--txt);
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--acc); }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  padding: 9px 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--txt);
  cursor: pointer;
  font-size: 13px;
}
.seg button.on { background: var(--acc); color: #04121f; border-color: var(--acc); font-weight: 600; }
button.primary {
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: var(--acc);
  color: #04121f;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
button.primary.join { width: auto; padding: 10px 18px; }
button.ghost {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.divider { text-align: center; color: var(--dim); margin: 14px 0; font-size: 12px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.hidden { display: none !important; }

/* ---- 房间 ---- */
#game { max-width: none; width: auto; }
header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.roominfo { font-size: 14px; color: var(--dim); }
.roominfo b { color: var(--txt); font-size: 16px; letter-spacing: 2px; }
#players { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.chip .sc { color: var(--acc); font-weight: 700; }
.chip.off { opacity: .45; }
.chip.turn { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
#turnHint { font-size: 13px; color: var(--dim); margin-left: auto; }
#turnHint b { color: var(--warn); }
.footer { margin-top: 12px; display: flex; justify-content: center; gap: 10px; }
button.primary.start { width: auto; padding: 10px 26px; }
button.primary:disabled { opacity: .45; cursor: not-allowed; }

#boardWrap { overflow: auto; max-width: 100%; }
#board {
  display: grid;
  gap: 0;
  width: max-content;
  margin: 0 auto;
  border: 1px solid var(--line);
  line-height: 0;
}
.cell {
  width: var(--cs, 30px);
  height: var(--cs, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cs, 30px) * .55);
  font-weight: 700;
  background: #cbd5e1;
  color: #0f172a;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border: 2px outset #eef2f7;
  line-height: 1;
}
.cell:hover { filter: brightness(1.06); }
.cell.open, .cell.boom, .cell.mine, .cell.wrong {
  background: #94a3b8;
  border: 1px solid #7c8ba1;
  cursor: default;
}
.cell.boom { background: #f87171; }
.cell.mine { background: #e2e8f0; }
.cell.wrong { background: #fca5a5; }
.cell.n1 { color: #1d4ed8; } .cell.n2 { color: #15803d; } .cell.n3 { color: #dc2626; }
.cell.n4 { color: #1e3a8a; } .cell.n5 { color: #7c2d12; } .cell.n6 { color: #0e7490; }
.cell.n7 { color: #111827; } .cell.n8 { color: #4b5563; }

/* ---- 弹层 ---- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 28px;
  width: min(380px, 92vw);
  text-align: center;
}
.modal h2 { margin-bottom: 6px; }
.modal p { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
#rankList { list-style: none; margin: 0 0 16px; }
#rankList li {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #0b1220;
}
#rankList li:first-child { background: #14532d; color: #fbbf24; font-weight: 700; }
#rankList .sc { color: var(--acc); font-weight: 700; }
.modal .primary { margin-bottom: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #0b1220;
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  z-index: 60;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
