:root {
  /* Spotify Inspired Palette */
  --bg-base: #121212;
  --bg-surface: #181818;
  --bg-interactive: #1f1f1f;
  --text-base: #ffffff;
  --text-secondary: #b3b3b3;
  --accent-spotify: #1ed760;
  --accent-blue: #539df5;
  --accent-yellow: #f5c153;
  /* 照度用のイエロー */
  --accent-red: #f3727f;
  --shadow-medium: rgba(0, 0, 0, 0.3) 0px 8px 8px;
  --shadow-heavy: rgba(0, 0, 0, 0.5) 0px 8px 24px;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-base);
  color: var(--text-base);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.container {
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-left: 10px;
  padding-right: 10px;
}

h1 {
  font-weight: 700;
  font-size: 2rem;
  color: var(--text-base);
  margin-bottom: 4px;
}

p.subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 400;
}

#last-update {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 10px;
  font-weight: 400;
}

/* スプレッドシートリンク */
.sheet-link {
  background-color: var(--bg-interactive);
  color: var(--text-base);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s ease, transform 0.1s ease, color 0.2s ease;
  text-decoration: none;
  box-shadow: var(--shadow-medium);
}

.sheet-link:hover {
  background-color: #2a2a2a;
  transform: scale(1.06);
  color: var(--accent-spotify);
}

.sheet-link:active {
  transform: scale(1.0);
}

/* 期間切り替えボタン */
.controls {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
}

.controls-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.btn {
  background-color: var(--bg-interactive);
  border: none;
  color: var(--text-base);
  padding: 8px 16px;
  border-radius: 9999px;
  cursor: pointer;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 0.813rem;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  transition: background-color 0.2s ease, transform 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover {
  background-color: #2a2a2a;
  transform: scale(1.04);
}

.btn:active {
  transform: scale(1.0);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  color: var(--text-secondary);
}

.btn-spinner {
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-left-color: var(--text-base);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn:disabled .btn-spinner {
  display: inline-block;
}

.btn.active {
  background-color: var(--accent-spotify);
  color: #000000;
}

/* ダッシュボードカード */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.card {
  background-color: var(--bg-surface);
  border-radius: 8px;
  padding: 20px;
  transition: background-color 0.3s ease;
  box-shadow: var(--shadow-medium);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 155px; /* 統計情報表示スペース確保のため引き上げ */
}

.card:hover {
  background-color: #282828;
}

.card-title {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 2.5rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  color: var(--text-base);
}

.card-unit {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-left: 4px;
}

/* グラフエリア */
.chart-container {
  background-color: var(--bg-surface);
  border-radius: 8px;
  padding: 24px;
  height: 450px;
  box-shadow: var(--shadow-medium);
  position: relative;
}

.chart-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(18, 18, 18, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.chart-loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: var(--accent-spotify);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.reload-btn {
  background-color: var(--bg-interactive);
  color: var(--text-base);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s ease, transform 0.1s ease, color 0.2s ease;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-medium);
  margin-left: 8px;
}

.reload-btn:hover {
  background-color: #2a2a2a;
  transform: scale(1.06);
  color: var(--accent-spotify);
}

.reload-btn:active {
  transform: scale(1.0);
}

/* ユーティリティ */
.text-temp {
  color: var(--accent-spotify);
}

.text-humi {
  color: var(--accent-blue);
}

.text-ilum {
  color: var(--accent-yellow);
}

/* 照度色 */

/* 快適度の状態色 */
.comfort-good {
  color: var(--accent-spotify);
}

.comfort-warn {
  color: var(--accent-yellow);
}

.comfort-bad {
  color: var(--accent-red);
}

/* 快適度のフォントサイズ縮小 */
#current-comfort {
  font-size: 1.8rem;
}

/* 比較表示 */
.card-stats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: auto; /* 下部に押し上げる */
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.stats-label {
  font-size: 0.625rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.stats-value {
  font-weight: 600;
  color: var(--text-base);
}

.card-comparison {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dotted rgba(255, 255, 255, 0.05); /* 統計値と比較値の区切り */
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.value-up {
  color: var(--accent-red);
}

.value-down {
  color: var(--accent-blue);
}

.value-stable {
  color: var(--text-secondary);
}

.loading {
  text-align: center;
  color: var(--text-secondary);
  font-size: 1rem;
  padding: 40px;
}

@media (max-width: 640px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .card {
    padding: 15px;
    min-height: 135px; /* モバイル時も統計表示エリアを考慮して高さを調整 */
  }

  .card-value {
    font-size: 1.5rem;
  }

  .card-unit {
    font-size: 1rem;
  }

  .controls {
    flex-wrap: wrap;
    gap: 4px;
  }

  header {
    flex-direction: row;
  }

  .chart-container {
    height: 320px;
    padding: 8px;
  }



  .controls-group {
    gap: 10px;
  }

  #current-comfort {
    font-size: 1.2rem;
  }
}

/* モーダル（ポップアップ） */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background-color: var(--bg-surface);
  color: var(--text-base);
  padding: 32px;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-heavy);
  position: relative;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.modal.active .modal-content {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s ease;
}

.modal-close:hover {
  color: var(--text-base);
}

.modal h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  font-weight: 700;
}

.modal-desc {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.modal-table th, .modal-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-table th {
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}

.modal-table td {
  font-size: 0.875rem;
  font-weight: 600;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

.modal-link {
  color: var(--accent-spotify);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s ease;
}

.modal-link:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* クリック可能なカード */
.card.clickable {
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.3s ease;
}

.card.clickable:hover {
  transform: translateY(-4px);
  background-color: #282828;
}
