*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(90deg, transparent 0 78px, color-mix(in srgb, var(--line) 22%, transparent) 78px 79px),
    linear-gradient(0deg, transparent 0 78px, color-mix(in srgb, var(--line) 18%, transparent) 78px 79px);
  opacity: 0.36;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; }
img, svg, canvas { max-width: 100%; }
h1, h2, h3, p, ul, ol { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
::selection { background: color-mix(in srgb, var(--accent) 36%, transparent); color: var(--text); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  transform: translateY(-160%);
  background: var(--accent);
  color: var(--text-on-accent);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-weight: 700;
}
.skip-link:focus { transform: none; }

.app-shell {
  position: relative;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 18px 32px 12px;
}

body[data-view="room"] .app-header,
body[data-view="table"] .app-header { display: none; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 13px;
  background: var(--seal);
  color: var(--seal-ink);
  border: 2px solid color-mix(in srgb, var(--gold) 58%, transparent);
  font-family: var(--font-display);
  font-size: 25px;
  line-height: 1;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--seal-ink) 16%, transparent);
  transform: rotate(-3deg);
}
.brand-mark-sm { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.04em; white-space: nowrap; }
.brand-text small { color: var(--text-3); font-size: 10px; letter-spacing: 0.12em; white-space: nowrap; }

.header-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.theme-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 9px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-3);
  font-size: var(--text-xs);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.theme-choice:hover { background: var(--surface-2); color: var(--text); }
.theme-choice[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 4px; flex: none; }
.swatch-jade { background: linear-gradient(135deg, var(--swatch-jade-a), var(--swatch-jade-b)); }
.swatch-neon { background: linear-gradient(135deg, var(--swatch-neon-a), var(--swatch-neon-b)); }
.swatch-campus { background: linear-gradient(135deg, var(--swatch-campus-a), var(--swatch-campus-b)); }

.icon-btn {
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  font-size: var(--text-sm);
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  transition: filter var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:not(:disabled):active { transform: translateY(1px); }
.btn:disabled { opacity: 0.46; }

.btn-primary { background: var(--accent); color: var(--text-on-accent); border-color: var(--accent); }
.btn-primary:not(:disabled):hover { filter: brightness(1.07); }

.btn-secondary { background: var(--surface-2); border-color: var(--line-strong); color: var(--text); }
.btn-secondary:not(:disabled):hover { background: var(--surface-3); }

.btn-quiet { color: var(--text-2); border-color: var(--line); background: transparent; }
.btn-quiet:not(:disabled):hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-badge); }
.btn-danger:not(:disabled):hover { filter: brightness(1.07); }

.btn-lg { min-height: 52px; padding: 12px 24px; font-size: 16px; }
.btn-sm { min-height: 36px; padding: 7px 13px; font-size: var(--text-xs); }
.btn-block { width: 100%; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-3);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}
.eyebrow-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

/* ---------- 大厅 ---------- */

.view-lobby {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 20px 32px 40px;
  flex: 1;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  gap: clamp(32px, 6vw, 84px);
  align-items: center;
  min-height: calc(100dvh - var(--header-h) - 110px);
  padding: 18px 0 26px;
}

.lobby-hero { min-width: 0; }

.lobby-hero h1 {
  margin: 0 0 20px;
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.035em;
}
.lobby-hero h1 em { color: var(--accent); font-style: normal; }

.hero-lead {
  max-width: 37ch;
  margin-bottom: 26px;
  color: var(--text-2);
  font-size: clamp(15px, 1.4vw, 17px);
  line-height: 1.75;
}

