/* ---------- 主题 ---------- */
:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --surface: #f7f7f8;
  --surface-2: #f2f2f3;
  --fg: #0d0d0d;
  --muted: #6b6b76;
  --faint: #9a9aa3;
  --border: #e7e7e8;
  --border-strong: #d3d3d6;
  --focus: rgba(13, 13, 13, 0.09);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.07);
  --warn: #b45309;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d0d0d;
  --bg-elev: #141414;
  --surface: #1c1c1e;
  --surface-2: #232325;
  --fg: #ececec;
  --muted: #9b9ba3;
  --faint: #75757d;
  --border: #262628;
  --border-strong: #3a3a3d;
  --focus: rgba(255, 255, 255, 0.12);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 1px 3px rgba(0, 0, 0, 0.5);
  --warn: #f0b45f;
  color-scheme: dark;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

code {
  font-family: var(--mono);
  font-size: 0.92em;
}

::selection { background: var(--fg); color: var(--bg); }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px 72px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  flex: none;
}

.brand-mark svg { width: 17px; height: 17px; }

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border);
}

.icon-btn svg { width: 18px; height: 18px; }

[data-theme="light"] .i-moon { display: none; }
[data-theme="dark"] .i-sun { display: none; }

/* ---------- 首屏 ---------- */
.hero {
  padding: 44px 0 0;
}

.hero h1 {
  font-size: clamp(25px, 4.4vw, 33px);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.022em;
  margin-bottom: 14px;
  max-width: 18em;
  text-wrap: balance;
}

.lede {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.72;
  max-width: 46em;
}

/* ---------- 表单 ---------- */
.panel {
  margin-top: 34px;
  display: grid;
  gap: 34px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 9px;
  letter-spacing: 0.01em;
}

.tag-opt {
  display: inline-block;
  margin-left: 7px;
  padding: 0 6px;
  font-size: 11px;
  line-height: 17px;
  font-weight: 400;
  color: var(--faint);
  border: 1px solid var(--border);
  border-radius: 5px;
  vertical-align: 1px;
}

/* 下拉选择 */
.select { position: relative; }

.select-btn {
  width: 100%;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  font-size: 15.5px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.select-btn:hover { border-color: var(--border-strong); }

.select-btn:focus-visible,
.select-btn[aria-expanded="true"] {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3.5px var(--focus);
}

.select-btn .placeholder { color: var(--faint); }

.chevron {
  width: 18px;
  height: 18px;
  color: var(--faint);
  flex: none;
  transition: transform 0.18s ease;
}

.select-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.select-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  padding: 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 288px;
  overflow-y: auto;
  animation: pop 0.14s ease-out;
}

.select-menu[hidden] { display: none; }

@keyframes pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}

.option .opt-sub {
  font-size: 12.5px;
  color: var(--faint);
}

.option:hover,
.option.is-active { background: var(--surface); }

.option[aria-selected="true"] { background: var(--surface-2); }

.opt-check {
  width: 15px;
  height: 15px;
  color: var(--fg);
  opacity: 0;
  flex: none;
}

.option[aria-selected="true"] .opt-check { opacity: 1; }

/* 输入框 */
.input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder {
  color: var(--faint);
  letter-spacing: 0;
}

.input:hover { border-color: var(--border-strong); }

.input:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3.5px var(--focus);
}

.hint {
  margin-top: 9px;
  font-size: 12.8px;
  color: var(--faint);
  line-height: 1.6;
}

.hint.is-warn { color: var(--warn); }

/* ---------- 结果 ---------- */
.result-card {
  margin-top: 34px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  animation: rise 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 17px;
}

.result-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.result-sub {
  margin-top: 3px;
  font-size: 12.8px;
  color: var(--faint);
}

.count {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.group { border-top: 1px solid var(--border); }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 20px 11px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface);
}

.group-head span {
  font-weight: 400;
  letter-spacing: 0;
  color: var(--faint);
}

.group-head span::before { content: "· "; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.row:first-of-type { border-top: 0; }

.row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-label {
  font-size: 14.5px;
  font-weight: 500;
}

.row-note {
  font-size: 12.5px;
  color: var(--faint);
  line-height: 1.5;
}

.row-value {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.code {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.13em;
  white-space: nowrap;
  cursor: pointer;
  user-select: all;
  padding: 1px 0;
}

.copy {
  flex: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.copy:hover {
  color: var(--fg);
  border-color: var(--border-strong);
  background: var(--surface);
}

.copy.is-done {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--fg);
}

.row.is-pending .row-label { color: var(--muted); }

.pending-text {
  flex: none;
  font-size: 13px;
  color: var(--faint);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* 计算过程 */
.details { border-top: 1px solid var(--border); }

.details summary {
  padding: 13px 20px;
  font-size: 12.8px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: color 0.15s;
}

.details summary:hover { color: var(--fg); }
.details summary::-webkit-details-marker { display: none; }

.details summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4.5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.18s ease;
}

.details[open] summary::before { transform: rotate(90deg); }

.calc {
  padding: 2px 20px 20px;
}

.calc-line {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.9;
}

.calc-line code {
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  letter-spacing: 0.08em;
}

.calc-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 12px;
}

.calc-table th {
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--faint);
  text-align: right;
  padding: 0 0 7px;
  border-bottom: 1px solid var(--border);
}

.calc-table th:first-child { text-align: left; }
.calc-table th:last-child { width: 4.2em; }

.calc-table td {
  padding: 6px 0;
  text-align: right;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.calc-table td:first-child {
  text-align: left;
  color: var(--fg);
}

.calc-table tr:last-child td { border-bottom: 0; }

.calc-table td:last-child {
  color: var(--fg);
  font-weight: 600;
}

/* 空状态 */
.empty {
  margin-top: 34px;
  padding: 40px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
}

/* ---------- 说明 ---------- */
.notes {
  margin-top: 52px;
  padding-top: 26px;
  border-top: 1px solid var(--border);
}

.notes h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 14px;
}

.notes ul {
  display: grid;
  gap: 11px;
}

.notes li {
  position: relative;
  padding-left: 16px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.72;
}

.notes li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--faint);
}

.notes strong {
  color: var(--fg);
  font-weight: 500;
}

.notes code {
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
}

/* ---------- 页脚 ---------- */
.footer {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--faint);
}

/* ---------- 移动端 ---------- */
@media (max-width: 560px) {
  .page { padding: 0 18px 56px; }
  .hero { padding-top: 30px; }
  .row {
    flex-direction: column;
    align-items: flex-start;
    gap: 9px;
  }
  .row-value { width: 100%; justify-content: space-between; }
  .code { font-size: 20px; }
  .pending-text { align-self: flex-start; }
  .result-head { padding: 18px 16px 15px; }
  .group-head, .row, .details summary, .calc { padding-left: 16px; padding-right: 16px; }
  .notes { margin-top: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
