
@media (orientation:portrait) and (max-width:740px) {
  body:has(#art-frame) {
    --phone-side: max(12px, env(safe-area-inset-left));
    --phone-bottom: max(13px, env(safe-area-inset-bottom));
    --phone-art-top: clamp(132px, calc(32dvh - 34px), 248px);
    --phone-art-height: calc(100vw * 941 / 1672);
    margin:0;padding:0;display:block;height:100dvh;overflow:hidden;
    background:#311a49 url("../phone/game.webp") center/cover no-repeat;
  }
  body:has(#art-frame):is(.cover-active,.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active,.count-active,.value-active)::before {display:none}
  body.cover-active:has(#art-frame) {background:#37224f url("../phone/opening.webp") center/cover no-repeat}
  body:has(#art-frame) #art-frame {
    position:fixed;inset:0;transform:none;width:100%;height:100dvh;
    aspect-ratio:auto;display:block;container-type:inline-size;isolation:isolate;
  }
  body:has(#art-frame) #art-frame .topbar {
    position:fixed;display:block;z-index:10;inset:max(8px, env(safe-area-inset-top)) 8px auto;
    width:auto;min-height:0;padding:0;margin:0;
  }
  body:has(#art-frame) #art-frame #levels,body:has(#art-frame) #art-frame .identity{display:none}
  #art-frame .topbar .tools{justify-content:flex-end;gap:6px}
  #art-frame .topbar .tools :is(#number-picker,#language-toggle,#sound,#full){height:44px;min-height:44px}
  #art-frame .topbar .tools :is(#language-toggle,#sound,#full){min-width:44px}
  #art-frame .topbar .tools #number-picker{min-width:86px;max-width:105px}
  #art-frame #full-label{display:none}
  #art-frame .language-popover{max-width:calc(100vw - 20px)}
  #art-frame .language-option{min-height:44px;font-size:1rem}
  #art-frame #language-search{min-height:42px;font-size:16px}
  body.cover-active #art-frame #cover {
    position:absolute;display:block;top:50%;left:50%;transform:translate(-50%,-50%);
    width:min(100vw,calc(100dvh * 841 / 1870));height:auto;aspect-ratio:841 / 1870;overflow:visible;
  }
  .cover-art,.cover-picture{width:100%;height:100%;object-fit:contain}
  body.cover-active #cover .cover-title {
    inset:15.8% 6% auto;height:11.5%;align-items:center;
  }
  body.cover-active #cover .cover-title span{font-size:clamp(1.35rem,7.4vw,2.45rem);white-space:normal;line-height:1.14}
  body.cover-active #cover .cover-start{inset:70.1% 8% 13.7% 8%;border-radius:50%}
  body.cover-active #cover .cover-start span{inset:12% 10%;font-size:clamp(1.3rem,8vw,2.9rem)}
  #art-frame main{position:fixed;inset:0;width:100%;max-width:none;min-height:0;padding:0}
  #art-frame #game{width:100%;height:100%;min-height:0}
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #scene{
    position:fixed;inset:var(--phone-art-top) 0 auto;width:100%;height:var(--phone-art-height);
    border-radius:12px;aspect-ratio:1672/941;overflow:hidden;
  }
  body.gate-active:not(.gate-solved) #art-frame #scene,
  body.cart-active:not(.cart-solved) #art-frame #scene,
  body.puppet-active:not(.puppet-solved) #art-frame #scene,
  body.rail-active:not(.rail-solved) #art-frame #scene{clip-path:inset(0 0 27% 0 round 12px)}
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #art-words{display:none}
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #game .heading{
    display:block!important;visibility:visible;position:fixed;
    inset:calc(var(--phone-art-top) - 12px) var(--phone-side) auto;transform:translateY(-100%);z-index:3;max-width:none;height:auto;
    padding:.45rem .6rem;border:1px solid #dca85d77;border-radius:14px;background:#43264dbf;
  }
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #game .heading h1{
    display:block;position:static;clip-path:none;width:auto;height:auto;overflow:visible;
    font-size:clamp(1.1rem,6vw,1.85rem);line-height:1.15;color:#ffedb8;
  }
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #game .heading #message{
    display:block;font-size:clamp(.8rem,3.85vw,1.05rem);line-height:1.2;color:#fff3ce;margin-top:.27rem;
  }
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active) #art-frame #gate-answers{
    position:fixed;inset:calc(var(--phone-art-top) + var(--phone-art-height) * .73 + 12px) 10px auto;
    display:flex;justify-content:center;gap:8px;z-index:5;
  }
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active) #art-frame #gate-answers > button{
    position:static;inset:auto;min-height:48px;height:auto;width:clamp(60px,20vw,92px);
    border:2px solid #ffdb82;border-radius:14px;padding:5px 7px;
    color:#fff0b8;background:linear-gradient(#914677,#602752)!important;
    box-shadow:0 3px 0 #30183f;font-size:1.25rem;
  }
  body:is(.gate-active,.cart-active,.puppet-active) #art-frame #gate-answers > button.correct{
    background:linear-gradient(#31976d,#1e6544)!important;
  }
  body.rail-active #art-frame #gate-answers > button{width:min(46%,172px);font-size:.87rem}
  body.rail-active #art-frame #gate-answers > button:last-child{background:linear-gradient(#347f5a,#21513b)!important}
  body.wheel-active #art-frame .bulb{width:42px;height:42px;border:0;background:none;box-shadow:none}
  body.wheel-active #art-frame .bulb.lit::after{
    content:"";position:absolute;inset:24%;border-radius:50%;
    background:radial-gradient(circle,#fffabd,#ffd34e 64%,#ee9c31);box-shadow:0 0 10px #ffcf54;
  }
  body:is(.count-active,.value-active) #art-frame #scene{
    position:fixed;inset:0;width:100%;height:100%;background-size:cover;
  }
  #art-frame .count-art{object-fit:cover}
  #art-frame .count-board{inset:14% 13px 25%;gap:10px}
  #art-frame .count-board h2,#art-frame .value-groups h2{font-size:clamp(.95rem,4.6vw,1.2rem)}
  #art-frame .count-grid{width:100%}
  #art-frame .count-grid .count-tag{font-size:.84rem;min-width:1.45em}
  #art-frame .count-tally,#art-frame .count-add{font-size:1rem}
  #art-frame .count-add{min-height:44px}
  #art-frame .water-seller{left:auto;right:0;bottom:-15%;width:26%}
  #art-frame .value-board{inset:10.5% 12px 24%;gap:9px}
  #art-frame .value-groups{grid-template-columns:1fr;grid-template-rows:1.55fr 1fr;gap:11px}
  #art-frame .value-groups section{height:100%;padding:4px 2px;min-height:0}
  #art-frame .value-progress,#art-frame .value-equation{font-size:1rem}
  #art-frame .value-tens .value-tray{max-width:26%;max-height:65px}
  #art-frame .value-tens.one-tray .value-tray{max-width:43%;max-height:85px}
  #art-frame .value-ones img{width:min(14%,43px);height:min(11vw,43px);flex-basis:min(14%,43px)}
  #art-frame .value-choices .choice{min-width:62px;min-height:44px;font-size:1.18rem}
  body:is(.count-active,.value-active) #art-frame #game .heading{inset:auto 12px 13%;padding:.45rem .55rem;min-height:0}
  body:is(.count-active,.value-active) #art-frame #game .heading #message{font-size:.9rem;line-height:1.15}
  body:not(.cover-active) #art-frame #game #controls{
    position:fixed;inset:auto var(--phone-side) var(--phone-bottom);z-index:6;
    display:flex;justify-content:space-between;width:auto;max-width:none;padding:0;transform:none;
    margin:0;background:none;border:0;pointer-events:none;
  }
  #art-frame #controls :is(#next,#previous){width:108px;height:48px;min-height:44px;font-size:.91rem}
  body:not(.cover-active,.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active,.count-active,.value-active) #art-frame #game{
    padding:72px 10px 64px
  }
  #art-frame #audio-status{position:fixed;left:12px;right:12px;bottom:68px;z-index:8}
}


@media (orientation:portrait) and (max-width:740px){
  body:has(#art-frame):is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active,.count-active,.value-active){
    background:#311a49 url("../phone/game.webp") center/cover no-repeat;
  }
  #art-frame #title:focus{outline:none}
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #game .heading{
    box-shadow:0 4px 9px #24133356;background:#43264df2;
  }
  body:is(.gate-active,.cart-active,.puppet-active,.rail-active,.wheel-active) #art-frame #scene{
    border-radius:12px;box-shadow:0 5px 16px #24133380;
  }
  #art-frame #controls :is(#next,#previous){filter:drop-shadow(0 2px 2px #23102a80)}
  #art-frame .count-item:is(button){min-height:44px}
  #art-frame .value-tens .value-tray b{font-size:clamp(.55rem,2.3vw,.75rem)}
  #art-frame .value-choices .choice:disabled:not(.correct){opacity:.55}
  @media(max-height:620px){
    body:has(#art-frame){--phone-art-top: clamp(132px, 30dvh, 169px)}
    #art-frame .count-board{top:11%}
    #art-frame .value-board{inset:11% 10px 25%;gap:4px}
  }
}