.hero-cards {
  position: relative;
  height: clamp(150px, 19vw, 196px);
  max-width: 380px;
  margin: 0 0 22px;
}
.hero-card {
  position: absolute;
  display: flex;
  width: clamp(92px, 11vw, 116px);
  height: clamp(132px, 15.5vw, 164px);
  padding: 10px 12px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--card);
  color: var(--card-ink);
  box-shadow: var(--shadow-md);
  font-family: var(--font-display);
  font-size: clamp(28px, 3.4vw, 38px);
  line-height: 1;
}
.hero-card .hero-suit { align-self: flex-end; font-size: 0.8em; }
.hero-card-a { left: 0; top: 18px; transform: rotate(-11deg); }
.hero-card-b { left: 84px; top: 0; transform: rotate(4deg); color: var(--card-red); }
.hero-card-c {
  left: 172px;
  top: 24px;
  transform: rotate(13deg);
  background: var(--card-back);
  color: var(--card-back-ink);
  border-color: var(--card-back-line);
  background-image:
    linear-gradient(45deg, transparent 46%, color-mix(in srgb, var(--card-back-line) 34%, transparent) 46%, color-mix(in srgb, var(--card-back-line) 34%, transparent) 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, color-mix(in srgb, var(--card-back-line) 34%, transparent) 46%, color-mix(in srgb, var(--card-back-line) 34%, transparent) 54%, transparent 54%);
  background-size: 14px 14px;
}
.hero-card-c .joker-word { writing-mode: vertical-rl; letter-spacing: 0.08em; font-size: 0.55em; }
.hero-card-c .hero-suit { font-size: 0.7em; }

.hero-points {
  display: grid;
  gap: 0;
  max-width: 440px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.hero-points li {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed var(--line);
  font-size: var(--text-sm);
  color: var(--text-2);
}
.hero-points li:last-child { border-bottom: 1px dashed var(--line); }
.hero-points strong { color: var(--accent); font-weight: 700; letter-spacing: 0.08em; }
.hero-foot { margin: 14px 0 0; color: var(--text-3); font-size: var(--text-xs); }

.lobby-panel { padding: clamp(22px, 3vw, 34px); }
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.panel-head h2 { margin: 0; font-family: var(--font-display); font-size: var(--text-2xl); line-height: 1.1; }
.panel-head .eyebrow { margin-bottom: 6px; }
.seat-chip {
  flex: none;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > span { color: var(--text-2); font-size: var(--text-xs); letter-spacing: 0.04em; }
.field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--input-line);
  border-radius: var(--radius-md);
  background: var(--input-bg);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.field input::placeholder { color: var(--text-3); }
.field input:hover { border-color: var(--line-strong); }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}

#lobby-form .btn-block { margin-top: 12px; }

.or-divider { display: flex; align-items: center; gap: 12px; margin: 24px 0 16px; color: var(--text-3); font-size: var(--text-xs); }
.or-divider::before, .or-divider::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.or-divider span { flex: none; }

.join-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.join-row .field input { font-family: var(--font-mono); font-size: 18px; letter-spacing: 0.18em; text-transform: uppercase; }
.btn-join { min-width: 88px; }
.field-hint { margin: 8px 0 0; color: var(--text-3); font-size: var(--text-xs); }

.resume-link {
  margin-top: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}
.resume-link strong { font-family: var(--font-mono); letter-spacing: 0.1em; }

.lobby-stats { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); color: var(--text-2); font-size: var(--text-sm); }
.lobby-stats .stats-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lobby-stats .stats-line + .stats-line { margin-top: 6px; }
.lobby-stats strong { color: var(--text); font-family: var(--font-mono); }
.lobby-note { margin: 14px 0 0; color: var(--text-3); font-size: var(--text-xs); line-height: 1.6; }

.lobby-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--content-max);
  margin: 8px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: var(--text-xs);
}

/* ---------- 等待房 ---------- */

.view-room {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 32px 32px;
  flex: 1;
}

.room-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.room-head h1 { display: flex; align-items: center; gap: 12px; margin: 0; font-family: var(--font-display); font-size: var(--text-2xl); line-height: 1.15; }
.code-display {
  padding: 5px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: clamp(20px, 2.4vw, 30px);
  letter-spacing: 0.17em;
  line-height: 1.2;
}
.room-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  gap: 20px;
  align-items: start;
}

.room-stage {
  display: flex;
  min-height: 500px;
  padding: clamp(18px, 2.6vw, 30px);
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
}

