:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --accent:   #58a6ff;
  --green:    #3fb950;
  --yellow:   #d29922;
  --red:      #f85149;
  --purple:   #bc8cff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── header ── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 700; font-size: 18px; color: var(--accent); letter-spacing: -0.5px; }
.header-stats { display: flex; gap: 12px; flex: 1; }
.stat { font-size: 12px; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border); }
.header-tabs { display: flex; gap: 4px; }
.tab { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px 14px; border-radius: 6px; font-size: 13px; transition: .15s; }
.tab:hover { background: var(--border); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }
.refresh-btn { background: none; border: 1px solid var(--border); color: var(--muted); cursor: pointer; padding: 6px 14px; border-radius: 6px; font-size: 13px; transition: .15s; margin-left: 8px; }
.refresh-btn:hover { background: var(--border); color: var(--text); }

/* ── tab content ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── dashboard layout ── */
.dashboard-layout { display: flex; height: calc(100vh - 49px); overflow: hidden; }

aside {
  width: 220px; min-width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header { padding: 10px 14px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; border-bottom: 1px solid var(--border); }

.challenge-item {
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  transition: .1s;
}
.challenge-item:hover { background: rgba(88,166,255,.07); }
.challenge-item.active-challenge { background: rgba(88,166,255,.12); border-left: 3px solid var(--accent); }
.challenge-name { font-size: 12px; color: var(--text); }
.challenge-desc { font-size: 11px; color: var(--muted); }
.badge { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.badge.completed { background: var(--green); }
.badge.active { background: var(--accent); animation: pulse 2s infinite; }
.badge.attempted { background: var(--yellow); }
.badge.pending { background: var(--border); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

main { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* ── panels ── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.panel-title { font-weight: 600; font-size: 13px; margin-bottom: 10px; color: var(--accent); }

.goal-text { font-size: 13px; color: var(--muted); white-space: pre-wrap; max-height: 100px; overflow-y: auto; }

/* ── frames ── */
.frames-row { display: flex; gap: 10px; flex-wrap: wrap; }
.frames-row img { width: 180px; height: 180px; border-radius: 6px; border: 1px solid var(--border); object-fit: cover; cursor: pointer; transition: .15s; }
.frames-row img:hover { border-color: var(--accent); transform: scale(1.02); }
.no-frames { color: var(--muted); font-size: 13px; padding: 20px 0; }
.frames-label { font-size: 11px; color: var(--muted); margin-top: 2px; text-align: center; }

.score-bar-wrap { margin-top: 12px; }
.score-label { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.score-label span { color: var(--accent); font-weight: 600; font-size: 16px; }
.score-bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.score-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 4px; transition: width .5s ease; }

/* ── rubric ── */
.rubric-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.rubric-name { width: 180px; font-size: 12px; color: var(--text); }
.rubric-bar-wrap { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.rubric-bar-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width .4s ease; }
.rubric-pts { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ── results table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 6px 10px; text-align: left; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 500; }
td { padding: 6px 10px; border-bottom: 1px solid rgba(48,54,61,.5); vertical-align: top; }
tr:hover td { background: rgba(48,54,61,.4); }
.score-cell { font-weight: 600; }
.score-cell.high { color: var(--green); }
.score-cell.mid  { color: var(--yellow); }
.score-cell.low  { color: var(--red); }
.best-pill { display: inline-block; padding: 1px 7px; background: rgba(63,185,80,.15); color: var(--green); border-radius: 10px; font-size: 11px; }
.count { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 6px; }
.patterns { color: var(--red); font-size: 11px; }

/* ── shader code ── */
.shader-code { font-size: 11px; color: #a9b7c6; background: var(--bg); border-radius: 6px; padding: 12px; overflow-x: auto; max-height: 360px; font-family: "JetBrains Mono", "Fira Code", monospace; white-space: pre; border: 1px solid var(--border); }

/* ── challenges grid ── */
.challenges-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; padding: 20px; }
.challenge-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; cursor: pointer; transition: .15s; }
.challenge-card:hover { border-color: var(--accent); }
.challenge-card.completed { border-color: rgba(63,185,80,.35); }
.challenge-card.active-card { border-color: var(--accent); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-name { font-size: 13px; font-weight: 600; }
.card-score { font-size: 20px; font-weight: 700; color: var(--accent); }
.card-desc { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.card-meta { font-size: 11px; color: var(--muted); }
.phase-tag { font-size: 10px; padding: 2px 7px; border-radius: 10px; background: rgba(88,166,255,.15); color: var(--accent); }

/* ── skill doc ── */
.skill-wrap { max-width: 860px; margin: 0 auto; padding: 24px 20px; }
.skill-actions { display: flex; justify-content: flex-end; align-items: center; margin-bottom: 14px; }
.skill-note { font-size: 12px; color: var(--muted); }
.skill-content { font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; white-space: pre-wrap; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.7; }

/* ── retrospective ── */
.retro-wrap { max-width: 1000px; margin: 0 auto; padding: 24px 20px; }
.retro-loading { color: var(--muted); text-align: center; padding: 40px; }

.retro-hero {
  background: linear-gradient(135deg, rgba(88,166,255,.12), rgba(188,140,255,.12));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  margin-bottom: 24px;
  text-align: center;
}
.retro-hero h1 { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.retro-hero .retro-subtitle { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.retro-kpis { display: flex; justify-content: center; gap: 32px; flex-wrap: wrap; }
.retro-kpi { text-align: center; }
.retro-kpi .kpi-value { font-size: 36px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.retro-kpi .kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }

.retro-section { margin-bottom: 24px; }
.retro-section h2 {
  font-size: 16px; font-weight: 600; color: var(--accent);
  margin-bottom: 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.retro-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.retro-challenge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
}
.retro-challenge-card.completed { border-left: 3px solid var(--green); }
.retro-challenge-card.stuck { border-left: 3px solid var(--yellow); }
.retro-challenge-card .rc-name { font-size: 11px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.retro-challenge-card .rc-score { font-size: 22px; font-weight: 700; }
.retro-challenge-card .rc-score.high { color: var(--green); }
.retro-challenge-card .rc-score.mid { color: var(--yellow); }
.retro-challenge-card .rc-score.low { color: var(--red); }
.retro-challenge-card .rc-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.retro-challenge-card .rc-bar { height: 3px; background: var(--bg); border-radius: 2px; margin-top: 6px; }
.retro-challenge-card .rc-bar-fill { height: 100%; border-radius: 2px; }

.retro-sparkline { display: flex; align-items: flex-end; gap: 1px; height: 32px; margin-top: 6px; }
.retro-sparkline .spark-bar { flex: 1; min-width: 2px; max-width: 6px; border-radius: 1px 1px 0 0; }

.retro-insights { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.retro-insight-row { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.retro-insight-row:last-child { margin-bottom: 0; }
.retro-insight-icon { font-size: 18px; flex-shrink: 0; width: 28px; text-align: center; }
.retro-insight-text { font-size: 13px; color: var(--text); line-height: 1.5; }
.retro-insight-text strong { color: var(--accent); }

.retro-hardest { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.retro-hardest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.retro-hardest-card .hc-name { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.retro-hardest-card .hc-stats { font-size: 11px; color: var(--muted); }
.retro-hardest-card .hc-stats span { color: var(--accent); font-weight: 600; }

.retro-frames-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.retro-frame-group { text-align: center; }
.retro-frame-group img { width: 100px; height: 100px; border-radius: 6px; border: 1px solid var(--border); object-fit: cover; cursor: pointer; }
.retro-frame-group img:hover { border-color: var(--accent); }
.retro-frame-label { font-size: 10px; color: var(--muted); margin-top: 2px; }

.retro-patterns { list-style: none; }
.retro-patterns li { font-size: 12px; color: var(--text); padding: 4px 0; border-bottom: 1px solid rgba(48,54,61,.3); display: flex; justify-content: space-between; }
.retro-patterns li:last-child { border-bottom: none; }
.retro-patterns .pat-count { color: var(--red); font-weight: 600; font-size: 11px; }

/* ── share draft ── */
.share-wrap { max-width: 700px; margin: 0 auto; padding: 24px 20px; }
.share-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.share-title { font-size: 14px; font-weight: 600; color: var(--accent); }
.copy-btn {
  background: var(--accent); color: #fff; border: none; padding: 6px 16px;
  border-radius: 6px; font-size: 13px; cursor: pointer; transition: .15s;
}
.copy-btn:hover { opacity: .85; }
.copy-btn.copied { background: var(--green); }
.share-textarea {
  width: 100%; min-height: 480px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.7; resize: vertical;
}

/* ── lightbox ── */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100; align-items: center; justify-content: center; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
.lightbox-close { position: absolute; top: 20px; right: 24px; font-size: 28px; color: #fff; cursor: pointer; }
