/* ---- Matte-cartoon study-app theme -------------------------------------
   Reference vibe: Xmethod "Ask Buddy", LumaLing, Duolingo, Finch.
   Matte pastels, thick ink outlines, chunky rounded cards, hard shadows. */
:root {
  --bg:      #F5F0E1;   /* matte cream paper            */
  --panel:   #FFFDF5;   /* card surface                 */
  --panel2:  #EFE9D6;   /* inset / secondary surface    */
  --ink:     #211F1A;   /* outlines + text (not pure black) */
  --muted:   #6C6656;
  --lime:    #BFE455;   /* primary brand surface        */
  --lime-d:  #A6CF3C;
  --orange:  #F26A1F;   /* call-to-action               */
  --blue:    #5C8DEF;
  --pink:    #F0A9C6;
  --grape:   #9B7BE0;
  --good:    #6DBE45;
  --warn:    #F2A93B;
  --bad:     #E5564B;
  --radius:  16px;
  --shadow:  3px 3px 0 var(--ink);
  --shadow-lg: 5px 5px 0 var(--ink);
  --font: "Nunito", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Fredoka", var(--font);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font);
  background-image: radial-gradient(var(--panel2) 1px, transparent 1px);
  background-size: 22px 22px;
}
h1, h2, h3, .big { font-family: var(--display); font-weight: 600; letter-spacing: .2px; }

/* ---- header / nav ---- */
header {
  position: sticky; top: 0; z-index: 5; background: var(--lime);
  border-bottom: 3px solid var(--ink);
  padding: 12px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
h1 { font-size: 20px; margin: 0; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }
nav button {
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font: 600 14px var(--font);
  box-shadow: 2px 2px 0 var(--ink); transition: transform .05s;
}
nav button:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--ink); }
nav button:active { transform: translate(2px,2px); box-shadow: none; }
nav button.active { background: var(--orange); color: #fff; }
.health {
  margin-left: auto; font-size: 12px; font-weight: 700; color: var(--ink);
  background: var(--panel); border: 2px solid var(--ink); border-radius: 999px;
  padding: 4px 10px;
}
.health.bad { background: var(--bad); color: #fff; }

main { max-width: 880px; margin: 0 auto; padding: 24px 20px 90px; }
.view { display: none; }
.view.active { display: block; animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.98); opacity: 0 } to { transform: scale(1); opacity: 1 } }

/* ---- form controls ---- */
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
select, input, textarea {
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px;
  font: 600 14px var(--font);
}
label { font-weight: 700; display: flex; gap: 6px; align-items: center; }
button {
  cursor: pointer; font: 700 14px var(--font);
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 999px; padding: 9px 16px;
  box-shadow: var(--shadow); transition: transform .05s;
}
button:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow-lg); }
button:active { transform: translate(3px,3px); box-shadow: none; }
button.primary, #quiz-next, #sprint-start, #quiz-gen { background: var(--orange); color: #fff; }
#quiz-gen { background: var(--grape); }
button:disabled { opacity: .5; transform: none; box-shadow: var(--shadow); cursor: default; }
textarea { width: 100%; min-height: 150px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 500; }

