.stats-summary {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.stats-summary > div {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-summary span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.stats-summary strong {
  display: block;
  color: var(--primary-dark);
  font-size: 1.35rem;
  line-height: 1.25;
}

.stats-help-text {
  margin: 0.55rem 0 0;
}

.stats-help-text a {
  color: var(--primary-dark);
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 0.2rem;
}

.stats-type-tabs {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.stats-type-button {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-weight: 900;
  box-shadow: var(--shadow);
}

.stats-type-button:hover,
.stats-type-button.active {
  border-color: #bfdbfe;
  background: #eef2ff;
  color: #3730a3;
}

.stats-trend-panel {
  margin-top: 1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-trend-panel summary {
  padding: 0.9rem 1rem;
  cursor: pointer;
  background: #eef2ff;
  color: #3730a3;
  font-size: 1.05rem;
  font-weight: 950;
  user-select: none;
}

.stats-trend-content {
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.stats-trend-controls {
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(0, 1fr);
  gap: 0.8rem;
  align-items: end;
  margin-bottom: 0.85rem;
}

.stats-trend-controls label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 850;
}

.stats-trend-controls select {
  min-height: 2.55rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
}

.stats-trend-range {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-weight: 750;
}

.stats-trend-chart-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
}

.stats-trend-chart-wrap canvas {
  display: block;
  width: 100%;
  min-width: 760px;
}

.stats-trend-legend {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.stats-trend-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.stats-trend-legend i {
  width: 1.4rem;
  height: 0.25rem;
  display: inline-block;
  border-radius: 999px;
}

.stats-trend-empty {
  margin: 0.85rem 0 0;
  padding: 1rem;
  color: var(--muted);
  border: 1px dashed #cbd5e1;
  border-radius: 1rem;
  text-align: center;
}

.stats-sections {
  display: grid;
  gap: 1rem;
}

.stats-section {
  margin-top: 1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-section h2 {
  margin: 0;
  padding: 0.85rem 1rem;
  background: #eef2ff;
  color: #3730a3;
  border-bottom: 1px solid var(--line);
  font-size: 1.1rem;
}

.stats-table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.stats-standard-table {
  min-width: 720px;
}

.stats-marks-table {
  min-width: 640px;
}

.stats-table th,
.stats-table td {
  padding: 0.78rem 0.85rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  word-break: break-word;
}

.stats-table th:first-child,
.stats-table td:first-child {
  width: 8.5rem;
  white-space: nowrap;
}

.stats-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 900;
}

.stats-table tbody th {
  color: var(--primary-dark);
}

.stats-table tr:last-child th,
.stats-table tr:last-child td {
  border-bottom: 0;
}

.stats-table th:last-child,
.stats-table td:last-child {
  border-right: 0;
}

.stats-tutorial-head {
  margin-top: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.stats-tutorial-title {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
}

.stats-back-link {
  color: var(--primary-dark);
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 0.2rem;
}

.stats-tutorial-card {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-tutorial-text {
  width: 100%;
  max-width: none;
  margin: 0;
  color: var(--text);
  font-size: 1.16rem;
  line-height: 1.9;
  text-align: left;
}

.stats-tutorial-text p {
  margin: 0.42rem 0;
}

.marks-content {
  padding: 1rem;
}

.marks-content p {
  color: var(--muted);
  line-height: 1.8;
}

.marks-content .stats-table-wrap + p,
.marks-content p + .stats-table-wrap {
  margin-top: 0.85rem;
}

.stats-empty {
  padding: 1rem;
  color: var(--muted);
}

html[data-theme="dark"] .stats-summary > div,
html[data-theme="dark"] .stats-section,
html[data-theme="dark"] .stats-type-button,
html[data-theme="dark"] .stats-tutorial-card,
html[data-theme="dark"] .stats-trend-panel,
html[data-theme="dark"] .stats-trend-controls select,
html[data-theme="dark"] .stats-trend-chart-wrap {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .stats-section h2,
html[data-theme="dark"] .stats-trend-panel summary {
  background: #1e3a5f !important;
  color: #bfdbfe !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .stats-help-text a,
html[data-theme="dark"] .stats-back-link {
  color: var(--primary-dark) !important;
}

html[data-theme="dark"] .stats-type-button:hover,
html[data-theme="dark"] .stats-type-button.active {
  background: #e8eefc !important;
  color: #312e81 !important;
  border-color: #bfdbfe !important;
}

html[data-theme="dark"] .stats-table th,
html[data-theme="dark"] .stats-table td {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .stats-table thead th {
  background: #111827 !important;
  color: var(--muted) !important;
}

html[data-theme="dark"] .stats-table tbody th {
  background: #111827 !important;
  color: #bfdbfe !important;
}

@media (max-width: 760px) {
  .stats-summary,
  .stats-type-tabs,
  .stats-trend-controls {
    grid-template-columns: 1fr;
  }
}
