/* Math Lab Fluency Hub — playful, clean, kid-friendly */

@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka-latin-ext.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Nunito';
  src: url('fonts/nunito-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Nunito';
  src: url('fonts/nunito-latin-ext.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #26183A;
  --muted: #5C5270;
  --bg: #FFF6EB;
  --bg-2: #FFE4F0;
  --card: #FFFFFF;
  --line: #F0D9C8;
  --primary: #5B3FD6;
  --primary-edge: #3F25A8;
  --primary-soft: #EFEAFF;
  --coral: #E23B5B;
  --coral-soft: #FFE4EA;
  --sky: #1E7BE0;
  --sky-soft: #E3F1FF;
  --teal: #0C8F78;
  --teal-soft: #D9F6EF;
  --sun: #E89A00;
  --sun-soft: #FFF1CC;
  --success: #0B7A4B;
  --success-bg: #E3F8ED;
  --warn: #8A4B12;
  --warn-bg: #FFF1D6;
  --danger: #B42318;
  --shadow: 0 10px 30px rgba(38, 24, 58, 0.08);
  --shadow-lift: 0 16px 36px rgba(38, 24, 58, 0.14);
  --radius: 24px;
  --radius-sm: 16px;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --tap: 48px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--ink);
  background:
    radial-gradient(900px 500px at -10% -20%, #FFD6E8 0%, transparent 55%),
    radial-gradient(800px 480px at 110% 0%, #D6E8FF 0%, transparent 50%),
    radial-gradient(700px 400px at 80% 110%, #CFF5E8 0%, transparent 50%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.45;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.35;
  background-image: radial-gradient(circle, rgba(91, 63, 214, 0.14) 1.2px, transparent 1.6px);
  background-size: 22px 22px;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
img, svg { display: block; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 10001;
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 800;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 68px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px max(20px, calc((100vw - 1100px) / 2));
  gap: 12px;
  background: rgba(255, 246, 235, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 2px solid rgba(240, 217, 200, 0.8);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand-mark { color: var(--primary); flex-shrink: 0; }
.brand-mark svg { width: 34px; height: 34px; }
.brand-light { font-weight: 500; color: var(--muted); padding-left: 6px; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.header-name {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ---------- Layout ---------- */
main {
  max-width: 1100px;
  margin: 24px auto 40px;
  padding: 0 20px;
}

.screen[hidden], button[hidden], span[hidden], p[hidden] { display: none !important; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------- Buttons ---------- */
.btn {
  --btn-edge: #c8c0d8;
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  min-height: var(--tap);
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.1;
  box-shadow: 0 4px 0 var(--btn-edge);
  transition: transform 0.12s var(--spring), box-shadow 0.12s ease, filter 0.12s ease, background 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.03); }
.btn:active { transform: translateY(4px) scale(0.97, 0.9); box-shadow: 0 0 0 var(--btn-edge); }
.btn:focus-visible,
.op:focus-visible,
.deck:focus-within .btn:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid #3F25A8;
  outline-offset: 3px;
}

.btn.primary { background: var(--primary); color: #fff; --btn-edge: var(--primary-edge); }
.btn.subtle { background: var(--primary-soft); color: #3F25A8; --btn-edge: #C8B8F5; }
.btn.ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); box-shadow: 0 3px 0 #e6d3c4; --btn-edge: #e6d3c4; }
.btn.danger { background: var(--danger); color: #fff; --btn-edge: #7A120C; }
.btn.large { padding: 16px 22px; font-size: 1.12rem; min-height: 56px; width: 100%; border-radius: 18px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ---------- Welcome ---------- */
.welcome-screen {
  min-height: calc(100vh - 180px);
  display: grid;
  place-items: center;
}

.welcome-panel {
  width: min(100%, 600px);
  padding: 40px 44px 36px;
  background: var(--card);
  border-radius: 32px;
  border: 3px solid #fff;
  box-shadow: var(--shadow), 0 0 0 4px rgba(91, 63, 214, 0.06);
  text-align: center;
  animation: pop-in 0.45s var(--spring);
}

.hero-star { margin-bottom: 8px; }
.star-bounce {
  display: inline-block;
  font-size: 3rem;
  color: var(--primary);
  animation: float-y 2.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 0 rgba(91, 63, 214, 0.15));
}

.welcome-panel h1 {
  font-size: clamp(1.8rem, 4vw, 2.45rem);
  margin: 10px 0 12px;
}

.lead, .welcome-panel p { color: var(--muted); }

.entry-form {
  text-align: left;
  display: grid;
  gap: 6px;
  width: min(100%, 380px);
  margin: 26px auto 0;
}
.entry-form label {
  font-size: 0.92rem;
  font-weight: 800;
  margin-top: 8px;
}
.entry-form input,
.answer-input {
  border: 2px solid #E4D2EE;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 1.1rem;
  background: #FFFCFA;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.entry-form input:hover,
.answer-input:hover { border-color: #C9B4EA; }
.entry-form input:focus,
.answer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(91, 63, 214, 0.18);
  outline: none;
}
.entry-form .btn { margin-top: 14px; }

.privacy-line {
  font-size: 0.82rem !important;
  max-width: 440px;
  margin: 18px auto 0;
  line-height: 1.45;
}

/* ---------- Select ---------- */
.intro { margin-bottom: 20px; }
.intro h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); margin: 8px 0 10px; }
.intro p { color: var(--muted); margin: 0; font-size: 1.05rem; }

.operations {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.op {
  appearance: none;
  border: 3px solid transparent;
  background: var(--card);
  min-height: 164px;
  border-radius: 22px;
  text-align: left;
  padding: 20px;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.18s var(--spring), box-shadow 0.18s ease, border-color 0.15s, background 0.15s;
  animation: pop-in 0.4s var(--spring);
}
.op:nth-child(1) { animation-delay: 0.02s; --op: var(--coral); --op-soft: var(--coral-soft); }
.op:nth-child(2) { animation-delay: 0.07s; --op: var(--sky); --op-soft: var(--sky-soft); }
.op:nth-child(3) { animation-delay: 0.12s; --op: var(--primary); --op-soft: var(--primary-soft); }
.op:nth-child(4) { animation-delay: 0.17s; --op: var(--sun); --op-soft: var(--sun-soft); }

.op:hover { transform: translateY(-6px) rotate(-0.4deg); box-shadow: var(--shadow-lift); }
.op:active { transform: translateY(2px) scale(0.98, 0.94); }
.op.active {
  background: var(--op-soft);
  border-color: var(--op);
  box-shadow: var(--shadow-lift);
}

.op-symbol {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.4rem;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: var(--op-soft, var(--primary-soft));
  color: var(--op, var(--primary));
  margin-bottom: 12px;
}
.op strong { display: block; font-size: 1.12rem; font-family: var(--font-display); }
.op small { display: block; color: var(--muted); margin-top: 6px; line-height: 1.35; font-weight: 600; }

.card {
  background: var(--card);
  border: 3px solid #fff;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.section-heading h2 { margin-top: 6px; font-size: 1.55rem; }

.chip {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 8px 13px;
  white-space: nowrap;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.deck {
  border: 2px solid #F0E4F4;
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s var(--spring), box-shadow 0.18s ease;
}
.deck:hover { transform: translateY(-5px); box-shadow: var(--shadow-lift); }

.deck-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 2px solid #F6EEF6;
  background: linear-gradient(180deg, #FFFCFA, #FFF8F2);
}
.deck-top strong { font-size: 1.05rem; font-family: var(--font-display); font-weight: 650; }
.deck-top small { color: var(--muted); font-weight: 800; }

.deck-visual {
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  background: #FFFCFA;
  overflow: hidden;
}
.deck-visual .visual-inner { transform: scale(0.72); transform-origin: center; }
.deck-visual .visual-caption { max-width: 290px; }

.deck-description {
  padding: 14px 16px 16px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: auto;
}
.deck-description small { max-width: 62%; color: var(--muted); line-height: 1.4; }
.deck-description .btn { flex-shrink: 0; }

/* ---------- Practice ---------- */
.practice-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.practice-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFF1CC;
  color: #8A4B12;
  font-weight: 800;
  font-family: var(--font-display);
  padding: 6px 12px;
  border-radius: 999px;
  animation: pop-in 0.35s var(--spring);
}
.streak.pulse { animation: bounce-sm 0.45s var(--spring); }

.answer-trail {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 22px;
  margin-bottom: 12px;
}
.trail-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  animation: pop-in 0.3s var(--spring);
}
.trail-dot.yes { background: var(--teal); }
.trail-dot.no { background: #E07A3D; }

.practice-card { position: relative; overflow: visible; }
.practice-card h2 { font-size: 1.8rem; margin: 6px 0; }
.practice-card > p { color: var(--muted); margin: 0 0 8px; }

.practice-card.correct-bounce { animation: bounce-sm 0.5s var(--spring); }
.practice-card.wrong-shake { animation: shake 0.45s ease; }

.visual-area {
  min-height: 240px;
  max-height: 340px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 12px;
  overflow: auto;
}
.visual-inner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
}
.visual-caption {
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
  max-width: 420px;
}

.ten-pair {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
.ten-frame {
  display: grid;
  grid-template-columns: repeat(5, 32px);
  grid-template-rows: repeat(2, 32px);
  border: 3px solid #4A6FA0;
  border-radius: 6px;
  background: #fff;
}
.ten-cell {
  border: 1px solid #B8CDE4;
  display: grid;
  place-items: center;
}
.counter {
  height: 22px;
  width: 22px;
  background: #0C8F78;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.counter.orange { background: #F08A2A; }
.counter.gone { background: #E8E0D8; box-shadow: none; opacity: 0.55; }

.array {
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(var(--cols, 4), auto);
}
.array-dot {
  background: #1E7BE0;
  width: var(--dot, 20px);
  height: var(--dot, 20px);
  border-radius: 6px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.array.orange .array-dot { background: #F08A2A; }

.groups {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 460px;
  justify-content: center;
}
.group-box {
  border-radius: 12px;
  background: #E5F7E9;
  border: 2px solid #2FA85A;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(var(--gcols, 3), var(--gdot, 12px));
  gap: 3px;
}
.group-box.alt { background: #FFF1CC; border-color: #E89A00; }
.group-box.alt .group-dot { background: #E89A00; }
.group-dot {
  height: var(--gdot, 12px);
  width: var(--gdot, 12px);
  background: #2FA85A;
  border-radius: 50%;
}

.number-bond { position: relative; width: 300px; height: 192px; }
.number-bond svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.bubble {
  position: absolute;
  background: #F2F8FF;
  width: 72px;
  height: 72px;
  border: 4px solid #2E79B5;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.55rem;
  font-weight: 800;
  font-family: var(--font-display);
}
.bubble.top { left: 114px; top: 0; }
.bubble.left { left: 24px; bottom: 0; }
.bubble.right { right: 24px; bottom: 0; }
.bubble.mystery { background: var(--sun-soft); border-color: var(--sun); color: #8A4B12; }

.family-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: min(90vw, 470px);
  text-align: center;
}
.family-card div {
  font-weight: 800;
  font-size: 1.2rem;
  color: #3F25A8;
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 12px;
  font-family: var(--font-display);
}
.family-card .missing {
  background: var(--sun-soft);
  color: #8A4B12;
  outline: 3px dashed var(--sun);
}

.factor-circles {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 1.7rem;
  font-weight: 800;
  font-family: var(--font-display);
}
.factor-circle {
  height: 84px;
  width: 84px;
  border: 10px solid #F08A2A;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
}
.factor-circle.blue { border-color: #1E7BE0; }

.answer-form {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
.question-equation {
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 700;
  font-family: var(--font-display);
}
.answer-input {
  width: 120px;
  border-width: 3px;
  border-radius: 16px;
  padding: 12px;
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  font-family: var(--font-display);
}

.feedback { margin: 14px 0 0; min-height: 0; }
.result-feedback {
  background: var(--sky-soft);
  border-radius: 16px;
  padding: 14px 18px;
  color: var(--ink);
  line-height: 1.5;
  animation: pop-in 0.35s var(--spring);
}
.result-feedback.correct {
  background: var(--success-bg);
  color: var(--success);
}
.result-feedback.wrong {
  background: var(--warn-bg);
  color: var(--warn);
}
.result-feedback.hint-only { background: var(--primary-soft); color: var(--ink); }
.result-feedback strong { display: block; font-size: 1.1rem; margin-bottom: 4px; font-family: var(--font-display); }

.practice-footer {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}
.footer-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Journey bar ---------- */
.journey {
  flex: 1 1 180px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
  max-width: 440px;
  margin: 0 8px;
}
.journey-level {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
  white-space: nowrap;
  min-width: 4.6rem;
}
.journey-track {
  position: relative;
  flex: 1;
  height: 16px;
  background: linear-gradient(90deg, #EDE4FF 0%, #D6E8FF 60%, #FFF1CC 100%);
  border-radius: 999px;
  border: 2px solid #C8B8F5;
  min-width: 80px;
}
.journey-ticks {
  position: absolute;
  inset: 0 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
.journey-ticks i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(91, 63, 214, 0.28);
  display: block;
}
.journey-rocket {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 28px;
  height: 28px;
  transform: translate(-30%, -58%) rotate(90deg);
  transform-origin: center;
  transition: left 0.45s var(--spring);
  z-index: 2;
  pointer-events: none;
}
.journey-rocket svg { display: block; width: 28px; height: 28px; overflow: visible; }
.rocket-flame { transform-origin: 16px 28px; animation: flame-flicker 0.5s ease-in-out infinite; }
.journey-goal {
  position: absolute;
  right: 0;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translate(35%, -55%);
  pointer-events: none;
  z-index: 1;
}
.journey-goal svg { display: block; overflow: visible; }
.journey.is-level-up .journey-goal { animation: bounce-sm 0.5s var(--spring); }
.journey.is-level-up .journey-rocket { animation: rocket-arrive 0.5s var(--spring); }
.journey.is-level-up .journey-track {
  box-shadow: 0 0 0 4px rgba(255, 209, 90, 0.45);
  border-color: #E89A00;
}
.journey.is-level-up .journey-level { color: #E89A00; }

@keyframes flame-flicker {
  0%, 100% { transform: scaleY(1); opacity: 1; }
  50% { transform: scaleY(1.25) scaleX(0.85); opacity: 0.85; }
}
@keyframes rocket-arrive {
  0% { transform: translate(-30%, -58%) rotate(90deg) scale(1); }
  40% { transform: translate(-30%, -72%) rotate(70deg) scale(1.2); }
  100% { transform: translate(-30%, -58%) rotate(90deg) scale(1); }
}

/* ---------- Mascot (Spark the star buddy) ---------- */
.answer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.answer-row .answer-form { margin-top: 0; }
.mascot-wrap {
  position: relative;
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  pointer-events: none;
}
.mascot {
  width: 72px;
  height: 72px;
  animation: mascot-bob 2.4s ease-in-out infinite;
  transform-origin: 50% 80%;
}
.mascot-svg { display: block; width: 72px; height: 72px; overflow: visible; }
.mascot-glow { opacity: 0.4; }
.mascot-wow, .mascot-hope { display: none; }
.mascot.is-wrong .mascot-smile { display: none; }
.mascot.is-wrong .mascot-hope { display: block; }
.mascot.is-celebrate .mascot-smile { display: none; }
.mascot.is-celebrate .mascot-wow { display: block; }
.mascot.is-celebrate .mascot-glow { opacity: 0.75; }

@keyframes mascot-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6px) rotate(3deg); }
}
@keyframes mascot-cheer {
  0% { transform: translateY(0) scale(1) rotate(0); }
  35% { transform: translateY(-14px) scale(1.12) rotate(-10deg); }
  65% { transform: translateY(-4px) scale(1.06) rotate(8deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
@keyframes mascot-wobble {
  0%, 100% { transform: rotate(0) translateX(0); }
  25% { transform: rotate(-14deg) translateX(-4px); }
  55% { transform: rotate(12deg) translateX(4px); }
  100% { transform: rotate(0) translateX(0); }
}
@keyframes mascot-celebrate {
  0% { transform: scale(1) rotate(0) translateY(0); }
  25% { transform: translateY(-16px) scale(1.18) rotate(-14deg); }
  50% { transform: translateY(-6px) scale(1.2) rotate(12deg); }
  75% { transform: translateY(-14px) scale(1.14) rotate(-8deg); }
  100% { transform: scale(1) rotate(0) translateY(0); }
}
.mascot.is-cheer { animation: mascot-cheer 0.5s var(--spring); }
.mascot.is-wrong { animation: mascot-wobble 0.5s ease; }
.mascot.is-celebrate { animation: mascot-celebrate 0.55s var(--spring); }

.mascot-speech {
  position: absolute;
  right: calc(100% + 4px);
  left: auto;
  top: 8px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 14px 14px 4px 14px;
  padding: 6px 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
  white-space: nowrap;
  line-height: 1.2;
  box-shadow: 0 4px 12px rgba(38, 24, 58, 0.12);
  z-index: 6;
  animation: pop-in 0.28s var(--spring);
  pointer-events: none;
}
.mascot-speech[hidden] { display: none !important; }

/* ---------- Visual entrance animations (practice only, not deck previews) ---------- */
#visual .counter,
#visual .array-dot,
#visual .group-dot,
#visual .family-card div,
#visual .factor-circle,
#visual .bubble {
  animation: vis-pop 0.3s var(--spring) both;
}
@keyframes vis-pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
#visual .bond-line {
  stroke-dasharray: 140;
  stroke-dashoffset: 140;
  animation: draw-line 0.45s ease forwards;
}
#visual .bond-line.second { animation-delay: 0.12s; }
@keyframes draw-line {
  to { stroke-dashoffset: 0; }
}
.deck-visual .counter,
.deck-visual .array-dot,
.deck-visual .group-dot,
.deck-visual .family-card div,
.deck-visual .factor-circle,
.deck-visual .bubble {
  animation: none;
}
.deck-visual .bond-line {
  animation: none;
  stroke-dashoffset: 0;
}



/* ---------- Summary ---------- */
.summary-card {
  max-width: 680px;
  margin: 40px auto;
  text-align: center;
  padding: 48px 32px;
  animation: pop-in 0.5s var(--spring);
}
.summary-card h1 { font-size: clamp(2rem, 5vw, 2.8rem); margin: 12px 0; }
.trophy { font-size: 4rem; animation: bounce-sm 0.8s var(--spring); }
.summary-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 22px auto 0;
}
.save-status {
  font-weight: 800;
  color: #0C5C8F;
  background: var(--sky-soft);
  border-radius: 14px;
  padding: 14px;
  margin: 16px 0 0;
}
.save-status.ok { background: var(--success-bg); color: var(--success); }
.save-status.err { background: var(--warn-bg); color: var(--warn); }

.site-footer {
  text-align: center;
  padding: 16px 16px 28px;
  color: #8A7E98;
  font-size: 0.82rem;
}

/* ---------- Confetti ---------- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}
.confetti-layer canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.confetti-static {
  position: fixed;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 700;
  color: var(--primary);
  text-shadow: 0 4px 0 rgba(91, 63, 214, 0.15);
  background: rgba(255, 246, 235, 0.45);
}

/* ---------- Animations ---------- */
@keyframes pop-in {
  0% { transform: scale(0.94) translateY(8px); }
  100% { transform: scale(1) translateY(0); }
}
@keyframes bounce-sm {
  0% { transform: scale(0.86); }
  40% { transform: scale(1.1); }
  70% { transform: scale(0.96); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes float-y {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .star-bounce { animation: none; }
  .btn:hover, .op:hover, .deck:hover { transform: none; }
  .btn:active, .op:active { transform: none; }
  .mascot, .mascot.is-cheer, .mascot.is-wrong, .mascot.is-celebrate,
  .rocket-flame, .journey.is-level-up .journey-goal, .journey.is-level-up .journey-rocket {
    animation: none !important;
  }
  .journey-rocket { transition: none; }
  #visual .counter,
  #visual .array-dot,
  #visual .group-dot,
  #visual .family-card div,
  #visual .factor-circle,
  #visual .bubble {
    animation: none !important;
    transform: none;
    opacity: 1;
  }
  #visual .bond-line {
    animation: none !important;
    stroke-dashoffset: 0;
  }
  .mascot-speech { animation: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .operations { grid-template-columns: repeat(2, 1fr); }
  .visual-area { min-height: 200px; max-height: 300px; }
}

@media (max-width: 760px) {
  .site-header { padding: 10px 14px; min-height: 62px; }
  #practice { padding-top: 4px; }
  .brand { font-size: 1.1rem; }
  .brand-light { display: none; }
  .header-name { display: none; }
  .deck-grid { grid-template-columns: 1fr; }
  .welcome-panel { padding: 28px 20px; }
  .welcome-panel h1 { font-size: 1.7rem; }
  .visual-area { padding: 10px; min-height: 200px; }
  .array-dot { --dot: 16px; }
  .practice-footer { align-items: flex-start; }
  .answer-form { flex-wrap: wrap; }
  main { margin-top: 16px; }
}

@media (max-width: 430px) {
  .site-header { flex-wrap: nowrap; }
  .site-header .brand-text { max-width: 7.2rem; overflow: hidden; }
  .top-actions { gap: 6px; }
  .top-actions .btn { padding: 8px 10px; font-size: 0.82rem; min-height: 42px; }
  #backButton { display: none !important; } /* Finish & save is already on the practice screen */

  .operations { gap: 8px; }
  .op { padding: 14px; min-height: 138px; }
  .op-symbol { font-size: 1.8rem; width: 48px; height: 48px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .ten-frame {
    grid-template-columns: repeat(5, 26px);
    grid-template-rows: repeat(2, 26px);
  }
  .ten-cell .counter { width: 18px; height: 18px; }
  .family-card { min-width: 0; width: 100%; }
  .family-card div { font-size: 1rem; padding: 10px; }
  .summary-card { margin: 16px auto; padding: 28px 16px; }
  .visual-area { min-height: 150px; max-height: 210px; padding: 6px; }
  .practice-card { padding: 14px 12px 16px; }
  .practice-card h2 { font-size: 1.4rem; }
  .practice-card > p { font-size: 0.92rem; margin-bottom: 4px; }
  .practice-footer { margin-top: 10px; }
  .practice-toolbar { margin-bottom: 6px; }
  .answer-trail { margin-bottom: 6px; }
  .feedback { margin-top: 10px; }
  .result-feedback { padding: 10px 12px; }
  .footer-buttons { width: 100%; }
  .footer-buttons .btn { flex: 1; }
  .practice-toolbar { flex-wrap: wrap; }
  .journey { flex: 1 1 100%; max-width: none; margin: 2px 0 0; order: 3; gap: 8px; }
  .journey-level { font-size: 0.78rem; min-width: auto; }
  .mascot-wrap, .mascot, .mascot-svg { width: 52px; height: 52px; }
  .mascot-speech {
    left: calc(100% + 4px);
    right: auto;
    top: 4px;
    bottom: auto;
    transform: none;
    border-radius: 12px 12px 12px 4px;
    font-size: 0.78rem;
    padding: 5px 8px;
    white-space: nowrap;
    max-width: none;
    text-align: left;
  }
  #practiceInstruction { display: none; }
  .answer-row { gap: 6px; }
  .visual-area { min-height: 130px; max-height: 180px; }
}

/* Chromebook / short laptop: keep practice and the first deck row on one screen */
@media (max-height: 800px) and (min-width: 900px) {
  .visual-area { min-height: 180px; max-height: 240px; padding: 8px; }
  .welcome-screen { min-height: calc(100vh - 150px); }
  .welcome-panel { padding: 28px 36px; }
  .practice-card h2 { font-size: 1.5rem; }
  main { margin-top: 12px; margin-bottom: 12px; }
  .intro { margin-bottom: 12px; }
  .intro h1 { font-size: 1.7rem; margin: 6px 0; }
  .operations { margin-bottom: 12px; gap: 10px; }
  .op { min-height: 118px; padding: 14px 16px; }
  .op-symbol { width: 46px; height: 46px; font-size: 1.8rem; margin-bottom: 8px; }
  .deck-visual { height: 128px; }
  .section-heading { margin-bottom: 10px; }
  .deck-description { padding: 10px 14px 12px; }
  #practiceInstruction { display: none; }
  .visual-area { min-height: 160px; max-height: 210px; padding: 6px; }
  .mascot-wrap, .mascot, .mascot-svg { width: 60px; height: 60px; }
  .practice-toolbar { margin-bottom: 6px; }
  .answer-trail { margin-bottom: 6px; }
  .journey { max-width: 360px; margin: 0 6px; }
  .journey-level { font-size: 0.8rem; }
}
