/* MathTown UI — warm, rounded, kid-friendly (DESIGN §2: the city is the reward).
   One stylesheet serves /editor (free build) and /play (the real game).

   Chrome iconography is generated art (editor/sprites/icon_*.png) wrapped in
   the .ic component; if an icon file is missing the component falls back to
   the emoji in its data-e attribute, so the UI never breaks while art is
   being (re)generated. */

:root {
  --bg: #F2EBDD;            /* warm paper */
  --card: #FFFDF7;          /* panel cards */
  --ink: #3A3F4C;           /* main text */
  --ink-soft: #7A8093;      /* secondary text */
  --line: #E8DFCC;          /* hairlines */
  --teal: #2FA8B7;          /* primary action */
  --teal-deep: #1E7E8C;
  --amber: #FFC94A;         /* coins / joy */
  --amber-deep: #E8A81E;
  --coral: #F0785A;         /* warnings, warm not scary */
  --green: #5BB85C;         /* success */
  --shadow: 0 2px 10px rgba(90, 70, 40, .12);
  --shadow-pop: 0 8px 26px rgba(90, 70, 40, .2);
  --radius: 16px;
  --bevel: 0 3px 0 rgba(90, 70, 40, .14);        /* sticker/candy button base */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; color: var(--ink);
  font-family: "Nunito", "Quicksand", ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}
#app { display: flex; height: 100vh; background: var(--bg); }
.hidden { display: none !important; }
button { font-family: inherit; }

/* --- .ic: generated icon with emoji fallback -------------------------------- */
.ic {
  display: inline-flex; width: 20px; height: 20px; flex: 0 0 auto;
  align-items: center; justify-content: center; vertical-align: -4px;
}
.ic img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ic.noimg img { display: none; }
.ic.noimg::before { content: attr(data-e); font-size: 15px; line-height: 1; }

/* --- sidebar -------------------------------------------------------------- */
#sidebar {
  width: 300px; flex: 0 0 300px; background: var(--bg);
  padding: 12px 12px 20px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
#brand { display: flex; align-items: center; gap: 10px; padding: 2px 2px 0; }
#brand .brand-logo { width: 46px; height: 46px; filter: drop-shadow(0 2px 3px rgba(90,70,40,.25)); }
#brand .brand-logo.noimg::before { font-size: 34px; }
#brand h1 { font-size: 25px; margin: 0; letter-spacing: .3px; font-weight: 900; }
#brand .tagline { margin: 0; font-size: 11.5px; color: var(--ink-soft); }
.mode-tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--teal); color: #fff; font-size: 10px; font-weight: 700;
  letter-spacing: .4px; text-transform: uppercase;
}

#earn-jobs {
  display: flex; align-items: center; gap: 11px; text-align: left;
  background: linear-gradient(180deg, #FFD56A, #FFB93E); color: #5C4300;
  border: none; border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; line-height: 1.25; cursor: pointer;
  box-shadow: var(--bevel), var(--shadow); transition: transform .12s, box-shadow .12s;
}
#earn-jobs:hover { transform: translateY(-1px); }
#earn-jobs:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(90,70,40,.14); }
#earn-jobs .ic { width: 32px; height: 32px; }
#earn-jobs .ic.noimg::before { font-size: 24px; }
#earn-jobs b { font-size: 14.5px; }
#earn-jobs small { color: #7A5A0A; }

