.settings-item {
  justify-content: flex-start;
  gap: 7px;
}

.settings-symbol {
  display: inline-grid;
  place-items: center;
  width: 1.1rem;
  flex: 0 0 1.1rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1;
  text-align: center;
}

.settings-item .check {
  width: 1.1rem;
  flex-basis: 1.1rem;
  color: var(--text-secondary);
  font-size: 0 !important;
  font-weight: 600;
}

.settings-item .check::before {
  display: block;
  color: var(--text-primary);
  font-size: 0.8rem;
  line-height: 1;
}

.settings-item[aria-pressed="false"] .check::before { content: "○"; }
.settings-item[aria-pressed="true"] .check::before { content: "●"; }

@media (max-width: 768px) {
  body { font-size: 13px; }
  .page-wrapper { width: 100%; }

  .controls {
    gap: 4px;
    padding: max(4px, env(safe-area-inset-top)) 5px 4px;
  }

  .search-box { flex: 1 1 auto; min-width: 0; }
  .search-box input {
    height: 32px;
    padding-left: 29px;
    border-radius: 0;
    font-size: 16px;
  }
  .search-box::before { left: 8px; width: 11px; height: 11px; }
  .search-box::after { left: 18px; top: 19px; }

  #preset-select {
    width: clamp(78px, 24vw, 104px);
    height: 32px;
    padding-left: 7px;
    padding-right: 22px;
    border-radius: 0;
    font-size: 0.73rem;
    background-position: right 7px center;
  }

  .settings-btn { width: 32px; height: 32px; border-radius: 0; }
  .settings-menu { right: 0; min-width: 164px; border-radius: 0; }

  #charts-container {
    gap: 12px;
    padding: 7px 0 9px;
  }

  .location-card {
    overflow: hidden;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .location-card + .location-card {
    padding-top: 8px;
    border-top: 1px solid var(--border-main);
  }

  .location-header {
    min-height: 34px;
    gap: 5px;
    padding: 0 4px 4px 0;
  }

  .location-header::before {
    width: 3px;
    min-height: 27px;
    flex-basis: 3px;
  }

  .location-header h2 {
    flex: 1 1 auto;
    max-width: none;
    font-size: 0.83rem;
    gap: 0;
  }
  .location-coordinates { display: none; }

  .header-actions { flex: 0 0 auto; gap: 2px; }
  .history-actions { gap: 0; font-size: 0.59rem; }
  .history-label { display: none; }

  .history-btn, .move-btn, .remove-btn {
    height: 25px;
    border: 0;
    border-radius: 0;
    background: transparent;
    font-size: 0.6rem;
  }
  .history-btn { padding: 0 5px; }

  .move-btn, .remove-btn {
    min-width: 24px;
    width: 24px;
    padding: 0;
    font-size: 0;
  }
  .move-btn::before, .remove-btn::before {
    font-size: 13px;
    font-weight: 650;
    line-height: 1;
  }
  .move-up::before { content: "↑"; }
  .move-down::before { content: "↓"; }
  .remove-btn::before { content: "×"; font-size: 15px; }

  .chart-section-label {
    margin-top: 0;
    padding: 2px 5px 1px;
    font-size: 0.54rem;
    letter-spacing: 0.09em;
  }

  /* All explanations remain visible: no horizontal legend overflow. */
  .chart-legend {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 9px;
    row-gap: 4px;
    padding: 4px 5px 5px;
    overflow: visible;
    font-size: 0.56rem;
    line-height: 1.2;
  }

  .legend-item {
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .legend-swatch { margin-top: 1px; }
  .legend-line { margin-top: 4px; }

  .chart-scroll-wrapper {
    width: 100%;
    padding: 0 0 2px;
  }
  .chart-scroll-wrapper::-webkit-scrollbar { height: 2px; }

  .loading { min-height: 62px; padding: 10px; font-size: 0.7rem; }

  .search-results {
    top: calc(100% + 3px);
    max-height: 48vh;
    border-radius: 0;
  }
  .search-result-item { padding: 8px; }

  footer {
    gap: 3px 10px;
    padding: 6px 8px max(9px, env(safe-area-inset-bottom));
    font-size: 0.58rem;
  }
}

@media (max-width: 430px) {
  .history-reset { display: none; }

  .location-header h2 {
    min-width: 70px;
    font-size: 0.81rem;
  }

  .legends-visible .chart-legend {
    display: grid;
  }
}

@media (max-width: 370px) {
  #preset-select { width: 74px; }

  .chart-legend {
    grid-template-columns: 1fr;
    row-gap: 3px;
  }

  .history-back { padding-left: 3px; padding-right: 3px; }
}
