/* PatternQuest — 3×3 matrix lesson */
:root {
  --bg0: #1a1140;
  --bg1: #2a1d63;
  --surface: #ffffff;
  --ink: #1f1840;
  --ink-soft: #6b6391;
  --line: #ece8fb;
  --brand: #7c4dff;
  --brand-d: #5a30d6;
  --gold: #ffc83d;
  --good: #23c16b;
  --bad: #ff5a6a;
  --r-lg: 26px;
  --r-md: 18px;
  --shadow: 0 18px 40px -18px rgba(20, 10, 60, 0.55);
  --font-d: "Fredoka", system-ui, sans-serif;
  --font-b: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-b);
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% -10%, #3a2680 0%, var(--bg1) 42%, var(--bg0) 100%);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 1280px; margin: 0 auto; padding: 14px 16px 16px;
  gap: 12px;
}

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.matrix-glyph {
  width: 38px; height: 38px; border-radius: 11px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px; flex: 0 0 auto;
  background: linear-gradient(135deg, #7c4dff, #f59e0b);
  box-shadow: 0 6px 16px -4px rgba(124,77,255,0.7), inset 0 0 0 3px rgba(255,255,255,.25);
}
.matrix-glyph span { background: rgba(255,255,255,0.85); border-radius: 3px; }
.brand-text { line-height: 1; }
.brand-name { font-family: var(--font-d); font-weight: 700; font-size: 22px; letter-spacing: .3px; }
.brand-sub  { font-size: 12px; font-weight: 700; color: #c9bdf6; text-transform: uppercase; letter-spacing: 1.4px; }

.hud { display: flex; align-items: center; gap: 16px; }
.progress { display: flex; gap: 7px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.22); transition: .3s; }
.dot.active { background: var(--gold); transform: scale(1.25); box-shadow: 0 0 0 4px rgba(255,200,61,.22); }
.dot.done { background: var(--good); }

.points {
  display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18); padding: 7px 14px 7px 10px; border-radius: 999px;
  color: #fff; font-family: var(--font-d); font-weight: 600; position: relative;
}
.points svg { width: 22px; height: 22px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }
.points #points { font-size: 19px; min-width: 22px; text-align: center; }
.points.pop { animation: pop .45s ease; }
@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.18)} 100%{transform:scale(1)} }
.float-pts {
  position: absolute; right: 14px; top: -6px; color: var(--gold); font-family: var(--font-d);
  font-weight: 700; font-size: 18px; pointer-events: none; animation: floatUp 1s ease forwards;
}
@keyframes floatUp { 0%{opacity:0;transform:translateY(6px)} 20%{opacity:1} 100%{opacity:0;transform:translateY(-26px)} }

/* ---------- Stage ---------- */
.stage {
  position: relative; flex: 1 1 auto; min-height: 0;
  border-radius: var(--r-lg); overflow: hidden;
  background:
    radial-gradient(80% 70% at 50% 38%, rgba(124,77,255,.30), rgba(124,77,255,0) 70%),
    linear-gradient(180deg, #221858, #15103c);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.06);
  display: flex; align-items: center; justify-content: center;
}
#canvas { position: absolute; inset: 0; }
#canvas canvas { display: block; }
#confetti { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

/* ---------- Coach panel ---------- */
.coach {
  flex: 0 0 auto;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: 18px 22px; position: relative;
  display: flex; flex-direction: column; gap: 10px;
}
.step-label {
  font-family: var(--font-d); font-weight: 600; font-size: 13px; letter-spacing: .6px;
  color: var(--brand); text-transform: uppercase;
  background: #f1ecff; padding: 4px 12px; border-radius: 999px;
  display: inline-block;
}
.headline { font-family: var(--font-d); font-weight: 600; font-size: 26px; margin: 0; color: var(--ink); line-height: 1.1; }
.body { margin: 0; font-size: 17px; line-height: 1.45; color: var(--ink-soft); font-weight: 600; max-width: 70ch; }
.body b { color: var(--ink); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 4px; }

/* Rule chips shown in intro step */
.rule-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.rule-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px;
  border-radius: 12px; border: 2px solid var(--line); font-family: var(--font-d);
  font-weight: 600; font-size: 16px; color: var(--ink); background: #f7f5ff;
}
.rule-chip .dot-preview { width: 16px; height: 16px; border-radius: 4px; }

