/* ───────────── 设计令牌 ───────────── */
:root {
  --bg: #f4f6f8;
  --bg-elev: #ffffff;
  --fg: #16181d;
  --fg-muted: #646b78;
  --fg-faint: #97a0ad;
  --line: #e3e7ec;
  --line-strong: #cfd6df;

  --accent: #1f6feb;
  --accent-soft: #e8f0fe;

  --yellow: #fff3b0;
  --yellow-line: #e8cf5a;
  --yellow-fg: #6b5300;

  --pos: #17864b;
  --pos-soft: #e6f6ec;
  --neg: #c62b3a;
  --neg-soft: #fdebed;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 26, 38, 0.04), 0 8px 24px -12px rgba(20, 26, 38, 0.14);
  --font: ui-sans-serif, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --bg-elev: #171b22;
    --fg: #e9edf3;
    --fg-muted: #9aa4b2;
    --fg-faint: #6c7686;
    --line: #242a34;
    --line-strong: #333b48;

    --accent: #5b9dff;
    --accent-soft: #1a2536;

    --yellow: #3d3410;
    --yellow-line: #6b5a16;
    --yellow-fg: #ffd85e;

    --pos: #3fce85;
    --pos-soft: #12291d;
    --neg: #ff6b7a;
    --neg-soft: #2c1519;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.7);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: clamp(20px, 5vw, 56px) clamp(14px, 4vw, 24px) 40px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  display: grid;
  gap: clamp(14px, 2vw, 18px);
}

/* ───────────── 页头 ───────────── */
.head {
  padding: 0 4px;
}

h1 {
  margin: 0;
  font-size: clamp(19px, 5.4vw, 30px);
  font-weight: 650;
  letter-spacing: -0.015em;
}

.sub {
  margin: 6px 0 0;
  color: var(--fg-muted);
  font-size: 14px;
  max-width: 46ch;
  line-height: 1.5;
}

/* ───────────── 卡片 ───────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 26px);
}

/* ───────────── 表单 ───────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 18px 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.01em;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 7px;
  margin-top: -1px;
  border-radius: 5px;
  background: var(--yellow);
  border: 1px solid var(--yellow-line);
  color: var(--yellow-fg);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

input[type="text"] {
  appearance: none;
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input[type="text"]:hover {
  border-color: var(--fg-faint);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="text"][aria-invalid="true"] {
  border-color: var(--neg);
  box-shadow: 0 0 0 3px var(--neg-soft);
}

/* 数值输入的浏览器调节箭头会干扰阅读，这里用纯文本输入 + inputmode */
input[type="text"]::-webkit-outer-spin-button,
input[type="text"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-suffix {
  position: relative;
}

.input-suffix input {
  padding-right: 34px;
}

.suffix {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-faint);
  font-family: var(--mono);
  font-size: 14px;
  pointer-events: none;
}

.hint {
  margin: 0;
  min-height: 17px;
  font-size: 12.5px;
  color: var(--fg-faint);
  line-height: 1.35;
}

.hint.error {
  color: var(--neg);
  font-weight: 550;
}

/* ───────────── 实时行情指示 ───────────── */
.quote {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -1px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.quote[data-state="up"] {
  color: var(--pos);
}

.quote[data-state="down"] {
  color: var(--neg);
}

.quote[data-state="error"] {
  color: var(--fg-faint);
}

.quote-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}

.quote[data-state="loading"] .quote-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

.quote[data-state="up"] .quote-dot,
.quote[data-state="down"] .quote-dot {
  opacity: 1;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 0.9;
  }
}

.quote-text {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: -0.01em;
}

.quote-action {
  appearance: none;
  margin: 0;
  padding: 1px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 11px;
  line-height: 1.6;
  cursor: pointer;
  opacity: 0.9;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.quote-action:hover {
  background: var(--accent-soft);
  opacity: 1;
}

.quote-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-status {
  margin: 16px 0 0;
  min-height: 20px;
  font-size: 13px;
  color: var(--neg);
}

/* ───────────── 结果 ───────────── */
.result-card {
  padding-top: clamp(16px, 2.4vw, 22px);
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge.pos {
  background: var(--pos-soft);
  color: var(--pos);
}

.badge.neg {
  background: var(--neg-soft);
  color: var(--neg);
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 12px 0 20px;
  border-bottom: 1px solid var(--line);
}

.hero-label {
  width: 100%;
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 600;
}

.hero-value {
  font-family: var(--mono);
  font-size: clamp(30px, 6vw, 44px);
  font-weight: 620;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

.hero-value.pos {
  color: var(--pos);
}

.hero-value.neg {
  color: var(--neg);
}

.hero-rate {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.hero-rate.pos {
  color: var(--pos);
}

.hero-rate.neg {
  color: var(--neg);
}

/* ───────────── 明细表 ───────────── */
.detail {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.detail th,
.detail td {
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  vertical-align: baseline;
  text-align: left;
}

.detail tr:last-child th,
.detail tr:last-child td {
  border-bottom: none;
}

.detail th {
  font-weight: 550;
  font-size: 14px;
  color: var(--fg);
}

.detail th small {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--fg-faint);
  font-family: var(--mono);
}

.detail td {
  text-align: right;
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--fg);
  width: 42%;
}

.formula {
  margin: 16px 0 0;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px dashed var(--line-strong);
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-x: auto;
  white-space: nowrap;
}

/* ───────────── 页脚 ───────────── */
.foot {
  padding: 2px 4px;
  color: var(--fg-faint);
  font-size: 12.5px;
}

@media (max-width: 420px) {
  .grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .detail th small {
    display: none;
  }

  .detail td {
    width: auto;
  }

  .hero {
    padding-bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
