/* Stage 4: compact history and performance layout for the 460px virtual canvas. */

@media (max-width: 767px) {
  html body .history-page .result-header {
    min-height: 62px;
    padding: 0.7rem 1rem;
    padding-top: calc(0.7rem + env(safe-area-inset-top));
    gap: 0.625rem;
  }

  html body .history-page .back-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  html body .history-page .result-title {
    font-size: 14px;
    line-height: 1.15;
  }

  html body .history-page .result-subtitle {
    margin-top: 2px;
    font-size: 10px;
    letter-spacing: 0.8px;
  }

  html body .history-page .history-page-body {
    gap: 0.65rem;
    padding: 0.75rem 1rem calc(1.25rem + env(safe-area-inset-bottom)) !important;
  }

  html body .history-page .history-page-summary {
    padding: 10px 12px;
    border-radius: 11px;
    font-size: 10px;
    line-height: 1.4;
  }

  html body .history-page .performance-card {
    padding: 12px 14px !important;
    border-radius: 14px !important;
  }

  html body .history-page .performance-head {
    align-items: center !important;
    gap: 10px !important;
    margin-bottom: 10px !important;
  }

  html body .history-page .performance-title {
    margin: 0 0 4px !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
    letter-spacing: 0.7px !important;
  }

  html body .history-page .performance-note {
    font-size: 9px !important;
    line-height: 1.3 !important;
  }

  html body .history-page .performance-badge {
    min-width: 56px !important;
    padding: 6px 8px !important;
    border-radius: 9px !important;
    font-size: 9px !important;
  }

  /* Six metrics: two rows of three equal columns. */
  html body .history-page .performance-grid,
  html body .history-page .perf-grid-ai6 {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
    align-items: stretch !important;
  }

  html body .history-page .performance-grid .perf-metric,
  html body .history-page .perf-grid-ai6 .perf-metric,
  html body .history-page .performance-grid .perf-metric:nth-child(1),
  html body .history-page .performance-grid .perf-metric:nth-child(2),
  html body .history-page .performance-grid .perf-metric:nth-child(3),
  html body .history-page .performance-grid .perf-metric:nth-child(4),
  html body .history-page .performance-grid .perf-metric:nth-child(5),
  html body .history-page .performance-grid .perf-metric:nth-child(6),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(1),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(2),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(3),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(4),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(5),
  html body .history-page .perf-grid-ai6 .perf-metric:nth-child(6) {
    grid-column: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 58px !important;
    padding: 8px 9px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: auto 1fr !important;
    gap: 5px 6px !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
  }

  html body .history-page .perf-metric span {
    grid-column: 1 / -1 !important;
    margin: 0 !important;
    font-size: 8px !important;
    line-height: 1.15 !important;
    letter-spacing: 0.45px !important;
    white-space: normal !important;
  }

  html body .history-page .perf-metric strong {
    grid-column: 1 !important;
    margin: 0 !important;
    font-size: 15px !important;
    line-height: 1 !important;
  }

  html body .history-page .perf-metric em {
    grid-column: 2 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 1 !important;
  }

  html body .history-page .history-panel.page-mode {
    padding: 0;
    border: 0;
    background: transparent;
  }

  html body .history-page .history-panel-title {
    margin: 0 0 7px;
    font-size: 10px;
    line-height: 1.2;
    letter-spacing: 0.65px;
  }

  html body .history-page .history-card {
    margin-bottom: 8px !important;
    padding: 10px 12px !important;
    border-radius: 12px !important;
  }

  html body .history-page .history-title {
    margin: 0 0 8px !important;
    font-size: 10px !important;
    line-height: 1.25 !important;
    letter-spacing: 0.55px !important;
  }

  /* AI4, CT6, BBFS8, BBFS9 stay in one equal-width row. */
  html body .history-page .history-card .eval-grid,
  html body .history-page .history-card .eval-grid.compact {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    margin: 0 0 7px !important;
    align-items: stretch !important;
  }

  html body .history-page .history-card .eval-grid .eval-pill,
  html body .history-page .history-card .eval-grid .eval-pill:nth-child(1),
  html body .history-page .history-card .eval-grid .eval-pill:nth-child(2),
  html body .history-page .history-card .eval-grid .eval-pill:nth-child(3),
  html body .history-page .history-card .eval-grid .eval-pill:nth-child(4) {
    grid-column: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 46px !important;
    padding: 6px 4px !important;
    gap: 3px !important;
    border-radius: 9px !important;
    box-sizing: border-box !important;
  }

  html body .history-page .history-card .eval-grid .eval-pill span {
    margin: 0 !important;
    font-size: 8px !important;
    line-height: 1 !important;
    letter-spacing: 0.45px !important;
  }

  html body .history-page .history-card .eval-grid .eval-pill strong {
    margin: 0 !important;
    font-size: 13px !important;
    line-height: 1 !important;
    letter-spacing: 0.2px !important;
  }

  html body .history-page .history-card .rank-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 5px !important;
    margin-top: 0 !important;
  }

  html body .history-page .history-card .rank-item {
    min-height: 32px;
    padding: 5px 4px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    border-radius: 8px;
    text-align: center;
  }

  html body .history-page .history-card .rank-item span {
    font-size: 7px;
    line-height: 1;
    letter-spacing: 0.4px;
  }

  html body .history-page .history-card .rank-item strong {
    font-size: 11px;
    line-height: 1;
  }

  html body .history-page .history-empty {
    padding: 1rem;
    border-radius: 12px;
    font-size: 10px;
  }
}
