:root {
  --ink: #292448;
  --muted: #706b89;
  --purple: #6c5ce7;
  --purple-dark: #5142c7;
  --pink: #fd79a8;
  --yellow: #ffd166;
  --mint: #55d6be;
  --red: #e95768;
  --paper: #ffffff;
  --border: #dfd9f4;
  --shadow: 0 18px 50px rgba(67,49,134,.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(253,121,168,.17), transparent 26%),
    radial-gradient(circle at 92% 14%, rgba(85,214,190,.18), transparent 25%),
    radial-gradient(circle at 50% 100%, rgba(255,209,102,.2), transparent 30%),
    #f5f2ff;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

button, select { font: inherit; }
.hidden { display: none !important; }
.metrics-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 60px; }
.metrics-nav { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.metrics-nav a { padding: 9px 13px; color: var(--purple); border-radius: 12px; background: rgba(255,255,255,.76); font-size: .9rem; font-weight: 900; text-decoration: none; }
.metrics-nav a:hover { background: white; }
.metrics-hero { display: flex; align-items: center; gap: 20px; margin-bottom: 26px; }
.metrics-hero img { width: 112px; height: 112px; border: 4px solid white; border-radius: 32px; object-fit: cover; box-shadow: var(--shadow); transform: rotate(-3deg); }
.eyebrow { margin: 0 0 5px; color: var(--purple); font-size: .78rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(2.2rem, 6vw, 4rem); letter-spacing: -.055em; }
.metrics-hero p:last-child { margin-bottom: 0; color: var(--muted); font-weight: 800; }

.report-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding: 14px 16px; border: 1px solid rgba(255,255,255,.8); border-radius: 18px; background: rgba(255,255,255,.78); box-shadow: 0 8px 24px rgba(67,49,134,.08); }
.report-controls label { font-weight: 900; }
.report-controls select { min-width: 190px; height: 42px; padding: 0 12px; color: var(--ink); border: 2px solid var(--border); border-radius: 12px; background: white; }
.report-controls button { height: 42px; padding: 0 16px; color: white; border: 0; border-radius: 12px; background: var(--purple); font-weight: 900; cursor: pointer; }
.report-controls .delete-metrics-button { margin-left: auto; color: #9b2634; border: 2px solid #ffadb8; background: #fff0f2; }
.report-controls .delete-metrics-button:hover { background: #ffe0e5; }
.report-controls .delete-metrics-button.armed { color: white; border-color: var(--red); background: var(--red); animation: danger-pulse .8s infinite alternate; }
.metrics-status.warning { color: #8b4c00; background: #fff3cf; }
@keyframes danger-pulse { to { transform: scale(1.025); } }
.metrics-status { padding: 20px; color: var(--muted); border-radius: 18px; background: rgba(255,255,255,.78); font-weight: 900; text-align: center; }
.metrics-status.error { color: #9b2634; background: #ffe4e8; }
.metrics-content { display: grid; gap: 20px; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.summary-card { display: grid; min-height: 145px; align-content: center; gap: 5px; padding: 22px; border: 2px solid transparent; border-radius: 24px; background: white; box-shadow: 0 10px 28px rgba(67,49,134,.1); }
.summary-card span { color: var(--muted); font-weight: 900; }
.summary-card strong { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1; }
.summary-card small { font-weight: 800; }
.attempts-card { border-color: #d8d0ff; }
.correct-card { color: #176654; border-color: var(--mint); background: #e8fbf6; }
.failures-card { color: #9b2634; border-color: #ffadb8; background: #fff0f2; }
.time-card { color: #7a5100; border-color: var(--yellow); background: #fff9df; }

.charts-grid { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.6fr); gap: 20px; }
.chart-card, .detail-card { padding: clamp(20px, 4vw, 32px); border: 1px solid rgba(255,255,255,.85); border-radius: 28px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); }
.card-heading h2 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.035em; }
.donut-wrap { display: grid; place-items: center; gap: 22px; padding-top: 26px; }
.accuracy-donut { --accuracy-angle: 0deg; display: grid; width: 220px; height: 220px; place-items: center; border-radius: 50%; background: conic-gradient(var(--mint) 0 var(--accuracy-angle), #ffd5db var(--accuracy-angle) 360deg); box-shadow: inset 0 0 0 2px rgba(255,255,255,.8), 0 12px 28px rgba(67,49,134,.12); }
.accuracy-donut::before { content: ""; grid-area: 1 / 1; width: 145px; height: 145px; border-radius: 50%; background: white; }
.accuracy-donut > div { display: grid; z-index: 1; grid-area: 1 / 1; text-align: center; }
.accuracy-donut strong { font-size: 2.7rem; }
.accuracy-donut span { color: var(--muted); font-weight: 900; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; color: var(--muted); font-weight: 800; }
.legend-dot { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 50%; }
.correct-dot { background: var(--mint); }
.failure-dot { background: #ff9aaa; }

.tables-chart { display: grid; min-height: 300px; grid-template-columns: repeat(10, minmax(30px, 1fr)); align-items: end; gap: 10px; padding: 34px 4px 0; border-bottom: 2px solid var(--border); }
.table-bar { display: grid; height: 270px; grid-template-rows: 1fr auto; align-items: end; gap: 8px; text-align: center; }
.bar-track { display: flex; height: 230px; align-items: flex-end; border-radius: 12px 12px 4px 4px; background: #f0edf9; overflow: hidden; }
.bar-fill { width: 100%; min-height: 0; border-radius: 12px 12px 4px 4px; background: var(--mint); transition: height .35s ease; }
.bar-fill.medium { background: var(--yellow); }
.bar-fill.low { background: var(--red); }
.bar-fill.empty { background: #d8d3e8; }
.bar-label { font-weight: 900; }
.bar-value { display: block; margin-bottom: 4px; color: var(--muted); font-size: .75rem; font-weight: 900; }

.detail-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.detail-heading > p { max-width: 430px; margin-bottom: 0; color: var(--muted); font-size: .88rem; font-weight: 800; text-align: right; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 13px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; }
td { font-weight: 800; }
.table-name { color: var(--purple); font-size: 1.05rem; font-weight: 900; }
.metric-main { display: block; }
.metric-percent { color: var(--muted); font-size: .78rem; }
.accuracy-pill { display: inline-block; min-width: 66px; padding: 5px 9px; color: #176654; border-radius: 99px; background: #dffaf3; text-align: center; }
.accuracy-pill.low { color: #9b2634; background: #ffe4e8; }
.accuracy-pill.empty { color: var(--muted); background: #efedf5; }
.recommendation-heading { text-align: center; }
.recommendation-cell { text-align: center; }
.recommendation-toggle { width: 22px; height: 22px; accent-color: var(--purple); cursor: pointer; }
.recommendation-toggle:disabled { cursor: wait; opacity: .55; }

@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .metrics-shell { padding-top: 20px; }
  .metrics-hero { align-items: flex-start; }
  .metrics-hero img { width: 84px; height: 84px; border-radius: 25px; }
  .report-controls { align-items: stretch; flex-direction: column; }
  .report-controls select, .report-controls button { width: 100%; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 120px; }
  .tables-chart { gap: 5px; }
  .bar-value { font-size: .65rem; transform: rotate(-45deg); }
  .detail-heading { align-items: flex-start; flex-direction: column; }
  .detail-heading > p { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