.room-seats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.seat-card {
  display: flex;
  min-width: 0;
  min-height: 150px;
  padding: 16px 12px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  text-align: center;
  position: relative;
}
.seat-card.is-empty { border-style: dashed; background: transparent; color: var(--text-3); }
.seat-card.is-ready { border-color: color-mix(in srgb, var(--success) 55%, var(--line)); }
.seat-card.is-you { box-shadow: inset 0 0 0 1px var(--accent); }
.seat-avatar {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--line-strong);
  font-family: var(--font-display);
  font-size: 24px;
}
.seat-card.is-empty .seat-avatar { background: transparent; border-style: dashed; color: var(--text-3); }
.seat-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.seat-sub { color: var(--text-3); font-size: var(--text-xs); }
.seat-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 10px;
  letter-spacing: 0.04em;
}
.tag-gold { background: color-mix(in srgb, var(--gold) 22%, var(--surface)); color: var(--gold); }
.tag-live { background: color-mix(in srgb, var(--success) 18%, var(--surface)); color: var(--success); }
.tag-off { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger-strong); }
.tag-you { background: var(--accent); color: var(--text-on-accent); }

.room-center { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0; text-align: center; }
.room-status { margin: 0; color: var(--text-2); font-size: var(--text-lg); }
.countdown-display { display: flex; align-items: baseline; gap: 8px; color: var(--accent); }
.countdown-display strong { font-family: var(--font-mono); font-size: clamp(40px, 5vw, 58px); line-height: 1; }
.countdown-display span { color: var(--text-2); font-size: var(--text-sm); }
#ready-btn { min-width: min(260px, 76vw); }
.room-note { margin: 0; max-width: 36ch; color: var(--text-3); font-size: var(--text-xs); }

.room-scoreboard { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; border-top: 1px dashed var(--line); }
.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text-2);
  font-size: var(--text-xs);
}
.score-pill strong { color: var(--text); font-family: var(--font-mono); }
.score-pill .score-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ---------- 侧栏 / 聊天 ---------- */

.rail-slot { min-width: 0; }
body[data-view="lobby"] .rail-slot { display: none; }

.rail {
  display: flex;
  height: min(680px, calc(100dvh - 118px));
  min-height: 430px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.rail-tabs { display: flex; align-items: center; gap: 3px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex: none; }
.rail-tab {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-size: var(--text-xs);
}
.rail-tab:hover { background: var(--surface-2); color: var(--text); }
.rail-tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }
.rail-close {
  display: none;
  width: 34px;
  height: 34px;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 20px;
  line-height: 1;
}

.rail-panel { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow: hidden; }
.rail-panel[hidden] { display: none; }

.chat-head { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px 4px; color: var(--text-3); font-size: var(--text-xs); flex: none; }
.chat-list { display: flex; min-height: 150px; flex: 1; flex-direction: column; gap: 8px; overflow-y: auto; padding: 10px 14px; overscroll-behavior: contain; }
.chat-empty { margin: auto; color: var(--text-3); font-size: var(--text-xs); text-align: center; line-height: 1.8; }

.msg {
  align-self: flex-start;
  max-width: 88%;
  padding: 7px 10px;
  border-radius: 4px 12px 12px 12px;
  background: var(--chat-other);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.msg.is-self { align-self: flex-end; border-radius: 12px 4px 12px 12px; background: var(--chat-self); }
.msg.is-system {
  align-self: center;
  max-width: 100%;
  padding: 2px 4px;
  background: transparent;
  color: var(--system);
  font-size: var(--text-xs);
  text-align: center;
}
.msg-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; color: var(--text-3); font-size: 10px; }
.msg.is-self .msg-meta { justify-content: flex-end; }
.msg-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.is-quick .msg-text { color: var(--accent); }

.quick-row { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 2px; flex: none; scrollbar-width: none; }
.quick-row::-webkit-scrollbar { display: none; }
.quick-chip {
  flex: none;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 10px;
  white-space: nowrap;
}
.quick-chip:hover { border-color: var(--accent); color: var(--text); }

