/* ===========================================================================
   Component styles: dashboard, map, heatmap, games, leaderboard, profile
   =========================================================================== */

/* ------------------------------------------------------- Dashboard layout */
.dash-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow-sm); margin-bottom: 26px; position: sticky; top: 84px; z-index: 40; }
.dash-toolbar label { font-weight: 700; font-size: .8rem; color: var(--ink-soft); }
.dash-toolbar select { padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-family: var(--font-body); font-weight: 600; background: #fff; color: var(--ink); }
.dash-toolbar .spacer { margin-left: auto; }

.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
@media (max-width: 980px){ .kpi-grid { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 560px){ .kpi-grid { grid-template-columns: 1fr;} }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); position: relative; transition: transform .25s var(--ease), box-shadow .25s; cursor: pointer; }
.kpi:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.kpi .kpi-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi .name { font-size: .82rem; font-weight: 700; color: var(--ink-soft); line-height: 1.3; max-width: 80%; }
.kpi .val { font-family: var(--font-display); font-size: 2.1rem; font-weight: 600; color: var(--ink); margin-top: 6px; line-height: 1; }
.kpi .val small { font-size: .9rem; color: var(--ink-soft); font-family: var(--font-body); }
.kpi .sub { font-size: .76rem; color: var(--ink-soft); margin-top: 4px; }
.kpi .spark { margin-top: 10px; position: relative; height: 38px; width: 100%; }
.kpi .spark canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.trend-pill { font-size: .72rem; font-weight: 800; padding: 3px 8px; border-radius: 100px; display: inline-flex; align-items: center; gap: 3px; }
.trend-improving { background: rgba(31,157,85,.14); color: #16713c; }
.trend-worsening { background: rgba(214,69,69,.14); color: var(--st-red); }
.trend-flat { background: rgba(196,186,166,.25); color: var(--ink-soft); }

/* ------------------------------------------------------- Africa map (SVG) */
.map-wrap { display: grid; grid-template-columns: 1.4fr .6fr; gap: 22px; align-items: start; }
@media (max-width: 900px){ .map-wrap { grid-template-columns: 1fr; } }
.map-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm); }
#africa-map { width: 100%; height: auto; }
#africa-map path { stroke: var(--paper); stroke-width: .6; fill: var(--st-nodata); transition: fill .4s, transform .15s, filter .15s; cursor: pointer; transform-box: fill-box; transform-origin: center; }
#africa-map path:hover { filter: brightness(1.08) saturate(1.2); stroke: var(--ink); stroke-width: 1; }
.map-tooltip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; padding: 9px 13px; border-radius: 10px; font-size: .82rem; font-weight: 600; z-index: 9000; opacity: 0; transition: opacity .15s; box-shadow: var(--shadow); }
.map-tooltip.show { opacity: 1; }
.map-tooltip .v { color: var(--gold-soft); font-weight: 800; }
.legend { display: flex; flex-direction: column; gap: 9px; }
.legend .lg-item { display: flex; align-items: center; gap: 10px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.legend .sw { width: 18px; height: 18px; border-radius: 5px; flex: none; }
.map-side h3 { margin-bottom: 4px; }
.map-rank { margin-top: 14px; }
.map-rank .row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .88rem; }
.map-rank .row b { color: var(--green); }

/* ------------------------------------------------------- Heatmap */
.heatmap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 6px; box-shadow: var(--shadow-sm); overflow: hidden; }
.hm-row { display: grid; grid-template-columns: 230px 1fr; gap: 0; border-bottom: 1px solid var(--line); }
.hm-row:last-child { border-bottom: none; }
.hm-asp { display: flex; align-items: center; gap: 10px; padding: 14px 16px; font-weight: 700; font-size: .9rem; }
.hm-asp .anum { width: 28px; height: 28px; border-radius: 8px; color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; flex: none; }
.hm-cells { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; align-content: center; }
.hm-cell { width: 30px; height: 30px; border-radius: 7px; position: relative; cursor: pointer; transition: transform .15s; display: grid; place-items: center; color: rgba(255,255,255,.92); font-size: .7rem; font-weight: 800; }
.hm-cell:hover { transform: scale(1.18); z-index: 5; box-shadow: var(--shadow); }
.hm-overall { width: 14px; height: 100%; min-height: 40px; border-radius: 4px; }
@media (max-width: 680px){ .hm-row { grid-template-columns: 1fr; } .hm-asp { border-bottom: 1px solid var(--line); } }

/* ------------------------------------------------------- Chart card */
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow-sm); }
.chart-box { position: relative; height: 340px; width: 100%; }
.flash-highlight { animation: flash-hi 2.2s ease; }
@keyframes flash-hi { 0%,100% { box-shadow: var(--shadow-sm); } 15% { box-shadow: 0 0 0 3px var(--gold), var(--shadow); } }
.chart-box canvas { position: absolute; inset: 0; }

