:root {
  --bg: #0f1720; --panel: #16212e; --panel2: #1c2a3a; --line: #263647;
  --text: #e8eef5; --muted: #93a4b8; --accent: #3b82f6; --accent2: #2563eb;
  --avail: #22c55e; --won: #64748b; --pending: #f59e0b; --danger: #ef4444;
  --tierS: #f43f5e; --tierA: #eab308;
  --radius: 14px; --gap: 12px;
  --grid-min: 120px; /* 格子最小宽,自适应缩放靠 auto-fit */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* 修复:.sheet/.amend-banner 的 display:flex 会盖过 UA 的 [hidden],显式兜底 */
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans CJK JP", "PingFang SC", system-ui, sans-serif;
  font-size: 15px; display: flex; flex-direction: column;
}

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  gap: 10px; flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--won); flex: 0 0 auto; }
.dot.online { background: var(--avail); box-shadow: 0 0 8px var(--avail); }
.dot.offline { background: var(--danger); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.lang-btn, .role-badge {
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.role-badge { text-transform: uppercase; }
.queue-badge {
  background: var(--pending); color: #1a1200; font-weight: 700; border-radius: 999px;
  min-width: 22px; text-align: center; padding: 3px 8px; font-size: 12px;
}

/* ── 状态条 ── */
.statusbar { padding: 8px 14px; font-size: 13px; text-align: center; flex: 0 0 auto; }
.statusbar.offline { background: #3a2020; color: #fca5a5; }
.statusbar.syncing { background: #2a2410; color: #fcd34d; }
.statusbar.ok { background: #12301c; color: #86efac; }

/* ── 主布局:平板横屏左右分栏,手机竖屏上下堆叠 ── */
.layout { flex: 1 1 auto; display: flex; gap: var(--gap); padding: var(--gap); min-height: 0; overflow: hidden; }
.grid-pane { flex: 1 1 62%; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side-pane { flex: 1 1 38%; display: flex; flex-direction: column; gap: var(--gap); min-width: 300px; max-width: 460px; min-height: 0; overflow: hidden; }

.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; flex: 0 0 auto; }
.pane-head h2, .pane-head h3 { margin: 0; font-size: 15px; }
.slot-count-tag { color: var(--muted); font-size: 12px; }

/* ── ★ 自适应号码格子(auto-fit + minmax,不写死列数)── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--grid-min), 1fr));
  gap: 10px; align-content: start; overflow-y: auto; padding-right: 4px; flex: 1 1 auto;
}
.grid-empty-note { grid-column: 1 / -1; }
.empty-state { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px 0; }

.slot {
  position: relative; background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 10px 8px 8px; cursor: pointer; user-select: none;
  display: flex; flex-direction: column; gap: 6px; aspect-ratio: 3/4; min-height: 96px;
  transition: transform .08s, border-color .12s, background .12s;
}
.slot:active { transform: scale(.97); }
.slot .no { font-size: clamp(22px, 4.4vw, 34px); font-weight: 800; line-height: 1; }
.slot .thumb {
  flex: 1 1 auto; border-radius: 8px; background: var(--panel2);
  display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 24px;
}
.slot .thumb span { font-size: 26px; opacity: .5; }
.slot .pname { font-size: 11px; color: var(--muted); line-height: 1.25; max-height: 2.5em; overflow: hidden; }
.slot .tier {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 6px;
  font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; color: #10151b;
}
.tier-S { background: var(--tierS); color: #fff; }
.tier-A { background: var(--tierA); }
/* 状态色 */
.slot.available { border-color: color-mix(in srgb, var(--avail) 55%, var(--line)); }
.slot.won { opacity: .55; border-color: var(--won); }
.slot.won::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 44px; color: var(--won); }
.slot.pending { border-color: var(--pending); box-shadow: 0 0 0 2px color-mix(in srgb, var(--pending) 30%, transparent); }
.slot.selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); background: var(--panel2); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .chip { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chip.available { background: var(--avail); } .chip.won { background: var(--won); } .chip.pending { background: var(--pending); }
.legend .tier { position: static; width: 18px; height: 18px; }

/* ── 右侧卡片 ── */
.register-card, .queue-card, .feed-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.register-card { flex: 0 0 auto; }
.queue-card { flex: 1 1 40%; display: flex; flex-direction: column; min-height: 120px; overflow: hidden; }
.feed-card { flex: 1 1 40%; display: flex; flex-direction: column; min-height: 120px; overflow: hidden; }
.register-card h3 { margin: 0 0 10px; font-size: 14px; }

.register-flow { display: flex; align-items: stretch; gap: 6px; }
.flow-step { flex: 1 1 0; background: var(--panel2); border-radius: 10px; padding: 8px; min-width: 0; }
.flow-step label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.flow-arrow { align-self: center; color: var(--muted); }
.flow-pick { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-pick.filled { border-color: var(--accent); color: var(--text); }
.flow-prize { display: block; padding: 8px 4px; font-size: 13px; font-weight: 600; color: var(--avail); text-align: center; }

.register-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn { border: none; border-radius: 10px; padding: 12px 14px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; flex: 1 1 auto; }
.btn.primary:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.tiny { padding: 5px 9px; font-size: 12px; }
.btn.danger { background: var(--danger); color: #fff; }

.amend-banner { margin-top: 10px; background: #2a2410; color: #fcd34d; padding: 8px 10px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; font-size: 13px; }

/* 列表 */
.order-list, .feed-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; }
.order-item, .feed-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer;
}
.order-item:hover { background: var(--panel2); }
.order-item.claimed { opacity: .45; }
.order-item .buyer { font-weight: 600; }
.order-item .meta { color: var(--muted); font-size: 12px; }
.order-item .price { color: var(--avail); font-variant-numeric: tabular-nums; }
.feed-item .fmeta { color: var(--muted); font-size: 12px; }
.feed-item.voided { opacity: .4; text-decoration: line-through; }
.feed-item.pulled .st { color: var(--won); }
.feed-item.new .st { color: var(--pending); }
.feed-item.queued { background: #2a2410; }
.feed-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.badge-slot { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; border-radius: 6px; background: var(--accent2); color: #fff; font-weight: 700; font-size: 13px; }

/* 弹层 */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 50; }
.sheet-body { background: var(--panel); width: 100%; max-height: 80vh; border-radius: 16px 16px 0 0; padding: 14px; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.search { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; margin-bottom: 10px; }
.sheet-list { max-height: 55vh; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0b1118; border: 1px solid var(--line); color: var(--text); padding: 12px 18px; border-radius: 12px; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.5); font-size: 14px; max-width: 90vw; }
.toast.err { border-color: var(--danger); color: #fca5a5; }
.toast.ok { border-color: var(--avail); color: #86efac; }

/* ── 手机竖屏:上下堆叠,格子更小 ── */
@media (max-width: 820px) {
  body { overflow: auto; }
  /* 堆叠布局:两栏都按内容自然高度,不再 flex 拉伸争抢高度(否则 grid 滚动容器塌陷→与下方卡片重叠) */
  .layout { flex-direction: column; overflow: visible; height: auto; }
  .grid-pane, .side-pane { flex: 0 0 auto; max-width: none; min-width: 0; overflow: visible; }
  .grid { --grid-min: 88px; max-height: none; overflow: visible; flex: 0 0 auto; }
  .queue-card, .feed-card { flex: 0 0 auto; min-height: 0; }
  .order-list, .feed-list { max-height: 260px; }
  .register-flow { flex-wrap: wrap; }
  .flow-arrow { display: none; }
  .flow-step { flex: 1 1 30%; }
}
@media (max-width: 420px) { .grid { --grid-min: 74px; } .slot .no { font-size: 24px; } }
