:root {
  color-scheme: light;
  --page: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --text: #17191c;
  --muted: #656b73;
  --muted-light: #9298a1;
  --border: #e3e6ea;
  --border-strong: #d4d8de;
  --gold: #b7791f;
  --gold-dark: #8c5c16;
  --gold-soft: #fff7e6;
  --accent-border: #ead5ac;
  --accent-edge: #ddb665;
  --red: #d94841;
  --red-soft: #fff1f0;
  --green: #14855f;
  --green-soft: #eaf8f2;
  --blue: #2d63b8;
  --shadow: 0 1px 2px rgba(20, 24, 31, .04), 0 8px 28px rgba(20, 24, 31, .05);
  --radius: 12px;
  --shell: min(1200px, calc(100vw - 48px));
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body[data-metal="silver"] {
  --gold: #647186;
  --gold-dark: #465164;
  --gold-soft: #f1f4f8;
  --accent-border: #d4dbe5;
  --accent-edge: #9aa6b8;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
}
.header-inner {
  width: var(--shell);
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--gold);
  font-size: 13px;
  font-weight: 700;
}
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand small { display: block; margin-top: 2px; color: var(--muted-light); font-size: 8px; letter-spacing: .13em; }
.main-nav { display: flex; align-items: center; gap: 30px; color: var(--muted); font-size: 13px; }
.main-nav a:hover { color: var(--text); }
.refresh-button {
  height: 36px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}
.refresh-button:hover { border-color: var(--gold); color: var(--gold-dark); }
.refresh-button svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button.loading svg { animation: spin .8s linear infinite; }

