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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #484f58;
  --up: #f23645;
  --down: #00c853;
  --accent: #58a6ff;
  --card-radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
  --skeleton: #21262d;
  --skeleton-shine: #2d333b;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface2: #e8ecef;
    --text: #1f2328;
    --text2: #656d76;
    --text3: #afb8c1;
    --up: #cf222e;
    --down: #1a7f37;
    --accent: #0969da;
    --shadow: 0 1px 2px rgba(0,0,0,0.08);
    --skeleton: #e8ecef;
    --skeleton-shine: #f0f2f5;
  }
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #484f58;
  --up: #f23645;
  --down: #00c853;
  --accent: #58a6ff;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
  --skeleton: #21262d;
  --skeleton-shine: #2d333b;
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface2: #e8ecef;
  --text: #1f2328;
  --text2: #656d76;
  --text3: #afb8c1;
  --up: #cf222e;
  --down: #1a7f37;
  --accent: #0969da;
  --shadow: 0 1px 2px rgba(0,0,0,0.08);
  --skeleton: #e8ecef;
  --skeleton-shine: #f0f2f5;
}

html { font-size: 16px; }

body {
  font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Header ── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

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

.header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.freshness {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text2);
}

.freshness-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transition: background 0.3s;
}

.freshness-dot.green { background: var(--down); }
.freshness-dot.yellow { background: #f0d43a; }
.freshness-dot.red { background: var(--up); }

.update-time {
  font-size: 0.72rem;
  color: var(--text2);
  font-family: "JetBrains Mono", monospace;
  white-space: nowrap;
}

.btn-refresh {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-refresh:hover { color: var(--text); background: var(--surface2); }
.btn-refresh:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-refresh.spinning { animation: spin 0.8s linear infinite; }

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

.theme-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--surface2);
}

.theme-btn {
  padding: 3px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.5;
  transition: all 0.2s;
  white-space: nowrap;
}

.theme-btn:hover { color: var(--text); }

.theme-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

/* ── Card ── */

.cards {
  margin-bottom: 14px;
}

.card {
  background: var(--surface);
  border-radius: var(--card-radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  transition: background 0.3s;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1px;
}

.card-title-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.card-symbol {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text2);
}

.card-name {
  font-size: 0.72rem;
  color: var(--text2);
}

.card-change {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  font-weight: 600;
}

.card-change.up { color: var(--up); }
.card-change.down { color: var(--down); }

.card-body {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.card-price {
  font-family: "JetBrains Mono", monospace;
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.2;
  transition: color 0.3s;
}

.card-stats {
  display: flex;
  gap: 3px 12px;
  flex-wrap: wrap;
  flex: 1;
}

.stat {
  display: flex;
  gap: 2px;
  font-size: 0.75rem;
  line-height: 1.6;
  align-items: center;
}

.stat-label { color: var(--text2); }

.stat-value {
  font-family: "JetBrains Mono", monospace;
  color: var(--text);
  font-weight: 500;
}

/* ── Risk Banner ── */

.risk-banner {
  display: none;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--card-radius);
  border-left: 4px solid var(--text3);
  box-shadow: var(--shadow);
  transition: background 0.3s, border-color 0.3s;
}

.risk-icon {
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
}

.risk-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.risk-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.risk-label {
  font-size: 0.78rem;
  color: var(--text2);
}

.risk-level {
  font-size: 0.95rem;
  font-weight: 700;
  transition: color 0.3s;
}

.risk-score {
  font-size: 0.7rem;
  color: var(--text3);
  font-family: "JetBrains Mono", monospace;
  margin-left: auto;
}

.risk-details {
  font-size: 0.72rem;
  color: var(--text2);
}

/* ── Chart ── */

.chart-section {
  background: var(--surface);
  border-radius: var(--card-radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: background 0.3s;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 10px;
  min-height: 20px;
}

.chart-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.indicator-toggles {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.indicator-toggle {
  padding: 2px 8px;
  border: 1px solid var(--text3);
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1.6;
  transition: all 0.2s;
}

.indicator-toggle:hover { border-color: var(--accent); color: var(--text); }

.indicator-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chart-title {
  font-size: 0.88rem;
  font-weight: 600;
}

.ma-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.7rem;
}

.ma-legend-item {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text2);
  font-family: "JetBrains Mono", monospace;
}

.ma-legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-container {
  width: 100%;
  height: 760px;
}

/* ── Skeleton ── */

.skeleton-pulse {
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-shine) 50%, var(--skeleton) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-chart {
  width: 100%;
  height: 720px;
  border-radius: 6px;
  margin-top: -732px;
  position: relative;
  z-index: 1;
  transition: opacity 0.3s;
}

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

.skeleton-legend {
  display: flex;
  gap: 10px;
  height: 14px;
}

.skeleton-legend.hidden { display: none; }

.skeleton-legend span {
  width: 80px;
  height: 10px;
  border-radius: 3px;
}

/* ── Footer ── */

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text3);
  padding: 6px 0 20px;
}

.footer-hint {
  font-size: 0.68rem;
  font-family: "JetBrains Mono", monospace;
  color: var(--text3);
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .app { padding: 10px; }

  .header { flex-wrap: wrap; gap: 8px; }
  .header-left { order: 0; }
  .header-right { order: 1; width: 100%; justify-content: flex-end; }

  .card { padding: 12px 14px; }
  .card-body { gap: 10px; }
  .card-price { font-size: 1.7rem; }

  .chart-container { height: 580px; }
  .skeleton-chart { height: 540px; margin-top: -552px; }

  .chart-header { flex-direction: column; align-items: flex-start; }

  .footer { flex-direction: column; align-items: center; text-align: center; }
}

@media (max-width: 480px) {
  .chart-container { height: 500px; }
  .skeleton-chart { height: 460px; margin-top: -472px; }

  .card-stats { gap: 2px 8px; }
  .stat { font-size: 0.7rem; }
  .card-price { font-size: 1.5rem; }
}
