:root { color-scheme: light; --bg: #f8f5ff; --surface: #fff; --text: #29263f; --muted: #625b79; --accent: #7051c5; --accent-text: #fff; --border: #ddd2f0; --soft: #ede5fb; --green: #18775a; --shadow: 0 16px 55px #7051c514; font-family: ui-rounded, 'SF Pro Rounded', system-ui, sans-serif; }
:root[data-theme="dark"] { color-scheme: dark; --bg: #17172b; --surface: #25243e; --text: #f4efff; --muted: #c0b8d5; --accent: #c1a5ff; --accent-text: #241638; --border: #4b4265; --soft: #35304e; --green: #81e0b5; --shadow: 0 16px 55px #0003; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
button { border: 1px solid var(--border); border-radius: 999px; padding: .55rem 1.15rem; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 650; }
button:hover { background: var(--soft); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.app-header { max-width: 72rem; margin: auto; padding: 1.25rem 2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { font-weight: 800; font-size: 1.25rem; color: var(--text); }
.brand span { color: var(--accent); font-weight: 500; }
main { max-width: 56rem; padding: 2.5rem 1.5rem 4rem; margin: auto; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.2; letter-spacing: -.035em; margin: .6rem 0 1rem; }
h2 { font-size: 1.45rem; line-height: 1.3; margin: 0; }
p { color: var(--muted); }
.eyebrow { color: var(--green); font-size: .85rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.welcome { margin-bottom: 2.5rem; }
.app-card { display: flex; align-items: center; gap: 1.5rem; background: var(--surface); border: 1px solid var(--border); padding: 2rem; border-radius: 1.75rem; box-shadow: var(--shadow); color: var(--text); }
.app-card + .app-card { margin-top: 1.25rem; }
.card-description { margin: .4rem 0 .75rem; font-size: .95rem; }
.app-card:hover { text-decoration: none; border-color: var(--accent); }
.card-icon { background: var(--soft); color: var(--accent); border-radius: 1.25rem; display: grid; place-items: center; min-width: 5rem; height: 5rem; font-size: 4rem; line-height: 1; }
.card-action { color: var(--accent); font-weight: 700; }
.back-link { margin-top: 2rem; }
.game { text-align: center; max-width: 38rem; margin: auto; }
.practice-card { padding: 2.5rem 1.5rem; border-radius: 2rem; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
#answer-form { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.question { display: block; font-size: clamp(2.5rem, 8vw, 4rem); font-weight: 750; letter-spacing: -.03em; color: var(--accent); }
#answer { width: 8rem; padding: .4rem; border: 2px solid var(--border); border-radius: 1rem; background: var(--bg); color: var(--text); text-align: center; font-size: 2rem; }
.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; padding: .65rem 2rem; }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.feedback { min-height: 1.6em; margin: 1rem 0 0; color: var(--green); }
#next-question { margin-top: 1rem; }
.game-actions { display: flex; justify-content: center; gap: .75rem; margin-top: 1.5rem; flex-wrap: wrap; }
.notice { font-size: .9rem; max-width: 38rem; margin: 1rem auto; padding: 0 1rem; text-align: center; }
.notice:empty { display: none; }
dialog { width: min(46rem, calc(100% - 1.5rem)); max-height: 90vh; padding: 1.5rem; border: 1px solid var(--border); border-radius: 1.5rem; background: var(--surface); color: var(--text); }
dialog::backdrop { background: #111127aa; }
.map-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
#map-pairs { display: grid; grid-template-columns: repeat(auto-fit, minmax(3.75rem, 1fr)); gap: .45rem; margin: 1rem 0; padding: 0; list-style: none; }
#map-pairs li { display: grid; place-items: center; min-height: 3.25rem; padding: .5rem .2rem; border-radius: .65rem; color: #202030; font-size: .9rem; font-weight: 750; white-space: nowrap; }
.level-unseen { background: var(--soft); color: var(--muted) !important; }
.level-0 { background: #f5b5cc; }
.level-1 { background: #f5c696; }
.level-2 { background: #f2df92; }
.level-3 { background: #bde19a; }
.level-4 { background: #92dcc5; }
.level-5 { background: #9fcdf9; }
.legend { display: flex; flex-wrap: wrap; gap: .6rem 1rem; margin-top: 1rem; font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 1rem; height: 1rem; border-radius: .25rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 35rem) { .app-header { padding: 1rem; } main { padding: 1.5rem 1rem 3rem; } .app-card { align-items: flex-start; gap: 1rem; padding: 1.5rem; } .card-icon { min-width: 3rem; height: 3rem; font-size: 2.5rem; } .practice-card { padding: 1.75rem 1rem; } dialog { padding: 1rem; } }

.header-controls { display: flex; align-items: center; gap: .5rem; }
#language-select { font: inherit; font-size: .9rem; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); max-width: 8rem; }
@media (max-width: 35rem) { .brand { font-size: 1rem; } .app-header { flex-wrap: wrap; } .header-controls button { padding: .55rem .8rem; } }

.numeric-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; width: min(17rem, 100%); }
.numeric-keypad button { border-radius: .8rem; min-height: 3.25rem; font-size: 1.35rem; padding: .4rem; touch-action: manipulation; }
#toggle-keypad { font-size: .9rem; padding: .35rem .9rem; }
button:disabled { cursor: default; opacity: .55; }
.practice-card { position: relative; }
.success-sparkles { position: absolute; top: 1.5rem; left: 0; width: 100%; display: none; pointer-events: none; color: var(--green); }
.success-sparkles span { position: absolute; left: 25%; font-size: 1.5rem; animation: sparkle-up 800ms ease-out both; }
.success-sparkles span:nth-child(2) { left: 50%; animation-delay: 70ms; color: var(--accent); }
.success-sparkles span:nth-child(3) { left: 75%; animation-delay: 140ms; }
.is-correct .success-sparkles { display: block; }
.is-correct .question { color: var(--green); animation: answer-pop 500ms ease-out; }
@keyframes answer-pop { 0% { transform: scale(1); } 40% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes sparkle-up { 0% { opacity: 0; transform: translateY(1rem) scale(.5); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(-1rem) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .is-correct .question { animation: none; } .is-correct .success-sparkles { display: none; } }

/* Fit the game and keypad into a phone viewport without clipping controls. */
body { min-height: 100dvh; }
/* Set on the root scroller as well as body for Android browser versions. */
html.multiplication-page, .multiplication-page body { overscroll-behavior-y: none; }
#heat-map { max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 35rem) {
  body[data-app="multiplication"] .app-header { padding: .5rem .75rem; gap: .5rem; }
  body[data-app="multiplication"] .brand span { display: none; }
  body[data-app="multiplication"] main { padding: .5rem .75rem 1rem; }
  .game .practice-card { padding: clamp(.5rem, 1.5dvh, 1rem); border-radius: 1.25rem; }
  .game #answer-form { gap: clamp(.35rem, 1dvh, .65rem); }
  .game .question { font-size: clamp(2rem, 7dvh, 2.75rem); line-height: 1.2; }
  .game #answer { font-size: 1.5rem; padding: .25rem; }
  .game .numeric-keypad { gap: .35rem; width: min(15rem, 100%); }
  .game .numeric-keypad button { min-height: clamp(2.5rem, 6dvh, 3rem); padding: .2rem; }
  .game .feedback { margin-top: .5rem; }
  .game #next-question { margin-top: .5rem; }
  .game .game-actions { margin-top: .75rem; gap: .5rem; }
  .game .game-actions button { font-size: .85rem; padding: .45rem .65rem; }
}

.app-menu { position: relative; }
.app-menu summary { cursor: pointer; border: 1px solid var(--border); border-radius: 999px; padding: .45rem 1rem; background: var(--surface); font-weight: 650; }
.menu-panel { position: absolute; right: 0; top: calc(100% + .5rem); z-index: 5; display: grid; gap: .75rem; width: min(17rem, calc(100vw - 1.5rem)); padding: 1rem; border: 1px solid var(--border); border-radius: 1rem; background: var(--surface); box-shadow: var(--shadow); }
.menu-panel label { font-size: .9rem; }
.menu-panel #language-select { max-width: none; width: 100%; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; }
#reset-dialog { max-width: 28rem; }
