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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Trebuchet MS', 'Trebuchet', sans-serif;
  color: #000000;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f4e7df;
}

@supports (background-image: url('')) {
  body {
    background-image: url('https://picsum.photos/1920/1080?random=1');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
  }
}

@media (max-width: 640px) {
  body {
    background-attachment: scroll;
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.1)), url('https://picsum.photos/1920/1080?random=1');
    background-color: #f4e7df;
    background-size: cover;
    background-position: center;
  }
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.08));
  z-index: -1;
  pointer-events: none;
}

.floating-status {
  position: fixed;
  top: 12px;
  right: 12px;
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.7);
  color: #eeeeee;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 120px;
  text-align: center;
}

@media (max-width: 480px) {
  .floating-status {
    top: 8px;
    right: 8px;
    padding: 6px 12px;
    font-size: 0.7rem;
    min-width: auto;
  }
}

.floating-status.disconnected,
.floating-status.error,
.floating-status.offline {
  background: rgba(0, 0, 0, 0.7);
  color: #eeeeee;
}

.floating-status.connected {
  background: rgba(203, 41, 87, 0.7);
  color: #eeeeee;
}

main {
  max-width: 1100px;
  width: 100%;
  padding: 20px 16px 24px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0 auto;
}

@media (min-width: 481px) {
  main {
    padding: 0 20px 24px;
  }
}

@media (max-width: 640px) {
  main {
    justify-content: flex-start;
    padding: 64px 12px 20px;
    min-height: auto;
  }
}

.card-grid {
  display: grid;
  gap: 16px;
  width: 100%;
  grid-template-columns: 1fr;
  grid-template-areas:
    "left-stack"
    "chart";
}

@media (min-width: 600px) {
  .card-grid {
    gap: 20px;
  }
}

@media (min-width: 900px) {
  .card-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "left-stack chart";
    gap: 24px;
    align-items: stretch;
  }
}

.card {
  background: rgba(238, 238, 238, 0.25);
  border: none;
  border-radius: 12px;
  padding: 24px 18px;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  will-change: transform;
  min-width: 0;
}

@media (max-width: 720px) {
  .card {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.14);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.54);
    border: 1px solid rgba(255, 255, 255, 0.34);
  }
}

@media (max-width: 640px) {
  .card {
    padding: 18px 14px;
    border-radius: 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.14);
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.32);
  }

  .left-stack {
    gap: 12px;
  }

  .sensor-display {
    margin: 18px 0;
  }

  .value-box {
    margin-bottom: 18px;
  }

  .value {
    font-size: 2.2rem;
  }

  .unit {
    font-size: 0.95rem;
  }

  .status-comment {
    margin-top: 8px;
    font-size: 0.9rem;
  }

  .weather-display {
    gap: 8px;
  }

  .weather-metric {
    min-width: 0;
    flex: 1 1 120px;
    padding: 8px 10px;
  }

  .weather-title {
    font-size: 0.98rem;
  }

  .weather-location {
    font-size: 0.82rem;
    overflow-wrap: anywhere;
  }

  .toggle-buttons,
  .chart-toggle-buttons {
    gap: 8px;
    margin-bottom: 14px;
  }

  .chart-frame {
    padding: 8px;
    margin: 0 auto 8px;
  }

  #history-chart {
    max-height: 220px;
  }

  .health-bar-container {
    height: 20px;
    margin: 12px 0;
  }

  .range-info {
    font-size: 0.78rem;
  }

  .last-update {
    margin-top: 20px;
    font-size: 0.78rem;
  }
}

.left-stack {
  grid-area: left-stack;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}

@media (min-width: 600px) {
  .left-stack {
    gap: 20px;
  }
}

@media (min-width: 900px) {
  .left-stack {
    gap: 24px;
  }
}

.left-stack .card {
  flex: 1;
}

.weather-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-card {
  grid-area: chart;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

@media (min-width: 481px) {
  .card {
    border-radius: 16px;
    padding: 30px 24px;
  }
}

@media (min-width: 768px) {
  .card {
    padding: 40px 30px;
  }
}

.weather-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weather-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.weather-location {
  font-size: 0.9rem;
  color: #4a4a4a;
}

.weather-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.weather-metric {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  min-width: 136px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.weather-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #444444;
}

.weather-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.weather-unit {
  font-size: 0.95rem;
  color: #333333;
}

.chart-toggle-buttons {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  justify-content: center;
}

.chart-hint {
  margin-top: 18px;
  color: #5a5a5a;
  font-size: 0.9rem;
}

.toggle-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  justify-content: center;
  flex-wrap: wrap;
}