.voice-strip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 12px; border-top: 1px solid var(--line); color: var(--text-3); font-size: var(--text-xs); flex: none; }
.mini-btn {
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  font-size: 10px;
}
.mini-btn:hover { border-color: var(--line-strong); color: var(--text); }

.chat-form { display: flex; gap: 7px; padding: 9px 12px calc(9px + var(--safe-bottom)); border-top: 1px solid var(--line); flex: none; }
.chat-form input {
  min-width: 0;
  flex: 1;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--input-line);
  border-radius: var(--radius-pill);
  background: var(--input-bg);
  color: var(--text);
}
.chat-form input::placeholder { color: var(--text-3); }
.chat-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }

.counter-head { padding: 14px 16px 8px; }
.counter-head h2 { margin: 0 0 2px; font-size: var(--text-md); }
.counter-head p { margin: 0; color: var(--text-3); font-size: var(--text-xs); }
.counter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; overflow-y: auto; padding: 8px 14px 12px; }
.counter-cell { padding: 6px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); text-align: center; }
.counter-rank { display: block; color: var(--text-2); font-family: var(--font-mono); font-size: 10px; }
.counter-count { display: block; margin-top: 1px; color: var(--text); font-family: var(--font-mono); font-size: 19px; font-weight: 700; line-height: 1.15; }
.counter-cell.is-hot { border-color: color-mix(in srgb, var(--accent) 44%, var(--line)); }
.counter-cell.is-hot .counter-count { color: var(--accent); }
.counter-cell.is-zero { opacity: 0.48; }
.counter-cell.is-zero .counter-count { color: var(--text-3); }
.counter-legend { display: flex; gap: 14px; padding: 0 16px 14px; color: var(--text-3); font-size: 10px; }
.counter-legend i { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; vertical-align: 0; }
.dot-hot { background: var(--accent); }
.dot-zero { background: var(--line-strong); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--badge-bg);
  color: var(--on-badge);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.voice-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--text-3); }
.voice-dot.is-on { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent); }

.rail-backdrop { position: fixed; inset: 0; z-index: 65; background: var(--overlay-soft); }

/* ---------- 弹窗 ---------- */

.app-dialog {
  width: min(calc(100vw - 32px), 780px);
  max-width: none;
  max-height: min(90dvh, 860px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.app-dialog::backdrop { background: var(--overlay); }
.app-dialog[open] { display: flex; flex-direction: column; }

.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); flex: none; }
.dialog-head h2 { margin: 0; font-family: var(--font-display); font-size: var(--text-xl); line-height: 1.2; }
.dialog-head .eyebrow { margin-bottom: 5px; }
.dialog-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 21px;
  line-height: 1;
}
.dialog-close:hover { background: var(--surface-2); color: var(--text); }

.dialog-body { padding: 20px 24px; overflow-y: auto; color: var(--text-2); font-size: var(--text-sm); line-height: 1.75; overscroll-behavior: contain; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 13px 24px calc(16px + var(--safe-bottom)); border-top: 1px solid var(--line); flex: none; }

.rules-body { display: grid; gap: 20px; }
.rule-block { padding-bottom: 16px; border-bottom: 1px dashed var(--line); }
.rule-block:last-child { border-bottom: 0; padding-bottom: 0; }
.rule-block h3 { margin: 0 0 8px; color: var(--text); font-family: var(--font-display); font-size: var(--text-lg); }
.rule-block p { margin: 0 0 8px; }
.rule-block p:last-child { margin-bottom: 0; }
.rule-block strong { color: var(--text); }
.rule-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rule-grid p { margin: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-2); font-size: var(--text-xs); line-height: 1.6; }
.rule-grid strong { display: block; margin-bottom: 2px; font-size: var(--text-sm); }
.rule-list { margin: 0; padding-left: 18px; }
.rule-list li + li { margin-top: 5px; }
kbd { display: inline-block; padding: 0 5px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface-3); color: var(--text); font-family: var(--font-mono); font-size: 10px; line-height: 1.7; }

