:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-d: #4338ca;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 60%, #312e81 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 14px;
}

.app {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- 顶部 ---------- */
.topbar { display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 48px; height: 48px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; font-weight: 800; font-size: 22px;
  display: grid; place-items: center; flex: none;
  box-shadow: 0 6px 16px rgba(79,70,229,.4);
}
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

.tabs { display: flex; gap: 10px; flex-wrap: wrap; }
.tab-group { display: inline-flex; background: #f1f5f9; border-radius: 12px; padding: 4px; gap: 4px; }
.tab {
  border: none; background: transparent; color: var(--ink-soft);
  font-size: 14px; font-weight: 600; padding: 8px 16px; border-radius: 9px;
  cursor: pointer; transition: .15s;
}
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.35); }

/* ---------- 状态栏 ---------- */
.status {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat span { font-size: 11px; color: var(--ink-soft); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* ---------- 多人面板 ---------- */
.multi { background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 14px; padding: 12px; }
.room-setup { display: flex; flex-direction: column; gap: 10px; }
.hint-text { margin: 0; font-size: 12px; color: #4338ca; line-height: 1.5; }
.hint-text strong { color: var(--primary-d); }
.room-form { display: flex; gap: 8px; }
.room-form input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none;
}
.room-form input:focus { border-color: var(--primary); }
.room-note { margin: 0; font-size: 12px; color: var(--danger); min-height: 16px; }

.room-head { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.room-head .role { margin-left: auto; color: var(--primary-d); font-weight: 700; }
.players { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.player {
  display: flex; align-items: center; gap: 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
}
.player .rank { width: 22px; font-weight: 800; color: var(--ink-soft); text-align: center; }
.player .pname { flex: 1; font-weight: 600; }
.player .pscore { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--primary-d); }
.player .pstatus { font-size: 12px; padding: 2px 8px; border-radius: 20px; background: #f1f5f9; color: var(--ink-soft); }
.player.solved { border-color: var(--ok); }
.player.solved .pstatus { background: #dcfce7; color: var(--ok); }
.player.me { box-shadow: 0 0 0 2px var(--primary) inset; }

/* ---------- 牌 ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.card {
  position: relative; aspect-ratio: 3 / 4; border-radius: 14px; background: #fff;
  border: 1px solid var(--line); box-shadow: 0 6px 14px rgba(15,23,42,.08);
  display: grid; place-items: center; user-select: none;
}
.card .num { font-size: clamp(30px, 11vw, 52px); font-weight: 800; line-height: 1; }
.card .corner { position: absolute; font-size: 14px; font-weight: 700; }
.card .corner.tl { top: 8px; left: 10px; }
.card .corner.br { bottom: 8px; right: 10px; transform: rotate(180deg); }
.card.red { color: var(--danger); }
.card.black { color: #0f172a; }
.card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.card:active { transform: scale(.94); }
.card.picked { box-shadow: 0 0 0 3px var(--primary); }
.card.pop { animation: pop .25s ease; }
@keyframes pop { 0%{transform:scale(.85);opacity:.4} 100%{transform:scale(1);opacity:1} }

/* ---------- 算式 ---------- */
.expr-area { display: flex; flex-direction: column; gap: 8px; }
.expr-display {
  display: flex; align-items: center; gap: 10px; min-height: 46px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px;
}
.expr-text { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; word-break: break-all; flex: 1; }
.badge {
  font-size: 15px; font-weight: 800; padding: 4px 12px; border-radius: 20px;
  background: #e2e8f0; color: var(--ink-soft); white-space: nowrap; transition: .15s;
}
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.err { background: #fee2e2; color: var(--danger); }

#exprInput {
  width: 100%; padding: 12px 14px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 12px; outline: none; font-family: inherit;
}
#exprInput:focus { border-color: var(--primary); }

/* ---------- 键盘 ---------- */
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.keypad button {
  height: 52px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 20px; font-weight: 700; cursor: pointer; transition: .12s; color: var(--ink);
}
.keypad button:active { transform: scale(.94); background: #eef2ff; }
.keypad button.func { font-size: 15px; background: #f1f5f9; color: var(--ink-soft); }
.keypad button.op { background: #eef2ff; color: var(--primary-d); }
.keypad button.submit { background: var(--primary); color: #fff; border-color: var(--primary); }
.keypad button.submit:active { background: var(--primary-d); }

/* ---------- 操作 ---------- */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 12px 10px; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer; transition: .12s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.ghost { background: #f8fafc; color: var(--ink-soft); }
.btn.tiny { padding: 6px 12px; font-size: 12px; }

.tip { margin: 0; font-size: 12px; color: var(--ink-soft); text-align: center; line-height: 1.5; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: grid; place-items: center; padding: 16px; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 460px; background: #fff; border-radius: 18px;
  padding: 18px; max-height: 80vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.tab-group.center { display: flex; justify-content: center; margin-bottom: 12px; }
.board-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.board-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: rgba(15,23,42,.92); color: #fff; padding: 11px 18px; border-radius: 24px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 60;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 响应式 ---------- */
@media (max-width: 380px) {
  .keypad button { height: 46px; font-size: 18px; }
  .actions { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 16px; }
}