/* Needs-attention list: tap a notice to jump the camera there and start the fix. */
#attention-panel h2 .ic.noimg::before { font-size: 18px; }
#attention-list { display: flex; flex-direction: column; gap: 7px; }
.attn {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: linear-gradient(180deg, #FFE3E0, #FFCFC8); color: #7A2418;
  border: none; border-radius: 12px; padding: 8px 11px; cursor: pointer;
  font-size: 13px; line-height: 1.2;
  box-shadow: var(--bevel); transition: transform .1s, box-shadow .1s;
}
.attn .ic { width: 24px; height: 24px; flex: 0 0 auto; }
.attn .ic.noimg::before { font-size: 19px; }
.attn b { font-size: 13.5px; }
.attn small { color: #9C4A3C; }
.attn:hover { transform: translateY(-1px); }
.attn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(120,40,25,.16); }

.panel {
  background: var(--card); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow);
}
.panel h2 {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-soft); margin: 0 0 9px; font-weight: 800;
}
.panel h2 .ic { width: 17px; height: 17px; }
.panel h2 .ic.noimg::before { font-size: 13px; }

/* Tool buttons: icon-forward tiles (sticker look, gentle press). */
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.tools button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #F8F3E7; color: var(--ink); border: 2px solid transparent;
  border-radius: 13px; padding: 8px 4px 6px; font-size: 10.5px; font-weight: 800;
  cursor: pointer; box-shadow: var(--bevel);
  transition: background .12s, border-color .12s, transform .1s, box-shadow .1s;
}
.tools button .ic { width: 26px; height: 26px; }
.tools button .ic.noimg::before { font-size: 20px; }
.tools button:hover { background: #F1EAD7; transform: translateY(-1px); }
.tools button:active { transform: translateY(2px); box-shadow: none; }
.tools button.active { background: #DFF4F6; border-color: var(--teal); color: var(--teal-deep); }

.brush { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); margin-top: 10px; }
.brush input { flex: 1; accent-color: var(--teal); }

/* Category tabs: a tidy shelf rail of five icon tiles. */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 9px; }
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: #F8F3E7; color: var(--ink-soft); border: 2px solid transparent;
  border-radius: 12px; padding: 7px 2px 5px; font-size: 9px; font-weight: 800;
  letter-spacing: .01em; cursor: pointer; box-shadow: var(--bevel);
  transition: background .12s, border-color .12s, transform .1s, box-shadow .1s;
}
.tabs button .ic { width: 24px; height: 24px; }
.tabs button .ic.noimg::before { font-size: 18px; }
.tabs button:hover { transform: translateY(-1px); }
.tabs button:active { transform: translateY(1px); box-shadow: none; }
.tabs button.active {
  background: linear-gradient(180deg, #E8F8FA, #D5F0F3);
  border-color: var(--teal); color: var(--teal-deep);
}

/* Palette: building cards with a coin badge; locked cards wear a padlock. */
.palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.palette .item {
  position: relative;
  background: #FDFAF1; border: 2px solid var(--line); border-radius: 13px; padding: 6px 4px 5px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: transform .1s, border-color .1s, box-shadow .1s;
}
.palette .item:hover { transform: translateY(-2px); border-color: #D8CBAA; box-shadow: var(--shadow); }
.palette .item.active { border-color: var(--teal); background: #EBF7F8; }
.palette .item.poor { opacity: .45; }
.palette .item > img { width: 100%; height: 52px; object-fit: contain; }
.palette .item .pname {
  font-size: 9.5px; font-weight: 700; color: var(--ink); text-align: center;
  line-height: 1.15; min-height: 2.3em; display: flex; align-items: center;
}
.palette .item .pcost {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 9.5px; font-weight: 900; color: #8A6400;
  background: #FFEDB8; border-radius: 999px; padding: 2px 8px;
}
.palette .item .pcost .ic { width: 12px; height: 12px; }
.palette .item .pcost .ic.noimg::before { font-size: 10px; }
.palette .item .pcost.free { background: #E2F3E2; color: #2E8B4A; }
.palette .item.locked { background: #F1EDE3; }
.palette .item.locked > img { filter: grayscale(1) opacity(.35); }
.palette .item.locked .pcost { background: #EFE7D3; color: #A48A2E; }
.palette .item.locked .pcost .ic { width: 13px; height: 13px; }

#skills-panel .skill-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 12px; }
#skills-panel .skill-name { color: var(--ink); }
#skills-panel .skill-stars { color: var(--amber-deep); letter-spacing: 1px; font-size: 12.5px; white-space: nowrap; }

/* --- saved towns ------------------------------------------------------------ */
#saves-panel .saves-empty { margin: 2px 0 8px; font-size: 11.5px; color: var(--ink-soft); line-height: 1.4; }
.save-row { display: flex; align-items: center; gap: 5px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.save-row:last-of-type { border-bottom: none; }
.save-info { flex: 1; min-width: 0; }
.save-info b { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-info small { font-size: 10.5px; color: var(--ink-soft); }
.save-load, .save-export {
  border: none; border-radius: 9px; padding: 5px 9px; font-size: 11px; font-weight: 800;
  cursor: pointer; flex: 0 0 auto;
}
.save-load { background: #DFF4F6; color: var(--teal-deep); }
.save-load:hover { background: #CBEDF0; }
.save-export { background: #F3ECDA; color: var(--amber-deep); }
.save-export:hover { background: #EDE2C8; }
.save-del { background: none; border: none; color: var(--ink-soft); font-size: 15px; cursor: pointer; padding: 2px 3px; }
.save-del:hover { color: #B4573D; }
#save-as, #save-import {
  width: 100%; margin-top: 8px; border: none; border-radius: 10px; padding: 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #F8F3E7; color: var(--ink); font-size: 12.5px; font-weight: 700; cursor: pointer;
  box-shadow: var(--bevel);
}
#save-as:hover, #save-import:hover { background: #F1EAD7; }
#save-as:active, #save-import:active { transform: translateY(2px); box-shadow: none; }
#save-import { margin-top: 6px; }

/* --- share modal (import / export a town by copy-paste) --------------------- */
#sharemodal {
  position: fixed; inset: 0; z-index: 52; display: flex; align-items: center; justify-content: center;
  background: rgba(58, 50, 34, .45); backdrop-filter: blur(2px);
}
.share-card {
  position: relative; width: min(560px, calc(100vw - 40px)); max-height: calc(100vh - 40px);
  overflow-y: auto; background: var(--card); border-radius: 20px; padding: 20px 22px 22px;
  box-shadow: 0 18px 60px rgba(60, 40, 10, .35);
}
.share-close {
  position: absolute; top: 10px; right: 13px; background: #F6F1E4; border: none;
  width: 30px; height: 30px; border-radius: 999px; color: var(--ink-soft);
  font-size: 17px; cursor: pointer; line-height: 1;
}
.share-close:hover { background: #EFE7D3; color: var(--ink); }
.share-title { margin: 0 30px 6px 0; font-size: 20px; line-height: 1.15; }
.share-intro { margin: 0 0 12px; font-size: 13px; color: var(--ink-soft); line-height: 1.45; }
.share-intro code { background: #F1EAD7; border-radius: 5px; padding: 0 4px; font-size: 12px; }
.share-text {
  width: 100%; height: 168px; resize: vertical; border: 2px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; color: var(--ink); background: #FDFBF4; word-break: break-all;
}
.share-text:focus { outline: none; border-color: var(--teal); }
.share-msg { margin: 8px 0 0; font-size: 12.5px; min-height: 1.2em; line-height: 1.4; }
.share-msg.good { color: var(--green); font-weight: 700; }
.share-msg.warn { color: var(--coral); font-weight: 700; }
.share-actions { display: flex; gap: 8px; margin-top: 12px; }
.share-btn {
  border: none; border-radius: 11px; padding: 10px 16px; font-size: 13.5px; font-weight: 800;
  cursor: pointer; box-shadow: var(--bevel); transition: transform .1s, box-shadow .1s;
}
.share-btn:active { transform: translateY(2px); box-shadow: none; }
.share-btn.primary { background: var(--teal); color: #fff; }
.share-btn.primary:hover { background: var(--teal-deep); }
.share-btn.ghost { background: #F3ECDA; color: var(--ink); }
.share-btn.ghost:hover { background: #EBE1C9; }

.hint { font-size: 12px; color: var(--ink-soft); }
.hint b { color: var(--teal-deep); }
.hint p { line-height: 1.45; }
.hint #reset {
  background: none; border: 2px solid #EAC7BC; color: #B4573D;
  border-radius: 10px; padding: 6px 12px; font-weight: 700; cursor: pointer;
}
.hint #reset:hover { background: #FBEFEA; }

/* --- viewport & game overlays --------------------------------------------- */
#viewport { position: relative; flex: 1; min-width: 0; padding: 12px 12px 12px 0; }
#stage {
  position: absolute; inset: 12px 12px 12px 0; width: calc(100% - 12px); height: calc(100% - 24px);
  display: block; background: #DCEAF2; cursor: default; border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#overlays {
  position: absolute; top: 22px; left: 14px; right: 26px;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start; pointer-events: none;
}

/* HUD: one continuous stat bar; coins get their own golden cap on the right. */
#hud {
  display: flex; align-items: stretch; flex-wrap: wrap;
  background: rgba(255, 253, 247, .95); border-radius: 999px;
  box-shadow: var(--shadow); padding: 4px 5px; gap: 2px;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--ink); border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 700; white-space: nowrap;
  border-right: 1px solid var(--line);
}
.chip:last-child { border-right: none; }
.chip .ic { width: 17px; height: 17px; }
.chip .ic.noimg::before { font-size: 13px; }
.chip b { color: var(--teal-deep); }
.chip.coins { background: linear-gradient(180deg, #FFE9B0, #FFD56A); color: #5C4300; border-right: none; }
.chip.coins b { color: #5C4300; }
.chip i { font-style: normal; font-size: 11px; color: #2E8B4A; margin-left: 2px; font-weight: 800; }
.chip.low b { color: #C4452E; }
.chip.low { background: #FFF0EA; }

#advisor {
  display: flex; align-items: center; gap: 11px;
  background: rgba(255, 253, 247, .95); border-radius: 18px; padding: 8px 15px 8px 9px;
  max-width: 480px; box-shadow: var(--shadow);
}
.advisor-face {
  position: relative; width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: 12px; background: #EBF7F8; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.advisor-face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.advisor-face .face-e { display: none; font-size: 24px; }
.advisor-face.noimg img { display: none; }
.advisor-face.noimg .face-e { display: inline; }
.meters { display: flex; gap: 8px; }
.meterwrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.meterwrap .ic { width: 14px; height: 14px; }
.meterwrap .ic.noimg::before { font-size: 11px; }
.meter { width: 12px; height: 32px; background: #EFE8D6; border-radius: 5px; position: relative; overflow: hidden; }
.meter .fill { position: absolute; bottom: 0; left: 0; right: 0; height: 0%; transition: height .5s; border-radius: 4px; }
#dem-r { background: var(--green); }
#dem-c { background: #4B9FE8; }
#dem-i { background: #F0A24B; }
#advice { font-size: 13px; color: var(--ink); line-height: 1.35; font-weight: 600; }

/* Board rotation buttons — top-right of the stage. */
#viewctl { position: absolute; top: 22px; right: 26px; display: flex; gap: 7px; z-index: 10; }
#viewctl button {
  width: 42px; height: 42px; border-radius: 999px; border: none;
  background: rgba(255, 253, 247, .95); box-shadow: var(--bevel), var(--shadow);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink); cursor: pointer; transition: transform .12s;
}
#viewctl button .ic { width: 22px; height: 22px; }
#viewctl button .ic.noimg::before { font-size: 19px; }
#viewctl button:hover { transform: scale(1.08); }
#viewctl button:active { transform: translateY(2px); }
#viewctl button.mirror .ic img { transform: scaleX(-1); }
/* The view toggle wears two icons: a down arrow in 3D (dive to the overhead
   map), an XYZ-axes gizmo in top-down (back to 3D). body.topdown flips them. */
#view-top .vt-axes { display: none; }
body.topdown #view-top .vt-down { display: none; }
body.topdown #view-top .vt-axes { display: inline-flex; }

#inspect {
  position: absolute; right: 26px; bottom: 24px; width: 272px;
  background: var(--card); color: var(--ink); border-radius: var(--radius);
  padding: 13px; font-size: 12.5px; box-shadow: var(--shadow-pop);
}
#inspect .close {
  position: absolute; top: 7px; right: 9px; background: none; border: none;
  color: var(--ink-soft); font-size: 17px; cursor: pointer; line-height: 1;
}
#inspect .close:hover { color: var(--ink); }
.ins-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.ins-head img { height: 56px; max-width: 56px; object-fit: contain; flex: 0 0 auto; }
.ins-head h3 { margin: 0 0 2px; font-size: 14px; }
.ins-head p { margin: 0; font-size: 11.5px; color: var(--ink-soft); line-height: 1.3; }
.ins-rows .row { padding: 4.5px 0; border-top: 1px solid var(--line); line-height: 1.35; }
.ins-rows .row b { color: var(--teal-deep); }
.ins-rows .row .ic { width: 16px; height: 16px; margin-right: 3px; }
.ins-rows .row .ic.noimg::before { font-size: 12px; }
.ins-action {
  width: 100%; margin-top: 10px; border: none; border-radius: 12px; padding: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: linear-gradient(180deg, #43BBC9, #2FA8B7); color: #fff;
  font-size: 14px; font-weight: 800; cursor: pointer;
  box-shadow: var(--bevel); transition: transform .1s, box-shadow .1s;
}
.ins-action .ic { width: 18px; height: 18px; }
.ins-action:hover { transform: scale(1.02); }
.ins-action:active { transform: translateY(2px); box-shadow: none; }

#toast {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(58, 63, 76, .95); color: #FFEEBE; border-radius: 999px;
  padding: 9px 20px; font-size: 13.5px; font-weight: 600; opacity: 0; transition: opacity .3s;
  pointer-events: none; white-space: nowrap; box-shadow: var(--shadow); z-index: 40;
}
#toast.show { opacity: 1; }

/* --- math challenge modal (built by challenge.js) -------------------------- */
#mathmodal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(58, 50, 34, .45); backdrop-filter: blur(2px);
}
.math-card {
  position: relative; width: min(560px, calc(100vw - 40px)); max-height: calc(100vh - 40px);
  overflow-y: auto; background: var(--card); border-radius: 20px; padding: 18px 22px 20px;
  box-shadow: 0 18px 60px rgba(60, 40, 10, .35);
}
.math-card.shake { animation: mt-shake .4s; }
@keyframes mt-shake {
  20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}
.math-close {
  position: absolute; top: 10px; right: 13px; background: #F6F1E4; border: none;
  width: 30px; height: 30px; border-radius: 999px; color: var(--ink-soft);
  font-size: 17px; cursor: pointer; line-height: 1;
}
.math-close:hover { background: #EFE7D3; color: var(--ink); }

.math-head { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.math-art { width: 132px; height: 99px; object-fit: contain; flex: 0 0 auto; }
.math-title { margin: 0; font-size: 21px; line-height: 1.15; }
.math-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); line-height: 1.35; }

.math-progress { display: flex; gap: 6px; margin: 8px 0 2px; }
.math-progress .dot {
  width: 13px; height: 13px; border-radius: 999px; background: #EFE8D6;
  border: 2px solid #E2D8C0; transition: background .3s;
}
.math-progress .dot.now { border-color: var(--teal); }
.math-progress .dot.full { background: var(--amber); border-color: var(--amber-deep); }

.math-meta { display: flex; gap: 7px; align-items: center; margin: 8px 0 2px; flex-wrap: wrap; }
.math-skillchip, .math-levelchip {
  font-size: 11px; font-weight: 800; border-radius: 999px; padding: 3px 10px;
}
.math-skillchip { background: #DFF4F6; color: var(--teal-deep); }
.math-levelchip { background: #F3EDFE; color: #7C5FC9; }
.math-earned {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 800; color: #8A6400; background: #FFE9B0; border-radius: 999px; padding: 3px 10px;
}
.math-earned .ic { width: 14px; height: 14px; }
.math-earned .ic.noimg::before { font-size: 11px; }

.math-prompt { font-size: 17.5px; line-height: 1.45; margin: 10px 0 6px; }

.math-hints p {
  margin: 6px 0; padding: 8px 12px; background: #FFF7DF; border-radius: 10px;
  font-size: 13.5px; line-height: 1.4; border-left: 4px solid var(--amber);
}
.math-steps {
  margin: 6px 0; padding: 10px 14px; background: #EBF7F8; border-radius: 10px;
  font-size: 13.5px; line-height: 1.5; border-left: 4px solid var(--teal);
}
.math-steps p { margin: 4px 0; }
.math-steps .math-tryit { color: var(--teal-deep); font-weight: 700; }

.math-form { display: flex; gap: 8px; margin: 10px 0 4px; }
.math-input {
  flex: 1; font-size: 18px; font-weight: 700; padding: 10px 14px; color: var(--ink);
  border: 2.5px solid var(--line); border-radius: 12px; background: #FDFAF1; outline: none;
}
.math-input:focus { border-color: var(--teal); background: #fff; }
.math-check {
  border: none; border-radius: 12px; padding: 10px 18px; font-size: 15px; font-weight: 800;
  background: linear-gradient(180deg, #43BBC9, #2FA8B7); color: #fff; cursor: pointer;
  box-shadow: var(--bevel);
}
.math-check:hover { filter: brightness(1.05); }
.math-check:active { transform: translateY(2px); box-shadow: none; }
.math-check:disabled, .math-input:disabled { opacity: .55; }

.math-feedback { min-height: 22px; font-size: 15px; font-weight: 800; margin: 2px 0; }
.math-feedback.good { color: #2E8B4A; }
.math-feedback.bad { color: var(--coral); }

.math-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.math-actions button {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 11px; padding: 9px 15px; font-size: 13.5px; font-weight: 800;
  cursor: pointer; background: #F6F1E4; color: var(--ink);
  box-shadow: var(--bevel); transition: transform .1s, box-shadow .1s;
}
.math-actions button .ic { width: 16px; height: 16px; }
.math-actions button:hover { transform: translateY(-1px); }
.math-actions button:active { transform: translateY(2px); box-shadow: none; }
.math-hint { background: #FFF1C6 !important; color: #8A6400 !important; }
.math-hint.glow { animation: mt-glow 1.2s infinite; }
@keyframes mt-glow { 50% { box-shadow: 0 0 0 5px rgba(255, 201, 74, .45); } }
.math-show { background: #EBF7F8 !important; color: var(--teal-deep) !important; }
.math-next, .math-finish {
  background: linear-gradient(180deg, #FFD56A, #FFB93E) !important; color: #5C4300 !important;
  font-size: 14.5px !important;
}
.math-done { color: var(--ink-soft) !important; }

.confetti {
  position: absolute; width: 9px; height: 13px; border-radius: 3px;
  pointer-events: none; z-index: 5;
}

/* --- talking-head advisor card (built by advisor.js) ----------------------- */
#advisor-card {
  position: fixed; left: 324px; bottom: 24px; z-index: 45;
  display: flex; gap: 12px; align-items: flex-start;
  width: min(420px, calc(100vw - 348px));
  background: var(--card); border-radius: 18px; padding: 12px 38px 12px 12px;
  box-shadow: 0 10px 34px rgba(90, 70, 40, .28);
  opacity: 0; transform: translateY(14px); transition: opacity .3s, transform .3s;
}
#advisor-card.show { opacity: 1; transform: translateY(0); }
.adv-portrait {
  position: relative; width: 74px; height: 74px; flex: 0 0 auto;
  border-radius: 16px; background: #EBF7F8; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.adv-portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.adv-emoji { font-size: 36px; }
.adv-name { font-size: 12px; color: var(--ink-soft); margin-bottom: 3px; }
.adv-name b { color: var(--teal-deep); font-size: 13px; }
.adv-body p { margin: 0; font-size: 13.5px; line-height: 1.45; font-weight: 600; }
.adv-close {
  position: absolute; top: 8px; right: 10px; background: none; border: none;
  color: var(--ink-soft); font-size: 17px; cursor: pointer; line-height: 1;
}
.adv-close:hover { color: var(--ink); }

/* --- onboarding tutorial card (built by tutorial.js) ------------------------ */
#tutorial-card {
  position: fixed; left: 50%; bottom: 64px; transform: translate(-50%, 16px); z-index: 46;
  display: flex; gap: 14px; align-items: flex-start;
  width: min(520px, calc(100vw - 360px));
  background: var(--card); border-radius: 20px; padding: 14px 16px 12px;
  box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
}
#tutorial-card.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.tut-portrait {
  position: relative; width: 84px; height: 84px; flex: 0 0 auto;
  border-radius: 18px; background: #FFF3D6; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.tut-portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tut-portrait .tut-emoji { display: none; font-size: 42px; }
.tut-portrait.noimg img { display: none; }
.tut-portrait.noimg .tut-emoji { display: inline; }
.tut-body { flex: 1; min-width: 0; }
.tut-name { font-size: 12px; color: var(--ink-soft); margin-bottom: 3px; }
.tut-name b { color: #B8770E; font-size: 13px; }
.tut-text { margin: 0; font-size: 14px; line-height: 1.45; font-weight: 600; }
.tut-foot { display: flex; align-items: center; gap: 10px; margin-top: 9px; }
.tut-dots { display: flex; gap: 5px; flex: 1; }
.tut-dots .dot {
  width: 10px; height: 10px; border-radius: 999px;
  background: #EFE8D6; border: 2px solid #E2D8C0;
}
.tut-dots .dot.now { border-color: var(--amber-deep); background: #FFF1C6; }
.tut-dots .dot.full { background: var(--amber); border-color: var(--amber-deep); }
.tut-next {
  border: none; border-radius: 11px; padding: 8px 16px; font-size: 13.5px; font-weight: 800;
  background: linear-gradient(180deg, #FFD56A, #FFB93E); color: #5C4300; cursor: pointer;
  box-shadow: var(--bevel); transition: transform .1s, box-shadow .1s;
}
.tut-next:hover { transform: translateY(-1px); }
.tut-next:active { transform: translateY(2px); box-shadow: none; }
.tut-skip {
  background: none; border: none; color: var(--ink-soft); font-size: 11.5px;
  font-weight: 700; cursor: pointer; padding: 4px;
}
.tut-skip:hover { color: var(--ink); text-decoration: underline; }

/* The element the tutorial is pointing at glows gently. */
.tut-glow { position: relative; animation: tut-pulse 1.4s ease-in-out infinite; border-radius: 12px; }
@keyframes tut-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 185, 62, .9), 0 0 18px 4px rgba(255, 201, 74, .55); }
  50% { box-shadow: 0 0 0 6px rgba(255, 185, 62, .55), 0 0 26px 8px rgba(255, 201, 74, .35); }
}

/* Centre-screen celebration layer — floats above the math modal (z 50). */
.math-fxlayer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.math-bigcheer {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  padding: 14px 28px; border-radius: 20px; white-space: nowrap;
  background: rgba(255, 255, 255, 0.96); box-shadow: var(--shadow);
  font-size: clamp(24px, 4.5vw, 40px); font-weight: 900; color: #2E8B4A;
}