.stats-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 20px; }
.stat-tile { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-2); text-align: center; }
.stat-value { display: block; color: var(--text); font-family: var(--font-mono); font-size: 26px; font-weight: 700; line-height: 1.15; }
.stat-label { display: block; margin-top: 3px; color: var(--text-3); font-size: 10px; letter-spacing: 0.05em; }
.stats-empty { padding: 30px 10px; color: var(--text-3); text-align: center; }
.history-title { margin: 0 0 8px; color: var(--text); font-size: var(--text-sm); }
.history-list { margin: 0; padding: 0; list-style: none; }
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px dashed var(--line); font-size: var(--text-xs); }
.history-room { font-family: var(--font-mono); letter-spacing: 0.1em; }
.history-role { color: var(--text-3); }
.history-delta { font-family: var(--font-mono); font-weight: 700; }
.is-positive { color: var(--success); }
.is-negative { color: var(--danger-strong); }

.share-body { display: grid; gap: 18px; }
.share-code { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--surface-2); }
.share-code span { color: var(--text-3); font-size: var(--text-xs); }
.share-code strong { flex: 1; color: var(--accent); font-family: var(--font-mono); font-size: clamp(24px, 4vw, 34px); letter-spacing: 0.2em; line-height: 1.1; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: var(--font-mono); font-size: var(--text-xs); }
.qr-wrap { text-align: center; }
.qr-wrap canvas {
  width: min(240px, 66vw);
  height: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--qr-paper);
  image-rendering: pixelated;
}
.qr-wrap p { margin: 8px 0 0; color: var(--text-3); font-size: var(--text-xs); }
.share-actions { display: flex; justify-content: flex-end; gap: 10px; }

.menu-dialog { width: min(calc(100vw - 32px), 420px); }
.menu-body { display: grid; gap: 2px; padding: 10px 12px 16px; }
.menu-theme { padding: 10px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-theme p { margin: 0 0 8px; color: var(--text-3); font-size: var(--text-xs); }
.menu-item {
  width: 100%;
  min-height: 46px;
  padding: 11px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: var(--text-sm);
  text-align: left;
}
.menu-item:hover { background: var(--surface-2); }
.menu-danger { color: var(--danger-strong); }

.small-dialog { width: min(calc(100vw - 32px), 420px); }
.small-dialog .dialog-body { padding: 26px 24px 20px; }
.small-dialog h2 { margin: 0 0 8px; color: var(--text); font-family: var(--font-display); font-size: var(--text-xl); }
.small-dialog p { margin: 0; line-height: 1.7; }
.closed-body { text-align: center; }
.seal-mark {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--seal);
  color: var(--seal-ink);
  font-family: var(--font-display);
  font-size: 26px;
  transform: rotate(-5deg);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--seal-ink) 18%, transparent);
}

/* ---------- 提示 / 网络 ---------- */

.toast-region {
  position: fixed;
  bottom: calc(22px + var(--safe-bottom));
  left: 50%;
  z-index: 120;
  display: flex;
  width: min(92vw, 440px);
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 100%;
  padding: 9px 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: var(--text-xs);
  line-height: 1.5;
  text-align: center;
  animation: toast-in 180ms var(--ease);
}
.toast.is-error { border-color: var(--danger); color: var(--danger-strong); }
.toast.is-good { border-color: color-mix(in srgb, var(--success) 60%, var(--line)); color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.net-banner {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 130;
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-pill);
  background: var(--danger-soft);
  color: var(--danger-strong);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.view:not([hidden]) { animation: view-in 240ms var(--ease); }
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) {
  :root { --rail-w: 304px; }
  .lobby-grid { gap: 36px; }
  .app-header { padding-inline: 24px; }
  .view-lobby, .view-room { padding-inline: 24px; }
}

