:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --ink: #16202e;
  --ink2: #3d4a5c;
  --muted: #6b7a90;
  --line: #e3e8ef;
  --line2: #eef1f6;
  --primary: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .05);
  --r: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.brand-title { font-size: clamp(19px, 2.2vw, 27px); font-weight: 800; letter-spacing: .01em; }
.brand-sub { color: var(--muted); font-size: 12px; letter-spacing: .1em; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--ink2); margin-bottom: 12px;
}
.card-title::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--primary); }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 15px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14.5px;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface2); border-color: #cfd8e3; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4fd7; border-color: #1d4fd7; }
.btn-cyan { background: #0f766e; border-color: #0f766e; color: #fff; }
.btn-cyan:hover:not(:disabled) { background: #0c655e; border-color: #0c655e; }
.btn-lime { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-lime:hover:not(:disabled) { background: #116b33; border-color: #116b33; }
.btn-pink { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger { background: #fdecec; border-color: #f6cccc; color: #b42318; }
.btn-danger:hover:not(:disabled) { background: #fbdede; border-color: #f2bcbc; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn-xl { padding: 15px 24px; font-size: 17px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.input::placeholder { color: #9aa7b8; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--surface2); color: var(--ink2);
}
.chip.ok { color: var(--ok); border-color: #bfe6cc; background: #eef9f1; }
.chip.warn { color: #b42318; border-color: #f3c9c9; background: #fdeeee; }
.chip.gold { color: var(--warn); border-color: #f0d9ae; background: #fdf5e6; }
.chip.cyan { color: #0f766e; border-color: #b6dedb; background: #ecf7f6; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex: none; }
.dot.on { background: #22c55e; }
.dot.off { background: #cbd5e1; }

.sw { position: relative; width: 42px; height: 23px; border-radius: 999px; background: #d7dee8; border: 1px solid transparent; cursor: pointer; transition: background .18s; flex: none; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .2); transition: transform .18s cubic-bezier(.3, 1.3, .5, 1); }
.sw[data-on="1"] { background: #22c55e; }
.sw[data-on="1"]::after { transform: translateX(19px); }
.sw[data-on="0"] { background: #f3b3ad; }

/* ---------- timer ---------- */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer.urgent { color: var(--danger); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 90; align-items: center; pointer-events: none; }
.toast-item {
  padding: 10px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-weight: 600; font-size: 14.5px; animation: rise .25s ease; max-width: 84vw; text-align: center;
}
.toast-item.ok { border-color: #bfe6cc; color: var(--ok); }
.toast-item.err { border-color: #f3c9c9; color: #b42318; }
.toast-item.info { color: var(--ink2); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(22, 32, 46, .35); display: flex; align-items: center; justify-content: center; z-index: 80; padding: 20px; }
.modal[hidden] { display: none; }
.modal-box { max-width: 420px; width: 100%; }

/* ---------- login ---------- */
.login-hero { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.sid-input { font-size: 21px !important; letter-spacing: .08em; text-align: center; font-variant-numeric: tabular-nums; }
.match-name { min-height: 20px; font-weight: 600; color: var(--ok); text-align: center; font-size: 13px; }
.match-name.none { color: var(--danger); }

/* ---------- leaderboard ---------- */
.lb-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; }
.lb-row + .lb-row { margin-top: 1px; }
.lb-rank { font-weight: 700; color: var(--muted); text-align: center; font-size: 13.5px; }
.lb-row.top1 .lb-rank { color: #b45309; }
.lb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.lb-score { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.lb-excluded { opacity: .5; }
.bar { height: 4px; border-radius: 3px; background: var(--line2); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 3px; transition: width .4s ease; }

/* ---------- options / band ---------- */
.q-title-lg { font-size: clamp(18px, 2vw, 24px); font-weight: 700; line-height: 1.4; }
.opt-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-list.dense { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
@media (max-width: 620px) { .opt-list { grid-template-columns: 1fr; } }
.opt {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 13px 15px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; font-weight: 600; text-align: left; width: 100%; color: var(--ink);
}
.opt .k { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface2); border: 1px solid var(--line); font-weight: 700; flex: none; color: var(--ink2); }
.opt.correct { border-color: #8fd3a8; background: #eef9f1; }
.opt.correct .k { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrongpick { border-color: #f0b4b4; background: #fdeeee; }
.opt.wrongpick .k { background: var(--danger); border-color: var(--danger); color: #fff; }
.opt.picked { box-shadow: 0 0 0 2px rgba(37, 99, 235, .35); }
.opt.compact { padding: 9px 10px; font-size: 15px; gap: 8px; border-radius: 10px; }
.opt.compact .k { width: 23px; height: 23px; border-radius: 6px; font-size: 12px; }
@media (max-width: 460px) { .opt.compact { padding: 8px 8px; font-size: 14px; gap: 6px; } }
.status-band { padding: 11px 15px; border-radius: 12px; font-weight: 600; text-align: center; border: 1px solid var(--line); background: var(--surface2); color: var(--ink2); }
.status-band.live { border-color: #f0d9ae; background: #fdf5e6; color: var(--warn); }
.status-band.win { border-color: #bfe6cc; background: #eef9f1; color: var(--ok); }
.status-band.stop { border-color: #f3c9c9; background: #fdeeee; color: #b42318; }

/* ---------- option editor (host) ---------- */
.opt-editor { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.oe-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 26px; gap: 6px; align-items: center; }
.oe-mark { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface2); color: var(--ink2); font-weight: 700; cursor: pointer; }
.oe-mark.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.oe-del { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; line-height: 1; }
.oe-del:hover { border-color: #f3c9c9; color: var(--danger); background: #fdeeee; }

/* ---------- canvas board ---------- */
.board-wrap { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: #fff; border: 1px solid #d5dce6; }
.board-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.board-wrap.view canvas { touch-action: pan-y; }
.board-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #a7b2c2; font-weight: 600; pointer-events: none; }

/* ---------- feed ---------- */
.feed { display: flex; flex-direction: column-reverse; gap: 6px; max-height: 240px; overflow-y: auto; padding-right: 4px; }
.feed-item { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; padding: 6px 9px; border-radius: 9px; background: var(--surface2); border: 1px solid var(--line2); }
.feed-item.hit { background: #eef9f1; border-color: #cbe9d5; }
.feed-item b { color: var(--muted); font-weight: 600; flex: none; }
.feed-item span { word-break: break-all; }
.feed-item.miss { color: var(--ink2); }

.flash { animation: flash .8s ease; }
@keyframes flash { 0%, 60% { background: #fdf5e6; } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d7dee8; border-radius: 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
