:root {
  --bg: #120b26;
  --bg-2: #1b1035;
  --card: rgba(255, 255, 255, 0.07);
  --card-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f2ff;
  --muted: rgba(245, 242, 255, 0.62);
  --gold: #ffc94d;
  --gold-2: #ff9f43;
  --green: #35e0a1;
  --red: #ff6b81;
  --purple: #8b5cf6;
  --blue: #4ea8ff;
  --radius: 18px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 12% -10%, #3a1d6e 0%, transparent 60%),
    radial-gradient(900px 600px at 105% 10%, #173a6b 0%, transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  min-height: 100%;
}

.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 20% 20%, rgba(255, 201, 77, 0.14), transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(139, 92, 246, 0.18), transparent 45%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 120px;
}

/* ---------- 通用 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 4px 10px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--muted);
}
.section-title .sub { font-weight: 500; font-size: 12px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 22px 10px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-strong);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform .12s ease, filter .15s ease, background .15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.12); }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #2a1a00;
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(255, 175, 67, .28);
}
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 11px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s ease;
}
.chip.active {
  background: linear-gradient(135deg, var(--purple), var(--blue));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(139, 92, 246, .35);
}
.chip:active { transform: scale(.96); }

.input {
  width: 100%;
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
.input:focus { border-color: var(--purple); }
.input::placeholder { color: rgba(245, 242, 255, .35); }
.input.code { text-align: center; letter-spacing: 8px; font-size: 22px; font-weight: 700; text-transform: uppercase; }

.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- 首页 ---------- */
.hero { text-align: center; padding: 26px 10px 8px; }
.hero .logo { font-size: 40px; }
.hero h1 {
  margin: 8px 0 6px;
  font-size: 27px;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { margin: 0; color: var(--muted); font-size: 13px; }

.hero-cards { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.hero-cards span {
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 5px 10px;
}

.tips { margin-top: 16px; font-size: 12.5px; line-height: 1.8; color: var(--muted); }
.tips b { color: var(--text); }

/* ---------- 房间头部 ---------- */
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
}
.code-badge {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.room-meta { font-size: 12px; color: var(--muted); }

/* ---------- 玩家卡 ---------- */
.players { display: grid; gap: 12px; }

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  position: relative;
}
.player.me { border-color: rgba(255, 201, 77, .55); box-shadow: 0 0 0 1px rgba(255,201,77,.2) inset; }
.player.lord { border-color: rgba(255, 201, 77, .45); }
.avatar .crown {
  position: absolute; top: -8px; left: -7px;
  font-size: 15px; line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .55));
}
.player.empty { border-style: dashed; cursor: pointer; justify-content: center; color: var(--muted); }