@media (min-width: 600px) {
  .toggle-buttons {
    gap: 8px;
    margin-bottom: 22px;
  }
}

.toggle-btn {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.16);
  color: #141414;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 600px) {
  .toggle-btn {
    padding: 8px 16px;
    font-size: 0.82rem;
  }
}

.toggle-btn:active {
  transform: scale(0.98);
}

@media (hover: hover) {
  .toggle-btn:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.28);
  }
}

.toggle-btn.active {
  background: rgba(203, 41, 87, 0.24);
  color: #fff;
  border-color: rgba(203, 41, 87, 0.85);
  box-shadow: 0 18px 30px rgba(203, 41, 87, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.chart-frame {
  margin: 0 auto 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

@media (min-width: 600px) {
  .chart-frame {
    padding: 18px;
    margin-bottom: 18px;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}

#history-chart {
  width: 100%;
  height: auto;
  max-height: 280px;
  border-radius: 12px;
  background: transparent;
  border: none;
  display: block;
}

@media (min-width: 600px) {
  #history-chart {
    max-height: 320px;
    border-radius: 16px;
  }
}

@media (min-width: 900px) {
  #history-chart {
    max-height: 360px;
  }
}

.sensor-display {
  margin: 30px 0;
}

.label {
  color: #000000;
  font-size: 1.1rem;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.value-box {
  margin-bottom: 30px;
}

.value {
  font-size: 2.5rem;
  font-weight: bold;
  color: #cb2957;
  line-height: 1;
  display: inline-block;
}

@media (min-width: 481px) {
  .value {
    font-size: 3.2rem;
  }
}

@media (min-width: 768px) {
  .value {
    font-size: 4rem;
  }
}

.unit {
  color: #000000;
  font-size: 1rem;
  margin-left: 6px;
  display: inline-block;
}

@media (min-width: 600px) {
  .unit {
    font-size: 1.5rem;
    margin-left: 8px;
  }
}

.status-comment {
  margin: 10px auto 0;
  color: rgba(17, 17, 17, 0.92);
  font-size: 0.95rem;
  font-style: italic;
  line-height: 1.4;
  max-width: 380px;
}

.health-bar-container {
  width: 100%;
  height: 24px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 20px;
  overflow: hidden;
  margin: 16px 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 12px 30px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

@media (min-width: 600px) {
  .health-bar-container {
    height: 30px;
    margin: 20px 0;
  }
}

.health-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, rgba(0, 102, 255, 0.95), rgba(255, 0, 0, 0.95));
  transition: width 0.5s ease, background 0.5s ease;
  border-radius: 18px;
  opacity: 0.92;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5), 0 10px 20px rgba(0, 0, 0, 0.14);
}

.range-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #5a5a5a;
  margin-top: 10px;
  padding: 0 5px;
}

.last-update {
  text-align: center;
  margin-top: 30px;
  color: #5a5a5a;
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Firefox mobile performance overrides */
.firefox .card,
.firefox .floating-status,
.firefox .toggle-btn,
.firefox .chart-frame,
.firefox .health-bar-container,
.firefox .weather-metric {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

.firefox .card,
.firefox .chart-frame {
  will-change: auto;
}

.firefox .card {
  background: rgba(238, 238, 238, 0.45);
}

@media (max-width: 720px) {
  .firefox .card {
    background: rgba(255, 255, 255, 0.66);
  }
}

@media (max-width: 640px) {
  .firefox .card {
    background: rgba(255, 255, 255, 0.62);
  }
}

.firefox .toggle-btn {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.firefox .health-bar {
  transition: width 0.1s linear, background 0.1s linear;
}

.firefox .chart-frame {
  transition: none;
}

.firefox .floating-status {
  background: rgba(0, 0, 0, 0.85);
}

.firefox body {
  background-attachment: scroll !important;
}

.firefox .weather-metric {
  background: rgba(255, 255, 255, 0.25);
}
