:root {
  --bg: #07111f;
  --bg-elevated: #0b1728;
  --surface: #0e1c30;
  --surface-strong: #13243b;
  --border: #263a56;
  --text: #f5f8fc;
  --text-muted: #a8b7cb;
  --primary: #60a5fa;
  --primary-strong: #2563eb;
  --discount: #34d399;
  --premium: #fb923c;
  --danger: #f87171;
  --warning: #fbbf24;
  --focus: #93c5fd;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% -10%, rgba(37, 99, 235, 0.22), transparent 32rem),
    linear-gradient(180deg, #07111f 0%, #081524 100%);
}

button, a, summary { touch-action: manipulation; }

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: 8px;
  background: #ffffff;
  color: #07111f;
  transform: translateY(-150%);
  transition: transform 180ms ease-out;
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid rgba(38, 58, 86, 0.82);
  background: rgba(7, 17, 31, 0.9);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  place-items: center;
  border: 1px solid #3b82f6;
  border-radius: 14px;
  background: linear-gradient(145deg, #1d4ed8, #0f2b50);
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.04em;
  box-shadow: 0 0 24px rgba(37, 99, 235, 0.3);
}

.eyebrow, .section-label {
  margin: 0;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.status-pill {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.status-ok { color: var(--discount); }
.status-partial, .status-stale { color: var(--warning); }
.status-error { color: var(--danger); }
.status-loading { color: var(--primary); }

.refresh-button, .nav-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid #3b82f6;
  border-radius: 12px;
  background: var(--primary-strong);
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 180ms ease-out, border-color 180ms ease-out;
}

.nav-button {
  background: transparent;
  color: var(--primary);
  text-decoration: none;
}

.refresh-button:hover, .nav-button:hover {
  background: #1d4ed8;
  border-color: #60a5fa;
}

.refresh-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.refresh-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.page-shell {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
  padding: 38px 0 56px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.75fr);
  gap: 20px;
}

.premium-card, .live-meta-card, .metric-card, .chart-card, .detail-card, .method-card {
  border: 1px solid var(--border);
  background: linear-gradient(150deg, rgba(19, 36, 59, 0.96), rgba(11, 23, 40, 0.98));
  box-shadow: var(--shadow);
}

.premium-card {
  min-height: 340px;
  padding: clamp(24px, 4vw, 42px);
  border-radius: var(--radius-lg);
}

.card-heading-row, .section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.premium-card h2, .chart-card h2, .detail-card h2 {
  margin: 4px 0 0;
  font-size: clamp(22px, 3vw, 30px);
}

.direction-badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 14px;
  font-weight: 750;
}

.direction-discount {
  color: var(--discount);
  background: rgba(52, 211, 153, 0.08);
}

.direction-premium {
  color: var(--premium);
  background: rgba(251, 146, 60, 0.08);
}

.direction-neutral {
  color: var(--text-muted);
  background: rgba(168, 183, 203, 0.06);
}

.premium-value {
  margin: 22px 0 0;
  font-size: clamp(58px, 10vw, 104px);
  font-weight: 800;
  letter-spacing: -0.065em;
  line-height: 1;
}

.premium-value.discount { color: var(--discount); }
.premium-value.premium { color: var(--premium); }

.premium-explanation {
  margin: 14px 0 28px;
  color: var(--text-muted);
  font-size: 15px;
}

.spread-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(7, 17, 31, 0.5);
}

.spread-grid div { padding: 16px 18px; }
.spread-grid div + div { border-left: 1px solid var(--border); }

.spread-grid span, .metric-card p {
  display: block;
  margin: 0 0 5px;
  color: var(--text-muted);
  font-size: 13px;
}

.spread-grid strong { font-size: 20px; }

.live-meta-card {
  padding: 26px;
  border-radius: var(--radius-lg);
}

.meta-list { margin: 18px 0 0; }

.meta-list div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 0;
  border-bottom: 1px solid rgba(38, 58, 86, 0.7);
}

.meta-list dt { color: var(--text-muted); }

.meta-list dd {
  margin: 0;
  text-align: right;
  font-weight: 650;
}

.estimate-notice {
  margin: 20px 0 0;
  padding: 14px 16px;
  border-left: 3px solid var(--warning);
  border-radius: 0 10px 10px 0;
  background: rgba(251, 191, 36, 0.07);
  color: #f8e9b4;
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.compare-hero {
  padding: clamp(24px, 4vw, 38px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(19, 36, 59, 0.97), rgba(11, 23, 40, 0.98));
  box-shadow: var(--shadow);
}

.compare-hero h2 {
  margin: 5px 0 10px;
  font-size: clamp(25px, 3.6vw, 38px);
}

.compare-hero p:last-child {
  max-width: 900px;
  margin: 0;
  color: var(--text-muted);
}

.comparison-note {
  margin: 18px 4px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.source-cell { color: var(--text-muted); }

.history-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(19, 36, 59, 0.97), rgba(11, 23, 40, 0.98));
  box-shadow: var(--shadow);
}

