:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1c1e21;
  --muted: #666;
  --border: #dde1e6;
  --accent: #3b6fd6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1e2126;
    --text: #e8e9ec;
    --muted: #9aa0a8;
    --border: #2c3038;
    --accent: #6a9bff;
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0 1.5rem 3rem;
}

h1 { font-size: 1.4rem; margin: 1rem 0 0.5rem; }

.back-link {
  font-size: 0.9rem;
  font-weight: 400;
  margin-left: 1rem;
  color: var(--accent);
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }
h2 { font-size: 1.1rem; margin-top: 0; }
h3 { font-size: 0.95rem; color: var(--muted); }

.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding-top: 0.5rem;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.global-filters, .actions, .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin: 0.5rem 0;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.25rem 0;
}
.user-bar form { margin: 0; }

.action-group { display: flex; align-items: center; gap: 0.5rem; }

label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.2rem; }

select, input[type=date], input[type=number], input[type=file], button {
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.status-line { font-size: 0.85rem; color: var(--muted); }

.kpi-tiles {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.kpi-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  min-width: 120px;
}
.kpi-tile .value { font-size: 1.3rem; font-weight: 600; }
.kpi-tile .label { font-size: 0.75rem; color: var(--muted); }

.kpi-tile--pb {
  border-color: #ffb300;
  box-shadow: 0 0 0 2px rgba(255, 179, 0, 0.35);
  animation: kpi-pb-pulse 1.6s ease-in-out 2;
}
@keyframes kpi-pb-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.pb-badge {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #b8860b;
}
.pb-badge-inline { font-size: 0.85em; }

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; cursor: pointer; }

.crosstab-axes {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}
.practice-ranking-columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem 2rem;
}
@media (max-width: 700px) {
  .practice-ranking-columns { grid-template-columns: 1fr; }
}
.tag-checklist {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 160px;
}
.tag-checklist label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
}

canvas { max-width: 100%; }

.efficiency-rate strong { color: var(--muted); font-weight: 600; margin-right: 0.3rem; }

details.card > summary {
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  list-style: none;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}
details.card[open] > summary::before { transform: rotate(90deg); }
.other-stats-body {
  display: grid;
  gap: 1.25rem;
  margin-top: 1rem;
}
.other-stats-body .subsection + .subsection {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.miss-rate-cell { border-radius: 4px; padding: 0.1rem 0.4rem; }

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.trend-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  margin: -0.1rem -0.3rem;
}
.trend-legend-item:hover { background: var(--border); }
.trend-legend-item.legend-hidden {
  opacity: 0.4;
  text-decoration: line-through;
}
.trend-legend-swatch {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  flex: none;
}
.trend-good { color: #2e9e4f; font-weight: 600; }
.trend-bad { color: #d1493f; font-weight: 600; }
.trend-flat { color: var(--muted); }

.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  margin-left: 0.4rem;
  vertical-align: middle;
  user-select: none;
}

.info-icon .tooltip {
  display: none;
  position: absolute;
  top: 140%;
  left: 0;
  z-index: 100;
  width: 280px;
  max-width: min(280px, 70vw);
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 400;
  font-style: normal;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  white-space: normal;
  text-align: left;
}

.info-icon:hover .tooltip,
.info-icon:focus .tooltip,
.info-icon.pinned .tooltip {
  display: block;
}