/* ------------------------------------------------------- Moonshot tracker */
.moon-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 16px; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--line); }
.moon-row:last-child { border: none; }
.moon-num { width: 44px; height: 44px; border-radius: 12px; color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; }
.moon-row .title { font-weight: 700; font-size: .98rem; }
.moon-row .barwrap { margin-top: 8px; }
.moon-pct { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; color: var(--green); min-width: 64px; text-align: right; }

/* ------------------------------------------------------- Game cards */
.game-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); transition: transform .25s var(--ease), box-shadow .25s; display: flex; flex-direction: column; gap: 10px; position: relative; }
.game-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
.gc-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; color: #fff; }
.game-card .gc-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.xp-tag { background: var(--gold); color: var(--ink); font-weight: 800; font-size: .74rem; padding: 3px 9px; border-radius: 100px; display: inline-flex; align-items: center; gap: 4px; }

/* ------------------------------------------------------- Quiz */
.quiz-stage { max-width: 720px; margin: 0 auto; }
.quiz-progress { height: 8px; background: var(--paper-2); border-radius: 100px; overflow: hidden; margin-bottom: 24px; }
.quiz-progress > span { display: block; height: 100%; background: linear-gradient(90deg,var(--green),var(--gold)); transition: width .4s var(--ease); }
.q-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 30px; box-shadow: var(--shadow); }
.q-num { font-size: .78rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); }
.q-text { font-family: var(--font-display); font-size: 1.5rem; margin: 8px 0 22px; }
.opt { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; cursor: pointer; transition: all .18s; font-weight: 600; background: #fff; }
.opt:hover { border-color: var(--green); transform: translateX(3px); }
.opt .marker { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; transition: all .18s; }
.opt .marker svg { width: 15px; height: 15px; display: block; }
.opt.selected { border-color: var(--green); background: rgba(11,93,52,.05); }
.opt.selected .marker { background: var(--green); border-color: var(--green); color: #fff; }
.opt.correct { border-color: var(--st-green); background: rgba(31,157,85,.1); }
.opt.wrong { border-color: var(--st-red); background: rgba(214,69,69,.08); }
.q-explain { background: var(--paper-2); border-radius: var(--radius-sm); padding: 14px 16px; font-size: .9rem; margin-top: 10px; }
.quiz-result { text-align: center; }
.result-ring { width: 160px; height: 160px; margin: 0 auto 20px; }
.score-big { font-family: var(--font-display); font-size: 3.4rem; font-weight: 600; }

/* ------------------------------------------------------- Flashcards */
.flash-stage { max-width: 560px; margin: 0 auto; text-align: center; }
.flashcard { perspective: 1400px; height: 320px; margin-bottom: 22px; cursor: pointer; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .6s var(--ease); transform-style: preserve-3d; }
.flashcard.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius-lg); display: grid; place-items: center; padding: 36px; box-shadow: var(--shadow); }
.flash-front { background: linear-gradient(155deg, var(--green), var(--green-900)); color: #fff; }
.flash-front .ft { font-family: var(--font-display); font-size: 2rem; }
.flash-back { background: var(--card); border: 2px solid var(--gold); transform: rotateY(180deg); color: var(--ink); }
.flash-back .bk { font-size: 1.1rem; }
.flash-hint { font-size: .8rem; color: var(--ink-soft); }
.flash-controls { display: flex; justify-content: center; gap: 12px; }

/* ------------------------------------------------------- Matching */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; max-width: 760px; margin: 0 auto; }
.match-col h4 { text-transform: uppercase; letter-spacing: .1em; font-size: .76rem; color: var(--ink-soft); margin-bottom: 12px; font-family: var(--font-body); }
.match-item { padding: 14px 16px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; cursor: pointer; font-weight: 600; background: #fff; transition: all .15s; }
.match-item:hover { border-color: var(--green); }
.match-item.active { border-color: var(--gold); background: rgba(240,168,24,.12); box-shadow: 0 0 0 3px rgba(240,168,24,.18); }
.match-item.matched { border-color: var(--st-green); background: rgba(31,157,85,.1); color: #16713c; cursor: default; pointer-events: none; opacity: .8; }
.match-item.shake { animation: shake .35s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

/* ------------------------------------------------------- Scenario */
.scenario-stage { max-width: 700px; margin: 0 auto; }
.scenario-meter { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.scenario-meter .bar { flex: 1; height: 12px; background: var(--paper-2); border-radius: 100px; overflow: hidden; }
.scenario-meter .bar > span { display: block; height: 100%; background: linear-gradient(90deg,var(--red),var(--gold),var(--st-green)); transition: width .5s var(--ease); }
.choice { display: block; width: 100%; text-align: left; padding: 16px 20px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; cursor: pointer; font-weight: 600; font-size: 1rem; background: #fff; transition: all .18s; }
.choice:hover { border-color: var(--green); transform: translateX(4px); }
.feedback { padding: 14px 18px; border-radius: var(--radius-sm); margin: 14px 0; font-weight: 600; }
.feedback.good { background: rgba(31,157,85,.12); color: #16713c; }
.feedback.bad { background: rgba(214,69,69,.12); color: var(--st-red); }
.feedback.mid { background: var(--paper-2); color: var(--ink-soft); }

/* ------------------------------------------------------- Leaderboard */
.lb-tabs { display: inline-flex; background: var(--paper-2); border-radius: 100px; padding: 4px; margin-bottom: 24px; }
.lb-tabs button { border: none; background: none; padding: 9px 20px; border-radius: 100px; font-weight: 700; cursor: pointer; color: var(--ink-soft); font-family: var(--font-body); transition: all .2s; }
.lb-tabs button.active { background: var(--green); color: #fff; }
.lb-row { display: grid; grid-template-columns: 48px 1fr auto auto; gap: 14px; align-items: center; padding: 14px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; transition: transform .2s; }
.lb-row:hover { transform: translateX(4px); }
.lb-rank { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; color: var(--ink-soft); text-align: center; }
.lb-row.top1 { background: linear-gradient(120deg, rgba(240,168,24,.16), var(--card)); border-color: var(--gold); }
.lb-row.top1 .lb-rank { color: var(--gold); }
.lb-row.top2 .lb-rank { color: #9a9a9a; } .lb-row.top3 .lb-rank { color: #b06a2c; }
.lb-name { font-weight: 700; }
.lb-meta { font-size: .8rem; color: var(--ink-soft); }
.lb-xp { font-weight: 800; color: var(--green); }

/* ------------------------------------------------------- Badges & profile */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 16px; }
.badge { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 14px; transition: transform .25s; }
.badge:hover { transform: translateY(-4px); }
.badge.locked { opacity: .5; filter: grayscale(.7); }
.badge .bdg-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 10px; color: #fff; }
.badge .bdg-name { font-weight: 800; font-size: .9rem; }
.badge .bdg-desc { font-size: .76rem; color: var(--ink-soft); margin-top: 4px; }

.profile-head { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; background: linear-gradient(135deg, var(--green), var(--green-900)); color: #fff; border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.profile-head .kente { position: absolute; top: 0; left: 0; }
.profile-avatar { width: 96px; height: 96px; border-radius: 50%; background: var(--gold); color: var(--ink); display: grid; place-items: center; font-family: var(--font-display); font-size: 2.6rem; font-weight: 600; flex: none; box-shadow: 0 0 0 5px rgba(255,255,255,.18); }
.profile-head h2 { color: #fff; }
.level-bar { height: 12px; background: rgba(255,255,255,.2); border-radius: 100px; overflow: hidden; margin-top: 10px; max-width: 380px; }
.level-bar > span { display: block; height: 100%; background: var(--gold); border-radius: 100px; transition: width 1s var(--ease); }
.stat-mini { display: flex; gap: 26px; margin-top: 14px; flex-wrap: wrap; }
.stat-mini .sm { } .stat-mini .sm b { font-family: var(--font-display); font-size: 1.6rem; display: block; }
@media (max-width: 600px){ .profile-head { grid-template-columns: 1fr; text-align: center; } .profile-avatar { margin: 0 auto; } .stat-mini { justify-content: center; } .match-grid { grid-template-columns: 1fr 1fr; gap: 14px; } }

/* daily challenge */
.challenge-card { background: linear-gradient(135deg, var(--gold), #d98a00); color: var(--ink); border-radius: var(--radius-lg); padding: 30px; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.challenge-card h2 { color: var(--ink); }
.challenge-card .streak-flame { position: absolute; right: 20px; top: 20px; font-size: 2.4rem; }

/* pledge wall */
.pledge-grid { columns: 3 260px; column-gap: 16px; }
.pledge-note { break-inside: avoid; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.pledge-note .who { font-weight: 800; font-size: .88rem; margin-top: 8px; }
.pledge-note .where { font-size: .78rem; color: var(--ink-soft); }

/* timeline (flagship milestones) */
.timeline { position: relative; padding-left: 30px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 24px 8px; }
.tl-item::before { content: ""; position: absolute; left: -25px; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); border: 3px solid var(--st-nodata); }
.tl-item.done::before { border-color: var(--st-green); background: var(--st-green); }
.tl-item.in_progress::before { border-color: var(--gold); background: var(--gold); }
.tl-item .tl-year { font-weight: 800; color: var(--green); font-size: .85rem; }

/* country grid */
.country-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); transition: transform .2s, box-shadow .2s; }
.country-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: transparent; }
.country-card .flag { font-size: 1.8rem; }
.country-card .cn { font-weight: 700; font-size: .92rem; color: var(--ink); }
.country-card .cr { font-size: .76rem; color: var(--ink-soft); }

.loading { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.spinner { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
