:root {
  --ink: #1c2027;
  --line: #e3e6ea;
  --muted: #6b7280;
  --accent: #2f6fed;
  --danger: #c53030;
  --ok: #2f855a;
  --warn: #b7791f;
  --bg: #f6f7f9;
  /* 微信里 100vh 会把浏览器标题栏/工具栏算进去导致内容被截，优先用 dvh（动态视口高度）。
     但老版微信的 X5 内核不认 dvh：整条声明会被判无效、--h 变空、height 直接塌成一团。
     所以先用 100vh 兜底，再用 @supports 只在认识的浏览器上覆盖成 dvh。 */
  --h: 100vh;
}
@supports (height: 100dvh) {
  :root { --h: 100dvh; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: var(--h);
  overflow: hidden;
  overscroll-behavior: none;      /* 禁掉下拉刷新，微信里否则会误触 */
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.screen { height: var(--h); display: flex; flex-direction: column; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13.5px; margin: 4px 0; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

input, select, button { font-family: inherit; }
input, select {
  padding: 12px 14px;
  font-size: 16px;                /* 低于 16px 时 iOS 会自动放大页面 */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 12px 18px;
  font-size: 15px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button:disabled { background: #cbd2dc; cursor: default; transform: none; }
button.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.small { padding: 9px 14px; font-size: 14px; flex: none; }
button.wide { width: 100%; }

/* ------------------------------ 进房页 ------------------------------ */
.entry-inner {
  margin: auto;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow: auto;
}
.entry-inner h1 { font-size: 26px; margin: 0; }
.entry-inner label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }
#code { text-transform: uppercase; letter-spacing: 3px; font-family: ui-monospace, Consolas, monospace; }

.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-pick {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
}
.avatar-pick[aria-pressed="true"] { border-color: var(--accent); background: #eef4ff; }

.board-rank { border-top: 1px solid var(--line); padding-top: 12px; }
.board-rank summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }

.rank-list { list-style: none; margin: 8px 0 0; padding: 0; }
.rank-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.rank-list .pos { width: 22px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-list .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .pts { font-variant-numeric: tabular-nums; font-weight: 600; }
.rank-list .games { font-size: 12px; color: var(--muted); }

/* ------------------------------ 顶栏 ------------------------------ */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
  flex: none;
}
.bar b { color: var(--ink); letter-spacing: 2px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; color: var(--ink); }
.timer.low { color: var(--danger); }
.role { margin-left: auto; font-size: 12.5px; }
.role.drawer { color: var(--accent); font-weight: 600; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
#lobbyCount + .dot { margin-left: auto; }
.dot.bad { background: var(--danger); }
.dot.mid { background: var(--warn); }

/* ------------------------------ 大厅 ------------------------------ */
.lobby-body { flex: 1; overflow: auto; padding: 20px 18px; }
.lobby-body h2 { font-size: 17px; margin: 0 0 12px; }
.players { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.players li {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  font-size: 13px;
  position: relative;
}
.players .face { font-size: 28px; display: block; line-height: 1.25; }
.players .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players li.offline { opacity: .42; }
.players li.offline::after { content: "离线"; position: absolute; top: 6px; right: 7px; font-size: 10px; color: var(--danger); }
.players li .host { position: absolute; top: 6px; left: 7px; font-size: 10px; color: var(--accent); }

.settings { display: flex; gap: 12px; }
.settings label { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.bar-bottom {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}

/* ------------------------------ 对局 ------------------------------ */
.board {
  flex: 1;
  min-height: 120px;
  position: relative;
  margin: 10px 10px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  overflow: hidden;
}
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;             /* 决定性一行：不写它，手指滑动会连带滚动/缩放页面 */
  cursor: crosshair;
}
#board.locked { cursor: not-allowed; }

.feed {
  flex: none;
  height: 25vh;
  min-height: 96px;
  margin: 0 10px;
  padding: 8px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  font-size: 13.5px;
}
.feed li { padding: 3px 0; display: flex; gap: 7px; align-items: baseline; }
.feed .who { color: var(--muted); flex: none; max-width: 5.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .what { word-break: break-word; }
.feed li.correct .what { color: var(--ok); font-weight: 600; }
.feed li.system { color: var(--muted); font-size: 12.5px; }
.feed li.score { color: var(--accent); font-size: 12.5px; }

.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}
.swatches { display: flex; gap: 8px; flex: 1; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  flex: none;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); transform: scale(1.12); }
#width { width: 84px; flex: none; accent-color: var(--accent); padding: 0; }
#guess { flex: 1; }

/* ------------------------------ 弹层 ------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, .55);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 20;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  max-height: 86vh;
  overflow: auto;
}
.modal-card h2 { margin: 0 0 6px; font-size: 19px; }
.modal-card.center { text-align: center; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; }

.picker-words { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.picker-words button {
  padding: 15px;
  font-size: 17px;
  letter-spacing: 2px;
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.picker-words button:active { border-color: var(--accent); }

.reveal-answer { font-size: 30px; letter-spacing: 3px; margin: 4px 0 8px; }

/* ------------------------------ 轻提示 ------------------------------ */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: 80vw;
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(28, 32, 39, .9);
  color: #fff;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;           /* 别挡住下面的画笔落点 */
  transition: opacity .18s, transform .18s;
  z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 宽屏：电脑浏览器直接打开时 ----------
   手机上满屏才是对的，但同一套布局拉到 1440px 会变成一条被横向拉扁的巨型手机页：
   画布超宽、聊天流和工具条横穿整个屏幕。这里把整个应用收成一块居中的竖版面板。
   必须同时要求 pointer:fine —— 只靠宽度会把横屏手机（宽度普遍 >720px）误判成桌面，
   给它套上 600px 面板反而在两侧留下大片空白，那就违背了"适配当前窗口"。
   触屏一律满屏；鼠标操作的真桌面才收窄。 */
@media (min-width: 720px) and (pointer: fine) {
  body { background: #eef0f4; }

  .screen {
    max-width: 600px;
    margin-inline: auto;
    background: #fff;
    box-shadow: 0 0 0 1px var(--line), 0 18px 44px rgba(15, 17, 21, .09);
  }

  .modal { padding: 32px; }
  .modal-card { max-width: 460px; }
}
