/* Phones in landscape (short screens). The desktop play screen needs ~500px of height; phones have 320–430px.
   Layout here: one slim header row, the room filling the rest, and the tools in a right-hand sidebar so
   Release and Place are always on screen. Loaded after game.css / game-fx.css. */
@media (orientation:landscape) and (max-height:520px){
  /* Phones held sideways: the level fills the full height; the header floats over its top edge; a slim tool rail on the right. */
  .play-screen:not([hidden]){
    --rail:clamp(112px,16vw,132px);
    position:relative;display:grid;grid-template-columns:minmax(0,1fr) var(--rail);grid-template-rows:minmax(0,1fr) auto;
    height:100vh;height:100dvh;min-height:0;box-sizing:border-box;
    padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right);
  }
  .mission-bar{display:none}
  #arena{grid-column:1;grid-row:1 / span 2;min-height:0;overflow:hidden}
  /* Floating header: two compact pills, the middle of the level stays visible. */
  .game-header{position:absolute;z-index:30;top:0;left:env(safe-area-inset-left);right:calc(var(--rail) + env(safe-area-inset-right));display:flex;align-items:flex-start;justify-content:space-between;gap:6px;padding:4px 6px;min-height:0;border:0;background:linear-gradient(#0f141acc,#0f141a00);pointer-events:none}
  .game-header>*{pointer-events:auto}
  .game-header>.icon-button{width:34px;height:34px;font-size:17px;border-radius:10px;background:#0f141ad9;border-color:#ffffff24}
  .stage-name{flex:0 1 auto;min-width:0;max-width:28%;padding:6px 10px;border-radius:10px;background:#0f141ad9}
  .stage-name .micro{display:none}
  .stage-name h2{font-size:12px;line-height:1.1;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .telemetry{order:0;flex:none;width:auto;padding:3px 4px;border-radius:10px;background:#0f141ae6;margin-left:auto}
  .telemetry>div{flex:none;padding:0 7px;display:flex;align-items:baseline;gap:4px}
  .telemetry>div>span{display:none}
  .telemetry strong{font-size:14px}
  .telemetry small{font-size:9px}
  .header-actions{gap:4px;flex:none}
  .header-actions .quiet,.speed,.fs-btn{min-height:34px;min-width:34px;padding:0 8px;border-radius:10px;background:#0f141ad9;border:1px solid #ffffff24}
  .header-actions .quiet span{display:none}
  /* Tool rail. */
  .tray{grid-column:2;grid-row:1;display:flex;flex-direction:column;flex-wrap:nowrap;align-items:stretch;gap:5px;padding:max(6px,env(safe-area-inset-top)) 6px 4px;border:0;border-left:1px solid #ffffff1f;overflow-y:auto;min-height:0;background:linear-gradient(#262830,#1d1f25)}
  .tray-label{display:none}
  .tools{display:grid;grid-template-columns:1fr 1fr;gap:5px;flex:none;width:auto}
  .tool{min-width:0;min-height:50px;padding:6px 2px 3px;gap:2px;border-radius:10px;border-color:#ffffff14;background:#ffffff08}
  .tool svg{width:22px;height:22px}
  .tool .tool-name{font-size:8px;letter-spacing:.2px}
  .tool small{display:none}
  .tool .count{top:-5px;right:-3px;font-size:9px;padding:1px 5px}
  .tool .count i{display:none}
  .tray-actions{border:0;padding:0;gap:5px;flex-direction:column;align-items:stretch;width:auto}
  .mini-actions{display:flex;gap:5px}
  .mini-actions .act-btn{flex:1;height:40px;padding:0 4px;gap:3px;font-size:9px}
  .act-btn .act-ico{font-size:15px}
  .release{width:100%;min-height:46px;justify-content:center;font-size:10px;padding:0 6px;border-radius:12px}
  .touch-place{display:none!important}
  .field-actions{grid-column:2;grid-row:2;display:flex;gap:4px;padding:4px 6px max(6px,env(safe-area-inset-bottom));border:0;border-left:1px solid #ffffff1f;background:#1d1f25;min-height:0}
  .field-tip,#zoom-button{display:none}
  .field-actions .text-button{flex:1;min-height:34px;padding:0 4px;font-size:9px;border:1px solid #ffffff17;border-radius:8px}
  .toast{bottom:14px;left:calc(50% - 62px);max-width:calc(100vw - 160px)}
}
@media (max-height:520px){
  dialog{max-height:calc(100dvh - 12px);width:min(680px,calc(100% - 24px))}
  .modal-inner{padding:14px 18px 0}
  .modal-top{margin-bottom:8px}
  .modal-inner h2{font-size:22px;line-height:1.1;margin-bottom:6px}
  .modal-inner h2 br{display:none}
  .modal-inner h2 em{margin-left:.25em}
  .modal-inner p{font-size:12px;line-height:1.5;margin:6px 0}
  .brief-tools{columns:2;column-gap:18px;font-size:12px;line-height:1.45;margin:6px 0;padding-left:18px}
  .brief-tools li{break-inside:avoid;margin-bottom:3px}
  .help-tools{grid-template-columns:repeat(3,1fr);gap:6px;margin:8px 0}
  .help-tool{padding:8px}
  .keyboard-note{display:none}
  .modal-actions{position:sticky;bottom:0;margin:10px -18px 0;padding:10px 18px max(10px,env(safe-area-inset-bottom));background:linear-gradient(#1d222b00,#1d222b 30%);gap:8px}
  .modal-actions>*{min-height:44px}
  .result-header{padding:14px 18px}
  .result-header h2{font-size:22px}
  .result-body{padding:12px 18px 0}
  .result-hero{padding:6px}
  .result-hero img,.result-hero canvas.mascot-display{width:84px!important;height:84px!important}
  .stars{font-size:26px}
  .result-stats{margin-top:10px;gap:8px}
  .result-stats div{padding:8px 10px}
  .result-stats b{font-size:18px}
  .score-post{display:flex;flex-wrap:wrap;align-items:center;gap:8px 14px;margin-top:8px}
  .score-post .primary{min-height:44px}
}
/* Very short screens (iPhone SE 1st gen, 320px): icon-only tools. */
@media (orientation:landscape) and (max-height:340px){
  .tool{min-height:44px}.tool .tool-name{display:none}.tool svg{width:24px;height:24px}
  .mini-actions .act-btn{height:36px}.act-btn .act-lbl{display:none}
  .release{min-height:42px}
  .stage-name{display:none}
}
/* Title screen in landscape on phones: headline and buttons left, mascot right, everything on one screen. */
@media (orientation:landscape) and (max-height:520px){
  .title-screen{height:100dvh;max-height:none;overflow-y:auto}
  .masthead{padding:10px 20px}
  .title-main-wrap{flex-direction:row;justify-content:space-between;align-items:center;gap:12px;padding:0 20px}
  .title-content{text-align:left;align-items:flex-start;padding:0;max-width:62%}
  .title-content .eyebrow{font-size:8px;max-width:none}
  .title-screen h1,.title-content h1{font-size:clamp(26px,8.5vh,40px);letter-spacing:-1.5px;margin:6px 0 4px}
  .subtitle{font-size:12px;max-width:none}
  .title-screen .intro{font-size:12px;margin:4px 0 0}
  .site-foot{margin:0 20px;padding:4px 0;font-size:10px}
  .title-actions{justify-content:flex-start;flex-wrap:wrap;gap:8px;margin-top:12px}
  .title-actions>*{min-height:44px;padding:0 16px;display:inline-flex;align-items:center}
  .title-actions .large{font-size:12px}
  .hero-display{width:min(34vw,58vh,260px);margin:0}
  /* Level select: smaller cards, more per row. */
  .level-content{padding:14px 20px 24px}
  .level-content h2{font-size:26px;margin:6px 0}
  .level-content>.muted{display:none}
  .level-grid{grid-template-columns:repeat(4,1fr);gap:8px;margin:12px 0}
  .level-info{padding:8px 10px}
  .level-info h3{font-size:13px;min-height:0;margin:6px 0 4px}
  .level-info p{margin:0;font-size:10px}
  .level-tag{margin-top:8px;padding-top:8px}
}
@media (orientation:landscape) and (max-height:520px) and (max-width:600px){ .level-grid{grid-template-columns:repeat(3,1fr)} }
/* Small phones held upright (iPhone SE 1st gen, old Androids): smaller mascot, skip the long copy. */
@media (orientation:portrait) and (max-height:700px){
  .title-screen{height:auto;min-height:100dvh;max-height:none;overflow-y:auto}
  .hero-display{width:min(34vw,120px)}
  .title-screen .intro{font-size:13px;margin:4px 0 0}
  .title-screen h1,.title-content h1{font-size:clamp(34px,10.5vw,44px);margin:8px 0 6px}
  .title-actions{margin-top:14px}
  .title-footer{position:static}
}
/* Labelled Flip / Undo on phones. */
@media (max-width:600px),(orientation:landscape) and (max-height:520px){
  .mini-actions .act-btn{flex:1;height:44px;padding:0 6px;font-size:10px;gap:4px}
  .act-btn .act-ico{font-size:17px}
}
@media (max-width:600px) and (orientation:portrait){ .mini-actions{flex:1.2} }
/* Home screen: header / body / footer only. */
.site-foot{align-items:center;gap:12px;flex-wrap:wrap;font-size:11px;letter-spacing:.8px}
.site-foot nav{display:flex;gap:4px;flex-wrap:wrap}
.site-foot nav a,.site-foot nav button{color:#d9cdd2;text-decoration:none;background:none;border:0;font:inherit;letter-spacing:inherit;text-transform:uppercase;padding:10px 10px;min-height:44px;display:inline-flex;align-items:center;cursor:pointer;border-radius:6px}
.site-foot nav a:first-child{padding-left:0}
.site-foot nav a:hover,.site-foot nav button:hover{color:var(--pink,#ffb1c1)}
.site-foot span:last-child{display:inline!important;color:#8b8790}
@media (max-width:600px){.site-foot{justify-content:center;text-align:center}.site-foot nav{justify-content:center}.site-foot nav a:first-child{padding-left:10px}}
/* "Playing now" counter */
.live-now{width:max-content;max-width:100%;box-sizing:border-box;display:inline-flex;align-items:center;gap:8px;margin:10px 0 0;padding:6px 12px;border-radius:999px;background:#ffffff0d;border:1px solid #ffffff1f;font:700 12px/1 Space,system-ui,sans-serif;color:#e9f7ef;letter-spacing:.02em}
.live-now b{font-size:14px;color:#9dffc8}
.live-dot{width:8px;height:8px;border-radius:50%;background:#3ee07f;box-shadow:0 0 0 0 #3ee07f99;animation:live-pulse 1.8s ease-out infinite}
@keyframes live-pulse{0%{box-shadow:0 0 0 0 #3ee07f99}100%{box-shadow:0 0 0 8px #3ee07f00}}
@media (prefers-reduced-motion:reduce){.live-dot{animation:none}}
.level-content .live-now{margin:8px 0 0}
/* Lighter home-screen and level-card art (WebP, same picture). */
.title-art{background:linear-gradient(90deg,#0f141afc 2%,#0f141ae8 34%,#0f141a47 73%),linear-gradient(0deg,#0f141a 0%,transparent 50%,#0f141a99 100%),url('ref/stitch/layout1.webp') center right/cover}
.level-art{background-image:url('ref/stitch/layout1.webp')}

/* Touch play: no page scrolling, zooming or text-selection popups while you play. */
.play-screen #world,.play-screen #world canvas{touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
.play-screen button,.tray{touch-action:manipulation;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
/* Magnifier shown above the finger while placing a tool. */
#loupe{position:fixed;z-index:200;width:132px;height:132px;border-radius:50%;pointer-events:none;box-shadow:0 10px 30px #000c}
#loupe[hidden]{display:none}
/* Fullscreen button only where the browser supports it (not iPhone Safari); Home Screen tip only on iPhone. */
.fs-only{display:none!important}
html.can-fs.touch .fs-only{display:inline-flex!important}
html.is-fs .fs-btn{opacity:.7}
.ios-only{display:none}
html.ios-tip .ios-only{display:block}
/* "Turn your phone" screen. */
#rotate-gate{gap:10px}
#rotate-gate .rot-phone{width:46px;height:80px;border:3px solid #ffb1c1;border-radius:10px;position:relative;animation:rot-turn 2.4s ease-in-out infinite;margin-bottom:10px}
#rotate-gate .rot-phone i{position:absolute;left:50%;bottom:6px;width:10px;height:3px;margin-left:-5px;border-radius:2px;background:#ffb1c1}
@keyframes rot-turn{0%,25%{transform:rotate(0)}55%,85%{transform:rotate(-90deg)}100%{transform:rotate(0)}}
#rotate-gate .primary{margin-top:10px;min-height:52px;padding:0 26px;font-size:16px}
#rotate-gate .ios-only{max-width:300px;font-size:13px;color:#b7a2ac;margin-top:8px}
@media (prefers-reduced-motion:reduce){#rotate-gate .rot-phone{animation:none;transform:rotate(-90deg)}}
.release .rb-long{font-weight:inherit}
@media (orientation:landscape) and (max-height:520px){.release .rb-long{display:none}.release{font-size:12px;letter-spacing:.06em}}
#rotate-gate{background:#0f141a}
#rotate-gate .ios-only b{display:inline;font-size:inherit;margin:0;color:#f4eef1}
/* Touch screens always show the whole level: no zoom (a zoomed level can't be panned while dragging tools). */
html.touch #zoom-button{display:none}
