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

  body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f2f1ec;
    color: #1c1c1a;
    padding: 0.44rem 0.88rem 0.18rem;
    min-height: 100vh;
  }

  /* ── header ── */
  header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.7rem;
    margin-bottom: 0.3rem;
  }
  h1 { font-size: 1.24rem; font-weight: 600; }
  .meta { font-size: 0.73rem; color: #7a7a72; margin-top: 0.05rem; }
  .site-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    padding: 0.16rem;
    border: 1px solid #d4d3cc;
    border-radius: 8px;
    background: rgba(255,255,255,0.78);
  }
  .site-nav a {
    display: inline-grid;
    place-items: center;
    width: 1.68rem;
    height: 1.68rem;
    border-radius: 6px;
    color: #555;
    text-decoration: none;
    font-size: 0.98rem;
    line-height: 1;
  }
  .site-nav a:hover { background: #ebe9e1; }
  .site-nav a.active {
    background: #5c7a62;
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  }

  /* ── station tabs ── */
  .station-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.24rem;
    margin-bottom: 0.04rem;
  }
  .station-btn {
    padding: 0.24rem 0.66rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 20px;
    background: #fff;
    font-size: 0.8rem;
    font-family: inherit;
    color: #444;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap;
  }
  .station-btn:hover { background: #ebe9e1; border-color: #b0afa8; }
  .station-btn.active {
    border-color: var(--sc);
    background: var(--sc);
    color: #fff;
    font-weight: 600;
  }
  .station-btn.secondary-active {
    border-color: var(--sc2);
    background: transparent;
    color: var(--sc2);
    font-weight: 600;
  }

  /* ── param + filter row ── */
  .controls {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.14rem;
  }
  .param-group {
    display: flex;
    gap: 0.28rem;
    flex-wrap: wrap;
  }
  .param-btn {
    padding: 0.22rem 0.58rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    background: #fff;
    font-size: 0.78rem;
    font-family: inherit;
    color: #555;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
  }
  .param-btn:hover { background: #ebe9e1; }
  .param-btn.active {
    border-color: #5c7a62;
    background: #5c7a62;
    color: #fff;
    font-weight: 600;
  }

  .sep { width: 1px; height: 1.4rem; background: #d4d3cc; margin: 0 0.1rem; }

  .range-group {
    display: flex;
    gap: 0.22rem;
    flex-wrap: wrap;
    margin-left: clamp(1.15rem, 1.4vw, 1.75rem);
  }
  .option-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-left: auto;
  }
  .option-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .agg-group {
    display: inline-flex;
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    overflow: hidden;
  }
  .agg-btn { display: flex; }
  .agg-btn input[type="radio"] {
    position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
  }
  .agg-btn span {
    display: block;
    padding: 0.22rem 0.56rem;
    font-size: 0.78rem;
    font-family: inherit;
    color: #555;
    background: #fff;
    cursor: pointer;
    border-right: 1px solid #c8c7c0;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
    user-select: none;
  }
  .agg-btn:last-child span { border-right: none; }
  .agg-btn:hover span { background: #ebe9e1; }
  .agg-btn:has(input:checked) span { background: #888; color: #fff; font-weight: 600; }
  .anomaly-group {
    display: inline-flex;
    align-items: center;
    gap: 0.34rem;
  }
  .anomaly-group .option-select { opacity: 0.45; transition: opacity 0.15s; }
  .anomaly-group:has(#anomaly-mode:checked) .option-select { opacity: 1; }
  .option-row:has(input[name="agg"][value="season"]:checked) .anomaly-group .option-select { opacity: 1; }
  .option-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    font-size: 0.78rem;
    color: #555;
    white-space: nowrap;
  }
  .option-toggle input {
    margin: 0;
    accent-color: #5c7a62;
  }
  .option-toggle:has(input:disabled) { opacity: 0.35; cursor: default; pointer-events: none; }
  .option-select {
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    padding: 0.2rem 0.42rem;
    background: #fff;
    font-size: 0.78rem;
    font-family: inherit;
    color: #555;
  }
  .info-btn {
    display: inline-grid;
    place-items: center;
    width: 1.35rem;
    height: 1.35rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 50%;
    background: #fff;
    color: #5c5c54;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
  }
  .info-btn:hover { background: #ebe9e1; }
  .range-btn {
    padding: 0.24rem 0.52rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    background: #fff;
    font-size: 0.78rem;
    font-family: inherit;
    color: #555;
    cursor: pointer;
  }
  .range-btn:hover { background: #ebe9e1; }
  .range-btn.active { border-color: #888; background: #888; color: #fff; }
  .compact-action {
    padding-left: 0.62rem;
    padding-right: 0.62rem;
  }

  /* ── date fields ── */
  .date-row {
    display: flex;
    align-items: center;
    gap: 0.34rem;
    flex-wrap: wrap;
    margin-bottom: 0.14rem;
    font-size: 0.82rem;
    color: #555;
  }
  .date-row label { color: #666; }
  .date-field { position: relative; display: inline-flex; align-items: center; }
  .date-display {
    width: 8.1rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    padding: 0.22rem 2.35rem 0.22rem 0.45rem;
    font-size: 0.82rem;
    font-family: inherit;
    background: #fff;
  }
  .date-display:focus { outline: 2px solid #5c7a62; border-color: transparent; }
  .picker-btn {
    position: absolute;
    right: 0.18rem;
    top: 50%;
    transform: translateY(-50%);
    min-width: 1.9rem;
    padding: 0.12rem 0.28rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 4px;
    background: #f0efe8;
    font-size: 0.68rem;
    cursor: pointer;
  }
  .picker-btn:hover { background: #e0dfd8; }
  .native-date-input {
    position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
  }
  .nav-btn {
    min-width: 2rem;
    padding: 0.22rem 0.44rem;
    border: 1.5px solid #c8c7c0;
    border-radius: 6px;
    background: #fff;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
  }
  .nav-btn:hover:not(:disabled) { background: #ebe9e1; }
  .nav-btn:disabled { opacity: 0.4; cursor: default; }

  /* ── messages ── */
  #error, #empty, #loading {
    display: none;
    border-radius: 8px;
    padding: 0.62rem 0.82rem;
    margin-bottom: 0.3rem;
    font-size: 0.84rem;
  }
  #error   { background: #fff3f0; border: 1px solid #f5c0b0; color: #8b1a00; }
  #empty   { background: #fffae8; border: 1px solid #e8d58a; color: #6a4d00; }
  #loading { background: #f0f5f0; border: 1px solid #b8cebb; color: #3a5c40; }
  .data-warning {
    border-radius: 8px;
    padding: 0.46rem 0.64rem;
    margin-bottom: 0.24rem;
    background: #fff8e8;
    border: 1px solid #e3c56d;
    color: #6d4b00;
    font-size: 0.78rem;
  }
  .data-warning[hidden] { display: none; }
  .chart-warning { color: #8a5a00; font-size: 0.74rem; font-weight: 500; margin-left: 0.45rem; white-space: nowrap; }

  /* ── stats grid ── */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.24rem;
    margin-bottom: 0.14rem;
  }
  .stat-card {
    min-width: 0;
    min-height: 4.45rem;
    max-height: 4.45rem;
    overflow: visible;
    padding: 0.28rem 0.54rem;
    border: 1px solid #deded5;
    border-radius: 9px;
    background: linear-gradient(170deg, #fafaf6, #f4f3ec);
  }
  .stat-label {
    display: block;
    font-size: 0.67rem;
    color: #7a7a72;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 0.1rem;
  }
  .stat-value {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.02rem;
    font-weight: 700;
    color: #1c1c1a;
    line-height: 1.15;
  }
  .stat-note {
    display: -webkit-box;
    min-width: 0;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 0.69rem;
    color: #7a7a72;
    margin-top: 0.15rem;
    line-height: 1.3;
  }
  .stat-card.has-detail {
    position: relative;
    cursor: help;
  }
  .detail-tooltip {
    position: absolute;
    left: 0.45rem;
    bottom: calc(100% + 0.36rem);
    z-index: 20;
    display: none;
    width: max-content;
    max-width: min(28rem, 82vw);
    padding: 0.44rem 0.56rem;
    border: 1px solid #d6d4c9;
    border-radius: 8px;
    background: #fffef9;
    color: #45453f;
    box-shadow: 0 0.45rem 1.4rem rgba(0,0,0,.16);
    font-size: 0.72rem;
    line-height: 1.45;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
  }
  .stat-card.has-detail:hover .detail-tooltip,
  .stat-card.has-detail:focus .detail-tooltip {
    display: block;
  }
  /* ── modal overlays ── */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(28, 28, 26, 0.32);
  }
  .modal-backdrop[hidden] { display: none; }
  .modal-panel {
    position: relative;
    width: min(44rem, 100%);
    max-height: min(80vh, 42rem);
    overflow: auto;
    border: 1px solid #d8d7cf;
    border-radius: 10px;
    background: #fff;
    padding: 0.9rem 1rem;
    box-shadow: 0 1rem 2.5rem rgba(0,0,0,.22);
  }
  .modal-panel h2 {
    font-size: 1rem;
    margin-bottom: 0.55rem;
  }
  .modal-panel p {
    margin-bottom: 0.55rem;
    color: #444;
    font-size: 0.86rem;
    line-height: 1.45;
  }
  .modal-close {
    position: absolute;
    top: 0.45rem;
    right: 0.55rem;
    border: 0;
    background: transparent;
    font-size: 1.35rem;
    line-height: 1;
    color: #666;
    cursor: pointer;
  }
  .records-table-wrap { overflow-x: auto; }
  .records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
  }
  .records-table th,
  .records-table td {
    padding: 0.34rem 0.42rem;
    border-bottom: 1px solid #e5e4dc;
    text-align: left;
    white-space: nowrap;
  }
  .records-table thead th {
    color: #666;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  /* ── chart card ── */
  .card {
    background: #fff;
    border-radius: 10px;
    padding: 0.32rem 0.78rem 0.22rem;
    box-shadow: 0 1px 5px rgba(0,0,0,.06);
    margin-bottom: 0.16rem;
  }
  .card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.32rem;
  }

  /* ── today in history ── */
  .today-section {
    background: #fff;
    border-radius: 10px;
    padding: 0.26rem 0.78rem 0.26rem;
    box-shadow: 0 1px 5px rgba(0,0,0,.06);
  }
  .today-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.32rem;
  }
  .today-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .today-card {
    padding: 0.32rem 0.5rem;
    border: 1px solid #deded5;
    border-radius: 8px;
    background: linear-gradient(170deg, #fafaf6, #f4f3ec);
  }
  .today-card .stat-label { font-size: 0.63rem; }
  .today-card .stat-value { font-size: 0.92rem; }
  .today-card .stat-value .rain-day-share { margin-left: 0.55rem; font-size: 0.72em; font-weight: 700; }
  .today-card .stat-note  { font-size: 0.64rem; }

  /* ── compare hint ── */
  .compare-hint {
    font-size: 0.72rem;
    color: #8a8a80;
    margin-bottom: 0.1rem;
  }

  /* ── responsive ── */
  @media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .today-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }
  @media (max-width: 640px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .today-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .range-group { margin-left: 0; }
    .sep { display: none; }
  }
