:root {
  --bg-primary: #080c14;
  --bg-secondary: #0e1420;
  --bg-card: #141c2b;
  --bg-card-hover: #1a2438;
  --border: #334155;
  --border-subtle: #2a3a50;
  --text-primary: #f8fafc;
  --text-secondary: #e2e8f0;
  --text-muted: #c0cad8;
  --accent: #10b981;
  --accent-light: #6ee7b7;
  --accent-glow: rgba(16, 185, 129, 0.18);
  --accent-dim: #064e3b;
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.1);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.1);
  --blue: #3b82f6;
  --yellow: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

html { font-size: 19px; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo svg { width: 32px; height: 32px; }

.logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.logo span {
  color: var(--accent);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-meta .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.header-meta .version {
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.pubhub-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.pubhub-link:hover { color: var(--accent); }

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Stats row */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.stat-card .value.accent { color: var(--accent); }

/* Navigation */
nav {
  display: flex;
  gap: 4px;
  margin-bottom: 28px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
}

nav button {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

nav button:hover { color: var(--text-primary); background: var(--bg-card); }
nav button.active { background: var(--accent-dim); color: var(--accent-light); }

/* Sections */
section { display: none; }
section.active { display: block; }

/* Currency grid */
.currency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.currency-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
}

.currency-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.currency-card .left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.currency-card .flag {
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.chart-header h2 .flag {
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 2px;
}

.currency-card .code {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-light);
  background: var(--accent-dim);
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 48px;
  text-align: center;
}

.currency-card .name {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.currency-card .rate {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: right;
}

.currency-card .rate small {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Sparkline canvas inline */
.currency-card .spark {
  width: 80px;
  height: 32px;
  margin-left: 12px;
}

/* Chart section */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

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

.chart-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.chart-header h2 span { color: var(--accent); }

.period-btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.period-btns button {
  padding: 6px 12px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.15s;
}

.period-btns button:hover { border-color: var(--border); color: var(--text-primary); }
.period-btns button.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.period-select {
  padding: 6px 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}
.period-select.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.chart-wrap {
  position: relative;
  height: 320px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: 16px;
  transition: all 0.15s;
}

.back-btn:hover { border-color: var(--border); color: var(--text-primary); }

/* Calculator */
.calc-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 680px;
  margin: 0 auto;
}

.calc-container h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
}

.calc-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}

.calc-field {
  flex: 1;
}

.calc-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.calc-field label .flag {
  border-radius: 2px;
  vertical-align: middle;
}

.calc-field input, .calc-field select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.15s;
}

.calc-field input:focus, .calc-field select:focus {
  border-color: var(--accent);
}

.calc-field select { cursor: pointer; }
.calc-field select option { background: var(--bg-secondary); }

.swap-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.swap-btn:hover { background: var(--accent); color: #fff; }

.calc-result {
  text-align: center;
  padding: 20px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  margin-top: 8px;
}

.calc-result .amount {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent-light);
  letter-spacing: -0.02em;
}

.calc-result .rate-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Search */
.search-box {
  margin-bottom: 20px;
}

.search-box input {
  width: 100%;
  padding: 12px 16px;
  padding-left: 40px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
}

.search-box input:focus { border-color: var(--accent); }

/* Loading */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* Footer */
footer {
  text-align: center;
  padding: 32px 0;
  margin-top: 48px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.75rem;
}

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

/* Responsive */
@media (max-width: 640px) {
  .app { padding: 0 16px; }
  header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .currency-grid { grid-template-columns: 1fr; }
  .calc-row { flex-direction: column; }
  .swap-btn { align-self: center; }
  .chart-header { flex-direction: column; }
  .currency-card .spark { display: none; }
}
