/* Times Tables Sprint, MIT licence, (c) learnwith.games. System fonts only. */
:root {
  --ink: #1b1f3b;
  --ink-soft: #474d70;
  --bg: #fffaf0;
  --card: #ffffff;
  --line: #e6e1d3;
  --brand: #3b5bdb;
  --brand-dark: #2b44b0;
  --brand-soft: #e5ebff;
  --sun: #ffd23f;
  --sun-dark: #e0a800;
  --good: #2b8a3e;
  --good-soft: #e3f9e5;
  --bad: #c92a2a;
  --bad-soft: #ffe3e3;
  --focus: #ff8a00;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 2px 0 rgba(27, 31, 59, .06), 0 8px 24px rgba(27, 31, 59, .08);
  --font-kid: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(circle at 10% 0%, #fff1d6 0, transparent 45%), radial-gradient(circle at 100% 100%, #e5ebff 0, transparent 40%);
}
#app {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}
h1, h2, .btn, .answer, .stat-value, .big-score, legend { font-family: var(--font-kid); }
h1 { font-size: clamp(1.8rem, 6vw, 2.4rem); margin: 0 0 4px; line-height: 1.1; }
.lead { margin: 0; color: var(--ink-soft); font-size: 1.1rem; }
.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;
}
[hidden] { display: none !important; }

.screen {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Start */
.hero { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.jigby { display: block; flex: none; }
.jigby-hero { width: 120px; height: 120px; }
.tables { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 700; font-size: 1.15rem; margin-bottom: 10px; padding: 0; }
.table-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.table-btn {
  font: inherit; font-family: var(--font-kid); font-weight: 700; font-size: 1.25rem;
  min-height: 52px; border-radius: var(--radius-sm);
  border: 2px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer;
}
.table-btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand-dark); color: #fff; }
.table-btn:hover { border-color: var(--brand); }

.start-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  font: inherit; font-family: var(--font-kid); font-weight: 700; font-size: 1.15rem;
  min-height: 52px; padding: 0 22px; border-radius: 999px; cursor: pointer;
  border: 2px solid transparent;
}
.btn-go { background: var(--sun); border-color: var(--sun-dark); color: var(--ink); box-shadow: 0 4px 0 var(--sun-dark); }
.btn-go:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--sun-dark); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); }
.btn-small { min-height: 40px; font-size: .95rem; padding: 0 16px; margin-top: 14px; }
.hint { color: var(--ink-soft); margin: 14px 0 0; font-size: .95rem; }
kbd {
  font-family: var(--font-body); font-size: .85em; border: 1px solid var(--line);
  border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; background: var(--bg);
}

/* Focus: always visible for keyboard users */
button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 4px solid var(--focus); outline-offset: 3px;
}

/* Game */
.hud { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat { background: var(--bg); border-radius: var(--radius-sm); padding: 6px 4px; }
.stat-label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.stat-value { display: block; font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.timebar { height: 10px; background: var(--line); border-radius: 999px; margin: 10px 0 6px; overflow: hidden; }
.timebar-fill { height: 100%; width: 100%; background: var(--brand); border-radius: 999px; transform-origin: left; }
.timebar-fill.low { background: var(--bad); }

.stage { display: flex; align-items: center; gap: 8px; min-height: 150px; }
.jigby-game { width: 110px; height: 110px; }
.question-wrap { flex: 1; text-align: center; }
.table-tag { margin: 0; color: var(--ink-soft); font-size: .95rem; }
.question { font-size: clamp(2.8rem, 13vw, 4.2rem); margin: 0; line-height: 1.1; font-variant-numeric: tabular-nums; }
.feedback { margin: 2px 0 0; font-weight: 700; min-height: 1.4em; font-size: 1.05rem; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.answer {
  position: relative; font: inherit; font-family: var(--font-kid);
  font-size: clamp(1.8rem, 8vw, 2.4rem); font-weight: 800; font-variant-numeric: tabular-nums;
  min-height: 84px; border-radius: var(--radius); cursor: pointer;
  background: var(--brand-soft); color: var(--ink); border: 3px solid #c5d1ff;
  box-shadow: 0 4px 0 #c5d1ff; touch-action: manipulation;
}
.answer:hover { border-color: var(--brand); }
.answer:active { transform: translateY(2px); box-shadow: 0 2px 0 #c5d1ff; }
.answer .key {
  position: absolute; top: 8px; left: 10px; font-family: var(--font-body);
  font-size: .8rem; font-weight: 700; color: var(--ink-soft);
  border: 1px solid #c5d1ff; border-radius: 6px; padding: 0 6px; background: #fff;
}
.answer.is-right { background: var(--good-soft); border-color: var(--good); box-shadow: 0 4px 0 var(--good); }
.answer.is-wrong { background: var(--bad-soft); border-color: var(--bad); box-shadow: 0 4px 0 var(--bad); }
.answers.locked .answer { cursor: default; }

/* End */
#screen-end { text-align: center; }
#screen-end .jigby-hero { margin: 0 auto; width: 140px; height: 140px; }
#end-title { font-size: 2rem; margin: 8px 0 0; }
#end-title:focus { outline: none; }
.big-score { font-size: 3.6rem; font-weight: 800; margin: 4px 0; line-height: 1; }
.big-score .unit { font-size: 1.2rem; color: var(--ink-soft); font-weight: 700; }
.summary { list-style: none; padding: 0; margin: 10px 0 14px; color: var(--ink-soft); line-height: 1.7; }
.new-best { display: inline-block; background: var(--sun); border-radius: 999px; padding: 4px 14px; font-weight: 800; margin: 0 0 14px; }
#screen-end .start-row { justify-content: center; }
.more { margin: 18px 0 0; font-size: 1.1rem; font-weight: 700; }
a { color: var(--brand-dark); }

.footer { text-align: center; color: var(--ink-soft); font-size: .9rem; padding: 8px 16px 18px; }
.footer p { margin: 0; }

/* Motion (switched off for reduced-motion users below) */
.bounce { animation: bounce .45s ease; }
.shake { animation: shake .4s ease; }
.pop { animation: pop .25s ease; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-14px); } 70% { transform: translateY(-4px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px) rotate(-3deg); } 75% { transform: translateX(6px) rotate(3deg); } }
@keyframes pop { 0% { transform: scale(.85); opacity: .4; } 100% { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 380px) {
  .screen { padding: 14px; }
  .table-grid { grid-template-columns: repeat(3, 1fr); }
  .jigby-game { width: 80px; height: 80px; }
}
