:root {
  --cream: #fff0a6;
  --peach: #ff9d5c;
  --coral: #ff3d5a;
  --teal: #00c7b6;
  --mint: #7ff8db;
  --navy: #172235;
  --deep: #0f172a;
  --shadow: rgba(15, 23, 42, 0.24);
  --glass: rgba(255, 255, 255, 0.84);
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--deep);
  background: radial-gradient(circle at top, #ffe066, #ffd4f0 42%, #d7fff7 72%, #bfe9ff);
  position: relative;
  overflow-x: hidden;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(0, 199, 182, 0.25) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  z-index: 0;
}

.background-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(16px);
  z-index: 0;
  opacity: 0.45;
}

.orb-one {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(255, 19, 88, 0.9), rgba(255, 19, 88, 0));
  top: -120px;
  right: -80px;
}

.orb-two {
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(0, 227, 198, 0.85), rgba(0, 227, 198, 0));
  bottom: -140px;
  left: -60px;
}

.orb-three {
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(255, 111, 0, 0.85), rgba(255, 111, 0, 0));
  top: 40%;
  left: 70%;
}

.hero {
  display: flex;
  align-items: center;
  padding: 48px 8vw 24px;
  position: relative;
  z-index: 1;
  gap: 32px;
  flex-wrap: wrap;
}

.error-banner {
  margin: 0 8vw 20px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #ffe4e6;
  color: #b91c1c;
  border: 1px solid rgba(185, 28, 28, 0.2);
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(185, 28, 28, 0.15);
  position: relative;
  z-index: 1;
}

.error-banner[data-kind="warning"] {
  background: #fef3c7;
  color: #92400e;
  border-color: rgba(146, 64, 14, 0.2);
  box-shadow: 0 10px 24px rgba(146, 64, 14, 0.12);
}

h1 {
  font-family: "Monoton", cursive;
  font-size: clamp(2.4rem, 5vw, 4rem);
  margin: 12px 0 8px;
  color: var(--navy);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
  padding: 0 8vw 60px;
  position: relative;
  z-index: 1;
}

.card {
  min-width: 0;
  background: var(--glass);
  border-radius: 24px;
  padding: 22px 24px;
  box-shadow: 0 14px 30px var(--shadow);
  backdrop-filter: blur(8px);
}

.card-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #64748b;
  margin: 0 0 8px;
}

.current-reading {
  grid-column: span 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.reading-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.reading {
  font-size: clamp(2.6rem, 4vw, 3.4rem);
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
}

.unit {
  font-size: 1rem;
  color: #475569;
}

.trend-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

.reading-time {
  margin: 2px 0 0;
  color: #64748b;
  font-size: 0.85rem;
}

.trend-arrow {
  font-size: 1.6rem;
}

.status-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--deep);
  font-weight: 600;
  box-shadow: none;
}

.chart-card {
  grid-column: span 8;
}

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

.chart-wrap canvas {
  display: block;
  max-width: 100%;
  width: 100% !important;
  height: 100% !important;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.chart-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.time-range-selector {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
}

.time-range-button {
  min-width: 44px;
  min-height: 34px;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #475569;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.time-range-button:hover {
  background: rgba(23, 34, 53, 0.08);
}

.time-range-button:active {
  transform: translateY(1px);
}

.time-range-button.active {
  background: var(--navy);
  color: white;
}

.time-range-button:focus-visible {
  outline: 3px solid rgba(0, 199, 182, 0.45);
  outline-offset: 2px;
}

.legend {
  display: flex;
  gap: 12px;
  font-size: 0.85rem;
  color: #64748b;
  align-items: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-range {
  background: rgba(0, 199, 182, 0.8);
}

.dot-line {
  background: var(--coral);
}

.averages-card {
  grid-column: span 12;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.period-stat {
  display: grid;
  gap: 7px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 18px;
  padding: 16px;
}

.period-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #64748b;
}

.period-value {
  font-family: "Fredoka", sans-serif;
  font-size: 1.45rem;
  font-weight: 600;
}

.period-detail {
  color: #64748b;
  font-size: 0.85rem;
}

.period-detail strong {
  color: var(--deep);
}

.stats-card {
  grid-column: span 7;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stat {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  padding: 12px 14px;
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #64748b;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 600;
  display: block;
  margin-top: 6px;
}

.list-card {
  grid-column: span 5;
}

.recent-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.recent-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.6);
  padding: 10px 12px;
  border-radius: 14px;
  font-weight: 500;
}

.recent-list .empty-state {
  color: #64748b;
  justify-content: center;
}

.footer {
  text-align: center;
  padding: 24px;
  font-size: 0.9rem;
  color: #475569;
  position: relative;
  z-index: 1;
}

.stagger {
  animation: rise 0.6s ease both;
}

.stagger:nth-of-type(1) {
  animation-delay: 0.05s;
}

.stagger:nth-of-type(2) {
  animation-delay: 0.1s;
}

.stagger:nth-of-type(3) {
  animation-delay: 0.15s;
}

.stagger:nth-of-type(4) {
  animation-delay: 0.2s;
}

.stagger:nth-of-type(5) {
  animation-delay: 0.25s;
}

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

@media (max-width: 960px) {
  .current-reading {
    grid-column: span 12;
  }

  .chart-card {
    grid-column: span 12;
  }

  .stats-card,
  .list-card {
    grid-column: span 6;
  }

  .period-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .hero {
    width: 100%;
    padding: 28px max(16px, 5vw) 16px;
    gap: 0;
  }

  .hero > div {
    width: 100%;
    min-width: 0;
  }

  h1 {
    max-width: 100%;
    margin: 8px 0 4px;
    font-size: clamp(1.9rem, 9vw, 2.8rem);
    line-height: 1.12;
    overflow-wrap: break-word;
  }

  .error-banner {
    margin: 0 max(16px, 5vw) 16px;
  }

  .grid {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 0 max(16px, 5vw) 42px;
  }

  .card {
    width: 100%;
    max-width: 100%;
    padding: 18px;
    border-radius: 20px;
  }

  .current-reading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .reading {
    font-size: clamp(2.4rem, 13vw, 3rem);
  }

  .unit {
    font-size: 0.9rem;
  }

  .status-pill {
    white-space: nowrap;
    padding: 9px 12px;
    font-size: 0.9rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .legend {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.78rem;
  }

  .chart-tools {
    width: 100%;
    align-items: stretch;
  }

  .time-range-selector {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .time-range-button {
    min-width: 0;
    min-height: 40px;
  }

  .chart-wrap {
    width: 100%;
    min-width: 0;
    height: 230px;
  }

  .current-reading,
  .chart-card,
  .averages-card,
  .stats-card,
  .list-card {
    grid-column: 1;
  }

  .period-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 14px;
  }

  .period-stat,
  .stat {
    min-width: 0;
  }

  .period-value,
  .stat-value {
    overflow-wrap: anywhere;
  }

  .recent-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .recent-list li {
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 10px;
  }

  .recent-list li span:last-child {
    font-weight: 600;
  }

  .recent-list .empty-state {
    grid-column: 1 / -1;
    align-items: center;
  }

  .footer {
    padding: 20px max(16px, 5vw);
    font-size: 0.8rem;
  }
}

@media (max-width: 380px) {
  .current-reading {
    grid-template-columns: minmax(0, 1fr);
  }

  .status-pill {
    justify-self: start;
  }

  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}
