.chart-card{
  background:#fff;
  border-radius:14px;
  box-shadow:0 6px 24px rgba(16,24,40,.06);
  padding:16px;
  position:relative;
  height:auto;
  min-height:420px;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-direction:column;
  gap:8px;
  margin: 24px auto;
  max-width: 1200px;
  border: 1px solid var(--card-border-color);
}
.chart-card canvas{
  width:100%;
  display:block;
  max-height:360px;
}
.chart-shell {
  position: relative;
  min-height: 280px;
}
.chart-shell canvas {
  display: block;
  width: 100%;
}
.chart-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--surface-2, rgba(0,0,0,.06));
  border-radius: inherit;
  transition: opacity .2s ease;
  opacity: .9;
  pointer-events: none;
  font-size: .95rem;
}
.chart-shell.is-ready .chart-loader {
  opacity: 0;
  visibility: hidden;
}
.html-legend ul{
  margin: 0;
  padding: 0;
  list-style: none;
  align-self: stretch;
}
.html-legend li{
  display: grid;
  grid-template-columns: 18px 1fr;
  column-gap: 12px;
  align-items: center;
  line-height: 1.4;
  padding: 5px 4px;
  border-radius: 8px;
  transition: opacity .18s ease, background-color .18s ease;
  user-select: none;
}
@media(hover: hover) {
  .html-legend li:hover { background: rgba(63,81,181,.06); }
}
.html-legend .swatch{
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.html-legend li.is-off,
.html-legend li.is-empty { opacity: .5; }
.html-legend li.is-off span:last-child,
.html-legend li.is-empty span:last-child {
  text-decoration: line-through;
  color: #aaa;
}
.html-legend li.is-off .swatch,
.html-legend li.is-empty .swatch {
  opacity: .5;
  filter: grayscale(.8);
}
.html-legend{
  max-width: none;
  width: 100%;
  margin: 12px 0 0;
  text-align: left;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#legendStrength ul,
#legendChapter ul{
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  column-gap: 24px;
  row-gap: 6px;
  align-items: start;
  align-self: stretch;
}
@media (max-width: 1280px){
  #legendStrength ul, #legendChapter ul{
    grid-template-columns: repeat(4, minmax(140px, 1fr));
  }
}
@media (max-width: 1024px){
  #legendStrength ul, #legendChapter ul{
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }
}
@media (max-width: 900px){
  #legendStrength ul, #legendChapter ul{
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}
@media (max-width: 600px){
  #legendStrength ul, #legendChapter ul{
    grid-template-columns: 1fr;
  }
}
@media (max-width: 900px){
  .chart-card{
    height: auto;
    min-height: unset;
    max-height: unset;
    overflow: hidden;
    gap: 24px;
    margin: 24px auto;
  }
  .chart-card canvas{
    height: 300px;
    min-height: 220px;
  }
  .html-legend{
    max-width: none;
    margin: 10px 16px 0;
  }
}
@media (max-width: 480px){
  .chart-card canvas{ height: 260px; }
}
.subcharts-grid{
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 12px;
  margin-top: 12px;
}
.subchart-card{
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(16,24,40,.06);
  padding: 10px 12px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--card-border-color);
}
.subchart-card canvas{
  width: 100%;
  height: 140px;
  display: block;
}
@media (max-width: 900px){
  .subcharts-grid{ grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 600px){
  .subcharts-grid{ grid-template-columns: 1fr; }
  .subchart-card canvas{ height: 160px; }
  .chart-card {
    margin: 16px auto;
    padding: 12px;
  }
}
.chart-inline-info{
  margin-top: 12px;
  color: #6b7280;
  font-size: 14px;
  text-align: center;
}
.chart-settings-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-card);
  background-color: var(--bg-pill);
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color 0.2s ease, transform 0.2s ease;
  font-size: 20px;
  line-height: 1;
}
@media (hover: hover) {
  .chart-settings-toggle:hover {
    background-color: #e9edf9;
  }
}
.chart-settings-toggle:active {
  transform: scale(0.95);
}
.chart-settings-toggle.is-spinning {
  animation: settings-spin 2s linear infinite;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
}
.settings-row > span:first-child {
  flex-grow: 1;
  padding-right: 12px;
  line-height: 1.3;
}
.settings-row .legend-row-title {
  opacity: 1;
  margin-right: 1rem;
  flex-grow: 1;
}
.settings-row.settings-display-title {
  justify-content: center;
  font-weight: bold;
}
.settings-row.settings-display-title > span {
  flex-grow: 1;
  width: 100%;
  text-align: center;
}
.settings-row.is-disabled {
  opacity: 0.5;
}
.settings-row.is-disabled input {
  pointer-events: none;
}
#pieStrength, #pieChapter {
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.chart-card canvas,
.chart-card canvas:focus,
.chart-card canvas:focus-visible{
  outline: none !important;
  border: 0 !important;
}
.chart-card {
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-card);
}
.subchart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  box-shadow: 0 4px 14px rgba(16,24,40,.06);
}
.chart-settings-toggle {
  border: 1px solid var(--border-card);
  background-color: var(--bg-pill);
}
.chartjs-html-tooltip {
  position: absolute;
  pointer-events: auto;
  z-index: 9999;
  background-color: rgba(17, 24, 39, 0.95);
  color: #d1d5db;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 280px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  white-space: normal;
}
.chartjs-html-tooltip .tooltip-title {
  font-weight: bold;
  margin-bottom: 4px;
}
.chartjs-html-tooltip .tooltip-value {
  font-weight: normal;
  margin-bottom: 8px;
}
.chartjs-html-tooltip .tooltip-names-header {
  font-weight: bold;
  margin-bottom: 4px;
}
.chartjs-html-tooltip .tooltip-names-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: scroll;
  scrollbar-width: none;
}
.chartjs-html-tooltip .tooltip-names-wrapper {
  position: relative;
  max-height: 200px;
  padding-right: 6px;
}
.chartjs-html-tooltip .tooltip-names-wrapper .tooltip-names-list {
  margin-right: 0;
}
.chartjs-html-tooltip .scroll-indicator {
  position: absolute;
  right: 0;
  top: 0;
  width: 3px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 2px;
  display: none;
}
.chartjs-html-tooltip .tooltip-names-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.chartjs-html-tooltip .tooltip-names-list::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 0;
}
.chartjs-html-tooltip .tooltip-names-list::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 0;
}
.chartjs-html-tooltip .tooltip-names-list li {
  margin-bottom: 2px;
}
.html-legend ul {
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
}
.html-legend.is-hidden ul {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}
.reload-badge {
  margin-left: 8px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: var(--bg-pill);
  color: var(--brand);
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease, transform 0.1s ease;
  padding-bottom: 3px;
  box-sizing: border-box;
}
@media (hover: hover) {
  .reload-badge:hover { background: var(--bg-pill-hover); }
}
.reload-badge:active { transform: scale(0.92); }
@keyframes reload-spin { to { transform: rotate(360deg); } }
.reload-badge.spin { animation: reload-spin .5s linear 1; }
