/* Kids Math Trainer */
.kmt {
  --ink: #23243a;
  --muted: #7a7c93;
  --line: #e7e8f2;
  --soft: #f5f6fb;
  --c: #5b6cff;
  --ok: #19b36b;
  --bad: #ef4b5c;
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
.kmt *, .kmt *::before, .kmt *::after { box-sizing: border-box; }
.kmt button {
  font: inherit; color: inherit; margin: 0; border: 0; background: none;
  text-transform: none; letter-spacing: normal; box-shadow: none; text-shadow: none;
  line-height: 1.2; cursor: pointer; border-radius: 0; padding: 0; min-height: 0; width: auto;
}
.kmt button:focus-visible { outline: 3px solid var(--c); outline-offset: 2px; }
.kmt h2 { font-size: 1.45rem; font-weight: 900; margin: 0 0 16px; line-height: 1.2; color: var(--ink); }
.kmt h3 { font-size: 1.05rem; font-weight: 800; margin: 22px 0 10px; color: var(--ink); }
.kmt p { margin: 0 0 12px; }
.kmt-muted { color: var(--muted); }
.kmt-center { text-align: center; }

.kmt-card {
  background: #fff;
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(35, 36, 58, .10), 0 2px 6px rgba(35, 36, 58, .06);
  border: 1px solid var(--line);
}

/* Buttons */
.kmt .kmt-btn {
  background: var(--c); color: #fff; padding: 13px 22px; border-radius: 999px;
  font-weight: 900; font-size: 1.05rem; box-shadow: 0 4px 0 rgba(0, 0, 0, .15);
  transition: transform .08s;
}
.kmt .kmt-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.kmt .kmt-btn.alt { background: var(--ok); }
.kmt .kmt-btn.ghost { background: var(--soft); color: var(--ink); box-shadow: none; }

/* Top bar */
.kmt-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.kmt .kmt-who { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); padding: 6px 14px 6px 6px; border-radius: 999px; font-weight: 800; }
.kmt-av { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--soft); font-size: 1.25rem; }
.kmt-streak { font-weight: 900; background: #fff4e5; color: #c96a00; padding: 6px 12px; border-radius: 999px; }
.kmt-sync { font-size: 1.1rem; color: var(--ok); }
.kmt-sync.saving { color: var(--muted); }
.kmt-sync.err { color: var(--bad); }
.kmt-nav { margin-left: auto; display: flex; gap: 6px; }
.kmt .kmt-nav button { width: 44px; height: 44px; border-radius: 50%; background: #fff; border: 1px solid var(--line); font-size: 1.2rem; }

.kmt-titlebar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.kmt-titlebar h2 { margin: 0; }
.kmt .kmt-back { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); font-size: 1.2rem; font-weight: 900; flex: none; }

/* Players */
.kmt-players { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 8px; }
.kmt-player { position: relative; }
.kmt .kmt-pick { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 18px; min-width: 110px; border-radius: 20px; background: var(--soft); border: 2px solid transparent; font-weight: 900; font-size: 1.05rem; }
.kmt .kmt-pick:hover { border-color: var(--c); }
.kmt .kmt-pick .kmt-av { width: 56px; height: 56px; font-size: 2rem; background: #fff; }
.kmt .kmt-del { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: 1rem; }
.kmt-add { margin-top: 10px; padding-top: 6px; border-top: 1px dashed var(--line); }
.kmt-avatars { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 12px; }
.kmt .kmt-avbtn { width: 44px; height: 44px; border-radius: 50%; font-size: 1.4rem; background: var(--soft); border: 2px solid transparent; }
.kmt .kmt-avbtn.on { border-color: var(--c); background: #eef0ff; }
.kmt-row { display: flex; gap: 8px; justify-content: center; }
.kmt-row input {
  flex: 1; max-width: 260px; font: inherit; font-size: 1.05rem; padding: 12px 16px; margin: 0;
  border: 2px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); min-width: 0;
}
.kmt-row input:focus { outline: none; border-color: var(--c); }
.kmt-note { font-size: .9rem; color: var(--muted); margin: 16px 0 0; font-weight: 600; }
.kmt-note a { color: var(--c); }

/* Modes */
.kmt-modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kmt .kmt-mode {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 10px 14px;
  border-radius: 20px; background: color-mix(in srgb, var(--c) 10%, #fff); border: 2px solid color-mix(in srgb, var(--c) 25%, #fff);
  transition: transform .1s;
}
.kmt .kmt-mode:hover { transform: translateY(-2px); border-color: var(--c); }
.kmt-mode-ic { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: var(--c); color: #fff; font-size: 2rem; font-weight: 900; box-shadow: 0 4px 0 rgba(0, 0, 0, .15); margin-bottom: 6px; }
.kmt-mode-name { font-weight: 900; font-size: 1.05rem; }
.kmt-mode-stars { font-size: .85rem; color: #d99a00; }

/* Levels */
.kmt-rules { background: #fff8e1; padding: 12px 14px; border-radius: 14px; font-weight: 600; }
.kmt-levels { display: flex; flex-direction: column; gap: 10px; }
.kmt .kmt-level {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; text-align: left;
  background: var(--soft); border: 2px solid transparent; width: 100%;
}
.kmt .kmt-level:hover { border-color: var(--c); background: #fff; }
.kmt-lv-emoji { font-size: 2rem; width: 48px; text-align: center; flex: none; }
.kmt-lv-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.kmt-lv-text small, .kmt-lv-best small { color: var(--muted); font-weight: 600; font-size: .85rem; }
.kmt-lv-best { display: flex; flex-direction: column; align-items: flex-end; flex: none; }

/* Stars */
.kmt-stars { color: #ffb400; letter-spacing: 1px; font-size: 1.15rem; white-space: nowrap; }
.kmt-stars i { color: #dcdde8; font-style: normal; }
.kmt-stars.big { font-size: 3.2rem; display: block; margin-bottom: 4px; }
.kmt-stars.mini { font-size: .85rem; letter-spacing: 0; }

/* Game */
.kmt-gbar { display: flex; align-items: center; gap: 12px; }
.kmt .kmt-x, .kmt .kmt-fsbtn { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); color: var(--muted); font-size: 1rem; flex: none; }
.kmt-prog { flex: 1; height: 12px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.kmt-prog i { display: block; height: 100%; width: 0; background: var(--c); border-radius: 99px; transition: width .3s; }
.kmt-clock { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 52px; text-align: right; }
.kmt-qcount { text-align: center; color: var(--muted); font-size: 1.05rem; margin: 12px 0 4px; }

.kmt-q {
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px;
  font-size: clamp(3rem, 13vw, 4.8rem); font-weight: 900; min-height: 120px; margin: 6px 0;
  font-variant-numeric: tabular-nums;
}
.kmt-blank {
  min-width: 1.6em; padding: 0 .25em; text-align: center; border-radius: 16px;
  background: color-mix(in srgb, var(--c) 12%, #fff); border: 3px dashed var(--c); color: var(--c);
}
.kmt-blank.ok { background: #e3f8ee; border: 3px solid var(--ok); color: var(--ok); }
.kmt-blank.bad { background: #fde8ea; border: 3px solid var(--bad); color: var(--bad); animation: kmt-shake .4s; }
.kmt-fb { text-align: center; min-height: 1.6em; font-size: 1.5rem; font-weight: 900; margin-bottom: 10px; }
.kmt-fb.ok { color: var(--ok); }
.kmt-fb.bad { color: var(--bad); }

.kmt-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 400px; margin: 0 auto; }
.kmt .kmt-pad button {
  height: 76px; border-radius: 20px; background: var(--soft); font-size: 2.2rem; font-weight: 900;
  box-shadow: 0 4px 0 #dfe1ee; transition: transform .06s;
  user-select: none; touch-action: manipulation;
}
.kmt .kmt-pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #dfe1ee; }
.kmt .kmt-pad .kmt-k-ok { background: var(--c); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, .2); }
.kmt .kmt-pad .kmt-k-del { color: var(--muted); }

/* Kakooma */
.kmt-hint { text-align: center; color: var(--muted); font-weight: 700; min-height: 1.4em; }
.kmt-hint.ok { color: var(--ok); font-size: 1.35rem; font-weight: 900; }
.kmt-board { position: relative; margin: 0 auto; }
.kmt-board.kmt-single { width: min(380px, 92%); aspect-ratio: 1; }
.kmt-board.kmt-flower { width: min(600px, 100%); aspect-ratio: 1; }
.kmt-grp { position: absolute; inset: 0; --bg: #fff3cc; }
.kmt-grp::before {
  content: ''; position: absolute; inset: 0; background: var(--bg);
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
  transition: background .25s;
}
.kmt-flower .kmt-grp { inset: auto; width: 36%; aspect-ratio: 1; transform: translate(-50%, -50%); }
.kmt-flower .kmt-grp.c { --bg: #ffe08a; }
.kmt-flower .kmt-grp.solved { --bg: #d6f5e5; }
.kmt-flower .kmt-grp.c.active { --bg: #ffd24d; }
.kmt-board.done .kmt-grp.c { --bg: #a8ecc8; }
.kmt-dot {
  position: absolute; left: 50%; top: 55%; width: 16%; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: #5ec8f0; clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
}
.kmt .kmt-n {
  position: absolute; transform: translate(-50%, -40%);
  width: 28%; aspect-ratio: 1; border-radius: 50%; background: #fff;
  font-size: clamp(1.1rem, 5vw, 1.75rem); font-weight: 900; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .12); display: grid; place-items: center; padding: 0;
  touch-action: manipulation;
}
.kmt-single .kmt-n { width: 26%; font-size: clamp(2rem, 9vw, 2.9rem); }
.kmt .kmt-n:disabled { background: rgba(255, 255, 255, .55); box-shadow: none; cursor: default; }
.kmt .kmt-n.ok { background: var(--ok); color: #fff; }
.kmt .kmt-n.bad { animation: kmt-shake .4s; background: #fde8ea; color: var(--bad); }
.kmt .kmt-n.pop { animation: kmt-pop .35s; }
.kmt-flower .kmt-grp.solved .kmt-n:not(.ok) { opacity: .45; }

/* Results */
.kmt-results h2 { margin-bottom: 8px; }
.kmt-badge { display: inline-block; background: #fff4e5; color: #c96a00; padding: 6px 14px; border-radius: 999px; margin-bottom: 10px; }
.kmt-score { font-size: 1.15rem; color: var(--muted); }
.kmt-missed { background: var(--soft); border-radius: 16px; padding: 4px 16px 12px; margin: 10px auto 4px; max-width: 360px; }
.kmt-missed h3 { margin-top: 12px; }
.kmt-missed div { font-size: 1.6rem; font-weight: 900; padding: 3px 0; }
.kmt-missed b { color: var(--ok); }
.kmt-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }

/* Progress */
.kmt-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.kmt-tiles div { background: var(--soft); border-radius: 16px; padding: 12px; text-align: center; display: flex; flex-direction: column; }
.kmt-tiles b { font-size: 1.35rem; font-weight: 900; }
.kmt-tiles span { color: var(--muted); font-size: .85rem; }
.kmt-chart { display: flex; align-items: flex-end; gap: 5px; height: 130px; padding: 6px 2px 0; }
.kmt-bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.kmt-bar i { display: block; width: 100%; max-width: 28px; min-height: 3px; background: #c9cdf8; border-radius: 6px 6px 2px 2px; }
.kmt-bar.today i { background: var(--c); }
.kmt-bar span { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.kmt-tablewrap { overflow-x: auto; }
.kmt-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 0; border: 0; }
.kmt-table th, .kmt-table td { padding: 7px 5px; text-align: center; border: 0; border-bottom: 1px solid var(--line); background: none; }
.kmt-table tbody th { text-align: left; white-space: nowrap; }
.kmt-table thead th small { display: block; font-size: .72rem; color: var(--muted); }
.kmt-table td small { display: block; color: var(--muted); font-weight: 600; font-size: .75rem; }
.kmt-table .kmt-empty { color: #c6c8d6; }
.kmt-table .kmt-sub th { color: var(--muted); font-size: .8rem; padding-top: 14px; text-align: center; }
.kmt-recent { list-style: none; margin: 0; padding: 0; }
.kmt-recent li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .92rem; margin: 0; }

/* Full screen */
.kmt .kmt-nav .kmt-fsbtn { width: 44px; height: 44px; background: #fff; border: 1px solid var(--line); font-size: 1.3rem; }
.kmt-gbar .kmt-fsbtn { background: var(--soft); color: var(--muted); font-size: 1.2rem; flex: none; border-radius: 50%; }
.kmt.kmt-fs {
  position: fixed; inset: 0; z-index: 999999; max-width: none; margin: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: linear-gradient(160deg, #eef1ff, #fff6e8);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.kmt.kmt-fs > * { max-width: 860px; margin-left: auto; margin-right: auto; }
.kmt.kmt-fs .kmt-q { font-size: clamp(3.4rem, 14vw, 6rem); min-height: 150px; }
.kmt.kmt-fs .kmt-pad { max-width: 460px; }
.kmt.kmt-fs .kmt-pad button { height: 84px; font-size: 2.5rem; }
.kmt.kmt-fs .kmt-board.kmt-flower { width: min(680px, 100%, 70vh); }
.kmt.kmt-fs .kmt-board.kmt-single { width: min(440px, 92%, 55vh); }
html.kmt-fs-lock, html.kmt-fs-lock body { overflow: hidden; }

/* Confetti */
.kmt-confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.kmt-confetti span { position: absolute; top: -40px; font-size: 1.6rem; animation: kmt-fall linear forwards; }

@keyframes kmt-shake { 0%, 100% { translate: 0; } 25% { translate: -6px; } 75% { translate: 6px; } }
@keyframes kmt-pop { 0% { scale: .4; } 70% { scale: 1.15; } 100% { scale: 1; } }
@keyframes kmt-fall { to { transform: translateY(720px) rotate(320deg); opacity: 0; } }

@media (max-width: 480px) {
  .kmt-table { font-size: .8rem; }
  .kmt-table th, .kmt-table td { padding: 6px 2px; }
  .kmt-table tbody th { white-space: normal; }
  .kmt-table thead th small { font-size: .62rem; }
  .kmt-stars.mini { font-size: .7rem; }
  .kmt-card { padding: 16px; border-radius: 20px; }
  .kmt-modes { grid-template-columns: 1fr 1fr; }
  .kmt-recent li { grid-template-columns: 1fr auto; }
  .kmt-recent li span:nth-child(4) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .kmt *, .kmt *::before, .kmt *::after { animation: none !important; transition: none !important; }
}

/* Halves with pizza (1.0.8) */
.kmt-viz:empty { display: none; }
.kmt-viz { display: flex; justify-content: center; margin: 4px 0 -4px; }
.kmt-pizza { width: min(240px, 52vw); height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.12)); }
.kmt.kmt-fs .kmt-pizza { width: min(320px, 38vh); }
