:root {
  --brand: #c2410c;
  --brand-dark: #9a3412;
  --brand-soft: #fff7ed;
  --brand-line: #fdba74;
  --ink: #1c1917;
  --ink-2: #44403c;
  --ink-3: #78716c;
  --ink-4: #a8a29e;
  --line: #f0efed;
  --bg: #f7f6f4;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(28, 25, 23, 0.05);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--bg) 78%, rgba(247, 246, 244, 0));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #ea580c);
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(194, 65, 12, 0.28);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 17px; font-weight: 800; letter-spacing: 0.5px; }
.brand-text em {
  font-style: normal;
  font-size: 11px;
  color: var(--ink-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.icon-btn {
  width: 36px; height: 36px;
  border: none;
  border-radius: 11px;
  background: var(--card);
  color: var(--ink-3);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- 搜索 ---------- */
.search-wrap { margin-bottom: 12px; }
.search-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
.search-input::placeholder { color: var(--ink-4); }
.search-input:focus { border-color: var(--brand-line); }

/* ---------- 分类 ---------- */
.cats {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat-chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border: none;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.cat-chip.cat-on {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(194, 65, 12, 0.25);
}

/* ---------- 工具网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 13px 15px;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.tool-card:active { transform: scale(0.98); }
.tool-icon { font-size: 21px; line-height: 1.2; }
.tool-star {
  position: absolute;
  top: 9px; right: 11px;
  color: #f59e0b;
  font-size: 13px;
}
.tool-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}
.tool-desc {
  font-size: 11px;
  color: var(--ink-4);
  line-height: 1.4;
}

/* ---------- 返回 / 小标题 ---------- */
.back-btn {
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-size: 14px;
  padding: 4px 2px 10px;
  cursor: pointer;
}
.sub-title {
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 800;
}

/* ---------- 计算页头部 ---------- */
.calc-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 2px 2px 18px;
}
.calc-icon {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--brand-soft);
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
}
.calc-head-text { flex: 1; min-width: 0; }
.calc-head-text h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.3;
}
.calc-head-text p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-4);
}
.fav-btn {
  border: none;
  background: transparent;
  color: #d6d3d1;
  font-size: 25px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}
.fav-btn.fav-on { color: #f59e0b; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.4px;
}
.tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: #fef3c7;
  color: #b45309;
  font-size: 10px;
  font-weight: 700;
}

/* ---------- 字段 ---------- */
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border-bottom: 1px solid var(--line);
}
.field.has-preset { border-bottom: none; }
.field:last-child { border-bottom: none; }
.field-label {
  flex: 0 0 auto;
  width: 42%;
  font-size: 14px;
  color: var(--ink-2);
}
.field-control {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
  gap: 6px;
}
.field-input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: right;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  padding: 6px 0;
}
.field-input::placeholder { font-weight: 400; color: var(--ink-4); }
/* 去掉数字输入框的上下箭头 */
.field-input::-webkit-outer-spin-button,
.field-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.field-unit {
  flex: 0 0 auto;
  min-width: 28px;
  text-align: right;
  font-size: 12px;
  color: var(--ink-4);
}
.field-select {
  flex: 1;
  border: none;
  background: transparent;
  text-align: right;
  text-align-last: right;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px 0;
  outline: none;
  cursor: pointer;
}

/* 单位换算：上下单位对调 */
.swap-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin-left: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafaf9;
  color: var(--ink-3);
  font-size: 15px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}
.swap-btn:active {
  transform: scale(0.94);
  background: var(--brand-soft);
  color: var(--brand);
}

/* 常用档位 */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding: 0 0 11px;
  border-bottom: 1px solid var(--line);
}
.preset-row:last-child { border-bottom: none; }
.preset-hint { font-size: 11px; color: var(--ink-4); }
.preset-chip {
  padding: 5px 11px;
  border: none;
  border-radius: 999px;
  background: #f5f5f4;
  color: var(--ink-2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.preset-chip.chip-on {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  box-shadow: inset 0 0 0 1.5px var(--brand-line);
}

/* ---------- 结果 ---------- */
.result-card { border-left: 4px solid var(--brand); }
.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
}
.result-row:last-of-type { border-bottom: none; }
.result-label { font-size: 14px; color: var(--ink-2); }
.result-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  text-align: right;
}
.result-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--brand);
  line-height: 1.2;
  word-break: break-all;
}
.result-unit { font-size: 12px; color: var(--ink-3); }
.result-row.is-error .result-value { font-size: 15px; color: #b91c1c; }
.result-row.is-error .result-label { color: #b91c1c; }

.actions { display: flex; gap: 10px; padding-top: 14px; }
.btn-primary, .btn-ghost {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: #f5f5f4; color: var(--ink-2); }
.btn-ghost:active { background: #e7e5e4; }

/* ---------- 公式 ---------- */
.formula-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 4px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.4px;
}
.formula-box {
  padding: 14px 16px;
  border-radius: 14px;
  background: #f5f5f4;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.75;
  word-break: break-word;
}

.disclaimer {
  margin: 22px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--ink-4);
  line-height: 1.6;
}

/* ---------- 历史 ---------- */
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.hist-tool { font-size: 14px; font-weight: 700; }
.hist-time { font-size: 11px; color: var(--ink-4); flex: 0 0 auto; }
.hist-params {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  padding: 9px 0;
}
.hist-param { font-size: 11px; color: var(--ink-4); }
.hist-results { padding-bottom: 9px; }
.hist-result {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
}
.hr-label { font-size: 13px; color: var(--ink-2); }
.hr-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--brand);
  text-align: right;
  word-break: break-all;
}
.hist-ops { display: flex; gap: 8px; padding-top: 4px; }
.mini-btn {
  flex: 1;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: #f5f5f4;
  color: var(--ink-2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.mini-btn.mini-danger { color: #b91c1c; background: #fef2f2; }

/* ---------- 其他 ---------- */
.empty {
  padding: 40px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-4);
  line-height: 1.7;
}
.foot-note {
  margin-top: 28px;
  text-align: center;
  font-size: 11px;
  color: var(--ink-4);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(34px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28, 25, 23, 0.9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 99;
}
.toast.toast-show {
  opacity: 1;
  transform: translate(-50%, 0);
}
