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

:root {
  --bg-primary: #08080c;
  --bg-card: rgba(255, 255, 255, 0.025);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text-primary: #f5f5f7;
  --text-secondary: rgba(245, 245, 247, 0.45);
  --text-muted: rgba(245, 245, 247, 0.25);
  --accent: #d4914a;
  --accent-glow: rgba(212, 145, 74, 0.15);
  --success: #34c759;
  --danger: #ff453a;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  --radius-lg: 28px;
  --radius-md: 14px;
  --radius-sm: 8px;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body::after {
  content: '';
  display: block;
  height: 48px;
}

/* ─── Background Ambience ─── */
.bg-orb {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle at center, var(--accent-glow), transparent 70%);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: orbPulse 8s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes orbPulse {
  0%   { transform: translate(-50%, -50%) scale(1);   opacity: 0.6; }
  100% { transform: translate(-50%, -55%) scale(1.2); opacity: 0.3; }
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* ─── Container ─── */
.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 24px 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ─── Card ─── */
.card {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px 28px 24px;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  animation: cardEnter 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── Card Header ─── */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}

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

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.brand-name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.badge {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 4px 10px;
}

/* ─── Balance Section ─── */
.balance-section {
  text-align: center;
  margin-bottom: 32px;
  position: relative;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.balance-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.balance-skeleton .shimmer {
  width: 180px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 25%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0.03) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

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

.balance-section.loading .balance-skeleton {
  visibility: visible;
  opacity: 1;
}

.balance-section.loading .balance-value,
.balance-section.loading .balance-label {
  visibility: hidden;
  opacity: 0;
}

.balance-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.balance-value.updating {
  transform: translateY(-4px);
  opacity: 0;
}

.currency-symbol {
  font-size: 28px;
  font-weight: 300;
  color: var(--text-secondary);
  letter-spacing: -0.02em;
}

.amount {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 300;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1;
  transition: color 0.5s ease;
}

.amount.changed-up {
  color: var(--success);
}

.amount.changed-down {
  color: var(--danger);
}

.balance-label {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 10px;
  letter-spacing: 0.02em;
  transition: opacity 0.3s ease;
}

/* ─── Footer ─── */
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-refresh:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.btn-refresh:active {
  transform: scale(0.96);
  transition-duration: 0.1s;
}

.btn-refresh:focus-visible {
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px rgba(212, 145, 74, 0.2);
}

.btn-refresh.loading {
  pointer-events: none;
  opacity: 0.6;
}

.btn-refresh.loading .btn-icon {
  animation: spin 0.8s linear infinite;
}

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

.btn-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-label {
  letter-spacing: 0.01em;
}

.timestamp {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  transition: opacity 0.3s ease;
}

/* ─── History Card ─── */
.history-card {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px 24px 20px;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.04) inset;
  animation: cardEnter 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 0.15s;
}

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

.history-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.history-range {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 200px;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius-sm);
}

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

.chart-empty.show {
  opacity: 1;
}

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

.chart-empty-text {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chart-empty-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
}

.chart-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chart-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 2s ease-in-out infinite;
}

.chart-status-dot.inactive {
  background: var(--text-muted);
  animation: none;
}

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

@media (max-width: 480px) {
  .history-card {
    padding: 24px 18px 18px;
    border-radius: 24px;
  }
  .chart-wrap {
    height: 170px;
  }
}

/* ─── Toast ─── */
.toast {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  color: var(--danger);
  border-color: rgba(255, 69, 58, 0.2);
  background: rgba(255, 69, 58, 0.06);
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
  .card {
    padding: 28px 20px 20px;
    border-radius: 24px;
  }

  .card-header {
    margin-bottom: 32px;
  }

  .amount {
    font-size: 48px;
  }

  .currency-symbol {
    font-size: 24px;
  }

  .btn-refresh {
    padding: 9px 16px;
    font-size: 13px;
  }
}

@media (min-width: 768px) {
  .amount {
    font-size: 64px;
  }

  .card {
    padding: 36px 32px 28px;
  }
}

/* ─── Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
  .bg-orb,
  .card,
  .balance-value,
  .shimmer {
    animation: none !important;
    transition: none !important;
  }
}
