/* 0.5.0: a single-screen game, not a scrolling webpage. Safe areas owned by CSS. */
:root{--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px);--safe-left:env(safe-area-inset-left,0px);--safe-right:env(safe-area-inset-right,0px)}
#illustrated-brand{display:none;width:202px;height:auto;max-height:46px;object-fit:contain}
.illustrated-art-ready .brand>span{display:none}
.illustrated-art-ready #illustrated-brand{display:block}
#illustrated-world{display:none;position:absolute;inset:0;width:100%;height:100%;object-fit:cover;border-radius:11px}
.illustrated-art-ready .game-shell[data-world="5"] #illustrated-world{display:block}
.illustrated-art-ready .game-shell[data-world="5"] .world-thumb-emoji{visibility:hidden}
.game-heading>.icon-button:before,.game-heading>.icon-button:after{pointer-events:none}
.game-stage canvas{width:100%;height:100%;max-width:none;aspect-ratio:auto;flex:none;display:block}
.game-stage{background:#203955}
.game-controls{position:relative}
#rotate-left,#rotate-right,#reset-board{touch-action:manipulation}
.game-nav button{touch-action:manipulation}
.route-note{display:none!important}
.stage-status{max-width:76%;left:50%;transform:translateX(-50%);top:9px;white-space:nowrap;letter-spacing:.25px;padding:8px 12px;background:#152741df;border:1px solid #f5fcff80;font-size:9px;font-weight:900}
.watch-fail{top:auto;right:7px;bottom:7px;font-size:9px;min-height:32px;background:#172c43ba}
.game-advice{font-weight:600;color:#4b5d7d;line-height:1.3}
.game-controls .selection-label:before{left:3px;top:8px;width:26px;height:11px}
.selection-label #selected-label,.selection-label #move-label{margin-left:35px}
.rotation-controls{justify-content:stretch;gap:7px}
.rotation-controls .rotate-button{flex:1;max-width:none}
.rotation-controls #angle-label{flex:1.4;min-width:0}
.help-row button{font-size:11px;font-weight:800;border:1px solid #e5dfd7;min-height:44px}
.help-row button svg{width:23px;height:23px;filter:drop-shadow(0 1px 1px #ffffff)}
.game-nav button{font-size:10px}
.game-nav button svg{width:23px;height:23px}
.game-nav button.active{background:linear-gradient(145deg,#fff6ec,#ffefe0);color:#e85e1c}
.primary-button#run-button{border-radius:17px;font-size:26px;font-weight:950;min-height:54px;text-shadow:0 2px 0 #c03b16,0 4px 5px #a43a1a70}
.primary-button#run-button::before{content:''}
.primary-button#run-button .button-spark{font-size:18px}
.primary-button#run-button>svg{transform:rotate(-14deg)}
.precision-panel{position:absolute;left:6px;right:6px;bottom:160px;z-index:8;background:#fffdf5;border:2px solid #ddd6c8;box-shadow:0 8px 30px #142a5055;border-radius:16px;margin:0;padding:11px}
.precision-controls button{min-height:44px}
#level-tip{position:absolute;z-index:7;bottom:210px;left:10px;right:10px;margin:0;max-height:135px;overflow:auto;background:#fff7dce8;font-size:12px;pointer-events:auto}
.coach-panel{display:none!important}
/* The browser and the native app share the portrait screen. */
@media(max-width:700px){
 html{height:100%;overflow:hidden;background:#f7f3ea}
 body{height:100vh;height:100dvh;min-height:0;width:100%;padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);overflow:hidden;display:flex;flex-direction:column;background:linear-gradient(180deg,#c8def7,#eaf0f7 20%,#fffaf1 100%);position:relative}
 .svg-defs{position:absolute;pointer-events:none}
 .site-header{flex:0 0 53px;min-height:53px;width:100%;max-width:520px;padding:4px 12px 5px;margin:0 auto;align-items:center;overflow:hidden}
 .brand{gap:7px;font-size:9px;max-width:64%;min-width:0}
 .brand-box{width:34px;height:35px;flex:0 0 34px}
 .brand>span:last-child{font-size:8px}
 .brand strong{font-size:20px}
 #illustrated-brand{width:197px;max-width:100%;height:auto;max-height:43px}
 .header-right{gap:0;flex:none}
 .language-switch{padding:2px;border-radius:17px;box-shadow:0 2px 7px #354d701a}
 .language-switch button{min-width:39px;min-height:38px;font-size:11px;padding:5px}
 .app-layout{display:block;flex:1 1 0;min-height:0;width:100%;max-width:520px;padding:0 7px;margin:0 auto}
 .intro-rail,.side-rail{display:none}
 .game-shell{height:100%;min-height:0;width:100%;display:flex;flex-direction:column;border-radius:22px;border-width:1px;box-shadow:0 3px 0 #b8c6d03d,0 7px 20px #24436514;position:relative}
 .game-heading{flex:0 0 65px;min-height:65px;padding:7px 10px 3px;gap:9px;background:linear-gradient(135deg,#fffcf4,#fef7ee);overflow:hidden}
 .game-heading>.icon-button{width:53px;height:53px;min-width:53px;flex:0 0 53px;border-radius:12px}
 .game-heading>div:nth-child(2){align-self:center;min-width:0}
 .world-thumb-emoji{font-size:27px}
 .game-heading p{font-size:8px;letter-spacing:.3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;line-height:1.1}
 .game-heading h2{font-size:clamp(11px,3.3vw,15px);line-height:1.16;max-height:2.32em;margin:3px 0 4px;letter-spacing:-.2px}
 .level-counter{font-size:23px;align-self:center;padding:0;line-height:1;white-space:nowrap}
 .level-counter span{font-size:9px}
 .journey-meter{height:7px;width:88%;max-width:170px}
 .challenge-strip{flex:0 0 28px;min-height:28px;padding:2px 10px 5px;gap:4px;border-bottom:1px solid #f0e8dc;overflow:hidden}
 .difficulty-badge{padding:3px 7px;border-radius:10px;font-size:9px;box-shadow:none}
 .difficulty-dots{font-size:7px!important}
 .checkpoint-count{font-size:9px;padding:3px 7px;border-radius:9px;box-shadow:none}
 .mechanic-label{font-size:8px;letter-spacing:.4px}
 .daily-banner{flex:0 0 26px;padding:2px 10px;min-height:26px}
 .game-stage,.guide-layout .game-stage,.precision-open .game-stage{position:relative;flex:1 1 0;min-height:0!important;max-height:none!important;height:auto!important;aspect-ratio:auto;width:100%;border:0;overflow:hidden}
 .game-stage canvas{width:100%!important;height:100%!important;max-width:none!important;aspect-ratio:auto;flex:none}
 .stage-status{font-size:9px;line-height:1.2;min-height:28px;top:7px;padding:6px 10px;max-width:85%;letter-spacing:.1px}
 .watch-fail{font-size:9px;max-width:108px;min-height:30px;top:auto;bottom:6px;right:6px}
 .game-advice{flex:0 0 34px;min-height:34px;max-height:34px;margin:5px 8px 0;padding:5px 8px;gap:6px;border-radius:12px;font-size:10px;overflow:hidden;box-shadow:0 1px 4px #9b784913}
 .game-advice-icon{flex:0 0 19px;font-size:19px}
 #game-advice-text{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
 .game-controls{flex:0 0 auto;display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:27px 44px 50px 44px;gap:5px 6px;padding:7px 8px 6px;margin:0;background:#fffaf4;min-height:0;max-height:none}
 .adjust-row{display:contents}
 .selection-label{grid-row:1;grid-column:1;padding:0;align-self:center;min-width:0}
 .selection-label:before{top:8px;left:2px;width:22px;height:9px}
 .selection-label #selected-label{font-size:10px;letter-spacing:.25px;margin:0 0 2px 29px;line-height:1.1}
 .selection-label #move-label{font-size:9px;margin:0 0 0 29px;line-height:1.15}
 .precision-row{grid-row:1;grid-column:2;margin:0;gap:4px;align-self:center;height:27px}
 .precision-row .text-button{height:27px;min-height:27px;font-size:9px;border-radius:9px;padding:3px 7px;box-shadow:0 1px 0 #dbd7d0}
 .precision-row #select-next{font-size:9px;max-width:92px;padding:3px 5px;min-height:27px}
 .precision-row .text-button>svg{width:11px;height:11px}
 .rotation-controls{grid-row:2;grid-column:1;gap:6px;align-self:stretch;min-height:0}
 .rotation-controls .rotate-button{min-width:44px;width:auto;height:44px;min-height:44px;flex:1;max-width:72px;font-size:27px;border-radius:12px}
 .rotation-controls #angle-label{height:44px;min-height:44px;font-size:22px;border-radius:12px;flex:1.5;line-height:1}
 .reset-button{grid-row:2;grid-column:2;width:100%;height:44px;min-width:44px;min-height:44px;max-width:none;justify-self:stretch;border-radius:12px}
 .main-actions{grid-column:1/-1;grid-row:3;margin:0}
 .primary-button#run-button{height:50px;min-height:50px;font-size:25px;border-radius:15px;padding:6px 20px;box-shadow:inset 0 2px 2px #ffef97,0 3px 0 #be4c20,0 5px 8px #df743e37}
 .primary-button#run-button>svg{width:25px;height:25px}
 .primary-button#run-button:after{right:8%;bottom:9px;font-size:15px}
 .help-row{grid-column:1/-1;grid-row:4;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px;margin:0;min-height:0}
 .help-row button{min-height:44px;height:44px;font-size:10px;padding:5px 4px;gap:4px;box-shadow:0 2px 0 #eadbd0;border-radius:14px;white-space:nowrap}
 .help-row button svg{width:20px;height:20px;flex:none}
 .help-row button span[id$='-count']{font-size:9px;min-width:18px;height:18px}
 .game-nav{flex:0 0 49px;min-height:49px;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:4px;padding:2px 5px 3px;margin:0;border-top:1px solid #eae2d9}
 .game-nav button{height:44px;min-height:44px;padding:3px 2px;font-size:9px;gap:2px}
 .game-nav button svg{width:20px;height:20px}
 .site-footer{flex:0 0 16px;min-height:16px;margin:0;width:100%;padding:1px 6px;display:flex;justify-content:center;align-items:center;font-size:8px;line-height:1;overflow:hidden}
 .site-footer>span:first-child{display:none}
 .site-footer #save-status{display:flex;align-items:center;justify-content:center;gap:5px;white-space:nowrap}
 .modal-backdrop{padding:calc(var(--safe-top) + 12px) max(12px,var(--safe-right)) calc(var(--safe-bottom) + 12px) max(12px,var(--safe-left))}
 .modal{max-height:100%;overflow-y:auto;-webkit-overflow-scrolling:touch}
 .toast{bottom:calc(var(--safe-bottom) + 72px)}
}
@media(max-width:370px){
 #illustrated-brand{width:175px}
 .site-header{flex-basis:46px;min-height:46px;padding:3px 9px}
 .game-heading{flex-basis:61px;min-height:61px;gap:6px;padding:6px 8px 3px}
 .game-heading>.icon-button{width:46px;min-width:46px;flex-basis:46px;height:49px}
 .game-heading p{font-size:7px}
 .level-counter{font-size:20px}
 .language-switch button{min-width:34px;min-height:34px}
 .game-controls{padding:6px;gap:4px}
 .selection-label #selected-label{font-size:9px}
 .selection-label #move-label{font-size:8px}
 .help-row button{font-size:9px;gap:3px}
 .help-row button svg{width:17px;height:17px}
 .precision-row .text-button{font-size:8px;padding:3px 5px}
 .precision-row #select-next{font-size:8px;padding:3px 4px}
}
@media(max-width:700px) and (max-height:700px){
 .game-advice{display:none}
 .site-footer{display:none}
 .site-header{flex-basis:44px;min-height:44px}
 .game-heading{flex-basis:57px;min-height:57px}
 .game-heading>.icon-button{height:45px;min-width:45px;width:45px;flex-basis:45px}
 .game-heading h2{font-size:12px;margin:2px 0 3px}
 .challenge-strip{flex-basis:24px;min-height:24px;padding-top:0;padding-bottom:3px}
 .game-controls{grid-template-rows:24px 44px 46px 44px;gap:4px;padding:5px 7px}
 .primary-button#run-button{height:46px;min-height:46px;font-size:23px}
 .game-nav{flex-basis:47px;min-height:47px}
}
@media(min-width:701px){
 .game-stage canvas{width:100%;height:100%;max-width:none}
 .game-shell{position:relative}
}
@media(orientation:landscape) and (max-height:520px){
 body{overflow:auto;height:auto;min-height:100dvh}
 .site-header{height:46px;min-height:46px}
 .app-layout{min-height:640px}
 .game-stage,.guide-layout .game-stage,.precision-open .game-stage{min-height:260px!important}
}
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important}}
/* Match the reference's control hierarchy while retaining an explicit reset. */
@media(max-width:700px){
 .game-controls{grid-template-columns:repeat(5,minmax(0,1fr))}
 .game-controls .selection-label{grid-column:1/3;grid-row:1}
 .game-controls .selection-label #selected-label{font-weight:850;letter-spacing:.1px;margin-left:27px}
 .game-controls .selection-label #move-label{margin-left:27px;font-size:8px}
 .game-controls .selection-label:before{left:2px;top:5px;width:20px;height:8px}
 .game-controls .precision-row{display:contents}
 .game-controls #precision-toggle{grid-column:4/6;grid-row:1;justify-self:stretch;align-self:center;font-size:10px;min-height:27px;padding:3px 7px}
 .game-controls #reset-board{grid-column:3;grid-row:1;min-height:27px;height:27px;min-width:29px;width:29px;justify-self:center;box-shadow:none;border-radius:9px}
 .game-controls #reset-board svg{width:17px;height:17px}
 .game-controls .rotation-controls{grid-column:1/4;grid-row:2;width:100%;gap:6px}
 .game-controls .rotation-controls .rotate-button{max-width:none}
 .game-controls #select-next{grid-column:4/6;grid-row:2;min-height:44px;height:44px;width:100%;max-width:none;justify-self:stretch;border-radius:12px;font-size:10px;background:linear-gradient(145deg,#fffefa,#eceaf2);padding:4px 5px}
 .game-controls #select-next:before{content:'';display:inline-block;flex:none;width:22px;height:8px;border:1px solid #466bba;border-radius:3px;transform:rotate(-24deg);background:linear-gradient(#b2d6ff,#5281d4);box-shadow:0 2px 1px #304e9044;margin:0 3px}
 .game-controls:not(:has(#select-next:not([hidden]))) .rotation-controls{grid-column:1/-1}
 .game-controls .main-actions,.game-controls .help-row{grid-column:1/-1}
 .game-heading h2{font-weight:850}
 .primary-button#run-button{font-weight:850}
 .help-row button,.game-nav button{font-weight:750}
 .illustrated-art-ready .primary-button#run-button>svg{display:none}
 .illustrated-art-ready .primary-button#run-button:before{content:'';position:static;display:block;flex:none;width:29px;height:23px;background-image:url('./art-atlas.png');background-size:184.32px 92.16px;background-position:-126px -31.68px;background-repeat:no-repeat;filter:drop-shadow(0 2px 1px #b64520)}
}


/* 0.7.2 — explicit Fine-tune dismissal. No backdrop: a tap on another control
   closes the popover AND performs that control's normal action in one touch. */
#precision-close {
  flex:0 0 38px;
  width:38px;
  height:38px;
  min-height:38px;
  margin-left:auto;
  display:grid;
  place-items:center;
  color:#4c5d7c;
  font-size:25px;
  font-weight:750;
  line-height:1;
  background:linear-gradient(150deg,#fffefb,#f2ecdf);
  border:1px solid #e4dfd7;
  border-radius:12px;
  box-shadow:0 2px 0 #d8d3c8;
  touch-action:manipulation;
}
#precision-close:active{transform:translateY(1px);box-shadow:0 1px 0 #d8d3c8}
#precision-close:focus-visible{outline:3px solid #ef8e3e;outline-offset:2px}
#precision-panel[hidden]{display:none!important}

/* 0.7.3 — always-available FREE restart for the current level.
   The old 29px reset icon was hidden in a cramped button strip. */
.game-stage #restart-level{
  position:absolute;right:9px;top:8px;z-index:15;
  min-width:107px;min-height:39px;padding:7px 10px;
  display:flex;align-items:center;justify-content:center;gap:4px;
  color:#25345c;background:linear-gradient(165deg,#fffdf4,#f8e6c8);
  border:2px solid #fffef0;border-radius:13px;
  box-shadow:0 3px 0 #996c4e,0 5px 14px #0b263c80;
  font-weight:950;font-size:11px;line-height:1.1;
  white-space:nowrap;touch-action:manipulation;-webkit-tap-highlight-color:transparent;
}
.game-stage #restart-level:active{transform:translateY(2px);box-shadow:0 1px 0 #996c4e}
.game-stage #restart-level:focus-visible{outline:3px solid #ffb858;outline-offset:3px}
.game-stage #restart-level.needs-reset{background:linear-gradient(155deg,#fff4d3,#ffc983);border-color:#fff0c5}
.game-controls #reset-board{display:none!important}
.game-stage .watch-fail{display:none!important}
.game-controls #move-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
@media(max-width:370px){
  .game-stage #restart-level{min-width:93px;min-height:36px;padding:6px 7px;font-size:10px;right:6px;top:6px}
  .game-stage .stage-status{max-width:54%;overflow:hidden;text-overflow:ellipsis}
}
@media(min-width:701px){.game-stage #restart-level{right:10px;top:10px}}
