/* 现代简洁风格 */
:root {
  --bg: #0b1020;
  --bg-soft: #121a33;
  --card: #182245;
  --text: #e8edff;
  --muted: #a7b1d6;
  --accent: #004f8b;
  --accent-2: #9f7aea;
  --good: #4ade80;
  --bad: #f87171;
  /* 新增：统一变量用于边框、顶栏、标签等（深色默认值） */
  --border: #1f2b56;
  --topbar-bg: rgba(18,26,51,0.7);
  --tabs-bg: rgba(18,26,51,0.5);
  --input-bg: #101734;
  --placeholder: #7c88b2;
  --badge-bg: #223064;
  --badge-text: #cbd5ff;
  --badge-border: #304080;
  --accent-glow: rgba(110,193,255,0.25);
}
/* 浅色主题（粉白）覆盖变量 */
body.theme-light {
  --bg: #fff7fa;         /* 背景：粉白 */
  --bg-soft: #fff0f6;    /* 次级背景 */
  --card: #ffffff;       /* 卡片纯白 */
  --text: #3b2c35;       /* 文本深玫瑰灰 */
  --muted: #8c7d86;      /* 次要文本 */
  --accent: #ff80ab;     /* 粉色强调 */
  --accent-2: #ff9ec7;   /* 次级粉色 */
  --good: #22c55e;
  --bad: #dc2626;
  --border: #f2c9d7;     /* 边框淡粉 */
  --topbar-bg: rgba(255,247,250,0.85);
  --tabs-bg: rgba(255,240,246,0.75);
  --input-bg: #fff0f6;   /* 输入背景浅粉 */
  --placeholder: #b08d9a;/* 占位符粉灰 */
  --badge-bg: #ffe6ef;   /* 徽章浅粉 */
  --badge-text: #7a4b5a; /* 徽章文字深粉 */
  --badge-border: #f2c9d7;/* 徽章边框 */
  --accent-glow: rgba(255,128,171,0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Microsoft Yahei", "Noto Sans", sans-serif;
  color: var(--text);
  /* 改为纯色背景 */
  background: var(--bg);
  accent-color: var(--accent);
}
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:16px 20px; background: var(--topbar-bg); position: sticky; top:0; backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar h1 { margin:0; font-size:20px; letter-spacing:1px; }
.stats { display:flex; gap:16px; flex-wrap: wrap; }
.stat { background: var(--bg-soft); padding:8px 10px; border-radius:8px; border:1px solid var(--border); }
.stat .label { color: var(--muted); margin-right:8px; }
.stat .value { font-weight:700; margin-right:8px; }
.stat .rate { color: var(--good); font-size:12px; }

.tabs { display:flex; gap:8px; padding:10px 20px; border-bottom:1px solid var(--border); background: var(--tabs-bg); position: sticky; top:58px; z-index: 5; }
.tab { padding:8px 14px; border-radius:8px; border:1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
 
 .content { padding: 20px; max-width: 1100px; margin: 0 auto; }
.panel { display:none; }
.panel.active { display:block; }
.desc { color: var(--muted); margin-top:0; }

.table { display:grid; grid-template-columns: 1fr 1fr 1fr; gap:12px; }
.card { background: var(--card); border:1px solid var(--border); border-radius:12px; padding:12px; }
.card h3 { margin:0 0 8px 0; }
.grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap:12px; margin-bottom: 16px; }
button { padding:8px 12px; border-radius:8px; border:1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
button:disabled { opacity:0.6; cursor:not-allowed; }
.hint { color: var(--muted); font-size: 12px; }
.footer { color: var(--muted); text-align:center; padding:16px; }

/* 表格/行样式 */
.row { display:grid; grid-template-columns: 160px 1fr; gap:10px; align-items:center; }
.row .controls { display:flex; gap:6px; align-items:center; flex-wrap: wrap; }
.badge { display:inline-block; padding:2px 6px; border-radius:999px; font-size:12px; background: var(--badge-bg); color: var(--badge-text); border:1px solid var(--badge-border); }
.small { font-size:12px; color: var(--muted); }
.value { font-weight:700; }
.rate { color: var(--good); font-size:12px; }
.cost { font-size:12px; }
.cost.bad { color: var(--bad); }
.cost.ok { color: var(--text); }

/* 弹窗样式 */
.modal.hidden { display:none; }
.modal .modal-backdrop { position: fixed; inset:0; background: rgba(0,0,0,0.5); }
.modal .modal-content { position: fixed; left:50%; top:50%; transform: translate(-50%, -50%); background: var(--card); border:1px solid var(--border); border-radius:12px; width: min(520px, 90vw); padding: 14px; z-index: 9; }
.modal .modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top: 8px; }
.modal .modal-row { display:flex; align-items:center; gap:8px; }
.modal input[type="range"] { width: 100%; }
.overlay { position: fixed; inset:0; background: rgba(0,0,0,0.5); z-index: 8; }
.overlay.hidden { display:none; }
.error { color: var(--bad); font-size: 12px; }
.slider-row { display:flex; align-items:center; gap:8px; }

/* 全局统一输入框样式（桌面+移动一致） */
input[type="text"], input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}
input[type="text"]::placeholder, input[type="password"]::placeholder { color: var(--placeholder); }
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
button:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent); color: #fff; }
::-moz-selection { background: var(--accent); color: #fff; }

/* 物质主线：名字更大更粗；左右区域宽度与间距调整（桌面） */
#matter-table .row { grid-template-columns: 140px 1fr; gap: 12px; }
#matter-table .card .row:first-child .name { font-size: 20px; font-weight: 700; color: var(--text); }
#matter-table .row > :first-child { font-size: 13px; color: var(--muted); }
#matter-table .row > :last-child { font-size: 16px; }
#matter-table .badge .value { font-size: 20px; }
#matter-table .badge .rate { font-size: 14px; }

/* 排行榜页表单行，左窄右宽（桌面） */
#tab-rank .row { grid-template-columns: 140px 1fr; }

@media (max-width: 640px){
  /* 顶部栏：手机端隐藏标题，统计+主题按钮保持同一行 */
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; gap:8px; flex-wrap: nowrap; }
  .topbar h1 { display: none; }
  .stats { gap:6px; flex-wrap: nowrap; white-space: nowrap; }
  .stat { padding:4px 6px; }
  .stat .label { font-size: 12px; }
  .stat .value { font-size: 14px; }
  .stat .rate { font-size: 12px; }
  .topbar .controls button { padding:6px 10px; font-size: 13px; }

  /* 底部标签栏（移动端） */
  .tabs { position: fixed; left:0; right:0; bottom:0; top:auto; z-index: 20; flex-wrap: nowrap; gap:6px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--tabs-bg); border-top:1px solid var(--border); border-bottom: none; box-shadow: 0 -4px 12px rgba(0,0,0,0.15); }
  .tab { flex: 1; padding:10px 8px; font-size: 14px; text-align: center; }
  .content { padding: 12px; padding-bottom: 88px; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .table { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .modal .modal-content { width: 94vw; }
  /* 移动端覆盖：物质主线与排行榜单列 */
  #matter-table .row { grid-template-columns: 1fr; }
  #matter-table .card .row:first-child .name { font-size: 18px; }
  #tab-rank .row { grid-template-columns: 1fr; }
}

/* 平板端适配：采用与手机相同的单列排版与底部标签栏 */
@media (min-width: 641px) and (max-width: 1024px){
  /* 顶部栏：平板端也隐藏标题，压缩统计信息 */
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; gap:10px; flex-wrap: nowrap; }
  .topbar h1 { display: none; }
  .stats { gap:8px; flex-wrap: nowrap; white-space: nowrap; }
  .stat { padding:6px 8px; }
  .topbar .controls button { padding:8px 12px; font-size: 14px; }

  /* 底部标签栏（平板端） */
  .tabs { position: fixed; left:0; right:0; bottom:0; top:auto; z-index: 20; flex-wrap: nowrap; gap:8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--tabs-bg); border-top:1px solid var(--border); border-bottom: none; box-shadow: 0 -4px 12px rgba(0,0,0,0.15); }
  .tab { flex: 1; padding:12px 10px; font-size: 15px; text-align: center; }
  .content { padding: 16px; padding-bottom: 96px; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* 单列排版 */
  .table { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .modal .modal-content { width: 92vw; }

  /* 平板端覆盖：物质主线与排行榜单列 */
  #matter-table .row { grid-template-columns: 1fr; }
  #matter-table .card .row:first-child .name { font-size: 20px; }
  #tab-rank .row { grid-template-columns: 1fr; }
}
button.secondary { background: var(--card); color: var(--text); border-color: var(--border); }