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

:root {
  --bg:         #0a0a12;
  --surface:    #111120;
  --surface-2:  #18182a;
  --gold:       #d4af37;
  --gold-light: #f0d060;
  --gold-dim:   #7a6318;
  --text:       #f0ede0;
  --text-2:     #8a806a;
  --up:         #3ecf8e;
  --down:       #e05252;
  --border:     rgba(212,175,55,0.15);
  --radius:     16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-left { display: flex; align-items: center; gap: 10px; }

.logo { width: 28px; height: 28px; flex-shrink: 0; }

h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-2);
  background: rgba(255,255,255,0.05);
  padding: 4px 10px;
  border-radius: 20px;
}

.pulse {
  width: 7px;
  height: 7px;
  background: var(--up);
  border-radius: 50%;
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.75); }
}

/* ── Main ── */
main {
  padding: 14px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

/* ── Price Cards ── */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  transition: border-color 0.3s;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.card:hover::before { opacity: 1; }

.card-label { margin-bottom: 10px; }

.card-name {
  font-size: 12px;
  color: var(--text-2);
  display: block;
  margin-bottom: 2px;
}

.card-tag {
  font-size: 10px;
  color: var(--gold-dim);
  letter-spacing: 0.5px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.card-price-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.card-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.card-price.flash { animation: price-flash 0.6s ease; }

@keyframes price-flash {
  0%   { color: var(--text); }
  40%  { color: var(--gold-light); }
  100% { color: var(--text); }
}

.card-unit {
  font-size: 10px;
  color: var(--text-2);
  flex-shrink: 0;
}

.card-change { min-height: 18px; }

.change-text {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.change-text.up   { color: var(--up); }
.change-text.down { color: var(--down); }

/* ── Meta Bar ── */
.meta-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  gap: 0;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.meta-label { font-size: 10px; color: var(--text-2); }

.meta-value {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 12px;
  flex-shrink: 0;
}

.refresh-btn {
  background: rgba(212,175,55,0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--gold);
  padding: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
  margin-left: 8px;
}
.refresh-btn:hover  { background: rgba(212,175,55,0.18); }
.refresh-btn:active { transform: scale(0.92); }
.refresh-btn svg    { width: 15px; height: 15px; }
.refresh-btn.spinning svg { animation: spin 0.7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chart ── */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 260px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chart-tabs, .time-tabs { display: flex; gap: 2px; }

.chart-tab, .time-tab {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.chart-tab.active, .time-tab.active {
  background: rgba(212,175,55,0.12);
  color: var(--gold);
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
}

#tv-chart {
  position: absolute;
  inset: 0;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
  transition: opacity 0.3s;
}

.chart-empty.hidden { opacity: 0; pointer-events: none; }

.chart-empty-icon { font-size: 36px; opacity: 0.3; }

.chart-empty p {
  color: var(--text-2);
  font-size: 14px;
}

.chart-empty .sub {
  font-size: 12px;
  opacity: 0.6;
}

/* ── Indicator Bar ── */
.ind-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ma-toggles, .sub-ind-tabs { display: flex; gap: 4px; }

.ma-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: 'SF Mono', 'Fira Code', monospace;
  transition: all 0.2s;
  color: var(--text-2);
}
.ma-btn[data-period="5"].on  { color: #f5a623; border-color: rgba(245,166,35,0.35); }
.ma-btn[data-period="20"].on { color: #7b9ef0; border-color: rgba(123,158,240,0.35); }
.ma-btn:not(.on)             { opacity: 0.35; }

.sub-ind-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  color: var(--text-2);
  font-family: inherit;
  transition: all 0.2s;
}
.sub-ind-btn.active {
  background: rgba(212,175,55,0.1);
  color: var(--gold);
  border-color: rgba(212,175,55,0.25);
}

/* ── Sub-chart ── */
.sub-chart-wrap {
  position: relative;
  height: 120px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}
.sub-chart-wrap.hidden { display: none; }

#tv-sub-chart {
  position: absolute;
  inset: 0;
}

.sub-chart-label {
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 10px;
  color: var(--text-2);
  opacity: 0.6;
  pointer-events: none;
  z-index: 2;
  font-family: 'SF Mono', monospace;
}

/* ── Bottom note ── */
.data-note {
  text-align: center;
  font-size: 10px;
  color: var(--text-2);
  opacity: 0.5;
  padding: 8px 0 12px;
  flex-shrink: 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1e1014;
  border: 1px solid var(--down);
  color: var(--down);
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 999;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Skeleton loader ── */
.card-price.loading { opacity: 0.4; animation: blink 1.2s ease infinite; }

@keyframes blink {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.2; }
}

/* ── Install banner ── */
.install-banner {
  margin: 0 14px 12px;
  background: rgba(212,175,55,0.08);
  border: 1px solid rgba(212,175,55,0.25);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--gold);
}

.install-banner.hidden { display: none; }

.install-btn {
  background: var(--gold);
  color: #0a0a12;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.install-dismiss {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
  flex-shrink: 0;
}
