/* ===== 雀神战绩 · 国潮主题 ===== */
:root {
  --red: #B3122B;
  --red-bright: #D4333F;
  --gold: #E8C05A;
  --gold-deep: #C89B3C;
  --green: #1F4E3D;
  --bg: #F6F2E9;
  --bg-card: #FFFFFF;
  --text: #2A1E1E;
  --text-dim: #8A7A70;
  --line: #EDE4D6;
  --win: #C0392B;
  --lose: #1F7A4D;
  --shadow: 0 2px 10px rgba(80, 30, 20, 0.08);
  --radius: 14px;
  --header-bg: linear-gradient(135deg, #7A1F1F 0%, #B3122B 55%, #8A5A1F 100%);
}
[data-theme="dark"] {
  --bg: #141210;
  --bg-card: #201B18;
  --text: #F0E6D8;
  --text-dim: #9B8B7C;
  --line: #332A24;
  --win: #E5604F;
  --lose: #4FB386;
  --shadow: 0 2px 12px rgba(0,0,0,0.5);
  --header-bg: linear-gradient(135deg, #3A1010 0%, #5A1018 55%, #4A3010 100%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  transition: background .25s, color .25s;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--text); }

/* ===== 顶部 ===== */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--header-bg);
  color: #F7E7C0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-top));
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.logo { font-size: 18px; letter-spacing: 1px; }
.logo b { color: var(--gold); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.15); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}

/* ===== 主体 ===== */
#app { max-width: 640px; margin: 0 auto; padding: 12px 12px 20px; }
.view { display: none; animation: fadeIn .22s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-title { font-size: 20px; margin: 6px 2px 12px; }
.sub-title { font-size: 15px; margin: 18px 4px 8px; color: var(--text); }
.muted { color: var(--text-dim); font-size: 13px; }
.lb-hint { color: var(--text-dim); font-size: 12px; margin: 4px 2px 8px; }

/* ===== 分段选择 ===== */
.seg {
  display: flex; background: var(--bg-card); border-radius: 12px;
  padding: 4px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.seg button {
  flex: 1; padding: 8px 0; border-radius: 9px; font-size: 14px; color: var(--text-dim);
  transition: all .15s;
}
.seg button.active { background: var(--red); color: #fff; font-weight: 600; box-shadow: 0 2px 6px rgba(179,18,43,.35); }

/* ===== 卡片 ===== */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.field-label { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.field-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.field-row label { width: 52px; font-size: 14px; color: var(--text-dim); flex-shrink: 0; }
.field-row input {
  flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); min-width: 0;
}
.unit { color: var(--text-dim); font-size: 13px; flex-shrink: 0; }

/* ===== 玩家选择 ===== */
.player-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); transition: all .15s; position: relative;
}
.pick .emoji { font-size: 28px; }
.pick .nm { font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick.sel { border-color: var(--red); background: rgba(179,18,43,.08); }
.pick.sel::after {
  content: "✓"; position: absolute; top: 4px; right: 6px;
  color: #fff; background: var(--red); font-size: 11px; width: 16px; height: 16px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.pick.add { color: var(--text-dim); }
.pick.disabled { opacity: .35; }

/* ===== 记分局输入 ===== */
.score-player-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.score-player-row:last-child { border-bottom: none; }
.score-player-row .emoji { font-size: 24px; }
.score-player-row .nm { flex: 1; font-size: 15px; font-weight: 600; }
.score-player-row input {
  width: 88px; padding: 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); text-align: center;
}
.score-player-row input.win { border-color: var(--win); color: var(--win); }
.score-player-row input.lose { border-color: var(--lose); color: var(--lose); }
.score-player-row .fan-in { width: 60px; }

/* ===== 结算校验 ===== */
#sumCheck { font-size: 14px; }
#sumCheck.ok { color: var(--lose); }
#sumCheck.bad { color: var(--win); }

/* ===== 按钮 ===== */
.btn {
  display: block; width: 100%; padding: 13px; border-radius: 12px;
  font-size: 16px; font-weight: 600; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-bright) 100%);
  color: #fff; box-shadow: 0 4px 14px rgba(179,18,43,.35);
}
.btn-ghost { color: var(--text-dim); border: 1px solid var(--line); margin-top: 8px; }
.btn-block { margin-top: 12px; }
.btn-sm { display: inline-block; width: auto; padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ===== 排行榜 ===== */
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .1s;
  position: relative; overflow: hidden;
}
.lb-item:active { transform: scale(.99); }
.rank { width: 28px; text-align: center; font-size: 17px; font-weight: 800; color: var(--text-dim); }
.rank.r1 { color: var(--gold-deep); font-size: 22px; }
.rank.r2 { color: #9aa3ad; font-size: 21px; }
.rank.r3 { color: #c98a5a; font-size: 20px; }
.lb-avatar { font-size: 30px; }
.lb-body { flex: 1; min-width: 0; }
.lb-name { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.lb-title { font-size: 11px; color: var(--gold-deep); background: rgba(232,192,90,.15); padding: 1px 6px; border-radius: 6px; }
.lb-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.lb-score { text-align: right; }
.lb-score .num { font-size: 19px; font-weight: 800; }
.lb-score.win .num { color: var(--win); }
.lb-score.lose .num { color: var(--lose); }
.lb-score .wl { font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }
.wdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 2px; }
.wdot.W { background: var(--win); }
.wdot.L { background: var(--lose); }
.wdot.D { background: var(--text-dim); }
.rank-up { color: var(--win); font-size: 12px; font-weight: 700; }
.rank-down { color: var(--lose); font-size: 12px; font-weight: 700; }
.streak-fire { font-size: 12px; }
.lb-empty { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 14px; }

/* ===== 统计卡 ===== */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat-card { background: var(--bg-card); border-radius: var(--radius); padding: 12px 8px; text-align: center; box-shadow: var(--shadow); }
.stat-card .v { font-size: 20px; font-weight: 800; color: var(--red); }
.stat-card .k { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* ===== 高光/称号 ===== */
.hl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.hl-card { background: var(--bg-card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); text-align: center; }
.hl-card .ic { font-size: 26px; }
.hl-card .v { font-size: 16px; font-weight: 800; margin-top: 4px; }
.hl-card .k { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ===== 成就墙 ===== */
.achievement-wall { display: flex; flex-wrap: wrap; gap: 8px; }
.ach {
  width: 64px; text-align: center; padding: 8px 2px; border-radius: 10px;
  background: var(--bg-card); box-shadow: var(--shadow);
}
.ach .emoji { font-size: 26px; filter: grayscale(1) opacity(.35); }
.ach.unlocked .emoji { filter: none; }
.ach .nm { font-size: 10px; color: var(--text-dim); margin-top: 3px; }
.ach.unlocked .nm { color: var(--text); }

/* ===== 菜单 ===== */
.menu-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 4px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.menu-item:last-child { border-bottom: none; }
.menu-item .chev { color: var(--text-dim); }
.foot-note { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 16px; }

/* ===== 返回栏 ===== */
.back-bar { margin: 2px 0 10px; }
.back-bar .icon-btn { background: var(--bg-card); box-shadow: var(--shadow); width: auto; padding: 0 12px; border-radius: 20px; font-size: 15px; }

/* ===== 玩家头部 ===== */
.player-head {
  background: var(--header-bg); color: #F7E7C0; border-radius: var(--radius);
  padding: 20px 16px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px;
}
.player-head .top { display: flex; align-items: center; gap: 14px; }
.player-head .emoji { font-size: 52px; }
.player-head .nm { font-size: 20px; font-weight: 800; }
.player-head .tt { font-size: 13px; color: var(--gold); margin-top: 2px; }
.player-head .grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.player-head .gv { font-size: 18px; font-weight: 800; color: #fff; }
.player-head .gk { font-size: 11px; opacity: .8; }

/* ===== 折线图 ===== */
#trendChart { width: 100%; height: 160px; }

/* ===== 历史对局 ===== */
.game-item { background: var(--bg-card); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.game-item .hd { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.game-item .pl { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.game-item .pl .s { margin-left: auto; font-weight: 700; }
.game-item .pl .s.win { color: var(--win); }
.game-item .pl .s.lose { color: var(--lose); }

/* ===== 底部导航 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; background: var(--bg-card);
  box-shadow: 0 -2px 14px rgba(0,0,0,.1);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; font-size: 11px; color: var(--text-dim); transition: color .15s;
}
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--red); font-weight: 700; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(30,20,15,.92); color: #F7E7C0; padding: 11px 20px; border-radius: 24px;
  font-size: 14px; z-index: 200; opacity: 0; pointer-events: none; transition: all .3s;
  max-width: 86%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.hidden { display: none; }
.modal-card {
  background: var(--bg-card); border-radius: 16px; padding: 20px; width: 100%;
  max-width: 420px; max-height: 82vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  animation: popIn .2s ease;
}
@keyframes popIn { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
.modal-card h3 { margin: 0 0 12px; font-size: 17px; }
.modal-card textarea {
  width: 100%; min-height: 120px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); font-size: 13px; resize: vertical;
}
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* ===== 管理员 ===== */
.admin-seg { margin-top: 12px; }
.admin-games .gi { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.admin-games .gi .d { font-size: 12px; color: var(--text-dim); width: 100%; }
.admin-games .gi .sum { font-weight: 700; margin-left: auto; }
.admin-player-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin-player-row .nm { flex: 1; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--line); color: var(--text-dim); }
.badge.archived { background: rgba(179,18,43,.15); color: var(--win); }
.danger { color: var(--win); }

/* ===== 撒花 canvas ===== */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; }

.hidden { display: none !important; }

@media (min-width: 700px) {
  .hl-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-cards { grid-template-columns: repeat(4, 1fr); }
}