/* Answer option chips */
.opt-row { display: flex; gap: 10px; flex-wrap: wrap; }
.opt-chip {
  width: 72px; height: 72px; border-radius: 14px; border: 3px solid var(--line);
  background: #f7f5ff; cursor: pointer; display: grid; place-items: center;
  transition: transform .1s, border-color .1s, box-shadow .1s;
  position: relative; overflow: hidden;
}
.opt-chip:active { transform: scale(.94); }
.opt-chip.correct { border-color: var(--good); background: #e7faf0; box-shadow: 0 0 0 4px rgba(35,193,107,.2); }
.opt-chip.wrong   { border-color: var(--bad);  background: #ffeef0; animation: shake .4s ease; }
.opt-chip.disabled { pointer-events: none; opacity: .6; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 60%{transform:translateX(6px)} 80%{transform:translateX(-3px)} }

.feedback { font-family: var(--font-d); font-weight: 600; font-size: 17px; margin-top: 4px; min-height: 24px; }
.feedback.good { color: var(--good); }
.feedback.bad  { color: var(--bad); }

/* chunky buttons */
.btn {
  font-family: var(--font-d); font-weight: 600; font-size: 19px; letter-spacing: .2px;
  border: none; cursor: pointer; border-radius: 16px; padding: 14px 26px; color: #fff;
  background: var(--brand); position: relative; transition: transform .06s, filter .15s;
  box-shadow: 0 6px 0 0 var(--brand-d), 0 14px 22px -10px rgba(90,48,214,.7);
  min-height: 54px; display: inline-flex; align-items: center; gap: 10px;
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 0 var(--brand-d); }
.btn.secondary { background: #efeaff; color: var(--brand-d); box-shadow: 0 6px 0 0 #d6caff; }
.btn.secondary:active { box-shadow: 0 1px 0 0 #d6caff; }
.btn.good { background: var(--good); box-shadow: 0 6px 0 0 #149a52; }
.btn.good:active { box-shadow: 0 1px 0 0 #149a52; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.hint-text { font-size: 14px; color: var(--ink-soft); font-weight: 700; }
.spacer { flex: 1; }

/* quiz (re-used for final quiz) */
.q-text { font-family: var(--font-d); font-size: 19px; font-weight: 600; color: var(--ink); margin: 0 0 10px; }
.q-opts { display: flex; gap: 10px; flex-wrap: wrap; }
.q-opt {
  padding: 12px 20px; border-radius: 14px; border: 2px solid var(--line);
  background: #f7f5ff; cursor: pointer; font-family: var(--font-d); font-weight: 600;
  font-size: 17px; color: var(--ink); transition: .1s;
}
.q-opt:active { transform: scale(.97); }
.q-opt.correct { border-color: var(--good); background: #e7faf0; }
.q-opt.wrong   { border-color: var(--bad);  background: #ffeef0; }
.q-opt.disabled { pointer-events: none; }
.q-fb { font-family: var(--font-d); font-weight: 600; font-size: 16px; margin-top: 6px; min-height: 22px; }
.q-fb.good { color: var(--good); }
.q-fb.bad  { color: var(--bad);  }

/* finish */
.finish { text-align: center; align-items: center; }
.stars { display: flex; gap: 10px; justify-content: center; margin: 4px 0; }
.stars svg { width: 46px; height: 46px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px), (max-height: 620px) {
  .headline { font-size: 22px; }
  .body { font-size: 15.5px; }
  .btn { font-size: 17px; padding: 12px 20px; }
  .brand-sub { display: none; }
  .opt-chip { width: 60px; height: 60px; }
}
@media (max-height: 560px) {
  .coach { padding: 12px 18px; }
  .headline { font-size: 20px; }
}
