:root {
  --bg: #0c110f;
  --surface: #141c19;
  --surface-2: #1b2621;
  --surface-3: #22302a;
  --border: #26352e;
  --border-strong: #354c41;
  --text: #ecf3ef;
  --text-muted: #93a69c;
  --text-dim: #667870;
  --accent: #2ea86f;
  --accent-soft: rgba(46, 168, 111, 0.14);
  --accent-border: rgba(46, 168, 111, 0.45);
  --gold: #d6a54b;
  --gold-soft: rgba(214, 165, 75, 0.14);
  --gold-border: rgba(214, 165, 75, 0.48);
  --danger: #dc6868;
  --danger-soft: rgba(220, 104, 104, 0.14);
  --danger-border: rgba(220, 104, 104, 0.42);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.app-shell {
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.boot-screen {
  min-height: 70dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.boot-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ---- 通用卡片与排版 ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.2px;
}

.section-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex-shrink: 0;
}

.icon-sm {
  width: 15px;
  height: 15px;
}

.icon-lg {
  width: 22px;
  height: 22px;
}

/* ---- 门禁页 ---- */

.gate-wrap {
  min-height: 78dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px 12px;
  gap: 14px;
}

.gate-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.gate-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.gate-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
  max-width: 300px;
  line-height: 1.7;
}

/* ---- 专属建房页 ---- */

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 2px;
}

.lobby-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lobby-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--accent-border);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.lobby-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
}

.lobby-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.roster-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.roster-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}

.roster-chip.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #dff8eb;
  font-weight: 600;
}

.roster-chip .order-badge {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--accent);
  color: #08120d;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.roster-chip .chip-del {
  color: var(--text-dim);
  display: inline-flex;
  padding: 2px;
  margin-left: 2px;
}

.inline-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.text-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s, border-color 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #07140d;
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 13px;
}

.btn-danger-soft {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: #f4b2b2;
}

.btn-block {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

.selected-strip {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px dashed var(--border-strong);
}

.selected-strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.order-preview-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.chain-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}

.chain-pill.breaker {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.chain-arrow {
  color: var(--text-dim);
  font-size: 12px;
}

details.rule-collapse {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

details.rule-collapse summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}

details.rule-collapse summary::-webkit-details-marker {
  display: none;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.field-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.field-box input,
.field-box select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  width: 100%;
  text-align: left;
  padding: 12px 13px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.recent-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.recent-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- 房间顶部栏 ---- */

.room-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.room-status-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-rack-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 16px;
  font-weight: 700;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.sync-dot.reconnecting {
  background: var(--gold);
  animation: pulse 1s infinite;
}

.room-meta-line {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: grid;
  place-items: center;
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* ---- 顶部防呆播报横条 ---- */

.last-event-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  min-height: 48px;
  transition: border-color 0.25s, background 0.25s;
}

.last-event-bar.flash {
  border-color: var(--accent);
  background: rgba(46, 168, 111, 0.1);
}

.last-event-text {
  min-width: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

.last-event-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.undo-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

/* ---- Tab 切换 ---- */

.tab-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}

.tab-btn {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-btn.active {
  background: var(--surface-3);
  color: var(--text);
}

.tab-count {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
}

/* ---- 玩家顺位卡片区 ---- */

.players-stack {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.player-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.14s, background 0.14s, transform 0.08s;
}

.player-card:active {
  transform: scale(0.99);
}

.player-card.selected {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(46, 168, 111, 0.13), var(--surface) 65%);
}

.player-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.seat-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

.seat-badge.breaker {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #7ee3b0;
}

.player-info {
  min-width: 0;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.player-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}

.pill-break {
  background: var(--accent-soft);
  color: #84e5b5;
  border: 1px solid var(--accent-border);
}

.pill-streak {
  background: var(--gold-soft);
  color: #f0ca7d;
  border: 1px solid var(--gold-border);
}

.pill-me {
  background: var(--surface-3);
  color: var(--text-muted);
}

.player-relation {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.player-score {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.score-pos {
  color: #46cb8c;
}

.score-neg {
  color: var(--danger);
}

.score-zero {
  color: var(--text-muted);
}

.left-strip {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

/* ---- 底部操作台（单手大按钮） ---- */

.action-dock {
  margin-top: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dock-target {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.dock-target strong {
  color: #7ee3b0;
}

.dock-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.win-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.foul-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.foul-row.single {
  grid-template-columns: 1fr;
}

.act-btn {
  border-radius: 13px;
  padding: 13px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-align: center;
  min-height: 70px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  transition: transform 0.08s ease, background 0.14s, border-color 0.14s;
}

.act-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.act-btn-win {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.act-btn-gold {
  background: var(--gold-soft);
  border-color: var(--gold-border);
}

.act-btn-big-gold {
  background: linear-gradient(160deg, rgba(214, 165, 75, 0.24), rgba(214, 165, 75, 0.09));
  border-color: var(--gold);
}

.act-btn-foul {
  min-height: 58px;
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.act-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.act-btn-gold .act-title,
.act-btn-big-gold .act-title {
  color: #f3d28f;
}

.act-btn-foul .act-title {
  font-size: 14px;
  color: #f4b7b7;
}

.act-sub {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.25;
}

/* ---- 身份认领轻提示条 ---- */

.identity-banner {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.identity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.identity-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.identity-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text);
}

/* ---- 流水与统计页 ---- */

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats-table th:first-child,
.stats-table td:first-child {
  text-align: left;
}

.stats-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.balance-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-item.undone {
  opacity: 0.45;
}

.history-item.undone .history-summary {
  text-decoration: line-through;
}

.history-summary {
  font-size: 13.5px;
  color: var(--text);
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* ---- 大字公共记分牌模式 ---- */

.board-mode {
  max-width: 820px;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.board-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-content: stretch;
}

.board-tile {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 20px;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
}

.board-tile.breaker {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(46, 168, 111, 0.14), var(--surface));
}

.board-name {
  font-size: 24px;
  font-weight: 700;
}

.board-score {
  font-size: 62px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ---- 模态抽屉 ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 6, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  padding: 12px;
}

.modal-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.qr-box {
  width: 210px;
  height: 210px;
  margin: 4px auto;
  padding: 10px;
  border-radius: 16px;
  background: #ffffff;
  display: grid;
  place-items: center;
}

.qr-box img {
  width: 100%;
  height: 100%;
  display: block;
}

.share-url-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
  word-break: break-all;
  text-align: center;
}

.manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 11px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.manage-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-btn {
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  color: var(--text);
}

/* ---- Toast ---- */

.toast-root {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 28px);
  max-width: 460px;
  z-index: 60;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #1b2822;
  border: 1px solid var(--accent-border);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.toast.warn {
  border-color: var(--gold);
  background: #262015;
}

.toast.error {
  border-color: var(--danger);
  background: #281717;
}