@media (max-width: 920px) {
  .lobby-grid { grid-template-columns: minmax(0, 1fr); min-height: 0; gap: 30px; padding-top: 8px; }
  .lobby-hero h1 { max-width: 12ch; }
  .hero-cards { margin-bottom: 18px; }
  .lobby-panel { max-width: 640px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .rail-slot { display: contents; }
  .rail {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: 100%;
    height: min(74dvh, 620px);
    min-height: 0;
    max-height: none;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    transform: translateY(110%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  body.rail-open .rail { transform: none; }
  body.rail-open { overflow: hidden; }
  .rail-close { display: grid; }
  .rail-tabs { padding-top: 8px; }
  .room-stage { min-height: 460px; }
  .room-head { align-items: flex-start; flex-direction: column; }
  .room-head-actions { width: 100%; }
  .room-head-actions .btn { flex: 1; }
  .dialog-body { padding: 18px 20px; }
  .dialog-head { padding: 18px 20px 14px; }
  .dialog-foot { padding-inline: 20px; }
}

@media (max-width: 720px) {
  .app-header { padding: 12px 16px 8px; gap: 10px; }
  .brand-text small { display: none; }
  .header-tools { gap: 5px; }
  .theme-choice span { display: none; }
  .theme-choice { padding: 7px; min-height: 34px; }
  .icon-btn { min-height: 36px; padding: 6px 10px; }
  .view-lobby, .view-room { padding: 14px 16px 28px; }
  .lobby-hero h1 { font-size: clamp(38px, 11.4vw, 58px); }
  .hero-lead { margin-bottom: 20px; }
  .lobby-panel { padding: 20px; border-radius: var(--radius-lg); }
  .panel-head { margin-bottom: 18px; }
  .join-row { grid-template-columns: minmax(0, 1fr) 88px; }
  .lobby-foot { flex-direction: column; gap: 4px; }
  .room-stage { padding: 16px; min-height: 430px; gap: 18px; }
  .room-seats { gap: 8px; }
  .seat-card { min-height: 132px; padding: 12px 6px; gap: 6px; }
  .seat-avatar { width: 46px; height: 46px; font-size: 20px; }
  .seat-name { font-size: var(--text-sm); }
  .seat-sub { font-size: 10px; }
  .room-status { font-size: var(--text-md); }
  .room-note { font-size: 11px; }
  .stats-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rule-grid { grid-template-columns: minmax(0, 1fr); }
  .dialog-head h2 { font-size: var(--text-lg); }
  .app-dialog { width: calc(100vw - 20px); max-height: 92dvh; border-radius: var(--radius-lg); }
  .share-code { gap: 8px; padding: 12px; }
  .share-code strong { font-size: clamp(22px, 6.4vw, 30px); }
  .copy-row { flex-direction: column; }
  .copy-row .btn { width: 100%; }
  .history-row { gap: 8px; }
}

@media (max-width: 520px) {
  .brand-text { display: none; }
  .brand-mark { width: 40px; height: 40px; border-radius: 11px; font-size: 21px; }
  .theme-switch { padding: 2px; }
  .theme-choice { min-height: 32px; padding: 6px; }
  .swatch { width: 12px; height: 12px; }
  .hero-cards { display: none; }
  .lobby-hero h1 { margin-bottom: 14px; }
  .lobby-grid { gap: 20px; padding-top: 0; }
  .hero-points li { grid-template-columns: 48px minmax(0, 1fr); gap: 8px; }
  .join-row { grid-template-columns: minmax(0, 1fr); }
  .btn-join { width: 100%; }
  .room-head h1 { flex-wrap: wrap; gap: 8px; font-size: 22px; }
  .room-head-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .room-seats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .seat-tags { min-height: 20px; }
  .seat-tags .tag:not(.tag-you):not(.tag-gold) { display: none; }
  .room-center { padding: 4px 0; }
  .room-scoreboard { gap: 5px; }
  .score-pill { padding: 4px 8px; font-size: 10px; }
  .counter-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .toast-region { bottom: calc(14px + var(--safe-bottom)); }
}
