/* Nuqta and her board. Self-contained so it can sit on top of any page (the Sinov app and the
   econometrics prep site). Colours fall back to literals when the host page has no tokens. */

/* ================= Nuqta herself ================= */
svg.nq { overflow: visible; --lx: 0px; --ly: 0px; }
svg.nq[data-poke] { cursor: pointer; pointer-events: auto; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
svg.nq .nq-shadow { fill: #000; opacity: .13; transform-box: fill-box; transform-origin: center; }
svg.nq .nq-all { transform-box: fill-box; transform-origin: 50% 100%; }
svg.nq .nq-look { transform: translate(var(--lx), var(--ly)); transition: transform .12s ease-out; }
svg.nq .nq-eyes { transform-box: fill-box; transform-origin: center; animation: nq-blink 5.2s infinite; }
svg.nq .nq-arm { transform-box: fill-box; transform-origin: 20% 60%; }
svg.nq .bl, svg.nq .br { transform-box: fill-box; transform-origin: center; transition: transform .2s; opacity: 0; }
svg.nq .nq-cheeks { transition: opacity .25s; }
@keyframes nq-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }

/* which eyes and mouth show, per mood */
svg.nq .e-arcs, svg.nq .e-x, svg.nq .m-grin, svg.nq .m-o, svg.nq .m-flat, svg.nq .m-talk { display: none; }
svg.nq[data-mood="cheer"] .e-dots, svg.nq[data-mood="dizzy"] .e-dots { display: none; }
svg.nq[data-mood="cheer"] .e-arcs, svg.nq[data-mood="dizzy"] .e-x { display: inline; }
svg.nq[data-mood="cheer"] .m-smile, svg.nq[data-mood="wow"] .m-smile, svg.nq[data-mood="worry"] .m-smile, svg.nq[data-mood="dizzy"] .m-smile, svg.nq[data-mood="curious"] .m-smile { display: none; }
svg.nq[data-mood="cheer"] .m-grin, svg.nq[data-mood="wow"] .m-o, svg.nq[data-mood="dizzy"] .m-o, svg.nq[data-mood="worry"] .m-flat, svg.nq[data-mood="curious"] .m-flat { display: inline; }
svg.nq[data-mood="cheer"] .nq-cheeks, svg.nq[data-mood="wow"] .nq-cheeks { opacity: .5; }
svg.nq[data-mood="wow"] .e-dots { transform: scale(1.18); transform-box: fill-box; transform-origin: center; }
svg.nq[data-mood="wow"] .bl, svg.nq[data-mood="wow"] .br { opacity: 1; transform: translateY(-3px); }
svg.nq[data-mood="worry"] .bl { opacity: 1; transform: rotate(-16deg); } svg.nq[data-mood="worry"] .br { opacity: 1; transform: rotate(16deg); }
svg.nq[data-mood="curious"] .bl { opacity: 1; transform: translateY(-3px) rotate(-10deg); } svg.nq[data-mood="curious"] .br { opacity: 1; }
svg.nq[data-mood="dizzy"] .nq-all { animation: nq-wobble .5s ease-in-out infinite alternate; }
svg.nq[data-mood="cheer"] .nq-arm { animation: nq-wave .35s ease-in-out infinite alternate; }
@keyframes nq-wobble { from { transform: rotate(-9deg); } to { transform: rotate(9deg); } }
@keyframes nq-wave { to { transform: rotate(-22deg); } }
/* talking: the mouth takes over while the window is speaking */
.tw.speaking svg.nq .nq-mouth > * { display: none !important; }
.tw.speaking svg.nq .m-talk { display: inline !important; transform-box: fill-box; transform-origin: center; animation: nq-talk .23s ease-in-out infinite alternate; }
@keyframes nq-talk { from { transform: scaleY(.25); } to { transform: scaleY(1.05); } }
/* poked: squash and spring back */
svg.nq.poked .nq-all { animation: nq-squish .5s cubic-bezier(.3, 1.6, .5, 1); }
svg.nq.poked .nq-shadow { animation: nq-shadow .5s ease-out; }
@keyframes nq-squish { 0% { transform: scale(1); } 25% { transform: scale(1.22, .7); } 55% { transform: scale(.9, 1.14); } 100% { transform: scale(1); } }
@keyframes nq-shadow { 25% { transform: scaleX(1.3); } }
svg.nq[data-poke]:hover .nq-all { transform: translateY(-1.5px); transition: transform .15s; }

.nq-say { position: fixed; z-index: 3000; max-width: 240px; padding: 8px 13px; border-radius: 16px 16px 16px 4px; background: #18233a; color: #fff; font: 500 .86rem "Lexend", system-ui, sans-serif; box-shadow: 0 6px 18px rgba(0, 0, 0, .28); animation: nq-pop .28s cubic-bezier(.2, 1.4, .4, 1) both; pointer-events: none; }
.nq-confetti { position: fixed; z-index: 3000; width: 8px; height: 12px; border-radius: 2px; pointer-events: none; animation: nq-burst 1s cubic-bezier(.15, .7, .4, 1) forwards; }
@keyframes nq-burst { to { transform: translate(var(--dx), calc(var(--dy) + 150px)) rotate(var(--rot)); opacity: 0; } }

/* ================= the window ================= */
.tw {
  --tw-surface: var(--surface, #fff); --tw-ink: var(--ink, #18233a); --tw-ink2: var(--ink-2, #47536a);
  --tw-line: var(--line, #d9e2ef); --tw-accent: var(--accent, #0d7f86); --tw-sun: var(--sun, #f4b63f);
  --tw-good: var(--good, #1a9a57); --tw-bad: var(--bad, #d9475a); --tw-warn: var(--warn, #c98100);
  --tw-soft: var(--surface-2, #f4f7fc);
  position: fixed; z-index: 1000; right: 20px; bottom: 20px; width: 420px; height: min(700px, calc(100dvh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--tw-surface); color: var(--tw-ink); border: 1px solid var(--tw-line); border-radius: 26px;
  box-shadow: 0 4px 10px rgba(10, 20, 40, .12), 0 24px 60px rgba(10, 20, 40, .3);
  font-family: "Lexend", "Segoe UI", system-ui, sans-serif; font-size: 14.5px; line-height: 1.45;
  transform-origin: var(--ox, 100%) var(--oy, 100%);
  animation: tw-in .45s cubic-bezier(.2, .9, .25, 1.1);
}
.tw.big { left: 50%; top: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%); width: min(780px, calc(100vw - 32px)); height: min(880px, calc(100dvh - 32px)); animation: none; }
.tw * { box-sizing: border-box; }
@keyframes tw-in { from { transform: scale(.08); opacity: 0; } }
@media (max-width: 640px) {
  .tw, .tw.big { left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important; width: auto; height: 92dvh; transform: none; border-radius: 26px 26px 0 0; transform-origin: 80% 100%; }
}
.tw button { font: inherit; color: inherit; cursor: pointer; }
.tw-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; cursor: grab; user-select: none; background: linear-gradient(180deg, color-mix(in srgb, var(--tw-sun) 20%, var(--tw-surface)), var(--tw-surface)); border-bottom: 1px solid var(--tw-line); }
.tw-head svg.face { width: 44px; height: 44px; flex: none; }
.tw-head .tt { flex: 1; min-width: 0; }
.tw-head .tt b { display: block; font-family: "Fredoka", "Lexend", sans-serif; font-weight: 600; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tw-head .tt span { font-size: .76rem; color: var(--tw-ink2); }
.tw-ib { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border: 1px solid var(--tw-line); background: var(--tw-soft); border-radius: 12px; transition: transform .08s; }
.tw-ib:hover { border-color: var(--tw-accent); }
.tw-ib:active { transform: scale(.92); }
.tw-ib svg { width: 19px; height: 19px; }
.tw-ib[aria-pressed="true"] { background: var(--tw-accent); border-color: var(--tw-accent); color: #fff; }
.tw-ib.rate { font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* board: squared paper */
.tw-board {
  flex: 1; min-height: 0; overflow-y: auto; position: relative; scroll-behavior: smooth;
  background-color: var(--tw-surface);
  background-image: linear-gradient(var(--tw-line) 1px, transparent 1px), linear-gradient(90deg, var(--tw-line) 1px, transparent 1px);
  background-size: 22px 22px; background-attachment: local;
}
.tw-sheet { position: relative; padding: 18px 60px 110px 18px; max-width: 620px; margin: 0 auto; }
.tw-step[hidden], .tw-blk.pending { display: none; }
.tw-blk { margin: 0 0 14px; font-family: "Caveat", "Segoe Print", cursive; font-size: 1.42rem; line-height: 1.22; color: var(--tw-ink); border-radius: 12px; transition: box-shadow .15s; }
.tw-step:not([data-i="end"]) .tw-blk { cursor: pointer; }
.tw-step:not([data-i="end"]) .tw-blk:hover { box-shadow: 0 0 0 3px color-mix(in srgb, var(--tw-sun) 55%, transparent); }
.tw-blk .katex { font-size: .78em; }
.tw-blk b { font-weight: 700; }
.tw-blk.b-heading { font-size: 1.9rem; font-weight: 700; }
.tw-blk.b-heading::after { content: ""; display: block; height: 4px; margin-top: 2px; width: 100%; border-radius: 4px; background: var(--tw-sun); transform-origin: left; }
.tone-key { color: var(--tw-accent); } .tone-good { color: var(--tw-good); } .tone-bad { color: var(--tw-bad); } .tone-warn { color: var(--tw-warn); }
.tw-blk.b-note.tone-key, .tw-blk.b-note.tone-warn { font-weight: 700; }
.tw-blk.b-note.tone-key .hw::before { content: "★ "; } .tw-blk.b-note.tone-warn .hw::before { content: "! "; }
.tw-blk.b-box { position: relative; padding: 10px 14px 11px; color: var(--tw-ink); background: color-mix(in srgb, var(--tc, var(--tw-ink2)) 9%, var(--tw-surface)); }
.tw-blk.b-box.tone-good { --tc: var(--tw-good); } .tw-blk.b-box.tone-bad { --tc: var(--tw-bad); } .tw-blk.b-box.tone-key { --tc: var(--tw-accent); } .tw-blk.b-box.tone-warn { --tc: var(--tw-warn); }
.tw-blk.b-box .bt { font-weight: 700; color: var(--tc, var(--tw-ink)); }
.tw-blk.b-box::before { content: ""; position: absolute; inset: 0; border: 2px solid var(--tc, var(--tw-ink2)); border-radius: 12px 15px 11px 16px; pointer-events: none; }
.tw-blk.b-formula { text-align: center; padding: 6px 0; overflow-x: auto; }
.tw-blk.b-formula .katex { font-size: .95em; }
.tw-blk.b-formula .cap { font-size: 1.15rem; color: var(--tw-ink2); }
.tw-blk.b-table { overflow-x: auto; }
.tw-blk.b-table table { border-collapse: collapse; width: 100%; font-size: 1.25rem; background: var(--tw-surface); }
.tw-blk.b-table th, .tw-blk.b-table td { border: 1.5px solid var(--tw-ink2); padding: 3px 9px; text-align: center; }
.tw-blk.b-table th { background: color-mix(in srgb, var(--tw-accent) 14%, var(--tw-surface)); }
.tw-blk.b-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 4px; }
.tw-blk.b-flow .fi { border: 2px solid var(--tw-accent); border-radius: 12px; padding: 2px 11px; background: color-mix(in srgb, var(--tw-accent) 9%, var(--tw-surface)); }
.tw-blk.b-flow .fa { color: var(--tw-accent); font-weight: 700; }
.tw-blk.b-plot svg { width: 100%; height: auto; display: block; overflow: visible; }
.tw-blk.b-plot .tw-ax { stroke: var(--tw-ink); stroke-width: 2; fill: none; stroke-linecap: round; }
.tw-blk.b-plot text { font-family: "Caveat", cursive; font-size: 17px; fill: var(--tw-ink2); }
.tw-blk.b-plot .ttl { font-size: 1.3rem; font-weight: 700; }
.tw-blk.b-plot .lg { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 1.1rem; color: var(--tw-ink2); }
.tw-blk.b-plot .lg i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; }

/* the closing question */
.tw-blk.b-check { margin-top: 22px; padding: 13px 14px; border: 2px dashed var(--tw-sun); border-radius: 16px; background: color-mix(in srgb, var(--tw-sun) 14%, var(--tw-surface)); }
.tw-blk.b-check small { display: block; font-family: "Lexend", sans-serif; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--tw-ink2); }
.ck-opts { display: grid; gap: 8px; margin-top: 10px; }
.ck-opts button { text-align: left; padding: 7px 13px; border-radius: 13px; border: 2px solid var(--tw-line); background: var(--tw-surface); font-family: "Caveat", cursive; font-size: 1.3rem; line-height: 1.2; box-shadow: 0 3px 0 var(--tw-line); transition: transform .08s; }
.ck-opts button:not(:disabled):hover { border-color: var(--tw-accent); }
.ck-opts button:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--tw-line); }
.ck-opts button.ok { border-color: var(--tw-good); background: color-mix(in srgb, var(--tw-good) 16%, var(--tw-surface)); box-shadow: 0 3px 0 var(--tw-good); }
.ck-opts button.no { border-color: var(--tw-bad); background: color-mix(in srgb, var(--tw-bad) 14%, var(--tw-surface)); box-shadow: 0 3px 0 var(--tw-bad); animation: tw-shake .35s; }
.ck-opts button.dim { opacity: .55; }
.ck-opts button:disabled { cursor: default; }
.ck-why { margin-top: 10px; font-family: "Lexend", sans-serif; font-size: .92rem; line-height: 1.45; animation: tw-fade .3s ease-out; }
@keyframes tw-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* drawing-in: lines are wiped left to right as if written; frames and curves are traced */
.tw-blk.draw .hw { animation: tw-write .7s linear both; animation-delay: calc(var(--i, 0) * .32s); }
@keyframes tw-write { from { clip-path: inset(-10% 100% -10% 0); } to { clip-path: inset(-10% -2% -10% 0); } }
.tw-blk.draw.b-heading::after { animation: tw-grow .5s .35s ease-out both; }
@keyframes tw-grow { from { transform: scaleX(0); } }
.tw-blk.draw .trace { animation: tw-trace var(--dur, .9s) ease-in-out both; }
.tw-blk.draw.b-box::before { animation: tw-write .8s ease-in-out both; }
@keyframes tw-trace { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.tw-blk.draw .tw-dot { animation: tw-pop .3s ease-out both; animation-delay: calc(var(--i, 0) * .07s + .2s); transform-box: fill-box; transform-origin: center; }
@keyframes tw-pop { from { transform: scale(0); opacity: 0; } }
.tw-blk.draw .rise { animation: tw-rise .5s ease-out both; animation-delay: calc(var(--i, 0) * .12s + .2s); transform-box: fill-box; transform-origin: bottom; }
@keyframes tw-rise { from { transform: scaleY(0); } }
.tw-blk.draw .fade { animation: tw-fade .35s ease-out both; animation-delay: calc(var(--i, 0) * .28s); }
@keyframes tw-fade { from { opacity: 0; transform: translateY(5px); } }

/* Nuqta on the board, next to what she is drawing */
.tw-pointer { position: absolute; right: 4px; top: 0; width: 54px; height: 54px; transition: transform .55s cubic-bezier(.3, .8, .3, 1); filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .2)); }
.tw-pointer svg { width: 100%; height: 100%; }
.tw-pointer.hop svg { animation: tw-hop .45s ease-out; }
.tw-pointer.jump svg { animation: tw-jump .9s cubic-bezier(.3, 1.4, .5, 1); }
.tw.speaking .tw-pointer svg .nq-arm { animation: nq-write .28s ease-in-out infinite alternate; }
@keyframes tw-hop { 40% { transform: translateY(-9px) rotate(-6deg); } }
@keyframes tw-jump { 30% { transform: translateY(-26px) rotate(-14deg) scale(1.15); } 60% { transform: translateY(0) rotate(8deg); } 80% { transform: translateY(-10px); } }
@keyframes nq-write { from { transform: rotate(-7deg); } to { transform: rotate(9deg) translateY(1.5px); } }

/* what she is saying: the spoken words fill in as she goes */
.tw-caption { position: relative; margin: 0 12px; padding: 10px 14px; border-radius: 16px; background: var(--tw-soft); border: 1px solid var(--tw-line); font-weight: 500; text-align: center; min-height: 2.7em; transform: translateY(-10px); box-shadow: 0 6px 16px rgba(10, 20, 40, .1); }
.tw-caption:empty { display: none; }
.tw-caption span { color: color-mix(in srgb, var(--tw-ink) 42%, transparent); transition: color .12s; }
.tw-caption span.said { color: var(--tw-ink); }
.tw-foot { padding: 0 12px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }
.tw-segs { display: flex; gap: 4px; }
.tw-segs i { flex: 1; height: 7px; border-radius: 7px; background: var(--tw-line); cursor: pointer; transition: background .2s; }
.tw-segs i:hover { background: color-mix(in srgb, var(--tw-accent) 45%, var(--tw-line)); }
.tw-segs i.on { background: var(--tw-accent); }
.tw-ctl { display: flex; gap: 8px; align-items: center; justify-content: center; }
.tw-ctl .tw-ib.play { width: 52px; height: 48px; background: var(--tw-accent); border-color: var(--tw-accent); color: #fff; border-radius: 16px; box-shadow: 0 4px 0 color-mix(in srgb, var(--tw-accent) 62%, #000); }
.tw-ctl .tw-ib.play:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--tw-accent) 62%, #000); }
.tw-quick { display: none; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tw.done .tw-quick { display: flex; }
.tw-quick button { flex: none; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--tw-line); background: var(--tw-soft); font-size: .8rem; font-weight: 500; }
.tw-quick button:hover { border-color: var(--tw-accent); color: var(--tw-accent); }
.tw-ask { display: flex; gap: 6px; min-width: 0; }
.tw-ask input { flex: 1; min-width: 0; height: 40px; border-radius: 13px; border: 1px solid var(--tw-line); background: var(--tw-soft); color: inherit; padding: 0 13px; font: inherit; }
.tw-ask input:focus { outline: 2px solid var(--tw-accent); outline-offset: 1px; }
.tw-tip { margin: 0; font-size: .74rem; color: var(--tw-ink2); text-align: center; }

.tw-wait { flex: 1; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center; padding: 20px; }
.tw-wait svg.nq { width: 110px; height: 110px; animation: tw-think 1.1s ease-in-out infinite alternate; }
.tw-wait svg.nq .nq-arm { animation: nq-write .25s ease-in-out infinite alternate; }
@keyframes tw-think { from { transform: translateY(0) rotate(-5deg); } to { transform: translateY(-10px) rotate(5deg); } }
.tw-wait b { font-family: "Fredoka", sans-serif; font-size: 1.15rem; }
.tw-wait p { margin: 0; color: var(--tw-ink2); max-width: 30ch; }
.tw-wait .scribble { width: 130px; height: 22px; }
.tw-wait .scribble path { fill: none; stroke: var(--tw-accent); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 1; animation: tw-trace 1.6s ease-in-out infinite alternate; }
.tw-wait.err svg.nq, .tw-wait.err svg.nq .nq-arm { animation: none; }
.tw-wait.err .scribble { display: none; }

.tw-script { position: absolute; inset: 65px 0 0; background: var(--tw-surface); overflow-y: auto; padding: 14px; z-index: 2; }
.tw-script h4 { margin: 0; font-family: "Fredoka", sans-serif; font-size: 1.1rem; }
.tw-script p { margin: 2px 0 12px; font-size: .8rem; color: var(--tw-ink2); }
.tw-script button { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 8px; border-radius: 12px; }
.tw-script button:hover, .tw-script button.cur { background: var(--tw-soft); }
.tw-script button span { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--tw-line); display: grid; place-items: center; font-size: .75rem; font-weight: 600; }
.tw-script button.cur span { background: var(--tw-sun); border-color: var(--tw-sun); color: #18233a; }

/* the "explain" chip Nuqta pops up in before flying into the window */
.nq-chip { display: inline-flex; align-items: center; gap: 10px; border: 0; background: var(--surface, #fff); color: var(--ink, #18233a); padding: 6px 16px 6px 8px; border-radius: 999px; font: 600 .92rem "Lexend", system-ui, sans-serif; text-align: left; cursor: pointer; box-shadow: 0 2px 4px rgba(10, 20, 40, .12), 0 8px 22px rgba(10, 20, 40, .2); animation: nq-pop .5s cubic-bezier(.2, 1.3, .4, 1) both; }
.nq-chip svg.nq { width: 44px; height: 44px; flex: none; animation: nq-bob .7s ease-in-out infinite alternate; }
.nq-chip small { display: block; font-weight: 400; font-size: .74rem; color: var(--ink-2, #47536a); }
.nq-chip:hover { outline: 2px solid var(--accent, #0d7f86); }
.nq-chip:hover svg.nq { animation-duration: .3s; }
.nq-chip:active { transform: scale(.96); }
@keyframes nq-pop { from { transform: translateY(26px) scale(.5); opacity: 0; } }
@keyframes nq-bob { to { transform: translateY(-4px) rotate(-5deg); } }

@media (prefers-reduced-motion: reduce) {
  .tw, .tw *, .nq-chip, svg.nq, svg.nq *, .nq-say { animation: none !important; transition: none !important; }
}
