:root {
  --bg: #f7f4ee;
  --panel: #fffdf9;
  --line: #e8e1d4;
  --text: #2b2620;
  --soft: #7a7064;
  --gold: #b07d2a;
  --gold-strong: #94661c;
  --gold-soft: #f6ecd8;
  --pend-bg: #fff6d8;
  --pend-line: #e3b007;
  --ok: #2f7d4f;
  --bad: #b23b3b;
  --grey: #a39a8d;
  --video-bg: #14110d;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(60, 45, 20, .10);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.small { font-size: 12px; }
.muted { color: var(--soft); }
.center-text { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- full-page screens (gates, login, binding) ---------- */
.screen { min-height: 100%; padding: 24px 16px; }
.center { display: flex; align-items: center; justify-content: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; }
.card.narrow { width: 100%; max-width: 380px; }
.card h1 { font-size: 20px; margin: 0 0 6px; }
.big-icon { font-size: 40px; text-align: center; }
.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 13px; color: var(--soft); margin-bottom: 6px; }
.field input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.field input:focus, .send-row input:focus, select:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
.hint { color: var(--soft); margin: 8px 0 0; }
.error { color: var(--bad); font-size: 13px; margin: 10px 0 0; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--gold-strong); }
.btn.link { border: 0; background: none; color: var(--soft); padding: 6px 8px; }
.btn.block { display: block; width: 100%; margin-top: 16px; padding: 11px; }
.btn.danger { color: var(--bad); }
.steps { padding-left: 18px; color: var(--soft); line-height: 1.6; }
.qr-wrap { display: flex; justify-content: center; margin: 10px 0; }
.qr-wrap canvas { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; word-break: break-all; user-select: all; }

/* ---------- console ---------- */
.console { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { font-weight: 600; color: var(--gold-strong); }
.team { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-pick select { padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; max-width: 180px; }
.me { color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.toggle { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; display: inline-flex; align-items: center; gap: 6px; }
.toggle[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); color: var(--gold-strong); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 12px; min-width: 20px; padding: 0 6px; line-height: 18px; text-align: center; }
.badge.zero { background: var(--grey); }

.stage { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); min-height: 0; }
.video-box { position: relative; background: var(--video-bg); display: flex; align-items: center; justify-content: center; min-height: 0; }
.video-box video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-cover { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #d9cfbf; font-size: 15px; }
.live-tag { position: absolute; top: 12px; left: 12px; background: #d23c3c; color: #fff; border-radius: 4px; font-size: 12px; padding: 2px 8px; }
.video-btn { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); color: #fff;
  border: 1px solid rgba(255,255,255,.3); border-radius: 999px; padding: 6px 14px; }

.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); }
.chat-wrap { position: relative; flex: 1; min-height: 0; }
.chat { height: 100%; overflow-y: auto; padding: 10px 12px 16px; outline: none; overscroll-behavior: contain; }
.chat-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--soft); pointer-events: none; }
.new-pill, .older-pill { position: absolute; left: 50%; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 5px 14px;
  background: var(--gold); color: #fff; box-shadow: var(--shadow); font-size: 13px; }
.new-pill { bottom: 10px; }
.older-pill { top: 8px; background: #fff; color: var(--gold-strong); border: 1px solid var(--gold); }

.m { padding: 7px 8px; border-radius: 8px; margin: 2px 0; line-height: 1.5; font-size: 14px; word-break: break-word; border-left: 3px solid transparent; }
.m.pending { background: var(--pend-bg); border-left-color: var(--pend-line); }
.m.sel { box-shadow: inset 0 0 0 2px var(--gold); }
.m.done .tx, .m.done .nm { text-decoration: line-through; color: var(--grey); }
.m.done { color: var(--grey); }
.m.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #ffe9a8; } to { background: transparent; } }
.m.gift { color: var(--gold-strong); }
.nm { font-weight: 600; color: #6b5a3e; }
button.nm { border: 0; background: none; padding: 0; text-decoration: underline dotted; text-underline-offset: 3px; }
.tg { display: inline-block; font-size: 11px; line-height: 16px; padding: 0 5px; border-radius: 4px; margin-left: 4px; background: #efe9de; color: var(--soft); vertical-align: 1px; }
.tg.pend { background: var(--pend-line); color: #fff; }
.tg.robot { background: #e7eef8; color: #3a5a86; }
.tg.off { background: var(--gold); color: #fff; }
.tg.mute { background: #f6e1e1; color: var(--bad); }
.reply { color: var(--soft); }
.meta { display: block; font-size: 12px; color: var(--soft); margin-top: 1px; }
.acts { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.acts button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 2px 10px; font-size: 13px; }
.acts .ok { border-color: var(--ok); color: var(--ok); }
.acts .no { border-color: var(--bad); color: var(--bad); }

.composer { border-top: 1px solid var(--line); padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--panel); }
.qbar { background: var(--gold-soft); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.qbar .top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qbar .grow { flex: 1; }
.qbar button { border: 0; background: none; color: var(--gold-strong); padding: 2px 4px; }
.qbar ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 140px; overflow-y: auto; }
.qbar li { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-top: 1px dashed #e5d5b5; }
.qbar li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qbar .voided { color: var(--bad); }
.reply-bar { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--soft); }
.reply-bar b { color: var(--text); }
.reply-bar button { border: 0; background: none; color: var(--soft); }
.ids, .groups, .phrases { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.id { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px 3px 4px; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; }
.id i { font-style: normal; width: 22px; height: 22px; border-radius: 50%; background: #efe6d4; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.id.official i { background: var(--gold); color: #fff; }
.id[aria-pressed="true"] { border-color: var(--gold); background: var(--gold-soft); color: var(--gold-strong); }
.groups button { flex: none; border: 0; background: none; padding: 2px 8px; color: var(--soft); border-bottom: 2px solid transparent; }
.groups button[aria-pressed="true"] { color: var(--gold-strong); border-bottom-color: var(--gold); }
.ph { flex: none; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-width: 240px; }
.ph button { border: 0; background: none; padding: 5px 8px; font-size: 13px; }
.ph .say { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; text-align: left; }
.ph .edit { border-left: 1px solid var(--line); color: var(--soft); }
.ph.all { border-color: var(--gold); }
.ph.all button { color: var(--gold-strong); }
.ph .who { color: var(--soft); font-size: 11px; margin-left: 4px; }
.phrases .none { color: var(--soft); font-size: 13px; padding: 4px 0; }
.send-row { display: flex; align-items: center; gap: 6px; }
.send-row input { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.count { color: var(--soft); }

/* ---------- sheet & toast ---------- */
.sheet { position: fixed; inset: 0; background: rgba(30, 22, 10, .35); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.sheet-panel { background: var(--panel); border-radius: 14px; width: 100%; max-width: 380px; padding: 18px; box-shadow: var(--shadow); max-height: 85vh; overflow-y: auto; }
.sheet-panel h2 { font-size: 16px; margin: 0 0 8px; }
.sheet-panel .hist { background: #f4efe6; border-radius: 8px; padding: 8px 10px; font-size: 13px; color: var(--soft); margin: 8px 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.sheet-panel .row { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.sheet-panel .row .btn { width: 100%; padding: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(30, 24, 16, .92); color: #fff; padding: 9px 16px;
  border-radius: 8px; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); text-align: center; }

/* ---------- phones ---------- */
@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .video-box { height: min(56.25vw, 32vh); }
  .side { border-left: 0; }
  .me { display: none; }
  .topbar { padding: 6px 12px; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