/* ---- cards ---- */
.card {
  background: var(--panel); border: 3px solid var(--ink); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow-lg);
}
.card h3 { margin: 0 0 6px; font-size: 17px; }
.meta { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.tag {
  display: inline-block; background: var(--panel2); border: 2px solid var(--ink);
  border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 800;
  margin: 0 6px 6px 0;
}
.tag.lime { background: var(--lime); } .tag.blue { background: var(--blue); color: #fff; }
.tag.pink { background: var(--pink); } .tag.grape { background: var(--grape); color: #fff; }

.stem {
  white-space: pre-wrap; background: var(--panel2); padding: 15px;
  border-radius: 12px; border: 2px solid var(--ink); margin-bottom: 12px; font-weight: 500;
}

/* ---- mascot ---- */
.mascot { width: 74px; height: 74px; flex: none; }
.today-head { display: flex; align-items: center; gap: 14px; }
.speech {
  position: relative; background: var(--panel); border: 2px solid var(--ink);
  border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 13px;
}

/* ---- feedback ---- */
.fb { border: 3px solid var(--ink); border-radius: 14px; padding: 14px 16px; margin-top: 16px;
  background: var(--panel2); }
.fb .score { font-family: var(--display); font-size: 26px; font-weight: 600; }
.fb ul { margin: 6px 0 12px; padding-left: 20px; }
.fb .right li::marker { content: "✓  "; color: var(--good); }
.fb .missing li::marker { content: "▲  "; color: var(--warn); }
.fb .right li { color: #3f6e28; font-weight: 600; }
.fb .missing li { color: #9a6410; font-weight: 600; }
.fb .next { background: var(--lime); border: 2px solid var(--ink); padding: 10px 12px;
  border-radius: 10px; font-weight: 700; }

/* ---- bars / xp ---- */
.bar { height: 12px; background: var(--panel2); border: 2px solid var(--ink);
  border-radius: 999px; overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; background: var(--lime); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }

.topicrow { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; font-weight: 700; }
.topicrow .name { flex: 0 0 42%; color: var(--muted); }
.topicrow .bar { flex: 1; margin: 0; }
.weak { color: var(--bad); font-weight: 800; }

.day { display: flex; gap: 12px; padding: 9px 6px; border-bottom: 2px dashed var(--panel2); font-size: 13px; }
.day.today { background: var(--lime); border: 2px solid var(--ink); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow); }
.day .d { flex: 0 0 104px; color: var(--muted); font-weight: 800; }
.day .k { flex: 0 0 62px; font-weight: 800; text-transform: uppercase; font-size: 11px; }
.k.learn { color: var(--blue); } .k.timed { color: var(--orange); } .k.review { color: var(--good); }

.timer { font-family: var(--display); font-size: 20px; font-variant-numeric: tabular-nums;
  background: var(--panel); border: 2px solid var(--ink); border-radius: 999px; padding: 3px 12px; }
.timer.low { background: var(--bad); color: #fff; }

.big { font-size: 30px; }
.muted { color: var(--muted); font-weight: 700; }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 44px; margin-top: 8px;
  border-bottom: 2px solid var(--ink); }
.spark > i { width: 12px; background: var(--blue); border: 2px solid var(--ink);
  border-bottom: none; border-radius: 4px 4px 0 0; }
.loading { color: var(--muted); font-weight: 700; font-style: italic; }

/* ==== game layer ===================================================== */
.brandrow { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; flex: 1 1 100%; }
.hud { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel); border: 2px solid var(--ink); border-radius: 999px;
  padding: 3px 11px; font: 800 13px var(--font); box-shadow: 2px 2px 0 var(--ink);
  font-variant-numeric: tabular-nums;
}
.chip.coins { background: #FFE9A8; }
.chip.gems  { background: #BFE0FF; }
.chip.combo { background: var(--orange); color: #fff; }
.chip.rank  { background: var(--grape); color: #fff; }
.chip .pulse { animation: chippop .4s ease-out; }
@keyframes chippop { 0% { transform: scale(1) } 40% { transform: scale(1.35) } 100% { transform: scale(1) } }

/* reward toasts */
#toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 40;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast {
  background: var(--panel); border: 3px solid var(--ink); border-radius: 14px;
  padding: 10px 16px; box-shadow: var(--shadow-lg); font-weight: 800;
  animation: toastin .35s cubic-bezier(.2,1.4,.4,1); max-width: 300px;
}
.toast.big { background: var(--lime); font-size: 15px; }
.toast .sub { font-weight: 700; font-size: 12px; color: var(--muted); }
@keyframes toastin { from { transform: translateX(40px) scale(.8); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.out { animation: toastout .3s ease-in forwards; }
@keyframes toastout { to { transform: translateX(40px); opacity: 0 } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 39; display: none; }

/* quests */
.quest {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 2px solid var(--ink); border-radius: 12px; margin-bottom: 10px; background: var(--panel);
}
.quest.done { background: var(--lime); }
.quest.claimed { opacity: .55; }
.quest .qmain { flex: 1; }
.quest .qtitle { font-weight: 800; }
.quest .qbar { height: 9px; background: var(--panel2); border: 2px solid var(--ink);
  border-radius: 999px; overflow: hidden; margin-top: 5px; }
.quest .qbar > i { display: block; height: 100%; background: var(--blue); }
.quest .qreward { font-weight: 800; font-size: 12px; white-space: nowrap; }
.scope-label { font-family: var(--display); font-size: 15px; margin: 4px 0 10px; }

/* achievements */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px,1fr)); gap: 10px; }
.badge { text-align: center; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 6px;
  background: var(--panel2); }
.badge.on { background: var(--lime); }
.badge .ico { font-size: 26px; filter: grayscale(1); opacity: .4; }
.badge.on .ico { filter: none; opacity: 1; }
.badge .bn { font-weight: 800; font-size: 11px; margin-top: 4px; }
.badge .bd { font-size: 10px; color: var(--muted); font-weight: 700; }

/* paper mode */
.paperclock {
  font-family: var(--display); font-size: 64px; font-variant-numeric: tabular-nums;
  text-align: center; padding: 10px 0;
}
.paperphase { text-align: center; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.paperphase.reading { color: var(--blue); }
.paperphase.writing { color: var(--orange); }
.paperphase.done { color: var(--good); }
.paperclock.warn { color: var(--warn); }
.paperclock.crit { color: var(--bad); animation: flash .8s steps(1) infinite; }
@keyframes flash { 50% { opacity: .35 } }
.mark-grid { display: grid; grid-template-columns: 1fr 90px; gap: 8px 12px; align-items: center; margin: 6px 0; }
.mark-grid label { font-size: 13px; }
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.photo-strip img { width: 90px; height: 90px; object-fit: cover; border: 2px solid var(--ink); border-radius: 8px; }
.filebtn { display: inline-block; background: var(--blue); color: #fff; }
.evo { font-size: 13px; font-weight: 800; margin-top: 6px; }

/* ---- friends & group leaderboard ---- */
.chip.league { background: var(--lime); }
.lb-switch, .lb-glist, .lb-owner { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.lb-switch .chip, .lb-glist .chip {
  cursor: pointer; background: var(--panel); border: 2px solid var(--ink);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-weight: 700;
}
.lb-switch .chip.on, .lb-glist .chip.on { background: var(--lime); }
.lb-banner {
  background: var(--panel2); border: 2px solid var(--ink); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; font-weight: 600; margin: 8px 0;
}
.lb { display: grid; gap: 6px; margin: 10px 0; }
.lb-row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 10px;
  align-items: baseline; background: var(--panel2); border: 2px solid var(--ink);
  border-radius: 10px; padding: 8px 12px;
}
.lb-row.lb-me { background: var(--lime); }
.lb-rank { font-weight: 800; }
.lb-name { font-weight: 700; }
.lb-tr { font-size: 12px; color: var(--muted); }
.lb-xp { font-weight: 800; white-space: nowrap; }
.lb-side { grid-column: 2 / -1; font-size: 12px; color: var(--muted); font-weight: 700; }
.lb-row.lb-me .lb-side { color: var(--ink); }
.lb-pending { margin-top: 10px; }
.lb-req {
  display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap;
}
.lb-req span { flex: 1 1 auto; font-weight: 700; }
.lb-flist { margin-top: 8px; display: grid; gap: 4px; }
.lb-code { font-family: var(--display, inherit); letter-spacing: 1px; }

/* ---- monetization: plan chip, upgrade modal, locked cards ---- */
a.chip { text-decoration: none; cursor: pointer; }
.chip.plan { background: #FFE9A8; }
.chip.plan.plus { background: var(--orange); color: #fff; }

.modal-wrap {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center;
  justify-content: center; padding: 20px; background: rgba(33,31,26,.45);
  animation: toastin .2s ease-out;
}
.upgrade-modal {
  background: var(--panel); border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 22px 24px; max-width: 380px; text-align: center;
}
.upgrade-modal h3 { margin: 10px 0 6px; }
.upgrade-modal .um-badge {
  display: inline-block; background: var(--orange); color: #fff; font-weight: 800;
  border: 2px solid var(--ink); border-radius: 999px; padding: 2px 12px; font-size: 13px;
}
.upgrade-modal .um-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.upgrade-modal a.primary {
  background: var(--orange); color: #fff; text-decoration: none;
  border: 2px solid var(--ink); border-radius: 999px; padding: 9px 16px;
  font-weight: 800; box-shadow: var(--shadow);
}
.locked-card {
  background: var(--panel2); border: 2px dashed var(--ink); border-radius: 12px;
  padding: 12px 14px; margin: 8px 0;
}
.locked-card a.primary {
  display: inline-block; background: var(--orange); color: #fff; text-decoration: none;
  border: 2px solid var(--ink); border-radius: 999px; padding: 7px 14px;
  font-weight: 800; box-shadow: var(--shadow);
}