.avatar {
  position: relative;
  width: 48px; height: 48px;
  flex: 0 0 48px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  box-shadow: 0 6px 14px rgba(0,0,0,.3);
}
.avatar.s1 { background: linear-gradient(135deg, #ff9f43, #ff6b81); }
.avatar.s2 { background: linear-gradient(135deg, #4ea8ff, #8b5cf6); }
.avatar.s3 { background: linear-gradient(135deg, #35e0a1, #2f9bd8); }

.p-info { flex: 1; min-width: 0; }
.p-name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.p-origin { font-size: 11px; color: var(--muted); margin-top: 3px; }
.tag-me {
  font-size: 10px; font-weight: 700; color: #2a1a00;
  background: var(--gold); border-radius: 6px; padding: 2px 5px;
}
.tag-lord {
  font-size: 11px; font-weight: 700; color: var(--gold);
  background: rgba(255, 201, 77, .16);
  border: 1px solid rgba(255, 201, 77, .38);
  border-radius: 6px; padding: 1px 6px;
  white-space: nowrap;
}

/* 结算动画 */
.player.flash-up { animation: flashUp .9s ease; }
.player.flash-down { animation: flashDown .9s ease; }
@keyframes flashUp {
  0% { border-color: rgba(53, 224, 161, .85); box-shadow: 0 0 0 0 rgba(53, 224, 161, .45), var(--shadow); }
  100% { border-color: var(--line); box-shadow: 0 0 0 16px rgba(53, 224, 161, 0), var(--shadow); }
}
@keyframes flashDown {
  0% { border-color: rgba(255, 107, 129, .85); box-shadow: 0 0 0 0 rgba(255, 107, 129, .45), var(--shadow); }
  100% { border-color: var(--line); box-shadow: 0 0 0 16px rgba(255, 107, 129, 0), var(--shadow); }
}

.float-delta {
  position: absolute; right: 16px; top: 12px;
  font-size: 19px; font-weight: 800;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .55);
  animation: floatUp 1.15s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(10px) scale(.85); }
  18% { opacity: 1; transform: translateY(0) scale(1.08); }
  100% { opacity: 0; transform: translateY(-32px) scale(1); }
}

.p-score.rolling { animation: scorePulse .6s ease; }
@keyframes scorePulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.p-score { font-size: 27px; font-weight: 800; min-width: 62px; text-align: right; font-variant-numeric: tabular-nums; }
.p-score.pos { color: var(--green); }
.p-score.neg { color: var(--red); }
.p-actions { display: flex; gap: 6px; }

.rank-medal { position: absolute; top: 0; right: 0; font-size: 11px; padding: 3px 8px; border-bottom-left-radius: 10px; background: rgba(255,201,77,.18); color: var(--gold); font-weight: 700; }

/* ---------- 历史 ---------- */
.history { display: grid; gap: 10px; }
.h-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255,255,255,.05);
  animation: pop .25s ease;
}
.h-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.h-title { font-size: 14px; font-weight: 700; }
.h-time { font-size: 11px; color: var(--muted); }
.h-flow { margin-top: 7px; display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.h-flow .plus { color: var(--green); font-weight: 700; }
.h-flow .minus { color: var(--red); font-weight: 700; }

.h-item.is-new {
  border-color: rgba(255, 201, 77, .55);
  background: rgba(255, 201, 77, .09);
  animation: slideIn .5s cubic-bezier(.2, .8, .3, 1);
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-12px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.h-lord { margin-right: 4px; }

/* 邀请 / 微信转发 */
.invite-logo { text-align: center; margin-bottom: 12px; }
.invite-logo img {
  width: 68px; height: 68px; border-radius: 18px; display: inline-block;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 201, 77, .35);
}
.invite-code {
  font-size: 40px; font-weight: 800; letter-spacing: 10px; text-align: center;
  color: var(--gold);
  background: rgba(255, 201, 77, .08);
  border: 1px dashed rgba(255, 201, 77, .45);
  border-radius: 14px; padding: 16px 8px 16px 18px; margin-bottom: 12px;
  text-shadow: 0 2px 14px rgba(255, 201, 77, .25);
}
.invite-desc { font-size: 13px; line-height: 1.75; opacity: .88; margin-bottom: 14px; }
.invite-desc b { color: var(--gold); }
.invite-link {
  margin-top: 12px; font-size: 12px; opacity: .55;
  word-break: break-all; text-align: center; line-height: 1.6;
}
.invite-tip { margin-top: 8px; font-size: 11px; opacity: .6; line-height: 1.6; text-align: center; }

.btn-wechat {
  background: #07C160; border-color: #07C160; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font-weight: 700;
}
.btn-wechat:hover { background: #06ad57; border-color: #06ad57; }
.btn-wechat svg { flex: none; }

/* 微信内「发送给朋友」指引蒙层 */
.wx-guide {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0, 0, 0, .74);
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 14px 20px;
  animation: wxFade .18s ease;
}
@keyframes wxFade { from { opacity: 0; } to { opacity: 1; } }
.wx-guide-inner { max-width: 230px; text-align: right; color: #fff; }
.wx-guide .btn { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .32); color: #fff; }
.wx-arrow {
  font-size: 30px; line-height: 1; margin-bottom: 8px;
  animation: wxNudge 1.2s ease-in-out infinite;
}
@keyframes wxNudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.wx-main { font-size: 15px; font-weight: 700; line-height: 1.75; margin: 0 0 8px; }
.wx-main b { color: var(--gold); }
.wx-sub { font-size: 12px; opacity: .82; line-height: 1.6; margin: 0 0 12px; }
.wx-tip { font-size: 11px; opacity: .6; margin-top: 10px; }

.mask.closing { animation: fadeOut .18s ease forwards; }
@keyframes fadeOut { to { opacity: 0; } }
.mask.closing .sheet { animation: sheetDown .2s ease forwards; }
@keyframes sheetDown { to { transform: translateY(34px); opacity: .25; } }

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

/* ---------- 底部操作条 ---------- */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(18,11,38,0), rgba(18,11,38,.92) 40%);
  display: flex; justify-content: center;
}
.dock-inner { width: 100%; max-width: 528px; display: flex; gap: 10px; }
.dock .btn { flex: 1; }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(8, 4, 20, .62);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 560px;
  background: linear-gradient(180deg, #241748, #1a1033);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow: auto;
  animation: up .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(24px); opacity: .4 } to { transform: none; opacity: 1 } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet .field { margin-bottom: 14px; }
.sheet .label { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.preview {
  border: 1px dashed rgba(255,201,77,.45);
  background: rgba(255,201,77,.08);
  border-radius: 14px;
  padding: 12px;
  font-size: 13.5px;
  line-height: 1.9;
}
.preview .pv-row { display: flex; justify-content: space-between; }
.preview b { font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs .chip { flex: 1; text-align: center; }

/* ---------- toast ---------- */
.toast-root { position: fixed; left: 0; right: 0; top: 14px; z-index: 40; display: grid; justify-items: center; pointer-events: none; }
.toast {
  background: rgba(20, 12, 40, .96);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastin .22s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: none } }

.settings details { }
.settings summary { cursor: pointer; font-size: 13px; color: var(--muted); outline: none; }
.settings .s-body { margin-top: 12px; display: grid; gap: 8px; }

@media (min-width: 640px) {
  .players { grid-template-columns: repeat(3, 1fr); }
  .player { flex-direction: column; text-align: center; }
  .p-score { text-align: center; }
}
