/* Layout: TikTok-profile style. Black page, big white crest, name, follow icons,
   then a big "What do you need?" menu of tiles visible on the first screen.
   Each tile jumps to its section below. Single black-and-white look by design. */
:root{
  --bg:#000;
  --panel:#111;
  --panel-2:#1c1c1c;
  --line:#2c2c2c;
  --text:#fff;
  --dim:#a3a3a3;
  --font:'Archivo', 'Helvetica Neue', Arial, sans-serif;
  color-scheme:dark;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth; background:var(--bg); scroll-padding-top:70px}
@media (prefers-reduced-motion: reduce){ html{scroll-behavior:auto} }
body{margin:0; background:var(--bg); color:var(--text); font-family:var(--font); font-size:17px; line-height:1.6}
a{color:var(--text)}
img{max-width:100%; display:block}
h1,h2,h3{margin:0; line-height:1.15; text-wrap:balance}
h2{font-size:clamp(26px, 6vw, 36px); font-weight:900; letter-spacing:-.01em}
h3{font-size:20px; font-weight:800}
p{margin:0}
svg{width:24px; height:24px}
:focus-visible{outline:2px solid #fff; outline-offset:3px}
.wrap{max-width:880px; margin:0 auto; padding-inline:16px}

/* top bar */
.top{position:sticky; top:0; z-index:10; background:rgba(0,0,0,.92); backdrop-filter:blur(8px); border-bottom:1px solid var(--line); padding-top:env(safe-area-inset-top,0px)}
.top .wrap{display:flex; align-items:center; gap:12px; min-height:56px}
.brand{display:flex; align-items:center; gap:9px; text-decoration:none; font-weight:800; font-size:17px; white-space:nowrap}
.brand img{width:34px; height:34px}
.nav{display:flex; gap:2px; margin-left:auto; overflow-x:auto; scrollbar-width:none}
.nav::-webkit-scrollbar{display:none}
.nav a{text-decoration:none; color:var(--dim); font-weight:600; font-size:15px; padding:6px 10px; border-radius:999px; white-space:nowrap}
.nav a:hover{color:var(--text); background:var(--panel-2)}
@media (max-width:640px){ .top .wrap{flex-wrap:wrap; gap:2px; padding-block:6px} .nav{margin-left:0; width:100%} .nav a{font-size:14px; padding:4px 9px} }

/* hero: profile */
.hero{padding-block:22px 12px; text-align:center}
.hero .wrap{display:flex; flex-direction:column; align-items:center; gap:8px}
.crest{width:min(44vw, 240px); height:auto}
.hero h1{font-size:clamp(30px, 8vw, 46px); font-weight:900; letter-spacing:-.015em}
.tag{color:var(--dim); font-size:15px; line-height:1.45}
.follow{display:flex; gap:12px; margin-top:4px}
.follow a{display:grid; place-items:center; width:42px; height:42px; border-radius:50%; border:1.5px solid var(--line); color:var(--text)}
.follow a:hover{background:var(--text); color:#000}
.follow a:hover svg use{color:#000}

/* menu */
.menu-sec{padding-block:6px 26px}
.menu-h{font-size:13px; font-weight:800; color:var(--dim); text-transform:uppercase; letter-spacing:.14em; text-align:center; margin-bottom:10px}
.menu{display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:10px}
.tile{display:flex; flex-direction:column; align-items:flex-start; gap:1px; padding:12px 14px; border-radius:16px; background:var(--panel); border:1.5px solid var(--line); text-decoration:none; transition:background .15s, border-color .15s, transform .1s}
.tile:hover{background:var(--panel-2); border-color:#fff}
.tile:active{transform:scale(.98)}
.tile svg{width:26px; height:26px; margin-bottom:4px}
.tile b{font-size:clamp(17px, 4.6vw, 21px); font-weight:800; line-height:1.2}
.tile span{color:var(--dim); font-size:13px; line-height:1.35}
.tile.wide{grid-column:1 / -1; flex-direction:row; align-items:center; gap:12px; padding-block:14px}
.tile.wide svg{margin:0}
.tile.wide span{margin-left:auto}
@media (min-width:760px){ .menu{grid-template-columns:repeat(4, minmax(0,1fr))} .tile b{font-size:17px} }
@media (max-width:759px){ .tile.car{grid-column:1 / -1; flex-direction:row; align-items:center; gap:12px; padding-block:14px} .tile.car svg{margin:0} .tile.car span{margin-left:auto} }
@media (max-width:520px){ .tile.car span{display:none} }
.tile.car b{white-space:nowrap}
@media (max-width:520px){ .tile.wide span{display:none} }
.tile.wide b{white-space:nowrap}

.news-line{display:flex; gap:12px; align-items:baseline; margin-top:14px; padding:10px 14px; border-radius:12px; border:1px solid var(--line); font-size:15px}
.news-line > b{font-size:12px; font-weight:800; letter-spacing:.12em; text-transform:uppercase; background:#fff; color:#000; padding:1px 7px; border-radius:4px; flex:none}
.news{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:3px; min-width:0}
.news time{color:var(--dim); margin-right:8px; font-variant-numeric:tabular-nums}
.news a{text-decoration:none}
.news a:hover{text-decoration:underline}

/* sections */
section[id]{padding-block:34px; border-top:1px solid var(--line)}
section#home{border-top:0}
.head{display:flex; flex-direction:column; gap:4px; margin-bottom:16px}
.head p{color:var(--dim); max-width:60ch}
.card{background:var(--panel); border:1.5px solid var(--line); border-radius:16px; padding:18px}

.btn{display:inline-flex; align-items:center; gap:7px; border:1.5px solid #fff; border-radius:999px; padding:8px 15px; text-decoration:none; font-weight:700; font-size:15px; color:#fff; background:transparent}
.btn:hover{background:var(--panel-2)}
.btn.solid{background:#fff; color:#000}
.btn.solid:hover{background:#ddd}
.btn svg{width:16px; height:16px}

.games{display:grid; grid-template-columns:repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap:12px}
.game{display:grid; grid-template-columns:88px 1fr; gap:16px; align-items:start}
.game img{width:88px; height:88px; border-radius:18px}
.game p{color:var(--dim); font-size:15px; margin-top:4px}
.game .row{display:flex; flex-wrap:wrap; gap:8px; margin-top:12px}
.soon{display:grid; place-items:center; color:var(--dim); border-style:dashed; min-height:120px; font-size:15px; text-align:center}

.video{aspect-ratio:16/9; width:100%; max-width:100%; border-radius:16px; overflow:hidden; background:var(--panel); border:1.5px solid var(--line)}
.video iframe{width:100%; height:100%; border:0; display:block}
.socials{display:grid; grid-template-columns:repeat(3, minmax(0,1fr)); gap:10px; margin-top:12px}
.social{display:flex; align-items:center; gap:10px; padding:12px; border-radius:14px; background:var(--panel); border:1.5px solid var(--line); text-decoration:none; min-width:0}
.social:hover{border-color:#fff}
.social svg{flex:none; width:26px; height:26px}
.social span{display:flex; flex-direction:column; color:var(--dim); font-size:13px; line-height:1.3; min-width:0}
.social b{color:var(--text); font-size:16px}
@media (max-width:480px){ .socials{grid-template-columns:1fr} }

.filters{display:flex; flex-wrap:wrap; gap:6px; margin-bottom:12px}
.filters button{font:inherit; font-size:14px; font-weight:600; color:var(--dim); background:transparent; border:1.5px solid var(--line); border-radius:999px; padding:5px 13px; cursor:pointer}
.filters button[aria-pressed="true"]{background:#fff; color:#000; border-color:#fff}
.search{width:100%; max-width:380px; font:inherit; font-size:15px; color:var(--text); background:var(--panel); border:1.5px solid var(--line); border-radius:999px; padding:9px 16px; margin-bottom:12px}
.search::placeholder{color:var(--dim)}
.list{display:grid; grid-template-columns:repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap:12px}
.res{display:flex; flex-direction:column; gap:6px; min-width:0}
.res h3{font-size:17px}
.res p{color:var(--dim); font-size:14px}
.res .row{display:flex; flex-wrap:wrap; gap:8px; margin-top:auto; padding-top:8px}
.chips{display:flex; flex-wrap:wrap; gap:6px}
.chip{font-size:12px; font-weight:700; letter-spacing:.05em; text-transform:uppercase; padding:2px 8px; border-radius:999px; border:1px solid var(--line); color:var(--dim)}
.empty{text-align:center; color:var(--dim); font-size:15px; padding:22px}
.empty b{color:var(--text)}

.about p+p{margin-top:10px}
.info{display:grid; grid-template-columns:repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap:12px; margin-top:12px}
.info h3{margin-bottom:6px}
.info p{color:var(--dim); font-size:15px}
.mail{color:var(--text)!important; font-weight:700; user-select:all; word-break:break-all; margin-top:6px}

.totop{opacity:0; pointer-events:none; transition:opacity .2s; position:fixed; right:16px; bottom:calc(16px + env(safe-area-inset-bottom,0px)); z-index:9; width:48px; height:48px; border-radius:50%; background:#fff; color:#000; display:grid; place-items:center; box-shadow:0 4px 16px rgba(0,0,0,.5)}
.totop svg{width:22px; height:22px}

footer{border-top:1px solid var(--line); padding-block:28px calc(80px + env(safe-area-inset-bottom,0px)); text-align:center; color:var(--dim); font-size:14px}
footer .wrap{display:flex; flex-direction:column; align-items:center; gap:10px}

.totop.show{opacity:1; pointer-events:auto}
@media (min-height:760px){ .crest{width:min(52vw, 260px)} }

/* Bibi, the mascot, standing beside the crest (never covering it) */
.crest-wrap{position:relative; display:inline-block}
.pip{position:absolute; left:86%; bottom:-2%; width:34%}
.pip img{width:100%; height:auto}
.bubble{position:absolute; bottom:104%; left:38%; background:#3fc4b1; color:#000; font-weight:800; font-size:13px; padding:3px 9px; border-radius:12px; white-space:nowrap}
.bubble::after{content:""; position:absolute; bottom:-6px; left:12px; border:6px solid transparent; border-bottom:0; border-top-color:#3fc4b1}
.tile:first-child{border-color:#3fc4b1}
.tile:first-child svg{color:#3fc4b1}

/* Buy me a coffee */
.support{display:grid; grid-template-columns:34px 1fr; gap:14px; margin-top:12px; border-color:#ffdd00}
.support > svg{width:34px; height:34px; color:#ffdd00}
.support h3{margin-bottom:6px}
.support p{color:var(--dim); font-size:15px}
.support p.small{font-size:13px; margin-top:6px}
.btn.coffee{margin-top:12px; background:#ffdd00; border-color:#ffdd00; color:#000}
.btn.coffee:hover{background:#ffe94d}
.foot-coffee{display:inline-flex; align-items:center; gap:6px; color:var(--text); font-weight:700; text-decoration:none; font-size:14px}
.foot-coffee svg{width:18px; height:18px; color:#ffdd00}
.foot-coffee:hover{text-decoration:underline}

.lead{font-size:clamp(18px,4.8vw,22px); font-weight:800; line-height:1.3; margin-top:2px}

.game.wide{grid-column:1 / -1}
.game .row + .row{margin-top:8px}
.soon{min-height:0; padding:14px}
@media (max-width:560px){
  .game{display:block}
  .game img{float:left; width:56px; height:56px; border-radius:12px; margin-right:12px}
  .game h3{line-height:56px}
  .game p{clear:both; margin-top:8px}
  .game .row{gap:6px}
  .game .row .btn{flex:1 1 auto; justify-content:center; padding:8px 8px; font-size:14px; gap:4px; white-space:nowrap}
  .game .row .btn svg{width:12px; height:12px}
}

/* Games: primary / high school split */
.sub{display:flex; align-items:baseline; gap:10px; font-size:19px; margin:22px 0 10px}
.sub:first-of-type{margin-top:4px}
.sub span{font-size:13px; font-weight:700; color:var(--dim); letter-spacing:.06em; text-transform:uppercase}
.games.hs{grid-template-columns:repeat(auto-fit, minmax(min(100%, 320px), 1fr))}
.game .chips{margin-top:6px}
.glyph{width:88px; height:88px; border-radius:18px; display:grid; place-items:center; background:#1b1a3a; border:1.5px solid #3b3a7a}
.glyph i{font-style:italic; font-family:Georgia, 'Times New Roman', serif; font-size:52px; color:#c6ff4a; line-height:1}
.glyph.pi{background:#0d1a33; border-color:#2b4c8f}
.glyph.pi i{color:#5ce1a0}
.games + .soon, .soon{margin-top:12px; min-height:0; padding:14px}
@media (max-width:560px){
  .glyph{float:left; width:56px; height:56px; border-radius:12px; margin-right:12px}
  .glyph i{font-size:34px}
  .game .chips{clear:none}
}

.glyph.quest{background:#2a1a08; border-color:#8a5a1a}
.glyph.quest i{font-style:normal; font-family:inherit; color:#ffc24d; font-size:46px}
.game.quest{border-color:#8a5a1a}
@media (max-width:560px){ .glyph.quest i{font-size:30px} }

@media (max-width:560px){ .game h3{line-height:1.2; min-height:56px; display:flex; align-items:center} }

/* worksheet opened from a game link (#the-tunnel-of-integers etc.) */
.res{scroll-margin-top:90px}
.res.hit{animation:hit 2.4s ease-out}
@keyframes hit{0%,35%{border-color:#fff; box-shadow:0 0 0 3px rgba(255,255,255,.35)}100%{box-shadow:0 0 0 0 rgba(255,255,255,0)}}
@media (prefers-reduced-motion:reduce){.res.hit{animation:none; border-color:#fff}}
/* Road Code Coach glyph */
.glyph.road{background:#2a2410; border-color:#8a6d12}
.glyph.road i{font-style:normal; font-family:Arial, sans-serif; font-weight:900; color:#1d2430; background:#ffd200; border:3px solid #1d2430; border-radius:8px; width:52px; height:52px; display:grid; place-items:center; font-size:38px}
@media (max-width:560px){.glyph.road i{width:38px; height:38px; font-size:26px; border-width:2px; border-radius:6px}}
.glyph.mystery{background:#2e1c0e;border-color:#d8a948}
.glyph.mystery i{color:#f6d886}
/* Turbo Racer glyph: a racing car */
.glyph.racer{background:#1b1030;border-color:#ff3d8b}
.glyph.racer svg{width:80px; height:auto}
@media (max-width:560px){ .glyph.racer svg{width:52px; height:auto} }

/* Hub pages (Primary, High school, Maths Tour) */
.hub-intro{padding-block:26px 6px}
.hub-intro h1{font-size:clamp(30px, 8vw, 44px); font-weight:900; letter-spacing:-.015em}
.hub-intro p{color:var(--dim); margin-top:6px; max-width:60ch}
.game{scroll-margin-top:90px}
.game:target{animation:hit 2.4s ease-out}
@media (prefers-reduced-motion:reduce){.game:target{animation:none; border-color:#fff}}
.game.solo{grid-template-columns:1fr}
.chip.rec{color:#fff; border-color:#fff}
.ws-year{margin-bottom:10px}

/* Mystery series: the flagship page */
.mystery-hero{padding-block:30px 8px; text-align:center}
.mystery-hero .wrap{display:flex; flex-direction:column; align-items:center; gap:6px}
.mystery-hero img{width:96px; height:96px; border-radius:24px; border:2px solid #d8a948}
.mystery-hero .kicker{font-size:12px; font-weight:800; letter-spacing:.14em; text-transform:uppercase; color:#f6d886}
.mystery-hero h1{font-size:clamp(34px, 9vw, 52px); font-weight:900; letter-spacing:-.015em}
.mystery-hero .lead2{color:var(--dim); max-width:52ch}
.game.feature{border-color:#d8a948}
#exams .more{margin-top:14px; font-size:15px}
#exams .more a{color:var(--dim)}

/* Primary tile on the home page: comic style, faint island behind the text (only this tile) */
.tile.isle{position:relative; overflow:hidden; isolation:isolate; background:linear-gradient(135deg,#1b5f58,#25806f); border:3px solid #fff; box-shadow:4px 4px 0 #3fc4b1; transform:rotate(-1deg); transition:transform .12s, box-shadow .12s}
.tile.isle::before{content:""; position:absolute; inset:0; z-index:-1; background:radial-gradient(rgba(0,0,0,.28) 1.3px, transparent 1.7px) 0 0/7px 7px}
.tile.isle:hover{background:linear-gradient(135deg,#1f6e66,#2b917f); border-color:#fff; transform:rotate(-1deg) translate(-1px,-1px); box-shadow:6px 6px 0 #3fc4b1}
.tile.isle:active{transform:rotate(-1deg) translate(2px,2px); box-shadow:2px 2px 0 #3fc4b1}
.tile.isle .isle-bg{position:absolute; right:-8px; bottom:-6px; width:82%; height:auto; opacity:.42; z-index:-1}
.tile.isle b{text-shadow:2px 2px 0 #0b2a26; font-weight:900}
.tile.isle span{color:#e4fbf6}
.tile.isle > svg:not(.isle-bg){color:#ffd54a}
.isle-pow{position:absolute; top:7px; right:8px; font-style:normal; font-weight:900; font-size:12px; letter-spacing:.02em; color:#0b2a26; background:#ffd54a; padding:3px 9px 3px 8px; border:2px solid #0b2a26; border-radius:4px 14px 4px 14px; transform:rotate(6deg); box-shadow:2px 2px 0 #0b2a26}
@media (prefers-reduced-motion: reduce){ .tile.isle, .tile.isle:hover, .tile.isle:active{transition:none} }

/* footer: Buy me a coffee + Teachers side by side */
.foot-row{display:flex; flex-wrap:wrap; justify-content:center; align-items:center; gap:6px 22px}
.foot-link{color:var(--text); font-weight:700; text-decoration:none; font-size:14px}
.foot-link:hover{text-decoration:underline}

/* Maths Tour: games for everyone (black and white; the Mystery cards keep their gold border) */
.tour-hero .kicker{color:#fff}
.tour-banner{position:relative; width:min(100%, 400px); margin:0 auto 14px}
.tour-map{display:block; width:100%; height:auto; transform:rotate(-1.5deg)}
.mystery-hero .tour-bibi img{width:100%; height:auto; border:0; border-radius:0}
.tour-bibi{position:absolute; right:-2%; bottom:-14%; width:27%}
.tour-bibi .bubble{bottom:100%; left:auto; right:8%; font-size:12.5px}
.tour-bibi .bubble::after{left:auto; right:22px}
.tour-home{margin-top:10px}
.tour-group{margin-top:30px}
.tour-back{margin-top:22px; text-align:center}
.glyph.puzzle{background:#fff; border-color:#fff}
.glyph.puzzle svg{width:66px; height:66px}
@media (max-width:560px){ #puzzles{grid-template-columns:64px 1fr; gap:12px} #puzzles .glyph{width:64px; height:64px; border-radius:14px} #puzzles .glyph svg{width:50px; height:50px} }

/* Home page: the Maths Tour tile looks like an old map (no character on the home page) */
.tile.tour{position:relative; overflow:hidden; isolation:isolate; background:linear-gradient(135deg,#f0dfb2,#dcbd7e); border:3px solid #4a3216; box-shadow:4px 4px 0 #b98a3c; transform:rotate(1deg); transition:transform .12s, box-shadow .12s}
.tile.tour:hover{background:linear-gradient(135deg,#f6e8c2,#e4c88c); border-color:#4a3216; transform:rotate(1deg) translate(-1px,-1px); box-shadow:6px 6px 0 #b98a3c}
.tile.tour:active{transform:rotate(1deg) translate(2px,2px); box-shadow:2px 2px 0 #b98a3c}
.tile.tour .tour-bg{position:absolute; inset:auto -6px -4px auto; width:88%; height:auto; opacity:.4; z-index:-1; margin:0}
.tile.tour b{color:#2e1c0e; font-weight:900}
.tile.tour span{color:#4a3216; font-weight:600}
.tile.tour > svg:not(.tour-bg){color:#2e1c0e}
.tour-pow{position:absolute; top:7px; right:8px; font-style:normal; font-weight:900; font-size:12px; letter-spacing:.02em; color:#fff; background:#2e1c0e; padding:3px 9px 3px 8px; border:2px solid #2e1c0e; border-radius:14px 4px 14px 4px; transform:rotate(-5deg); box-shadow:2px 2px 0 #b98a3c}
@media (prefers-reduced-motion: reduce){ .tile.tour, .tile.tour:hover, .tile.tour:active{transition:none} }

/* Home page: Road Code tile shows a yellow L plate (black L on yellow) */
.tile .lplate{display:grid; place-items:center; width:26px; height:26px; margin-bottom:4px; background:#ffd200; color:#000; border:2px solid #000; border-radius:4px; font-style:normal; font-weight:900; font-size:19px; line-height:1; box-shadow:0 0 0 1.5px #fff}
.tile.road{position:relative}
.tile.road .road-car{position:absolute; top:12px; right:12px; width:40px; height:40px; margin:0; color:#fff}

/* Home page: High school and Road Code tiles get a white border and a shadow, like the other two */
.menu .tile:not(.isle):not(.tour){border:3px solid #fff; box-shadow:4px 4px 0 #6b6b6b}
.menu .tile:not(.isle):not(.tour):hover{transform:translate(-1px,-1px); box-shadow:6px 6px 0 #6b6b6b}
.menu .tile:not(.isle):not(.tour):active{transform:translate(2px,2px); box-shadow:2px 2px 0 #6b6b6b}