.history-controls h2 {
  margin: 4px 0 6px;
  font-size: clamp(24px, 3vw, 34px);
}

.history-controls p:last-child {
  margin: 0;
  color: var(--text-muted);
}

.date-control {
  display: flex;
  align-items: end;
  gap: 12px;
}

.date-control label {
  align-self: center;
  color: var(--text-muted);
  font-size: 14px;
}

.date-control input {
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  color-scheme: dark;
}

#history-chart {
  display: block;
  width: 100%;
  min-height: 300px;
  overflow: visible;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.pagination-top { margin-top: 0; }

.page-button {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.page-button:disabled {
  cursor: default;
  opacity: 0.4;
}

.metric-card {
  min-height: 150px;
  padding: 22px;
  border-radius: var(--radius-md);
}

.metric-value {
  display: block;
  margin-top: 10px;
  font-size: clamp(28px, 3.4vw, 40px);
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.metric-subvalue {
  display: block;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.positive { color: var(--premium); }
.negative { color: var(--discount); }

.warning-panel {
  margin-top: 20px;
  padding: 20px 22px;
  border: 1px solid rgba(251, 191, 36, 0.55);
  border-radius: var(--radius-md);
  background: rgba(120, 74, 10, 0.18);
}

.warning-panel h2 {
  margin: 0 0 8px;
  color: #fde68a;
  font-size: 18px;
}

.warning-panel ul {
  margin: 0;
  padding-left: 20px;
  color: #f8e9b4;
}

.chart-card, .detail-card, .method-card {
  margin-top: 20px;
  padding: 26px;
  border-radius: var(--radius-lg);
}

.range-label {
  color: var(--text-muted);
  font-size: 14px;
}

.chart-wrap {
  position: relative;
  min-height: 320px;
  margin-top: 18px;
}

#premium-chart {
  display: block;
  width: 100%;
  min-height: 300px;
  overflow: visible;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--text-muted);
}

.chart-grid-line {
  stroke: rgba(168, 183, 203, 0.16);
  stroke-width: 1;
}

.chart-zero-line {
  stroke: rgba(251, 191, 36, 0.55);
  stroke-dasharray: 6 6;
  stroke-width: 1.5;
}

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
  filter: drop-shadow(0 0 7px rgba(96, 165, 250, 0.42));
}

.chart-area { fill: url("#chart-gradient"); }

.chart-label {
  fill: var(--text-muted);
  font-size: 13px;
}

.chart-point {
  fill: var(--bg-elevated);
  stroke: var(--primary);
  stroke-width: 3;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid rgba(38, 58, 86, 0.72);
  text-align: right;
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

th {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

td { font-size: 14px; }

td a {
  color: var(--primary);
  text-decoration-color: rgba(96, 165, 250, 0.45);
  text-underline-offset: 3px;
}

.empty-cell {
  padding: 36px;
  color: var(--text-muted);
  text-align: center !important;
}

.method-card { padding: 0; }

.method-card summary {
  min-height: 54px;
  padding: 17px 22px;
  cursor: pointer;
  font-weight: 750;
}

.method-content {
  padding: 0 22px 20px;
  color: var(--text-muted);
}

.method-content p { color: var(--text); }
.method-content li + li { margin-top: 8px; }

.footer {
  padding: 24px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

.tabular { font-variant-numeric: tabular-nums; }

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

@media (max-width: 960px) {
  .topbar {
    align-items: flex-start;
    padding: 16px 24px;
  }
  .eyebrow { display: none; }
  .hero-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-controls { align-items: stretch; flex-direction: column; }
  .date-control { align-items: stretch; }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    flex-direction: column;
    gap: 14px;
    padding: 14px 16px;
  }
  .topbar-actions { width: 100%; }
  .status-pill, .refresh-button, .nav-button { flex: 1; }
  .brand-mark {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }
  .page-shell {
    width: min(100% - 24px, 1240px);
    padding-top: 18px;
  }
  .premium-card, .live-meta-card, .chart-card, .detail-card {
    padding: 20px;
    border-radius: 18px;
  }
  .premium-card { min-height: 0; }
  .premium-value {
    margin-top: 18px;
    font-size: clamp(54px, 19vw, 76px);
  }
  .spread-grid { grid-template-columns: 1fr; }
  .spread-grid div + div {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
  .metric-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .metric-card {
    min-height: 130px;
    padding: 18px;
  }
  .metric-value { font-size: 27px; }
  .chart-wrap { min-height: 260px; }
  #premium-chart { min-height: 240px; }
  .card-heading-row { flex-direction: column; }
  .direction-badge { align-self: flex-start; }
}

@media (max-width: 420px) {
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .status-pill, .refresh-button, .nav-button { width: 100%; }
  .metric-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .date-control { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
