:root {
  --bg: #f6f7fb;
  --bg-soft: #eef1f7;
  --card: #ffffff;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --muted: #8a93a3;
  --line: #e7eaf0;
  --gold: #c8962a;
  --gold-soft: #f3e6c6;
  --gold-deep: #9a6f12;
  --up: #1a8f5a;
  --up-soft: #e3f5ec;
  --down: #d23f3f;
  --down-soft: #fae6e6;
  --buy: #1f6feb;
  --sell: #b8860b;
  --shadow: 0 1px 2px rgba(20, 30, 50, .04), 0 8px 24px rgba(20, 30, 50, .06);
  --radius: 14px;
  --maxw: 1160px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 80% -120px, #fff7e6 0%, rgba(255, 247, 230, 0) 60%),
    var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

.muted { color: var(--muted); }

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
pre {
  background: #1d2330; color: #e7ecf5; padding: 14px 16px;
  border-radius: 10px; overflow-x: auto; font-size: 13px;
}
pre code { background: none; color: inherit; padding: 0; }
code {
  background: var(--bg-soft); padding: 1px 6px; border-radius: 6px;
  font-size: .9em; color: var(--gold-deep);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 22px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px;
  background: linear-gradient(135deg, #e7c777, var(--gold));
  color: #fff; font-weight: 800; border-radius: 10px; font-size: 15px;
  box-shadow: 0 4px 10px rgba(200, 150, 42, .35);
}
.brand-text { font-size: 17px; letter-spacing: .2px; }
.brand-text strong { color: var(--gold-deep); }

.main-nav { display: flex; gap: 4px; margin-left: 8px; }
.main-nav a {
  color: var(--ink-soft); padding: 8px 14px; border-radius: 9px;
  font-weight: 500; font-size: 14.5px;
}
.main-nav a:hover { background: var(--bg-soft); text-decoration: none; color: var(--ink); }
.main-nav a.active { background: var(--gold-soft); color: var(--gold-deep); }

.header-meta { margin-left: auto; }
.update-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--up-soft); color: var(--up);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}
.update-badge.muted { background: var(--bg-soft); color: var(--muted); }
.update-badge .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--up);
  box-shadow: 0 0 0 0 rgba(26, 143, 90, .5); animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(26, 143, 90, .45); }
  70% { box-shadow: 0 0 0 7px rgba(26, 143, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 143, 90, 0); }
}

/* ---------- Layout ---------- */
.page { padding: 28px 0 56px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.4px; }
.lead { margin: 0; color: var(--ink-soft); font-size: 15.5px; max-width: 720px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 18px; }
.card h2 { font-size: 19px; margin: 0 0 12px; }

