/* ===================================================================
   core.css — 移动端优先的布局与主题变量
   =================================================================== */

:root {
  --c-bg: #f4f6fb;
  --c-surface: #ffffff;
  --c-surface-2: #eef1f8;
  --c-border: #e2e6f0;
  --c-text: #16181d;
  --c-text-2: #5b6270;
  --c-text-3: #8b93a3;
  --c-accent: #1f4fd8;
  --c-accent-soft: #e8eeff;
  --c-ok: #0f9d58;
  --c-ok-soft: #e6f6ee;
  --c-warn: #b8860b;
  --c-warn-soft: #fdf4e0;
  --c-bad: #d93025;
  --c-bad-soft: #fdeceb;
  --c-gold: #b07d18;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 16px;
  --fs-lg: 19px;
  --fs-xl: 23px;
  --fs-2xl: 28px;

  --topbar-h: 52px;
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --shadow-sm: 0 1px 2px rgba(18, 24, 40, .06), 0 1px 3px rgba(18, 24, 40, .04);
  --shadow-md: 0 4px 16px rgba(18, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
          "Noto Sans CJK SC", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --c-bg: #101216;
  --c-surface: #191c22;
  --c-surface-2: #22262e;
  --c-border: #2c313b;
  --c-text: #e9ecf2;
  --c-text-2: #a7aebc;
  --c-text-3: #767e8d;
  --c-accent: #6f96ff;
  --c-accent-soft: #1e2740;
  --c-ok: #46d18a;
  --c-ok-soft: #17281f;
  --c-warn: #e0b154;
  --c-warn-soft: #2a2415;
  --c-bad: #ff6b60;
  --c-bad-soft: #2c1a19;
  --c-gold: #e0b154;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, .45);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--c-text);
  background: var(--c-bg);
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  max-width: 100vw;
}

/* 手机端防横向溢出：所有直接子元素都不得超过容器宽度 */
.app, .view, .card, .hero, .q-card { max-width: 100%; }
.view > *, .card > *, .q-card > * { min-width: 0; }
.hero, .card, .q-card, .blk, .answer-box { overflow-wrap: break-word; word-break: break-word; }
img, svg, video, table, pre { max-width: 100%; }

img { max-width: 100%; display: block; }
a { color: var(--c-accent); text-decoration: none; }
button { font-family: inherit; font-size: inherit; }
h1, h2, h3, h4 { margin: 0 0 var(--sp-2); line-height: 1.35; font-weight: 700; }
p { margin: 0 0 var(--sp-3); }
ul, ol { margin: 0 0 var(--sp-3); padding-left: 1.3em; }
li { margin-bottom: 3px; }
hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-4) 0; }
code { font-family: var(--mono); font-size: .92em; background: var(--c-surface-2); padding: 1px 5px; border-radius: 5px; }
pre { background: var(--c-surface-2); padding: var(--sp-3); border-radius: var(--r-md); overflow-x: auto; }
pre code { background: none; padding: 0; }
table { width: 100%; border-collapse: collapse; margin: 0 0 var(--sp-4); font-size: var(--fs-sm); display: block; overflow-x: auto; }
th, td { border: 1px solid var(--c-border); padding: 6px 9px; text-align: left; vertical-align: top; }
th { background: var(--c-surface-2); font-weight: 600; white-space: nowrap; }
blockquote { margin: 0 0 var(--sp-3); padding: 2px 0 2px 12px; border-left: 3px solid var(--c-accent); color: var(--c-text-2); }

/* ---------------- 布局骨架 ---------------- */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;   /* 兜住"两端出血"（负外边距）造成的宽度记账溢出 */
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--sp-2) 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 650;
  font-size: var(--fs-md);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--c-text);
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--c-surface-2); }

