* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  font-size: 0.8em;
  max-width: 900px;
  margin: 20px auto;
  background-color: #fffbea;
}

.header {
  background: #fffbea;
  padding: 12px 20px;
}

.header h1 {
  color: #4a4635;
  /* color: #24231e; */
  font-size: 2em;
  margin: 0;
  letter-spacing: 0.05em;
}

/* --------------------
   SPA <-> 別タブ切り替え
-------------------- */
.selector-options {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.new-tab-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #4a4635;
  font-size: 0.9em;
  cursor: pointer;
  user-select: none;
}

.new-tab-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: #ddd8bd;
  border: 1px solid #e8dfad;
  border-radius: 999px;
  transition: background-color 0.2s;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background-color: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.new-tab-toggle input:checked + .toggle-switch {
  background-color: #17e975;
}

.new-tab-toggle input:checked + .toggle-switch::after {
  transform: translateX(20px);
}

@media (max-width: 500px) {
  .selector-options {
    display: none;
  }
}

/* --------------------
   都府県・地点選択
-------------------- */
.weather-selector {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  margin-bottom: 20px;
  background-color: white;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.select-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.select-group label {
  color: #4a4635;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.select-group select {
  width: 100%;
  padding: 10px 12px;
  background-color: white;
  color: #4a4635;
  border: 1px solid #ddd6c4;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}

.select-group select:focus {
  outline: 2px solid #17e975;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px rgba(232, 223, 173, 0.4);
}

.select-group select:disabled {
  background-color: #f3f1e8;
  color: #999;
  cursor: not-allowed;
}

.selected-location {
  padding: 12px 16px;
  color: #4a4635;
  background-color: #fffbea;
  border-left: 5px solid #17e975;
  border-radius: 6px;
}

.selected-location strong {
  margin-left: 8px;
  font-size: 18px;
}

/* --------------------
   日付一覧
-------------------- */
.date-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.date-year {
  overflow: hidden;
  background-color: white;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.date-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: #4a4635;
  text-align: left;
  cursor: pointer;
}

.year-toggle {
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 600;
  border-bottom: 2px solid #e8dfad;
}

.year-toggle:hover {
  background: #f3fff8;
}

.date-months {
  padding: 0 12px 12px;
}

.date-month {
  border-top: 1px solid #ddd6c4;
}

.date-month:first-child {
  border-top: none;
}

.month-toggle {
  padding: 10px 12px;
  font-size: 16px;
}

.month-toggle:hover {
  background: #fffbea;
}

.date-days {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px 16px;
}

.date-days a, .date-days button {
  min-width: 48px;
  padding: 7px 10px;
  color: #4a4635;
  background-color: white;
  border: 1px solid #ddd6c4;
  border-radius: 6px;
  text-align: center;
  text-decoration: none;
}

.date-days a:hover, .date-days button:hover {
  border-color: #17e975;
  background-color: #e8dfad;
}

/* --------------------
   ロード画面
-------------------- */
.weather-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 240px;
  color: #4a4635;
  font-size: 1em;
  letter-spacing: 0.05em;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 5px solid #e8dfad;
  border-top-color: #17e975;
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.weather-view-wrapper {
  position: relative;
}

.card-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
}

/* --------------------
   Card部分
-------------------- */
hr {
  border: none;
  border-top: 1px solid #ddd6c4;
  margin: 20px 0;
}

.weather-card {
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  background-color: white;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.weather-card h2 {
  color: #5a5543;
  font-size: 1.4em;
  margin: 0 0 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e8dfad;
}

.weather-card h3 {
  color: #4a4635;
  letter-spacing: 0.05em;
}

.comparison {
  color: #666;
  margin-bottom: 15px;
}

.actual {
  margin-bottom: 15px;
  letter-spacing: 0.08em;
}

.actual strong {
  font-size: 1.2em;
}

.averages {
  display: flex;
  gap: 0;
  margin-bottom: 5px;
  letter-spacing: 0.03em;
}

.averages span {
  padding: 0 15px;
  border-right: 1px solid #ccc;
}

.averages span:first-child {
  padding-left: 0;
}

.averages span:last-child {
  border-right: none;
}

.differences {
  display: flex;
  gap: 0;
  margin-bottom: 15px;
  letter-spacing: 0.02em;
}

.differences > span {
  padding: 0 15px;
  border-right: 1px solid #ccc;
}

.differences > span:first-child {
  padding-left: 0;
}

.differences > span:last-child {
  border-right: none;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.score-label {
  width: 40px;
  font-weight: bold;
  color: #4a4635;
  letter-spacing: 0.05em;
}

.bar {
  position: relative;
  flex: 1;
  height: 20px;
  background: repeating-linear-gradient(
    to right,
    #ddd 0,
    #ddd 5px,
    transparent 5px,
    transparent 10px
  );
}

.bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: repeating-linear-gradient(
    to right,
    white 0,
    white 5px,
    transparent 5px,
    transparent 10px
  );
}

.marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 13px;
  font-weight: bold;
  color: white;
}

.high {
  font-weight: bold;
  margin-left: 10px;
  letter-spacing: 0.05em;
}

.low {
  font-weight: bold;
  margin-right: 5px;
  letter-spacing: 0.05em;
}

.positive {
  color: #d32f2f;
}

.negative {
  color: #1565c0;
}

.zero {
  color: #666;
}

.weather-group {
  display: none;
}

.weather-group.active {
  display: block;
}

/* --------------------
   極値ポップアップ
-------------------- */
.extreme-link {
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: bold;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.extreme-link:hover {
  text-decoration: underline;
}

.extreme-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: rgba(0, 0, 0, 0.45);
}

.extreme-popup {
  position: relative;
  width: min(90%, 500px);
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  color: #4a4635;
  background-color: white;
  border-radius: 10px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.extreme-popup h4 {
  margin: 0 0 16px;
  padding-bottom: 10px;
  color: #5a5543;
  font-size: 1.3em;
  letter-spacing: 0.05em;
  border-bottom: 2px solid #e8dfad;
}

.extreme-value {
  margin: 16px 0 20px;
  padding: 12px 16px;
  background-color: #fffbea;
  border-left: 5px solid #17e975;
  border-radius: 6px;
  font-size: 24px;
  font-weight: bold;
}

.extreme-record {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 12px 14px;
  color: inherit;
  background-color: transparent;
  border: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}


.extreme-record + .extreme-record {
  border-top: 1px solid #ddd6c4;
}

.extreme-record div:first-child {
  color: #666;
}

.extreme-record:hover {
  background-color: #f3fff8;
}

.extreme-record:focus-visible {
  outline: 2px solid #17e975;
  outline-offset: -2px;
}

.extreme-popup > p {
  margin: 20px 0;
  padding: 12px 16px;
  background-color: #fffbea;
  border-radius: 6px;
}

.extreme-close {
  display: block;
  margin: 20px 0 0 auto;
  padding: 8px 16px;
  color: #4a4635;
  background-color: white;
  border: 1px solid #ddd6c4;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}

.extreme-close:hover {
  border-color: #17e975;
  background-color: #f3fff8;
}

.extreme-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background-color: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  color: #4a4635;
  font-size: 0.9em;
}

.extreme-loading .spinner {
  width: 32px;
  height: 32px;
  border-width: 4px;
}

/* --------------------
   ナビゲーションボタン
-------------------- */
.weather-back {
  margin-left: 20px;
  padding: 7px 12px;
  color: #4a4635;
  background-color: #fffbea;
  border: 1px solid #e8dfad;
  border-radius: 6px;
  font: inherit;
  font-size: 1em;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.weather-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 0;
  background-color: #fffbea;
}

.header h1.card-header {
  font-size: 1.4em;
}

.date-navigator {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0 20px;
}

.date-nav-row {
  display: grid;
  grid-template-columns: 24px 40px 100px 40px;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.date-nav-label {
  color: #77715c;
  font-size: 0.85em;
  font-weight: bold;
}

.date-nav-value {
  text-align: center;
  color: #4a4635;
  font-size: 1.1em;
  font-weight: bold;
  letter-spacing: 0.05em;
}

.date-nav-row button, .date-nav-row a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 40px;
  height: 34px;
  padding: 0;
  color: #4a4635;
  background-color: white;
  border: 1px solid #e8dfad;
  border-radius: 6px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.date-nav-row button:hover:not(:disabled) {
  background-color: #17e975;
}

.date-nav-row button:active:not(:disabled) {
  transform: translateY(1px);
}

.date-nav-row button:disabled {
  opacity: 0.25;
  cursor: default;
}

/* --------------------
   Cardのタブ
-------------------- */
.weather-back:hover {
  background-color: #17e975;
}

.weather-back:active {
  transform: translateY(1px);
}

.weather-tabs {
  display: flex;
  margin: 20px 0;
}

.weather-tabs button {
  flex: 1;
  padding: 10px;
  color: #4a4635;
  background-color: white;
  border: 1px solid #e8dfad;
  font-size: 1.2em;
  font-weight: bold;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.weather-tabs button:first-child {
  border-radius: 8px 0 0 8px;
}

.weather-tabs button:last-child {
  border-radius: 0 8px 8px 0;
}

.weather-tabs button:not(:first-child) {
  border-left: 0;
}

.weather-tabs button.active {
  background-color: #17e975;
}

/* --------------------
   SP用 (全般)
-------------------- */
@media (max-width: 600px) {
  body {
    margin: 10px;
  }

  .header {
    padding: 10px 12px;
  }

  .header h1.card-header {
    font-size: 1.2em;
  }

  .weather-selector {
    padding: 15px;
  }

  .date-days {
    gap: 6px;
    padding: 8px 6px 14px;
  }

  .date-days a, .date-days button {
    min-width: 44px;
    padding: 7px 8px;
  }
}

/* --------------------
   SP用 (狭い)
-------------------- */
@media (max-width: 500px) {
  .header {
    position: static;
  }

  .weather-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 6px 0 8px;
  }

  .weather-back {
    margin-left: 10px;
    margin-bottom: 6px;
    padding: 5px 8px;
    font-size: 0.85em;
  }

  .date-navigator {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin: 0;
  }

  .date-nav-row {
    display: grid;
    grid-template-columns: 26px 1fr 26px;
    gap: 2px;
  }

  .date-nav-label {
    display: none;
  }

  .date-nav-row button, .date-nav-row a {
    width: 26px;
    height: 30px;
    font-size: 0.75em;
  }

  .date-nav-value {
    font-size: 0.9em;
    white-space: nowrap;
  }
}