:root {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --full: #22c55e;
  --high: #84cc16;
  --mid: #eab308;
  --low: #ef4444;
  --fill: var(--mid);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.card {
  width: min(420px, 92vw);
  padding: clamp(1rem, 5vw, 2rem);
  border-radius: 1.25rem;
  background: var(--card);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
  text-align: center;
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.connection {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
}

.connection.live {
  background: var(--full);
  box-shadow: 0 0 8px var(--full);
}

.connection.down {
  background: var(--low);
}

.battery {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
}

.battery-body {
  position: relative;
  width: 100%;
  max-width: 240px;
  aspect-ratio: 2 / 1;
  border: 6px solid var(--text);
  border-radius: 18px;
  padding: 6px;
  overflow: hidden;
}

.battery-cap {
  flex: none;
  width: 14px;
  height: 44px;
  margin-left: 4px;
  border-radius: 0 6px 6px 0;
  background: var(--text);
}

.battery-fill {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: var(--fill);
  transition:
    width 0.8s ease,
    background-color 0.8s ease;
}

.battery[data-status="charging"] .battery-fill {
  background-image: linear-gradient(
    110deg,
    transparent 30%,
    rgb(255 255 255 / 0.25) 50%,
    transparent 70%
  );
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
}

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

.battery-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 10vw, 2.6rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 6px rgb(0 0 0 / 0.6);
}

.battery-label small {
  font-size: 1.2rem;
}

.status {
  margin: 0 0 0.3rem;
  font-size: 1.3rem;
  font-weight: 600;
}

.status.full {
  color: var(--full);
}

.power,
.updated {
  margin: 0.2rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.error {
  margin-top: 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  background: rgb(239 68 68 / 0.15);
  color: #fca5a5;
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  .battery-fill {
    transition: none;
    animation: none !important;
  }
}
