/* Brain games: hub, shared game frame (intro, status chips, result overlay) and the five games. */

/* ---------- hub ---------- */
.gm-hub { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.gm-hub-hi { display: flex; align-items: center; gap: 14px; }
.gm-hub-hi svg { display: block; }
.gm-hub-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.gm-card {
  position: relative; overflow: hidden; background: #fff; border-radius: var(--r); box-shadow: var(--sh);
  padding: 0 18px 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; transition: transform .12s;
}
.gm-card::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 62px; background: var(--gc); opacity: .2; }
.gm-card:hover { transform: translateY(-4px); }
.gm-card:focus-visible { outline: 4px solid var(--gc); outline-offset: 3px; }
.gm-card-ic {
  position: relative; margin-top: 16px; width: 84px; height: 84px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 5px var(--gc); display: grid; place-items: center; font-size: 46px; line-height: 1;
}
.gm-card-name { font-size: 23px; margin-top: 6px; }
.gm-card-desc { color: var(--ink2); font-weight: 700; font-size: 15px; line-height: 1.3; min-height: 2.6em; }
.gm-card-stat { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px; font-size: 15px; font-weight: 800; color: var(--ink2); margin-top: 2px; }
.gm-card-stat > span { background: #F4F7FC; border-radius: 999px; padding: 4px 12px; }
.gm-card-stat > .gm-new { color: var(--green-d); background: #E3FBF3; }
.gm-age { position: absolute; top: 10px; right: 12px; font-size: 14px; font-weight: 900; background: #fff; color: var(--ink2); padding: 2px 10px; border-radius: 999px; }

/* ---------- shared game frame ---------- */
.gm-main { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; padding: 0 20px 16px; }
.gm-stage { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; }
.gm-intro { width: 100%; max-width: 760px; margin: auto; padding: 24px 32px 28px; display: flex; flex-direction: column; gap: 16px; animation: fadeIn .25s; }
.gm-intro-head { display: flex; align-items: center; gap: 16px; }
.gm-intro-ic { width: 64px; height: 64px; flex: none; border-radius: 20px; display: grid; place-items: center; font-size: 38px; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .12); }
.gm-intro-head h2 { font-size: 32px; flex: 1; }
.gm-rules { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 20px; font-weight: 700; line-height: 1.35; }
.gm-rules li { position: relative; padding-left: 30px; }
.gm-rules li::before { content: ''; position: absolute; left: 6px; top: .45em; width: 12px; height: 12px; border-radius: 50%; background: var(--yellow); box-shadow: inset 0 0 0 2px #E0B800; }
.gm-lvl-box { background: #F4F7FC; border-radius: var(--r-s); padding: 12px 14px 14px; }
.gm-lvl-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-weight: 900; color: var(--ink2); margin-bottom: 10px; }
.gm-lvl-title small { font-weight: 700; color: var(--muted); font-size: 14px; }
.gm-lvls { display: flex; flex-wrap: wrap; gap: 10px; }
.gm-lvl {
  position: relative; flex: 1 1 110px; min-height: 60px; padding: 8px 12px; border-radius: 16px; background: #fff;
  box-shadow: 0 4px 0 var(--line), inset 0 0 0 2px var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.gm-lvl b { font-size: 18px; }
.gm-lvl small { font-size: 13px; font-weight: 700; color: var(--muted); }
.gm-lvl:hover:not(.on) { box-shadow: 0 4px 0 var(--line), inset 0 0 0 2px var(--blue); }
.gm-lvl.on { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-d); }
.gm-lvl.on small { color: #DDE9FF; }
.gm-foryou {
  position: absolute; top: -9px; right: -6px; width: 26px; height: 26px; border-radius: 50%; background: var(--yellow); color: #9A6B00;
  display: grid; place-items: center; font-size: 15px; box-shadow: 0 2px 0 #E0B800;
}
.gm-go { align-self: center; min-width: 260px; }
.gm-speak { flex: none; }

.gm-bar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.gm-chip { display: inline-flex; align-items: center; gap: 7px; background: #fff; border-radius: 999px; padding: 6px 16px 6px 10px; box-shadow: var(--sh); font-size: 20px; min-height: 44px; }
.gm-chip small { color: var(--muted); font-weight: 800; font-size: 14px; }
.gm-chip b { font-variant-numeric: tabular-nums; }
.gm-chip-ic { font-size: 19px; }
.gm-frac { display: inline-flex; flex-direction: column; align-items: center; font-weight: 900; line-height: 1.05; }
.gm-frac > span:first-child { border-bottom: .09em solid currentColor; padding: 0 .18em .04em; }
.gm-frac > span:last-child { padding-top: .04em; }

/* result overlay */
.gm-end { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(230, 244, 255, .78); animation: fadeIn .3s; overflow: auto; }
.gm-end-card { width: 100%; max-width: 660px; padding: 20px 28px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.gm-end-card h2 { font-size: 34px; }
.gm-end-bot svg { display: block; }
.gm-stars { font-size: 50px; line-height: 1; }
.gm-end-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.gm-end-stats > div { flex: 1 1 110px; background: #F4F7FC; border-radius: 16px; padding: 10px 8px; display: flex; flex-direction: column; }
.gm-end-stats b { font-size: 26px; }
.gm-end-stats small { color: var(--muted); font-weight: 700; }
.gm-notes { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.gm-note { background: #F4F7FC; border-radius: 14px; padding: 8px 14px; font-weight: 800; }
.gm-note.good { background: #E3FBF3; }
.gm-note.badge { background: #FFF6D6; }
.gm-end-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 6px; }
.gm-end-btns .btn.big { padding: 14px 24px; font-size: 20px; }

/* ---------- memory ("Pairs") ---------- */
.mem-wrap { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.mem-board {
  --gap: 12px;
  --cw: min(150px, calc((100vw - 60px) / var(--cols) - var(--gap)), calc(((100vh - 196px) / var(--rows) - var(--gap)) / 1.12));
  display: grid; grid-template-columns: repeat(var(--cols), var(--cw)); gap: var(--gap); margin: auto 0;
}
.mem-card { width: var(--cw); height: calc(var(--cw) * 1.12); padding: 0; border-radius: 18px; perspective: 900px; }
.mem-card:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
.mem-inner { position: relative; display: block; width: 100%; height: 100%; transition: transform .4s ease; transform-style: preserve-3d; }
.mem-card.up .mem-inner { transform: rotateY(180deg); }
.mem-back, .mem-face { position: absolute; inset: 0; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-items: center; }
.mem-back {
  background: radial-gradient(circle at 25% 25%, rgba(255, 255, 255, .18) 0 9%, transparent 10%) 0 0 / 28px 28px, linear-gradient(145deg, #8374F2, #5B4BD8);
  box-shadow: 0 5px 0 #4536B5; transition: transform .12s;
}
.mem-card:hover:not(.up) .mem-back { transform: translateY(-3px); }
.mem-back span {
  width: 48%; aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .22); display: grid; place-items: center;
  color: #fff; font-size: calc(var(--cw) * .3); font-weight: 900;
}
.mem-face { background: #fff; transform: rotateY(180deg); box-shadow: 0 5px 0 var(--line), inset 0 0 0 3px var(--line); padding: 8%; color: var(--ink); }
.mem-face.num { background: #FFFBEA; }
.mem-card.done .mem-face { background: #EAFBF4; box-shadow: 0 5px 0 var(--green-d), inset 0 0 0 4px var(--green); }
.mem-card.done { animation: memPop .45s ease; }
.mem-card.miss { animation: shake .45s; }
.mem-card.miss .mem-face { box-shadow: 0 5px 0 #E8A0A0, inset 0 0 0 4px var(--red); }
@keyframes memPop { 50% { transform: scale(1.07); } }
.mem-t { font-weight: 900; font-size: calc(var(--cw) * .27); white-space: nowrap; line-height: 1; }
.mem-t.xl { font-size: calc(var(--cw) * .42); }
.mem-t.m { font-size: calc(var(--cw) * .3); }
.mem-t.s { font-size: calc(var(--cw) * .2); }
.mem-face svg { width: 84%; height: auto; max-height: 84%; display: block; }
.mem-face .gm-frac { font-size: calc(var(--cw) * .27); }

/* ---------- sudoku ---------- */
.sdk-wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; gap: 28px; }
.sdk-grid {
  --cell: min(calc((100vh - 128px) / var(--n) - 3px), calc((100vw - 380px) / var(--n) - 3px), 70px);
  display: grid; grid-template-columns: repeat(var(--bc), auto); gap: 4px; padding: 4px; background: var(--ink); border-radius: 14px;
  box-shadow: var(--sh); flex: none; transition: background .4s;
}
.sdk-n4 { --cell: min(calc((100vh - 150px) / 4), 116px); }
.sdk-n6 { --cell: min(calc((100vh - 140px) / 6 - 3px), calc((100vw - 380px) / 6 - 3px), 86px); }
.sdk-grid.solved { background: var(--green-d); }
.sdk-box { display: grid; grid-template-columns: repeat(var(--bw), var(--cell)); gap: 2px; background: #B8C5DC; }
.sdk-cell {
  width: var(--cell); height: var(--cell); padding: 0; background: #fff; display: grid; place-items: center;
  font-size: calc(var(--cell) * .56); font-weight: 900; color: var(--blue-d); line-height: 1; outline: none;
}
.sdk-cell svg { display: block; width: 70%; height: 70%; }
.sdk-cell.given { color: var(--ink); background: #EEF2F9; }
.sdk-cell.peer { background: #E8F1FF; }
.sdk-cell.given.peer { background: #DCE7F7; }
.sdk-cell.same { background: #CFE0FF; }
.sdk-cell.hint { color: var(--green-d); }
.sdk-cell.bad { color: #E03131; background: #FFE3E3; }
.sdk-cell.sel { background: #FFE58A; box-shadow: inset 0 0 0 3px #F0B400; }
.sdk-cell.bad.sel { background: #FFD3D3; box-shadow: inset 0 0 0 3px var(--red); }
.sdk-cell.clash { box-shadow: inset 0 0 0 4px var(--red); animation: sdkClash .7s 2; }
.sdk-cell.glow { animation: sdkGlow .7s ease; }
.sdk-cell:focus-visible { box-shadow: inset 0 0 0 3px var(--blue); }
.sdk-cell.sel:focus-visible { box-shadow: inset 0 0 0 3px #F0B400; }
@keyframes sdkClash { 50% { background: #FFC9C9; } }
@keyframes sdkGlow { 40% { background: #BFF3DE; } }
.sdk-side { width: 290px; flex: none; display: flex; flex-direction: column; gap: 16px; }
.sdk-bar { justify-content: flex-start; }
.sdk-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sdk-pad4 { grid-template-columns: repeat(2, 1fr); }
.sdk-key {
  height: 72px; border-radius: 18px; background: #fff; font-size: 34px; font-weight: 900; color: var(--blue-d);
  box-shadow: 0 5px 0 var(--line), inset 0 0 0 2px var(--line); display: grid; place-items: center; transition: transform .08s, opacity .2s;
}
.sdk-pad4 .sdk-key { height: 96px; font-size: 42px; }
.sdk-key svg { width: 58px; height: 58px; display: block; }
.sdk-key:hover { box-shadow: 0 5px 0 var(--line), inset 0 0 0 3px var(--blue); }
.sdk-key:active { transform: translateY(3px); }
.sdk-key.full { opacity: .35; }
.sdk-acts { display: flex; flex-wrap: wrap; gap: 10px; }
.sdk-act { flex: 1 1 110px; min-height: 48px; padding: 12px 8px; font-size: 17px; white-space: nowrap; }

/* ---------- tower of Hanoi ---------- */
.hn-wrap { flex: 1; width: 100%; max-width: 1100px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hn-hint { min-height: 48px; padding: 9px 18px; font-size: 18px; }
.hn-board {
  --h: min(470px, calc(100vh - 226px)); --dh: min(46px, calc((var(--h) - 110px) / (var(--n) + 1)));
  width: 100%; height: var(--h); display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; touch-action: none; margin: auto 0;
}
.hn-rod { position: relative; height: 100%; padding: 0; border-radius: 22px; background: rgba(255, 255, 255, .5); transition: background .15s, box-shadow .15s; }
.hn-rod:hover, .hn-rod.cur { background: rgba(255, 255, 255, .92); }
.hn-rod:focus-visible { outline: 4px solid var(--blue); outline-offset: 2px; }
.hn-rod.from { box-shadow: inset 0 0 0 5px var(--blue); }
.hn-rod.to { box-shadow: inset 0 0 0 5px var(--green); background: #EAFFF6; }
.hn-pole { position: absolute; left: 50%; bottom: 22px; width: 14px; margin-left: -7px; height: calc(var(--dh) * var(--n) + var(--dh) * .7 + 10px); border-radius: 7px 7px 0 0; background: linear-gradient(90deg, #A67C52, #D2A578, #A67C52); }
.hn-base { position: absolute; left: 6%; right: 6%; bottom: 10px; height: 16px; border-radius: 8px; background: #8D6A48; }
.hn-rod.goal .hn-base { background: var(--green-d); }
.hn-flag { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); font-size: 34px; line-height: 1; }
.hn-stack { position: absolute; left: 0; right: 0; bottom: 26px; display: flex; flex-direction: column-reverse; align-items: center; gap: 3px; pointer-events: none; }
.hn-disc {
  display: block; width: var(--w); height: var(--dh); border-radius: 999px; background: var(--c);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14), inset 0 0 0 3px rgba(45, 49, 66, .22);
}
.hn-disc.gone { opacity: .22; }
.hn-lift { position: absolute; left: 0; right: 0; top: 54px; display: flex; justify-content: center; pointer-events: none; animation: hnUp .16s ease-out; }
.hn-disc.held { box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14), inset 0 0 0 3px rgba(45, 49, 66, .22), 0 12px 18px rgba(45, 49, 66, .22); }
@keyframes hnUp { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.hn-mark { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); font-size: 40px; line-height: 1; animation: hnBob 1s ease-in-out infinite; pointer-events: none; }
@keyframes hnBob { 50% { transform: translate(-50%, 8px); } }
.hn-board.solved .hn-rod.goal { background: #E3FBF3; }
.hn-board.solved .hn-rod.goal .hn-stack { animation: memPop .5s ease; }
.hn-msg { min-height: 30px; font-size: 20px; font-weight: 800; color: #D9480F; text-align: center; }

/* ---------- quick maths ---------- */
.spd-wrap { flex: 1; width: 100%; max-width: 980px; display: flex; flex-direction: column; gap: 16px; }
.spd-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
.spd-timer { flex: 1 1 360px; display: flex; align-items: center; gap: 12px; }
.spd-clock { font-size: 26px; }
.spd-track { flex: 1; height: 22px; background: #fff; border-radius: 999px; overflow: hidden; box-shadow: inset 0 0 0 3px var(--line); }
.spd-fill { width: 100%; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), var(--blue)); }
.spd-fill.low { background: linear-gradient(90deg, var(--red), var(--orange)); }
.spd-sec { font-size: 30px; min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.spd-combo { gap: 10px; }
.spd-segs { display: inline-flex; gap: 4px; }
.spd-segs i { width: 14px; height: 24px; border-radius: 5px; background: #E3E8F2; transition: background .15s; }
.spd-segs i.on { background: var(--orange); }
.spd-mult { font-size: 22px; min-width: 38px; }
.spd-mult.hot { color: #E8590C; }
.spd-card { position: relative; flex: 1; min-height: 180px; display: grid; place-items: center; padding: 16px; }
.spd-q { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spd-text { font-size: 78px; font-weight: 900; white-space: nowrap; line-height: 1.1; }
.spd-text.long { font-size: 58px; }
.spd-dots { display: flex; align-items: center; gap: 14px; }
.spd-dots b { font-size: 40px; }
.spd-dots svg { display: block; }
.spd-count { font-size: 84px; font-weight: 900; color: var(--blue); animation: spdIn .35s ease; }
.spd-count.go { color: var(--green-d); }
@keyframes spdIn { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.spd-float { position: absolute; right: 44px; top: 40px; font-size: 34px; font-weight: 900; color: #E0A800; opacity: 0; pointer-events: none; }
.spd-float.go { animation: spdFloat .8s ease-out; }
@keyframes spdFloat { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-46px); } }
.spd-opts { display: grid; gap: 16px; }
.spd-o3 { grid-template-columns: repeat(3, 1fr); }
.spd-o4 { grid-template-columns: repeat(4, 1fr); }
.spd-opt {
  position: relative; height: 108px; border-radius: 24px; background: #fff; font-size: 46px; font-weight: 900;
  box-shadow: 0 6px 0 var(--line), inset 0 0 0 3px var(--line); transition: transform .08s;
}
.spd-opt:hover:not(:disabled) { box-shadow: 0 6px 0 var(--line), inset 0 0 0 3px var(--blue); }
.spd-opt:active:not(:disabled) { transform: translateY(4px); }
.spd-opt:disabled { cursor: default; }
.spd-opt.right { background: #E3FBF3; box-shadow: 0 6px 0 var(--green-d), inset 0 0 0 4px var(--green); }
.spd-opt.wrong { background: #FFE9E9; box-shadow: 0 6px 0 #E8A0A0, inset 0 0 0 4px var(--red); animation: shake .45s; }
.spd-key { position: absolute; top: 8px; left: 14px; font-size: 14px; font-weight: 800; color: var(--muted); }

/* ---------- make 10 ---------- */
.m10-wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; gap: 28px; }
.m10-side { width: 300px; flex: none; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.m10-target { text-align: center; }
.m10-target small { color: var(--muted); font-weight: 800; font-size: 15px; }
.m10-sum { font-size: 46px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.m10-sum span { color: var(--muted); font-size: 30px; }
.m10-sum-n.over { color: var(--red); }
.m10-sum-n.hit { color: var(--green-d); }
.m10-meter.cells { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.m10-meter.cells i { aspect-ratio: 1; border-radius: 6px; background: #EEF2F8; box-shadow: inset 0 0 0 2px var(--line); transition: background .15s; }
.m10-meter.cells i.on { background: var(--orange); box-shadow: inset 0 0 0 2px #E8890C; }
.m10-meter.c20 i.on:nth-child(n+11) { background: var(--blue); box-shadow: inset 0 0 0 2px var(--blue-d); }
.m10-meter.bar { position: relative; height: 24px; border-radius: 999px; overflow: hidden; background: #EEF2F8; box-shadow: inset 0 0 0 2px var(--line); }
.m10-meter.bar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(255, 255, 255, .8) calc(10% - 2px) 10%); }
.m10-meter-fill { height: 100%; width: 0; background: var(--orange); transition: width .2s; }
.m10-expr { text-align: center; font-weight: 800; font-size: 20px; min-height: 28px; color: var(--ink2); }
.m10-goal { height: 12px; border-radius: 999px; background: #EEF2F8; overflow: hidden; }
.m10-goal-fill { height: 100%; width: 0; background: var(--green); transition: width .3s; }
.m10-btns { display: flex; flex-direction: column; gap: 10px; }
.m10-btns .btn { min-height: 48px; padding: 11px 12px; font-size: 18px; }
.m10-msg { min-height: 46px; font-weight: 800; color: #D9480F; text-align: center; }
.m10-board {
  --t: min(116px, calc((100vh - 130px) / var(--rows) - 14px), calc((100vw - 400px) / var(--cols) - 14px));
  display: grid; grid-template-columns: repeat(var(--cols), var(--t)); gap: 14px; flex: none;
}
.m10-tile {
  width: var(--t); height: var(--t); padding: 0; border-radius: 22px; background: #fff; font-weight: 900; color: var(--ink);
  box-shadow: 0 6px 0 var(--line), inset 0 0 0 3px var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .12s, background .12s;
}
.m10-v { font-size: calc(var(--t) * .4); line-height: 1; }
.m10-tile:hover { box-shadow: 0 6px 0 var(--line), inset 0 0 0 3px var(--blue); }
.m10-tile:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
.m10-tile.sel { background: #FFF1C2; box-shadow: 0 6px 0 #E0B000, inset 0 0 0 4px #FFC300; transform: translateY(-5px); }
.m10-tile.hint { box-shadow: 0 6px 0 var(--green-d), inset 0 0 0 4px var(--green); animation: m10Hint 1s ease infinite; }
.m10-tile.pop { animation: m10Pop .42s ease forwards; }
.m10-tile.drop { animation: m10Drop .38s ease; }
@keyframes m10Hint { 50% { transform: translateY(-5px); } }
@keyframes m10Pop { 30% { transform: scale(1.12); background: #C9F7E6; } to { transform: scale(0); opacity: 0; } }
@keyframes m10Drop { from { transform: translateY(-30px) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.m10-pips { display: grid; grid-template-columns: repeat(5, auto); justify-content: center; gap: 3px; }
.m10-pips i { width: calc(var(--t) * .085); height: calc(var(--t) * .085); border-radius: 50%; background: #FF6B6B; }

/* ---------- smaller windows ---------- */
@media (max-width: 1000px) {
  .gm-hub-grid { gap: 14px; }
  .sdk-wrap, .m10-wrap { gap: 18px; }
  .sdk-side { width: 240px; }
  .sdk-grid { --cell: min(calc((100vh - 128px) / var(--n) - 3px), calc((100vw - 310px) / var(--n) - 3px), 70px); }
  .sdk-n4 { --cell: min(calc((100vh - 150px) / 4), calc((100vw - 330px) / 4), 116px); }
  .sdk-n6 { --cell: min(calc((100vh - 140px) / 6 - 3px), calc((100vw - 310px) / 6 - 3px), 86px); }
  .sdk-key { height: 62px; }
  .sdk-pad4 .sdk-key { height: 84px; }
  .m10-side { width: 250px; padding: 14px; }
  .m10-board { --t: min(116px, calc((100vh - 130px) / var(--rows) - 14px), calc((100vw - 330px) / var(--cols) - 14px)); }
  .spd-text { font-size: 64px; }
  .spd-opt { height: 96px; font-size: 40px; }
}
@media (max-width: 760px) {
  .gm-hub-grid { grid-template-columns: repeat(2, 1fr); }
  .gm-intro { padding: 18px; }
  .gm-rules { font-size: 18px; }
}
@media (max-height: 720px) {
  .gm-hub-hi { display: none; }
  .gm-hub { padding-bottom: 12px; }
  .gm-end-bot svg { width: 80px; height: 80px; }
  .gm-end-card { gap: 8px; padding: 16px 24px 20px; }
  .gm-stars { font-size: 42px; }
  .gm-intro { gap: 12px; padding-top: 18px; padding-bottom: 20px; }
  .gm-rules { font-size: 18px; gap: 6px; }
}
@media (max-height: 640px) {
  .gm-hub-grid { gap: 12px; }
  .gm-card { padding-bottom: 12px; }
  .gm-card-ic { width: 70px; height: 70px; font-size: 38px; margin-top: 12px; }
}

/* ---------- phones (both orientations): no text under 14px ---------- */
@media (max-width: 700px), (max-height: 500px) and (min-width: 560px) {
  .gm-lvl small, .gm-lvl-title small, .gm-chip small, .gm-end-stats small, .spd-key { font-size: 14px; }
}

/* ---------- phones (portrait): boards on top, controls below ---------- */
@media (max-width: 700px) {
  .gm-hub { gap: 12px; padding: 0 12px 24px; }
  .gm-hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gm-card { padding: 0 10px 14px; }
  .gm-card-ic { width: 70px; height: 70px; font-size: 38px; margin-top: 12px; }
  .gm-card-name { font-size: 20px; }
  .gm-card-stat { font-size: 14px; }
  .gm-card-stat > span { padding: 4px 10px; }
  .gm-main { padding: 0 12px 14px; }
  .gm-intro { gap: 12px; padding: 16px 16px 18px; }
  .gm-intro-ic { width: 52px; height: 52px; font-size: 30px; }
  .gm-intro-head h2 { font-size: 26px; }
  .gm-rules { font-size: 17px; }
  .gm-lvl small { font-size: 14px; }
  .gm-go { width: 100%; min-width: 0; }
  .gm-bar { gap: 8px; }
  .gm-chip { padding: 6px 12px 6px 8px; font-size: 18px; }
  /* memory: the board turned upright (fewer, bigger cards per row; arrow keys follow the layout) */
  .mem-board { --gap: 10px; grid-template-columns: repeat(var(--rows), var(--cw));
    --cw: min(120px, calc((100vw - 36px) / var(--rows) - var(--gap)), calc(((100vh - 190px) / var(--cols) - var(--gap)) / 1.12)); }
  /* sudoku: the grid, then the counters and a flat number pad */
  .sdk-wrap { flex-direction: column; justify-content: flex-start; gap: 14px; }
  .sdk-grid { --cell: min(calc((100vw - 44px) / var(--n) - 3px), 64px); }
  .sdk-n4 { --cell: min(calc((100vw - 56px) / 4 - 4px), 96px); }
  .sdk-n6 { --cell: min(calc((100vw - 52px) / 6 - 4px), 72px); }
  .sdk-side { width: 100%; max-width: 460px; gap: 12px; }
  .sdk-bar { justify-content: center; }
  .sdk-pad { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .sdk-pad6 { grid-template-columns: repeat(6, 1fr); }
  .sdk-pad4 { grid-template-columns: repeat(4, 1fr); }
  .sdk-key, .sdk-pad4 .sdk-key { height: 56px; font-size: 28px; }
  .sdk-key svg { width: 40px; height: 40px; }
  /* make 10: the sum on top, the tiles below */
  .m10-wrap { flex-direction: column; justify-content: flex-start; gap: 14px; }
  .m10-side { width: 100%; max-width: 460px; gap: 10px; padding: 14px 16px; }
  .m10-sum { font-size: 38px; }
  .m10-btns { flex-direction: row; }
  .m10-btns .btn { flex: 1; }
  .m10-msg { min-height: 0; }
  .m10-msg:empty { display: none; }
  .m10-board { --t: min(100px, calc((100vw - 28px) / var(--cols) - 12px)); gap: 12px; }
  /* quick maths */
  .spd-wrap { gap: 12px; }
  .spd-top { gap: 10px; }
  .spd-timer { flex-basis: 100%; }
  .spd-card { min-height: 150px; }
  .spd-text { font-size: 48px; }
  .spd-text.long { font-size: 38px; }
  .spd-count { font-size: min(48px, 11vw); }
  .spd-opts { gap: 10px; }
  .spd-o4 { grid-template-columns: repeat(2, 1fr); }
  .spd-opt { height: 84px; font-size: 36px; }
  .spd-float { top: 16px; right: 20px; }
  /* result overlay */
  .gm-end { padding: 12px; }
  .gm-end-card { gap: 8px; padding: 18px 16px 20px; }
  .gm-end-card h2 { font-size: 28px; }
  .gm-end-stats > div { flex-basis: 90px; }
  .gm-end-btns .btn.big { flex: 1 1 auto; padding: 12px 18px; font-size: 18px; }
}

/* ---------- phones (landscape): boards beside their controls, sized to the short screen ---------- */
@media (max-height: 500px) and (min-width: 560px) {
  .gm-hub { padding: 0 14px 16px; }
  .gm-hub-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .gm-card-desc { min-height: 0; }
  .gm-main { padding: 0 14px 10px; }
  .gm-intro { gap: 10px; padding: 14px 20px 16px; }
  .gm-intro-head h2 { font-size: 26px; }
  .gm-rules { gap: 4px; font-size: 16px; }
  .gm-lvl { min-height: 48px; }
  .gm-lvl small { font-size: 14px; }
  .gm-chip { padding: 5px 12px 5px 8px; font-size: 18px; }
  /* memory: the counters beside the board */
  .mem-wrap { flex-direction: row; justify-content: center; align-items: center; gap: 18px; }
  .mem-wrap > .gm-bar { flex-direction: column; align-items: stretch; }
  .mem-board { --gap: 8px; margin: 0;
    --cw: min(150px, calc((100vw - 260px) / var(--cols) - var(--gap)), calc(((100vh - 80px) / var(--rows) - var(--gap)) / 1.12)); }
  /* sudoku */
  .sdk-wrap { gap: 18px; }
  .sdk-grid { --cell: min(calc((100vh - 84px) / var(--n) - 3px), calc((100vw - 330px) / var(--n) - 3px), 60px); }
  .sdk-n4 { --cell: min(calc((100vh - 96px) / 4 - 4px), 90px); }
  .sdk-n6 { --cell: min(calc((100vh - 84px) / 6 - 2px), 64px); }
  .sdk-side { width: 270px; gap: 10px; }
  .sdk-bar { flex-wrap: nowrap; justify-content: flex-start; gap: 6px; }
  .sdk-bar .gm-chip small { display: none; }
  .sdk-pad { gap: 8px; }
  .sdk-key { height: 50px; font-size: 26px; }
  .sdk-pad4 .sdk-key { height: 64px; font-size: 32px; }
  .sdk-key svg { width: 40px; height: 40px; }
  .sdk-act { min-height: 44px; padding: 8px; font-size: 16px; }
  /* tower of Hanoi */
  .hn-wrap { gap: 6px; }
  .hn-board { --h: calc(100vh - 150px); }
  .hn-msg { min-height: 0; }
  /* quick maths */
  .spd-wrap { gap: 10px; }
  .spd-card { min-height: 100px; padding: 10px; }
  .spd-text { font-size: 46px; }
  .spd-text.long { font-size: 38px; }
  .spd-count { font-size: 48px; }
  .spd-opts { gap: 10px; }
  .spd-opt { height: 70px; font-size: 32px; }
  /* make 10 */
  .m10-wrap { gap: 16px; }
  .m10-side { width: 290px; gap: 8px; padding: 12px 14px; }
  .m10-sum { font-size: 32px; }
  .m10-btns { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .m10-btns .btn { flex: 1 1 auto; padding: 10px 8px; font-size: 16px; }
  .m10-msg { min-height: 0; }
  .m10-msg:empty { display: none; }
  .m10-board { --t: min(96px, calc((100vh - 84px) / var(--rows) - 12px), calc((100vw - 340px) / var(--cols) - 12px)); gap: 12px; }
  /* result overlay */
  .gm-end-bot { display: none; }
  .gm-end-card { gap: 6px; padding: 14px 20px 16px; }
  .gm-end-card h2 { font-size: 26px; }
  .gm-stars { font-size: 36px; }
  .gm-end-stats b { font-size: 22px; }
  .gm-end-btns .btn.big { padding: 10px 18px; font-size: 17px; }
}

/* ---------- number crossword ---------- */
.crs-wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; gap: 32px; }
.crs-grid {
  --c: min(96px, calc((100vh - 150px) / var(--n) - 8px), calc((100vw - 400px) / var(--n) - 8px));
  display: grid; grid-template-columns: repeat(var(--n), var(--c)); gap: 8px; flex: none;
}
.crs-cell {
  width: var(--c); height: var(--c); padding: 0; border-radius: 18px; display: grid; place-items: center;
  font-size: calc(var(--c) * .44); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.crs-cell.long { font-size: calc(var(--c) * .34); }
.crs-sign { color: var(--ink2); font-size: calc(var(--c) * .5); transition: color .3s; }
.crs-sign.done, .crs-grid.solved .crs-sign { color: var(--green-d); }
.crs-num { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--line), inset 0 0 0 2px var(--line); }
.crs-blank { background: #FFFBEA; color: var(--blue-d); box-shadow: 0 5px 0 #F3DB8A, inset 0 0 0 3px #F3DB8A; outline: none; }
.crs-blank.empty { color: #E3C66E; }
.crs-blank.sel { background: #FFE58A; box-shadow: 0 5px 0 #E0B000, inset 0 0 0 4px #F0B400; }
.crs-blank.sel.empty { color: #B98F00; }
.crs-blank.ok, .crs-blank.hint, .crs-grid.solved .crs-num { background: #E3FBF3; color: var(--green-d); box-shadow: 0 5px 0 var(--green-d), inset 0 0 0 3px var(--green); }
.crs-blank.bad { background: #FFE3E3; color: #E03131; box-shadow: 0 5px 0 #E8A0A0, inset 0 0 0 4px var(--red); }
.crs-blank:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
.crs-cell.glow { animation: crsGlow .9s ease; }
.crs-shake { animation: crsShake .4s; }
@keyframes crsGlow { 40% { transform: scale(1.08); background: #BFF3DE; } }
@keyframes crsShake { 25%, 75% { transform: translateX(-5px); } 50% { transform: translateX(5px); } }
.crs-side { width: 290px; flex: none; display: flex; flex-direction: column; gap: 16px; }
.crs-bar { justify-content: flex-start; }
.crs-hint { min-height: 48px; padding: 12px 8px; font-size: 18px; }
.crs-pad .keypad-wrap { align-items: stretch; }
.crs-pad .keypad { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1000px) {
  .crs-wrap { gap: 20px; }
  .crs-side { width: 250px; }
  .crs-grid { --c: min(96px, calc((100vh - 150px) / var(--n) - 8px), calc((100vw - 340px) / var(--n) - 8px)); }
}
/* phones: the grid, then a flat keypad (7 keys a row in portrait, 4 in landscape) */
@media (max-width: 700px) {
  .crs-wrap { flex-direction: column; justify-content: flex-start; gap: 14px; }
  .crs-grid { --c: min(80px, calc((100vw - 24px) / var(--n) - 6px)); gap: 6px; }
  .crs-cell { border-radius: 14px; }
  .crs-side { width: 100%; max-width: 460px; gap: 10px; }
  .crs-bar { justify-content: center; }
  .crs-pad { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
  .crs-pad .key { min-width: 0; height: 52px; font-size: 26px; }
  .crs-pad .key-ok { grid-row: auto; grid-column: span 3; min-height: 52px; padding: 8px 6px; font-size: 18px; }
}
@media (max-width: 700px), (max-height: 500px) and (min-width: 560px) {
  .crs-pad .keypad-wrap, .crs-pad .keypad { display: contents; }
  .crs-pad .keypad > span { display: none; }
}
@media (max-height: 500px) and (min-width: 560px) {
  .crs-wrap { flex-direction: row; justify-content: center; gap: 18px; }
  .crs-grid { --c: min(80px, calc((100vh - 84px) / var(--n) - 5px)); gap: 5px; }
  .crs-cell { border-radius: 12px; }
  .crs-side { width: 300px; gap: 8px; }
  .crs-bar { flex-wrap: nowrap; justify-content: flex-start; gap: 6px; }
  .crs-bar .gm-chip small { display: none; }
  .crs-pad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .crs-pad .key { min-width: 0; height: 44px; font-size: 24px; }
  .crs-pad .key-ok { grid-column: auto; min-height: 44px; padding: 6px; font-size: 16px; }
  .crs-hint { min-height: 44px; padding: 8px; font-size: 16px; }
}
