/* Louhtak photo studio — phone layout (≤760px).
   Wide canvas first; one clear top bar; tools as a labelled dock under the canvas; panels as bottom sheets.
   Only presentation: every button keeps its original data-action / data-tool and handlers. */
@media (max-width:760px){
  :root{--ms-bg:#161616;--ms-s1:#232323;--ms-s2:#2f2f2f;--ms-line:rgba(255,255,255,.09);--ms-ink:#f2ede6;--ms-mute:#a5a09a;--ms-acc:#c4573a;--ms-acc2:#9a3a22;--ms-dock:118px;--ms-nav:58px}
  html,body{background:var(--ms-bg)!important;overscroll-behavior:none}
  .app{display:flex!important;flex-direction:column;height:100dvh!important;min-height:0;overflow:hidden;background:var(--ms-bg)}

  /* top bar */
  .top{order:0;height:auto!important;min-height:54px;flex-wrap:nowrap!important;align-items:center!important;gap:6px!important;padding:calc(6px + env(safe-area-inset-top,0px)) 10px 6px!important;background:var(--ms-bg)!important;border:0!important;position:relative}
  .top .brand{display:flex;align-items:center;gap:6px;font-size:0!important;color:var(--ms-ink)!important;text-decoration:none;min-width:40px;min-height:40px}
  .top .brand:before{content:"";width:34px;height:34px;border-radius:50%;background:var(--ms-s2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f1e8da' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E") center/18px no-repeat}
  .top .brand i,.top .brand span{display:none}
  .ms-title{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;line-height:1.2}
  .ms-title input{background:none;border:0;color:var(--ms-ink);font:700 15px/1.3 inherit;font-family:inherit;padding:0;width:100%;outline:0;text-overflow:ellipsis}
  .ms-title small{color:var(--ms-mute);font-size:10.5px}
  .menubar{display:none!important}
  .top-actions{order:3;margin:0!important;gap:6px!important;display:flex!important;align-items:center}
  .top-actions button{min-height:36px!important;border-radius:18px!important;font-size:13px!important;padding:0 12px!important}
  .top-actions [data-action=undo],.top-actions [data-action=redo],.top-actions .quiet{display:none!important}
  .top-actions .outline{display:inline-flex!important;align-items:center;background:var(--ms-s2)!important;border:0!important;color:var(--ms-ink)!important}
  .top-actions .primary{background:var(--ms-acc2)!important;border:0!important;color:#fff!important;font-weight:700}
  .ms-more{order:4;width:36px;height:36px;border-radius:50%;border:0;background:var(--ms-s2);color:var(--ms-ink);font-size:18px;line-height:1;display:grid;place-items:center}

  /* canvas — as big as possible */
  .workspace{order:1;flex:1 1 auto!important;min-height:0;display:flex!important;flex-direction:column!important;position:relative}
  .stage-area{order:1;flex:1 1 auto!important;min-height:0;position:relative;background:#0e0c0b!important;margin:0 8px;border-radius:18px;overflow:hidden}
  .document-tab{display:none!important}
  #stage{position:absolute!important;inset:0!important;height:auto!important}
  .statusbar{position:absolute!important;left:10px;bottom:10px;height:auto!important;padding:3px!important;border-radius:16px;background:rgba(20,18,16,.72)!important;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border:1px solid var(--ms-line)!important;z-index:5;gap:2px!important}
  .statusbar #dimensions,.statusbar #coordinates{display:none!important}
  .statusbar button{min-width:34px!important;min-height:30px!important;border-radius:14px;color:var(--ms-ink)!important;font-size:13px!important}
  .ms-undo{position:absolute;right:10px;bottom:10px;z-index:5;display:flex;gap:2px;padding:3px;border-radius:16px;background:rgba(20,18,16,.72);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border:1px solid var(--ms-line)}
  .ms-undo button{width:40px;height:32px;border:0;border-radius:13px;background:none;color:var(--ms-ink);font-size:18px}
  .ms-undo button:active{background:var(--ms-s2)}

  /* active-tool options: one slim scrollable row under the canvas */
  .context{order:2!important;height:auto!important;min-height:46px;margin:6px 8px 0;padding:0 10px!important;gap:12px!important;border-radius:14px;background:var(--ms-s1)!important;border:0!important;overflow-x:auto;scrollbar-width:none;flex-wrap:nowrap!important}
  .context::-webkit-scrollbar{display:none}
  .context>button,.context .divider,.context-hint{display:none!important}
  .context .active-tool{min-width:auto!important;font-size:13px!important;color:var(--ms-ink);gap:6px!important;flex:none}
  .context .active-tool b{display:inline!important}
  .context label{flex:none;font-size:12px!important;color:var(--ms-mute);gap:6px!important;white-space:nowrap}
  .context input[type=number]{width:52px!important;height:32px;border-radius:9px;font-size:15px!important}
  .context input[type=range]{width:96px!important;accent-color:var(--ms-acc)}
  .context .pressure,.context .smooth{display:flex!important}

  /* tools: every tool on screen at once — 2 rows × 7, ordered by daily use (Photoshop-style tool grid) */
  .toolrail,.toolrail.open{order:4;position:static!important;display:grid!important;grid-template-columns:repeat(7,1fr)!important;grid-auto-rows:54px;flex-direction:initial!important;width:auto!important;height:auto!important;margin:6px 8px 0!important;padding:5px!important;gap:4px!important;overflow:visible!important;background:var(--ms-s1)!important;border-radius:16px;box-shadow:none!important;border:0!important}
  .toolrail .separator,.toolrail .rail-color,.toolrail .group-more{display:none!important}
  .toolrail .tool-group{position:relative;display:flex!important;min-width:0}
  .toolrail .tool-group>button:first-child{width:100%!important;min-width:0;min-height:0!important;height:100%!important;padding:6px 1px 4px!important;border-radius:11px!important;display:flex!important;flex-direction:column;align-items:center;justify-content:center;gap:4px;background:none!important;color:var(--ms-ink)!important;border:0!important;transition:background .18s,transform .12s}
  .toolrail .tool-group>button:first-child:active{transform:scale(.94)}
  .toolrail svg{width:21px!important;height:21px!important}
  .toolrail small{display:block!important;font-size:10px!important;line-height:1.15;margin:0!important;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;color:var(--ms-mute)}
  .toolrail .tool-group.ms-active>button:first-child{background:var(--ms-acc2)!important;color:#fff!important;box-shadow:0 4px 12px rgba(154,58,34,.4)}
  .toolrail .tool-group.ms-active small{color:#fff}
  .toolrail .tool-group.ms-multi:after{content:"";position:absolute;top:5px;left:5px;transform:rotate(180deg);width:0;height:0;border-left:5px solid currentColor;border-top:5px solid transparent;color:rgba(255,255,255,.35);pointer-events:none}
  .toolrail .tool-group.ms-active.ms-multi:after{color:rgba(255,255,255,.75)}

  /* sub-tools of the active tool, always visible as chips (or a one-line hint) */
  .ms-vars{order:2;display:flex;align-items:center;gap:6px;height:40px;margin:6px 8px 0;padding:0 2px;overflow-x:auto;scrollbar-width:none;flex:none}
  .ms-vars::-webkit-scrollbar{display:none}
  .ms-vars button{flex:none;display:flex;align-items:center;gap:6px;height:34px;padding:0 12px 0 10px;border-radius:17px;border:1px solid var(--ms-line);background:var(--ms-s1);color:var(--ms-ink);font:inherit;font-size:12.5px;white-space:nowrap}
  .ms-vars button svg{width:16px;height:16px}
  .ms-vars button[aria-pressed=true]{background:var(--ms-ink);color:var(--ms-bg);border-color:transparent;font-weight:700}
  .ms-vars .ms-hint{color:var(--ms-mute);font-size:12px;white-space:nowrap;padding:0 6px}
  .context{order:3!important}
  body.ms-on:not(.ms-paint) .context{display:none!important}
  .context .active-tool{display:none!important}

  /* bottom bar */
  .mobile-nav{order:4;display:flex!important;justify-content:space-around!important;gap:0!important;min-height:var(--ms-nav)!important;margin-top:6px;padding:0 6px env(safe-area-inset-bottom,0px)!important;background:var(--ms-s1)!important;border-top:1px solid var(--ms-line)!important}
  .mobile-nav button{flex:1;display:flex!important;flex-direction:column;align-items:center;justify-content:center;gap:3px;min-height:var(--ms-nav)!important;font-size:11px!important;color:var(--ms-mute)!important;background:none!important;border:0!important;padding:4px 2px!important}
  .mobile-nav button:before{content:"";width:22px;height:22px;background:currentColor;-webkit-mask:var(--i) center/contain no-repeat;mask:var(--i) center/contain no-repeat}
  .mobile-nav [data-action=toolsPanel]{display:none!important}
  .mobile-nav [data-action=propsPanel]{--i:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 7h10M18 7h2M4 17h4M12 17h8'/%3E%3Ccircle cx='16' cy='7' r='2'/%3E%3Ccircle cx='10' cy='17' r='2'/%3E%3C/svg%3E")}
  .mobile-nav [data-action=layersPanel]{--i:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M12 3 3 8l9 5 9-5z'/%3E%3Cpath d='m3 13 9 5 9-5'/%3E%3C/svg%3E")}
  .mobile-nav [data-action=upload]{--i:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='3'/%3E%3Ccircle cx='9' cy='10' r='1.6'/%3E%3Cpath d='m4 17 5-4 4 3 3-2 4 3'/%3E%3C/svg%3E");font-size:0!important}
  .mobile-nav [data-action=upload]:after{content:"صورة";font-size:11px}
  .mobile-nav .ms-color{--i:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8'%3E%3Cpath d='M12 3a9 9 0 1 0 0 18c1.2 0 1.7-1 1.3-2-.6-1.1-.2-2.5 1.4-2.5H17a4 4 0 0 0 4-4A9.5 9.5 0 0 0 12 3z'/%3E%3C/svg%3E")}
  .mobile-nav .ms-fit{--i:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E")}
  .mobile-nav button.on{color:var(--ms-ink)!important}
  .mobile-nav .ms-swatch{position:relative}
  .mobile-nav .ms-swatch i{position:absolute;top:8px;left:calc(50% + 6px);width:10px;height:10px;border-radius:50%;border:2px solid var(--ms-s1);background:var(--ms-col,#9a3a22)}

  /* panels as bottom sheets */
  .panel,.inspector{display:none}
  .panel.open,.layers-panel.open,.inspector.open{display:flex!important;flex-direction:column;position:fixed!important;left:0!important;right:0!important;top:auto!important;bottom:0!important;width:auto!important;max-height:min(66dvh,560px);z-index:60;
    background:var(--ms-s1)!important;border-radius:22px 22px 0 0;box-shadow:0 -18px 50px rgba(0,0,0,.55)!important;overflow:auto;padding-bottom:env(safe-area-inset-bottom,0px);animation:ms-up .32s cubic-bezier(.22,.8,.24,1)}
  .panel.open:before{content:"";display:block;flex:none;width:38px;height:5px;border-radius:3px;background:rgba(255,255,255,.22);margin:8px auto 2px}
  .panel-head{height:44px!important;padding:0 16px!important}
  .panel-head>button,.color-section .section-head>button{display:grid!important;place-items:center;width:32px;height:32px;min-height:0!important;border-radius:50%;background:var(--ms-s2)!important}
  .ms-scrim{position:fixed;inset:0;z-index:55;background:rgba(0,0,0,.35);opacity:0;pointer-events:none;transition:opacity .25s}
  body.ms-sheet .ms-scrim{opacity:1;pointer-events:auto}
  .layers-panel.open .history-panel{max-height:none}
  .layers-panel.ms-color-only .panel-tabs,.layers-panel.ms-color-only .pane,.layers-panel.ms-color-only .history-panel{display:none!important}
  .layers-panel.ms-layers-only .color-section{display:none!important}
  .swatches button{width:34px!important;min-height:34px!important;border-radius:50%!important}
  #tool-flyout:not([hidden]){display:none!important;position:fixed!important;left:8px!important;right:8px!important;top:auto!important;bottom:calc(var(--ms-nav) + var(--ms-dock) + 18px + env(safe-area-inset-bottom,0px))!important;display:flex!important;flex-wrap:wrap;gap:6px;padding:10px;border-radius:18px;background:var(--ms-s2)!important;box-shadow:0 18px 40px rgba(0,0,0,.5);z-index:65}
  #tool-flyout button{flex:1 1 calc(50% - 6px);min-height:48px!important;border-radius:12px;font-size:13px}

  /* "more" sheet = the original menubar, laid out as sections */
  body.ms-menu .menubar{display:block!important;position:fixed!important;left:0;right:0;bottom:0;top:auto!important;height:auto!important;max-height:78dvh;overflow:auto;z-index:70;background:var(--ms-s1)!important;border-radius:22px 22px 0 0;padding:6px 14px calc(16px + env(safe-area-inset-bottom,0px))!important;box-shadow:0 -18px 50px rgba(0,0,0,.55);animation:ms-up .32s cubic-bezier(.22,.8,.24,1)}
  body.ms-menu .menubar:before{content:"";display:block;width:38px;height:5px;border-radius:3px;background:rgba(255,255,255,.22);margin:4px auto 10px}
  body.ms-menu .menubar details{display:block;border-bottom:1px solid var(--ms-line)}
  body.ms-menu .menubar summary{font-size:15px!important;font-weight:700;padding:14px 4px!important;color:var(--ms-ink);list-style:none;display:flex;justify-content:space-between}
  body.ms-menu .menubar summary::-webkit-details-marker{display:none}
  body.ms-menu .menubar summary:after{content:"›";transform:rotate(90deg);color:var(--ms-mute)}
  body.ms-menu .menubar details[open] summary:after{transform:rotate(-90deg)}
  body.ms-menu .menubar details>div{position:static!important;width:auto!important;max-height:none!important;box-shadow:none!important;background:none!important;border:0!important;padding:0 0 10px!important;display:grid!important;grid-template-columns:1fr 1fr;gap:6px}
  body.ms-menu .menubar details>div button,body.ms-menu .menubar details>div a{min-height:46px!important;border-radius:12px;background:var(--ms-s2)!important;color:var(--ms-ink)!important;font-size:12.5px!important;padding:6px 10px!important;text-align:start;display:flex;align-items:center}
  body.ms-menu .menubar kbd{display:none}
  #dialog{max-width:calc(100vw - 16px)!important;border-radius:20px}
  #toast{bottom:calc(var(--ms-nav) + var(--ms-dock) + 70px + env(safe-area-inset-bottom,0px))!important}
}
@keyframes ms-up{from{transform:translateY(40px);opacity:.4}to{transform:none;opacity:1}}
@media (max-width:760px) and (prefers-reduced-motion:reduce){.panel.open,body.ms-menu .menubar{animation:none}}
/* iOS zooms into any field under 16px */
@media (max-width:899px),(pointer:coarse){
 input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]),textarea,select,[contenteditable=true]{font-size:16px!important}
 .ms-title input{font-size:16px!important}
}

/* r31 — legible fields and 44px touch areas, without adding any controls. */
input:not([type=range]):not([type=checkbox]):not([type=color]):not([type=file]),select,textarea{font-size:16px!important}
:is(button,a,input,select,textarea,summary):focus-visible{outline:2px solid #e7a774!important;outline-offset:2px}
@media(max-width:760px){
 .top .brand,.top-actions button,.statusbar button{min-width:44px!important;min-height:44px!important}
 .top{gap:4px!important;padding-inline:8px!important}
 .top-actions{gap:4px!important}.top-actions button{padding-inline:9px!important}
 .ms-title #doc-name{min-height:44px!important;width:100%;line-height:1.3!important}
 .ms-title small{line-height:1.2}.ms-title{min-width:30px}
 .panel input,.panel select,.panel textarea,dialog input,dialog select,dialog textarea{scroll-margin-block:20px}
 .ms-vars button{min-width:44px!important;min-height:44px!important}
 .ms-vars{min-height:44px!important}
}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}

html[lang=en] .mobile-nav [data-action=upload]:after{content:'Photo'}
/* r31: opened sheets need the same touch targets as the main toolbar. */
@media(max-width:760px){
 .panel-head>button,.color-section .section-head>button,.swatches button{min-width:44px!important;min-height:44px!important;width:44px!important;height:44px!important}
 .panel button,.inspector button,dialog button,.panel input:not([type=checkbox]):not([type=radio]):not([type=color]),.inspector input:not([type=checkbox]):not([type=radio]):not([type=color]),dialog input:not([type=checkbox]):not([type=radio]):not([type=color]){min-height:44px!important}
 .panel.open,.inspector.open,body.ms-menu .menubar{animation-duration:.2s!important}.ms-scrim{transition-duration:.18s}
}