/* ---------- Notices ---------- */
.notice { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14.5px; }
.notice.warn { background: #fff6e5; border: 1px solid #f3dca0; color: #8a5d00; }
.notice.info { background: #eef4ff; border: 1px solid #cfe0ff; color: #2c5bb5; }

.empty-state { text-align: center; padding: 44px 20px; }
.empty-state h2 { margin-top: 0; }
.empty-state pre { display: inline-block; text-align: left; margin: 10px auto; }

/* ---------- Hero ---------- */
.hero-grid { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 18px; margin-bottom: 18px; }
.hero-ref {
  background: linear-gradient(160deg, #fffdf7, #fbf3df);
  border-color: var(--gold-soft);
  position: relative; overflow: hidden;
}
.hero-ref::after {
  content: "Au"; position: absolute; right: -8px; bottom: -22px;
  font-size: 120px; font-weight: 800; color: rgba(200, 150, 42, .08);
}
.hero-ref-label { font-size: 13px; font-weight: 700; color: var(--gold-deep); text-transform: uppercase; letter-spacing: .5px; }
.hero-prices { display: flex; gap: 26px; margin: 16px 0 12px; flex-wrap: wrap; }
.hero-price { display: flex; flex-direction: column; }
.hp-label { font-size: 13px; color: var(--ink-soft); }
.hp-value { font-size: 23px; font-weight: 800; letter-spacing: -.5px; }
.hp-value.buy { color: var(--buy); }
.hp-value.sell { color: var(--sell); }
.hp-unit { font-size: 12px; color: var(--muted); }
.hero-change { margin-bottom: 10px; }
.hero-foot { font-size: 12.5px; }

.delta { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13.5px; padding: 5px 11px; border-radius: 999px; }
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
.delta.flat { background: var(--bg-soft); color: var(--muted); }

.hero-chart { display: flex; flex-direction: column; }
.chart-legend { display: flex; gap: 14px; font-size: 13px; }
.lg { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.lg::before { content: ""; width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.lg-sell::before { background: var(--sell); }
.lg-buy::before { background: var(--buy); }
.chart-wrap { position: relative; flex: 1; min-height: 240px; }
#priceChart { width: 100%; display: block; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; }
.chart-empty[hidden] { display: none; }

/* ---------- World gold reference ---------- */
.world-ref { margin-bottom: 18px; padding: 18px 20px; }
.world-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.world-item { display: flex; flex-direction: column; gap: 3px; padding-right: 14px; border-right: 1px solid var(--line); }
.world-item:last-child { border-right: none; padding-right: 0; }
.wi-label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.wi-value { font-size: 21px; font-weight: 800; letter-spacing: -.5px; color: var(--ink); }
.world-main .wi-value { color: var(--gold-deep); }
.world-premium .wi-value.up { color: var(--down); }
.world-premium .wi-value.down { color: var(--up); }
.wi-unit { font-size: 12px; color: var(--muted); }
.world-foot { margin-top: 14px; font-size: 12px; }
@media (max-width: 760px) {
  .world-grid { grid-template-columns: 1fr 1fr; }
  .world-item:nth-child(2n) { border-right: none; padding-right: 0; }
}

/* ---------- Matrix table ---------- */
.table-card { margin-bottom: 18px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.matrix th, .matrix td { padding: 13px 14px; text-align: center; border-bottom: 1px solid var(--line); }
.matrix thead th { font-size: 13px; color: var(--ink-soft); font-weight: 600; background: var(--bg-soft); }
.matrix thead th:first-child { border-top-left-radius: 10px; }
.matrix thead th:last-child { border-top-right-radius: 10px; }
.th-region { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.matrix .col-kind { text-align: left; font-weight: 600; }
.matrix tbody tr:hover { background: #fcfbf6; }
.cell-prices { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-size: 14px; }
.cell-buy { color: var(--buy); font-weight: 600; }
.cell-sell { color: var(--sell); font-weight: 700; }
.cell-sep { color: var(--muted); }
.cell-buy.best, .cell-sell.best {
  background: var(--gold-soft); border-radius: 6px; padding: 1px 6px;
  box-shadow: inset 0 0 0 1px rgba(154, 111, 18, .25);
}
.na { color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.buy { background: var(--buy); }
.sw.sell { background: var(--sell); }
.sw.best { background: var(--gold-soft); box-shadow: inset 0 0 0 1px rgba(154, 111, 18, .3); }
.sw.up { background: var(--down); }
.sw.down { background: var(--up); }

/* ---------- Source cards ---------- */
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.source-card { padding: 18px; }
.source-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.source-head h3 { margin: 0; font-size: 16px; }
.tag { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--bg-soft); color: var(--ink-soft); }
.tag-dn { background: var(--gold-soft); color: var(--gold-deep); }
table.mini { font-size: 13.5px; }
table.mini td { padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.mini-name { text-align: left; color: var(--ink-soft); }
.mini-buy { text-align: right; color: var(--buy); font-weight: 600; }
.mini-sell { text-align: right; color: var(--sell); font-weight: 700; }
.source-foot { margin-top: 10px; font-size: 12px; }

/* ---------- Compare ---------- */
.ref-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; padding: 14px 20px; }
.ref-label { font-weight: 700; color: var(--gold-deep); margin-right: 8px; }
.ref-val { font-weight: 700; margin-right: 14px; font-variant-numeric: tabular-nums; }
table.compare th, table.compare td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
table.compare thead th { background: var(--bg-soft); color: var(--ink-soft); font-size: 13px; font-weight: 600; }
table.compare .num { text-align: right; font-variant-numeric: tabular-nums; }
.th-sub { font-weight: 400; color: var(--muted); font-size: 11px; }
table.compare .prod { color: var(--ink-soft); }
table.compare .buy { color: var(--buy); font-weight: 600; }
table.compare .sell { color: var(--sell); font-weight: 700; }
table.compare .spread { color: var(--ink-soft); }
table.compare tbody tr:hover { background: #fcfbf6; }
.diff { font-weight: 700; display: inline-flex; flex-direction: column; line-height: 1.15; }
.diff small { font-weight: 500; opacity: .8; }
.diff.up { color: var(--down); }
.diff.down { color: var(--up); }

.ref-world { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ref-prem { font-weight: 700; font-variant-numeric: tabular-nums; }
.ref-prem.up { color: var(--down); }
.ref-prem.down { color: var(--up); }
table.compare tr.world-row { background: linear-gradient(0deg, #fffdf7, #fbf3df); }
table.compare tr.world-row:hover { background: #f7efd9; }
table.compare tr.world-row td:first-child { font-weight: 700; color: var(--gold-deep); }

/* ---------- Calculator ---------- */
.calc-grid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 18px; align-items: start; }
.calc-form .field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select, input[type="number"] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px; background: #fff; color: var(--ink);
  font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(200, 150, 42, .15); }
.btn-primary {
  width: 100%; margin-top: 4px; padding: 12px 16px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #e0b04a, var(--gold)); color: #fff;
  font-weight: 700; font-size: 15.5px; border-radius: 11px;
  box-shadow: 0 6px 16px rgba(200, 150, 42, .3);
}
.btn-primary:hover { filter: brightness(1.04); }
.calc-hint { margin: 12px 0 0; font-size: 12.5px; }

.result-label { font-weight: 700; color: var(--gold-deep); margin: 0 0 14px; min-height: 1.2em; }
.result-block { border-top: 1px solid var(--line); padding-top: 6px; }
.result-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.result-row span { color: var(--ink-soft); }
.result-row strong { font-variant-numeric: tabular-nums; }
.result-row.sub { font-size: 13.5px; }
.result-highlight { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.rh-item { padding: 14px; border-radius: 12px; text-align: center; }
.rh-item span { font-size: 13px; color: var(--ink-soft); }
.rh-item strong { display: block; margin-top: 8px; font-size: 19px; font-variant-numeric: tabular-nums; }
.buy-box { background: #eef4ff; }
.buy-box strong { color: var(--buy); }
.sell-box { background: #fff6e5; }
.sell-box strong { color: var(--sell); }
.loss { color: var(--down); }
.result-pl { margin-top: 14px; padding-top: 4px; border-top: 2px solid var(--line); }
.result-pl h3 { font-size: 15px; margin: 10px 0; }
.pl-final strong { font-size: 17px; }
.result-note { margin: 16px 0 0; font-size: 12.5px; }

/* ---------- About ---------- */
.about-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 18px; align-items: start; }
.src-list { list-style: none; padding: 0; margin: 0; }
.src-list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.src-list li:last-child { border-bottom: none; }
.src-name { font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.src-list p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.bullet { margin: 0 0 16px; padding-left: 20px; color: var(--ink-soft); }
.bullet li { margin: 6px 0; }
.notice-card { background: #fff9ee; border-color: #f1ddae; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: #fff; margin-top: 30px; }
.footer-inner { display: flex; justify-content: space-between; gap: 20px; padding: 22px 0; font-size: 13.5px; color: var(--ink-soft); flex-wrap: wrap; }
.footer-links { display: flex; gap: 16px; align-items: center; }

/* ---------- Reload toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 14px; cursor: pointer;
  z-index: 100; display: flex; align-items: center; gap: 10px;
}
.toast strong { color: #ffd874; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .hero-grid, .calc-grid { grid-template-columns: 1fr; }
  .main-nav { gap: 0; }
  .main-nav a { padding: 8px 10px; font-size: 13.5px; }
  .brand-text { display: none; }
}
@media (max-width: 560px) {
  .page-head h1 { font-size: 23px; }
  .header-inner { gap: 10px; }
  .header-meta { display: none; }
  .result-highlight { grid-template-columns: 1fr; }
  .footer-inner { flex-direction: column; }
}
