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

:root {
  --bg:         #0a0a0a;
  --card-bg:    #111111;
  --card-border:#1e1e1e;
  --text-primary:  #f1f5f9;
  --text-secondary:#64748b;
  --positive:   #22c55e;
  --negative:   #ef4444;
  --accent:     #6366f1;
  --header-h:   64px;
  --footer-h:   52px;
  --radius:     12px;
  --gap:        16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 24px;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
}

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

.header-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.live-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s ease infinite;
}

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

.last-update-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#last-update-time {
  color: var(--text-primary);
  font-weight: 500;
}

/* ===== Main / Grid ===== */
.main {
  min-height: calc(100vh - var(--header-h) - var(--footer-h));
  padding: 24px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 16px;
  }
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
}

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

.card-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.card-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.card-currency {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.7;
  margin-left: auto;
}

.card-price {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.1;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.card-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  width: fit-content;
}

.card-change.positive {
  color: var(--positive);
  background: rgba(34, 197, 94, 0.1);
}

.card-change.negative {
  color: var(--negative);
  background: rgba(239, 68, 68, 0.1);
}

.card-change.neutral {
  color: var(--text-secondary);
  background: rgba(100, 116, 139, 0.1);
}

/* ===== Sparkline ===== */
.sparkline-wrap {
  margin-top: 8px;
  height: 44px;
}

.sparkline-wrap svg {
  width: 100%;
  height: 44px;
  overflow: visible;
}

.spark-line {
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark-line.positive { stroke: var(--positive); }
.spark-line.negative { stroke: var(--negative); }
.spark-line.neutral  { stroke: var(--text-secondary); }

.spark-fill {
  opacity: 0.08;
}

.spark-fill.positive { fill: var(--positive); }
.spark-fill.negative { fill: var(--negative); }
.spark-fill.neutral  { fill: var(--text-secondary); }

/* ===== Skeleton ===== */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}

.skeleton {
  pointer-events: none;
}

.sk-line {
  border-radius: 6px;
  background: linear-gradient(90deg, #1a1a1a 25%, #252525 50%, #1a1a1a 75%);
  background-size: 400px 100%;
  animation: shimmer 1.4s ease infinite;
}

.sk-icon  { width: 32px; height: 24px; margin-bottom: 4px; }
.sk-name  { width: 60%;  height: 12px; margin-bottom: 8px; }
.sk-price { width: 75%;  height: 32px; margin-bottom: 8px; }
.sk-change{ width: 45%;  height: 20px; }

/* ===== Error Banner ===== */
.error-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  color: #fca5a5;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.retry-btn {
  margin-left: auto;
  padding: 5px 14px;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.retry-btn:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* ===== Footer ===== */
.footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-top: 1px solid var(--card-border);
  background: rgba(10, 10, 10, 0.8);
  font-size: 0.8rem;
  color: var(--text-secondary);
  gap: 12px;
  flex-wrap: wrap;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

#countdown {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.footer-source {
  color: var(--text-primary);
  opacity: 0.6;
}

/* ===== Update Flash Animation ===== */
@keyframes flash-update {
  0%   { border-color: var(--accent); box-shadow: 0 0 12px rgba(99,102,241,0.3); }
  100% { border-color: var(--card-border); box-shadow: none; }
}

.card.updated {
  animation: flash-update 0.8s ease forwards;
}

/* ===== Positive/Negative card accent ===== */
.card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
  opacity: 0;
  transition: opacity 0.3s;
}

.card.pos::after { background: var(--positive); opacity: 1; }
.card.neg::after { background: var(--negative); opacity: 1; }

/* Section titles */
.section-title {
  color: #e2e8f0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 1.5rem 0 0.5rem 0.25rem;
  margin: 0;
}
