* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: #f3f5f8;
  color: #222;
  min-height: 100dvh;
}

/* ===== 悬浮记牌器面板（可拖动 / 可最小化）===== */
.float {
  position: fixed;
  left: 3vw; right: 3vw;
  bottom: 10px;
  z-index: 40;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
  display: flex; flex-direction: column;
  max-height: 84vh;
  overflow: hidden;
}
.float.hidden { display: none; }
.float-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: linear-gradient(135deg, #2E75B6, #1F4E79);
  color: #fff;
  cursor: grab;
  touch-action: none;          /* 拖动时禁止页面滚动 */
  user-select: none;
}
.float-bar:active { cursor: grabbing; }
.float-title { font-weight: 700; font-size: clamp(13px, 3.6vw, 15px); }
.float-min-btn {
  border: none; background: rgba(255,255,255,.25); color: #fff;
  width: 30px; height: 30px; border-radius: 8px; font-size: 16px; line-height: 1;
  cursor: pointer; flex: 0 0 auto;
}
.float-min-btn:active { background: rgba(255,255,255,.45); }
.float-body { display: flex; flex-direction: column; min-height: 0; }

/* 最小化后的小圆点 */
.float-min {
  display: none;
  position: fixed; right: 16px; bottom: 16px; z-index: 41;
  width: 56px; height: 56px; border-radius: 50%;
  border: none; background: linear-gradient(135deg, #2E75B6, #1F4E79); color: #fff;
  font-size: 26px; box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer;
}
.float-min.show { display: flex; align-items: center; justify-content: center; }
.float-min:active { transform: scale(.92); }

.plays { display: flex; gap: 6px; padding: 8px 10px 4px; justify-content: center; }
.play-btn {
  flex: 1; max-width: 120px;
  padding: 6px 0; border: none; border-radius: 16px;
  background: rgba(46,117,182,.12); color: #1F4E79;
  font-size: clamp(12px, 3.4vw, 14px); font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.play-btn.active { background: #2E75B6; color: #fff; }

.voicebar {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 4px 10px 8px; flex-wrap: wrap;
}
#mic {
  padding: 6px 16px; border: none; border-radius: 16px;
  background: #2E75B6; color: #fff;
  font-size: clamp(12px, 3.4vw, 14px); font-weight: 600; cursor: pointer;
  transition: background .15s;
}
#mic.on { background: #ff5252; }
#mic.disabled { opacity: .55; }
#manual {
  padding: 6px 14px; border: none; border-radius: 16px;
  background: #e8eef6; color: #1F4E79;
  font-size: clamp(12px, 3.4vw, 14px); font-weight: 600; cursor: pointer;
}
#manual:active { background: #d8e2ef; }
#voiceStatus {
  font-size: clamp(11px, 3vw, 13px); color: #1F4E79;
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  flex-basis: 100%; min-height: 16px;
}

/* main 内部可上下滚动（牌多时拖动查看） */
main {
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
  grid-auto-rows: minmax(52px, auto);
  gap: 5px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.card {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: 100px;
  margin: 0 auto;
  border: 2px solid #cfd8e3;
  border-radius: 8px;
  background: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  transition: transform .08s, background .15s;
}
.card:active { transform: scale(.94); }
.card .rank { font-size: clamp(16px, 5vw, 22px); font-weight: 700; color: #1F4E79; line-height: 1; }
.card .left { font-size: clamp(10px, 2.8vw, 13px); color: #888; margin-top: 3px; }
.card.empty { background: #eceff3; border-color: #e0e0e0; }
.card.empty .rank { color: #c0c0c0; }
.card.empty .left { color: #c0c0c0; }
.card.empty::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top left, transparent 47%, #d9534f 47%, #d9534f 53%, transparent 53%);
  opacity: .5; border-radius: 6px;
}

footer {
  background: #fff;
  border-top: 1px solid #e3e8ef;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  display: flex; align-items: center; gap: 10px;
  flex: 0 0 auto;
}
.info { flex: 1; font-size: clamp(12px, 3.4vw, 15px); }
.info b { color: #2E75B6; font-size: clamp(14px, 3.8vw, 17px); }
#reset {
  padding: 8px 18px; border: none; border-radius: 18px;
  background: #2E75B6; color: #fff; font-size: clamp(12px, 3.4vw, 15px); font-weight: 600; cursor: pointer;
}
#reset:active { background: #1F4E79; }

/* ===== 手动记牌底部面板（拖动滑块）===== */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50;
}
.sheet-mask.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: #fff; border-radius: 16px 16px 0 0;
  max-height: 82dvh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .25s;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.show { transform: translateY(0); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #e3e8ef;
}
.sheet-head h2 { margin: 0; font-size: 16px; color: #1F4E79; }
.sheet-close {
  border: none; background: #eee; border-radius: 12px;
  padding: 6px 14px; font-size: 14px; cursor: pointer;
}
.sheet-body { overflow-y: auto; padding: 6px 16px 16px; }
.manual-row {
  display: grid; grid-template-columns: 44px 1fr 56px; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #f0f3f7;
}
.manual-row .mrank { font-weight: 700; color: #1F4E79; font-size: 17px; }
.manual-row input[type=range] { width: 100%; accent-color: #2E75B6; height: 28px; }
.manual-row .mval { text-align: right; font-size: 13px; color: #666; }
.manual-row.empty .mrank { color: #c0c0c0; }

/* ===== 核销码门禁（全屏遮罩，未验证打不开记牌器）===== */
.gate {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: #0f1a2b; padding: 20px;
}
.gate-box {
  width: 100%; max-width: 340px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px; padding: 30px 22px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
.gate-title { font-size: 1.3rem; font-weight: 700; color: #fff; margin-bottom: 6px; }
.gate-sub { font-size: .85rem; color: #9fb3c8; margin-bottom: 22px; }
.gate-input {
  width: 100%; padding: 14px; margin-bottom: 14px;
  border-radius: 10px; border: 2px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); color: #fff;
  font-size: 1.1rem; text-align: center; letter-spacing: .18em;
  font-family: inherit; outline: none; box-sizing: border-box;
}
.gate-input:focus { border-color: #2E75B6; }
.gate-btn {
  width: 100%; padding: 14px; border-radius: 10px; border: none;
  background: #2E75B6; color: #fff; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.gate-btn:disabled { opacity: .6; }
.gate-err { color: #ff8a80; font-size: .8rem; margin-top: 12px; min-height: 1em; }
