/* === Reset & Base === */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-card-hover: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.1);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.1);
  --blue: #58a6ff;
  --blue-bg: rgba(88, 166, 255, 0.1);
  --accent: #1f6feb;
  --gold: #d29922;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

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

/* === Header === */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
}

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

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

.update-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.market-state {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 10px;
}

.market-state.open {
  background: var(--green-bg);
  color: var(--green);
}

.market-state.closed {
  background: var(--red-bg);
  color: var(--red);
}

.market-state.pre, .market-state.post {
  background: var(--blue-bg);
  color: var(--blue);
}

.last-update {
  font-size: 11px;
  color: var(--text-muted);
}

.refresh-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.refresh-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.refresh-btn.spinning svg {
  animation: spin 1s linear infinite;
}

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

/* === Main === */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.section {
  margin-bottom: 40px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.flag {
  font-size: 20px;
}

.section-tag {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

/* === Cards === */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

.card.up { border-top: 3px solid var(--green); }
.card.down { border-top: 3px solid var(--red); }

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

.card-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.card-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.03em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.card-price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.price {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

.currency {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.card-change {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.change-value, .change-pct {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card.up .change-value,
.card.up .change-pct { color: var(--green); }

.card.down .change-value,
.card.down .change-pct { color: var(--red); }

/* Sparkline */
.sparkline {
  width: 100%;
  height: 60px;
  display: block;
  margin-bottom: 12px;
  border-radius: 6px;
}

/* Card meta */
.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.range-info, .vol-info {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}

/* === Loading === */
.card.loading .price,
.card.loading .change-value,
.card.loading .change-pct {
  color: var(--text-muted);
}

.card.loading::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Error */
.card.error {
  opacity: 0.6;
}

.card .error-msg {
  font-size: 12px;
  color: var(--red);
  margin-top: 8px;
}

/* === Footer === */
footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer-brand {
  margin-top: 6px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .cards {
    grid-template-columns: 1fr;
  }
  .price {
    font-size: 26px;
  }
  main {
    padding: 20px 16px 40px;
  }
}

@media (max-width: 400px) {
  .card {
    padding: 16px;
  }
  .price {
    font-size: 24px;
  }
}

/* === Data Freshness === */
.data-freshness {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.data-freshness.stale {
  color: var(--gold);
}

.card.stale-data {
  border-color: var(--gold);
}

/* Stale Banner */
.stale-banner {
  background: rgba(210, 153, 34, 0.15);
  color: var(--gold);
  text-align: center;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 1px solid rgba(210, 153, 34, 0.3);
}

/* === Animations === */
.card {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Price flash */
.price-flash-up {
  animation: flashGreen 0.6s ease-out;
}

.price-flash-down {
  animation: flashRed 0.6s ease-out;
}

@keyframes flashGreen {
  0%, 100% { color: inherit; }
  25% { color: var(--green); text-shadow: 0 0 8px rgba(63, 185, 80, 0.3); }
}

@keyframes flashRed {
  0%, 100% { color: inherit; }
  25% { color: var(--red); text-shadow: 0 0 8px rgba(248, 81, 73, 0.3); }
}