.page-section { width: var(--shell); margin: 0 auto; padding-top: 72px; }
.market-section { padding-top: 46px; }
.page-title-row, .section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 22px;
}
.page-title-row h1, .section-heading h2 { margin: 4px 0 0; font-size: 30px; line-height: 1.25; letter-spacing: -.03em; }
.market-title-line { display: flex; align-items: center; gap: 18px; }
.metal-switch { display: inline-flex; margin-top: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.metal-switch button { padding: 7px 11px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 11px; cursor: pointer; }
.metal-switch button b { margin-right: 4px; font-size: 9px; }
.metal-switch button:hover { color: var(--text); }
.metal-switch button.active { color: #fff; background: var(--gold); box-shadow: 0 1px 4px rgba(18, 23, 31, .12); }
.metal-switch button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.section-label { margin: 0; color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: .14em; }
.section-heading > p { max-width: 460px; margin: 0 0 3px; color: var(--muted); font-size: 13px; line-height: 1.6; text-align: right; }
.update-status { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 11px; }
.update-status b { color: var(--text); font-weight: 500; }
.status-line { display: flex; align-items: center; gap: 7px; }
.status-line i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

.overview-grid { display: grid; grid-template-columns: .92fr 1.08fr; gap: 16px; }
.primary-quote, .metric-card, .chart-panel, .bank-card, .tool-card, .formula-grid {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.primary-quote { position: relative; overflow: hidden; min-height: 314px; padding: 26px 28px 0; border-radius: var(--radius); }
.quote-heading, .quote-meta, .metric-head, .metric-foot, .bank-card-head, .spread-row, .bank-foot, .current-watch {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.quote-heading > div > span { display: block; font-size: 13px; font-weight: 600; }
.quote-heading small { display: block; margin-top: 4px; color: var(--muted-light); font-size: 10px; }
.live-badge { display: flex; align-items: center; gap: 6px; color: var(--green); font-size: 10px; }
.live-badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.primary-value { display: flex; align-items: baseline; gap: 7px; margin-top: 26px; white-space: nowrap; }
.primary-value > span { color: var(--gold); font-size: 24px; }
.primary-value strong, .metric-card > strong, .bank-prices strong, .current-watch strong, .valuation-result strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: -.035em;
}
.primary-value strong { font-size: clamp(52px, 5vw, 68px); font-weight: 650; line-height: 1; }
.primary-value small { color: var(--muted); font-size: 12px; }
.quote-meta { position: relative; z-index: 2; margin-top: 20px; color: var(--muted); font-size: 11px; }
.change-pill { padding: 6px 9px; border-radius: 6px; font-weight: 600; }
.change-pill.up { color: var(--red); background: var(--red-soft); }
.change-pill.down { color: var(--green); background: var(--green-soft); }
.change-pill.neutral { color: var(--muted); background: #f2f3f5; }
.hero-sparkline { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 95px; }

.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.metric-card { min-width: 0; padding: 21px; border-radius: var(--radius); }
.metric-card.featured { border-color: var(--accent-border); background: var(--gold-soft); }
.metric-head span { color: var(--muted); font-size: 12px; }
.metric-head small { color: var(--muted-light); font-size: 10px; }
.metric-card > strong { display: block; margin: 24px 0 22px; overflow: hidden; font-size: clamp(26px, 2.7vw, 36px); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.metric-foot { color: var(--muted-light); font-size: 10px; }
.copy-price { padding: 0; border: 0; color: var(--muted); background: transparent; font-size: 10px; cursor: pointer; }
.copy-price:hover { color: var(--gold-dark); }
.market-facts { margin-top: 14px; padding: 13px 16px; display: flex; align-items: center; gap: 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 9px; color: var(--muted); background: var(--surface); font-size: 10px; white-space: nowrap; }
.market-facts span { padding: 0 18px; border-right: 1px solid var(--border); }
.market-facts span:first-child { padding-left: 0; }
.market-facts span:last-child { border-right: 0; }
.market-facts b { color: var(--gold-dark); }

.chart-panel { padding: 22px 24px 16px; border-radius: var(--radius); }
.chart-controls { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.control-group { min-width: 0; }
.control-group > span, .range-row > span:first-child { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; }
.metric-control { flex: 1; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); }
.segmented button, .range-switch button { border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.segmented button { padding: 7px 12px; border-radius: 6px; font-size: 11px; }
.segmented button.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 4px rgba(18, 23, 31, .1); font-weight: 600; }
.metric-control .segmented { float: right; }
.range-row { margin-top: 18px; padding-top: 17px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; border-top: 1px solid var(--border); }
.range-row > span:first-child { margin: 0; }
.range-switch { display: flex; gap: 3px; min-width: 0; overflow-x: auto; }
.range-switch button { flex: none; padding: 6px 10px; border-radius: 6px; font-size: 10px; }
.range-switch button:hover { background: #f1f2f4; }
.range-switch button.active { color: #fff; background: var(--gold); font-weight: 600; }
.chart-source { color: var(--muted-light); font-size: 9px; text-align: right; }
.chart-stats { display: grid; grid-template-columns: repeat(4, 1fr); margin: 22px 0 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); }
.chart-stats > div { padding: 13px 16px; border-right: 1px solid var(--border); }
.chart-stats > div:last-child { border-right: 0; }
.chart-stats span { display: block; margin-bottom: 5px; color: var(--muted-light); font-size: 9px; }
.chart-stats strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.chart-stats strong.up { color: var(--red); }
.chart-stats strong.down { color: var(--green); }
.candle-legend { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin: 8px 3px -3px; color: var(--muted-light); font-size: 9px; }
.candle-legend[hidden] { display: none; }
.candle-legend span { display: flex; align-items: center; gap: 5px; }
.candle-legend i { width: 8px; height: 8px; border-radius: 2px; }
.candle-legend .up i { background: var(--red); }
.candle-legend .down i { background: var(--green); }
.chart-wrap { position: relative; min-height: 390px; }
#historyChart { width: 100%; min-height: 390px; overflow: visible; }
.chart-tooltip { position: absolute; z-index: 10; min-width: 150px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 7px; color: var(--text); background: rgba(255, 255, 255, .98); box-shadow: 0 8px 25px rgba(20, 24, 31, .14); font-size: 10px; line-height: 1.55; pointer-events: none; transform: translate(-50%, calc(-100% - 12px)); }
.chart-tooltip > span { display: block; margin-bottom: 3px; color: var(--muted); }
.chart-tooltip > strong { color: var(--gold-dark); font-size: 13px; }
.tooltip-ohlc { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin-top: 5px; }
.tooltip-ohlc b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); background: rgba(255,255,255,.78); font-size: 11px; }
.chart-loading span { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
.chart-loading.hidden { display: none; }
.chart-note { margin: 0; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted-light); font-size: 9px; line-height: 1.6; }

.bank-insight { margin-bottom: 14px; padding: 13px 16px; display: flex; align-items: center; gap: 14px; border: 1px solid var(--accent-border); border-radius: 9px; background: var(--gold-soft); }
.bank-insight > span { flex: none; padding: 4px 7px; border-radius: 5px; color: #fff; background: var(--gold); font-size: 9px; }
.bank-insight p { margin: 0; }
.bank-insight strong { display: block; margin-bottom: 2px; font-size: 12px; }
.bank-insight small { color: var(--muted); font-size: 10px; }
.bank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bank-card { padding: 22px; border-radius: var(--radius); }
.bank-card.best-sell { border-top: 3px solid var(--green); }
.bank-card.best-buy { box-shadow: inset 0 -3px 0 var(--accent-edge), var(--shadow); }
.bank-logo { width: 42px; height: 42px; margin-right: 11px; display: grid; place-items: center; border-radius: 8px; color: #fff; font-size: 9px; font-weight: 700; }
.ccb-logo { background: #1763aa; }
.icbc-logo { background: #c92d35; }
.bank-card-head h3 { margin: 0 0 4px; font-size: 14px; }
.bank-card-head p { margin: 0; color: var(--muted-light); font-size: 9px; }
.bank-live { margin-left: auto; padding: 4px 7px; border: 1px solid #b8dfcf; border-radius: 5px; color: var(--green); font-size: 8px; }
.bank-live.error { color: var(--red); border-color: #efc4c1; }
.bank-prices { display: grid; grid-template-columns: 1fr 1fr; margin: 22px 0 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.bank-prices > div { padding: 18px 0; }
.bank-prices > div + div { padding-left: 20px; border-left: 1px solid var(--border); }
.bank-prices span { display: block; margin-bottom: 9px; color: var(--muted); font-size: 10px; }
.bank-prices small { margin-left: 3px; color: var(--gold-dark); font-size: 8px; }
.bank-prices strong { font-size: 28px; }
.bank-prices em { margin-left: 4px; color: var(--muted-light); font-size: 8px; font-style: normal; }
.spread-row { color: var(--muted); font-size: 10px; }
.spread-row b { color: var(--text); font-weight: 500; }
.bank-foot { margin-top: 20px; color: var(--muted-light); font-size: 9px; }
.bank-foot a { color: var(--blue); }
.disclaimer { margin: 12px 0 0; color: var(--muted-light); font-size: 9px; line-height: 1.6; }

.tools-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
.tool-card { padding: 22px; border-radius: var(--radius); }
.tool-title { margin-bottom: 20px; }
.tool-title h3 { margin: 0 0 4px; font-size: 15px; }
.tool-title p { margin: 0; color: var(--muted-light); font-size: 9px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label > span { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 10px; }
.form-grid label span small { color: var(--muted-light); }
.wide-field { grid-column: 1 / -1; }
.input-unit, select { height: 42px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface); }
.input-unit { display: flex; align-items: center; }
.input-unit:focus-within, select:focus { border-color: var(--gold); outline: 2px solid var(--gold-soft); }
.input-unit input { width: 100%; min-width: 0; height: 100%; padding: 0 11px; border: 0; outline: 0; background: transparent; }
.input-unit b { flex: none; padding-right: 11px; color: var(--muted-light); font-size: 9px; font-weight: 400; }
select { width: 100%; padding: 0 10px; color: var(--text); outline: 0; }
.valuation-result { display: grid; grid-template-columns: 1.2fr .8fr .8fr; gap: 10px; margin-top: 17px; padding: 16px; border-radius: 8px; background: var(--gold-soft); }
.valuation-result span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 9px; }
.valuation-result strong { color: var(--gold-dark); font-size: 23px; }
.valuation-result b { font-size: 12px; font-weight: 600; }
.valuation-result b.up { color: var(--red); }
.valuation-result b.down { color: var(--green); }
.current-watch { margin-bottom: 17px; padding: 13px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.current-watch span { color: var(--muted); font-size: 10px; }
.current-watch strong { color: var(--gold-dark); font-size: 24px; }
.primary-button { width: 100%; height: 42px; margin-top: 16px; border: 0; border-radius: 7px; color: #fff; background: var(--gold); cursor: pointer; }
.primary-button:hover { background: var(--gold-dark); }
.alert-message { margin-top: 10px; color: var(--muted-light); font-size: 9px; }
.alert-message.triggered { color: var(--red); font-weight: 600; }

.methodology { padding-bottom: 72px; }
.formula-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-radius: var(--radius); overflow: hidden; }
.formula-grid article { padding: 19px; border-right: 1px solid var(--border); }
.formula-grid article:last-child { border-right: 0; }
.formula-grid h3 { margin: 0 0 12px; font-size: 12px; }
.formula-grid code { color: var(--gold-dark); font-family: Consolas, monospace; font-size: 10px; }
.formula-grid p { margin: 8px 0 0; color: var(--muted-light); font-size: 9px; line-height: 1.55; }
.app-footer { min-height: 90px; padding: 0 max(24px, calc((100vw - 1200px) / 2)); display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); color: var(--muted); background: var(--surface); font-size: 10px; }
.app-footer strong { margin-right: 12px; color: var(--text); }
.app-footer a { color: var(--blue); }

.toast { position: fixed; left: 50%; bottom: 22px; z-index: 50; padding: 10px 15px; border-radius: 7px; color: #fff; background: rgba(23, 25, 28, .92); box-shadow: 0 8px 25px rgba(0,0,0,.18); font-size: 10px; opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.skeleton { position: relative; overflow: hidden; }
.skeleton::before { content: ""; position: absolute; inset: 0; z-index: 10; background: linear-gradient(100deg, transparent 20%, rgba(230,232,235,.7) 45%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; pointer-events: none; }
body.loaded .skeleton::before { display: none; }
.data-error { color: var(--red) !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 980px) {
  .overview-grid { grid-template-columns: 1fr; }
  .primary-quote { min-height: 300px; }
  .tools-grid { grid-template-columns: 1fr; }
  .formula-grid { grid-template-columns: 1fr 1fr; }
  .formula-grid article:nth-child(2) { border-right: 0; }
  .formula-grid article:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
}

@media (max-width: 760px) {
  :root { --shell: min(100% - 28px, 640px); }
  .app-header { height: 58px; }
  .main-nav { display: none; }
  .refresh-button { width: 36px; padding: 0; justify-content: center; }
  .refresh-button span { display: none; }
  .page-section { padding-top: 54px; }
  .market-section { padding-top: 30px; }
  .page-title-row, .section-heading { align-items: flex-start; flex-direction: column; }
  .market-title-line { align-items: flex-start; flex-direction: column; gap: 10px; }
  .page-title-row h1, .section-heading h2 { font-size: 26px; }
  .section-heading > p { text-align: left; }
  .update-status { width: 100%; gap: 12px; flex-wrap: wrap; }
  .overview-grid { grid-template-columns: 1fr; }
  .primary-quote { min-height: 285px; padding: 22px 19px 0; }
  .primary-value strong { font-size: 54px; }
  .price-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 17px 15px; }
  .metric-card > strong { font-size: 27px; }
  .chart-panel { padding: 16px 12px 12px; }
  .chart-controls { align-items: flex-start; flex-direction: column; }
  .metric-control { width: 100%; }
  .metric-control .segmented { width: 100%; float: none; overflow-x: auto; }
  .segmented button { flex: none; }
  .range-row { grid-template-columns: 1fr; gap: 8px; }
  .chart-source { text-align: left; }
  .chart-stats { grid-template-columns: 1fr 1fr; }
  .chart-stats > div:nth-child(2) { border-right: 0; }
  .chart-stats > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .chart-wrap, #historyChart { min-height: 340px; }
  .bank-grid { grid-template-columns: 1fr; }
  .formula-grid { grid-template-columns: 1fr; }
  .formula-grid article { border-right: 0; border-bottom: 1px solid var(--border); }
  .formula-grid article:last-child { border-bottom: 0; }
  .app-footer { min-height: 110px; padding: 24px 14px; align-items: flex-start; flex-direction: column; gap: 12px; }
}

@media (max-width: 470px) {
  .price-grid { grid-template-columns: 1fr; }
  .metric-card > strong { font-size: 32px; }
  .market-facts span { padding: 0 12px; }
  .bank-prices strong { font-size: 25px; }
  .form-grid, .alert-form { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .valuation-result { grid-template-columns: 1fr 1fr; }
  .valuation-result > div:first-child { grid-column: 1 / -1; }
  .candle-legend span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