.view {
  flex: 1;
  padding: var(--sp-4) var(--sp-4) calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-6));
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  outline: none;
  overflow-x: hidden;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--c-surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--c-border);
}
.tab {
  border: 0;
  background: none;
  color: var(--c-text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s;
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab.active { color: var(--c-accent); font-weight: 600; }
.tab:active { background: var(--c-surface-2); }

/* ---------------- 抽屉 ---------------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(10, 14, 24, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 41;
  width: min(310px, 84vw);
  padding: calc(var(--safe-top) + var(--sp-4)) var(--sp-4) calc(var(--safe-bottom) + var(--sp-4));
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  box-shadow: var(--shadow-md);
  transform: translateX(-102%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  overflow-y: auto;
}
.drawer.show { transform: none; }
.drawer-logo { font-size: var(--fs-lg); font-weight: 750; letter-spacing: -.01em; }
.drawer-sub { color: var(--c-text-3); font-size: var(--fs-sm); }
.drawer-count {
  background: var(--c-accent-soft);
  color: var(--c-accent);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.5;
}
.drawer-nav { display: flex; flex-direction: column; gap: 2px; }
.drawer-nav .d-group {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  margin: var(--sp-3) 0 2px;
  font-weight: 600;
  letter-spacing: .06em;
}
.drawer-nav button {
  border: 0;
  background: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--c-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.drawer-nav button:active, .drawer-nav button.on { background: var(--c-accent-soft); color: var(--c-accent); }
.drawer-nav .d-badge { margin-left: auto; font-size: 11px; color: var(--c-text-3); }
.drawer-foot { margin-top: auto; padding-top: var(--sp-3); display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* ---------------- 通用组件 ---------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--sp-3);
}
.card.tight { padding: var(--sp-3); }
.card.flush { padding: 0; overflow: hidden; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin: var(--sp-5) 0 var(--sp-3);
  font-size: var(--fs-md);
  font-weight: 700;
}
.section-title .st-sub { font-size: var(--fs-xs); color: var(--c-text-3); font-weight: 500; margin-left: auto; }
.section-title:first-child { margin-top: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--c-accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:active { filter: brightness(.93); }
.btn.ghost { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn.soft { background: var(--c-accent-soft); color: var(--c-accent); }
.btn.danger { color: var(--c-bad); }
.btn.sm { padding: 6px 12px; font-size: var(--fs-sm); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.chip.accent { background: var(--c-accent-soft); color: var(--c-accent); }
.chip.ok { background: var(--c-ok-soft); color: var(--c-ok); }
.chip.warn { background: var(--c-warn-soft); color: var(--c-warn); }
.chip.bad { background: var(--c-bad-soft); color: var(--c-bad); }
.chip.gold { background: color-mix(in srgb, var(--c-gold) 16%, transparent); color: var(--c-gold); }

.row { display: flex; align-items: center; gap: var(--sp-2); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--c-text-2); }
.dim { color: var(--c-text-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.bold { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt2 { margin-top: var(--sp-2); }
.mt3 { margin-top: var(--sp-3); }
.mt4 { margin-top: var(--sp-4); }
.mb0 { margin-bottom: 0; }

.scroll-x {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 0 0 var(--sp-3);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scroll-x::-webkit-scrollbar { display: none; }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--c-surface-2);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c-accent), color-mix(in srgb, var(--c-accent) 55%, var(--c-ok)));
  transition: width .4s ease;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }

.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; border-bottom: 1px dashed var(--c-border); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 650; }

.empty { text-align: center; color: var(--c-text-3); padding: var(--sp-8) var(--sp-4); }
.empty .e-ico { font-size: 34px; display: block; margin-bottom: var(--sp-2); }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  z-index: 60;
  transform: translate(-50%, 12px);
  background: rgba(22, 24, 29, .94);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 86vw;
  text-align: center;
}
html[data-theme="dark"] .toast { background: rgba(240, 243, 250, .95); color: #14161b; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* modal */
.modal-root { position: fixed; inset: 0; z-index: 70; }
.modal-mask { position: absolute; inset: 0; background: rgba(10, 14, 24, .5); }
.modal-box {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--c-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--sp-5) var(--sp-4) calc(var(--safe-bottom) + var(--sp-5));
  box-shadow: var(--shadow-md);
  animation: sheet-up .24s cubic-bezier(.32, .72, 0, 1);
}
@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.modal-title { font-size: var(--fs-lg); font-weight: 700; margin-bottom: var(--sp-3); }
.modal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }
.modal-actions .btn { flex: 1; }

@media (min-width: 640px) {
  .modal-box { top: 50%; bottom: auto; transform: translate(-50%, -50%); border-radius: var(--r-xl); animation: none; }
}

/* 打印（导出打印友好） */
@media print {
  .topbar, .tabbar, .drawer, .drawer-mask, .btn { display: none !important; }
  .view { padding: 0; }
}
