*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;font-family:Arial,sans-serif}body{background:#c3e8f8;display:flex;flex-direction:column;overflow:hidden;--orange:#ff690b}button,summary,select,a{cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent}button,select,summary{border:0;outline:0;box-shadow:none;font:inherit}button:focus-visible,select:focus-visible,summary:focus-visible,a:focus-visible{outline:2px solid #245ba5;outline-offset:3px}button:hover{transform:none}header{height:112px;flex-shrink:0;display:flex;align-items:flex-start;padding:20px 75px 10px 125px;gap:14px;position:relative;z-index:30}.logo{position:absolute;left:10px;top:8px;width:100px;height:96px;object-fit:contain}#top-controls{display:flex;justify-content:center;align-items:center;flex-wrap:wrap;gap:14px;margin:0 auto}#top-controls>button,#top-controls>select,#top-controls summary{height:42px;min-width:42px;background:var(--orange);color:white;border-radius:6px;padding:6px}#top-controls>button svg{width:30px;height:30px;fill:none;stroke:currentColor;stroke-width:2}#top-controls #reset{margin-right:16px;background:transparent;color:var(--orange)}#whiteboard-toggle img{width:30px;height:30px;display:block}#sound[aria-pressed=false]{opacity:.5}#colors{position:relative}#colors summary{list-style:none;display:flex;align-items:center;gap:4px}summary::-webkit-details-marker{display:none}#current-color{display:block;width:28px;height:28px;border-radius:50%;background:#1685dc}#swatches{position:absolute;top:50px;left:0;display:grid;grid-template-columns:repeat(3,32px);gap:6px;padding:8px;background:white;border-radius:8px;z-index:2}details:not([open])>div{display:none!important}#swatches button{width:30px;height:30px;border-radius:50%;border:2px solid transparent}#swatches button[aria-pressed=true]{border-color:#333}.exit{position:absolute;right:18px;top:15px;font-size:43px;line-height:1;text-decoration:none;color:var(--orange)}main{flex:1;min-height:0;padding:10px 5vw 26px}.workspace{height:100%;width:100%;display:grid;grid-template-columns:minmax(0,1fr) 130px;gap:25px;align-items:center;max-width:1400px;margin:auto}#figure-area{position:relative;height:100%;min-height:0;min-width:0;display:grid;place-items:center}#figure{height:100%;width:100%;overflow:visible}#figure [data-cell]{cursor:pointer;stroke:#333;stroke-width:1;vector-effect:non-scaling-stroke;touch-action:manipulation}aside{align-self:start;margin-top:20px}.fraction{background:white;border:2px solid #ff7624;border-radius:15px;padding:8px 14px;width:124px;text-align:center;font-size:54px;color:#5e5b5b}.fraction output{display:block;border-bottom:4px solid #5e5b5b;padding-bottom:6px}.fraction input{font:inherit;color:inherit;text-align:center;border:0;width:100%;background:transparent;outline:0;padding-top:6px;appearance:textfield}.fraction input::-webkit-inner-spin-button{appearance:none}.steps{display:flex;justify-content:space-between;margin-top:14px}.steps button{color:#ff7624;background:white;border-radius:8px;font-size:38px;width:52px;height:52px;line-height:1}.steps button:disabled{opacity:.35}footer{position:absolute;bottom:4px;left:12px;font-size:11px;color:#555}#rect-resize{position:absolute;pointer-events:none}#rect-resize[hidden]{display:none}#rect-resize i{position:absolute;pointer-events:auto;touch-action:none}#rect-resize [data-edge=n],#rect-resize [data-edge=s]{height:20px;left:0;right:0;cursor:ns-resize}#rect-resize [data-edge=n]{top:-27px}#rect-resize [data-edge=s]{bottom:-27px}#rect-resize [data-edge=e],#rect-resize [data-edge=w]{width:20px;top:0;bottom:0;cursor:ew-resize}#rect-resize [data-edge=e]{right:-27px}#rect-resize [data-edge=w]{left:-27px}
#whiteboard-panel{position:fixed;inset:0;z-index:20;display:flex;flex-direction:column;background:#ffffff10}#whiteboard-panel[hidden]{display:none}#whiteboard-surface{flex:1;min-height:0}.whiteboard-tools{display:flex;gap:7px;align-self:center;align-items:center;padding:5px;margin:0 5px calc(6px + env(safe-area-inset-bottom));border:1px solid #aaa;border-radius:10px;background:white}.whiteboard-tools button,#whiteboard-color summary{width:38px;height:38px;padding:0;background:#00bcd4;border-radius:50%;color:white;font-size:23px;display:grid;place-items:center}.whiteboard-tools button svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2}.whiteboard-tools [data-tool=delete]{background:red}.whiteboard-tools button[aria-pressed=true]{background:#ff731b}.color-menu{position:relative}.color-menu summary{list-style:none}.color-dot{width:17px;height:17px;border-radius:50%;background:var(--active-color)}.color-swatches{position:absolute;bottom:calc(100% + 8px);left:50%;transform:translateX(-50%);display:flex;gap:5px;padding:7px;background:white;border:1px solid #ff731b;border-radius:30px}.whiteboard-tools .color-swatches button{width:22px;height:22px;background:var(--swatch)}
@media(max-width:850px){header{height:100px;padding-left:110px;gap:8px}#top-controls{gap:9px}.workspace{grid-template-columns:minmax(0,1fr) 112px;gap:12px}.fraction{font-size:44px;width:108px}.steps button{width:46px;height:46px}}@media(max-width:600px),(max-width:950px) and (max-height:500px){header{height:76px;padding:14px 60px 4px 86px}.logo{width:70px;height:65px}.exit{font-size:36px;top:16px}main{padding:0 15px 12px}.workspace{grid-template-columns:minmax(0,1fr) 85px;gap:10px}.fraction{width:82px;font-size:34px;padding:5px 8px;border-radius:10px}aside{margin-top:12px}.steps{gap:5px}.steps button{width:38px;height:38px;font-size:29px}#top-controls #reset{margin-right:12px}.whiteboard-tools{gap:4px;padding:4px;max-width:calc(100vw - 10px);flex-wrap:wrap;justify-content:center}.whiteboard-tools button,#whiteboard-color summary{width:30px;height:30px;font-size:20px}.whiteboard-tools button svg{width:19px;height:19px}footer{display:none}}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}}

/* Optional numeric views reserve the existing side column. */
[hidden]{display:none!important}#top-controls>button[aria-pressed=true]:not(#sound){box-shadow:inset 0 -3px white}#top-controls #language img{width:30px;height:22px;display:block}#top-controls #show-decimal{font-weight:bold;min-width:48px}#percent-mode{font-size:27px!important;font-weight:bold}.fraction-symbol{font-size:32px;line-height:1}.value-box{display:block;border:2px solid #ff7624;border-radius:12px;background:white;color:#5e5b5b;text-align:center;width:124px;padding:10px 4px;font-size:28px;margin-top:12px;font-variant-numeric:tabular-nums}#figure{touch-action:none}#top-controls{row-gap:8px}header{height:122px}@media(max-width:850px){header{height:132px}.value-box{width:108px;font-size:25px}}@media(max-width:600px),(max-width:950px) and (max-height:500px){header{height:76px}.value-box{width:82px;font-size:20px;padding:8px 2px}.fraction-symbol{font-size:28px}#top-controls #show-decimal{min-width:40px}}

/* Constrain the SVG viewport independently of its intrinsic 600px size. */
html,body{height:100%;height:100dvh;min-height:0}
header{height:auto;min-height:112px;padding-bottom:14px;flex:0 0 auto}
main{flex:1 1 0;min-height:0;overflow:hidden}
.workspace{min-height:0;grid-template-rows:minmax(0,1fr)}
#figure-area{width:100%;height:100%;overflow:hidden;min-height:0}
#figure{display:block;position:absolute;inset:0;width:100%;height:100%;max-width:100%;max-height:100%;overflow:hidden}
aside{align-self:center;max-height:100%;margin-top:0;display:flex;flex-direction:column;align-items:center;gap:10px}
.value-box{margin-top:0;flex-shrink:0}.steps{margin-top:0}
#top-controls #reset img{display:block;width:36px;height:36px;object-fit:contain}
#top-controls #reset{padding:3px;background:transparent}
#shape{font-size:31px!important;line-height:1;padding:0 4px!important;width:66px;min-width:66px}
@media(max-width:850px){header{height:auto;min-height:106px}}
@media(max-width:600px),(max-width:950px) and (max-height:500px){header{height:76px;min-height:76px}#top-controls #reset img{width:30px;height:30px}#shape{font-size:27px!important;width:52px;min-width:52px}aside{gap:7px}}
@media(max-height:500px){main{padding-bottom:12px}.fraction{font-size:27px;padding:4px 8px}.fraction output{padding-bottom:3px;border-bottom-width:2px}.fraction input{padding-top:3px}.value-box{font-size:21px;padding:5px 2px}.steps button{height:34px;width:36px;font-size:28px}aside{gap:6px}}

/* Figure and colour use stable, explicit disclosure buttons. */
#shape-menu{position:relative}#shape-menu summary,#colors summary{display:flex!important;align-items:center;justify-content:center;gap:7px;width:64px;min-width:64px;padding:6px!important;list-style:none;user-select:none;caret-color:transparent}
#shape-menu summary svg{width:29px;height:29px;fill:white;flex-shrink:0}.menu-chevron{display:block;width:8px;height:8px;border-right:2px solid white;border-bottom:2px solid white;transform:rotate(45deg);margin-top:-4px;flex-shrink:0}
#shape-options{position:absolute;top:50px;left:0;display:flex;gap:7px;padding:8px;border-radius:8px;background:white;box-shadow:0 2px 10px #0002;z-index:5}#shape-options button{display:grid;place-items:center;width:42px;height:42px;background:var(--orange);color:white;border-radius:6px;padding:5px}#shape-options button svg{width:30px;height:30px;fill:currentColor}#shape-options button[aria-pressed=true]{box-shadow:inset 0 -3px white}
.value-box{font-size:39px;padding:9px 3px;line-height:1.15}.value-box.long-value{font-size:31px}
@media(max-width:850px){.value-box{font-size:34px}.value-box.long-value{font-size:27px}}
@media(max-width:600px),(max-width:950px) and (max-height:500px){#shape-menu summary,#colors summary{width:54px!important;min-width:54px;gap:5px}#shape-menu summary svg{width:26px;height:26px}#top-controls #shape-menu{width:54px!important;flex-basis:54px!important}#top-controls #colors{width:54px!important;flex-basis:54px!important}.value-box{font-size:27px;padding:7px 2px}.value-box.long-value{font-size:21px}}
@media(max-height:500px){.value-box{font-size:26px;padding:4px 2px}.value-box.long-value{font-size:21px}}

#top-controls #shape-menu summary,#shape-options button{background:transparent!important;border:0!important;box-shadow:none!important}#shape-menu summary svg,#shape-options button svg{fill:#ff690b}#shape-menu .menu-chevron{border-color:#ff690b}
#top-controls button[aria-pressed],#top-controls summary,#shape-options button[aria-pressed]{box-shadow:none!important;border-bottom:0!important}#top-controls button:active{transform:none!important}#language{font-size:25px!important;font-weight:bold;min-width:58px!important;white-space:nowrap}#computer img{width:30px;height:30px;object-fit:contain}#game-level{font-size:17px!important;font-weight:bold;max-width:105px}
#figure [data-cell]{stroke-width:.6}#rect-resize i{z-index:3}#rect-resize [data-edge=n],#rect-resize [data-edge=s]{height:24px}#rect-resize [data-edge=e],#rect-resize [data-edge=w]{width:24px}
#game-controls{width:100%;text-align:center}#exercise{display:block;min-height:96px;font-size:29px;font-weight:bold;color:#555;overflow-wrap:anywhere;margin-bottom:32px}#score{display:block;width:124px;max-width:100%;margin:auto auto 22px;padding:6px;border:2px solid orange;border-radius:12px;background:white;font-size:28px;white-space:nowrap}#right-score{color:green}#wrong-score{color:red}.game-actions{display:flex;align-items:center;justify-content:center;gap:8px}.game-actions button{padding:0;background:transparent;border:0;position:relative}.game-actions img{display:block;object-fit:contain;width:65px;height:65px}#next img{width:85px}#check:disabled{opacity:.35}#guide-hand{position:absolute;top:-45px;left:28px;font-size:35px;animation:guide 1.4s ease-in-out infinite}#next.waiting img{animation:blink 1.7s ease-in-out infinite}#feedback{position:fixed;inset:0;z-index:15;display:grid;place-items:center;pointer-events:none}#feedback img{width:min(340px,60vw);max-height:55vh;object-fit:contain;opacity:0;transform:scale(.65);transition:opacity .4s,transform .4s}#feedback.appearing img{opacity:1;transform:scale(1)}@keyframes blink{50%{opacity:.35}}@keyframes guide{50%{transform:translateY(10px)}}
@media(max-width:600px),(max-width:950px) and (max-height:500px){#exercise{font-size:21px;min-height:65px;margin-bottom:25px}#score{font-size:22px;margin-bottom:20px;padding:5px 2px}.game-actions{gap:2px}.game-actions img{width:34px;height:45px}#next img{width:49px}#guide-hand{font-size:28px;left:12px;top:-35px}}
@media(prefers-reduced-motion:reduce){#guide-hand,#next.waiting img{animation:none}#feedback img{transition:none}}

@media(min-width:601px) and (min-height:501px){.game-actions img{width:50px;height:58px}#next img{width:70px}}

/* White shapes with a crisp dark outline, including the selected shape. */
#shape-menu summary svg,#shape-options button svg{fill:white!important;stroke:#222;stroke-width:1.4;overflow:visible}#shape-menu summary svg{width:34px;height:34px}#shape-menu summary{gap:6px}#shape-menu .menu-chevron{border-color:#222}#shape-options button{width:46px;height:46px;padding:4px}#shape-options button svg{width:35px;height:35px}
.exercise-prompt{position:relative;transform:translateY(-35px);margin-bottom:12px}#color-label{display:block;font-size:20px;font-weight:normal;color:#555;line-height:1.2;margin-bottom:14px}#exercise{min-height:62px;margin-bottom:0;font-size:36px;line-height:1.25;white-space:nowrap;overflow-wrap:normal}#guide-hand{font-size:43px;top:-51px;left:20px;pointer-events:none}
@media(max-width:600px),(max-width:950px) and (max-height:500px){#shape-menu summary svg{width:29px;height:29px}.exercise-prompt{transform:translateY(-24px);margin-bottom:8px}#color-label{font-size:17px;margin-bottom:10px}#exercise{font-size:26px;min-height:45px}#guide-hand{font-size:35px;top:-43px;left:8px}}

/* Large decimal separators within the existing fixed menu slot. */
#top-controls #language{font-size:34px!important;line-height:28px;font-weight:700;padding:0 3px;width:68px;min-width:68px!important;height:42px;white-space:nowrap;letter-spacing:-2px;overflow:hidden}
@media(max-width:600px),(max-width:950px) and (max-height:500px){#top-controls #language{font-size:28px!important;line-height:26px;width:58px;min-width:58px!important;height:36px;padding:0 2px;letter-spacing:-2px}}

/* Fixed origin for the fraction and its controls, optional values below. */
aside{align-self:stretch;justify-content:flex-start;padding-top:clamp(12px,6vh,55px)}
#game-controls{margin-top:50px}#fraction-box{flex-shrink:0}.steps{flex-shrink:0}
#top-controls #language svg{display:block;width:58px;height:34px;fill:white;stroke:white;stroke-linecap:round;stroke-linejoin:round}#top-controls #language .separator-comma{fill:none;stroke-width:7}#top-controls #language .separator-dot{stroke:none}#top-controls #language .separator-divider{fill:none;stroke-width:1.25}
@media(min-width:1100px){main{padding-left:1.5vw;padding-right:1.5vw}.workspace{max-width:none;gap:18px}}
@media(max-width:600px),(max-width:950px) and (max-height:500px){header>.mi-mobile-toggle{position:absolute;right:66px;top:18px;margin:0;width:34px;height:36px;padding:0;line-height:1;background:transparent}#top-controls #language svg{width:50px;height:30px}aside{padding-top:12px}#game-controls{margin-top:35px}}

/* Keep menu geometry unchanged while removing manual numeric-view controls. */
#top-controls>.game-reserved{visibility:hidden!important;pointer-events:none!important}

/* Named slots keep every numerical display in place when another is hidden. */
.workspace{grid-template-columns:minmax(0,1fr) clamp(150px,13vw,210px)}
aside{display:grid;grid-template-columns:124px;grid-template-rows:158px 52px 70px 70px;gap:12px;align-content:start;justify-content:center;align-items:start;justify-items:center;padding-top:clamp(45px,10vh,90px);padding-right:16px;max-height:100%}
#fraction-box{grid-area:1/1}.steps{grid-area:2/1;width:124px}#decimal-box{grid-area:3/1}#percent-box{grid-area:4/1}#game-controls{grid-area:1/1/5/2;margin-top:40px}
@media(max-width:850px){aside{grid-template-columns:108px;grid-template-rows:140px 46px 62px 62px;gap:9px;padding-right:10px;padding-top:45px}.steps{width:108px}}
@media(max-width:600px),(max-width:950px) and (max-height:500px){
 /* Hide before the shared script starts, preventing the initial palette flash. */
 #top-controls[data-mobile-menu]:not(.mi-menu-open){display:none!important}
 #top-controls.mi-menu-open{gap:9px!important;padding:12px!important;width:calc(100vw - 20px)!important}
 #top-controls>button,#top-controls>select,#top-controls summary{height:32px!important;min-height:32px!important;min-width:32px;padding:3px;font-size:14px}
 #top-controls>button{width:32px}#top-controls>button svg,#top-controls>button img,#top-controls #reset img,#computer img{width:25px!important;height:25px!important}
 #top-controls #language{width:52px!important;min-width:52px!important}#top-controls #language svg{width:46px!important;height:28px!important}
 #top-controls #show-decimal{width:39px;min-width:39px}#top-controls #shape-menu,#top-controls #colors{width:46px!important;flex-basis:46px!important}#top-controls #shape-menu summary,#top-controls #colors summary{width:46px!important;min-width:46px;gap:5px}#shape-menu summary svg,#current-color{width:24px!important;height:24px!important}
 #top-controls #game-level{width:88px!important;max-width:88px;font-size:14px!important}
 .workspace{grid-template-columns:minmax(0,1fr) 95px;gap:8px}aside{grid-template-columns:82px;grid-template-rows:112px 38px 52px 52px;gap:7px;padding-top:20px;padding-right:5px}.steps{width:82px}
}
@media(max-width:600px) and (orientation:portrait){
 .workspace{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) 158px;gap:8px}#figure-area{grid-area:1/1}
 aside{grid-area:2/1;grid-template-columns:repeat(3,minmax(0,82px));grid-template-rows:110px 34px;column-gap:clamp(9px,4vw,24px);row-gap:6px;justify-content:center;padding:0;align-self:stretch;width:100%;max-height:none}
 #fraction-box{grid-area:1/1;width:78px;font-size:32px;padding:4px 8px}.steps{grid-area:2/1;width:78px;gap:5px}.steps button{height:32px;width:35px;font-size:26px}
 #decimal-box{grid-area:1/2}#percent-box{grid-area:1/3}.value-box{width:78px;font-size:26px;padding:8px 2px;align-self:center}.value-box.long-value{font-size:20px}
 #game-controls{grid-area:1/1/3/4;margin:0;display:grid;grid-template-columns:minmax(0,1fr) 95px;grid-template-rows:55px 70px;gap:10px 18px;align-items:center;padding:10px 8px}
 .exercise-prompt{grid-area:1/1/3/2;transform:none;margin:0}#color-label{margin-bottom:10px}#exercise{font-size:30px;min-height:40px}#score{grid-area:1/2;margin:0;width:95px}.game-actions{grid-area:2/2}#guide-hand{top:-36px;font-size:30px}
}
@media(max-height:500px) and (orientation:landscape){aside{padding-top:7px;grid-template-rows:86px 32px 41px 41px;gap:5px}#game-controls{margin-top:25px}}

/* Prevent SVG tap/focus rectangles after touching individual sectors. */
#figure [data-cell]{-webkit-tap-highlight-color:transparent;outline:none;user-select:none;-webkit-user-select:none}
#figure [data-cell]:focus:not(:focus-visible){outline:none;box-shadow:none}
#figure [data-cell]:focus-visible{outline:none;stroke:#155cba;stroke-width:2}
@media(hover:none) and (pointer:coarse){#figure [data-cell]:focus,#figure [data-cell]:active{outline:none;box-shadow:none}}

/* Phone palette adapts automatically to available width. */
@media(max-width:600px),(max-width:950px) and (max-height:500px){
 #top-controls[data-mobile-menu].mi-mobile-menu.mi-menu-open{left:10px!important;right:10px!important;width:calc(100vw - 20px)!important;max-width:calc(100vw - 20px)!important;height:auto!important;max-height:calc(100dvh - 82px);display:flex!important;flex-wrap:wrap;justify-content:flex-start;align-items:center!important;align-content:flex-start;gap:12px!important;padding:14px!important;overflow:auto;box-sizing:border-box}
 #top-controls>.game-reserved{display:none!important}
 #top-controls>button,#top-controls>select,#top-controls>details{flex-shrink:0}
}

/* Four-digit fractions fit without enlarging the fixed value slots. */
.fraction input.four-digits,.fraction output.four-digits{font-size:.68em;letter-spacing:-.035em}

.whiteboard-tools {
  align-self: flex-end;
  margin-right: max(8px, env(safe-area-inset-right));
}
#color-label {
  font-size: clamp(23px, 4vw, 34px);
  font-weight: 700;
}
#denominator {
  caret-color: transparent;
}
#computer {
  position: relative;
}
#computer[aria-pressed="true"]::after {
  content: "×";
  position: absolute;
  top: 0;
  right: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #bd1c20;
  color: #fff;
  font: 700 17px/18px Arial, sans-serif;
  text-align: center;
  pointer-events: none;
}
